forked from len0rd/rockbox
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 "rbalbumart.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
|
RBAlbumArt::RBAlbumArt(QGraphicsItem *parent, int x, int y, int maxWidth,
|
||||||
int maxHeight, int artWidth, int artHeight, char hAlign,
|
int maxHeight, int artWidth, int artHeight, char hAlign,
|
||||||
char vAlign)
|
char vAlign)
|
||||||
: QGraphicsItem(parent), size(x, y, maxWidth,
|
: RBMovable(parent), size(0, 0, maxWidth,
|
||||||
maxHeight),
|
maxHeight),
|
||||||
artWidth(artWidth), artHeight(artHeight),
|
artWidth(artWidth), artHeight(artHeight),
|
||||||
hAlign(hAlign), vAlign(vAlign),
|
hAlign(hAlign), vAlign(vAlign),
|
||||||
texture(":/render/albumart.png")
|
texture(":/render/albumart.png")
|
||||||
{
|
{
|
||||||
|
setPos(x, y);
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,4 +92,11 @@ void RBAlbumArt::paint(QPainter *painter,
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->fillRect(drawArea, texture);
|
painter->fillRect(drawArea, texture);
|
||||||
|
|
||||||
|
RBMovable::paint(painter, option, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RBAlbumArt::saveGeometry()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class RBAlbumArt : public QGraphicsItem
|
#include "rbmovable.h"
|
||||||
|
|
||||||
|
class RBAlbumArt : public RBMovable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBAlbumArt(QGraphicsItem* parent, int x, int y, int maxWidth, int maxHeight,
|
RBAlbumArt(QGraphicsItem* parent, int x, int y, int maxWidth, int maxHeight,
|
||||||
|
@ -37,6 +39,9 @@ public:
|
||||||
|
|
||||||
void position(){ this->setPos(size.x(), size.y()); }
|
void position(){ this->setPos(size.x(), size.y()); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void saveGeometry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF size;
|
QRectF size;
|
||||||
int artWidth;
|
int artWidth;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "rbimage.h"
|
#include "rbimage.h"
|
||||||
|
|
||||||
RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent)
|
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))
|
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)
|
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)
|
if(other.image)
|
||||||
image = new QPixmap(*(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()
|
painter->drawPixmap(size, *image, QRect(0, currentTile * image->height()
|
||||||
/ tiles, image->width(),
|
/ tiles, image->width(),
|
||||||
image->height() / tiles));
|
image->height() / tiles));
|
||||||
|
|
||||||
|
RBMovable::paint(painter, option, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RBImage::saveGeometry()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class RBImage: public QGraphicsItem
|
#include "rbmovable.h"
|
||||||
|
|
||||||
|
class RBImage: public RBMovable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0);
|
RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0);
|
||||||
|
@ -44,6 +46,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void saveGeometry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap* image;
|
QPixmap* image;
|
||||||
int tiles;
|
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)
|
if(albumArt)
|
||||||
{
|
{
|
||||||
albumArt->setParentItem(view);
|
albumArt->setParentItem(view);
|
||||||
albumArt->position();
|
|
||||||
albumArt->show();
|
albumArt->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
const double RBViewport::scrollRate = 30;
|
const double RBViewport::scrollRate = 30;
|
||||||
|
|
||||||
RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
|
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),
|
background(info.screen()->background()), textOffset(0,0),
|
||||||
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
||||||
statusBarTexture(":/render/statusbar.png"),
|
statusBarTexture(":/render/statusbar.png"),
|
||||||
|
@ -178,6 +178,8 @@ void RBViewport::paint(QPainter *painter,
|
||||||
|
|
||||||
if(showStatusBar)
|
if(showStatusBar)
|
||||||
painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture);
|
painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture);
|
||||||
|
|
||||||
|
RBMovable::paint(painter, option, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBViewport::newLine()
|
void RBViewport::newLine()
|
||||||
|
@ -297,24 +299,9 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RBViewport::itemChange(GraphicsItemChange change,
|
void RBViewport::saveGeometry()
|
||||||
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()));
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QGraphicsItem::itemChange(change, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBViewport::alignLeft()
|
void RBViewport::alignLeft()
|
||||||
|
|
|
@ -24,13 +24,14 @@
|
||||||
|
|
||||||
#include "skin_parser.h"
|
#include "skin_parser.h"
|
||||||
#include "rbfont.h"
|
#include "rbfont.h"
|
||||||
|
#include "rbmovable.h"
|
||||||
|
|
||||||
class RBScreen;
|
class RBScreen;
|
||||||
class RBRenderInfo;
|
class RBRenderInfo;
|
||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
class RBViewport : public QGraphicsItem
|
class RBViewport : public RBMovable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Alignment
|
enum Alignment
|
||||||
|
@ -78,7 +79,7 @@ public:
|
||||||
skin_element* noId3);
|
skin_element* noId3);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
void saveGeometry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,8 @@ HEADERS += models/parsetreemodel.h \
|
||||||
qtfindreplacedialog/finddialog.h \
|
qtfindreplacedialog/finddialog.h \
|
||||||
gui/projectexporter.h \
|
gui/projectexporter.h \
|
||||||
gui/targetdownloader.h \
|
gui/targetdownloader.h \
|
||||||
gui/syntaxcompleter.h
|
gui/syntaxcompleter.h \
|
||||||
|
graphics/rbmovable.h
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
models/parsetreemodel.cpp \
|
models/parsetreemodel.cpp \
|
||||||
models/parsetreenode.cpp \
|
models/parsetreenode.cpp \
|
||||||
|
@ -147,7 +148,8 @@ SOURCES += main.cpp \
|
||||||
qtfindreplacedialog/finddialog.cpp \
|
qtfindreplacedialog/finddialog.cpp \
|
||||||
gui/projectexporter.cpp \
|
gui/projectexporter.cpp \
|
||||||
gui/targetdownloader.cpp \
|
gui/targetdownloader.cpp \
|
||||||
gui/syntaxcompleter.cpp
|
gui/syntaxcompleter.cpp \
|
||||||
|
graphics/rbmovable.cpp
|
||||||
OTHER_FILES += README \
|
OTHER_FILES += README \
|
||||||
resources/windowicon.png \
|
resources/windowicon.png \
|
||||||
resources/appicon.xcf \
|
resources/appicon.xcf \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue