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
This commit is contained in:
parent
851be21f67
commit
83c60a1012
10 changed files with 166 additions and 29 deletions
|
@ -22,17 +22,17 @@
|
|||
#include "rbalbumart.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
#include <QPixmap>
|
||||
#include <QGraphicsItem>
|
||||
|
||||
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;
|
||||
|
|
71
utils/themeeditor/graphics/rbmovable.cpp
Normal file
71
utils/themeeditor/graphics/rbmovable.cpp
Normal file
|
@ -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);
|
||||
}
|
||||
|
53
utils/themeeditor/graphics/rbmovable.h
Normal file
53
utils/themeeditor/graphics/rbmovable.h
Normal file
|
@ -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 <QGraphicsItem>
|
||||
|
||||
/*
|
||||
* 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
|
|
@ -81,7 +81,6 @@ public:
|
|||
if(albumArt)
|
||||
{
|
||||
albumArt->setParentItem(view);
|
||||
albumArt->position();
|
||||
albumArt->show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -24,13 +24,14 @@
|
|||
|
||||
#include "skin_parser.h"
|
||||
#include "rbfont.h"
|
||||
#include "rbmovable.h"
|
||||
|
||||
class RBScreen;
|
||||
class RBRenderInfo;
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
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:
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in a new issue