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 "focusrectangle.h"
27 #define OUTER_LENGTH 30
28 #define INNER_LENGTH 29
30 FocusRectangle::FocusRectangle(QDeclarativeItem *parent) :
31 QDeclarativeItem(parent),
34 setFlag(QGraphicsItem::ItemHasNoContents, false);
37 FocusRectangle::~FocusRectangle() {
41 QColor FocusRectangle::color() const {
45 void FocusRectangle::setColor(const QColor& color) {
46 if (color != m_color) {
54 void FocusRectangle::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
57 QDeclarativeItem::paint(painter, option, widget);
61 painter->setPen(QPen(QBrush(Qt::black), OUTER_WIDTH));
62 painter->drawPath(m_outer);
64 painter->setPen(QPen(QBrush(m_color), INNER_WIDTH));
65 painter->drawPath(m_inner);
70 void FocusRectangle::geometryChanged( const QRectF& newGeometry, const QRectF& oldGeometry) {
71 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
78 m_outer = QPainterPath(QPointF(0, OUTER_LENGTH));
80 m_outer.lineTo(OUTER_LENGTH, 0);
83 m_outer.moveTo(w - OUTER_LENGTH, 0);
85 m_outer.lineTo(w, OUTER_LENGTH);
88 m_outer.moveTo(w, h - OUTER_LENGTH);
90 m_outer.lineTo(w - OUTER_LENGTH, h);
93 m_outer.moveTo(OUTER_LENGTH, h);
95 m_outer.lineTo(0, h - OUTER_LENGTH);
99 m_inner = QPainterPath(QPointF(0, INNER_LENGTH));
100 m_inner.lineTo(0, 0);
101 m_inner.lineTo(INNER_LENGTH, 0);
104 m_inner.moveTo(w - INNER_LENGTH, 0);
105 m_inner.lineTo(w, 0);
106 m_inner.lineTo(w, INNER_LENGTH);
109 m_inner.moveTo(w, h - INNER_LENGTH);
110 m_inner.lineTo(w, h);
111 m_inner.lineTo(w - INNER_LENGTH, h);
114 m_inner.moveTo(INNER_LENGTH, h);
115 m_inner.lineTo(0, h);
116 m_inner.lineTo(0, h - INNER_LENGTH);