From 83c60a1012f2db6c21c5779f7e11b2f3e479df85 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Tue, 3 Aug 2010 22:29:26 +0000 Subject: 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 --- utils/themeeditor/graphics/rbalbumart.cpp | 13 ++++-- utils/themeeditor/graphics/rbalbumart.h | 7 ++- utils/themeeditor/graphics/rbimage.cpp | 11 ++++- utils/themeeditor/graphics/rbimage.h | 7 ++- utils/themeeditor/graphics/rbmovable.cpp | 71 +++++++++++++++++++++++++++++++ utils/themeeditor/graphics/rbmovable.h | 53 +++++++++++++++++++++++ utils/themeeditor/graphics/rbscreen.h | 1 - utils/themeeditor/graphics/rbviewport.cpp | 21 ++------- utils/themeeditor/graphics/rbviewport.h | 5 ++- utils/themeeditor/themeeditor.pro | 6 ++- 10 files changed, 166 insertions(+), 29 deletions(-) create mode 100644 utils/themeeditor/graphics/rbmovable.cpp create mode 100644 utils/themeeditor/graphics/rbmovable.h diff --git a/utils/themeeditor/graphics/rbalbumart.cpp b/utils/themeeditor/graphics/rbalbumart.cpp index bd3a8791fb..1dbe2855f8 100644 --- a/utils/themeeditor/graphics/rbalbumart.cpp +++ b/utils/themeeditor/graphics/rbalbumart.cpp @@ -22,17 +22,17 @@ #include "rbalbumart.h" #include -#include RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth, int maxHeight, int artWidth, int artHeight, char hAlign, char vAlign) - : QGraphicsItem(parent), size(x, y, maxWidth, - maxHeight), + : RBMovable(parent), size(0, 0, maxWidth, + maxHeight), artWidth(artWidth), artHeight(artHeight), hAlign(hAlign), vAlign(vAlign), texture(":/render/albumart.png") { + setPos(x, y); hide(); } @@ -92,4 +92,11 @@ void RBAlbumArt::paint(QPainter *painter, } painter->fillRect(drawArea, texture); + + RBMovable::paint(painter, option, widget); +} + +void RBAlbumArt::saveGeometry() +{ + } diff --git a/utils/themeeditor/graphics/rbalbumart.h b/utils/themeeditor/graphics/rbalbumart.h index f32c5f9bb1..8baf7a2198 100644 --- a/utils/themeeditor/graphics/rbalbumart.h +++ b/utils/themeeditor/graphics/rbalbumart.h @@ -24,7 +24,9 @@ #include -class RBAlbumArt : public QGraphicsItem +#include "rbmovable.h" + +class RBAlbumArt : public RBMovable { public: RBAlbumArt(QGraphicsItem* parent, int x, int y, int maxWidth, int maxHeight, @@ -37,6 +39,9 @@ public: void position(){ this->setPos(size.x(), size.y()); } +protected: + void saveGeometry(); + private: QRectF size; int artWidth; diff --git a/utils/themeeditor/graphics/rbimage.cpp b/utils/themeeditor/graphics/rbimage.cpp index ce92d2fcde..954983eae2 100644 --- a/utils/themeeditor/graphics/rbimage.cpp +++ b/utils/themeeditor/graphics/rbimage.cpp @@ -26,7 +26,7 @@ #include "rbimage.h" RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent) - : QGraphicsItem(parent), tiles(tiles), currentTile(0) + : RBMovable(parent), tiles(tiles), currentTile(0) { if(QFile::exists(file)) { @@ -56,7 +56,7 @@ RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent) } RBImage::RBImage(const RBImage &other, QGraphicsItem* parent) - : QGraphicsItem(parent), tiles(other.tiles), currentTile(other.currentTile) + : RBMovable(parent), tiles(other.tiles), currentTile(other.currentTile) { if(other.image) image = new QPixmap(*(other.image)); @@ -86,4 +86,11 @@ void RBImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->drawPixmap(size, *image, QRect(0, currentTile * image->height() / tiles, image->width(), image->height() / tiles)); + + RBMovable::paint(painter, option, widget); +} + +void RBImage::saveGeometry() +{ + } diff --git a/utils/themeeditor/graphics/rbimage.h b/utils/themeeditor/graphics/rbimage.h index abfe8eb052..f9562b82e9 100644 --- a/utils/themeeditor/graphics/rbimage.h +++ b/utils/themeeditor/graphics/rbimage.h @@ -25,7 +25,9 @@ #include #include -class RBImage: public QGraphicsItem +#include "rbmovable.h" + +class RBImage: public RBMovable { public: RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0); @@ -44,6 +46,9 @@ public: } +protected: + void saveGeometry(); + private: QPixmap* image; int tiles; 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 @@ +/*************************************************************************** + * __________ __ ___. + * 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 +#include + +#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); +} + diff --git a/utils/themeeditor/graphics/rbmovable.h b/utils/themeeditor/graphics/rbmovable.h new file mode 100644 index 0000000000..e8ef69b5bd --- /dev/null +++ b/utils/themeeditor/graphics/rbmovable.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +#ifndef RBMOVABLE_H +#define RBMOVABLE_H + +#include + +/* + * This is a base class for scene elements that can be moved around and + * resized. It adds some basic functionality for showing a border around + * selected items and ensuring that they don't get moved out of their parent's + * bounding rect, as well as resizing them. It includes one pure virtual + * function, saveGeometry(), that is responsible for syncing the changed + * geometry back to the parse tree to be code gen'd into the file. + */ + +class RBMovable : public QGraphicsItem +{ +public: + RBMovable(QGraphicsItem* parent); + ~RBMovable(); + + virtual void paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, QWidget *widget); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, + const QVariant &value); + /* Responsible for updating the parse tree */ + virtual void saveGeometry() = 0; + +}; + +#endif // RBMOVABLE_H diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h index 5bb8ab1602..c2417aa1b4 100644 --- a/utils/themeeditor/graphics/rbscreen.h +++ b/utils/themeeditor/graphics/rbscreen.h @@ -81,7 +81,6 @@ public: if(albumArt) { albumArt->setParentItem(view); - albumArt->position(); albumArt->show(); } } diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index f7b1bc4ca2..fe17ebbeef 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp @@ -39,7 +39,7 @@ const double RBViewport::scrollRate = 30; RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) - : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), + : RBMovable(info.screen()), foreground(info.screen()->foreground()), background(info.screen()->background()), textOffset(0,0), screen(info.screen()), textAlign(Left), showStatusBar(false), statusBarTexture(":/render/statusbar.png"), @@ -178,6 +178,8 @@ void RBViewport::paint(QPainter *painter, if(showStatusBar) painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture); + + RBMovable::paint(painter, option, widget); } void RBViewport::newLine() @@ -297,24 +299,9 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start, } } -QVariant RBViewport::itemChange(GraphicsItemChange change, - const QVariant &value) +void RBViewport::saveGeometry() { - 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())); - - return pos; - } - return QGraphicsItem::itemChange(change, value); } void RBViewport::alignLeft() diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h index ea47225f09..b9bafe47d1 100644 --- a/utils/themeeditor/graphics/rbviewport.h +++ b/utils/themeeditor/graphics/rbviewport.h @@ -24,13 +24,14 @@ #include "skin_parser.h" #include "rbfont.h" +#include "rbmovable.h" class RBScreen; class RBRenderInfo; #include -class RBViewport : public QGraphicsItem +class RBViewport : public RBMovable { public: enum Alignment @@ -78,7 +79,7 @@ public: skin_element* noId3); protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void saveGeometry(); private: diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index bf2be3abd8..da5fe4156b 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -106,7 +106,8 @@ HEADERS += models/parsetreemodel.h \ qtfindreplacedialog/finddialog.h \ gui/projectexporter.h \ gui/targetdownloader.h \ - gui/syntaxcompleter.h + gui/syntaxcompleter.h \ + graphics/rbmovable.h SOURCES += main.cpp \ models/parsetreemodel.cpp \ models/parsetreenode.cpp \ @@ -147,7 +148,8 @@ SOURCES += main.cpp \ qtfindreplacedialog/finddialog.cpp \ gui/projectexporter.cpp \ gui/targetdownloader.cpp \ - gui/syntaxcompleter.cpp + gui/syntaxcompleter.cpp \ + graphics/rbmovable.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ -- cgit v1.2.3