3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
13
#include "backend/cswordmoduleinfo.h"
14
#include "backend/cswordversekey.h"
16
#include "frontend/displaywindow/cdisplaywindow.h"
17
#include "frontend/keychooser/ckeychooser.h"
22
#include <kpopupmenu.h>
23
#include <kapplication.h>
27
#include <qobjectlist.h>
31
#if QT_VERSION < 0x030200
32
//We need this to close all windows with Qt < 3.2
33
#include <qwidgetlist.h>
37
CMDIArea::CMDIArea(QWidget *parent, const char *name )
38
: QWorkspace(parent, name),
41
m_appCaption(QString::null) {
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)
53
/** Initilizes the connectiosn to SIGNALS */
54
void CMDIArea::initConnections() {
55
connect(this, SIGNAL(windowActivated(QWidget*)),
56
this, SLOT(slotClientActivated(QWidget*)));
59
/** Called whan a client window was activated */
60
void CMDIArea::slotClientActivated(QWidget* client) {
61
if (!client || !isUpdatesEnabled()) {
65
CDisplayWindow* sp = dynamic_cast<CDisplayWindow*>(client);
67
if (!sp || !sp->isReady()) {
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
78
CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(w);
79
window->windowActivated( (window == sp) ? true : false);
82
emit sigSetToplevelCaption( ( m_appCaption = client->caption().stripWhiteSpace() ) );
85
/** Reimplementation. Used to make use of the fixedGUIOption part. */
86
void CMDIArea::childEvent( QChildEvent * e ) {
87
QWorkspace::childEvent(e);
89
if ( m_childEvent || !e) {
95
if (!windowList().count()) {
96
m_appCaption = QString::null;
97
emit sigSetToplevelCaption( KApplication::kApplication()->makeStdCaption(m_appCaption) );
98
emit sigLastPresenterClosed();
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
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
109
triggerWindowUpdate();
112
m_childEvent = false;
115
/** Reimplementation */
116
void CMDIArea::resizeEvent(QResizeEvent* e) {
117
QWorkspace::resizeEvent(e);
119
if (isUpdatesEnabled()) {
120
triggerWindowUpdate();
125
void CMDIArea::saveSettings() {}
128
void CMDIArea::readSettings() {}
130
/** Deletes all the presenters in the MDI area. */
131
void CMDIArea::deleteAll() {
132
#if QT_VERSION >= 0x030200
135
QWidgetListIt it(windowList());
136
while (it.current() != 0){
137
it.current()->close();
143
/** Enable / disable autoCascading */
144
void CMDIArea::setGUIOption( const MDIOption& newOption ) {
145
//now do the initial action
146
m_guiOption = newOption;
148
triggerWindowUpdate();
152
void CMDIArea::myTileVertical() {
153
if (!isUpdatesEnabled() || !usableWindowList().count() ) {
157
QPtrList<QWidget> windows = usableWindowList();
159
if ((windows.count() == 1) && windows.at(0)) {
160
m_appCaption = windows.at(0)->caption();
161
windows.at(0)->showMaximized();
164
QWidget* active = activeWindow();
170
void CMDIArea::myTileHorizontal() {
171
if (!isUpdatesEnabled() || !usableWindowList().count() ) {
175
QPtrList<QWidget> windows = usableWindowList();
177
if ((windows.count() == 1) && windows.at(0)) {
178
m_appCaption = windows.at(0)->caption();
179
windows.at(0)/*->parentWidget()*/->showMaximized();
183
QWidget* active = activeWindow();
184
if (active->isMaximized()) {
185
active->showNormal();
189
setUpdatesEnabled(false);
190
int heightForEach = height() / windows.count();
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 );
197
const int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
198
const int actHeight = QMAX(heightForEach, preferredHeight);
200
window->parentWidget()->setGeometry( 0, y, width(), actHeight );
204
setUpdatesEnabled(true);
212
void CMDIArea::myCascade() {
213
if (!isUpdatesEnabled() || !usableWindowList().count() ) {
217
QPtrList<QWidget> windows = usableWindowList();
218
if ( !windows.count() ) {
222
if ((windows.count() == 1) && windows.at(0)) {
223
m_appCaption = windows.at(0)->caption();
224
windows.at(0)->parentWidget()->showMaximized();
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;
235
QWidget* const active = activeWindow();
236
if (active->isMaximized()) {
237
active->showNormal();
241
setUpdatesEnabled(false);
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
249
window->setUpdatesEnabled(false);
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);
256
window->setUpdatesEnabled(true);
259
setUpdatesEnabled(true);
261
active->parentWidget()->setGeometry(x, y, windowWidth, windowHeight);
262
active->parentWidget()->raise();
263
active->setActiveWindow();
270
\fn CMDIArea::emitWindowCaptionChanged()
272
void CMDIArea::emitWindowCaptionChanged() {
273
if (activeWindow()) {
274
m_appCaption = activeWindow()->caption();
277
emit sigSetToplevelCaption(currentApplicationCaption());
282
\fn CMDIArea::usableWindowsCount()
284
QPtrList<QWidget> CMDIArea::usableWindowList() {
285
QPtrList<QWidget> ret;
287
QWidgetList windows = windowList();
288
for ( QWidget* w = windows.first(); w; w = windows.next() ) {
289
if (w->isMinimized() || w->isHidden()) { //not usable for us
299
bool CMDIArea::eventFilter( QObject *o, QEvent *e ) {
303
QWidget* w = dynamic_cast<QWidget*>( o );
304
bool ret = QWorkspace::eventFilter(o,e);
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();
312
else if (!o->inherits("CDisplayWindow")){
313
qDebug("CMDIArea: bad mdi child classname: %s", o->className());
314
//o->dumpObjectInfo();
315
//o->dumpObjectTree();
319
if (w && o->inherits("CDisplayWindow")){
320
if ((e->type() == QEvent::ShowMinimized) ||
321
(e->type() == QEvent::Hide)){
322
triggerWindowUpdate();
326
else if (!o->inherits("CDisplayWindow")){
327
qDebug("bad mdi child classname: %s", o->className());
328
//o->dumpObjectInfo();
329
//o->dumpObjectTree();
332
return ret; // standard event processing
337
\fn CMDIArea::triggerWindowUpdate()
339
void CMDIArea::triggerWindowUpdate() {
340
qDebug("CMDIArea::triggerWindowUpfdate");
342
if (isUpdatesEnabled() && usableWindowList().count() ) {
343
switch (m_guiOption) {
344
case autoTileVertical:
345
QTimer::singleShot(0, this, SLOT(myTileVertical()));
347
case autoTileHorizontal:
348
QTimer::singleShot(0, this, SLOT(myTileHorizontal()));
351
QTimer::singleShot(0, this, SLOT(myCascade()));
354
qDebug("CMDIArea::triggerWindowUpdate: no known m_guiType");