2 Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 enum GradientType
{ Vertical
, Horizontal
, Diagonal
, CrossDiagonal
, Elliptic
};
28 class SlopeConfig
: public Config
33 SlopeConfig(Slope
*slope
, QWidget
*parent
);
36 void setGradient(const QString
&text
);
37 void setReversed(bool);
38 void setStuckOnGround(bool);
39 void gradeChanged(double);
45 class Slope
: public QGraphicsRectItem
, public CanvasItem
, public RectItem
48 Slope(const QRect
&rect
, QGraphicsItem
*parent
, QGraphicsScene
*scene
);
50 virtual void aboutToDie();
52 virtual void showInfo();
53 virtual void hideInfo();
54 void resize(double resizeFactor
);
55 void firstMove(int x
, int y
);
56 virtual void editModeChanged(bool changed
);
57 virtual bool canBeMovedByOthers() const { return !stuckOnGround
; }
58 virtual QList
<QGraphicsItem
*> moveableItems() const;
59 virtual Config
*config(QWidget
*parent
) { return new SlopeConfig(this, parent
); }
60 virtual void setSize(double width
, double height
);
61 virtual void newSize(double width
, double height
);
62 virtual void moveBy(double dx
, double dy
);
64 virtual void paint(QPainter
*painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0 );
65 virtual QPainterPath
shape () const;
67 void setGradient(const QString
&text
);
68 void setGrade(double grade
);
70 double curGrade() const { return grade
; }
71 GradientType
curType() const { return type
; }
72 void setColor(QColor color
) { this->color
= color
; updatePixmap(); }
73 void setReversed(bool reversed
) { this->reversed
= reversed
; updatePixmap(); }
74 bool isReversed() const { return reversed
; }
76 bool isStuckOnGround() const { return stuckOnGround
; }
77 void setStuckOnGround(bool yes
) { stuckOnGround
= yes
; updateZ(); }
79 virtual void load(KConfigGroup
*cfgGroup
);
80 virtual void save(KConfigGroup
*cfgGroup
);
82 virtual bool collision(Ball
*ball
, long int id
);
83 virtual bool terrainCollisions() const;
85 QMap
<GradientType
, QString
> gradientI18nKeys
;
86 QMap
<GradientType
, QString
> gradientKeys
;
88 virtual void updateZ(QGraphicsRectItem
*vStrut
= 0);
92 void updateBaseResizeInfo();
94 double width() const { return rect().width(); }
95 double height() const { return rect().height(); }
99 inline void setType(GradientType type
);
108 * base numbers are the size or position when no resizing has taken place (i.e. the defaults)
110 double baseX
, baseY
, baseWidth
, baseHeight
;
111 double baseArrowPenThickness
, arrowPenThickness
;
112 int baseFontPixelSize
;
117 QList
<Arrow
*> arrows
;
118 QGraphicsSimpleTextItem
*text
;
122 class SlopeObj
: public Object
125 SlopeObj() { m_name
= i18n("Slope"); m__name
= "slope"; }
126 virtual QGraphicsItem
*newObject(QGraphicsItem
* parent
, QGraphicsScene
*scene
) { return new Slope(QRect(0, 0, 40, 40), parent
, scene
); }