Source /tmp/session_bus_address.user before invoking dbus-send in postinst script
[harmattan/cameraplus] / src / gridlines.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "gridlines.h"
22 #include <QPainter>
23
24 #if defined(QT4)
25 GridLines::GridLines(QDeclarativeItem *parent) :
26   QDeclarativeItem(parent) {
27 #elif defined(QT5)
28 GridLines::GridLines(QQuickItem *parent) :
29   QQuickPaintedItem(parent) {
30 #endif
31
32 #if defined(QT4)
33   setFlag(QGraphicsItem::ItemHasNoContents, false);
34 #endif
35 }
36
37 GridLines::~GridLines() {
38
39 }
40
41 #if defined(QT4)
42 void GridLines::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
43                            QWidget* widget) {
44
45   QDeclarativeItem::paint(painter, option, widget);
46 #elif defined(QT5)
47 void GridLines::paint(QPainter* painter) {
48 #endif
49
50   painter->save();
51   painter->setPen(QPen(Qt::black, 3));
52   painter->drawLines(m_lines, 4);
53
54   painter->setPen(QPen(Qt::white, 1));
55   painter->drawLines(m_lines, 4);
56   painter->restore();
57 }
58
59 void GridLines::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
60 #if defined(QT4)
61   QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
62 #elif defined(QT5)
63   QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
64 #endif
65
66   qreal width = newGeometry.width();
67   qreal height = newGeometry.height();
68   qreal w = newGeometry.width() / 3;
69   qreal h = newGeometry.height() / 3;
70
71   m_lines[0] = QLineF(QPointF(0, h), QPointF(width, h));
72   m_lines[1] = QLineF(QPointF(0, h * 2), QPointF(width, h * 2));
73   m_lines[2] = QLineF(QPointF(w, 0), QPointF(w, height));
74   m_lines[3] = QLineF(QPointF(w * 2, 0), QPointF(w * 2, height));
75 }