src/graphicsscreen.cpp \
src/abstractscreen.cpp \
src/widgetscreen.cpp \
- src/imageitem.cpp \
+ src/toolbaritem.cpp \
src/reader.cpp \
src/zipreader.cpp \
src/filereader.cpp \
src/graphicsscreen.h \
src/abstractscreen.h \
src/widgetscreen.h \
- src/imageitem.h \
+ src/toolbaritem.h \
src/reader.h \
src/zipreader.h \
src/filereader.h \
#include <QtGui/QApplication>
#include <QtGui/QDesktopWidget>
#include "graphicsscreen.h"
-#include "imageitem.h"
+#include "toolbaritem.h"
#include "graphicsscene.h"
#include "odometer.h"
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()));
#include "abstractscreen.h"
class GraphicsScene;
-class ImageItem;
+class ToolbarItem;
class GraphicsScreen : public QGraphicsView, public AbstractScreen
{
private:
GraphicsScene* scene_;
- ImageItem* minimizeButton_;
- ImageItem* settingsButton_;
- ImageItem* closeButton_;
+ ToolbarItem* minimizeButton_;
+ ToolbarItem* settingsButton_;
+ ToolbarItem* closeButton_;
int imageWidth_;
};
{
{"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();
}
case SRC:
return loadImage(value);
break;
-
+ case WIDTH:
+ width_ = intVal;
+ break;
+ case HEIGHT:
+ height_ = intVal;
+ break;
default:
qDebug() << "Unknown attribute: " << attr;
return false;
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_);
}
bool ImageElement::loadImage(QString const& name)
{
- QPixmap pixmap;
QByteArray data;
if(!readFile(name, data))
return false;
}
- if(!pixmap.loadFromData(data))
+ if(!pixmap_.loadFromData(data))
{
setError("Invalid image file: " + name);
return false;
}
- element_->setPixmap(pixmap);
+ imageSet_ = true;
return true;
}
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);
private:
bool loadImage(QString const& name);
QGraphicsPixmapItem* element_;
+ QPixmap pixmap_;
+ int width_;
+ int height_;
+ bool imageSet_;
};
#endif
+++ /dev/null
-/*
- * 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();
-}
-
+++ /dev/null
-/*
- * 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
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);
<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>
--- /dev/null
+/*
+ * 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_);
+ }
+}
+
--- /dev/null
+/*
+ * 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