author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdeui/kmainwindow.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'microkde/kdeui/kmainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/kmainwindow.cpp | 994 |
1 files changed, 994 insertions, 0 deletions
diff --git a/microkde/kdeui/kmainwindow.cpp b/microkde/kdeui/kmainwindow.cpp new file mode 100644 index 0000000..3a2a4d0 --- a/dev/null +++ b/microkde/kdeui/kmainwindow.cpp | |||
@@ -0,0 +1,994 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright | ||
3 | (C) 2000 Reginald Stadlbauer (reggie@kde.org) | ||
4 | (C) 1997 Stephan Kulow (coolo@kde.org) | ||
5 | (C) 1997-2000 Sven Radej (radej@kde.org) | ||
6 | (C) 1997-2000 Matthias Ettrich (ettrich@kde.org) | ||
7 | (C) 1999 Chris Schlaeger (cs@kde.org) | ||
8 | (C) 2002 Joseph Wenninger (jowenn@kde.org) | ||
9 | |||
10 | This library is free software; you can redistribute it and/or | ||
11 | modify it under the terms of the GNU Library General Public | ||
12 | License version 2 as published by the Free Software Foundation. | ||
13 | |||
14 | This library is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | Library General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU Library General Public License | ||
20 | along with this library; see the file COPYING.LIB. If not, write to | ||
21 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
22 | Boston, MA 02111-1307, USA. | ||
23 | */ | ||
24 | #include <qobjectlist.h> | ||
25 | #include <qstringlist.h> | ||
26 | #include <qtimer.h> | ||
27 | #include <qmenubar.h> | ||
28 | #include <qstatusbar.h> | ||
29 | #include <qapplication.h> | ||
30 | |||
31 | |||
32 | #include "kdebug.h" | ||
33 | #include "kmainwindow.h" | ||
34 | #include "kglobalsettings.h" | ||
35 | #include "kactioncollection.h" | ||
36 | |||
37 | class KMainWindowPrivate { | ||
38 | public: | ||
39 | //US bool showHelpMenu:1; | ||
40 | |||
41 | bool autoSaveSettings:1; | ||
42 | bool settingsDirty:1; | ||
43 | bool autoSaveWindowSize:1; | ||
44 | bool care_about_geometry:1; | ||
45 | QString autoSaveGroup; | ||
46 | //US KAccel * kaccel; | ||
47 | //US KMainWindowInterface *m_interface; | ||
48 | KDEPrivate::ToolBarHandler *toolBarHandler; | ||
49 | QTimer* settingsTimer; | ||
50 | KToggleAction *showStatusBarAction; | ||
51 | QRect defaultWindowSize; | ||
52 | }; | ||
53 | |||
54 | static bool no_query_exit = false; | ||
55 | |||
56 | KMainWindow::KMainWindow( QWidget* parent, const char *name, WFlags f ) | ||
57 | : QMainWindow( parent, name, f )/*US, KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 )*/ | ||
58 | { | ||
59 | mQToolBar = 0; | ||
60 | initKMainWindow(name); | ||
61 | } | ||
62 | |||
63 | void KMainWindow::parseGeometry(bool parsewidth) | ||
64 | { | ||
65 | //US the following code is not getting used in the embedded version !! So disable it for now | ||
66 | /*US | ||
67 | |||
68 | assert ( !kapp->geometryArgument().isNull() ); | ||
69 | assert ( d->care_about_geometry ); | ||
70 | |||
71 | #ifndef Q_WS_QWS | ||
72 | // FIXME: (E) Implement something similar for Qt Embedded (or decide we don't need it) | ||
73 | int x, y; | ||
74 | int w, h; | ||
75 | int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); | ||
76 | if (parsewidth) { | ||
77 | QSize minSize = minimumSize(); | ||
78 | QSize maxSize = maximumSize(); | ||
79 | if ( (m & WidthValue) == 0 ) | ||
80 | w = width(); | ||
81 | if ( (m & HeightValue) == 0 ) | ||
82 | h = height(); | ||
83 | w = QMIN(w,maxSize.width()); | ||
84 | h = QMIN(h,maxSize.height()); | ||
85 | w = QMAX(w,minSize.width()); | ||
86 | h = QMAX(h,minSize.height()); | ||
87 | resize(w, h); | ||
88 | } else { | ||
89 | if ( parsewidth && (m & XValue) == 0 ) | ||
90 | x = geometry().x(); | ||
91 | if ( parsewidth && (m & YValue) == 0 ) | ||
92 | y = geometry().y(); | ||
93 | if ( (m & XNegative) ) | ||
94 | x = KApplication::desktop()->width() + x - w; | ||
95 | if ( (m & YNegative) ) | ||
96 | y = KApplication::desktop()->height() + y - h; | ||
97 | move(x, y); | ||
98 | } | ||
99 | #endif | ||
100 | */ | ||
101 | } | ||
102 | |||
103 | KMainWindow::~KMainWindow() | ||
104 | { | ||
105 | delete d->settingsTimer; | ||
106 | QMenuBar* mb = internalMenuBar(); | ||
107 | delete mb; | ||
108 | //US delete d->m_interface; | ||
109 | |||
110 | delete d; | ||
111 | //US memberList->remove( this ); | ||
112 | } | ||
113 | |||
114 | void KMainWindow::initKMainWindow(const char *name) | ||
115 | { | ||
116 | setDockMenuEnabled( FALSE ); | ||
117 | //US mHelpMenu = 0; | ||
118 | |||
119 | //US kapp->setTopWidget( this ); | ||
120 | actionCollection()->setWidget( this ); | ||
121 | //US connect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown())); | ||
122 | //US if( !memberList ) | ||
123 | //US memberList = new QPtrList<KMainWindow>; | ||
124 | /*US | ||
125 | |||
126 | if ( !ksm ) | ||
127 | ksm = ksmd.setObject(new KMWSessionManaged()); | ||
128 | // set a unique object name. Required by session management. | ||
129 | QCString objname; | ||
130 | QCString s; | ||
131 | int unusedNumber; | ||
132 | if ( !name ) | ||
133 | { // no name given | ||
134 | objname = kapp->instanceName() + "-mainwindow#"; | ||
135 | s = objname + '1'; // start adding number immediately | ||
136 | unusedNumber = 1; | ||
137 | } | ||
138 | else if( name[ strlen( name ) - 1 ] == '#' ) | ||
139 | { // trailing # - always add a number | ||
140 | objname = name; | ||
141 | s = objname + '1'; // start adding number immediately | ||
142 | unusedNumber = 1; | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | objname = name; | ||
147 | s = objname; | ||
148 | unusedNumber = 0; // add numbers only when needed | ||
149 | } | ||
150 | for(;;) { | ||
151 | QWidgetList* list = kapp->topLevelWidgets(); | ||
152 | QWidgetListIt it( *list ); | ||
153 | bool found = false; | ||
154 | for( QWidget* w = it.current(); | ||
155 | w != NULL; | ||
156 | ++it, w = it.current()) | ||
157 | if( w != this && w->name() == s ) | ||
158 | { | ||
159 | found = true; | ||
160 | break; | ||
161 | } | ||
162 | delete list; | ||
163 | if( !found ) | ||
164 | break; | ||
165 | s.setNum( ++unusedNumber ); | ||
166 | s = objname + s; | ||
167 | } | ||
168 | setName( s ); | ||
169 | memberList->append( this ); | ||
170 | */ | ||
171 | |||
172 | d = new KMainWindowPrivate; | ||
173 | //US d->showHelpMenu = true; | ||
174 | d->settingsDirty = false; | ||
175 | d->autoSaveSettings = false; | ||
176 | d->autoSaveWindowSize = true; // for compatibility | ||
177 | //US d->kaccel = actionCollection()->kaccel(); | ||
178 | d->toolBarHandler = 0; | ||
179 | d->settingsTimer = 0; | ||
180 | d->showStatusBarAction = NULL; | ||
181 | /*US | ||
182 | if ((d->care_about_geometry == beeing_first)) { | ||
183 | beeing_first = false; | ||
184 | if ( kapp->geometryArgument().isNull() ) // if there is no geometry, it doesn't mater | ||
185 | d->care_about_geometry = false; | ||
186 | else | ||
187 | parseGeometry(false); | ||
188 | } | ||
189 | */ | ||
190 | d->care_about_geometry = false; | ||
191 | |||
192 | //US setCaption( kapp->caption() ); | ||
193 | // attach dcop interface | ||
194 | //US d->m_interface = new KMainWindowInterface(this); | ||
195 | |||
196 | //US if (!kapp->authorize("movable_toolbars")) | ||
197 | //US setDockWindowsMovable(false); | ||
198 | } | ||
199 | |||
200 | KAction *KMainWindow::toolBarMenuAction() | ||
201 | { | ||
202 | if ( !d->toolBarHandler ) | ||
203 | return 0; | ||
204 | |||
205 | return d->toolBarHandler->toolBarMenuAction(); | ||
206 | } | ||
207 | |||
208 | bool KMainWindow::canBeRestored( int number ) | ||
209 | { | ||
210 | /*US we do not have and want to save sessioninformation. Use info from the default | ||
211 | application config. | ||
212 | */ | ||
213 | //US if ( !kapp->isRestored() ) | ||
214 | //US return FALSE; | ||
215 | //US KConfig *config = kapp->sessionConfig(); | ||
216 | KConfig *config = KGlobal::config(); | ||
217 | if ( !config ) | ||
218 | return FALSE; | ||
219 | config->setGroup( QString::fromLatin1("Number") ); | ||
220 | int n = config->readNumEntry( QString::fromLatin1("NumberOfWindows") , 1 ); | ||
221 | return number >= 1 && number <= n; | ||
222 | |||
223 | } | ||
224 | |||
225 | const QString KMainWindow::classNameOfToplevel( int number ) | ||
226 | { | ||
227 | /*US we do not have and want to save sessioninformation. Use info from the default | ||
228 | application config. | ||
229 | */ | ||
230 | //US if ( !kapp->isRestored() ) | ||
231 | //US return QString::null; | ||
232 | //US KConfig *config = kapp->sessionConfig(); | ||
233 | KConfig *config = KGlobal::config(); | ||
234 | if ( !config ) | ||
235 | return QString::null; | ||
236 | QString s; | ||
237 | s.setNum( number ); | ||
238 | s.prepend( QString::fromLatin1("WindowProperties") ); | ||
239 | config->setGroup( s ); | ||
240 | if ( !config->hasKey( QString::fromLatin1("ClassName") ) ) | ||
241 | return QString::null; | ||
242 | else | ||
243 | return config->readEntry( QString::fromLatin1("ClassName") ); | ||
244 | } | ||
245 | |||
246 | bool KMainWindow::restore( int number, bool show ) | ||
247 | { | ||
248 | /*US we do not have and want to save sessioninformation. Use info from the default | ||
249 | application config. | ||
250 | */ | ||
251 | if ( !canBeRestored( number ) ) | ||
252 | return FALSE; | ||
253 | //US KConfig *config = kapp->sessionConfig(); | ||
254 | KConfig *config = KGlobal::config(); | ||
255 | |||
256 | if ( readPropertiesInternal( config, number ) ){ | ||
257 | if ( show ) | ||
258 | KMainWindow::show(); | ||
259 | return FALSE; | ||
260 | } | ||
261 | return FALSE; | ||
262 | |||
263 | } | ||
264 | |||
265 | void KMainWindow::setCaption( const QString &caption ) | ||
266 | { | ||
267 | //US setPlainCaption( kapp->makeStdCaption(caption) ); | ||
268 | setPlainCaption( caption ); | ||
269 | } | ||
270 | |||
271 | void KMainWindow::setCaption( const QString &caption, bool modified ) | ||
272 | { | ||
273 | //US setPlainCaption( kapp->makeStdCaption(caption, true, modified) ); | ||
274 | setPlainCaption( caption + "modified:" ); | ||
275 | } | ||
276 | |||
277 | void KMainWindow::setPlainCaption( const QString &caption ) | ||
278 | { | ||
279 | QMainWindow::setCaption( caption ); | ||
280 | #ifndef Q_WS_QWS | ||
281 | //US the following is disabled for the embedded version | ||
282 | //US NETWinInfo info( qt_xdisplay(), winId(), qt_xrootwin(), 0 ); | ||
283 | //US info.setName( caption.utf8().data() ); | ||
284 | #endif | ||
285 | } | ||
286 | |||
287 | void KMainWindow::slotStateChanged(const QString &newstate) | ||
288 | { | ||
289 | stateChanged(newstate, KXMLGUIClient::StateNoReverse); | ||
290 | } | ||
291 | |||
292 | /* | ||
293 | * Get rid of this for KDE 4.0 | ||
294 | */ | ||
295 | void KMainWindow::slotStateChanged(const QString &newstate, | ||
296 | KXMLGUIClient::ReverseStateChange reverse) | ||
297 | { | ||
298 | stateChanged(newstate, reverse); | ||
299 | } | ||
300 | |||
301 | void KMainWindow::closeEvent ( QCloseEvent *e ) | ||
302 | { | ||
303 | // Save settings if auto-save is enabled, and settings have changed | ||
304 | if (d->settingsDirty && d->autoSaveSettings) | ||
305 | saveAutoSaveSettings(); | ||
306 | |||
307 | if (queryClose()) { | ||
308 | e->accept(); | ||
309 | |||
310 | int not_withdrawn = 0; | ||
311 | /*US | ||
312 | QPtrListIterator<KMainWindow> it(*KMainWindow::memberList); | ||
313 | for (it.toFirst(); it.current(); ++it){ | ||
314 | if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this ) | ||
315 | not_withdrawn++; | ||
316 | } | ||
317 | */ | ||
318 | if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted? | ||
319 | /*US | ||
320 | if ( queryExit() && !kapp->sessionSaving()) { // Yes, Quit app? | ||
321 | // don't call queryExit() twice | ||
322 | disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown())); | ||
323 | kapp->deref(); // ...and quit aplication. | ||
324 | } else { | ||
325 | // cancel closing, it's stupid to end up with no windows at all.... | ||
326 | e->ignore(); | ||
327 | } | ||
328 | */ | ||
329 | //US we have no sessionmanagement. Simply close app. | ||
330 | if ( queryExit() ) { // Yes, Quit app? | ||
331 | qDebug("KMainWindow::closeEvent: Exit application ???"); | ||
332 | // don't call queryExit() twice | ||
333 | //US disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown())); | ||
334 | } | ||
335 | |||
336 | } | ||
337 | } | ||
338 | } | ||
339 | |||
340 | bool KMainWindow::queryExit() | ||
341 | { | ||
342 | return TRUE; | ||
343 | } | ||
344 | |||
345 | bool KMainWindow::queryClose() | ||
346 | { | ||
347 | return TRUE; | ||
348 | } | ||
349 | |||
350 | void KMainWindow::saveGlobalProperties( KConfig* ) | ||
351 | { | ||
352 | } | ||
353 | |||
354 | void KMainWindow::readGlobalProperties( KConfig* ) | ||
355 | { | ||
356 | } | ||
357 | |||
358 | void KMainWindow::savePropertiesInternal( KConfig *config, int number ) | ||
359 | { | ||
360 | bool oldASWS = d->autoSaveWindowSize; | ||
361 | d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size | ||
362 | |||
363 | QString s; | ||
364 | s.setNum(number); | ||
365 | s.prepend(QString::fromLatin1("WindowProperties")); | ||
366 | config->setGroup(s); | ||
367 | |||
368 | // store objectName, className, Width and Height for later restoring | ||
369 | // (Only useful for session management) | ||
370 | config->writeEntry(QString::fromLatin1("ObjectName"), name()); | ||
371 | config->writeEntry(QString::fromLatin1("ClassName"), className()); | ||
372 | |||
373 | saveMainWindowSettings(config); // Menubar, statusbar and Toolbar settings. | ||
374 | |||
375 | s.setNum(number); | ||
376 | config->setGroup(s); | ||
377 | saveProperties(config); | ||
378 | |||
379 | d->autoSaveWindowSize = oldASWS; | ||
380 | } | ||
381 | |||
382 | void KMainWindow::setStandardToolBarMenuEnabled( bool enable ) | ||
383 | { | ||
384 | if ( enable ) | ||
385 | { | ||
386 | if ( d->toolBarHandler ) | ||
387 | return; | ||
388 | |||
389 | d->toolBarHandler = new KDEPrivate::ToolBarHandler( this ); | ||
390 | |||
391 | /*US if ( factory() ) | ||
392 | factory()->addClient( d->toolBarHandler ); | ||
393 | */ | ||
394 | } | ||
395 | else | ||
396 | { | ||
397 | if ( !d->toolBarHandler ) | ||
398 | return; | ||
399 | /*US | ||
400 | if ( factory() ) | ||
401 | factory()->removeClient( d->toolBarHandler ); | ||
402 | */ | ||
403 | delete d->toolBarHandler; | ||
404 | d->toolBarHandler = 0; | ||
405 | } | ||
406 | |||
407 | } | ||
408 | |||
409 | bool KMainWindow::isStandardToolBarMenuEnabled() const | ||
410 | { | ||
411 | return ( d->toolBarHandler != 0 ); | ||
412 | } | ||
413 | |||
414 | void KMainWindow::createStandardStatusBarAction(){ | ||
415 | if(!d->showStatusBarAction){ | ||
416 | d->showStatusBarAction = KStdAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection()); | ||
417 | connect(d->showStatusBarAction, SIGNAL(toggled(bool)), statusBar(), SLOT(setShown(bool))); | ||
418 | if(internalStatusBar()) | ||
419 | d->showStatusBarAction->setChecked(!internalStatusBar()->isHidden()); | ||
420 | } | ||
421 | } | ||
422 | |||
423 | QToolBar *KMainWindow::tBar( ) | ||
424 | { | ||
425 | if ( ! mQToolBar ) | ||
426 | mQToolBar = new QToolBar( this ); | ||
427 | return mQToolBar; | ||
428 | } | ||
429 | |||
430 | KToolBar *KMainWindow::toolBar( const char * name ) | ||
431 | { | ||
432 | |||
433 | if (!name) | ||
434 | name = "mainToolBar"; | ||
435 | KToolBar *tb = (KToolBar*)child( name, "KToolBar" ); | ||
436 | if ( tb ) | ||
437 | return tb; | ||
438 | bool honor_mode = (name == "mainToolBar"); | ||
439 | |||
440 | /*US | ||
441 | if ( builderClient() ) | ||
442 | return new KToolBar(this, name, honor_mode); // XMLGUI constructor | ||
443 | else | ||
444 | */ | ||
445 | return new KToolBar(this, Top, false, name, honor_mode ); // non-XMLGUI | ||
446 | } | ||
447 | |||
448 | QPtrListIterator<KToolBar> KMainWindow::toolBarIterator() | ||
449 | { | ||
450 | toolbarList.clear(); | ||
451 | QPtrList<QToolBar> lst; | ||
452 | for ( int i = (int)QMainWindow::Unmanaged; i <= (int)Minimized; ++i ) { | ||
453 | lst = toolBars( (ToolBarDock)i ); | ||
454 | for ( QToolBar *tb = lst.first(); tb; tb = lst.next() ) { | ||
455 | if ( !tb->inherits( "KToolBar" ) ) | ||
456 | continue; | ||
457 | toolbarList.append( (KToolBar*)tb ); | ||
458 | } | ||
459 | } | ||
460 | return QPtrListIterator<KToolBar>( toolbarList ); | ||
461 | } | ||
462 | |||
463 | void KMainWindow::setAutoSaveSettings( const QString & groupName, bool saveWindowSize ) | ||
464 | { | ||
465 | d->autoSaveSettings = true; | ||
466 | d->autoSaveGroup = groupName; | ||
467 | d->autoSaveWindowSize = saveWindowSize; | ||
468 | // Get notified when the user moves a toolbar around | ||
469 | //US connect( this, SIGNAL( dockWindowPositionChanged( QDockWindow * ) ), | ||
470 | //US this, SLOT( setSettingsDirty() ) ); | ||
471 | connect( this, SIGNAL( toolBarPositionChanged(QToolBar *) ), | ||
472 | this, SLOT( setSettingsDirty() ) ); | ||
473 | |||
474 | |||
475 | // Get default values | ||
476 | //US int scnum = QApplication::desktop()->screenNumber(parentWidget()); | ||
477 | //US QRect desk = QApplication::desktop()->screenGeometry(scnum); | ||
478 | QRect desk = KGlobalSettings::desktopGeometry(0); | ||
479 | |||
480 | d->defaultWindowSize = QRect(desk.width(), width(), desk.height(), height()); | ||
481 | // Now read the previously saved settings | ||
482 | applyMainWindowSettings( KGlobal::config(), groupName ); | ||
483 | } | ||
484 | |||
485 | |||
486 | void KMainWindow::resetAutoSaveSettings() | ||
487 | { | ||
488 | d->autoSaveSettings = false; | ||
489 | if ( d->settingsTimer ) | ||
490 | d->settingsTimer->stop(); | ||
491 | } | ||
492 | |||
493 | bool KMainWindow::autoSaveSettings() const | ||
494 | { | ||
495 | return d->autoSaveSettings; | ||
496 | } | ||
497 | |||
498 | QString KMainWindow::autoSaveGroup() const | ||
499 | { | ||
500 | return d->autoSaveGroup; | ||
501 | } | ||
502 | |||
503 | void KMainWindow::saveAutoSaveSettings() | ||
504 | { | ||
505 | ASSERT( d->autoSaveSettings ); | ||
506 | //kdDebug(200) << "KMainWindow::saveAutoSaveSettings -> saving settings" << endl; | ||
507 | saveMainWindowSettings( KGlobal::config(), d->autoSaveGroup ); | ||
508 | KGlobal::config()->sync(); | ||
509 | d->settingsDirty = false; | ||
510 | if ( d->settingsTimer ) | ||
511 | d->settingsTimer->stop(); | ||
512 | } | ||
513 | |||
514 | void KMainWindow::createGUI( const QString &xmlfile, bool _conserveMemory ) | ||
515 | { | ||
516 | // disabling the updates prevents unnecessary redraws | ||
517 | setUpdatesEnabled( false ); | ||
518 | |||
519 | // just in case we are rebuilding, let's remove our old client | ||
520 | //US guiFactory()->removeClient( this ); | ||
521 | |||
522 | // make sure to have an empty GUI | ||
523 | QMenuBar* mb = internalMenuBar(); | ||
524 | if ( mb ) | ||
525 | mb->clear(); | ||
526 | |||
527 | (void)toolBarIterator(); // make sure toolbarList is most-up-to-date | ||
528 | toolbarList.setAutoDelete( true ); | ||
529 | toolbarList.clear(); | ||
530 | toolbarList.setAutoDelete( false ); | ||
531 | /*US | ||
532 | // don't build a help menu unless the user ask for it | ||
533 | if (d->showHelpMenu) { | ||
534 | // we always want a help menu | ||
535 | if (helpMenu2 == 0) | ||
536 | helpMenu2 = new KHelpMenu(this, instance()->aboutData(), true, | ||
537 | actionCollection()); | ||
538 | } | ||
539 | |||
540 | // we always want to load in our global standards file | ||
541 | setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) ); | ||
542 | |||
543 | // now, merge in our local xml file. if this is null, then that | ||
544 | // means that we will be only using the global file | ||
545 | if ( !xmlfile.isNull() ) { | ||
546 | setXMLFile( xmlfile, true ); | ||
547 | } else { | ||
548 | QString auto_file(instance()->instanceName() + "ui.rc"); | ||
549 | setXMLFile( auto_file, true ); | ||
550 | } | ||
551 | |||
552 | // make sure we don't have any state saved already | ||
553 | setXMLGUIBuildDocument( QDomDocument() ); | ||
554 | |||
555 | // do the actual GUI building | ||
556 | guiFactory()->addClient( this ); | ||
557 | |||
558 | // try and get back *some* of our memory | ||
559 | if ( _conserveMemory ) | ||
560 | { | ||
561 | // before freeing the memory allocated by the DOM document we also | ||
562 | // free all memory allocated internally in the KXMLGUIFactory for | ||
563 | // the menubar and the toolbars . This however implies that we | ||
564 | // have to take care of deleting those widgets ourselves. For | ||
565 | // destruction this is no problem, but when rebuilding we have | ||
566 | // to take care of that (and we want to rebuild the GUI when | ||
567 | // using stuff like the toolbar editor ). | ||
568 | // In addition we have to take care of not removing containers | ||
569 | // like popupmenus, defined in the XML document. | ||
570 | // this code should probably go into a separate method in KMainWindow. | ||
571 | // there's just one problem: I'm bad in finding names ;-) , so | ||
572 | // I skipped this ;-) | ||
573 | |||
574 | QDomDocument doc = domDocument(); | ||
575 | |||
576 | QDomElement e = doc.documentElement().firstChild().toElement(); | ||
577 | for (; !e.isNull(); e = e.nextSibling().toElement() ) { | ||
578 | if ( e.tagName().lower() == "toolbar" ) | ||
579 | factory_->resetContainer( e.attribute( "name" ) ); | ||
580 | else if ( e.tagName().lower() == "menubar" ) | ||
581 | factory_->resetContainer( e.tagName(), true ); | ||
582 | } | ||
583 | |||
584 | conserveMemory(); | ||
585 | } | ||
586 | */ | ||
587 | setUpdatesEnabled( true ); | ||
588 | updateGeometry(); | ||
589 | } | ||
590 | |||
591 | void KMainWindow::saveMainWindowSettings(KConfig *config, const QString &configGroup) | ||
592 | { | ||
593 | kdDebug(200) << "KMainWindow::saveMainWindowSettings " << configGroup << endl; | ||
594 | //US QStrList entryList; | ||
595 | QStringList entryList; | ||
596 | QString oldGroup; | ||
597 | |||
598 | if (!configGroup.isEmpty()) | ||
599 | { | ||
600 | oldGroup = config->group(); | ||
601 | config->setGroup(configGroup); | ||
602 | } | ||
603 | |||
604 | // Called by session management - or if we want to save the window size anyway | ||
605 | if ( d->autoSaveWindowSize ) | ||
606 | saveWindowSize( config ); | ||
607 | |||
608 | QStatusBar* sb = internalStatusBar(); | ||
609 | if (sb) { | ||
610 | entryList.clear(); | ||
611 | if ( sb->isHidden() ) | ||
612 | entryList.append("Disabled"); | ||
613 | else | ||
614 | entryList.append("Enabled"); | ||
615 | |||
616 | if(sb->isHidden()) | ||
617 | //US config->writeEntry(QString::fromLatin1("StatusBar"), entryList, ';'); | ||
618 | config->writeEntry(QString::fromLatin1("StatusBar"), entryList); | ||
619 | else | ||
620 | config->deleteEntry(QString::fromLatin1("StatusBar")); | ||
621 | } | ||
622 | |||
623 | QMenuBar* mb = internalMenuBar(); | ||
624 | if (mb) { | ||
625 | entryList.clear(); | ||
626 | if ( mb->isHidden() ) | ||
627 | entryList.append("Disabled"); | ||
628 | else | ||
629 | entryList.append("Enabled"); | ||
630 | |||
631 | // By default we don't hide. | ||
632 | if(mb->isHidden()) | ||
633 | //US config->writeEntry(QString::fromLatin1("MenuBar"), entryList, ';'); | ||
634 | config->writeEntry(QString::fromLatin1("MenuBar"), entryList); | ||
635 | else | ||
636 | config->deleteEntry(QString::fromLatin1("MenuBar")); | ||
637 | } | ||
638 | |||
639 | int n = 1; // Toolbar counter. toolbars are counted from 1, | ||
640 | KToolBar *toolbar = 0; | ||
641 | QPtrListIterator<KToolBar> it( toolBarIterator() ); | ||
642 | while ( ( toolbar = it.current() ) ) { | ||
643 | ++it; | ||
644 | QString group; | ||
645 | if (!configGroup.isEmpty()) | ||
646 | { | ||
647 | // Give a number to the toolbar, but prefer a name if there is one, | ||
648 | // because there's no real guarantee on the ordering of toolbars | ||
649 | group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name()); | ||
650 | group.prepend(" Toolbar"); | ||
651 | group.prepend(configGroup); | ||
652 | } | ||
653 | toolbar->saveSettings(config, group); | ||
654 | n++; | ||
655 | } | ||
656 | if (!configGroup.isEmpty()) | ||
657 | config->setGroup(oldGroup); | ||
658 | } | ||
659 | |||
660 | bool KMainWindow::readPropertiesInternal( KConfig *config, int number ) | ||
661 | { | ||
662 | if ( number == 1 ) | ||
663 | readGlobalProperties( config ); | ||
664 | |||
665 | // in order they are in toolbar list | ||
666 | QString s; | ||
667 | s.setNum(number); | ||
668 | s.prepend(QString::fromLatin1("WindowProperties")); | ||
669 | |||
670 | config->setGroup(s); | ||
671 | |||
672 | // restore the object name (window role) | ||
673 | if ( config->hasKey(QString::fromLatin1("ObjectName" )) ) | ||
674 | setName( config->readEntry(QString::fromLatin1("ObjectName")).latin1()); // latin1 is right here | ||
675 | |||
676 | applyMainWindowSettings(config); // Menubar, statusbar and toolbar settings. | ||
677 | |||
678 | s.setNum(number); | ||
679 | config->setGroup(s); | ||
680 | readProperties(config); | ||
681 | return true; | ||
682 | } | ||
683 | |||
684 | void KMainWindow::applyMainWindowSettings(KConfig *config, const QString &configGroup) | ||
685 | { | ||
686 | kdDebug(200) << "KMainWindow::applyMainWindowSettings" << endl; | ||
687 | QString entry; | ||
688 | //US QStrList entryList; | ||
689 | QStringList entryList; | ||
690 | int i = 0; // Number of entries in list | ||
691 | |||
692 | if (!configGroup.isEmpty()) | ||
693 | config->setGroup(configGroup); | ||
694 | |||
695 | restoreWindowSize(config); | ||
696 | |||
697 | QStatusBar* sb = internalStatusBar(); | ||
698 | if (sb) { | ||
699 | entryList.clear(); | ||
700 | //US i = config->readListEntry (QString::fromLatin1("StatusBar"), entryList, ';'); | ||
701 | entryList = config->readListEntry (QString::fromLatin1("StatusBar")); | ||
702 | entry = entryList.first(); | ||
703 | if (entry == QString::fromLatin1("Disabled")) | ||
704 | sb->hide(); | ||
705 | else | ||
706 | sb->show(); | ||
707 | if(d->showStatusBarAction) | ||
708 | d->showStatusBarAction->setChecked(!sb->isHidden()); | ||
709 | } | ||
710 | |||
711 | QMenuBar* mb = internalMenuBar(); | ||
712 | if (mb) { | ||
713 | entryList.clear(); | ||
714 | //US i = config->readListEntry (QString::fromLatin1("MenuBar"), entryList, ';'); | ||
715 | entryList = config->readListEntry (QString::fromLatin1("MenuBar")); | ||
716 | entry = entryList.first(); | ||
717 | if (entry==QString::fromLatin1("Disabled")) | ||
718 | { | ||
719 | mb->hide(); | ||
720 | } else | ||
721 | { | ||
722 | mb->show(); | ||
723 | } | ||
724 | } | ||
725 | |||
726 | int n = 1; // Toolbar counter. toolbars are counted from 1, | ||
727 | KToolBar *toolbar; | ||
728 | QPtrListIterator<KToolBar> it( toolBarIterator() ); // must use own iterator | ||
729 | |||
730 | for ( ; it.current(); ++it) { | ||
731 | toolbar= it.current(); | ||
732 | QString group; | ||
733 | if (!configGroup.isEmpty()) | ||
734 | { | ||
735 | // Give a number to the toolbar, but prefer a name if there is one, | ||
736 | // because there's no real guarantee on the ordering of toolbars | ||
737 | group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name()); | ||
738 | group.prepend(" Toolbar"); | ||
739 | group.prepend(configGroup); | ||
740 | } | ||
741 | toolbar->applySettings(config, group); | ||
742 | n++; | ||
743 | } | ||
744 | |||
745 | finalizeGUI( true ); | ||
746 | } | ||
747 | |||
748 | void KMainWindow::finalizeGUI( bool force ) | ||
749 | { | ||
750 | //kdDebug(200) << "KMainWindow::finalizeGUI force=" << force << endl; | ||
751 | // The whole reason for this is that moveToolBar relies on the indexes | ||
752 | // of the other toolbars, so in theory it should be called only once per | ||
753 | // toolbar, but in increasing order of indexes. | ||
754 | // Since we can't do that immediately, we move them, and _then_ | ||
755 | // we call positionYourself again for each of them, but this time | ||
756 | // the toolbariterator should give them in the proper order. | ||
757 | // Both the XMLGUI and applySettings call this, hence "force" for the latter. | ||
758 | QPtrListIterator<KToolBar> it( toolBarIterator() ); | ||
759 | for ( ; it.current() ; ++ it ) | ||
760 | it.current()->positionYourself( force ); | ||
761 | |||
762 | d->settingsDirty = false; | ||
763 | } | ||
764 | |||
765 | void KMainWindow::saveWindowSize( KConfig * config ) const | ||
766 | { | ||
767 | /*US | ||
768 | int scnum = QApplication::desktop()->screenNumber(parentWidget()); | ||
769 | QRect desk = QApplication::desktop()->screenGeometry(scnum); | ||
770 | */ | ||
771 | QRect desk = KGlobalSettings::desktopGeometry(0); | ||
772 | |||
773 | QRect size( desk.width(), width(), desk.height(), height() ); | ||
774 | if(size != d->defaultWindowSize){ | ||
775 | config->writeEntry(QString::fromLatin1("Width %1").arg(desk.width()), width() ); | ||
776 | config->writeEntry(QString::fromLatin1("Height %1").arg(desk.height()), height() ); | ||
777 | } | ||
778 | else{ | ||
779 | config->deleteEntry(QString::fromLatin1("Width %1").arg(desk.width())); | ||
780 | config->deleteEntry(QString::fromLatin1("Height %1").arg(desk.height())); | ||
781 | } | ||
782 | } | ||
783 | |||
784 | void KMainWindow::restoreWindowSize( KConfig * config ) | ||
785 | { | ||
786 | if (d->care_about_geometry) { | ||
787 | parseGeometry(true); | ||
788 | } else { | ||
789 | // restore the size | ||
790 | /*US int scnum = QApplication::desktop()->screenNumber(parentWidget()); | ||
791 | QRect desk = QApplication::desktop()->screenGeometry(scnum); | ||
792 | */ | ||
793 | QRect desk = KGlobalSettings::desktopGeometry(0); | ||
794 | |||
795 | QSize size( config->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ), | ||
796 | config->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) ); | ||
797 | if (size.isEmpty()) { | ||
798 | // try the KDE 2.0 way | ||
799 | size = QSize( config->readNumEntry( QString::fromLatin1("Width"), 0 ), | ||
800 | config->readNumEntry( QString::fromLatin1("Height"), 0 ) ); | ||
801 | if (!size.isEmpty()) { | ||
802 | // make sure the other resolutions don't get old settings | ||
803 | config->writeEntry( QString::fromLatin1("Width"), 0 ); | ||
804 | config->writeEntry( QString::fromLatin1("Height"), 0 ); | ||
805 | } | ||
806 | } | ||
807 | if ( !size.isEmpty() ) | ||
808 | resize( size ); | ||
809 | } | ||
810 | } | ||
811 | |||
812 | bool KMainWindow::initialGeometrySet() const | ||
813 | { | ||
814 | return d->care_about_geometry; | ||
815 | } | ||
816 | |||
817 | void KMainWindow::ignoreInitialGeometry() | ||
818 | { | ||
819 | d->care_about_geometry = false; | ||
820 | } | ||
821 | |||
822 | void KMainWindow::setSettingsDirty() | ||
823 | { | ||
824 | //kdDebug(200) << "KMainWindow::setSettingsDirty" << endl; | ||
825 | d->settingsDirty = true; | ||
826 | if ( d->autoSaveSettings ) | ||
827 | { | ||
828 | // Use a timer to save "immediately" user-wise, but not too immediately | ||
829 | // (to compress calls and save only once, in case of multiple changes) | ||
830 | if ( !d->settingsTimer ) | ||
831 | { | ||
832 | d->settingsTimer = new QTimer( this ); | ||
833 | connect( d->settingsTimer, SIGNAL( timeout() ), SLOT( saveAutoSaveSettings() ) ); | ||
834 | } | ||
835 | d->settingsTimer->start( 500, true ); | ||
836 | } | ||
837 | } | ||
838 | |||
839 | bool KMainWindow::settingsDirty() const | ||
840 | { | ||
841 | return d->settingsDirty; | ||
842 | } | ||
843 | |||
844 | QString KMainWindow::settingsGroup() const | ||
845 | { | ||
846 | return d->autoSaveGroup; | ||
847 | } | ||
848 | |||
849 | void KMainWindow::resizeEvent( QResizeEvent * ) | ||
850 | { | ||
851 | if ( d->autoSaveWindowSize ) | ||
852 | setSettingsDirty(); | ||
853 | } | ||
854 | |||
855 | bool KMainWindow::hasMenuBar() | ||
856 | { | ||
857 | return (internalMenuBar()); | ||
858 | } | ||
859 | |||
860 | //US KMenuBar *KMainWindow::menuBar() | ||
861 | QMenuBar *KMainWindow::menuBar() | ||
862 | { | ||
863 | //US KMenuBar * mb = internalMenuBar(); | ||
864 | QMenuBar * mb = internalMenuBar(); | ||
865 | if ( !mb ) { | ||
866 | //US mb = new KMenuBar( this ); | ||
867 | mb = new QMenuBar( this ); | ||
868 | // trigger a re-layout and trigger a call to the private | ||
869 | // setMenuBar method. | ||
870 | QMainWindow::menuBar(); | ||
871 | } | ||
872 | return mb; | ||
873 | } | ||
874 | |||
875 | //US KStatusBar *KMainWindow::statusBar() | ||
876 | QStatusBar *KMainWindow::statusBar() | ||
877 | { | ||
878 | //US KStatusBar * sb = internalStatusBar(); | ||
879 | QStatusBar * sb = internalStatusBar(); | ||
880 | if ( !sb ) { | ||
881 | //US sb = new KStatusBar( this ); | ||
882 | sb = new QStatusBar( this ); | ||
883 | // trigger a re-layout and trigger a call to the private | ||
884 | // setStatusBar method. | ||
885 | QMainWindow::statusBar(); | ||
886 | } | ||
887 | return sb; | ||
888 | } | ||
889 | |||
890 | void KMainWindow::shuttingDown() | ||
891 | { | ||
892 | // Needed for Qt <= 3.0.3 at least to prevent reentrancy | ||
893 | // when queryExit() shows a dialog. Check before removing! | ||
894 | static bool reentrancy_protection = false; | ||
895 | if (!reentrancy_protection) | ||
896 | { | ||
897 | reentrancy_protection = true; | ||
898 | // call the virtual queryExit | ||
899 | queryExit(); | ||
900 | reentrancy_protection = false; | ||
901 | } | ||
902 | |||
903 | } | ||
904 | |||
905 | //US KMenuBar *KMainWindow::internalMenuBar() | ||
906 | QMenuBar *KMainWindow::internalMenuBar() | ||
907 | { | ||
908 | //US QObjectList *l = queryList( "KMenuBar", 0, false, false ); | ||
909 | QObjectList *l = queryList( "QMenuBar", 0, false, false ); | ||
910 | if ( !l || !l->first() ) { | ||
911 | delete l; | ||
912 | return 0; | ||
913 | } | ||
914 | |||
915 | //US KMenuBar *m = (KMenuBar*)l->first(); | ||
916 | QMenuBar *m = (QMenuBar*)l->first(); | ||
917 | delete l; | ||
918 | return m; | ||
919 | } | ||
920 | |||
921 | //US KStatusBar *KMainWindow::internalStatusBar() | ||
922 | QStatusBar *KMainWindow::internalStatusBar() | ||
923 | { | ||
924 | //US QObjectList *l = queryList( "KStatusBar", 0, false, false ); | ||
925 | QObjectList *l = queryList( "QStatusBar", 0, false, false ); | ||
926 | if ( !l || !l->first() ) { | ||
927 | delete l; | ||
928 | return 0; | ||
929 | } | ||
930 | |||
931 | //US KStatusBar *s = (KStatusBar*)l->first(); | ||
932 | QStatusBar *s = (QStatusBar*)l->first(); | ||
933 | delete l; | ||
934 | return s; | ||
935 | } | ||
936 | |||
937 | void KMainWindow::childEvent( QChildEvent* e) | ||
938 | { | ||
939 | QMainWindow::childEvent( e ); | ||
940 | } | ||
941 | |||
942 | void KMainWindow::paintEvent( QPaintEvent * ) | ||
943 | { | ||
944 | // do nothing | ||
945 | } | ||
946 | |||
947 | QSize KMainWindow::sizeForCentralWidgetSize(QSize size) | ||
948 | { | ||
949 | KToolBar *tb = (KToolBar*)child( "mainToolBar", "KToolBar" ); | ||
950 | if (tb && !tb->isHidden()) { | ||
951 | switch( tb->barPos() ) | ||
952 | { | ||
953 | case KToolBar::Top: | ||
954 | case KToolBar::Bottom: | ||
955 | size += QSize(0, tb->sizeHint().height()); | ||
956 | break; | ||
957 | |||
958 | case KToolBar::Left: | ||
959 | case KToolBar::Right: | ||
960 | size += QSize(toolBar()->sizeHint().width(), 0); | ||
961 | break; | ||
962 | |||
963 | case KToolBar::Flat: | ||
964 | //US size += QSize(0, 3+kapp->style().pixelMetric( QStyle::PM_DockWindowHandleExtent )); | ||
965 | size += QSize(0, tb->sizeHint().height()); | ||
966 | break; | ||
967 | |||
968 | default: | ||
969 | break; | ||
970 | } | ||
971 | } | ||
972 | //US KMenuBar *mb = menuBar(); | ||
973 | QMenuBar *mb = menuBar(); | ||
974 | if (!mb->isHidden()) { | ||
975 | size += QSize(0,mb->heightForWidth(size.width())); | ||
976 | /*US if (style().styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, this)) | ||
977 | size += QSize( 0, dockWindowsMovable() ? 1 : 2); | ||
978 | */ | ||
979 | size += QSize( 0, 2); | ||
980 | } | ||
981 | QStatusBar *sb = internalStatusBar(); | ||
982 | if( sb && !sb->isHidden() ) | ||
983 | size += QSize(0, sb->sizeHint().height()); | ||
984 | |||
985 | return size; | ||
986 | } | ||
987 | |||
988 | // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI; | ||
989 | void KMainWindow::finalizeGUI( KXMLGUIClient *client ) | ||
990 | { /*US KXMLGUIBuilder::finalizeGUI( client );*/ } | ||
991 | |||
992 | void KMainWindow::virtual_hook( int id, void* data ) | ||
993 | { /*US KXMLGUIBuilder::virtual_hook( id, data );*/ | ||
994 | KXMLGUIClient::virtual_hook( id, data ); } | ||