summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-08-04 09:16:52 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-08-04 09:16:52 +0000
commit49865b23f601e636c9a80b21826fc607f1964eb5 (patch)
treeeb7959fd8aa5c572842e8d295440348cb17fc3cf /utils/themeeditor
parent2db08d41536b875f35b055f8e0bb3845b47a7ba3 (diff)
downloadrockbox-49865b23f601e636c9a80b21826fc607f1964eb5.tar.gz
rockbox-49865b23f601e636c9a80b21826fc607f1964eb5.tar.bz2
rockbox-49865b23f601e636c9a80b21826fc607f1964eb5.zip
Theme Editor: Began implementing code generation for movable viewports
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27691 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/graphics/rbmovable.cpp18
-rw-r--r--utils/themeeditor/graphics/rbmovable.h4
-rw-r--r--utils/themeeditor/graphics/rbrenderinfo.cpp7
-rw-r--r--utils/themeeditor/graphics/rbrenderinfo.h8
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp23
-rw-r--r--utils/themeeditor/graphics/rbviewport.h10
-rw-r--r--utils/themeeditor/gui/skindocument.cpp2
-rw-r--r--utils/themeeditor/gui/skindocument.h5
-rw-r--r--utils/themeeditor/models/parsetreemodel.cpp14
-rw-r--r--utils/themeeditor/models/parsetreemodel.h2
-rw-r--r--utils/themeeditor/models/parsetreenode.cpp32
-rw-r--r--utils/themeeditor/models/parsetreenode.h2
12 files changed, 104 insertions, 23 deletions
diff --git a/utils/themeeditor/graphics/rbmovable.cpp b/utils/themeeditor/graphics/rbmovable.cpp
index 11b3a6812f..3eca8bd18c 100644
--- a/utils/themeeditor/graphics/rbmovable.cpp
+++ b/utils/themeeditor/graphics/rbmovable.cpp
@@ -25,7 +25,7 @@
#include "rbmovable.h"
RBMovable::RBMovable(QGraphicsItem* parent)
- : QGraphicsItem(parent)
+ : QGraphicsItem(parent), geomChanged(false)
{
setFlags(ItemIsMovable | ItemIsSelectable | ItemSendsGeometryChanges);
}
@@ -61,7 +61,7 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
pos.setY(qMax(0., pos.y()));
pos.setY(qMin(pos.y(), bound.height() - boundingRect().height()));
- saveGeometry();
+ geomChanged = true;
return pos;
}
@@ -69,3 +69,17 @@ QVariant RBMovable::itemChange(GraphicsItemChange change, const QVariant &value)
return QGraphicsItem::itemChange(change, value);
}
+void RBMovable::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mousePressEvent(event);
+}
+
+void RBMovable::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsItem::mouseReleaseEvent(event);
+ if(isSelected())
+ {
+ saveGeometry();
+ geomChanged = false;
+ }
+}
diff --git a/utils/themeeditor/graphics/rbmovable.h b/utils/themeeditor/graphics/rbmovable.h
index e8ef69b5bd..5b6330228d 100644
--- a/utils/themeeditor/graphics/rbmovable.h
+++ b/utils/themeeditor/graphics/rbmovable.h
@@ -41,6 +41,8 @@ public:
virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
protected:
virtual QVariant itemChange(GraphicsItemChange change,
@@ -48,6 +50,8 @@ protected:
/* Responsible for updating the parse tree */
virtual void saveGeometry() = 0;
+ bool geomChanged;
+
};
#endif // RBMOVABLE_H
diff --git a/utils/themeeditor/graphics/rbrenderinfo.cpp b/utils/themeeditor/graphics/rbrenderinfo.cpp
index 0b9ea41397..e39a4cea43 100644
--- a/utils/themeeditor/graphics/rbrenderinfo.cpp
+++ b/utils/themeeditor/graphics/rbrenderinfo.cpp
@@ -22,10 +22,11 @@
#include "rbrenderinfo.h"
RBRenderInfo::RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
- QMap<QString, QString>* settings,
+ SkinDocument* doc, QMap<QString, QString>* settings,
DeviceState* device, RBScreen* screen,
RBScreen* sbsScreen)
- :mProject(project), mSettings(settings),
+ :mProject(project), mDoc(doc),
+ mSettings(settings),
mDevice(device), mScreen(screen),
mSbsScreen(sbsScreen), mModel(model)
{
@@ -41,6 +42,7 @@ RBRenderInfo::RBRenderInfo(const RBRenderInfo &other)
mProject = other.mProject;
mSettings = other.mSettings;
mDevice = other.mDevice;
+ mDoc = other.mDoc;
mScreen = other.mScreen;
mSbsScreen = other.mSbsScreen;
mModel = other.mModel;
@@ -51,6 +53,7 @@ const RBRenderInfo& RBRenderInfo::operator=(const RBRenderInfo& other)
mProject = other.mProject;
mSettings = other.mSettings;
mDevice = other.mDevice;
+ mDoc = other.mDoc;
mScreen = other.mScreen;
mSbsScreen = other.mSbsScreen;
mModel = other.mModel;
diff --git a/utils/themeeditor/graphics/rbrenderinfo.h b/utils/themeeditor/graphics/rbrenderinfo.h
index 599a563da2..17b87dbb6b 100644
--- a/utils/themeeditor/graphics/rbrenderinfo.h
+++ b/utils/themeeditor/graphics/rbrenderinfo.h
@@ -28,13 +28,15 @@ class RBScreen;
class ProjectModel;
class ParseTreeModel;
class DeviceState;
+class SkinDocument;
class RBRenderInfo
{
public:
RBRenderInfo(ParseTreeModel* model, ProjectModel* project,
- QMap<QString, QString>* settings, DeviceState* device,
- RBScreen* screen, RBScreen* sbsScreen = 0);
+ SkinDocument* doc, QMap<QString, QString>* settings,
+ DeviceState* device, RBScreen* screen,
+ RBScreen* sbsScreen = 0);
RBRenderInfo();
RBRenderInfo(const RBRenderInfo& other);
virtual ~RBRenderInfo();
@@ -43,6 +45,7 @@ public:
ProjectModel* project() const{ return mProject; }
DeviceState* device() const{ return mDevice; }
+ SkinDocument* document() const{ return mDoc; }
QMap<QString, QString>* settings() const{ return mSettings; }
RBScreen* screen() const{ return mScreen; }
RBScreen* sbsScreen() const{ return mSbsScreen; }
@@ -50,6 +53,7 @@ public:
private:
ProjectModel* mProject;
+ SkinDocument* mDoc;
QMap<QString, QString>* mSettings;
DeviceState* mDevice;
RBScreen* mScreen;
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index fe17ebbeef..33749fdb7f 100644
--- a/utils/themeeditor/graphics/rbviewport.cpp
+++ b/utils/themeeditor/graphics/rbviewport.cpp
@@ -34,16 +34,19 @@
#include "parsetreemodel.h"
#include "tag_table.h"
#include "skin_parser.h"
+#include "skindocument.h"
/* Pixels/second of text scrolling */
const double RBViewport::scrollRate = 30;
-RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
+RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info,
+ ParseTreeNode* pNode)
: 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"),
- leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0)
+ leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0),
+ node(pNode), doc(info.document())
{
setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges);
@@ -67,7 +70,6 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
}
else
{
- int param = 0;
QString ident;
int x,y,w,h;
/* Rendering one of the other types of viewport */
@@ -75,7 +77,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
{
case '\0':
customUI = false;
- param = 0;
+ baseParam= 0;
break;
case 'l':
@@ -85,13 +87,13 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
if(!screen->viewPortDisplayed(ident))
hide();
info.screen()->loadViewport(ident, this);
- param = 1;
+ baseParam= 1;
break;
case 'i':
/* Custom UI Viewport */
customUI = true;
- param = 1;
+ baseParam= 1;
if(node->params[0].type == skin_tag_parameter::DEFAULT)
{
setVisible(true);
@@ -104,6 +106,7 @@ RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
break;
}
/* Now we grab the info common to all viewports */
+ int param = baseParam;
x = node->params[param++].data.number;
if(x < 0)
x = info.screen()->boundingRect().right() + x;
@@ -301,7 +304,15 @@ void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
void RBViewport::saveGeometry()
{
+ QRectF bounds = boundingRect();
+ QPointF origin = pos();
+ node->modParam(static_cast<int>(origin.x()), baseParam);
+ node->modParam(static_cast<int>(origin.y()), baseParam + 1);
+ node->modParam(static_cast<int>(bounds.width()), baseParam + 2);
+ node->modParam(static_cast<int>(bounds.height()), baseParam + 3);
+
+ doc->genCode();
}
void RBViewport::alignLeft()
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index b9bafe47d1..691133beeb 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -28,9 +28,12 @@
class RBScreen;
class RBRenderInfo;
+class ParseTreeNode;
#include <QGraphicsItem>
+class SkinDocument;
+
class RBViewport : public RBMovable
{
public:
@@ -43,7 +46,8 @@ public:
static const double scrollRate;
- RBViewport(skin_element* node, const RBRenderInfo& info);
+ RBViewport(skin_element* node, const RBRenderInfo& info,
+ ParseTreeNode* pNode);
virtual ~RBViewport();
QPainterPath shape() const;
@@ -112,6 +116,10 @@ private:
RBText* rightGraphic;
double scrollTime;
+
+ int baseParam;
+ ParseTreeNode* node;
+ SkinDocument* doc;
};
#endif // RBVIEWPORT_H
diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp
index 15111cbed8..bd52685c6b 100644
--- a/utils/themeeditor/gui/skindocument.cpp
+++ b/utils/themeeditor/gui/skindocument.cpp
@@ -301,7 +301,7 @@ void SkinDocument::codeChanged()
if(lastUpdate.msecsTo(QTime::currentTime()) >= updateInterval)
{
- model->render(project, device, &fileName);
+ model->render(project, device, this, &fileName);
checkUpdate.stop();
lastUpdate = QTime::currentTime();
}
diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h
index d20d0fb1ec..10c9e3ff11 100644
--- a/utils/themeeditor/gui/skindocument.h
+++ b/utils/themeeditor/gui/skindocument.h
@@ -76,7 +76,10 @@ public:
TabType type() const{ return Skin; }
- QGraphicsScene* scene(){ return model->render(project, device, &fileName); }
+ QGraphicsScene* scene()
+ {
+ return model->render(project, device, this, &fileName);
+ }
void showFind(){ findReplace->show(); }
void hideFind(){ findReplace->hide(); }
diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp
index 8d8855a5a6..a7f04ffbf2 100644
--- a/utils/themeeditor/models/parsetreemodel.cpp
+++ b/utils/themeeditor/models/parsetreemodel.cpp
@@ -271,7 +271,8 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value,
}
QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
- DeviceState* device, const QString* file)
+ DeviceState* device,
+ SkinDocument* doc, const QString* file)
{
scene->clear();
@@ -327,14 +328,14 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
if(sbsModel.root != 0)
{
- RBRenderInfo sbsInfo(&sbsModel, project, &settings, device,
+ RBRenderInfo sbsInfo(&sbsModel, project, doc, &settings, device,
sbsScreen);
sbsScreen = new RBScreen(sbsInfo, remote);
scene->addItem(sbsScreen);
- sbsInfo = RBRenderInfo(&sbsModel, project, &settings, device,
- sbsScreen);
+ sbsInfo = RBRenderInfo(&sbsModel, project, doc, &settings,
+ device, sbsScreen);
sbsModel.root->render(sbsInfo);
}
@@ -342,7 +343,7 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
}
RBScreen* screen = 0;
- RBRenderInfo info(this, project, &settings, device, screen, sbsScreen);
+ RBRenderInfo info(this, project, doc, &settings, device, screen, sbsScreen);
/* Adding the screen */
if(sbsScreen)
@@ -353,7 +354,8 @@ QGraphicsScene* ParseTreeModel::render(ProjectModel* project,
if(!sbsScreen)
scene->addItem(screen);
- info = RBRenderInfo(this, project, &settings, device, screen, sbsScreen);
+ info = RBRenderInfo(this, project, doc, &settings, device, screen,
+ sbsScreen);
/* Rendering the tree */
diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h
index 463f6ca82d..ec0a420a84 100644
--- a/utils/themeeditor/models/parsetreemodel.h
+++ b/utils/themeeditor/models/parsetreemodel.h
@@ -63,7 +63,7 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role);
QGraphicsScene* render(ProjectModel* project, DeviceState* device,
- const QString* file = 0);
+ SkinDocument* doc, const QString* file = 0);
static QString safeSetting(ProjectModel* project, QString key,
QString fallback)
diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp
index 1349ba9ad6..8d1fcc7d1a 100644
--- a/utils/themeeditor/models/parsetreenode.cpp
+++ b/utils/themeeditor/models/parsetreenode.cpp
@@ -523,7 +523,7 @@ void ParseTreeNode::render(const RBRenderInfo& info)
return;
}
- rendered = new RBViewport(element, info);
+ rendered = new RBViewport(element, info, this);
for(int i = element->params_count; i < children.count(); i++)
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
@@ -1057,3 +1057,33 @@ double ParseTreeNode::findConditionalTime(ParseTreeNode *conditional,
conditional->children.count()).toInt();
return findBranchTime(conditional->children[child], info);
}
+
+void ParseTreeNode::modParam(QVariant value, int index)
+{
+ if(element)
+ {
+ if(index < 0 || index >= children.count())
+ return;
+ children[index]->modParam(value);
+ }
+ else if(param)
+ {
+ if(value.type() == QVariant::Double)
+ {
+ param->type = skin_tag_parameter::DECIMAL;
+ param->data.number = static_cast<int>(value.toDouble() * 10);
+ }
+ else if(value.type() == QVariant::String)
+ {
+ param->type = skin_tag_parameter::STRING;
+ free(param->data.text);
+ param->data.text = strdup(value.toString().toStdString().c_str());
+ }
+ else if(value.type() == QVariant::Int)
+ {
+ param->type = skin_tag_parameter::INTEGER;
+ param->data.number = value.toInt();
+ }
+
+ }
+}
diff --git a/utils/themeeditor/models/parsetreenode.h b/utils/themeeditor/models/parsetreenode.h
index ca01ddd5ae..39f0dbdfcd 100644
--- a/utils/themeeditor/models/parsetreenode.h
+++ b/utils/themeeditor/models/parsetreenode.h
@@ -67,6 +67,8 @@ public:
double findConditionalTime(ParseTreeNode* conditional,
const RBRenderInfo& info);
+ void modParam(QVariant value, int index = -1);
+
private:
bool execTag(const RBRenderInfo& info, RBViewport* viewport);