Added width and height parameters to image element. Added different active color...
authoreshe <jessehakanen@gmail.com>
Wed, 14 Jul 2010 14:23:30 +0000 (15:23 +0100)
committereshe <jessehakanen@gmail.com>
Wed, 14 Jul 2010 14:23:30 +0000 (15:23 +0100)
17 files changed:
jspeed.pro
src/graphicsscreen.cpp
src/graphicsscreen.h
src/imageelement.cpp
src/imageelement.h
src/imageitem.cpp [deleted file]
src/imageitem.h [deleted file]
src/mainmenu.cpp
src/resources.qrc
src/resources/close_active.png [new file with mode: 0644]
src/resources/minimize_active.png [new file with mode: 0644]
src/resources/settings_active.png [new file with mode: 0644]
src/resources/themes/default/background.png [changed mode: 0755->0644]
src/resources/themes/default/digital7.ttf [changed mode: 0755->0644]
src/resources/themes/default/theme.xml [changed mode: 0755->0644]
src/toolbaritem.cpp [new file with mode: 0644]
src/toolbaritem.h [new file with mode: 0644]

index b770792..d5f39ee 100644 (file)
@@ -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 \
index 006a33c..322dae9 100644 (file)
@@ -19,7 +19,7 @@
 #include <QtGui/QApplication>
 #include <QtGui/QDesktopWidget>
 #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()));
index 9799bf3..afa7097 100644 (file)
@@ -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_;
 };
 
index 2002666..675924b 100644 (file)
@@ -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;
 }
index 0452123..b4ac299 100644 (file)
@@ -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 (file)
index 0891f36..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <QtCore/QString>
-#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 (file)
index 30ff5e4..0000000
+++ /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 <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef IMAGEITEM_H
-#define IMAGEITEM_H
-
-#include <QtCore/QObject>
-#include <QtGui/QGraphicsPixmapItem>
-
-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
index e9bb4f8..a10d69b 100644 (file)
@@ -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);
index 7b6a999..72fcf5d 100644 (file)
@@ -3,6 +3,9 @@
     <file>resources/minimize.png</file>
     <file>resources/close.png</file>
     <file>resources/settings.png</file>
+    <file>resources/minimize_active.png</file>
+    <file>resources/close_active.png</file>
+    <file>resources/settings_active.png</file>
     <file>resources/appicon.png</file>
     <file>resources/themes/default/theme.xml</file>
     <file>resources/themes/default/digital7.ttf</file>
diff --git a/src/resources/close_active.png b/src/resources/close_active.png
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..82f5b8c
Binary files /dev/null and b/src/resources/settings_active.png differ
old mode 100755 (executable)
new mode 100644 (file)
index d4f20b1..6c67ee4
Binary files a/src/resources/themes/default/background.png and b/src/resources/themes/default/background.png differ
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/src/toolbaritem.cpp b/src/toolbaritem.cpp
new file mode 100644 (file)
index 0000000..d08d34d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QtGui/QGraphicsSceneMouseEvent>
+#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 (file)
index 0000000..f80ecde
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef TOOLBARITEM_H
+#define TOOLBARITEM_H
+
+#include <QtCore/QObject>
+#include <QtGui/QGraphicsPixmapItem>
+
+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