summaryrefslogtreecommitdiff
path: root/utils/themeeditor/graphics/rbmovable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/graphics/rbmovable.cpp')
-rw-r--r--utils/themeeditor/graphics/rbmovable.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/utils/themeeditor/graphics/rbmovable.cpp b/utils/themeeditor/graphics/rbmovable.cpp
new file mode 100644
index 0000000000..11b3a6812f
--- /dev/null
+++ b/utils/themeeditor/graphics/rbmovable.cpp
@@ -0,0 +1,71 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Robert Bieber
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QPainter>
23#include <QDebug>
24
25#include "rbmovable.h"
26
27RBMovable::RBMovable(QGraphicsItem* parent)
28 : QGraphicsItem(parent)
29{
30 setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);
31}
32
33RBMovable::~RBMovable()
34{
35}
36
37void RBMovable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
38 QWidget *widget)
39{
40 if(isSelected())
41 {
42 painter->setBrush(Qt::NoBrush);
43 QPen pen;
44 pen.setStyle(Qt::DashLine);
45 pen.setColor(Qt::green);
46 painter->setPen(pen);
47 painter->drawRect(boundingRect());
48 }
49}
50
51QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
52{
53 if(change == ItemPositionChange)
54 {
55 QPointF pos = value.toPointF();
56 QRectF bound = parentItem()->boundingRect();
57
58 pos.setX(qMax(0., pos.x()));
59 pos.setX(qMin(pos.x(), bound.width() - boundingRect().width()));
60
61 pos.setY(qMax(0., pos.y()));
62 pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
63
64 saveGeometry();
65
66 return pos;
67 }
68
69 return QGraphicsItem::itemChange(change, value);
70}
71