[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/kolf
From: Stefan Majewsky <majewsky () gmx ! net>
Date: 2010-10-31 22:15:38
Message-ID: 20101031221538.2A484AC8AC () svn ! kde ! org
[Download RAW message or body]
SVN commit 1191685 by majewsky:
Simplify Wall and WallPoint code, remove obsolete resizing code.
M +43 -88 game.cpp
M +15 -25 game.h
--- trunk/KDE/kdegames/kolf/game.cpp #1191684:1191685
@@ -127,10 +127,10 @@
/////////////////////////
Arrow::Arrow(QGraphicsItem * parent)
- : AntiAliasedLine(parent)
+ : HintedLineItem(true, parent)
{
- line1 = new AntiAliasedLine(this);
- line2 = new AntiAliasedLine(this);
+ line1 = new HintedLineItem(true, this);
+ line2 = new HintedLineItem(true, this);
m_angle = 0;
m_length = 20;
@@ -301,13 +301,13 @@
setPos(baseX*resizeFactor, baseY*resizeFactor);
// setRect(0, 0, baseWidth*resizeFactor, baseHeight*resizeFactor);
botWall->setPos(baseBotWallX*resizeFactor, baseBotWallY*resizeFactor);
- botWall->resize(resizeFactor);
+// botWall->resize(resizeFactor);
topWall->setPos(baseTopWallX*resizeFactor, baseTopWallY*resizeFactor);
- topWall->resize(resizeFactor);
+// topWall->resize(resizeFactor);
leftWall->setPos(baseLeftWallX*resizeFactor, baseLeftWallY*resizeFactor);
- leftWall->resize(resizeFactor);
+// leftWall->resize(resizeFactor);
rightWall->setPos(baseRightWallX*resizeFactor, baseRightWallY*resizeFactor);
- rightWall->resize(resizeFactor);
+// rightWall->resize(resizeFactor);
}
bool Bridge::collision(Ball *ball, long int /*id*/)
@@ -504,7 +504,6 @@
baseGuardSpeed = 5;
guard = new WindmillGuard(Kolf::findBoard(this));
guard->setPen(QPen(Qt::black, 5));
- guard->setBasePenWidth(5);
guard->setVisible(true);
guard->setAlwaysShow(true);
setSpeed(baseGuardSpeed);
@@ -537,12 +536,12 @@
Bridge::resize(resizeFactor);
guard->setBetween(baseGuardMin*resizeFactor, baseGuardMax*resizeFactor);
guard->QGraphicsLineItem::setPos(baseGuardX*resizeFactor, baseGuardY*resizeFactor);
- guard->resize(resizeFactor);
+// guard->resize(resizeFactor);
setSpeed(baseGuardSpeed*resizeFactor);
left->QGraphicsLineItem::setPos(baseLeftX*resizeFactor, baseLeftY*resizeFactor);
- left->resize(resizeFactor);
+// left->resize(resizeFactor);
right->QGraphicsLineItem::setPos(baseRightX*resizeFactor, baseRightY*resizeFactor);
- right->resize(resizeFactor);
+// right->resize(resizeFactor);
}
void Windmill::aboutToDie()
@@ -980,7 +979,7 @@
/////////////////////////
Putter::Putter(QGraphicsItem* parent)
-: AntiAliasedLine(parent)
+: HintedLineItem(true, parent)
{
setData(0, Rtti_Putter);
m_showGuideLine = true;
@@ -992,7 +991,7 @@
basePutterWidth = putterWidth = 11;
angle = 0;
- guideLine = new AntiAliasedLine(this);
+ guideLine = new HintedLineItem(true, this);
guideLine->setPen(QPen(Qt::white, baseGuideLineThickness));
guideLine->setZValue(998.8);
@@ -1293,7 +1292,7 @@
void BlackHole::showInfo()
{
delete infoLine;
- infoLine = new AntiAliasedLine(Kolf::findBoard(this));
+ infoLine = new HintedLineItem(true, Kolf::findBoard(this));
infoLine->setVisible(true);
infoLine->setPen(QPen(exitItem->pen().color(), baseInfoLineThickness));
infoLine->setZValue(10000);
@@ -1529,7 +1528,7 @@
/////////////////////////
BlackHoleExit::BlackHoleExit(BlackHole *blackHole, QGraphicsItem * parent)
-: AntiAliasedLine(parent)
+: HintedLineItem(true, parent)
{
setData(0, Rtti_NoCollision);
this->blackHole = blackHole;
@@ -1660,15 +1659,15 @@
/////////////////////////
-AntiAliasedLine::AntiAliasedLine(QGraphicsItem *parent)
+HintedLineItem::HintedLineItem(bool antialiased, QGraphicsItem *parent)
: QGraphicsLineItem(parent)
+ , m_antialiased(antialiased)
{
- ;
}
-void AntiAliasedLine::paint(QPainter *p, const QStyleOptionGraphicsItem *style, \
QWidget *widget) +void HintedLineItem::paint(QPainter *p, const \
QStyleOptionGraphicsItem *style, QWidget *widget) {
- p->setRenderHint(QPainter::Antialiasing, true);
+ p->setRenderHint(QPainter::Antialiasing, m_antialiased);
QGraphicsLineItem::paint(p, style, widget);
}
@@ -1686,13 +1685,7 @@
lastId = INT_MAX - 10;
dontmove = false;
- setPos(0, 0);
- QPointF p;
- if (start)
- p = wall->startPointF();
- else
- p = wall->endPointF();
- setPos(p.x(), p.y());
+ setPos(start ? wall->startPointF() : wall->endPointF());
setPen(QPen(Qt::NoPen));
}
@@ -1701,15 +1694,16 @@
double oldWidth = width();
setSize(7, 7);
- QGraphicsItem *onPoint = 0;
QList<QGraphicsItem *> l = collidingItems();
for (QList<QGraphicsItem *>::Iterator it = l.begin(); it != l.end(); ++it)
+ {
if ((*it)->data(0) == data(0))
- onPoint = (*it);
+ {
+ setPos((*it)->pos());
+ break;
+ }
+ }
- if (onPoint)
- setPos(onPoint->x(), onPoint->y());
-
setSize(oldWidth, oldWidth);
}
@@ -1730,11 +1724,11 @@
if (start)
{
- wall->setLine(x(), y(), wall->endPoint().x() + wall->x(), wall->endPoint().y() + \
wall->y()); + wall->setLine(QLineF(pos(), wall->endPointF() + wall->pos()));
}
else
{
- wall->setLine(wall->startPointF().x() + wall->x(), wall->startPointF().y() + \
wall->y(), x(), y()); + wall->setLine(QLineF(wall->startPointF() + wall->pos(), \
pos())); }
wall->setPos(0, 0);
wall->moveBy(0, 0);
@@ -1847,10 +1841,9 @@
/////////////////////////
-Wall::Wall( QGraphicsItem *parent, bool antialiasing)
-: AntiAliasedLine(parent)
+Wall::Wall(QGraphicsItem *parent, bool antialiased)
+: HintedLineItem(antialiased, parent)
{
- basePenWidth = 3;
this->antialiasing = antialiasing;
setData(0, Rtti_Wall);
editing = false;
@@ -1868,7 +1861,7 @@
endItem = new WallPoint(false, this, parent);
startItem->setVisible(true);
endItem->setVisible(true);
- setPen(QPen(Qt::darkRed, basePenWidth));
+ setPen(QPen(Qt::darkRed, 3));
setLine(-15, 10, 15, -5);
@@ -1877,46 +1870,13 @@
editModeChanged(false);
}
-void Wall::resize(double resizeFactor)
-{
- this->resizeFactor = resizeFactor;
- this->startItem->resizeFactor = resizeFactor;
- this->endItem->resizeFactor = resizeFactor;
-
- QGraphicsLineItem::setLine(startItem->baseX*resizeFactor, \
startItem->baseY*resizeFactor, endItem->baseX*resizeFactor, \
endItem->baseY*resizeFactor);
- startItem->dontMove();
- endItem->dontMove();
- startItem->setPos(startPointF().x() + x(), startPointF().y() + y());
- endItem->setPos(endPointF().x() + x(), endPointF().y() + y());
-
- QPen newPen = pen();
- newPen.setWidthF(basePenWidth*resizeFactor);
- setPen(newPen);
-}
-
-void Wall::setLine(const QLineF & line)
-{
- setLine(line.x1(), line.y1(), line.x2(), line.y2());
-}
-
-void Wall::setLine(qreal x1, qreal y1, qreal x2, qreal y2)
-{
- startItem->baseX = x1;
- startItem->baseY = y1;
-
- endItem->baseX = x2;
- endItem->baseY = y2;
-
- QGraphicsLineItem::setLine(x1, y1, x2, y2);
-}
-
void Wall::selectedItem(QGraphicsItem *item)
{
if (item->data(0) == Rtti_WallPoint)
{
WallPoint *wallPoint = dynamic_cast<WallPoint *>(item);
if (wallPoint) {
- setLine(startPointF().x(), startPointF().y(), wallPoint->x() - x(), \
wallPoint->y() - y()); + setLine(QLineF(startPointF(), wallPoint->pos() - pos()));
}
}
}
@@ -1957,9 +1917,9 @@
QGraphicsLineItem::setPen(p);
if (startItem)
- startItem->setBrush(QBrush(p.color()));
+ startItem->setBrush(p.brush());
if (endItem)
- endItem->setBrush(QBrush(p.color()));
+ endItem->setBrush(p.brush());
}
void Wall::aboutToDie()
@@ -1991,15 +1951,16 @@
void Wall::setPos(double x, double y)
{
- QGraphicsLineItem::setPos(x, y);
+ const QPointF pos(x ,y);
+ QGraphicsLineItem::setPos(pos);
if (!startItem || !endItem)
return;
startItem->dontMove();
endItem->dontMove();
- startItem->setPos(startPointF().x() + x, startPointF().y() + y);
- endItem->setPos(endPointF().x() + x, endPointF().y() + y);
+ startItem->setPos(startPointF() + pos);
+ endItem->setPos(endPointF() + pos);
}
void Wall::editModeChanged(bool changed)
@@ -2079,17 +2040,17 @@
QPoint end(endPoint());
end = cfgGroup->readEntry("endPoint", end);
- setLine(start.x(), start.y(), end.x(), end.y());
+ setLine(QLineF(start, end));
moveBy(0, 0);
- startItem->setPos(start.x(), start.y());
- endItem->setPos(end.x(), end.y());
+ startItem->setPos(start);
+ endItem->setPos(end);
}
void Wall::save(KConfigGroup *cfgGroup)
{
- cfgGroup->writeEntry("startPoint", QPoint((int)startItem->x(), \
(int)startItem->y()));
- cfgGroup->writeEntry("endPoint", QPoint((int)endItem->x(), (int)endItem->y()));
+ cfgGroup->writeEntry("startPoint", startItem->pos().toPoint());
+ cfgGroup->writeEntry("endPoint", endItem->pos().toPoint());
}
void Wall::doAdvance()
@@ -2942,6 +2903,7 @@
void KolfGame::resizeAllItems(double resizeFactor, bool resizeBorderWalls)
{
+ Q_UNUSED(resizeBorderWalls);
//resizeFactor is the number to multiply default sizes and positions by to get \
their resized value (i.e. if it is 1 then use default size, if it is >1 then \
everything needs to be bigger, and if it is <1 then everything needs to be smaller)
//stroke circle resize
@@ -2950,14 +2912,7 @@
//putter resize
putter->setPos((*curPlayer).ball()->x(), (*curPlayer).ball()->y());
putter->resize(resizeFactor);
-
- //border wall resize
- QList<Wall *>::const_iterator wall;
- if(resizeBorderWalls) {
- for (wall = borderWalls.constBegin(); wall != borderWalls.constEnd(); ++wall)
- (*wall)->resize(resizeFactor);
}
-}
void KolfGame::puttRelease()
{
--- trunk/KDE/kdegames/kolf/game.h #1191684:1191685
@@ -115,14 +115,17 @@
typedef QList<Player> PlayerList;
-class AntiAliasedLine : public QGraphicsLineItem
+class HintedLineItem : public QGraphicsLineItem
{
public:
- AntiAliasedLine(QGraphicsItem *parent);
- void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget *widget);
+ HintedLineItem(bool antialiased, QGraphicsItem *parent);
+
+ virtual void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget \
*widget); +private:
+ bool m_antialiased;
};
-class Arrow : public AntiAliasedLine
+class Arrow : public HintedLineItem
{
public:
Arrow(QGraphicsItem *parent);
@@ -316,7 +319,7 @@
BlackHole *blackHole;
};
-class BlackHoleExit : public AntiAliasedLine, public CanvasItem
+class BlackHoleExit : public HintedLineItem, public CanvasItem
{
public:
BlackHoleExit(BlackHole *blackHole, QGraphicsItem *parent);
@@ -427,19 +430,15 @@
};
class WallPoint;
-class Wall : public AntiAliasedLine, public CanvasItem
+class Wall : public HintedLineItem, public CanvasItem
{
public:
- Wall( QGraphicsItem *parent, bool antialiasing=1);
+ Wall(QGraphicsItem *parent, bool antialiasing = true);
virtual void aboutToDie();
double dampening;
void setAlwaysShow(bool yes);
virtual void setZValue(double newz);
- void resize(double resizeFactor);
- void setBasePenWidth(double basePenWidth) { this->basePenWidth=basePenWidth; }
- void setLine(const QLineF & line);
- void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
virtual void setPen(QPen p);
virtual bool collision(Ball *ball, long int id);
virtual void save(KConfigGroup *cfgGroup);
@@ -458,24 +457,18 @@
virtual void setGame(KolfGame *game);
virtual void setVisible(bool);
- QPointF startPointF() const { return QPointF(line().x1(), line().y1() ); }
- QPointF endPointF() const { return QPointF(line().x2(), line().y2() ); }
- QPoint startPoint() const { return QPoint((int)line().x1(), (int)line().y1() ); }
- QPoint endPoint() const { return QPoint((int)line().x2(), (int)line().y2() ); }
+ QPointF startPointF() const { return line().p1(); }
+ QPointF endPointF() const { return line().p2(); }
+ QPoint startPoint() const { return line().p1().toPoint(); }
+ QPoint endPoint() const { return line().p2().toPoint(); }
void doAdvance();
-
protected:
WallPoint *startItem;
WallPoint *endItem;
bool editing;
private:
- /*
- * base numbers are the size or position when no resizing has taken place (i.e. the \
defaults)
- */
- double resizeFactor;
- double basePenWidth;
bool antialiasing;
long int lastId;
@@ -501,9 +494,6 @@
double height() { return rect().height(); }
Wall *parentWall() { return wall; }
-
- double baseX, baseY, resizeFactor;
-
protected:
Wall *wall;
bool editing;
@@ -518,7 +508,7 @@
friend class Wall;
};
-class Putter : public AntiAliasedLine, public CanvasItem
+class Putter : public HintedLineItem, public CanvasItem
{
public:
Putter(QGraphicsItem* parent);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic