693380ed5c517fd3208c28a247ba084a78d6e6be
[harmattan/cameraplus] / src / gridlines.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 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 GridLines::GridLines(QDeclarativeItem *parent) :
25   QDeclarativeItem(parent) {
26
27   setFlag(QGraphicsItem::ItemHasNoContents, false);
28 }
29
30 GridLines::~GridLines() {
31
32 }
33
34 void GridLines::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
35   Q_UNUSED(option);
36   Q_UNUSED(widget);
37
38   painter->save();
39   painter->setPen(QPen(Qt::black, 3));
40   painter->drawLines(m_lines, 4);
41
42   painter->setPen(QPen(Qt::white, 1));
43   painter->drawLines(m_lines, 4);
44   painter->restore();
45 }
46
47 void GridLines::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
48   QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
49
50   qreal width = newGeometry.width();
51   qreal height = newGeometry.height();
52   qreal w = newGeometry.width() / 3;
53   qreal h = newGeometry.height() / 3;
54
55   m_lines[0] = QLineF(QPointF(0, h), QPointF(width, h));
56   m_lines[1] = QLineF(QPointF(0, h * 2), QPointF(width, h * 2));
57   m_lines[2] = QLineF(QPointF(w, 0), QPointF(w, height));
58   m_lines[3] = QLineF(QPointF(w * 2, 0), QPointF(w * 2, height));
59 }