• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • widgets
kmainwindow.cpp
Go to the documentation of this file.
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  (C) 2005-2006 Hamish Rodda (rodda@kde.org)
10  (C) 2000-2008 David Faure (faure@kde.org)
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Library General Public
14  License version 2 as published by the Free Software Foundation.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Library General Public License for more details.
20 
21  You should have received a copy of the GNU Library General Public License
22  along with this library; see the file COPYING.LIB. If not, write to
23  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  Boston, MA 02110-1301, USA.
25  */
26 
27 #include "kmainwindow.h"
28 #include "kmainwindow_p.h"
29 #include "kmainwindowiface_p.h"
30 #include "ktoolbarhandler_p.h"
31 #include "kcmdlineargs.h"
32 #include "ktoggleaction.h"
33 #include "ksessionmanager.h"
34 #include "kstandardaction.h"
35 
36 #include <QtCore/QList>
37 #include <QtCore/QObject>
38 #include <QtCore/QTimer>
39 #include <QtGui/QCloseEvent>
40 #include <QtGui/QDesktopWidget>
41 #include <QtGui/QDockWidget>
42 #include <QtGui/QLayout>
43 #include <QtGui/QSessionManager>
44 #include <QtGui/QStyle>
45 #include <QtGui/QWidget>
46 
47 #include <kaction.h>
48 #include <kapplication.h>
49 #include <kauthorized.h>
50 #include <kconfig.h>
51 #include <kdebug.h>
52 #include <kdialog.h>
53 #include <khelpmenu.h>
54 #include <klocale.h>
55 #include <kmenubar.h>
56 #include <kstandarddirs.h>
57 #include <kstatusbar.h>
58 #include <ktoolbar.h>
59 #include <kwindowsystem.h>
60 #include <kconfiggroup.h>
61 #include <kglobalsettings.h>
62 
63 #if defined Q_WS_X11
64 #include <qx11info_x11.h>
65 #include <netwm.h>
66 #endif
67 
68 #include <stdlib.h>
69 #include <ctype.h>
70 #include <assert.h>
71 
72 #include <config.h>
73 
74 static bool no_query_exit = false;
75 
76 static KMenuBar *internalMenuBar(KMainWindow *mw)
77 {
78  return KGlobal::findDirectChild<KMenuBar *>(mw);
79 }
80 
81 static KStatusBar *internalStatusBar(KMainWindow *mw)
82 {
83  // Don't use qFindChild here, it's recursive!
84  // (== slow, but also finds konqueror's per-view statusbars)
85  return KGlobal::findDirectChild<KStatusBar *>(mw);
86 }
87 
95 class DockResizeListener : public QObject
96 {
97 public:
98  DockResizeListener(KMainWindow *win);
99  virtual ~DockResizeListener();
100  virtual bool eventFilter(QObject *watched, QEvent *event);
101 
102 private:
103  KMainWindow *m_win;
104 };
105 
106 DockResizeListener::DockResizeListener(KMainWindow *win) :
107  QObject(win),
108  m_win(win)
109 {
110 }
111 
112 DockResizeListener::~DockResizeListener()
113 {
114 }
115 
116 bool DockResizeListener::eventFilter(QObject *watched, QEvent *event)
117 {
118  switch( event->type() ) {
119  case QEvent::Resize:
120  case QEvent::Move:
121  case QEvent::Hide:
122  m_win->k_ptr->setSettingsDirty(KMainWindowPrivate::CompressCalls);
123  break;
124 
125  default:
126  break;
127  }
128 
129  return QObject::eventFilter(watched, event);
130 }
131 
132 class KMWSessionManager : public KSessionManager
133 {
134 public:
135  KMWSessionManager()
136  {
137  }
138  ~KMWSessionManager()
139  {
140  }
141  bool dummyInit() { return true; }
142  bool saveState( QSessionManager& )
143  {
144  KConfig* config = KApplication::kApplication()->sessionConfig();
145  if ( KMainWindow::memberList().count() ){
146  // According to Jochen Wilhelmy <digisnap@cs.tu-berlin.de>, this
147  // hook is useful for better document orientation
148  KMainWindow::memberList().first()->saveGlobalProperties(config);
149  }
150 
151  int n = 0;
152  foreach (KMainWindow* mw, KMainWindow::memberList()) {
153  n++;
154  mw->savePropertiesInternal(config, n);
155  }
156 
157  KConfigGroup group( config, "Number" );
158  group.writeEntry("NumberOfWindows", n );
159  return true;
160  }
161 
162  bool commitData( QSessionManager& sm )
163  {
164  // not really a fast method but the only compatible one
165  if ( sm.allowsInteraction() ) {
166  bool canceled = false;
167  ::no_query_exit = true;
168 
169  foreach (KMainWindow *window, KMainWindow::memberList()) {
170  if ( !window->testAttribute( Qt::WA_WState_Hidden ) ) {
171  QCloseEvent e;
172  QApplication::sendEvent( window, &e );
173  canceled = !e.isAccepted();
174  if (canceled)
175  break;
176  /* Don't even think_about deleting widgets with
177  Qt::WDestructiveClose flag set at this point. We
178  are faking a close event, but we are *not*_
179  closing the window. The purpose of the faked
180  close event is to prepare the application so it
181  can safely be quit without the user losing data
182  (possibly showing a message box "do you want to
183  save this or that?"). It is possible that the
184  session manager quits the application later
185  (emitting QApplication::aboutToQuit() when this
186  happens), but it is also possible that the user
187  cancels the shutdown, so the application will
188  continue to run.
189  */
190  }
191  }
192  ::no_query_exit = false;
193  if (canceled)
194  return false;
195 
196  KMainWindow* last = 0;
197  foreach (KMainWindow *window, KMainWindow::memberList()) {
198  if ( !window->testAttribute( Qt::WA_WState_Hidden ) ) {
199  last = window;
200  }
201  }
202  if ( last )
203  return last->queryExit();
204  // else
205  return true;
206  }
207 
208  // the user wants it, the user gets it
209  return true;
210  }
211 };
212 
213 K_GLOBAL_STATIC(KMWSessionManager, ksm)
214 K_GLOBAL_STATIC(QList<KMainWindow*>, sMemberList)
215 static bool being_first = true;
216 
217 KMainWindow::KMainWindow( QWidget* parent, Qt::WindowFlags f )
218  : QMainWindow(parent, f), k_ptr(new KMainWindowPrivate)
219 {
220  k_ptr->init(this);
221 }
222 
223 KMainWindow::KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WindowFlags f)
224  : QMainWindow(parent, f), k_ptr(&dd)
225 {
226  k_ptr->init(this);
227 }
228 
229 void KMainWindowPrivate::init(KMainWindow *_q)
230 {
231  KGlobal::ref();
232 
233  // We set allow quit to true when the first mainwindow is created, so that when the refcounting
234  // reaches 0 the application can quit. We don't want this to happen before the first mainwindow
235  // is created, otherwise running a job in main would exit the app too early.
236  KGlobal::setAllowQuit(true);
237 
238  q = _q;
239 
240  q->setAnimated(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects);
241 
242  q->setAttribute( Qt::WA_DeleteOnClose );
243 
244  // We handle this functionality (quitting the app) ourselves, with KGlobal::ref/deref.
245  // This makes apps stay alive even if they only have a systray icon visible, or
246  // a progress widget with "keep open" checked, for instance.
247  // So don't let the default Qt mechanism allow any toplevel widget to just quit the app on us.
248  // Setting WA_QuitOnClose to false for all KMainWindows is not enough, any progress widget
249  // or dialog box would still quit the app...
250  if (qApp)
251  qApp->setQuitOnLastWindowClosed(false);
252 
253  helpMenu = 0;
254 
255  //actionCollection()->setWidget( this );
256  QObject::connect(qApp, SIGNAL(aboutToQuit()), q, SLOT(_k_shuttingDown()));
257  QObject::connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)),
258  q, SLOT(_k_slotSettingsChanged(int)));
259 
260  // force KMWSessionManager creation - someone a better idea?
261  ksm->dummyInit();
262 
263  sMemberList->append( q );
264 
265  settingsDirty = false;
266  autoSaveSettings = false;
267  autoSaveWindowSize = true; // for compatibility
268  //d->kaccel = actionCollection()->kaccel();
269  settingsTimer = 0;
270  sizeTimer = 0;
271  shuttingDown = false;
272  if ((care_about_geometry = being_first)) {
273  being_first = false;
274 
275  QString geometry;
276  KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
277  if (args && args->isSet("geometry"))
278  geometry = args->getOption("geometry");
279 
280  if ( geometry.isNull() ) // if there is no geometry, it doesn't matter
281  care_about_geometry = false;
282  else
283  q->parseGeometry(false);
284  }
285 
286  q->setWindowTitle( KGlobal::caption() );
287 
288  dockResizeListener = new DockResizeListener(_q);
289  letDirtySettings = true;
290 
291  sizeApplied = false;
292 }
293 
294 static bool endsWithHashNumber( const QString& s )
295 {
296  for( int i = s.length() - 1;
297  i > 0;
298  --i )
299  {
300  if( s[ i ] == '#' && i != s.length() - 1 )
301  return true; // ok
302  if( !s[ i ].isDigit())
303  break;
304  }
305  return false;
306 }
307 
308 static inline bool isValidDBusObjectPathCharacter(const QChar &c)
309 {
310  register ushort u = c.unicode();
311  return (u >= 'a' && u <= 'z')
312  || (u >= 'A' && u <= 'Z')
313  || (u >= '0' && u <= '9')
314  || (u == '_') || (u == '/');
315 }
316 
317 void KMainWindowPrivate::polish(KMainWindow *q)
318 {
319  // Set a unique object name. Required by session management, window management, and for the dbus interface.
320  QString objname;
321  QString s;
322  int unusedNumber = 1;
323  const QString name = q->objectName();
324  bool startNumberingImmediately = true;
325  bool tryReuse = false;
326  if ( name.isEmpty() )
327  { // no name given
328  objname = "MainWindow#";
329  }
330  else if( name.endsWith( QLatin1Char( '#' ) ) )
331  { // trailing # - always add a number - KWin uses this for better grouping
332  objname = name;
333  }
334  else if( endsWithHashNumber( name ))
335  { // trailing # with a number - like above, try to use the given number first
336  objname = name;
337  tryReuse = true;
338  startNumberingImmediately = false;
339  }
340  else
341  {
342  objname = name;
343  startNumberingImmediately = false;
344  }
345 
346  s = objname;
347  if ( startNumberingImmediately )
348  s += '1';
349 
350  for(;;) {
351  const QList<QWidget*> list = qApp->topLevelWidgets();
352  bool found = false;
353  foreach ( QWidget* w, list ) {
354  if( w != q && w->objectName() == s )
355  {
356  found = true;
357  break;
358  }
359  }
360  if( !found )
361  break;
362  if( tryReuse ) {
363  objname = name.left( name.length() - 1 ); // lose the hash
364  unusedNumber = 0; // start from 1 below
365  tryReuse = false;
366  }
367  s.setNum( ++unusedNumber );
368  s = objname + s;
369  }
370  q->setObjectName( s );
371  q->winId(); // workaround for setWindowRole() crashing, and set also window role, just in case TT
372  q->setWindowRole( s ); // will keep insisting that object name suddenly should not be used for window role
373 
374  dbusName = '/' + qApp->applicationName() + '/' + q->objectName().replace(QLatin1Char('/'), QLatin1Char('_'));
375  // Clean up for dbus usage: any non-alphanumeric char should be turned into '_'
376  const int len = dbusName.length();
377  for ( int i = 0; i < len; ++i ) {
378  if ( !isValidDBusObjectPathCharacter( dbusName[i] ) )
379  dbusName[i] = QLatin1Char('_');
380  }
381 
382  QDBusConnection::sessionBus().registerObject(dbusName, q, QDBusConnection::ExportScriptableSlots |
383  QDBusConnection::ExportScriptableProperties |
384  QDBusConnection::ExportNonScriptableSlots |
385  QDBusConnection::ExportNonScriptableProperties |
386  QDBusConnection::ExportAdaptors);
387 }
388 
389 void KMainWindowPrivate::setSettingsDirty(CallCompression callCompression)
390 {
391  if (!letDirtySettings) {
392  return;
393  }
394 
395  settingsDirty = true;
396  if (autoSaveSettings) {
397  if (callCompression == CompressCalls) {
398  if (!settingsTimer) {
399  settingsTimer = new QTimer(q);
400  settingsTimer->setInterval(500);
401  settingsTimer->setSingleShot(true);
402  QObject::connect(settingsTimer, SIGNAL(timeout()), q, SLOT(saveAutoSaveSettings()));
403  }
404  settingsTimer->start();
405  } else {
406  q->saveAutoSaveSettings();
407  }
408  }
409 }
410 
411 void KMainWindowPrivate::setSizeDirty()
412 {
413  if (autoSaveWindowSize) {
414  if (!sizeTimer) {
415  sizeTimer = new QTimer(q);
416  sizeTimer->setInterval(500);
417  sizeTimer->setSingleShot(true);
418  QObject::connect(sizeTimer, SIGNAL(timeout()), q, SLOT(_k_slotSaveAutoSaveSize()));
419  }
420  sizeTimer->start();
421  }
422 }
423 
424 void KMainWindow::parseGeometry(bool parsewidth)
425 {
426  K_D(KMainWindow);
427  QString cmdlineGeometry;
428  KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
429  if (args->isSet("geometry"))
430  cmdlineGeometry = args->getOption("geometry");
431 
432  assert ( !cmdlineGeometry.isNull() );
433  assert ( d->care_about_geometry );
434  Q_UNUSED(d); // fix compiler warning in release mode
435 
436 #if defined Q_WS_X11
437  int x, y;
438  int w, h;
439  int m = XParseGeometry( cmdlineGeometry.toLatin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
440  if (parsewidth) {
441  const QSize minSize = minimumSize();
442  const QSize maxSize = maximumSize();
443  if ( !(m & WidthValue) )
444  w = width();
445  if ( !(m & HeightValue) )
446  h = height();
447  w = qMin(w,maxSize.width());
448  h = qMin(h,maxSize.height());
449  w = qMax(w,minSize.width());
450  h = qMax(h,minSize.height());
451  resize(w, h);
452  } else {
453  if ( (m & XNegative) )
454  x = KApplication::desktop()->width() + x - w;
455  else if ( !(m & XValue) )
456  x = geometry().x();
457  if ( (m & YNegative) )
458  y = KApplication::desktop()->height() + y - h;
459  else if ( !(m & YValue) )
460  y = geometry().y();
461 
462  move(x, y);
463  }
464 #endif
465 }
466 
467 KMainWindow::~KMainWindow()
468 {
469  sMemberList->removeAll( this );
470  delete static_cast<QObject *>(k_ptr->dockResizeListener); //so we don't get anymore events after k_ptr is destroyed
471  delete k_ptr;
472  KGlobal::deref();
473 }
474 
475 KMenu* KMainWindow::helpMenu( const QString &aboutAppText, bool showWhatsThis )
476 {
477  K_D(KMainWindow);
478  if(!d->helpMenu) {
479  if ( aboutAppText.isEmpty() )
480  d->helpMenu = new KHelpMenu( this, KGlobal::mainComponent().aboutData(), showWhatsThis);
481  else
482  d->helpMenu = new KHelpMenu( this, aboutAppText, showWhatsThis );
483 
484  if (!d->helpMenu)
485  return 0;
486  }
487 
488  return d->helpMenu->menu();
489 }
490 
491 KMenu* KMainWindow::customHelpMenu( bool showWhatsThis )
492 {
493  K_D(KMainWindow);
494  if (!d->helpMenu) {
495  d->helpMenu = new KHelpMenu( this, QString(), showWhatsThis );
496  connect(d->helpMenu, SIGNAL(showAboutApplication()),
497  this, SLOT(showAboutApplication()));
498  }
499 
500  return d->helpMenu->menu();
501 }
502 
503 bool KMainWindow::canBeRestored( int number )
504 {
505  if ( !qApp->isSessionRestored() )
506  return false;
507  KConfig *config = kapp->sessionConfig();
508  if ( !config )
509  return false;
510 
511  KConfigGroup group( config, "Number" );
512  const int n = group.readEntry( "NumberOfWindows", 1 );
513  return number >= 1 && number <= n;
514 }
515 
516 const QString KMainWindow::classNameOfToplevel( int number )
517 {
518  if ( !qApp->isSessionRestored() )
519  return QString();
520  KConfig *config = kapp->sessionConfig();
521  if ( !config )
522  return QString();
523  QString s;
524  s.setNum( number );
525  s.prepend( QLatin1String("WindowProperties") );
526 
527  KConfigGroup group( config, s );
528  if ( !group.hasKey( "ClassName" ) )
529  return QString();
530  else
531  return group.readEntry( "ClassName" );
532 }
533 
534 bool KMainWindow::restore( int number, bool show )
535 {
536  if ( !canBeRestored( number ) )
537  return false;
538  KConfig *config = kapp->sessionConfig();
539  if ( readPropertiesInternal( config, number ) ){
540  if ( show )
541  KMainWindow::show();
542  return false;
543  }
544  return false;
545 }
546 
547 void KMainWindow::setCaption( const QString &caption )
548 {
549  setPlainCaption( KDialog::makeStandardCaption( caption, this ) );
550 }
551 
552 void KMainWindow::setCaption( const QString &caption, bool modified )
553 {
554  KDialog::CaptionFlags flags = KDialog::HIGCompliantCaption;
555 
556  if ( modified )
557  {
558  flags |= KDialog::ModifiedCaption;
559  }
560 
561  setPlainCaption( KDialog::makeStandardCaption(caption, this, flags) );
562 }
563 
564 void KMainWindow::setPlainCaption( const QString &caption )
565 {
566  setWindowTitle(caption);
567 }
568 
569 void KMainWindow::appHelpActivated( void )
570 {
571  K_D(KMainWindow);
572  if( !d->helpMenu ) {
573  d->helpMenu = new KHelpMenu( this );
574  if ( !d->helpMenu )
575  return;
576  }
577  d->helpMenu->appHelpActivated();
578 }
579 
580 void KMainWindow::closeEvent ( QCloseEvent *e )
581 {
582  K_D(KMainWindow);
583 
584  // Save settings if auto-save is enabled, and settings have changed
585  if (d->settingsTimer && d->settingsTimer->isActive()) {
586  d->settingsTimer->stop();
587  saveAutoSaveSettings();
588  }
589  if (d->sizeTimer && d->sizeTimer->isActive()) {
590  d->sizeTimer->stop();
591  d->_k_slotSaveAutoSaveSize();
592  }
593 
594  if (queryClose()) {
595  e->accept();
596 
597  int not_withdrawn = 0;
598  foreach (KMainWindow* mw, KMainWindow::memberList()) {
599  if ( !mw->isHidden() && mw->isTopLevel() && mw != this )
600  not_withdrawn++;
601  }
602 
603  if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted?
604  if (!( queryExit() && ( !kapp || !kapp->sessionSaving() ) && !d->shuttingDown )) {
605  // cancel closing, it's stupid to end up with no windows at all....
606  e->ignore();
607  }
608  }
609  } else e->ignore(); //if the window should not be closed, don't close it
610 }
611 
612 bool KMainWindow::queryExit()
613 {
614  return true;
615 }
616 
617 bool KMainWindow::queryClose()
618 {
619  return true;
620 }
621 
622 void KMainWindow::saveGlobalProperties( KConfig* )
623 {
624 }
625 
626 void KMainWindow::readGlobalProperties( KConfig* )
627 {
628 }
629 
630 void KMainWindow::showAboutApplication()
631 {
632 }
633 
634 void KMainWindow::savePropertiesInternal( KConfig *config, int number )
635 {
636  K_D(KMainWindow);
637  const bool oldASWS = d->autoSaveWindowSize;
638  d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size
639 
640  QString s;
641  s.setNum(number);
642  s.prepend(QLatin1String("WindowProperties"));
643  KConfigGroup cg(config, s);
644 
645  // store objectName, className, Width and Height for later restoring
646  // (Only useful for session management)
647  cg.writeEntry(QLatin1String("ObjectName"), objectName());
648  cg.writeEntry(QLatin1String("ClassName"), metaObject()->className());
649 
650  saveMainWindowSettings(cg); // Menubar, statusbar and Toolbar settings.
651 
652  s.setNum(number);
653  cg = KConfigGroup(config, s);
654  saveProperties(cg);
655 
656  d->autoSaveWindowSize = oldASWS;
657 }
658 
659 void KMainWindow::saveMainWindowSettings(const KConfigGroup &_cg)
660 {
661  K_D(KMainWindow);
662  //kDebug(200) << "KMainWindow::saveMainWindowSettings " << _cg.name();
663 
664  // Called by session management - or if we want to save the window size anyway
665  if ( d->autoSaveWindowSize )
666  saveWindowSize( _cg );
667 
668  KConfigGroup cg(_cg); // for saving
669 
670  // One day will need to save the version number, but for now, assume 0
671  // Utilise the QMainWindow::saveState() functionality.
672  const QByteArray state = saveState();
673  cg.writeEntry(QString("State"), state.toBase64());
674 
675  QStatusBar* sb = internalStatusBar(this);
676  if (sb) {
677  if(!cg.hasDefault("StatusBar") && !sb->isHidden() )
678  cg.revertToDefault("StatusBar");
679  else
680  cg.writeEntry("StatusBar", sb->isHidden() ? "Disabled" : "Enabled");
681  }
682 
683  QMenuBar* mb = internalMenuBar(this);
684  if (mb) {
685  const QString MenuBar = QLatin1String("MenuBar");
686  if(!cg.hasDefault("MenuBar") && !mb->isHidden() )
687  cg.revertToDefault("MenuBar");
688  else
689  cg.writeEntry("MenuBar", mb->isHidden() ? "Disabled" : "Enabled");
690  }
691 
692  if ( !autoSaveSettings() || cg.name() == autoSaveGroup() ) { // TODO should be cg == d->autoSaveGroup, to compare both kconfig and group name
693  if(!cg.hasDefault("ToolBarsMovable") && !KToolBar::toolBarsLocked())
694  cg.revertToDefault("ToolBarsMovable");
695  else
696  cg.writeEntry("ToolBarsMovable", KToolBar::toolBarsLocked() ? "Disabled" : "Enabled");
697  }
698 
699  int n = 1; // Toolbar counter. toolbars are counted from 1,
700  foreach (KToolBar* toolbar, toolBars()) {
701  QString group("Toolbar");
702  // Give a number to the toolbar, but prefer a name if there is one,
703  // because there's no real guarantee on the ordering of toolbars
704  group += (toolbar->objectName().isEmpty() ? QString::number(n) : QString(" ")+toolbar->objectName());
705 
706  KConfigGroup toolbarGroup(&cg, group);
707  toolbar->saveSettings(toolbarGroup);
708  n++;
709  }
710 }
711 
712 bool KMainWindow::readPropertiesInternal( KConfig *config, int number )
713 {
714  K_D(KMainWindow);
715 
716  const bool oldLetDirtySettings = d->letDirtySettings;
717  d->letDirtySettings = false;
718 
719  if ( number == 1 )
720  readGlobalProperties( config );
721 
722  // in order they are in toolbar list
723  QString s;
724  s.setNum(number);
725  s.prepend(QLatin1String("WindowProperties"));
726 
727  KConfigGroup cg(config, s);
728 
729  // restore the object name (window role)
730  if ( cg.hasKey(QLatin1String("ObjectName" )) )
731  setObjectName( cg.readEntry("ObjectName").toLatin1()); // latin1 is right here
732 
733  d->sizeApplied = false; // since we are changing config file, reload the size of the window
734  // if necessary. Do it before the call to applyMainWindowSettings.
735  applyMainWindowSettings(cg); // Menubar, statusbar and toolbar settings.
736 
737  s.setNum(number);
738  KConfigGroup grp(config, s);
739  readProperties(grp);
740 
741  d->letDirtySettings = oldLetDirtySettings;
742 
743  return true;
744 }
745 
746 void KMainWindow::applyMainWindowSettings(const KConfigGroup &cg, bool force)
747 {
748  K_D(KMainWindow);
749  kDebug(200) << "KMainWindow::applyMainWindowSettings " << cg.name();
750 
751  QWidget *focusedWidget = QApplication::focusWidget();
752 
753  const bool oldLetDirtySettings = d->letDirtySettings;
754  d->letDirtySettings = false;
755 
756  if (!d->sizeApplied) {
757  restoreWindowSize(cg);
758  d->sizeApplied = true;
759  }
760 
761  QStatusBar* sb = internalStatusBar(this);
762  if (sb) {
763  QString entry = cg.readEntry("StatusBar", "Enabled");
764  if ( entry == "Disabled" )
765  sb->hide();
766  else
767  sb->show();
768  }
769 
770  QMenuBar* mb = internalMenuBar(this);
771  if (mb) {
772  QString entry = cg.readEntry ("MenuBar", "Enabled");
773  if ( entry == "Disabled" )
774  mb->hide();
775  else
776  mb->show();
777  }
778 
779  if ( !autoSaveSettings() || cg.name() == autoSaveGroup() ) { // TODO should be cg == d->autoSaveGroup, to compare both kconfig and group name
780  QString entry = cg.readEntry ("ToolBarsMovable", "Disabled");
781  if ( entry == "Disabled" )
782  KToolBar::setToolBarsLocked(true);
783  else
784  KToolBar::setToolBarsLocked(false);
785  }
786 
787  int n = 1; // Toolbar counter. toolbars are counted from 1,
788  foreach (KToolBar* toolbar, toolBars()) {
789  QString group("Toolbar");
790  // Give a number to the toolbar, but prefer a name if there is one,
791  // because there's no real guarantee on the ordering of toolbars
792  group += (toolbar->objectName().isEmpty() ? QString::number(n) : QString(" ")+toolbar->objectName());
793 
794  KConfigGroup toolbarGroup(&cg, group);
795  toolbar->applySettings(toolbarGroup, force);
796  n++;
797  }
798 
799  QByteArray state;
800  if (cg.hasKey("State")) {
801  state = cg.readEntry("State", state);
802  state = QByteArray::fromBase64(state);
803  // One day will need to load the version number, but for now, assume 0
804  restoreState(state);
805  }
806 
807  if (focusedWidget) {
808  focusedWidget->setFocus();
809  }
810 
811  d->settingsDirty = false;
812  d->letDirtySettings = oldLetDirtySettings;
813 }
814 
815 #ifdef Q_WS_WIN
816 
817 /*
818  The win32 implementation for restoring/savin windows size differs
819  from the unix/max implementation in three topics:
820 
821 1. storing and restoring the position, which may not work on x11
822  see http://doc.trolltech.com/4.3/geometry.html#x11-peculiarities
823 2. using QWidget::saveGeometry() and QWidget::restoreGeometry()
824  this would probably be usable on x11 and/or on mac, but I'm unable to
825  check this on unix/mac, so I leave this fix to the x11/mac experts.
826 3. store geometry separately for each resolution -> on unix/max the size
827  and with of the window are already saved separately on non windows
828  system although not using ...Geometry functions -> could also be
829  fixed by x11/mac experts.
830 */
831 void KMainWindow::restoreWindowSize( const KConfigGroup & _cg )
832 {
833  K_D(KMainWindow);
834 
835  int scnum = QApplication::desktop()->screenNumber(window());
836  QRect desk = QApplication::desktop()->screenGeometry(scnum);
837 
838  QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desk.width()).arg(desk.height());
839  QByteArray geometry = _cg.readEntry( geometryKey, QByteArray() );
840  // if first time run, center window
841  if (!restoreGeometry( QByteArray::fromBase64(geometry) ))
842  move( (desk.width()-width())/2, (desk.height()-height())/2 );
843 }
844 
845 void KMainWindow::saveWindowSize( const KConfigGroup & _cg ) const
846 {
847  K_D(const KMainWindow);
848  int scnum = QApplication::desktop()->screenNumber(window());
849  QRect desk = QApplication::desktop()->screenGeometry(scnum);
850 
851  // geometry is saved separately for each resolution
852  QString geometryKey = QString::fromLatin1("geometry-%1-%2").arg(desk.width()).arg(desk.height());
853  QByteArray geometry = saveGeometry();
854  KConfigGroup cg(_cg);
855  cg.writeEntry( geometryKey, geometry.toBase64() );
856 }
857 
858 #elif defined(Q_OS_MAC)
859 
860 void KMainWindow::restoreWindowSize( const KConfigGroup & _cg )
861 {
862 
863  QString geometryKey = QString::fromLatin1("geometry");
864  QByteArray geometry = _cg.readEntry( geometryKey, QByteArray() );
865  kDebug(200) << "restoreWindowSize():" << geometryKey << "=" << geometry;
866  if (!restoreGeometry( QByteArray::fromBase64(geometry) )) {
867  // try first if there data has been stored using the X11-like approach from earlier kdelibs versions.
868  // This code is copied from restoreWindowSize() below.
869  int scnum = QApplication::desktop()->screenNumber(window());
870  QRect desk = QApplication::desktop()->screenGeometry(scnum);
871  const QSize size( _cg.readEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ),
872  _cg.readEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) );
873  if ( !size.isEmpty() ) {
874  kDebug(200) << "restoreWindowSize(): falling back to legacy saved state" << size;
875  if (size.width() > desk.width() || size.height() > desk.height()) {
876  setWindowState( Qt::WindowMaximized );
877  }
878  else {
879  resize( size );
880  }
881  }
882  else {
883  // if first time run, centre window
884  kDebug(200) << "restoreWindowSize(): moving the window to the screen centre of" << desk;
885  move( (desk.width()-width())/2, (desk.height()-height())/2 );
886  }
887  }
888 }
889 
890 void KMainWindow::saveWindowSize( const KConfigGroup & _cg ) const
891 {
892  QString geometryKey = QString::fromLatin1("geometry");
893  QByteArray geometry = saveGeometry();
894  kDebug(200) << "saveWindowSize():" << geometryKey << "=" << geometry;
895  KConfigGroup cg(_cg);
896  cg.writeEntry( geometryKey, geometry.toBase64() );
897 }
898 
899 #else // Q_WS_X11 and select others.
900 void KMainWindow::saveWindowSize( const KConfigGroup & _cg ) const
901 {
902  K_D(const KMainWindow);
903  int scnum = QApplication::desktop()->screenNumber(window());
904  QRect desk = QApplication::desktop()->screenGeometry(scnum);
905 
906  int w, h;
907 #if defined Q_WS_X11
908  // save maximalization as desktop size + 1 in that direction
909  KWindowInfo info = KWindowSystem::windowInfo( winId(), NET::WMState );
910  w = info.state() & NET::MaxHoriz ? desk.width() + 1 : width();
911  h = info.state() & NET::MaxVert ? desk.height() + 1 : height();
912 #else
913  if (isMaximized()) {
914  w = desk.width() + 1;
915  h = desk.height() + 1;
916  } else {
917  w = width();
918  h = height();
919  }
920  //TODO: add "Maximized" property instead "+1" hack
921 #endif
922  KConfigGroup cg(_cg);
923 
924  QRect size( desk.width(), w, desk.height(), h );
925  bool defaultSize = (size == d->defaultWindowSize);
926  QString widthString = QString::fromLatin1("Width %1").arg(desk.width());
927  QString heightString = QString::fromLatin1("Height %1").arg(desk.height());
928  if (!cg.hasDefault(widthString) && defaultSize)
929  cg.revertToDefault(widthString);
930  else
931  cg.writeEntry(widthString, w );
932 
933  if (!cg.hasDefault(heightString) && defaultSize)
934  cg.revertToDefault(heightString);
935  else
936  cg.writeEntry(heightString, h );
937 }
938 
939 void KMainWindow::restoreWindowSize( const KConfigGroup & config )
940 {
941  K_D(KMainWindow);
942  if (d->care_about_geometry) {
943  parseGeometry(true);
944  } else {
945  // restore the size
946  const int scnum = QApplication::desktop()->screenNumber(window());
947  QRect desk = QApplication::desktop()->screenGeometry(scnum);
948 
949  if ( d->defaultWindowSize.isNull() ) // only once
950  d->defaultWindowSize = QRect(desk.width(), width(), desk.height(), height()); // store default values
951  const QSize size( config.readEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ),
952  config.readEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) );
953  if ( !size.isEmpty() ) {
954 #ifdef Q_WS_X11
955  int state = ( size.width() > desk.width() ? NET::MaxHoriz : 0 )
956  | ( size.height() > desk.height() ? NET::MaxVert : 0 );
957  if(( state & NET::Max ) == NET::Max )
958  resize( desk.width(), desk.height() ); // WORKAROUND: this should not be needed. KWindowSystem::setState
959  // should be enough for maximizing. (ereslibre)
960  else if(( state & NET::MaxHoriz ) == NET::MaxHoriz )
961  resize( desk.width(), size.height() );
962  else if(( state & NET::MaxVert ) == NET::MaxVert )
963  resize( size.width(), desk.height() );
964  else
965  resize( size );
966  // QWidget::showMaximized() is both insufficient and broken
967  KWindowSystem::setState( winId(), state );
968 #else
969  if (size.width() > desk.width() || size.height() > desk.height())
970  setWindowState( Qt::WindowMaximized );
971  else
972  resize( size );
973 #endif
974  }
975  }
976 }
977 #endif
978 
979 bool KMainWindow::initialGeometrySet() const
980 {
981  K_D(const KMainWindow);
982  return d->care_about_geometry;
983 }
984 
985 void KMainWindow::ignoreInitialGeometry()
986 {
987  K_D(KMainWindow);
988  d->care_about_geometry = false;
989 }
990 
991 void KMainWindow::setSettingsDirty()
992 {
993  K_D(KMainWindow);
994  d->setSettingsDirty();
995 }
996 
997 bool KMainWindow::settingsDirty() const
998 {
999  K_D(const KMainWindow);
1000  return d->settingsDirty;
1001 }
1002 
1003 void KMainWindow::setAutoSaveSettings( const QString & groupName, bool saveWindowSize )
1004 {
1005  setAutoSaveSettings(KConfigGroup(KGlobal::config(), groupName), saveWindowSize);
1006 }
1007 
1008 void KMainWindow::setAutoSaveSettings( const KConfigGroup & group,
1009  bool saveWindowSize )
1010 {
1011  K_D(KMainWindow);
1012  d->autoSaveSettings = true;
1013  d->autoSaveGroup = group;
1014  d->autoSaveWindowSize = saveWindowSize;
1015 
1016  if (!saveWindowSize && d->sizeTimer) {
1017  d->sizeTimer->stop();
1018  }
1019 
1020  // Now read the previously saved settings
1021  applyMainWindowSettings(d->autoSaveGroup);
1022 }
1023 
1024 void KMainWindow::resetAutoSaveSettings()
1025 {
1026  K_D(KMainWindow);
1027  d->autoSaveSettings = false;
1028  if (d->settingsTimer) {
1029  d->settingsTimer->stop();
1030  }
1031 }
1032 
1033 bool KMainWindow::autoSaveSettings() const
1034 {
1035  K_D(const KMainWindow);
1036  return d->autoSaveSettings;
1037 }
1038 
1039 QString KMainWindow::autoSaveGroup() const
1040 {
1041  K_D(const KMainWindow);
1042  return d->autoSaveSettings ? d->autoSaveGroup.name() : QString();
1043 }
1044 
1045 KConfigGroup KMainWindow::autoSaveConfigGroup() const
1046 {
1047  K_D(const KMainWindow);
1048  return d->autoSaveSettings ? d->autoSaveGroup : KConfigGroup();
1049 }
1050 
1051 void KMainWindow::saveAutoSaveSettings()
1052 {
1053  K_D(KMainWindow);
1054  Q_ASSERT( d->autoSaveSettings );
1055  //kDebug(200) << "KMainWindow::saveAutoSaveSettings -> saving settings";
1056  saveMainWindowSettings(d->autoSaveGroup);
1057  d->autoSaveGroup.sync();
1058  d->settingsDirty = false;
1059 }
1060 
1061 bool KMainWindow::event( QEvent* ev )
1062 {
1063  K_D(KMainWindow);
1064  switch( ev->type() ) {
1065 #if defined(Q_WS_WIN) || defined(Q_OS_MAC)
1066  case QEvent::Move:
1067 #endif
1068  case QEvent::Resize:
1069  d->setSizeDirty();
1070  break;
1071  case QEvent::Polish:
1072  d->polish(this);
1073  break;
1074  case QEvent::ChildPolished:
1075  {
1076  QChildEvent *event = static_cast<QChildEvent*>(ev);
1077  QDockWidget *dock = qobject_cast<QDockWidget*>(event->child());
1078  KToolBar *toolbar = qobject_cast<KToolBar*>(event->child());
1079  QMenuBar *menubar = qobject_cast<QMenuBar*>(event->child());
1080  if (dock) {
1081  connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
1082  this, SLOT(setSettingsDirty()));
1083  connect(dock, SIGNAL(visibilityChanged(bool)),
1084  this, SLOT(setSettingsDirty()), Qt::QueuedConnection);
1085  connect(dock, SIGNAL(topLevelChanged(bool)),
1086  this, SLOT(setSettingsDirty()));
1087 
1088  // there is no signal emitted if the size of the dock changes,
1089  // hence install an event filter instead
1090  dock->installEventFilter(k_ptr->dockResizeListener);
1091  } else if (toolbar) {
1092  // there is no signal emitted if the size of the toolbar changes,
1093  // hence install an event filter instead
1094  toolbar->installEventFilter(k_ptr->dockResizeListener);
1095  } else if (menubar) {
1096  // there is no signal emitted if the size of the menubar changes,
1097  // hence install an event filter instead
1098  menubar->installEventFilter(k_ptr->dockResizeListener);
1099  }
1100  }
1101  break;
1102  case QEvent::ChildRemoved:
1103  {
1104  QChildEvent *event = static_cast<QChildEvent*>(ev);
1105  QDockWidget *dock = qobject_cast<QDockWidget*>(event->child());
1106  KToolBar *toolbar = qobject_cast<KToolBar*>(event->child());
1107  QMenuBar *menubar = qobject_cast<QMenuBar*>(event->child());
1108  if (dock) {
1109  disconnect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
1110  this, SLOT(setSettingsDirty()));
1111  disconnect(dock, SIGNAL(visibilityChanged(bool)),
1112  this, SLOT(setSettingsDirty()));
1113  disconnect(dock, SIGNAL(topLevelChanged(bool)),
1114  this, SLOT(setSettingsDirty()));
1115  dock->removeEventFilter(k_ptr->dockResizeListener);
1116  } else if (toolbar) {
1117  toolbar->removeEventFilter(k_ptr->dockResizeListener);
1118  } else if (menubar) {
1119  menubar->removeEventFilter(k_ptr->dockResizeListener);
1120  }
1121  }
1122  break;
1123  default:
1124  break;
1125  }
1126  return QMainWindow::event( ev );
1127 }
1128 
1129 bool KMainWindow::hasMenuBar()
1130 {
1131  return internalMenuBar(this);
1132 }
1133 
1134 KMenuBar *KMainWindow::menuBar()
1135 {
1136  KMenuBar * mb = internalMenuBar(this);
1137  if ( !mb ) {
1138  mb = new KMenuBar( this );
1139  // trigger a re-layout and trigger a call to the private
1140  // setMenuBar method.
1141  setMenuBar(mb);
1142  }
1143  return mb;
1144 }
1145 
1146 KStatusBar *KMainWindow::statusBar()
1147 {
1148  KStatusBar * sb = internalStatusBar(this);
1149  if ( !sb ) {
1150  sb = new KStatusBar( this );
1151  // trigger a re-layout and trigger a call to the private
1152  // setStatusBar method.
1153  setStatusBar(sb);
1154  }
1155  return sb;
1156 }
1157 
1158 void KMainWindowPrivate::_k_shuttingDown()
1159 {
1160  // Needed for Qt <= 3.0.3 at least to prevent reentrancy
1161  // when queryExit() shows a dialog. Check before removing!
1162  static bool reentrancy_protection = false;
1163  if (!reentrancy_protection)
1164  {
1165  reentrancy_protection = true;
1166  shuttingDown = true;
1167  // call the virtual queryExit
1168  q->queryExit();
1169  reentrancy_protection = false;
1170  }
1171 }
1172 
1173 void KMainWindowPrivate::_k_slotSettingsChanged(int category)
1174 {
1175  Q_UNUSED(category);
1176 
1177  // This slot will be called when the style KCM changes settings that need
1178  // to be set on the already running applications.
1179 
1180  // At this level (KMainWindow) the only thing we need to restore is the
1181  // animations setting (whether the user wants builtin animations or not).
1182 
1183  q->setAnimated(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects);
1184 }
1185 
1186 void KMainWindowPrivate::_k_slotSaveAutoSaveSize()
1187 {
1188  if (autoSaveGroup.isValid()) {
1189  q->saveWindowSize(autoSaveGroup);
1190  }
1191 }
1192 
1193 KToolBar *KMainWindow::toolBar( const QString& name )
1194 {
1195  QString childName = name;
1196  if (childName.isEmpty())
1197  childName = "mainToolBar";
1198 
1199  KToolBar *tb = findChild<KToolBar*>(childName);
1200  if ( tb )
1201  return tb;
1202 
1203  KToolBar* toolbar = new KToolBar(childName, this); // non-XMLGUI toolbar
1204  return toolbar;
1205 }
1206 
1207 QList<KToolBar*> KMainWindow::toolBars() const
1208 {
1209  QList<KToolBar*> ret;
1210 
1211  foreach (QObject* child, children())
1212  if (KToolBar* toolBar = qobject_cast<KToolBar*>(child))
1213  ret.append(toolBar);
1214 
1215  return ret;
1216 }
1217 
1218 QList<KMainWindow*> KMainWindow::memberList() { return *sMemberList; }
1219 
1220 QString KMainWindow::dbusName() const
1221 {
1222  return k_func()->dbusName;
1223 }
1224 
1225 #include "kmainwindow.moc"
1226 
QObject::className
const char * className() const
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
kdialog.h
KGlobal::caption
QString caption()
QMenuBar
kapp
#define kapp
Definition: kapplication.h:56
QWidget::isMaximized
bool isMaximized() const
QEvent
QWidget
KMainWindow::helpMenu
KMenu * helpMenu(const QString &aboutAppText=QString(), bool showWhatsThis=true)
Retrieve the standard help menu.
Definition: kmainwindow.cpp:475
QDesktopWidget::screenGeometry
const QRect screenGeometry(int screen) const
QEvent::type
Type type() const
QWidget::isHidden
bool isHidden() const
KMainWindow::k_ptr
KMainWindowPrivate *const k_ptr
Definition: kmainwindow.h:691
KMainWindow::setSettingsDirty
void setSettingsDirty()
Tell the main window that it should save its settings when being closed.
Definition: kmainwindow.cpp:991
QSize::width
int width() const
KToolBar::setToolBarsLocked
static void setToolBarsLocked(bool locked)
Allows you to lock and unlock all toolbars (i.e., disallow/allow moving of the toobars).
Definition: ktoolbar.cpp:1417
kdebug.h
KMainWindow::savePropertiesInternal
void savePropertiesInternal(KConfig *, int)
Definition: kmainwindow.cpp:634
kapplication.h
being_first
static bool being_first
Definition: kmainwindow.cpp:215
QWidget::window
QWidget * window() const
QByteArray
QDockWidget
KMainWindow::event
virtual bool event(QEvent *event)
Reimplemented to catch QEvent::Polish in order to adjust the object name if needed, once all constructor code for the main window has run.
Definition: kmainwindow.cpp:1061
KSessionManager::saveState
virtual bool saveState(QSessionManager &sm)
See QApplication::saveState() for documentation.
Definition: ksessionmanager.cpp:35
group
kglobalsettings.h
KToolBar::saveSettings
void saveSettings(KConfigGroup &cg)
Save the toolbar settings to group configGroup in config.
Definition: ktoolbar.cpp:828
QSize::isEmpty
bool isEmpty() const
QSessionManager
kauthorized.h
QWidget::setWindowRole
void setWindowRole(const QString &role)
KConfigGroup::hasDefault
bool hasDefault(const QString &key) const
QChar
timeout
int timeout
KCmdLineArgs::parsedArgs
static KCmdLineArgs * parsedArgs(const QByteArray &id=QByteArray())
QString::prepend
QString & prepend(QChar ch)
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
KMainWindow::customHelpMenu
KMenu * customHelpMenu(bool showWhatsThis=true)
Returns the help menu.
Definition: kmainwindow.cpp:491
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
kconfig.h
KCmdLineArgs
KWindowSystem::windowInfo
static KWindowInfo windowInfo(WId win, unsigned long properties, unsigned long properties2=0)
Returns information about window win.
Definition: kwindowsystem_mac.cpp:330
QObject::children
const QObjectList & children() const
KMenuBar
KDE Style-able menubar.
Definition: kmenubar.h:38
KMainWindow::saveWindowSize
void saveWindowSize(const KConfigGroup &config) const
For inherited classes.
Definition: kmainwindow.cpp:845
QDBusConnection::registerObject
bool registerObject(const QString &path, QObject *object, QFlags< QDBusConnection::RegisterOption > options)
endsWithHashNumber
static bool endsWithHashNumber(const QString &s)
Definition: kmainwindow.cpp:294
QWidget::y
int y() const
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
QObject::metaObject
virtual const QMetaObject * metaObject() const
KMainWindow::autoSaveGroup
QString autoSaveGroup() const
KMainWindow::resetAutoSaveSettings
void resetAutoSaveSettings()
Disable the auto-save-settings feature.
Definition: kmainwindow.cpp:1024
KWindowInfo
Information about a window.
Definition: kwindowinfo.h:35
ksessionmanager.h
KMainWindow::~KMainWindow
virtual ~KMainWindow()
Destructor.
Definition: kmainwindow.cpp:467
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QWidget::isTopLevel
bool isTopLevel() const
QRect::height
int height() const
QRect::x
int x() const
QRect::y
int y() const
QDBusConnection::sessionBus
QDBusConnection sessionBus()
KComponentData::aboutData
const KAboutData * aboutData() const
KWindowInfo::state
unsigned long state() const
Returns the window's state flags (see the NET::State enum for details).
Definition: kwindowinfo_mac.cpp:175
KGlobalSettings::self
static KGlobalSettings * self()
Return the KGlobalSettings singleton.
Definition: kglobalsettings.cpp:188
QStatusBar
KMainWindow::classNameOfToplevel
static const QString classNameOfToplevel(int number)
Returns the className() of the number of the toplevel window which should be restored.
Definition: kmainwindow.cpp:516
kstatusbar.h
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
KMainWindow::ignoreInitialGeometry
void ignoreInitialGeometry()
Definition: kmainwindow.cpp:985
KStatusBar
KDE statusbar widget
Definition: kstatusbar.h:59
QDesktopWidget::screenNumber
int screenNumber(const QWidget *widget) const
KGlobal::ref
void ref()
KApplication::kApplication
static KApplication * kApplication()
Returns the current application object.
Definition: kapplication.cpp:603
KCmdLineArgs::isSet
bool isSet(const QByteArray &option) const
QMainWindow::setStatusBar
void setStatusBar(QStatusBar *statusbar)
isValidDBusObjectPathCharacter
static bool isValidDBusObjectPathCharacter(const QChar &c)
Definition: kmainwindow.cpp:308
QWidget::geometry
const QRect & geometry() const
config
KSharedConfigPtr config()
QString::isNull
bool isNull() const
KMainWindow::restoreWindowSize
void restoreWindowSize(const KConfigGroup &config)
For inherited classes Note that a -geometry on the command line has priority.
Definition: kmainwindow.cpp:831
KMainWindow::menuBar
KMenuBar * menuBar()
Returns a pointer to the menu bar.
Definition: kmainwindow.cpp:1134
KMainWindow::restore
bool restore(int number, bool show=true)
Try to restore the toplevel widget as defined by number (1..X).
Definition: kmainwindow.cpp:534
KDialog::ModifiedCaption
Definition: kdialog.h:444
QWidget::width
int width() const
QCloseEvent
QWidget::resize
void resize(int w, int h)
KMainWindow::setPlainCaption
virtual void setPlainCaption(const QString &caption)
Make a plain caption without any modifications.
Definition: kmainwindow.cpp:564
QWidget::setWindowState
void setWindowState(QFlags< Qt::WindowState > windowState)
QWidget::minimumSize
QSize minimumSize() const
QObject::name
const char * name() const
QRect
KMainWindow::saveGlobalProperties
virtual void saveGlobalProperties(KConfig *sessionConfig)
Save your application-wide properties.
Definition: kmainwindow.cpp:622
QMainWindow::setAnimated
void setAnimated(bool enabled)
QWidget::testAttribute
bool testAttribute(Qt::WidgetAttribute attribute) const
QString::number
QString number(int n, int base)
KMainWindow::readProperties
virtual void readProperties(const KConfigGroup &)
Read your instance-specific properties.
Definition: kmainwindow.h:592
KSessionManager
Provides highlevel access to session management on a per-object base.
Definition: ksessionmanager.h:45
QList::append
void append(const T &value)
KMainWindow::saveAutoSaveSettings
void saveAutoSaveSettings()
This slot should only be called in case you reimplement closeEvent() and if you are using the "auto-s...
Definition: kmainwindow.cpp:1051
KHelpMenu
Standard KDE help menu with dialog boxes.
Definition: khelpmenu.h:110
QEvent::isAccepted
bool isAccepted() const
QEvent::ignore
void ignore()
netwm.h
KGlobal::deref
void deref()
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
QMainWindow::setMenuBar
void setMenuBar(QMenuBar *menuBar)
QTimer
QWidget::x
int x() const
KDialog::makeStandardCaption
static QString makeStandardCaption(const QString &userCaption, QWidget *window=0, CaptionFlags flags=HIGCompliantCaption)
Builds a caption that contains the application name along with the userCaption using a standard layou...
Definition: kdialog.cpp:442
internalMenuBar
static KMenuBar * internalMenuBar(KMainWindow *mw)
Definition: kmainwindow.cpp:76
KMainWindow
KDE top level main window
Definition: kmainwindow.h:106
QWidget::restoreGeometry
bool restoreGeometry(const QByteArray &geometry)
QObject
QWidget::setFocus
void setFocus()
QMainWindow::event
virtual bool event(QEvent *event)
khelpmenu.h
kcmdlineargs.h
QObject::objectName
objectName
QString::isEmpty
bool isEmpty() const
QApplication::focusWidget
QWidget * focusWidget()
KDialog::HIGCompliantCaption
Definition: kdialog.h:445
KGlobal::setAllowQuit
void setAllowQuit(bool allowQuit)
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
kmenubar.h
KMainWindow::queryExit
virtual bool queryExit()
Called before the very last window is closed, either by the user or indirectly by the session manager...
Definition: kmainwindow.cpp:612
NET::MaxVert
indicates that the window is vertically maximized.
Definition: netwm_def.h:441
QWidget::move
void move(int x, int y)
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
KMainWindow::saveMainWindowSettings
void saveMainWindowSettings(const KConfigGroup &config)
Save settings for statusbar, menubar and toolbar to their respective groups in the config group confi...
Definition: kmainwindow.cpp:659
internalStatusBar
static KStatusBar * internalStatusBar(KMainWindow *mw)
Definition: kmainwindow.cpp:81
QObject::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
KMainWindow::autoSaveSettings
bool autoSaveSettings() const
KMainWindow::canBeRestored
static bool canBeRestored(int number)
If the session did contain so high a number, true is returned, else false.
Definition: kmainwindow.cpp:503
KMainWindow::readPropertiesInternal
bool readPropertiesInternal(KConfig *, int)
Definition: kmainwindow.cpp:712
QWidget::winId
WId winId() const
KMainWindow::hasMenuBar
bool hasMenuBar()
Returns true, if there is a menubar.
KMainWindow::queryClose
virtual bool queryClose()
Called before the window is closed, either by the user or indirectly by the session manager...
Definition: kmainwindow.cpp:617
QString
kstandardaction.h
QList
QWidget::hide
void hide()
QChar::unicode
ushort unicode() const
QSessionManager::allowsInteraction
bool allowsInteraction()
KMainWindow::closeEvent
virtual void closeEvent(QCloseEvent *)
Reimplemented to call the queryClose() and queryExit() handlers.
Definition: kmainwindow.cpp:580
KMainWindow::setCaption
virtual void setCaption(const QString &caption)
Makes a KDE compliant caption (window title).
Definition: kmainwindow.cpp:547
QMainWindow
NET::MaxHoriz
indicates that the window is horizontally maximized.
Definition: netwm_def.h:445
QChildEvent
kaction.h
KSessionManager::commitData
virtual bool commitData(QSessionManager &sm)
See QApplication::commitData() for documentation.
Definition: ksessionmanager.cpp:40
QEvent::accept
void accept()
KMainWindow::appHelpActivated
void appHelpActivated(void)
Open the help page for the application.
Definition: kmainwindow.cpp:569
KWindowSystem::setState
static void setState(WId win, unsigned long state)
Sets the state of window win to state.
Definition: kwindowsystem_mac.cpp:506
QSize
KMainWindow::showAboutApplication
virtual void showAboutApplication()
This slot does nothing.
Definition: kmainwindow.cpp:630
QLatin1Char
KMainWindow::initialGeometrySet
bool initialGeometrySet() const
KToolBar::applySettings
void applySettings(const KConfigGroup &cg, bool forceGlobal=false)
Read the toolbar settings from group configGroup in config and apply them.
Definition: ktoolbar.cpp:1041
KConfigGroup::name
QString name() const
KMainWindow::applyMainWindowSettings
virtual void applyMainWindowSettings(const KConfigGroup &config, bool forceGlobal=false)
Read settings for statusbar, menubar and toolbar from their respective groups in the config file and ...
Definition: kmainwindow.cpp:746
QMainWindow::saveState
QByteArray saveState(int version) const
KMainWindow::parseGeometry
void parseGeometry(bool parsewidth)
parse the geometry from the geometry command line argument
Definition: kmainwindow.cpp:424
kmainwindow.h
KConfigGroup::hasKey
bool hasKey(const QString &key) const
QWidget::maximumSize
QSize maximumSize() const
KConfigGroup
ktoolbar.h
KConfig
KMainWindow::setAutoSaveSettings
void setAutoSaveSettings(const QString &groupName=QLatin1String("MainWindow"), bool saveWindowSize=true)
Call this to enable "auto-save" of toolbar/menubar/statusbar settings (and optionally window size)...
Definition: kmainwindow.cpp:1003
QString::toLatin1
QByteArray toLatin1() const
QRect::width
int width() const
QWidget::saveGeometry
QByteArray saveGeometry() const
QLatin1String
QApplication::desktop
QDesktopWidget * desktop()
QByteArray::fromBase64
QByteArray fromBase64(const QByteArray &base64)
KMainWindow::KMainWindow
KMainWindow(QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS)
Construct a main window.
Definition: kmainwindow.cpp:217
KToolBar
Floatable toolbar with auto resize.
Definition: ktoolbar.h:53
KMainWindow::statusBar
KStatusBar * statusBar()
Returns a pointer to the status bar.
Definition: kmainwindow.cpp:1146
QString::setNum
QString & setNum(short n, int base)
kstandarddirs.h
QWidget::setWindowTitle
void setWindowTitle(const QString &)
KMainWindow::toolBar
KToolBar * toolBar(const QString &name=QString())
Returns a pointer to the toolbar with the specified name.
Definition: kmainwindow.cpp:1193
KMainWindow::settingsDirty
bool settingsDirty() const
For inherited classes.
Definition: kmainwindow.cpp:997
KMainWindow::dbusName
QString dbusName() const
Returns the path under which this window's D-Bus object is exported.
Definition: kmainwindow.cpp:1220
QMainWindow::restoreState
bool restoreState(const QByteArray &state, int version)
QSize::height
int height() const
KGlobal::mainComponent
const KComponentData & mainComponent()
QString::length
int length() const
kwindowsystem.h
QString::left
QString left(int n) const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
ktoggleaction.h
KCmdLineArgs::getOption
QString getOption(const QByteArray &option) const
Qt::WindowFlags
typedef WindowFlags
KApplication::sessionConfig
KConfig * sessionConfig()
Returns the application session config object.
Definition: kapplication.cpp:608
QWidget::show
void show()
QByteArray::toBase64
QByteArray toBase64() const
NET::Max
convenience value.
Definition: netwm_def.h:449
KGlobalSettings::graphicEffectsLevel
static GraphicEffects graphicEffectsLevel()
This function determines the desired level of effects on the GUI.
Definition: kglobalsettings.cpp:782
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
no_query_exit
static bool no_query_exit
Definition: kmainwindow.cpp:74
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KMainWindow::readGlobalProperties
virtual void readGlobalProperties(KConfig *sessionConfig)
The counterpart of saveGlobalProperties().
Definition: kmainwindow.cpp:626
KConfigGroup::revertToDefault
void revertToDefault(const QString &key)
NET::WMState
Definition: netwm_def.h:635
KMainWindow::saveProperties
virtual void saveProperties(KConfigGroup &)
Save your instance-specific properties.
Definition: kmainwindow.h:585
KGlobalSettings::SimpleAnimationEffects
GUI with simple animations enabled.
Definition: kglobalsettings.h:467
QObject::removeEventFilter
void removeEventFilter(QObject *obj)
QWidget::height
int height() const
KMainWindow::memberList
static QList< KMainWindow * > memberList()
List of members of KMainWindow class.
Definition: kmainwindow.cpp:1218
kconfiggroup.h
KToolBar::toolBarsLocked
static bool toolBarsLocked()
Returns whether the toolbars are locked (i.e., moving of the toobars disallowed). ...
Definition: ktoolbar.cpp:1430
KMainWindow::autoSaveConfigGroup
KConfigGroup autoSaveConfigGroup() const
Definition: kmainwindow.cpp:1045
KMainWindow::toolBars
QList< KToolBar * > toolBars() const
Definition: kmainwindow.cpp:1207
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal