1 /*************************************************************************** 2 File : MyWidget.h 3 Project : SciDAVis 4 Description : MDI window widget 5 -------------------------------------------------------------------- 6 Copyright : (C) 2006-2009 Knut Franke (knut.franke*gmx.de) 7 Copyright : (C) 2006-2009 Tilman Benkert (thzs*gmx.net) 8 Copyright : (C) 2006-2007 by Ion Vasilief (ion_vasilief*yahoo.fr) 9 (replace * with @ in the email address) 10 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 * This program is distributed in the hope that it will be useful, * 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 23 * GNU General Public License for more details. * 24 * * 25 * You should have received a copy of the GNU General Public License * 26 * along with this program; if not, write to the Free Software * 27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 28 * Boston, MA 02110-1301 USA * 29 * * 30 ***************************************************************************/ 31 #ifndef WIDGET_H 32 #define WIDGET_H 33 34 #include <QMdiSubWindow> 35 class QEvent; 36 class QCloseEvent; 37 class QString; 38 class Folder; 39 40 /** 41 * \brief Base class of all MDI client windows. 42 * 43 * These are the main objects of every SciDAVis project. 44 * All content (apart from the directory structure) is managed by subclasses of MyWidget. 45 * 46 * \section future_plans Future Plans 47 * Rename to Aspect. 48 * 49 * \sa Folder, ApplicationWindow 50 */ 51 class MyWidget : public QMdiSubWindow 52 { 53 Q_OBJECT 54 55 public: 56 //! Constructor 57 /** 58 * \param label window label 59 * \param parent parent widget 60 * \param name window name 61 * \param f window flags 62 * \sa setCaptionPolicy(), captionPolicy() 63 */ 64 MyWidget(const QString &label = QString(), QWidget *parent = 0, const QString name = 0, 65 Qt::WindowFlags f = Qt::Widget); 66 67 //! Possible window captions. 68 enum CaptionPolicy { 69 Name = 0, //!< caption determined by the window name 70 Label = 1, //!< caption detemined by the window label 71 Both = 2 //!< caption = "name - label" 72 }; 73 enum Status { Hidden = -1, Normal = 0, Minimized = 1, Maximized = 2 }; 74 75 //! Return the window label windowLabel()76 virtual QString windowLabel() { return QString(w_label); }; 77 //! Set the window label setWindowLabel(const QString & s)78 virtual void setWindowLabel(const QString &s) 79 { 80 auto label = s; 81 w_label = label.replace("\n", " ").replace("\t", " "); 82 updateCaption(); 83 }; 84 85 //! Return the window name name()86 virtual QString name() { return objectName(); }; 87 //! Set the window name setName(const QString & s)88 virtual void setName(const QString &s) 89 { 90 setObjectName(s); 91 updateCaption(); 92 }; 93 94 //! Return the caption policy captionPolicy()95 virtual CaptionPolicy captionPolicy() { return caption_policy; }; 96 //! Set the caption policy setCaptionPolicy(CaptionPolicy policy)97 virtual void setCaptionPolicy(CaptionPolicy policy) 98 { 99 caption_policy = policy; 100 updateCaption(); 101 } 102 103 //! Return the creation date birthDate()104 virtual QString birthDate() { return birthdate; }; 105 //! Set the creation date setBirthDate(const QString & s)106 virtual void setBirthDate(const QString &s) { birthdate = s; }; 107 108 //! Return the window status as a string 109 QString aspect(); 110 //! Return the window status flag (hidden, normal, minimized or maximized) status()111 Status status() { return w_status; }; 112 //! Set the window status flag (hidden, normal, minimized or maximized) 113 void setStatus(Status s); 114 saveAsTemplate(const QString &)115 virtual QString saveAsTemplate(const QString &) { return QString(); }; 116 // TODO: 117 //! Not implemented yet restore(const QStringList &)118 virtual void restore(const QStringList &) {}; 119 print()120 virtual void print() {}; exportPDF(const QString &)121 virtual void exportPDF(const QString &) {}; 122 saveToString(const QString &)123 virtual QString saveToString(const QString &) { return QString(); }; 124 125 //!Notifies that a window was hidden by a direct user action 126 virtual void setHidden(); 127 128 // event handlers 129 //! Close event handler 130 /** 131 * Ask the user "delete, hide, or cancel?" if the 132 * "ask on close" flag is set. 133 */ 134 void closeEvent(QCloseEvent *); 135 //! Toggle the "ask on close" flag askOnCloseEvent(bool ask)136 void askOnCloseEvent(bool ask) { askOnClose = ask; }; 137 //! Customizes title bar's context menu) 138 void contextMenuEvent(QContextMenuEvent *e); 139 140 //! Returns the pointer to the parent folder of the window folder()141 Folder *folder() { return parentFolder; }; 142 143 //! Initializes the pointer to the parent folder of the window setFolder(Folder * f)144 void setFolder(Folder *f) { parentFolder = f; }; 145 146 //! Notifies the main application that the window has been modified notifyChanges()147 void notifyChanges() { emit modifiedWindow(this); }; 148 149 void setNormal(); 150 void setMinimized(); 151 void setMaximized(); 152 153 signals: 154 //! Emitted when the window was closed 155 void closedWindow(MyWidget *); 156 //! Emitted when the window was hidden 157 void hiddenWindow(MyWidget *); 158 void modifiedWindow(MyWidget *); 159 void resizedWindow(MyWidget *); 160 //! Emitted when the window status changed 161 void statusChanged(MyWidget *); 162 //! Emitted when the title bar recieves a QContextMenuEvent 163 void showTitleBarMenu(); 164 165 protected slots: 166 //! Set caption according to current CaptionPolicy, name and label 167 void updateCaption(); 168 169 protected: 170 virtual void changeEvent(QEvent *event); 171 //!Pointer to the parent folder of the window 172 Folder *parentFolder; 173 //! The window label 174 /** 175 * \sa setWindowLabel(), windowLabel(), setCaptionPolicy() 176 */ 177 QString w_label; 178 //! The creation date 179 QString birthdate; 180 //! The window status 181 Status w_status; 182 //! The caption policy 183 /** 184 * \sa setCaptionPolicy(), captionPolicy() 185 */ 186 CaptionPolicy caption_policy; 187 //! Toggle on/off: Ask the user "delete, hide, or cancel?" on a close event 188 bool askOnClose; 189 }; 190 191 #endif 192