2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 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"
24 GridLines::GridLines(QDeclarativeItem *parent) :
25 QDeclarativeItem(parent) {
27 setFlag(QGraphicsItem::ItemHasNoContents, false);
30 GridLines::~GridLines() {
34 void GridLines::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
39 painter->setPen(QPen(Qt::black, 3));
40 painter->drawLines(m_lines, 4);
42 painter->setPen(QPen(Qt::white, 1));
43 painter->drawLines(m_lines, 4);
47 void GridLines::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
48 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
50 qreal width = newGeometry.width();
51 qreal height = newGeometry.height();
52 qreal w = newGeometry.width() / 3;
53 qreal h = newGeometry.height() / 3;
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));