# HG changeset patch # User koda # Date 1291817888 -3600 # Node ID 85695e3d2623451d17440345169103a37eda3817 # Parent 05029b4d849009bd0405c82b0c6af865d69a02b1# Parent b7a098f2649aff196f4b905e9e4b8c715bf21c8f merge diff -r 05029b4d8490 -r 85695e3d2623 QTfrontend/gamecfgwidget.cpp --- a/QTfrontend/gamecfgwidget.cpp Wed Dec 08 15:16:57 2010 +0100 +++ b/QTfrontend/gamecfgwidget.cpp Wed Dec 08 15:18:08 2010 +0100 @@ -179,7 +179,7 @@ sl.append(QString("e$turntime %1").arg(schemeData(25).toInt() * 1000)); sl.append(QString("e$sd_turns %1").arg(schemeData(27).toInt())); sl.append(QString("e$casefreq %1").arg(schemeData(28).toInt())); - sl.append(QString("e$minestime %1").arg(schemeData(29).toInt())); + sl.append(QString("e$minestime %1").arg(schemeData(29).toInt() * 1000)); sl.append(QString("e$minesnum %1").arg(schemeData(30).toInt())); sl.append(QString("e$minedudpct %1").arg(schemeData(31).toInt())); sl.append(QString("e$explosives %1").arg(schemeData(32).toInt())); diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/VGSHandlers.inc --- a/hedgewars/VGSHandlers.inc Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/VGSHandlers.inc Wed Dec 08 15:18:08 2010 +0100 @@ -566,7 +566,11 @@ for i:= 0 to 31 do begin vg:= AddVisualGear(gX, gY, vgtFire); - if vg <> nil then vg^.State:= 1; + if vg <> nil then + begin + vg^.State:= gstTmpFlag; + inc(vg^.FrameTicks, vg^.FrameTicks) + end end; for i:= 0 to 8 do AddVisualGear(gX, gY, vgtExplPart); for i:= 0 to 8 do AddVisualGear(gX, gY, vgtExplPart2); @@ -604,7 +608,11 @@ for i:= 0 to 46 do begin vg:= AddVisualGear(gX, gY, vgtFire); - if vg <> nil then vg^.State:= 1; + if vg <> nil then + begin + vg^.State:= gstTmpFlag; + inc(vg^.FrameTicks, vg^.FrameTicks) + end end; for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart); for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart2); diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uGears.pas Wed Dec 08 15:18:08 2010 +0100 @@ -285,7 +285,7 @@ if cMinesTime < 0 then gear^.Timer:= getrandom(51)*100 else - gear^.Timer:= cMinesTime*1000; + gear^.Timer:= cMinesTime; end; gtSMine: begin gear^.Health:= 10; diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uScript.pas Wed Dec 08 15:18:08 2010 +0100 @@ -83,6 +83,39 @@ // where L contains the state, returns the number of return values on the stack // call lua_gettop(L) to receive number of parameters passed +function lc_band(L: PLua_State): LongInt; Cdecl; +begin + if lua_gettop(L) <> 2 then + begin + LuaError('Lua: Wrong number of parameters passed to band!'); + lua_pushnil(L); + end + else lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); + lc_band := 1; +end; + +function lc_bor(L: PLua_State): LongInt; Cdecl; +begin + if lua_gettop(L) <> 2 then + begin + LuaError('Lua: Wrong number of parameters passed to bor!'); + lua_pushnil(L); + end + else lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); + lc_bor := 1; +end; + +function lc_bnot(L: PLua_State): LongInt; Cdecl; +begin + if lua_gettop(L) <> 1 then + begin + LuaError('Lua: Wrong number of parameters passed to bnot!'); + lua_pushnil(L); + end + else lua_pushinteger(L, not lua_tointeger(L, 1)); + lc_bnot := 1; +end; + function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; begin if lua_gettop(L) = 1 then @@ -166,7 +199,7 @@ else begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, 0); - lua_pushnumber(L, gear^.uid); + lua_pushinteger(L, gear^.uid); end; lc_spawnhealthcrate := 1; end; @@ -181,7 +214,7 @@ else begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3)); - lua_pushnumber(L, gear^.uid); + lua_pushinteger(L, gear^.uid); end; lc_spawnammocrate := 1; end; @@ -196,7 +229,7 @@ else begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), UtilityCrate, lua_tointeger(L, 3)); - lua_pushnumber(L, gear^.uid); + lua_pushinteger(L, gear^.uid); end; lc_spawnutilitycrate := 1; end; @@ -223,7 +256,7 @@ t:= lua_tointeger(L, 7); gear:= AddGear(x, y, gt, s, dx, dy, t); - lua_pushnumber(L, gear^.uid) + lua_pushinteger(L, gear^.uid) end; lc_addgear:= 1; // 1 return value end; @@ -263,8 +296,8 @@ c:= lua_toboolean(L, 5); vg:= AddVisualGear(x, y, vgt, s, c); - if vg <> nil then lua_pushnumber(L, vg^.uid) - else lua_pushnumber(L, 0) + if vg <> nil then lua_pushinteger(L, vg^.uid) + else lua_pushinteger(L, 0) end; lc_addvisualgear:= 1; // 1 return value end; @@ -352,7 +385,7 @@ if FollowGear = nil then lua_pushnil(L) else - lua_pushnumber(L, FollowGear^.uid); + lua_pushinteger(L, FollowGear^.uid); lc_getfollowgear:= 1; // 1 return value end; @@ -498,7 +531,7 @@ begin gear:= GearByUID(lua_tointeger(L, 1)); if gear <> nil then - lua_pushnumber(L, gear^.Timer) + lua_pushinteger(L, gear^.Timer) else lua_pushnil(L); end; @@ -517,7 +550,7 @@ begin gear:= GearByUID(lua_tointeger(L, 1)); if gear <> nil then - lua_pushnumber(L, gear^.Health) + lua_pushinteger(L, gear^.Health) else lua_pushnil(L); end; @@ -536,7 +569,7 @@ begin gear:= GearByUID(lua_tointeger(L, 1)); if gear <> nil then - lua_pushnumber(L, hwRound(gear^.X)) + lua_pushinteger(L, hwRound(gear^.X)) else lua_pushnil(L); end; @@ -555,7 +588,7 @@ begin gear:= GearByUID(lua_tointeger(L, 1)); if gear <> nil then - lua_pushnumber(L, hwRound(gear^.Y)) + lua_pushinteger(L, hwRound(gear^.Y)) else lua_pushnil(L); end; @@ -645,6 +678,22 @@ lc_hogsay:= 0 end; +function lc_addammo(L : Plua_State) : LongInt; Cdecl; +var gear : PGear; +begin + if lua_gettop(L) <> 2 then + begin + LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); + end + else + begin + gear:= GearByUID(lua_tointeger(L, 1)); + if (gear <> nil) and (gear^.Hedgehog <> nil) then + AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); + end; + lc_addammo:= 0 +end; + function lc_sethealth(L : Plua_State) : LongInt; Cdecl; var gear : PGear; begin @@ -1302,6 +1351,9 @@ ScriptSetInteger(EnumToStr(he), ord(he)); // register functions +lua_register(luaState, 'band', @lc_band); +lua_register(luaState, 'bor', @lc_bor); +lua_register(luaState, 'bnot', @lc_bnot); lua_register(luaState, 'AddGear', @lc_addgear); lua_register(luaState, 'DeleteGear', @lc_deletegear); lua_register(luaState, 'AddVisualGear', @lc_addvisualgear); @@ -1325,6 +1377,7 @@ lua_register(luaState, 'PlaySound', @lc_playsound); lua_register(luaState, 'AddTeam', @lc_addteam); lua_register(luaState, 'AddHog', @lc_addhog); +lua_register(luaState, 'AddAmmo', @lc_addammo); lua_register(luaState, 'SetHealth', @lc_sethealth); lua_register(luaState, 'GetHealth', @lc_gethealth); lua_register(luaState, 'SetEffect', @lc_seteffect); diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uTeams.pas Wed Dec 08 15:18:08 2010 +0100 @@ -36,7 +36,7 @@ procedure TeamGoneEffect(var Team: TTeam); implementation -uses uLocale, uAmmos, uChat, uMobile, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug; +uses uLocale, uAmmos, uChat, uMobile, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug, uScript; const MaxTeamHealth: LongInt = 0; @@ -248,6 +248,7 @@ end; perfExt_NewTurnBeginning(); +ScriptCall('onNewTurn'); end; function AddTeam(TeamColor: Longword): PTeam; diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uVariables.pas Wed Dec 08 15:18:08 2010 +0100 @@ -2168,7 +2168,7 @@ cMapGen := 0; // MAPGEN_REGULAR cMazeSize := 0; cHedgehogTurnTime := 45000; - cMinesTime := 3; + cMinesTime := 3000; cMaxAIThinkTime := 9000; cCloudsNumber := 9; cHealthCaseProb := 35; diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uVisualGears.pas --- a/hedgewars/uVisualGears.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uVisualGears.pas Wed Dec 08 15:18:08 2010 +0100 @@ -373,12 +373,13 @@ procedure DrawVisualGears(Layer: LongWord); var Gear: PVisualGear; + tinted: boolean; begin Gear:= VisualGearsList; case Layer of 0: while Gear <> nil do begin - Tint(Gear^.Tint); + if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); case Gear^.Kind of vgtFlake: if vobVelocity = 0 then DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) @@ -386,17 +387,20 @@ DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); vgtCloud: DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame); end; + if Gear^.Tint <> $FFFFFFFF then Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end; 1: while Gear <> nil do begin - Tint(Gear^.Tint); + tinted:= false; + if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); case Gear^.Kind of vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); vgtLineTrail: DrawLine(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 1.0, $FF, min(Gear^.Timer, $C0), min(Gear^.Timer, $80), min(Gear^.Timer, $FF)); vgtSpeechBubble: if (Gear^.Hedgehog^.Team <> CurrentTeam) and (Gear^.Tex <> nil) then begin + tinted:= true; Tint($FF, $FF, $FF, $66); DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex) end @@ -408,18 +412,24 @@ vgtDust: DrawSprite(sprDust, round(Gear^.X) + WorldDx - 11, round(Gear^.Y) + WorldDy - 11, 7 - Gear^.Frame); vgtFeather: begin if Gear^.FrameTicks < 255 then + begin Tint($FF, $FF, $FF, Gear^.FrameTicks); + tinted:= true + end; DrawRotatedF(sprFeather, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle); end; end; + if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end; 2: while Gear <> nil do begin - Tint(Gear^.Tint); + tinted:= false; + if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); case Gear^.Kind of vgtExplosion: DrawSprite(sprExplosion50, round(Gear^.X) - 32 + WorldDx, round(Gear^.Y) - 32 + WorldDy, Gear^.State); vgtBigExplosion: begin + tinted:= true; Tint($FF, $FF, $FF, round($FF * (1 - power(Gear^.Timer / 250, 4)))); DrawRotatedTextureF(SpritesData[sprBigExplosion].Texture, 0.85 * (-power(2, -10 * Int(Gear^.Timer)/250) + 1) + 0.4, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 385, 385, Gear^.Angle); end; @@ -435,11 +445,13 @@ vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8); vgtSteam: DrawSprite(sprSmokeWhite, round(Gear^.X) + WorldDx - 11, round(Gear^.Y) + WorldDy - 11, 7 - Gear^.Frame); vgtAmmo: begin + tinted:= true; Tint($FF, $FF, $FF, round(Gear^.alpha * $FF)); DrawTextureF(ropeIconTex, Gear^.scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 32, 32); DrawTextureF(SpritesData[sprAMAmmos].Texture, Gear^.scale * 0.90, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame - 1, 1, 32, 32); end; vgtHealth: begin + tinted:= true; case Gear^.Frame div 10 of 0:Tint(0, $FF, 0, round(Gear^.FrameTicks * $FF / 1000)); 1:Tint($FF, 0, 0, round(Gear^.FrameTicks * $FF / 1000)); @@ -448,12 +460,18 @@ end; vgtShell: begin if Gear^.FrameTicks < $FF then + begin Tint($FF, $FF, $FF, Gear^.FrameTicks); + tinted:= true + end; DrawRotatedF(sprShell, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle); end; vgtEgg: begin if Gear^.FrameTicks < $FF then + begin Tint($FF, $FF, $FF, Gear^.FrameTicks); + tinted:= true + end; DrawRotatedF(sprEgg, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle); end; vgtSplash: DrawSprite(sprSplash, round(Gear^.X) + WorldDx - 40, round(Gear^.Y) + WorldDy - 58, 19 - (Gear^.FrameTicks div 37)); @@ -463,9 +481,11 @@ Tint($FF, $FF, $FF, Gear^.FrameTicks div 2) else Tint($FF, $FF, $FF, $80); + tinted:= true; DrawRotatedF(sprBeeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, (RealTicks shr 4) mod cMaxAngle); end; vgtSmokeRing: begin + tinted:= true; Tint($FF, $FF, $FF, round(Gear^.alpha * $FF)); DrawRotatedTextureF(SpritesData[sprSmokeRing].Texture, Gear^.scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 200, 200, Gear^.Angle); end; @@ -479,10 +499,10 @@ vgtHealthTag: if Gear^.Tex <> nil then DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex); vgtCircle: DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer); end; + if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end end; -Tint($FFFFFFFF); end; function VisualGearByUID(uid : Longword) : PVisualGear; diff -r 05029b4d8490 -r 85695e3d2623 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Wed Dec 08 15:16:57 2010 +0100 +++ b/hedgewars/uWorld.pas Wed Dec 08 15:18:08 2010 +0100 @@ -141,14 +141,14 @@ ScreenFadeSpeed:= 1; // modified mine timers? -if cMinesTime <> 3 then +if cMinesTime <> 3000 then begin if cMinesTime = 0 then g:= AddGoal(g, gfAny, gidNoMineTimer) else if cMinesTime < 0 then g:= AddGoal(g, gfAny, gidRandomMineTimer) else - g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime); + g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime div 1000); end; // if the string has been set, show it for (default timeframe) seconds diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/drawMapTest.pro --- a/tools/drawMapTest/drawMapTest.pro Wed Dec 08 15:16:57 2010 +0100 +++ b/tools/drawMapTest/drawMapTest.pro Wed Dec 08 15:18:08 2010 +0100 @@ -5,7 +5,11 @@ TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ - drawmapscene.cpp + drawmapscene.cpp \ + qaspectratiolayout.cpp \ + drawmapwidget.cpp HEADERS += mainwindow.h \ - drawmapscene.h + drawmapscene.h \ + qaspectratiolayout.h \ + drawmapwidget.h FORMS += mainwindow.ui diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/drawmapwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/drawMapTest/drawmapwidget.cpp Wed Dec 08 15:18:08 2010 +0100 @@ -0,0 +1,38 @@ +#include "drawmapwidget.h" + +DrawMapWidget::DrawMapWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::DrawMapWidget) +{ + ui->setupUi(this); +} + +DrawMapWidget::~DrawMapWidget() +{ + delete ui; +} + +void DrawMapWidget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void DrawMapWidget::setScene(DrawMapScene * scene) +{ + ui->graphicsView->setScene(scene); +} + +void DrawMapWidget::resizeEvent(QResizeEvent * event) +{ + Q_UNUSED(event); + + if(ui->graphicsView && ui->graphicsView->scene()) + ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); +} diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/drawmapwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/drawMapTest/drawmapwidget.h Wed Dec 08 15:18:08 2010 +0100 @@ -0,0 +1,61 @@ +#ifndef DRAWMAPWIDGET_H +#define DRAWMAPWIDGET_H + +#include +#include +#include +#include +#include + +#include "qaspectratiolayout.h" +#include "drawmapscene.h" + +namespace Ui { + class Ui_DrawMapWidget + { + public: + QGraphicsView *graphicsView; + QPushButton *pbUndo; + + void setupUi(QWidget *drawMapWidget) + { + QAspectRatioLayout * arLayout = new QAspectRatioLayout(drawMapWidget); + arLayout->setMargin(0); + + graphicsView = new QGraphicsView(drawMapWidget); + arLayout->addWidget(graphicsView); + + retranslateUi(drawMapWidget); + + QMetaObject::connectSlotsByName(drawMapWidget); + } // setupUi + + void retranslateUi(QWidget *drawMapWidget) + { + Q_UNUSED(drawMapWidget); + } // retranslateUi + + }; + + class DrawMapWidget: public Ui_DrawMapWidget {}; +} + +class DrawMapWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DrawMapWidget(QWidget *parent = 0); + ~DrawMapWidget(); + + void setScene(DrawMapScene * scene); + +protected: + void changeEvent(QEvent *e); + virtual void resizeEvent(QResizeEvent * event); + +private: + Ui::DrawMapWidget *ui; +}; + +#endif // DRAWMAPWIDGET_H diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/mainwindow.cpp --- a/tools/drawMapTest/mainwindow.cpp Wed Dec 08 15:16:57 2010 +0100 +++ b/tools/drawMapTest/mainwindow.cpp Wed Dec 08 15:18:08 2010 +0100 @@ -11,7 +11,8 @@ ui->setupUi(this); scene = new DrawMapScene(this); - ui->graphicsView->setScene(scene); + //ui->graphicsView->setScene(scene); + ui->drawMapWidget->setScene(scene); connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo())); connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged())); @@ -34,14 +35,6 @@ } } -void MainWindow::resizeEvent(QResizeEvent * event) -{ - Q_UNUSED(event); - - if(ui->graphicsView) - ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); -} - void MainWindow::scene_pathChanged() { QString str = scene->encode().toBase64(); @@ -49,11 +42,6 @@ ui->sbBytes->setValue(str.size()); } -void MainWindow::on_pbSimplify_clicked() -{ - scene->simplifyLast(); -} - void MainWindow::on_pbSave_clicked() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), "."); diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/mainwindow.h --- a/tools/drawMapTest/mainwindow.h Wed Dec 08 15:16:57 2010 +0100 +++ b/tools/drawMapTest/mainwindow.h Wed Dec 08 15:18:08 2010 +0100 @@ -22,12 +22,9 @@ Ui::MainWindow *ui; DrawMapScene * scene; - virtual void resizeEvent(QResizeEvent * event); - private slots: void on_pbLoad_clicked(); void on_pbSave_clicked(); - void on_pbSimplify_clicked(); void scene_pathChanged(); }; diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/mainwindow.ui --- a/tools/drawMapTest/mainwindow.ui Wed Dec 08 15:16:57 2010 +0100 +++ b/tools/drawMapTest/mainwindow.ui Wed Dec 08 15:18:08 2010 +0100 @@ -15,9 +15,6 @@ - - - @@ -75,10 +72,21 @@ + + + + + + DrawMapWidget + QWidget +
drawmapwidget.h
+ 1 +
+
diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/qaspectratiolayout.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/drawMapTest/qaspectratiolayout.cpp Wed Dec 08 15:18:08 2010 +0100 @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2009 Nokia Corporation. + */ + +#include "qaspectratiolayout.h" + +QAspectRatioLayout::QAspectRatioLayout(QWidget* parent, int spacing) : QLayout(parent) { + init(spacing); +} + +QAspectRatioLayout::QAspectRatioLayout(int spacing) { + init(spacing); +} + +QAspectRatioLayout::~QAspectRatioLayout() { + delete item; + delete lastReceivedRect; + delete _geometry; +} + +void QAspectRatioLayout::init(int spacing) { + item = 0; + lastReceivedRect = new QRect(0, 0, 0, 0); + _geometry = new QRect(0, 0, 0, 0); + setSpacing(spacing); +} + + +/* Adds item if place isn't already taken. */ +void QAspectRatioLayout::add(QLayoutItem* item) { + if(!hasItem()) { + replaceItem(item); + } +} + +/* Adds item if place isn't already taken. */ +void QAspectRatioLayout::addItem(QLayoutItem* item) { + if(!hasItem()) { + replaceItem(item); + } +} + +/* Adds widget if place isn't already taken. */ +void QAspectRatioLayout::addWidget(QWidget* widget) { + if(!hasItem()) { + replaceItem(new QWidgetItem(widget)); + } +} + +/* Returns the item pointer and dereferences it here. */ +QLayoutItem* QAspectRatioLayout::take() { + QLayoutItem* item = 0; + if(this->hasItem()) { + item = this->item; + this->item = 0; + } + return item; +} + +/* Returns the item pointer and dereferences it here. */ +QLayoutItem* QAspectRatioLayout::takeAt(int index) { + if(index != 0) { + return 0; + } + return this->take(); +} + +/* Returns the item pointer. */ +QLayoutItem* QAspectRatioLayout::itemAt(int index) const { + if(index != 0) { + return 0; + } + if(hasItem()) { + return this->item; + } + return 0; +} + +/* Checks if we have an item. */ +bool QAspectRatioLayout::hasItem() const { + return this->item != 0; +} + +/* Returns the count of items which can be either 0 or 1. */ +int QAspectRatioLayout::count() const { + int returnValue = 0; + if(hasItem()) { + returnValue = 1; + } + return returnValue; +} + +/* Replaces the item with the new and returns the old. */ +QLayoutItem* QAspectRatioLayout::replaceItem(QLayoutItem* item) { + QLayoutItem* old = 0; + if(this->hasItem()) { + old = this->item; + } + this->item = item; + setGeometry(*this->_geometry); + return old; +} + +/* Tells which way layout expands. */ +Qt::Orientations QAspectRatioLayout::expandingDirections() const { + return Qt::Horizontal | Qt::Vertical; +} + +/* Tells which size is preferred. */ +QSize QAspectRatioLayout::sizeHint() const { + return this->item->minimumSize(); +} + +/* Tells minimum size. */ +QSize QAspectRatioLayout::minimumSize() const { + return this->item->minimumSize(); +} + +/* + * Tells if heightForWidth calculations is handled. + * It isn't since width isn't enough to calculate + * proper size. + */ +bool QAspectRatioLayout::hasHeightForWidth() const { + return false; +} + +/* Replaces lastReceivedRect. */ +void QAspectRatioLayout::setLastReceivedRect(const QRect& rect) { + QRect* oldRect = this->lastReceivedRect; + this->lastReceivedRect = new QRect(rect.topLeft(), rect.size()); + delete oldRect; +} + +/* Returns geometry */ +QRect QAspectRatioLayout::geometry() { + return QRect(*this->_geometry); +} + +/* Sets geometry to given size. */ +void QAspectRatioLayout::setGeometry(const QRect& rect) { + /* + * We check if the item is set and + * if size is the same previously received. + * If either is false nothing is done. + */ + if(!this->hasItem() || + areRectsEqual(*this->lastReceivedRect, rect)) { + return; + } + /* Replace the last received rectangle. */ + setLastReceivedRect(rect); + /* Calculate proper size for the item relative to the received size. */ + QSize properSize = calculateProperSize(rect.size()); + /* Calculate center location in the rect and with item size. */ + QPoint properLocation = calculateCenterLocation(rect.size(), properSize); + /* Set items geometry */ + this->item->setGeometry(QRect(properLocation, properSize)); + QRect* oldRect = this->_geometry; + /* Cache the calculated geometry. */ + this->_geometry = new QRect(properLocation, properSize); + delete oldRect; + /* Super classes setGeometry */ + QLayout::setGeometry(*this->_geometry); +} + +/* Takes the shortest side and creates QSize + * with the shortest side as width and height. */ +QSize QAspectRatioLayout::calculateProperSize(QSize from) const { + QSize properSize; + if(from.height() * 2 < from.width()) { + properSize.setHeight(from.height() - this->margin()); + properSize.setWidth(from.height() * 2 - this->margin()); + } + else { + properSize.setWidth(from.width() - this->margin()); + properSize.setHeight(from.width() / 2 - this->margin()); + } + return properSize; +} + +/* Calculates center location from the given height and width for item size. */ +QPoint QAspectRatioLayout::calculateCenterLocation(QSize from, + QSize itemSize) const { + QPoint centerLocation; + if((from.width() - itemSize.width()) > 0) { + centerLocation.setX((from.width() - itemSize.width())/2); + } + if((from.height() - itemSize.height()) > 0) { + centerLocation.setY((from.height() - itemSize.height())/2); + } + return centerLocation; +} + +/* Compares if two QRects are equal. */ +bool QAspectRatioLayout::areRectsEqual(const QRect& a, + const QRect& b) const { + bool result = false; + if(a.x() == b.x() && + a.y() == b.y() && + a.height() == b.height() && + a.width() == b.width()) { + result = true; + } + return result; +} diff -r 05029b4d8490 -r 85695e3d2623 tools/drawMapTest/qaspectratiolayout.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/drawMapTest/qaspectratiolayout.h Wed Dec 08 15:18:08 2010 +0100 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2009 Nokia Corporation. + */ + +#ifndef QASPECTRATIOLAYOUT_H_ +#define QASPECTRATIOLAYOUT_H_ + +#include +#include +#include +#include +#include + + +class QAspectRatioLayout : public QLayout +{ + Q_OBJECT + +public: + QAspectRatioLayout(QWidget* parent, int spacing =-1); + QAspectRatioLayout(int spacing = -1); + ~QAspectRatioLayout(); + + /* Convenience method */ + virtual void add(QLayoutItem* item); + +/* http://doc.trolltech.com/qlayout.html#addItem */ + virtual void addItem(QLayoutItem* item); + /* http://doc.trolltech.com/qlayout.html#addWidget */ + virtual void addWidget(QWidget* widget); + /* http://doc.trolltech.com/qlayout.html#takeAt */ + virtual QLayoutItem* takeAt(int index); + /* http://doc.trolltech.com/qlayout.html#itemAt */ + virtual QLayoutItem* itemAt(int index) const; + /* http://doc.trolltech.com/qlayout.html#count */ + virtual int count() const; + + /* + * These are ours since we do have only one item. + */ + virtual QLayoutItem* replaceItem(QLayoutItem* item); + virtual QLayoutItem* take(); + virtual bool hasItem() const; + +/* http://doc.trolltech.com/qlayout.html#expandingDirections */ + virtual Qt::Orientations expandingDirections() const; + + /* + * This method contains most of the juice of this article. + * http://doc.trolltech.com/qlayoutitem.html#setGeometry + */ + virtual void setGeometry(const QRect& rect); + /* http://doc.trolltech.com/qlayoutitem.html#geometry */ + virtual QRect geometry(); + + /* http://doc.trolltech.com/qlayoutitem.html#sizeHint */ + virtual QSize sizeHint() const; + /* http://doc.trolltech.com/qlayout.html#minimumSize */ + virtual QSize minimumSize() const; + /* http://doc.trolltech.com/qlayoutitem.html#hasHeightForWidth */ + virtual bool hasHeightForWidth() const; + +private: + /* Saves the last received rect. */ + void setLastReceivedRect(const QRect& rect); + /* Used to initialize the object. */ + void init(int spacing); + /* Calculates the maximum size for the item from the assigned size. */ + QSize calculateProperSize(QSize from) const; + /* Calculates the center location from the assigned size and + * the items size. */ + QPoint calculateCenterLocation(QSize from, QSize itemSize) const; + /* Check if two QRects are equal */ + bool areRectsEqual(const QRect& a, const QRect& b) const; + /* Contains item reference */ + QLayoutItem* item; + /* + * Used for caching so we won't do calculations every time + * setGeometry is called. + */ + QRect* lastReceivedRect; + /* Contains geometry */ + QRect* _geometry; + +}; + +#endif /* QASPECTRATIOLAYOUT_H_ */