1
/***************************************************************************
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)
11
***************************************************************************/
13
/***************************************************************************
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. *
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. *
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 *
30
***************************************************************************/
34
#include <QMessageBox>
36
#include <QCloseEvent>
42
MyWidget::MyWidget(const QString& label, QWidget * parent, const char * name, Qt::WFlags f):
46
caption_policy = Both;
50
setObjectName(QString(name));
53
void MyWidget::updateCaption()
55
switch (caption_policy)
58
setWindowTitle(name());
62
if (!windowLabel().isEmpty())
63
setWindowTitle(windowLabel());
65
setWindowTitle(name());
69
if (!windowLabel().isEmpty())
70
setWindowTitle(name() + " - " + windowLabel());
72
setWindowTitle(name());
77
void MyWidget::closeEvent( QCloseEvent *e )
81
switch( QMessageBox::information(this,tr("SciDAVis"),
82
tr("Do you want to hide or delete") + "<p><b>'" + objectName() + "'</b> ?",
83
tr("Delete"), tr("Hide"), tr("Cancel"), 0,2))
86
emit closedWindow(this);
92
emit hiddenWindow(this);
102
emit closedWindow(this);
107
QString MyWidget::aspect()
109
QString s = tr("Normal");
120
return tr("Minimized");
124
return tr("Maximized");
130
// Modifying the title bar menu is somewhat more complicated in Qt4.
131
// Apart from the trivial change in how we intercept the reparenting,
132
// in Qt4 the title bar doesn't exist yet at this point.
133
// Thus, we now also have to intercept the creation of the title bar
134
// in MyWidget::eventFilter.
135
void MyWidget::changeEvent(QEvent *event)
137
if (event->type() == QEvent::ParentChange) {
139
if (parent()) parent()->installEventFilter(this);
141
else if (!isHidden() && event->type() == QEvent::WindowStateChange) {
142
if (((QWindowStateChangeEvent *)event)->oldState() == windowState())
145
if( windowState() & Qt::WindowMinimized )
146
w_status = Minimized;
147
else if ( windowState() & Qt::WindowMaximized )
148
w_status = Maximized;
151
emit statusChanged (this);
153
QWidget::changeEvent(event);
156
bool MyWidget::eventFilter(QObject *object, QEvent *e)
159
if (e->type()==QEvent::ContextMenu && object == titleBar)
161
emit showTitleBarMenu();
162
((QContextMenuEvent*)e)->accept();
165
else if (e->type()==QEvent::ChildAdded && object == parent() && (tmp = qobject_cast<QWidget *>(((QChildEvent*)e)->child())))
167
(titleBar = tmp)->installEventFilter(this);
168
parent()->removeEventFilter(this);
174
void MyWidget::setStatus(Status s)
180
emit statusChanged (this);
183
void MyWidget::setHidden()
186
emit statusChanged (this);
190
void MyWidget::setNormal()
194
emit statusChanged (this);
197
void MyWidget::setMinimized()
200
w_status = Minimized;
201
emit statusChanged (this);
204
void MyWidget::setMaximized()
207
w_status = Maximized;
208
emit statusChanged (this);