mainwindow.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt Solutions component.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** You may use this file under the terms of the BSD license as follows:
10**
11** "Redistribution and use in source and binary forms, with or without
12** modification, are permitted provided that the following conditions are
13** met:
14** * Redistributions of source code must retain the above copyright
15** notice, this list of conditions and the following disclaimer.
16** * Redistributions in binary form must reproduce the above copyright
17** notice, this list of conditions and the following disclaimer in
18** the documentation and/or other materials provided with the
19** distribution.
20** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21** of its contributors may be used to endorse or promote products derived
22** from this software without specific prior written permission.
23**
24**
25** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#pragma once
42
43#include <QMainWindow>
44#include <QMap>
45
46#include "qtcanvas.h"
47
49class QtProperty;
50
51class QtBrowserIndex;
52
53class CanvasView : public QtCanvasView
54{
55 Q_OBJECT
56public:
57 CanvasView(QWidget* parent = 0) : QtCanvasView(parent), moving(0)
58 {
59 }
60
61 CanvasView(QtCanvas* canvas, QWidget* parent = 0) : QtCanvasView(canvas, parent), moving(0)
62 {
63 }
64
65signals:
68
69protected:
70 void contentsMousePressEvent(QMouseEvent* event);
71 void contentsMouseDoubleClickEvent(QMouseEvent* event);
72 void contentsMouseMoveEvent(QMouseEvent* event);
73
74private:
75 void handleMouseClickEvent(QMouseEvent* event);
76 QPoint moving_start;
77 QtCanvasItem* moving;
78};
79
80class MainWindow : public QMainWindow
81{
82 Q_OBJECT
83public:
84 MainWindow(QWidget* parent = 0);
85
86private slots:
87 void newRectangle();
88 void newEllipse();
89 void newLine();
90 void newText();
91 void deleteObject();
92 void clearAll();
93 void fillView();
94
95
96 void itemClicked(QtCanvasItem* item);
97 void itemMoved(QtCanvasItem* item);
98 void valueChanged(QtProperty* property, const QVariant& value);
99
100private:
101 QtCanvasItem* addRectangle();
102 QtCanvasItem* addEllipse();
103 QtCanvasItem* addLine();
104 QtCanvasItem* addText();
105 void addProperty(QtVariantProperty* property, const QString& id);
106 void updateExpandState();
107
108 QAction* deleteAction;
109
110 class QtVariantPropertyManager* variantManager;
111
112 class QtTreePropertyBrowser* propertyEditor;
113 CanvasView* canvasView;
114 QtCanvas* canvas;
115 QtCanvasItem* currentItem;
116 QMap<QtProperty*, QString> propertyToId;
117 QMap<QString, QtVariantProperty*> idToProperty;
118 QMap<QString, bool> idToExpanded;
119};
void contentsMouseMoveEvent(QMouseEvent *event)
void itemClicked(QtCanvasItem *item)
CanvasView(QWidget *parent=0)
Definition mainwindow.h:57
void itemMoved(QtCanvasItem *item)
void contentsMouseDoubleClickEvent(QMouseEvent *event)
CanvasView(QtCanvas *canvas, QWidget *parent=0)
Definition mainwindow.h:61
void contentsMousePressEvent(QMouseEvent *event)
MainWindow(QWidget *parent=0)
QtCanvasView(QWidget *parent=0)
friend class QtCanvas
Definition qtcanvas.h:507
QtCanvas * canvas() const
Definition qtcanvas.h:474
The QtProperty class encapsulates an instance of a property.
The QtTreePropertyBrowser class provides QTreeWidget based property browser.
The QtVariantPropertyManager class provides and manages QVariant based properties.
The QtVariantProperty class is a convenience class handling QVariant based properties.