| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef MAINWINDOW_H
|
|---|
| 43 | #define MAINWINDOW_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui/QMainWindow>
|
|---|
| 46 | #include <QtCore/QList>
|
|---|
| 47 | #include <QtGui/QMdiArea>
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | class QDesignerActions;
|
|---|
| 52 | class QDesignerWorkbench;
|
|---|
| 53 | class QDesignerToolWindow;
|
|---|
| 54 | class QDesignerFormWindow;
|
|---|
| 55 | class QDesignerSettings;
|
|---|
| 56 |
|
|---|
| 57 | class QtToolBarManager;
|
|---|
| 58 | class QToolBar;
|
|---|
| 59 | class QMdiArea;
|
|---|
| 60 | class QMenu;
|
|---|
| 61 | class QByteArray;
|
|---|
| 62 | class QMimeData;
|
|---|
| 63 |
|
|---|
| 64 | /* A main window that has a configureable policy on handling close events. If
|
|---|
| 65 | * enabled, it can forward the close event to external handlers.
|
|---|
| 66 | * Base class for windows that can switch roles between tool windows
|
|---|
| 67 | * and main windows. */
|
|---|
| 68 |
|
|---|
| 69 | class MainWindowBase: public QMainWindow
|
|---|
| 70 | {
|
|---|
| 71 | Q_DISABLE_COPY(MainWindowBase)
|
|---|
| 72 | Q_OBJECT
|
|---|
| 73 | protected:
|
|---|
| 74 | explicit MainWindowBase(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Window);
|
|---|
| 75 |
|
|---|
| 76 | public:
|
|---|
| 77 | enum CloseEventPolicy {
|
|---|
| 78 | /* Always accept close events */
|
|---|
| 79 | AcceptCloseEvents,
|
|---|
| 80 | /* Emit a signal with the event, have it handled elsewhere */
|
|---|
| 81 | EmitCloseEventSignal };
|
|---|
| 82 |
|
|---|
| 83 | CloseEventPolicy closeEventPolicy() const { return m_policy; }
|
|---|
| 84 | void setCloseEventPolicy(CloseEventPolicy pol) { m_policy = pol; }
|
|---|
| 85 |
|
|---|
| 86 | static QList<QToolBar *> createToolBars(const QDesignerActions *actions, bool singleToolBar);
|
|---|
| 87 | static QString mainWindowTitle();
|
|---|
| 88 |
|
|---|
| 89 | // Use the minor Qt version as settings versions to avoid conflicts
|
|---|
| 90 | static int settingsVersion();
|
|---|
| 91 |
|
|---|
| 92 | signals:
|
|---|
| 93 | void closeEventReceived(QCloseEvent *e);
|
|---|
| 94 |
|
|---|
| 95 | protected:
|
|---|
| 96 | virtual void closeEvent(QCloseEvent *e);
|
|---|
| 97 | private:
|
|---|
| 98 | CloseEventPolicy m_policy;
|
|---|
| 99 | };
|
|---|
| 100 |
|
|---|
| 101 | /* An MdiArea that listens for desktop file manager file drop events and emits
|
|---|
| 102 | * a signal to open a dropped file. */
|
|---|
| 103 | class DockedMdiArea : public QMdiArea
|
|---|
| 104 | {
|
|---|
| 105 | Q_DISABLE_COPY(DockedMdiArea)
|
|---|
| 106 | Q_OBJECT
|
|---|
| 107 | public:
|
|---|
| 108 | explicit DockedMdiArea(const QString &extension, QWidget *parent = 0);
|
|---|
| 109 |
|
|---|
| 110 | signals:
|
|---|
| 111 | void fileDropped(const QString &);
|
|---|
| 112 |
|
|---|
| 113 | protected:
|
|---|
| 114 | bool event (QEvent *event);
|
|---|
| 115 |
|
|---|
| 116 | private:
|
|---|
| 117 | QStringList uiFiles(const QMimeData *d) const;
|
|---|
| 118 |
|
|---|
| 119 | const QString m_extension;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | // Convenience class that manages a QtToolBarManager and an action to trigger
|
|---|
| 123 | // it on a mainwindow.
|
|---|
| 124 | class ToolBarManager : public QObject
|
|---|
| 125 | {
|
|---|
| 126 | Q_OBJECT
|
|---|
| 127 | Q_DISABLE_COPY(ToolBarManager)
|
|---|
| 128 | public:
|
|---|
| 129 | explicit ToolBarManager(QMainWindow *configureableMainWindow,
|
|---|
| 130 | QWidget *parent,
|
|---|
| 131 | QMenu *toolBarMenu,
|
|---|
| 132 | const QDesignerActions *actions,
|
|---|
| 133 | const QList<QToolBar *> &toolbars,
|
|---|
| 134 | const QList<QDesignerToolWindow*> &toolWindows);
|
|---|
| 135 |
|
|---|
| 136 | QByteArray saveState(int version = 0) const;
|
|---|
| 137 | bool restoreState(const QByteArray &state, int version = 0);
|
|---|
| 138 |
|
|---|
| 139 | private slots:
|
|---|
| 140 | void configureToolBars();
|
|---|
| 141 | void updateToolBarMenu();
|
|---|
| 142 |
|
|---|
| 143 | private:
|
|---|
| 144 | QMainWindow *m_configureableMainWindow;
|
|---|
| 145 | QWidget *m_parent;
|
|---|
| 146 | QMenu *m_toolBarMenu;
|
|---|
| 147 | QtToolBarManager *m_manager;
|
|---|
| 148 | QAction *m_configureAction;
|
|---|
| 149 | QList<QToolBar *> m_toolbars;
|
|---|
| 150 | };
|
|---|
| 151 |
|
|---|
| 152 | /* Main window to be used for docked mode */
|
|---|
| 153 | class DockedMainWindow : public MainWindowBase {
|
|---|
| 154 | Q_OBJECT
|
|---|
| 155 | Q_DISABLE_COPY(DockedMainWindow)
|
|---|
| 156 | public:
|
|---|
| 157 | typedef QList<QDesignerToolWindow*> DesignerToolWindowList;
|
|---|
| 158 | typedef QList<QDockWidget *> DockWidgetList;
|
|---|
| 159 |
|
|---|
| 160 | explicit DockedMainWindow(QDesignerWorkbench *wb,
|
|---|
| 161 | QMenu *toolBarMenu,
|
|---|
| 162 | const DesignerToolWindowList &toolWindows);
|
|---|
| 163 |
|
|---|
| 164 | // Create a MDI subwindow for the form.
|
|---|
| 165 | QMdiSubWindow *createMdiSubWindow(QWidget *fw, Qt::WindowFlags f, const QKeySequence &designerCloseActionShortCut);
|
|---|
| 166 |
|
|---|
| 167 | QMdiArea *mdiArea() const;
|
|---|
| 168 |
|
|---|
| 169 | DockWidgetList addToolWindows(const DesignerToolWindowList &toolWindows);
|
|---|
| 170 |
|
|---|
| 171 | void restoreSettings(const QDesignerSettings &s, const DockWidgetList &dws, const QRect &desktopArea);
|
|---|
| 172 | void saveSettings(QDesignerSettings &) const;
|
|---|
| 173 |
|
|---|
| 174 | signals:
|
|---|
| 175 | void fileDropped(const QString &);
|
|---|
| 176 | void formWindowActivated(QDesignerFormWindow *);
|
|---|
| 177 |
|
|---|
| 178 | private slots:
|
|---|
| 179 | void slotSubWindowActivated(QMdiSubWindow*);
|
|---|
| 180 |
|
|---|
| 181 | private:
|
|---|
| 182 | ToolBarManager *m_toolBarManager;
|
|---|
| 183 | };
|
|---|
| 184 |
|
|---|
| 185 | QT_END_NAMESPACE
|
|---|
| 186 |
|
|---|
| 187 | #endif // MAINWINDOW_H
|
|---|