~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/cmdiarea.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
#include "cmdiarea.h"
 
13
#include "backend/cswordmoduleinfo.h"
 
14
#include "backend/cswordversekey.h"
 
15
 
 
16
#include "frontend/displaywindow/cdisplaywindow.h"
 
17
#include "frontend/keychooser/ckeychooser.h"
 
18
 
 
19
#include "config.h"
 
20
 
 
21
//KDE includes
 
22
#include <kpopupmenu.h>
 
23
#include <kapplication.h>
 
24
#include <klocale.h>
 
25
 
 
26
//QT includes
 
27
#include <qobjectlist.h>
 
28
#include <qtimer.h>
 
29
#include <qevent.h>
 
30
#include <qtimer.h>
 
31
#if QT_VERSION < 0x030200
 
32
//We need this to close all windows with Qt < 3.2
 
33
#include <qwidgetlist.h>
 
34
#endif
 
35
 
 
36
 
 
37
CMDIArea::CMDIArea(QWidget *parent, const char *name )
 
38
: QWorkspace(parent, name),
 
39
m_guiOption(Nothing),
 
40
m_childEvent(false),
 
41
m_appCaption(QString::null) {
 
42
        initView();
 
43
        initConnections();
 
44
        readSettings();
 
45
}
 
46
 
 
47
 
 
48
/** Initializes the view of the MDI area */
 
49
void CMDIArea::initView() {
 
50
        setPaletteBackgroundColor( parentWidget()->paletteBackgroundColor() ); //work around a KDE bug (IMHO was in KDE 2.x)
 
51
}
 
52
 
 
53
/** Initilizes the connectiosn to SIGNALS */
 
54
void CMDIArea::initConnections() {
 
55
        connect(this, SIGNAL(windowActivated(QWidget*)),
 
56
                        this, SLOT(slotClientActivated(QWidget*)));
 
57
}
 
58
 
 
59
/** Called whan a client window was activated */
 
60
void CMDIArea::slotClientActivated(QWidget* client) {
 
61
        if (!client || !isUpdatesEnabled()) {
 
62
                return;
 
63
        }
 
64
 
 
65
        CDisplayWindow* sp = dynamic_cast<CDisplayWindow*>(client);
 
66
        Q_ASSERT(sp);
 
67
        if (!sp || !sp->isReady()) {
 
68
                return;
 
69
        }
 
70
 
 
71
        QWidgetList windows = windowList();
 
72
        for ( QWidget* w = windows.first(); w; w = windows.next() ) {
 
73
                //Don't use!! It would disable accel enabling for the active window, see CDisplayWindow::windowActivated
 
74
                /*    if (w == client)
 
75
                    continue;
 
76
                */
 
77
 
 
78
                CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(w);
 
79
                window->windowActivated( (window == sp) ? true : false);
 
80
        }
 
81
 
 
82
        emit sigSetToplevelCaption( ( m_appCaption = client->caption().stripWhiteSpace() ) );
 
83
}
 
84
 
 
85
/** Reimplementation. Used to make use of the fixedGUIOption part. */
 
86
void CMDIArea::childEvent( QChildEvent * e ) {
 
87
        QWorkspace::childEvent(e);
 
88
 
 
89
        if ( m_childEvent || !e) {
 
90
                return;
 
91
        }
 
92
 
 
93
        m_childEvent = true;
 
94
 
 
95
        if (!windowList().count()) {
 
96
                m_appCaption = QString::null;
 
97
                emit sigSetToplevelCaption( KApplication::kApplication()->makeStdCaption(m_appCaption) );
 
98
                emit sigLastPresenterClosed();
 
99
        }
 
100
 
 
101
        if ((e->inserted() || e->removed()) ) {
 
102
                if (e->inserted() && e->child() && e->child()->inherits("CDisplayWindow")) {
 
103
                        e->child()->installEventFilter(this); //make sure we catch the events of the new window
 
104
                }
 
105
                else if (e->removed() && e->child() && e->child()->inherits("CDisplayWindow")) {
 
106
                        e->child()->removeEventFilter(this); //make sure we catch the events of the new window
 
107
                }
 
108
 
 
109
                triggerWindowUpdate();
 
110
        }
 
111
 
 
112
        m_childEvent = false;
 
113
}
 
114
 
 
115
/** Reimplementation */
 
116
void CMDIArea::resizeEvent(QResizeEvent* e) {
 
117
        QWorkspace::resizeEvent(e);
 
118
 
 
119
        if (isUpdatesEnabled()) {
 
120
                triggerWindowUpdate();
 
121
        };
 
122
}
 
123
 
 
124
/**  */
 
125
void CMDIArea::saveSettings() {}
 
126
 
 
127
/**  */
 
128
void CMDIArea::readSettings() {}
 
129
 
 
130
/** Deletes all the presenters in the MDI area. */
 
131
void CMDIArea::deleteAll() {
 
132
#if QT_VERSION >= 0x030200
 
133
        closeAllWindows();
 
134
#else
 
135
        QWidgetListIt it(windowList());
 
136
        while (it.current() != 0){
 
137
                it.current()->close();
 
138
                ++it;
 
139
        }
 
140
#endif
 
141
}
 
142
 
 
143
/** Enable / disable autoCascading */
 
144
void CMDIArea::setGUIOption( const MDIOption& newOption ) {
 
145
        //now do the initial action
 
146
        m_guiOption = newOption;
 
147
 
 
148
        triggerWindowUpdate();
 
149
}
 
150
 
 
151
/**  */
 
152
void CMDIArea::myTileVertical() {
 
153
        if (!isUpdatesEnabled() || !usableWindowList().count() ) {
 
154
                return;
 
155
        }
 
156
 
 
157
        QPtrList<QWidget> windows = usableWindowList();
 
158
 
 
159
        if ((windows.count() == 1) && windows.at(0)) {
 
160
                m_appCaption = windows.at(0)->caption();
 
161
                windows.at(0)->showMaximized();
 
162
        }
 
163
        else {
 
164
                QWidget* active = activeWindow();
 
165
                QWorkspace::tile();
 
166
                active->setFocus();
 
167
        }
 
168
}
 
169
 
 
170
void CMDIArea::myTileHorizontal() {
 
171
        if (!isUpdatesEnabled() || !usableWindowList().count() ) {
 
172
                return;
 
173
        }
 
174
 
 
175
        QPtrList<QWidget> windows = usableWindowList();
 
176
 
 
177
        if ((windows.count() == 1) && windows.at(0)) {
 
178
                m_appCaption = windows.at(0)->caption();
 
179
                windows.at(0)/*->parentWidget()*/->showMaximized();
 
180
        }
 
181
        else {
 
182
 
 
183
                QWidget* active = activeWindow();
 
184
                if (active->isMaximized()) {
 
185
                        active->showNormal();
 
186
                }
 
187
 
 
188
                blockSignals(true);
 
189
                setUpdatesEnabled(false);
 
190
                int heightForEach = height() / windows.count();
 
191
                int y = 0;
 
192
                for ( int i = 0; i < int(windows.count()); ++i ) {
 
193
                        QWidget *window = windows.at(i);
 
194
                        window->parentWidget()->showNormal();
 
195
                        qApp->sendPostedEvents( 0, QEvent::ShowNormal );
 
196
 
 
197
                        const int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
 
198
                        const int actHeight = QMAX(heightForEach, preferredHeight);
 
199
 
 
200
                        window->parentWidget()->setGeometry( 0, y, width(), actHeight );
 
201
                        y += actHeight;
 
202
                }
 
203
 
 
204
                setUpdatesEnabled(true);
 
205
                active->setFocus();
 
206
                blockSignals(false);
 
207
        }
 
208
 
 
209
}
 
210
 
 
211
/**  */
 
212
void CMDIArea::myCascade() {
 
213
        if (!isUpdatesEnabled() || !usableWindowList().count() ) {
 
214
                return;
 
215
        }
 
216
 
 
217
        QPtrList<QWidget> windows = usableWindowList();
 
218
        if ( !windows.count() ) {
 
219
                return;
 
220
        }
 
221
 
 
222
        if ((windows.count() == 1) && windows.at(0)) {
 
223
                m_appCaption = windows.at(0)->caption();
 
224
                windows.at(0)->parentWidget()->showMaximized();
 
225
        }
 
226
        else {
 
227
                const int offsetX = 40;
 
228
                const int offsetY = 40;
 
229
                const int windowWidth =  width() - (windows.count()-1)*offsetX;
 
230
                const int windowHeight = height() - (windows.count()-1)*offsetY;
 
231
 
 
232
                int x = 0;
 
233
                int y = 0;
 
234
 
 
235
                QWidget* const active = activeWindow();
 
236
                if (active->isMaximized()) {
 
237
                        active->showNormal();
 
238
                }
 
239
 
 
240
                blockSignals(true);
 
241
                setUpdatesEnabled(false);
 
242
 
 
243
                for (int i(0); i < int(windows.count()); ++i) {
 
244
                        QWidget* window = windows.at(i);
 
245
                        if (window == active) { //leave out the active window which should be the top window
 
246
                                continue;
 
247
                        }
 
248
 
 
249
                        window->setUpdatesEnabled(false);
 
250
 
 
251
                        window->parentWidget()->raise(); //make it the on-top-of-window-stack window to make sure they're in the right order
 
252
                        window->parentWidget()->setGeometry(x, y, windowWidth, windowHeight);
 
253
                        x += offsetX;
 
254
                        y += offsetY;
 
255
 
 
256
                        window->setUpdatesEnabled(true);
 
257
                }
 
258
 
 
259
                setUpdatesEnabled(true);
 
260
 
 
261
                active->parentWidget()->setGeometry(x, y, windowWidth, windowHeight);
 
262
                active->parentWidget()->raise();
 
263
                active->setActiveWindow();
 
264
 
 
265
                blockSignals(false);
 
266
        }
 
267
}
 
268
 
 
269
/*!
 
270
    \fn CMDIArea::emitWindowCaptionChanged()
 
271
 */
 
272
void CMDIArea::emitWindowCaptionChanged() {
 
273
        if (activeWindow()) {
 
274
                m_appCaption = activeWindow()->caption();
 
275
        }
 
276
 
 
277
        emit sigSetToplevelCaption(currentApplicationCaption());
 
278
}
 
279
 
 
280
 
 
281
/*!
 
282
    \fn CMDIArea::usableWindowsCount()
 
283
 */
 
284
QPtrList<QWidget> CMDIArea::usableWindowList() {
 
285
        QPtrList<QWidget> ret;
 
286
 
 
287
        QWidgetList windows = windowList();
 
288
        for ( QWidget* w = windows.first(); w; w = windows.next() ) {
 
289
                if (w->isMinimized() || w->isHidden()) { //not usable for us
 
290
                        continue;
 
291
                }
 
292
 
 
293
                ret.append( w );
 
294
        }
 
295
 
 
296
        return ret;
 
297
}
 
298
 
 
299
bool CMDIArea::eventFilter( QObject *o, QEvent *e ) {
 
300
        Q_ASSERT(o);
 
301
        Q_ASSERT(e);
 
302
 
 
303
        QWidget* w = dynamic_cast<QWidget*>( o );
 
304
        bool ret = QWorkspace::eventFilter(o,e);
 
305
 
 
306
#if QT_VERSION >= 0x030300
 
307
        if ( w && (e->type() == QEvent::WindowStateChange) ) {
 
308
                if (o->inherits("CDisplayWindow") && ((w->windowState() & Qt::WindowMinimized) || w->isHidden())) { //window was minimized, trigger a tile/cascade update if necessary
 
309
                        triggerWindowUpdate();
 
310
                        ret = false;
 
311
                }
 
312
                else if (!o->inherits("CDisplayWindow")){
 
313
                        qDebug("CMDIArea: bad mdi child classname: %s", o->className());
 
314
                        //o->dumpObjectInfo();
 
315
                        //o->dumpObjectTree();
 
316
                }
 
317
        }
 
318
#else
 
319
        if (w && o->inherits("CDisplayWindow")){
 
320
                if ((e->type() == QEvent::ShowMinimized) ||
 
321
                        (e->type() == QEvent::Hide)){
 
322
                        triggerWindowUpdate();
 
323
                        ret = false;
 
324
                }
 
325
        }
 
326
        else if (!o->inherits("CDisplayWindow")){
 
327
                qDebug("bad mdi child classname: %s", o->className());
 
328
                //o->dumpObjectInfo();
 
329
                //o->dumpObjectTree();
 
330
        }
 
331
#endif
 
332
        return ret; // standard event processing
 
333
}
 
334
 
 
335
 
 
336
/*!
 
337
    \fn CMDIArea::triggerWindowUpdate()
 
338
 */
 
339
void CMDIArea::triggerWindowUpdate() {
 
340
        qDebug("CMDIArea::triggerWindowUpfdate");
 
341
 
 
342
        if (isUpdatesEnabled() && usableWindowList().count() ) {
 
343
                switch (m_guiOption) {
 
344
                        case autoTileVertical:
 
345
                        QTimer::singleShot(0, this, SLOT(myTileVertical()));
 
346
                        break;
 
347
                        case autoTileHorizontal:
 
348
                        QTimer::singleShot(0, this, SLOT(myTileHorizontal()));
 
349
                        break;
 
350
                        case autoCascade:
 
351
                        QTimer::singleShot(0, this, SLOT(myCascade()));
 
352
                        break;
 
353
                        default:
 
354
                        qDebug("CMDIArea::triggerWindowUpdate: no known m_guiType");
 
355
                        break;
 
356
                }
 
357
        }
 
358
}