From df1ff115f50f77473efeec33bea670388e7e3325 Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Fri, 6 Aug 2010 20:53:50 +0000 Subject: Theme Editor: Added coordinate display when moving mouse around preview window git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27738 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/graphics/rbscene.cpp | 36 +++++++++++++++++++++++++ utils/themeeditor/graphics/rbscene.h | 41 +++++++++++++++++++++++++++++ utils/themeeditor/graphics/rbscreen.cpp | 15 +++++++++++ utils/themeeditor/graphics/rbscreen.h | 3 +++ utils/themeeditor/gui/skindocument.h | 2 +- utils/themeeditor/gui/skinviewer.cpp | 4 +++ utils/themeeditor/gui/skinviewer.ui | 20 ++++++++++++++ utils/themeeditor/models/parsetreemodel.cpp | 4 +-- utils/themeeditor/models/parsetreemodel.h | 8 +++--- utils/themeeditor/themeeditor.pro | 6 +++-- 10 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 utils/themeeditor/graphics/rbscene.cpp create mode 100644 utils/themeeditor/graphics/rbscene.h diff --git a/utils/themeeditor/graphics/rbscene.cpp b/utils/themeeditor/graphics/rbscene.cpp new file mode 100644 index 0000000000..836abee489 --- /dev/null +++ b/utils/themeeditor/graphics/rbscene.cpp @@ -0,0 +1,36 @@ +/*************************************************************************** + * __________ __ ___. + * 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 "rbscene.h" + +RBScene::RBScene(QObject* parent) + : QGraphicsScene(parent) +{ +} + +RBScene::~RBScene() +{ +} + diff --git a/utils/themeeditor/graphics/rbscene.h b/utils/themeeditor/graphics/rbscene.h new file mode 100644 index 0000000000..2c4e0ee193 --- /dev/null +++ b/utils/themeeditor/graphics/rbscene.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * 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 RBSCENE_H +#define RBSCENE_H + +#include + +class RBScene : public QGraphicsScene +{ + Q_OBJECT + +public: + RBScene(QObject* parent = 0); + ~RBScene(); + + void moveMouse(QString position){ emit mouseMoved(position); } + +signals: + void mouseMoved(QString position); +}; + +#endif // RBSCENE_H diff --git a/utils/themeeditor/graphics/rbscreen.cpp b/utils/themeeditor/graphics/rbscreen.cpp index df72d5005b..1b1adc8be4 100644 --- a/utils/themeeditor/graphics/rbscreen.cpp +++ b/utils/themeeditor/graphics/rbscreen.cpp @@ -19,12 +19,15 @@ * ****************************************************************************/ +#include "rbscene.h" #include "rbscreen.h" #include "rbviewport.h" #include "devicestate.h" #include #include +#include +#include RBScreen::RBScreen(const RBRenderInfo& info, bool remote, QGraphicsItem *parent) @@ -32,6 +35,8 @@ RBScreen::RBScreen(const RBRenderInfo& info, bool remote, albumArt(0), customUI(0) { + setAcceptHoverEvents(true); + if(remote) { fullWidth = info.device()->data("remotewidth").toInt(); @@ -265,3 +270,13 @@ QColor RBScreen::stringToColor(QString str, QColor fallback) return retval; } + +void RBScreen::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +{ + RBScene* s = dynamic_cast(scene()); + QPoint p = event->scenePos().toPoint(); + s->moveMouse("(" + QString::number(p.x()) + ", " + + QString::number(p.y()) + ")"); + + QGraphicsItem::hoverMoveEvent(event); +} diff --git a/utils/themeeditor/graphics/rbscreen.h b/utils/themeeditor/graphics/rbscreen.h index 2903a29585..c9f6ae2dbc 100644 --- a/utils/themeeditor/graphics/rbscreen.h +++ b/utils/themeeditor/graphics/rbscreen.h @@ -88,6 +88,9 @@ public: void breakSBS(); +protected: + void hoverMoveEvent(QGraphicsSceneHoverEvent *event); + private: int width; int height; diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h index 5e72e29a8d..bf47897b0b 100644 --- a/utils/themeeditor/gui/skindocument.h +++ b/utils/themeeditor/gui/skindocument.h @@ -75,7 +75,7 @@ public: TabType type() const{ return Skin; } - QGraphicsScene* scene() + RBScene* scene() { return model->render(project, device, this, &fileName); } diff --git a/utils/themeeditor/gui/skinviewer.cpp b/utils/themeeditor/gui/skinviewer.cpp index f1f3af9c8c..ab4d522f2a 100644 --- a/utils/themeeditor/gui/skinviewer.cpp +++ b/utils/themeeditor/gui/skinviewer.cpp @@ -69,11 +69,15 @@ void SkinViewer::connectSkin(SkinDocument *skin) QObject::connect(ui->codeUndoButton, SIGNAL(pressed()), skin, SLOT(parseCode())); + QObject::connect(skin->scene(), SIGNAL(mouseMoved(QString)), + ui->coordinateLabel, SLOT(setText(QString))); + doc = skin; } else { ui->viewer->setScene(0); + ui->coordinateLabel->setText(""); doc = 0; } diff --git a/utils/themeeditor/gui/skinviewer.ui b/utils/themeeditor/gui/skinviewer.ui index dc4a786a33..aa10cddbe7 100644 --- a/utils/themeeditor/gui/skinviewer.ui +++ b/utils/themeeditor/gui/skinviewer.ui @@ -54,6 +54,26 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/utils/themeeditor/models/parsetreemodel.cpp b/utils/themeeditor/models/parsetreemodel.cpp index 2186788fd6..fbedf10d45 100644 --- a/utils/themeeditor/models/parsetreemodel.cpp +++ b/utils/themeeditor/models/parsetreemodel.cpp @@ -44,7 +44,7 @@ ParseTreeModel::ParseTreeModel(const char* document, QObject* parent): else this->root = 0; - scene = new QGraphicsScene(); + scene = new RBScene(); } @@ -272,7 +272,7 @@ bool ParseTreeModel::setData(const QModelIndex &index, const QVariant &value, return true; } -QGraphicsScene* ParseTreeModel::render(ProjectModel* project, +RBScene* ParseTreeModel::render(ProjectModel* project, DeviceState* device, SkinDocument* doc, const QString* file) { diff --git a/utils/themeeditor/models/parsetreemodel.h b/utils/themeeditor/models/parsetreemodel.h index f176b760d3..bef8cc8f48 100644 --- a/utils/themeeditor/models/parsetreemodel.h +++ b/utils/themeeditor/models/parsetreemodel.h @@ -29,10 +29,10 @@ #include #include -#include #include "parsetreenode.h" #include "devicestate.h" +#include "rbscene.h" class ParseTreeModel : public QAbstractItemModel { @@ -64,8 +64,8 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role); - QGraphicsScene* render(ProjectModel* project, DeviceState* device, - SkinDocument* doc, const QString* file = 0); + RBScene* render(ProjectModel* project, DeviceState* device, + SkinDocument* doc, const QString* file = 0); static QString safeSetting(ProjectModel* project, QString key, QString fallback) @@ -85,7 +85,7 @@ private: ParseTreeNode* root; ParseTreeModel* sbsModel; struct skin_element* tree; - QGraphicsScene* scene; + RBScene* scene; }; diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 5418bbf555..0cecd2d96b 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -107,7 +107,8 @@ HEADERS += models/parsetreemodel.h \ gui/projectexporter.h \ gui/targetdownloader.h \ gui/syntaxcompleter.h \ - graphics/rbmovable.h + graphics/rbmovable.h \ + graphics/rbscene.h SOURCES += main.cpp \ models/parsetreemodel.cpp \ models/parsetreenode.cpp \ @@ -149,7 +150,8 @@ SOURCES += main.cpp \ gui/projectexporter.cpp \ gui/targetdownloader.cpp \ gui/syntaxcompleter.cpp \ - graphics/rbmovable.cpp + graphics/rbmovable.cpp \ + graphics/rbscene.cpp OTHER_FILES += README \ resources/windowicon.png \ resources/appicon.xcf \ -- cgit v1.2.3