~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/MyWidget.h

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

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