1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
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 The Qt Company Ltd nor the names of its
21 **     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 #ifndef MAINWINDOW_H
42 #define MAINWINDOW_H
43 
44 #include <QMainWindow>
45 
46 #include "diagramitem.h"
47 
48 class DiagramScene;
49 
50 QT_BEGIN_NAMESPACE
51 class QAction;
52 class QToolBox;
53 class QSpinBox;
54 class QComboBox;
55 class QFontComboBox;
56 class QButtonGroup;
57 class QLineEdit;
58 class QGraphicsTextItem;
59 class QFont;
60 class QToolButton;
61 class QAbstractButton;
62 class QGraphicsView;
63 QT_END_NAMESPACE
64 
65 //! [0]
66 class MainWindow : public QMainWindow
67 {
68     Q_OBJECT
69 
70 public:
71    MainWindow();
72 
73 private slots:
74     void backgroundButtonGroupClicked(QAbstractButton *button);
75     void buttonGroupClicked(int id);
76     void deleteItem();
77     void pointerGroupClicked(int id);
78     void bringToFront();
79     void sendToBack();
80     void itemInserted(DiagramItem *item);
81     void textInserted(QGraphicsTextItem *item);
82     void currentFontChanged(const QFont &font);
83     void fontSizeChanged(const QString &size);
84     void sceneScaleChanged(const QString &scale);
85     void textColorChanged();
86     void itemColorChanged();
87     void lineColorChanged();
88     void textButtonTriggered();
89     void fillButtonTriggered();
90     void lineButtonTriggered();
91     void handleFontChange();
92     void itemSelected(QGraphicsItem *item);
93     void about();
94 
95 private:
96     void createToolBox();
97     void createActions();
98     void createMenus();
99     void createToolbars();
100     QWidget *createBackgroundCellWidget(const QString &text,
101                                         const QString &image);
102     QWidget *createCellWidget(const QString &text,
103                               DiagramItem::DiagramType type);
104     QMenu *createColorMenu(const char *slot, QColor defaultColor);
105     QIcon createColorToolButtonIcon(const QString &image, QColor color);
106     QIcon createColorIcon(QColor color);
107 
108     DiagramScene *scene;
109     QGraphicsView *view;
110 
111     QAction *exitAction;
112     QAction *addAction;
113     QAction *deleteAction;
114 
115     QAction *toFrontAction;
116     QAction *sendBackAction;
117     QAction *aboutAction;
118 
119     QMenu *fileMenu;
120     QMenu *itemMenu;
121     QMenu *aboutMenu;
122 
123     QToolBar *textToolBar;
124     QToolBar *editToolBar;
125     QToolBar *colorToolBar;
126     QToolBar *pointerToolbar;
127 
128     QComboBox *sceneScaleCombo;
129     QComboBox *itemColorCombo;
130     QComboBox *textColorCombo;
131     QComboBox *fontSizeCombo;
132     QFontComboBox *fontCombo;
133 
134     QToolBox *toolBox;
135     QButtonGroup *buttonGroup;
136     QButtonGroup *pointerTypeGroup;
137     QButtonGroup *backgroundButtonGroup;
138     QToolButton *fontColorToolButton;
139     QToolButton *fillColorToolButton;
140     QToolButton *lineColorToolButton;
141     QAction *boldAction;
142     QAction *underlineAction;
143     QAction *italicAction;
144     QAction *textAction;
145     QAction *fillAction;
146     QAction *lineAction;
147 };
148 //! [0]
149 
150 #endif
151