diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-08-03 22:29:26 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-08-03 22:29:26 +0000 |
| commit | 83c60a1012f2db6c21c5779f7e11b2f3e479df85 (patch) | |
| tree | c4ceb451457fe34cd0df156d0b9a6ecc593496ac /utils/themeeditor/graphics/rbmovable.cpp | |
| parent | 851be21f671feb0bf41e1dcaaced4d7e2e5cf72c (diff) | |
| download | rockbox-83c60a1012f2db6c21c5779f7e11b2f3e479df85.zip rockbox-83c60a1012f2db6c21c5779f7e11b2f3e479df85.tar.gz rockbox-83c60a1012f2db6c21c5779f7e11b2f3e479df85.tar.bz2 rockbox-83c60a1012f2db6c21c5779f7e11b2f3e479df85.tar.xz | |
Theme Editor: Created the RBMovable abstract class for screen elements that can be moved around, began implementing it and making images, viewports, and album art children of it
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27685 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/graphics/rbmovable.cpp')
| -rw-r--r-- | utils/themeeditor/graphics/rbmovable.cpp | 71 |
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 0000000..11b3a68 --- /dev/null +++ b/utils/themeeditor/graphics/rbmovable.cpp @@ -0,0 +1,71 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Robert Bieber + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include <QPainter> +#include <QDebug> + +#include "rbmovable.h" + +RBMovable::RBMovable(QGraphicsItem* parent) + : QGraphicsItem(parent) +{ + setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges); +} + +RBMovable::~RBMovable() +{ +} + +void RBMovable::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) +{ + if(isSelected()) + { + painter->setBrush(Qt::NoBrush); + QPen pen; + pen.setStyle(Qt::DashLine); + pen.setColor(Qt::green); + painter->setPen(pen); + painter->drawRect(boundingRect()); + } +} + +QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if(change == ItemPositionChange) + { + QPointF pos = value.toPointF(); + QRectF bound = parentItem()->boundingRect(); + + pos.setX(qMax(0., pos.x())); + pos.setX(qMin(pos.x(), bound.width() - boundingRect().width())); + + pos.setY(qMax(0., pos.y())); + pos.setY(qMin(pos.y(), bound.height() - boundingRect().height())); + + saveGeometry(); + + return pos; + } + + return QGraphicsItem::itemChange(change, value); +} + |