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