Initial commit.
[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 <QtGui/QGraphicsScene>
22 #include <QtGui/QApplication>
23 #include "graphicsscreen.h"
24 #include "imageitem.h"
25 #include "graphicsscene.h"
26 #include "odometer.h"
27
28 namespace
29 {
30     int const PADDING = 8;
31 }
32
33 GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent),
34 AbstractScreen(), scene_(0)
35 {
36     QRect rect = QApplication::desktop()->availableGeometry();
37
38     scene_ = new GraphicsScene(QRect(QPoint(0, 0), rect.size()));
39     setScene(scene_);
40
41     connect(scene_, SIGNAL(clicked()), this, SIGNAL(clicked()));
42
43     minimizeButton_ = new ImageItem(":/resources/minimize.png");
44     minimizeButton_->setZValue(9999);
45     scene_->addItem(minimizeButton_);
46     connect(minimizeButton_, SIGNAL(clicked()), this, SIGNAL(minimizePressed()));
47
48     imageWidth_ = minimizeButton_->pixmap().width();
49
50     closeButton_ = new ImageItem(":/resources/close.png");
51     closeButton_->setZValue(9999);
52     scene_->addItem(closeButton_);
53     connect(closeButton_, SIGNAL(clicked()), this, SIGNAL(closePressed()));
54
55     settingsButton_ = new ImageItem(":/resources/settings.png");
56     settingsButton_->setZValue(9999);
57     scene_->addItem(settingsButton_);
58     connect(settingsButton_, SIGNAL(clicked()), this, SIGNAL(settingsPressed()));
59
60     reArrange();
61
62     connect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(update()));
63     connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(update()));
64 }
65
66 GraphicsScreen::~GraphicsScreen()
67 {
68 }
69
70 void GraphicsScreen::reArrange()
71 {
72     QRect rect = QApplication::desktop()->screenGeometry();
73     scene_->setSceneRect(rect);
74     minimizeButton_->setPos(PADDING, PADDING);
75     closeButton_->setPos(rect.width() - imageWidth_ - PADDING, PADDING);
76     settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2) - (PADDING / 2), PADDING);
77 }
78
79 void GraphicsScreen::flip()
80 {
81     if(isTransformed())
82     {
83         resetMatrix();
84         return;
85     }
86
87     setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1));
88 }
89
90 GraphicsScene* GraphicsScreen::getScene() const
91 {
92     return scene_;
93 }