summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-08-05 22:31:46 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-08-05 22:31:46 +0000
commit10b9e3b024c3a1f3796b6c3f764a5dc3d19b84cb (patch)
tree8a7564f61395200b46575fb084edf647f7c84a15
parent4b49ef2adea6f478c157f398777a7708a45932df (diff)
downloadrockbox-10b9e3b024c3a1f3796b6c3f764a5dc3d19b84cb.tar.gz
rockbox-10b9e3b024c3a1f3796b6c3f764a5dc3d19b84cb.zip
Theme Editor: Implemented resizing in RBMovable subclasses. Implementation is still somewhat crash-prone, but mostly works at this point
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27729 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/themeeditor/graphics/rbalbumart.cpp12
-rw-r--r--utils/themeeditor/graphics/rbalbumart.h2
-rw-r--r--utils/themeeditor/graphics/rbimage.cpp5
-rw-r--r--utils/themeeditor/graphics/rbimage.h3
-rw-r--r--utils/themeeditor/graphics/rbmovable.cpp223
-rw-r--r--utils/themeeditor/graphics/rbmovable.h28
-rw-r--r--utils/themeeditor/graphics/rbprogressbar.cpp5
-rw-r--r--utils/themeeditor/graphics/rbprogressbar.h2
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp5
-rw-r--r--utils/themeeditor/graphics/rbviewport.h2
10 files changed, 249 insertions, 38 deletions
diff --git a/utils/themeeditor/graphics/rbalbumart.cpp b/utils/themeeditor/graphics/rbalbumart.cpp
index 40c6f05605..bb9bd12369 100644
--- a/utils/themeeditor/graphics/rbalbumart.cpp
+++ b/utils/themeeditor/graphics/rbalbumart.cpp
@@ -28,23 +28,17 @@
28RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth, 28RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
29 int maxHeight, int artWidth, int artHeight, 29 int maxHeight, int artWidth, int artHeight,
30 ParseTreeNode* node, char hAlign, char vAlign) 30 ParseTreeNode* node, char hAlign, char vAlign)
31 : RBMovable(parent), size(0, 0, maxWidth, 31 : RBMovable(parent),artWidth(artWidth),
32 maxHeight), 32 artHeight(artHeight), hAlign(hAlign), vAlign(vAlign),
33 artWidth(artWidth), artHeight(artHeight),
34 hAlign(hAlign), vAlign(vAlign),
35 texture(":/render/albumart.png"), node(node) 33 texture(":/render/albumart.png"), node(node)
36{ 34{
35 size = QRectF(0, 0, maxWidth, maxHeight);
37 setFlag(ItemSendsGeometryChanges, false); 36 setFlag(ItemSendsGeometryChanges, false);
38 37
39 setPos(x, y); 38 setPos(x, y);
40 hide(); 39 hide();
41} 40}
42 41
43QRectF RBAlbumArt::boundingRect() const
44{
45 return size;
46}
47
48void RBAlbumArt::paint(QPainter *painter, 42void RBAlbumArt::paint(QPainter *painter,
49 const QStyleOptionGraphicsItem *option, QWidget *widget) 43 const QStyleOptionGraphicsItem *option, QWidget *widget)
50{ 44{
diff --git a/utils/themeeditor/graphics/rbalbumart.h b/utils/themeeditor/graphics/rbalbumart.h
index 2c8090f9c3..d862f25659 100644
--- a/utils/themeeditor/graphics/rbalbumart.h
+++ b/utils/themeeditor/graphics/rbalbumart.h
@@ -35,7 +35,6 @@ public:
35 int artWidth, int artHeight, ParseTreeNode* node, 35 int artWidth, int artHeight, ParseTreeNode* node,
36 char hAlign = 'c', char vAlign = 'c'); 36 char hAlign = 'c', char vAlign = 'c');
37 37
38 QRectF boundingRect() const;
39 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 38 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
40 QWidget *widget); 39 QWidget *widget);
41 40
@@ -48,7 +47,6 @@ protected:
48 void saveGeometry(); 47 void saveGeometry();
49 48
50private: 49private:
51 QRectF size;
52 int artWidth; 50 int artWidth;
53 int artHeight; 51 int artHeight;
54 char hAlign; 52 char hAlign;
diff --git a/utils/themeeditor/graphics/rbimage.cpp b/utils/themeeditor/graphics/rbimage.cpp
index 83a564c465..9d82fb110d 100644
--- a/utils/themeeditor/graphics/rbimage.cpp
+++ b/utils/themeeditor/graphics/rbimage.cpp
@@ -79,11 +79,6 @@ RBImage::~RBImage()
79 delete image; 79 delete image;
80} 80}
81 81
82QRectF RBImage::boundingRect() const
83{
84 return size;
85}
86
87void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 82void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
88 QWidget *widget) 83 QWidget *widget)
89{ 84{
diff --git a/utils/themeeditor/graphics/rbimage.h b/utils/themeeditor/graphics/rbimage.h
index ba028de7e2..f89213bb33 100644
--- a/utils/themeeditor/graphics/rbimage.h
+++ b/utils/themeeditor/graphics/rbimage.h
@@ -37,7 +37,6 @@ public:
37 RBImage(const RBImage& other, QGraphicsItem* parent); 37 RBImage(const RBImage& other, QGraphicsItem* parent);
38 virtual ~RBImage(); 38 virtual ~RBImage();
39 39
40 QRectF boundingRect() const;
41 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 40 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
42 QWidget *widget); 41 QWidget *widget);
43 42
@@ -62,8 +61,6 @@ private:
62 int tiles; 61 int tiles;
63 int currentTile; 62 int currentTile;
64 63
65 QRectF size;
66
67 ParseTreeNode* node; 64 ParseTreeNode* node;
68 65
69}; 66};
diff --git a/utils/themeeditor/graphics/rbmovable.cpp b/utils/themeeditor/graphics/rbmovable.cpp
index 3eca8bd18c..5d493c61e7 100644
--- a/utils/themeeditor/graphics/rbmovable.cpp
+++ b/utils/themeeditor/graphics/rbmovable.cpp
@@ -19,13 +19,16 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include <QGraphicsSceneMouseEvent>
22#include <QPainter> 23#include <QPainter>
23#include <QDebug> 24#include <QDebug>
24 25
25#include "rbmovable.h" 26#include "rbmovable.h"
26 27
28const double RBMovable::handleSize = 7;
29
27RBMovable::RBMovable(QGraphicsItem* parent) 30RBMovable::RBMovable(QGraphicsItem* parent)
28 : QGraphicsItem(parent), geomChanged(false) 31 : QGraphicsItem(parent), dragMode(None)
29{ 32{
30 setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges); 33 setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);
31} 34}
@@ -45,6 +48,11 @@ void RBMovable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
45 pen.setColor(Qt::green); 48 pen.setColor(Qt::green);
46 painter->setPen(pen); 49 painter->setPen(pen);
47 painter->drawRect(boundingRect()); 50 painter->drawRect(boundingRect());
51
52 painter->fillRect(topLeftHandle(), Qt::green);
53 painter->fillRect(topRightHandle(), Qt::green);
54 painter->fillRect(bottomLeftHandle(), Qt::green);
55 painter->fillRect(bottomRightHandle(), Qt::green);
48 } 56 }
49} 57}
50 58
@@ -61,7 +69,6 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
61 pos.setY(qMax(0., pos.y())); 69 pos.setY(qMax(0., pos.y()));
62 pos.setY(qMin(pos.y(), bound.height() - boundingRect().height())); 70 pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
63 71
64 geomChanged = true;
65 72
66 return pos; 73 return pos;
67 } 74 }
@@ -71,15 +78,223 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
71 78
72void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event) 79void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event)
73{ 80{
74 QGraphicsItem::mousePressEvent(event); 81 if(!isSelected())
82 {
83 QGraphicsItem::mousePressEvent(event);
84 return;
85 }
86
87 if(topLeftHandle().contains(event->pos()))
88 {
89 dragStartClick = event->pos() + pos();
90 dragStartPos = pos();
91 dragStartSize = boundingRect();
92
93 dWidthMin = -1. * pos().x();
94 dWidthMax = boundingRect().width() - childrenBoundingRect().right();
95
96 dHeightMin = -1. * pos().y();
97 dHeightMax = boundingRect().height() - childrenBoundingRect().bottom();
98
99 dragMode = TopLeft;
100 }
101 else if(topRightHandle().contains(event->pos()))
102 {
103 dragStartClick = event->pos() + pos();
104 dragStartPos = pos();
105 dragStartSize = boundingRect();
106
107 dWidthMin = childrenBoundingRect().width() - boundingRect().width();
108 dWidthMin = qMax(dWidthMin, -1. * size.width());
109 dWidthMax = parentItem()->boundingRect().width()
110 - boundingRect().width() - pos().x();
111
112 dHeightMin = -1. * pos().y();
113 dHeightMax = boundingRect().height() - childrenBoundingRect().bottom();
114 dHeightMax = qMin(dHeightMax, boundingRect().height());
115
116 dragMode = TopRight;
117 }
118 else if(bottomLeftHandle().contains(event->pos()))
119 {
120 dragStartClick = event->pos() + pos();
121 dragStartPos = pos();
122 dragStartSize = boundingRect();
123
124 dWidthMin = -1. * pos().x();
125 dWidthMax = boundingRect().width() - childrenBoundingRect().right();
126 dWidthMax = qMin(dWidthMax, size.width());
127
128 dHeightMin = -1. * (boundingRect().height()
129 - childrenBoundingRect().bottom());
130 dHeightMin = qMax(dHeightMin, -1. * boundingRect().height());
131
132 dragMode = BottomLeft;
133 }
134 else if(bottomRightHandle().contains(event->pos()))
135 {
136 dragStartClick = event->pos() + pos();
137 dragStartPos = pos();
138 dragStartSize = boundingRect();
139
140 dWidthMin = -1. * (boundingRect().width()
141 - childrenBoundingRect().right());
142 dWidthMin = qMax(dWidthMin, -1. * boundingRect().width());
143 dWidthMax = parentItem()->boundingRect().width() -
144 boundingRect().width() - pos().x();
145
146 dHeightMin = -1. * (boundingRect().height()
147 - childrenBoundingRect().bottom());
148 dHeightMin = qMax(dHeightMin, -1. * boundingRect().height());
149 dHeightMax = parentItem()->boundingRect().height() -
150 boundingRect().height() - pos().y();
151
152 dragMode = BottomRight;
153 }
154 else
155 {
156 QGraphicsItem::mousePressEvent(event);
157 }
158}
159
160void RBMovable::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
161{
162
163 QPointF absPos;
164 QPointF dPos;
165 QPointF dMouse;
166 switch(dragMode)
167 {
168 case None:
169 QGraphicsItem::mouseMoveEvent(event);
170 break;
171
172 case TopLeft:
173 /* Dragging from the top left corner */
174 absPos = event->pos() + pos();
175 dMouse = absPos - dragStartClick;
176
177 dPos.setX(qMin(dMouse.x(), dWidthMax));
178 dPos.setX(qMax(dPos.x(), dWidthMin));
179
180 dPos.setY(qMin(dMouse.y(), dHeightMax));
181 dPos.setY(qMax(dPos.y(), dHeightMin));
182
183 prepareGeometryChange();
184
185 setPos(dragStartPos + dPos);
186
187 size.setWidth(dragStartSize.width() - dPos.x());
188 size.setHeight(dragStartSize.height() - dPos.y());
189
190 break;
191
192 case TopRight:
193 /* Dragging from the top right corner */
194 absPos = event->pos() + pos();
195 dMouse = absPos - dragStartClick;
196
197 dPos.setX(qMin(dMouse.x(), dWidthMax));
198 dPos.setX(qMax(dPos.x(), dWidthMin));
199
200 dPos.setY(qMin(dMouse.y(), dHeightMax));
201 dPos.setY(qMax(dPos.y(), dHeightMin));
202
203 prepareGeometryChange();
204
205 setPos(dragStartPos.x(), dragStartPos.y() + dPos.y());
206
207 size.setWidth(dragStartSize.width() + dPos.x());
208 size.setHeight(dragStartSize.height() - dPos.y());
209
210 break;
211
212 case BottomLeft:
213 /* Dragging from the bottom left corner */
214 absPos = event->pos() + pos();
215 dMouse = absPos - dragStartClick;
216
217 dPos.setX(qMin(dMouse.x(), dWidthMax));
218 dPos.setX(qMax(dPos.x(), dWidthMin));
219
220 dPos.setY(qMin(dMouse.y(), dHeightMax));
221 dPos.setY(qMax(dPos.y(), dHeightMin));
222
223 prepareGeometryChange();
224 setPos(dragStartPos.x() + dPos.x(), dragStartPos.y());
225 size.setHeight(dragStartSize.height() + dPos.y());
226 size.setWidth(dragStartSize.width() - dPos.x());
227
228 break;
229
230 case BottomRight:
231 /* Dragging from the bottom right corner */
232 absPos = event->pos() + pos();
233 dMouse = absPos - dragStartClick;
234
235 dPos.setX(qMin(dMouse.x(), dWidthMax));
236 dPos.setX(qMax(dPos.x(), dWidthMin));
237
238 dPos.setY(qMin(dMouse.y(), dHeightMax));
239 dPos.setY(qMax(dPos.y(), dHeightMin));
240
241 prepareGeometryChange();
242
243 size.setWidth(dragStartSize.width() + dPos.x());
244 size.setHeight(dragStartSize.height() + dPos.y());
245
246 break;
247 }
75} 248}
76 249
77void RBMovable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) 250void RBMovable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
78{ 251{
79 QGraphicsItem::mouseReleaseEvent(event); 252 QGraphicsItem::mouseReleaseEvent(event);
253
254 dragMode = None;
255
80 if(isSelected()) 256 if(isSelected())
81 { 257 {
82 saveGeometry(); 258 saveGeometry();
83 geomChanged = false;
84 } 259 }
85} 260}
261
262QRectF RBMovable::topLeftHandle()
263{
264 QRectF bounds = boundingRect();
265 double width = qMin(bounds.width() / 2. - .5, handleSize);
266 double height = qMin(bounds.height() / 2. - .5, handleSize);
267 double size = qMin(width, height);
268
269 return QRectF(0, 0, size, size);
270}
271
272QRectF RBMovable::topRightHandle()
273{
274 QRectF bounds = boundingRect();
275 double width = qMin(bounds.width() / 2. - .5, handleSize);
276 double height = qMin(bounds.height() / 2. - .5, handleSize);
277 double size = qMin(width, height);
278
279 return QRectF(bounds.width() - size, 0, size, size);
280}
281
282QRectF RBMovable::bottomLeftHandle()
283{
284 QRectF bounds = boundingRect();
285 double width = qMin(bounds.width() / 2. - .5, handleSize);
286 double height = qMin(bounds.height() / 2. - .5, handleSize);
287 double size = qMin(width, height);
288
289 return QRectF(0, bounds.height() - size, size, size);
290}
291
292QRectF RBMovable::bottomRightHandle()
293{
294 QRectF bounds = boundingRect();
295 double width = qMin(bounds.width() / 2. - .5, handleSize);
296 double height = qMin(bounds.height() / 2. - .5, handleSize);
297 double size = qMin(width, height);
298
299 return QRectF(bounds.width() - size, bounds.height() - size, size, size);
300}
diff --git a/utils/themeeditor/graphics/rbmovable.h b/utils/themeeditor/graphics/rbmovable.h
index 5b6330228d..b4ade98f0c 100644
--- a/utils/themeeditor/graphics/rbmovable.h
+++ b/utils/themeeditor/graphics/rbmovable.h
@@ -42,15 +42,41 @@ public:
42 virtual void paint(QPainter *painter, 42 virtual void paint(QPainter *painter,
43 const QStyleOptionGraphicsItem *option, QWidget *widget); 43 const QStyleOptionGraphicsItem *option, QWidget *widget);
44 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); 44 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
45 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
45 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 46 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
46 47
48 virtual QRectF boundingRect() const{ return size; }
49
47protected: 50protected:
48 virtual QVariant itemChange(GraphicsItemChange change, 51 virtual QVariant itemChange(GraphicsItemChange change,
49 const QVariant &value); 52 const QVariant &value);
50 /* Responsible for updating the parse tree */ 53 /* Responsible for updating the parse tree */
51 virtual void saveGeometry() = 0; 54 virtual void saveGeometry() = 0;
52 55
53 bool geomChanged; 56 QRectF size;
57
58private:
59 static const double handleSize;
60
61 QRectF topLeftHandle();
62 QRectF topRightHandle();
63 QRectF bottomLeftHandle();
64 QRectF bottomRightHandle();
65
66 enum{
67 None,
68 TopLeft,
69 TopRight,
70 BottomLeft,
71 BottomRight
72 } dragMode;
73 QPointF dragStartPos;
74 QRectF dragStartSize;
75 QPointF dragStartClick;
76 double dHeightMin;
77 double dHeightMax;
78 double dWidthMin;
79 double dWidthMax;
54 80
55}; 81};
56 82
diff --git a/utils/themeeditor/graphics/rbprogressbar.cpp b/utils/themeeditor/graphics/rbprogressbar.cpp
index 15515f8a18..292318cf60 100644
--- a/utils/themeeditor/graphics/rbprogressbar.cpp
+++ b/utils/themeeditor/graphics/rbprogressbar.cpp
@@ -103,11 +103,6 @@ RBProgressBar::~RBProgressBar()
103 delete bitmap; 103 delete bitmap;
104} 104}
105 105
106QRectF RBProgressBar::boundingRect() const
107{
108 return size;
109}
110
111void RBProgressBar::paint(QPainter *painter, 106void RBProgressBar::paint(QPainter *painter,
112 const QStyleOptionGraphicsItem *option, 107 const QStyleOptionGraphicsItem *option,
113 QWidget *widget) 108 QWidget *widget)
diff --git a/utils/themeeditor/graphics/rbprogressbar.h b/utils/themeeditor/graphics/rbprogressbar.h
index 782d08e4f9..69686098ed 100644
--- a/utils/themeeditor/graphics/rbprogressbar.h
+++ b/utils/themeeditor/graphics/rbprogressbar.h
@@ -40,7 +40,6 @@ public:
40 ParseTreeNode* node, bool pv = 0); 40 ParseTreeNode* node, bool pv = 0);
41 virtual ~RBProgressBar(); 41 virtual ~RBProgressBar();
42 42
43 QRectF boundingRect() const;
44 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 43 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
45 QWidget *widget); 44 QWidget *widget);
46 45
@@ -50,7 +49,6 @@ protected:
50private: 49private:
51 QPixmap* bitmap; 50 QPixmap* bitmap;
52 QColor color; 51 QColor color;
53 QRectF size;
54 QRectF renderSize; 52 QRectF renderSize;
55 53
56 ParseTreeNode* node; 54 ParseTreeNode* node;
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index 274edd67fd..015ed729d1 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -161,11 +161,6 @@ QPainterPath RBViewport::shape() const
161 return retval; 161 return retval;
162} 162}
163 163
164QRectF RBViewport::boundingRect() const
165{
166 return size;
167}
168
169void RBViewport::paint(QPainter *painter, 164void RBViewport::paint(QPainter *painter,
170 const QStyleOptionGraphicsItem *option, QWidget *widget) 165 const QStyleOptionGraphicsItem *option, QWidget *widget)
171{ 166{
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index 691133beeb..9bbceb4065 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -51,7 +51,6 @@ public:
51 virtual ~RBViewport(); 51 virtual ~RBViewport();
52 52
53 QPainterPath shape() const; 53 QPainterPath shape() const;
54 QRectF boundingRect() const;
55 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
56 QWidget *widget); 55 QWidget *widget);
57 56
@@ -91,7 +90,6 @@ private:
91 void alignCenter(); 90 void alignCenter();
92 void alignRight(); 91 void alignRight();
93 92
94 QRectF size;
95 RBFont* font; 93 RBFont* font;
96 QColor foreground; 94 QColor foreground;
97 QColor background; 95 QColor background;