1
/****************************************************************************
3
** Copyright (C) 2005-2005 Trolltech AS. All rights reserved.
5
** This file is part of the example classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
31
#include "displayshape.h"
32
#include "displaywidget.h"
34
DisplayWidget::DisplayWidget(QWidget *parent)
40
timer = new QTimer(this);
41
connect(timer, SIGNAL(timeout()), this, SLOT(updateShapes()));
42
timer->setSingleShot(false);
45
setBackgroundRole(QPalette::Base);
46
setMouseTracking(true);
49
void DisplayWidget::appendShape(DisplayShape *shape)
56
void DisplayWidget::insertShape(int position, DisplayShape *shape)
58
shapes.insert(position, shape);
63
QSize DisplayWidget::minimumSizeHint() const
65
return QSize(800, 600);
68
void DisplayWidget::mouseMoveEvent(QMouseEvent *event)
75
foreach (DisplayShape *shape, shapes) {
76
if (shape->isInteractive() && shape->rect().contains(event->pos())
77
&& !shape->contains("fade")) {
78
shape->setMetaData("highlight", true);
80
} else if (shape->isInteractive() && shape->contains("highlight")) {
81
shape->setMetaData("highlight", false);
90
void DisplayWidget::mousePressEvent(QMouseEvent *event)
92
if (event->button() != Qt::LeftButton)
98
foreach (DisplayShape *shape, shapes) {
99
if (shape->rect().contains(event->pos()) && !shape->contains("fade")) {
100
if (shape->contains("action"))
101
emit actionRequested(shape->metaData("action").toString());
102
else if (shape->contains("category"))
103
emit categoryRequested(shape->metaData("category").toString());
104
else if (shape->contains("example"))
105
emit exampleRequested(shape->metaData("example").toString());
106
else if (shape->contains("documentation")) {
107
emit documentationRequested(
108
shape->metaData("documentation").toString());
109
shape->setMetaData("highlight", false);
111
} else if (shape->contains("launch")) {
112
emit launchRequested(shape->metaData("launch").toString());
113
shape->setMetaData("fade", -5);
120
void DisplayWidget::paintEvent(QPaintEvent *event)
124
painter.fillRect(event->rect(), Qt::white);
125
foreach (DisplayShape *shape, shapes)
126
shape->paint(&painter);
130
void DisplayWidget::reset()
135
if (shapes.size() == 0) {
138
emit displayEmpty(); // Note: synchronous signal
143
foreach (DisplayShape *shape, shapes) {
144
shape->setMetaData("fade", -15);
145
shape->setMetaData("fade minimum", 0);
150
DisplayShape *DisplayWidget::shape(int index) const
152
return shapes.value(index);
155
int DisplayWidget::shapesCount() const
157
return shapes.size();
160
void DisplayWidget::enableUpdates()
162
if (!timer->isActive())
166
void DisplayWidget::updateShapes()
168
QVector<DisplayShape*> discard;
172
foreach (DisplayShape *shape, shapes) {
173
QRect oldRect = shape->rect().toRect().adjusted(-1,-1,1,1);
174
if (shape->animate()) {
177
QRect newRect = shape->rect().toRect().adjusted(-1,-1,1,1);
180
if (shape->contains("destroy")) {
181
discard.append(shape);
191
foreach (DisplayShape *shape, discard) {
192
shapes.removeAll(shape);
196
if (shapes.size() == 0 && !empty) {
200
emit displayEmpty(); // Note: synchronous signal