2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
21 #include "gridlines.h"
25 GridLines::GridLines(QDeclarativeItem *parent) :
26 QDeclarativeItem(parent) {
28 GridLines::GridLines(QQuickItem *parent) :
29 QQuickPaintedItem(parent) {
33 setFlag(QGraphicsItem::ItemHasNoContents, false);
37 GridLines::~GridLines() {
42 void GridLines::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
45 QDeclarativeItem::paint(painter, option, widget);
47 void GridLines::paint(QPainter* painter) {
51 painter->setPen(QPen(Qt::black, 3));
52 painter->drawLines(m_lines, 4);
54 painter->setPen(QPen(Qt::white, 1));
55 painter->drawLines(m_lines, 4);
59 void GridLines::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
61 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
63 QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
66 qreal width = newGeometry.width();
67 qreal height = newGeometry.height();
68 qreal w = newGeometry.width() / 3;
69 qreal h = newGeometry.height() / 3;
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));