Debian Codegraph @

src/Gui/MDIView.h

raw
1 /***************************************************************************
2 * Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
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 *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_MDIVIEW_H
24 #define GUI_MDIVIEW_H
25
26 #include <boost/signals2.hpp>
27 #include <QMainWindow>
28 #include <Gui/ActiveObjectList.h>
29 #include <Gui/View.h>
30
31
32 QT_BEGIN_NAMESPACE
33 class QPrinter;
34 QT_END_NAMESPACE
35
36 namespace Gui
37 {
38 class Document;
39 class MainWindow;
40 class ViewProvider;
41 class ViewProviderDocumentObject;
42
43 /** Base class of all windows belonging to a document.
44 * There are two ways of belonging to a document:
45 * \li belong to a fix document
46 * \li always belong to the active document
47 * The latter means whenever the active document is changing the view belongs to
48 * this document. It also means that the view belongs sometimes to no document at
49 * all.
50 * @see TreeView
51 * @see Gui::Document
52 * @see Application
53 * @author Jürgen Riegel, Werner Mayer
54 */
55 class GuiExport MDIView: public QMainWindow, public BaseView
56 {
57 Q_OBJECT
58
59 TYPESYSTEM_HEADER_WITH_OVERRIDE();
60
61 public:
62 /** View constructor
63 * Attach the view to the given document. If the document is zero
64 * the view will attach to the active document. Be aware, there isn't
65 * always an active document.
66 */
67 MDIView(Gui::Document* pcDocument, QWidget* parent, Qt::WindowFlags wflags = Qt::WindowFlags());
68 /** View destructor
69 * Detach the view from the document, if attached.
70 */
71 ~MDIView() override;
72
73 virtual MDIView* clone();
74
75 /// get called when the document is updated
76 void onRelabel(Gui::Document* pDoc) override;
77 virtual void viewAll();
78
79 /// build window title
80 QString buildWindowTitle() const;
81 /// reimplementation of QWidget::setWindowTitle(const QString &title)
82 void setWindowTitle(const QString& title);
83
84 /// Message handler
85 bool onMsg(const char* pMsg, const char** ppReturn) override;
86 /// Message handler test
87 bool onHasMsg(const char* pMsg) const override;
88 /// overwrite when checking on close state
89 bool canClose() override;
90 /// delete itself
91 void deleteSelf() override;
92 PyObject* getPyObject() override;
93 /** @name Printing */
94 //@{
95 public Q_SLOTS:
96 virtual void print(QPrinter* printer);
97
98 public:
99 /** Print content of view */
100 virtual void print();
101 /** Print to PDF file */
102 virtual void printPdf();
103 /** Show a preview dialog */
104 virtual void printPreview();
105 /** Save the printer configuration */
106 void savePrinterSettings(QPrinter* printer);
107 /** Restore the printer configuration */
108 void restorePrinterSettings(QPrinter* printer);
109 //@}
110
111 /** @name Undo/Redo actions */
112 //@{
113 virtual QStringList undoActions() const;
114 virtual QStringList redoActions() const;
115 //@}
116
117 QSize minimumSizeHint() const override;
118
119 /// MDI view mode enum
120 enum ViewMode
121 {
122 Child, /**< Child viewing, view is docked inside the MDI application window */
123 TopLevel, /**< The view becomes a top level window and can be moved outsinde the application
124 window */
125 FullScreen /**< The view goes to full screen viewing */
126 };
127 /**
128 * If \a b is set to \a FullScreen the MDI view is displayed in full screen mode, if \a b
129 * is set to \a TopLevel then it is displayed as an own top-level window, otherwise (\a Normal)
130 * as tabbed window. For more hints refer to the Qt documentation to
131 * QWidget::showFullScreen ().
132 */
133 virtual void setCurrentViewMode(ViewMode mode);
134 ViewMode currentViewMode() const
135 {
136 return currentMode;
137 }
138
139
140 /// access getter for the active object list
141 template<typename _T>
142 inline _T getActiveObject(
143 const char* name,
144 App::DocumentObject** parent = nullptr,
145 std::string* subname = nullptr
146 ) const
147 {
148 return ActiveObjects.getObject<_T>(name, parent, subname);
149 }
150 void setActiveObject(App::DocumentObject* o, const char* n, const char* subname = nullptr)
151 {
152 ActiveObjects.setObject(o, n, subname);
153 }
154 bool hasActiveObject(const char* n) const
155 {
156 return ActiveObjects.hasObject(n);
157 }
158 bool isActiveObject(App::DocumentObject* o, const char* n, const char* subname = nullptr) const
159 {
160 return ActiveObjects.hasObject(o, n, subname);
161 }
162
163 App::DocumentObject* getActiveObjectWithExtension(const Base::Type extensionTypeId) const
164 {
165 return ActiveObjects.getObjectWithExtension(extensionTypeId);
166 }
167
168 /*!
169 * \brief containsViewProvider
170 * Checks if the given view provider is part of this view. The default implementation
171 * returns false.
172 * \return bool
173 */
174 virtual bool containsViewProvider(const ViewProvider*) const
175 {
176 return false;
177 }
178
179 public Q_SLOTS:
180 virtual void setOverrideCursor(const QCursor&);
181 virtual void restoreOverrideCursor();
182
183 Q_SIGNALS:
184 void message(const QString&, int);
185
186 protected Q_SLOTS:
187 /** This method gets called from the main window this view is attached to
188 * whenever the window state of the active view changes.
189 * The default implementation does nothing.
190 */
191 virtual void windowStateChanged(QWidget*);
192
193 protected:
194 void closeEvent(QCloseEvent* e) override;
195 /** \internal */
196 void changeEvent(QEvent* e) override;
197
198 bool eventFilter(QObject* watched, QEvent* e) override;
199
200 void cloneFrom(const MDIView& from);
201
202 protected:
203 PyObject* pythonObject;
204
205 private:
206 ViewMode currentMode;
207 Qt::WindowStates wstate;
208 // list of active objects of this view
209 ActiveObjectList ActiveObjects;
210 using Connection = boost::signals2::connection;
211 Connection connectDelObject; // remove active object upon delete.
212
213 friend class MainWindow;
214 };
215
216 } // namespace Gui
217
218 #endif // GUI_MDIVIEW_H