From: eshe Date: Wed, 14 Jul 2010 14:23:30 +0000 (+0100) Subject: Added width and height parameters to image element. Added different active color... X-Git-Url: http://git.maemo.org/git/?p=jspeed;a=commitdiff_plain;h=cb2ec80bb51d03d84b694d234e23ab1b3639b63b Added width and height parameters to image element. Added different active color to toolbar items. Changed default background file to smaller one. --- diff --git a/jspeed.pro b/jspeed.pro index b770792..d5f39ee 100644 --- a/jspeed.pro +++ b/jspeed.pro @@ -8,7 +8,7 @@ SOURCES += src/main.cpp \ src/graphicsscreen.cpp \ src/abstractscreen.cpp \ src/widgetscreen.cpp \ - src/imageitem.cpp \ + src/toolbaritem.cpp \ src/reader.cpp \ src/zipreader.cpp \ src/filereader.cpp \ @@ -34,7 +34,7 @@ HEADERS += src/mainwindow.h \ src/graphicsscreen.h \ src/abstractscreen.h \ src/widgetscreen.h \ - src/imageitem.h \ + src/toolbaritem.h \ src/reader.h \ src/zipreader.h \ src/filereader.h \ diff --git a/src/graphicsscreen.cpp b/src/graphicsscreen.cpp index 006a33c..322dae9 100644 --- a/src/graphicsscreen.cpp +++ b/src/graphicsscreen.cpp @@ -19,7 +19,7 @@ #include #include #include "graphicsscreen.h" -#include "imageitem.h" +#include "toolbaritem.h" #include "graphicsscene.h" #include "odometer.h" @@ -38,19 +38,19 @@ AbstractScreen(), scene_(0) connect(scene_, SIGNAL(clicked()), this, SIGNAL(clicked())); - minimizeButton_ = new ImageItem(":/resources/minimize.png"); + minimizeButton_ = new ToolbarItem(":/resources/minimize.png", ":/resources/minimize_active.png"); minimizeButton_->setZValue(9999); scene_->addItem(minimizeButton_); connect(minimizeButton_, SIGNAL(clicked()), this, SIGNAL(minimizePressed())); imageWidth_ = minimizeButton_->pixmap().width(); - closeButton_ = new ImageItem(":/resources/close.png"); + closeButton_ = new ToolbarItem(":/resources/close.png", ":/resources/close_active.png"); closeButton_->setZValue(9999); scene_->addItem(closeButton_); connect(closeButton_, SIGNAL(clicked()), this, SIGNAL(closePressed())); - settingsButton_ = new ImageItem(":/resources/settings.png"); + settingsButton_ = new ToolbarItem(":/resources/settings.png", ":/resources/settings_active.png"); settingsButton_->setZValue(9999); scene_->addItem(settingsButton_); connect(settingsButton_, SIGNAL(clicked()), this, SIGNAL(settingsPressed())); diff --git a/src/graphicsscreen.h b/src/graphicsscreen.h index 9799bf3..afa7097 100644 --- a/src/graphicsscreen.h +++ b/src/graphicsscreen.h @@ -23,7 +23,7 @@ #include "abstractscreen.h" class GraphicsScene; -class ImageItem; +class ToolbarItem; class GraphicsScreen : public QGraphicsView, public AbstractScreen { @@ -50,9 +50,9 @@ protected: private: GraphicsScene* scene_; - ImageItem* minimizeButton_; - ImageItem* settingsButton_; - ImageItem* closeButton_; + ToolbarItem* minimizeButton_; + ToolbarItem* settingsButton_; + ToolbarItem* closeButton_; int imageWidth_; }; diff --git a/src/imageelement.cpp b/src/imageelement.cpp index 2002666..675924b 100644 --- a/src/imageelement.cpp +++ b/src/imageelement.cpp @@ -30,11 +30,14 @@ namespace { {"xpos", true}, {"ypos", true}, - {"src", false} + {"src", false}, + {"width", true}, + {"height", true} }; } -ImageElement::ImageElement(Reader* reader): GraphicsElement(reader) +ImageElement::ImageElement(Reader* reader): GraphicsElement(reader), +width_(0), height_(0), imageSet_(false) { element_ = new QGraphicsPixmapItem(); } @@ -60,7 +63,12 @@ bool ImageElement::setAttribute(QString const& name, case SRC: return loadImage(value); break; - + case WIDTH: + width_ = intVal; + break; + case HEIGHT: + height_ = intVal; + break; default: qDebug() << "Unknown attribute: " << attr; return false; @@ -76,6 +84,31 @@ bool ImageElement::setAttribute(QString const& name, void ImageElement::addToScene(GraphicsScene* scene) { + if(!imageSet_) + { + return; + } + + QPixmap pix; + + if(width_ > 0 && height_ > 0) + { + pix = pixmap_.scaled(width_, height_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + else if(width_ > 0) + { + pix = pixmap_.scaledToWidth(width_, Qt::SmoothTransformation); + } + else if(height_ > 0) + { + pix = pixmap_.scaledToHeight(height_, Qt::SmoothTransformation); + } + else + { + pix = pixmap_; + } + + element_->setPixmap(pix); scene->addItem(element_); } @@ -85,7 +118,6 @@ void ImageElement::update() bool ImageElement::loadImage(QString const& name) { - QPixmap pixmap; QByteArray data; if(!readFile(name, data)) @@ -93,13 +125,13 @@ bool ImageElement::loadImage(QString const& name) return false; } - if(!pixmap.loadFromData(data)) + if(!pixmap_.loadFromData(data)) { setError("Invalid image file: " + name); return false; } - element_->setPixmap(pixmap); + imageSet_ = true; return true; } diff --git a/src/imageelement.h b/src/imageelement.h index 0452123..b4ac299 100644 --- a/src/imageelement.h +++ b/src/imageelement.h @@ -30,7 +30,7 @@ class GraphicsScene; class ImageElement : public GraphicsElement { public: - enum Attribute {XPOS, YPOS, SRC, ATTRIBUTE_COUNT}; + enum Attribute {XPOS, YPOS, SRC, WIDTH, HEIGHT, ATTRIBUTE_COUNT}; ImageElement(Reader* reader); virtual bool setAttribute(QString const& name, QString const& value); virtual void addToScene(GraphicsScene* scene); @@ -39,6 +39,10 @@ public: private: bool loadImage(QString const& name); QGraphicsPixmapItem* element_; + QPixmap pixmap_; + int width_; + int height_; + bool imageSet_; }; #endif diff --git a/src/imageitem.cpp b/src/imageitem.cpp deleted file mode 100644 index 0891f36..0000000 --- a/src/imageitem.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of jSpeed. - * - * jSpeed 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 3 of the License, or - * (at your option) any later version. - * - * jSpeed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with jSpeed. If not, see . - * - */ - -#include -#include "imageitem.h" - -ImageItem::ImageItem(QString const& filename, QGraphicsItem *parent): -QGraphicsPixmapItem(QPixmap(filename), parent) -{ -} - -void ImageItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); - emit clicked(); -} - diff --git a/src/imageitem.h b/src/imageitem.h deleted file mode 100644 index 30ff5e4..0000000 --- a/src/imageitem.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of jSpeed. - * - * jSpeed 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 3 of the License, or - * (at your option) any later version. - * - * jSpeed is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with jSpeed. If not, see . - * - */ - -#ifndef IMAGEITEM_H -#define IMAGEITEM_H - -#include -#include - -class QString; - -class ImageItem: public QObject, public QGraphicsPixmapItem -{ - Q_OBJECT - -public: - ImageItem(QString const& filename, QGraphicsItem *parent = 0); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - -signals: - void clicked(); -}; - - -#endif diff --git a/src/mainmenu.cpp b/src/mainmenu.cpp index e9bb4f8..a10d69b 100644 --- a/src/mainmenu.cpp +++ b/src/mainmenu.cpp @@ -88,6 +88,8 @@ void MainMenu::showAbout() void MainMenu::confirmReset() { + hide(); + QMessageBox::StandardButton result = QMessageBox::question(this, tr("Reset all"), tr("Are you sure? All recorded data will be lost."), QMessageBox::Yes | QMessageBox::No); diff --git a/src/resources.qrc b/src/resources.qrc index 7b6a999..72fcf5d 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -3,6 +3,9 @@ resources/minimize.png resources/close.png resources/settings.png + resources/minimize_active.png + resources/close_active.png + resources/settings_active.png resources/appicon.png resources/themes/default/theme.xml resources/themes/default/digital7.ttf diff --git a/src/resources/close_active.png b/src/resources/close_active.png new file mode 100644 index 0000000..7a436b7 Binary files /dev/null and b/src/resources/close_active.png differ diff --git a/src/resources/minimize_active.png b/src/resources/minimize_active.png new file mode 100644 index 0000000..62d78ca Binary files /dev/null and b/src/resources/minimize_active.png differ diff --git a/src/resources/settings_active.png b/src/resources/settings_active.png new file mode 100644 index 0000000..82f5b8c Binary files /dev/null and b/src/resources/settings_active.png differ diff --git a/src/resources/themes/default/background.png b/src/resources/themes/default/background.png old mode 100755 new mode 100644 index d4f20b1..6c67ee4 Binary files a/src/resources/themes/default/background.png and b/src/resources/themes/default/background.png differ diff --git a/src/resources/themes/default/digital7.ttf b/src/resources/themes/default/digital7.ttf old mode 100755 new mode 100644 diff --git a/src/resources/themes/default/theme.xml b/src/resources/themes/default/theme.xml old mode 100755 new mode 100644 diff --git a/src/toolbaritem.cpp b/src/toolbaritem.cpp new file mode 100644 index 0000000..d08d34d --- /dev/null +++ b/src/toolbaritem.cpp @@ -0,0 +1,64 @@ +/* + * This file is part of jSpeed. + * + * jSpeed 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 3 of the License, or + * (at your option) any later version. + * + * jSpeed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with jSpeed. If not, see . + * + */ + +#include +#include +#include +#include "toolbaritem.h" + +ToolbarItem::ToolbarItem(QString const& filename, QString const& activeFilename, QGraphicsItem *parent): +QGraphicsPixmapItem(parent), active_(false) +{ + pixmap_.load(filename); + activePixmap_.load(activeFilename); + setPixmap(pixmap_); +} + +void ToolbarItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + setPixmap(activePixmap_); + active_ = true; +} + +void ToolbarItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + + if(active_) + { + active_ = false; + setPixmap(pixmap_); + update(); + emit clicked(); + } +} + +void ToolbarItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QPointF pos = event->pos(); + qreal x = pos.x(); + qreal y = pos.y(); + + if(active_ && (x < 0 || y < 0 || x > activePixmap_.width() || y > activePixmap_.height())) + { + active_ = false; + setPixmap(pixmap_); + } +} + diff --git a/src/toolbaritem.h b/src/toolbaritem.h new file mode 100644 index 0000000..f80ecde --- /dev/null +++ b/src/toolbaritem.h @@ -0,0 +1,49 @@ +/* + * This file is part of jSpeed. + * + * jSpeed 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 3 of the License, or + * (at your option) any later version. + * + * jSpeed is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with jSpeed. If not, see . + * + */ + +#ifndef TOOLBARITEM_H +#define TOOLBARITEM_H + +#include +#include + +class QString; + +class ToolbarItem: public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT + +public: + ToolbarItem(QString const& filename, QString const& activeFilename, QGraphicsItem *parent = 0); + +protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* event); + +signals: + void clicked(); + +private: + QPixmap pixmap_; + QPixmap activePixmap_; + bool active_; +}; + + +#endif