2 * This file is part of jSpeed.
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.
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.
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/>.
19 #include <QtCore/QDebug>
20 #include <QtGui/QApplication>
21 #include <QtGui/QDesktopWidget>
22 #include "graphicsscreen.h"
23 #include "toolbaritem.h"
24 #include "graphicsscene.h"
29 int const PADDING = 6;
30 QString const BACKGROUND_COLOR = "#000";
33 GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent),
34 AbstractScreen(), scene_(0), isFlipped_(false)
36 QRect rect = QApplication::desktop()->availableGeometry();
38 scene_ = new GraphicsScene(QRect(QPoint(0, 0), rect.size()));
41 setBackgroundBrush(QBrush(QColor(BACKGROUND_COLOR)));
43 connect(scene_, SIGNAL(clicked()), this, SIGNAL(clicked()));
45 minimizeButton_ = new ToolbarItem(":/resources/minimize.png", ":/resources/minimize_active.png");
46 minimizeButton_->setZValue(9999);
47 scene_->addItem(minimizeButton_);
48 connect(minimizeButton_, SIGNAL(clicked()), this, SIGNAL(minimizePressed()));
50 imageWidth_ = minimizeButton_->pixmap().width();
52 closeButton_ = new ToolbarItem(":/resources/close.png", ":/resources/close_active.png");
53 closeButton_->setZValue(9999);
54 scene_->addItem(closeButton_);
55 connect(closeButton_, SIGNAL(clicked()), this, SIGNAL(closePressed()));
57 settingsButton_ = new ToolbarItem(":/resources/settings.png", ":/resources/settings_active.png");
58 settingsButton_->setZValue(9999);
59 scene_->addItem(settingsButton_);
60 connect(settingsButton_, SIGNAL(clicked()), this, SIGNAL(settingsPressed()));
64 connect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(update()));
65 connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(update()));
68 GraphicsScreen::~GraphicsScreen()
72 void GraphicsScreen::reArrange()
74 QRect rect = QApplication::desktop()->screenGeometry();
75 scene_->setSceneRect(rect);
76 minimizeButton_->setPos(PADDING, PADDING);
77 closeButton_->setPos(rect.width() - imageWidth_ - PADDING, PADDING);
78 settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2), PADDING);
81 void GraphicsScreen::flip()
90 setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1));
95 GraphicsScene* GraphicsScreen::getScene() const
100 void GraphicsScreen::forceRepaint()
102 QApplication::processEvents();
104 viewport()->update();
105 QApplication::processEvents();