Added width and height parameters to image element. Added different active color...
[jspeed] / src / graphicsscreen.cpp
1 /*
2  * This file is part of jSpeed.
3  *
4  * jSpeed is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * jSpeed is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtGui/QApplication>
20 #include <QtGui/QDesktopWidget>
21 #include "graphicsscreen.h"
22 #include "toolbaritem.h"
23 #include "graphicsscene.h"
24 #include "odometer.h"
25
26 namespace
27 {
28     int const PADDING = 8;
29 }
30
31 GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent),
32 AbstractScreen(), scene_(0)
33 {
34     QRect rect = QApplication::desktop()->availableGeometry();
35
36     scene_ = new GraphicsScene(QRect(QPoint(0, 0), rect.size()));
37     setScene(scene_);
38
39     connect(scene_, SIGNAL(clicked()), this, SIGNAL(clicked()));
40
41     minimizeButton_ = new ToolbarItem(":/resources/minimize.png", ":/resources/minimize_active.png");
42     minimizeButton_->setZValue(9999);
43     scene_->addItem(minimizeButton_);
44     connect(minimizeButton_, SIGNAL(clicked()), this, SIGNAL(minimizePressed()));
45
46     imageWidth_ = minimizeButton_->pixmap().width();
47
48     closeButton_ = new ToolbarItem(":/resources/close.png", ":/resources/close_active.png");
49     closeButton_->setZValue(9999);
50     scene_->addItem(closeButton_);
51     connect(closeButton_, SIGNAL(clicked()), this, SIGNAL(closePressed()));
52
53     settingsButton_ = new ToolbarItem(":/resources/settings.png", ":/resources/settings_active.png");
54     settingsButton_->setZValue(9999);
55     scene_->addItem(settingsButton_);
56     connect(settingsButton_, SIGNAL(clicked()), this, SIGNAL(settingsPressed()));
57
58     reArrange();
59
60     connect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(update()));
61     connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(update()));
62 }
63
64 GraphicsScreen::~GraphicsScreen()
65 {
66 }
67
68 void GraphicsScreen::reArrange()
69 {
70     QRect rect = QApplication::desktop()->screenGeometry();
71     scene_->setSceneRect(rect);
72     minimizeButton_->setPos(PADDING, PADDING);
73     closeButton_->setPos(rect.width() - imageWidth_ - PADDING, PADDING);
74     settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2) - (PADDING / 2), PADDING);
75 }
76
77 void GraphicsScreen::flip()
78 {
79     if(isTransformed())
80     {
81         resetMatrix();
82         return;
83     }
84
85     setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1));
86 }
87
88 GraphicsScene* GraphicsScreen::getScene() const
89 {
90     return scene_;
91 }