KDEUI
ktoolbar.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright 00003 (C) 2000 Reginald Stadlbauer (reggie@kde.org) 00004 (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 00005 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 00006 (C) 1997, 1998 Sven Radej (radej@kde.org) 00007 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 00008 (C) 1999 Chris Schlaeger (cs@kde.org) 00009 (C) 1999 Kurt Granroth (granroth@kde.org) 00010 (C) 2005-2006 Hamish Rodda (rodda@kde.org) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Library General Public 00014 License version 2 as published by the Free Software Foundation. 00015 00016 This library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 Library General Public License for more details. 00020 00021 You should have received a copy of the GNU Library General Public License 00022 along with this library; see the file COPYING.LIB. If not, write to 00023 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00024 Boston, MA 02110-1301, USA. 00025 */ 00026 00027 #include "ktoolbar.h" 00028 00029 #include <config.h> 00030 00031 #include <QtCore/QPointer> 00032 #include <QtGui/QDesktopWidget> 00033 #include <QtGui/QFrame> 00034 #include <QtGui/QLayout> 00035 #include <QtGui/QMouseEvent> 00036 #include <QtGui/QToolButton> 00037 #include <QtXml/QDomElement> 00038 00039 #include <kaction.h> 00040 #include <kactioncollection.h> 00041 #include <kapplication.h> 00042 #include <kauthorized.h> 00043 #include <kconfig.h> 00044 #include <kdebug.h> 00045 #include <kedittoolbar.h> 00046 #include <kglobalsettings.h> 00047 #include <kguiitem.h> 00048 #include <kicon.h> 00049 #include <kiconloader.h> 00050 #include <klocale.h> 00051 #include <kxmlguiwindow.h> 00052 #include <kmenu.h> 00053 #include <kstandardaction.h> 00054 #include <ktoggleaction.h> 00055 #include <kxmlguifactory.h> 00056 00057 #include <kconfiggroup.h> 00058 00059 /* 00060 Toolbar settings (e.g. icon size or toolButtonStyle) 00061 ===================================================== 00062 00063 We have the following stack of settings (in order of priority) : 00064 - user-specified settings (loaded/saved in KConfig) 00065 - developer-specified settings in the XMLGUI file (if using xmlgui) (cannot change at runtime) 00066 - KDE-global default (user-configurable; can change at runtime) 00067 and when switching between kparts, they are saved as xml in memory, 00068 which, in the unlikely case of no-kmainwindow-autosaving, could be 00069 different from the user-specified settings saved in KConfig and would have 00070 priority over it. 00071 00072 So, in summary, without XML: 00073 Global config / User settings (loaded/saved in kconfig) 00074 and with XML: 00075 Global config / App-XML attributes / User settings (loaded/saved in kconfig) 00076 00077 And all those settings (except the KDE-global defaults) have to be stored in memory 00078 since we cannot retrieve them at random points in time, not knowing the xml document 00079 nor config file that holds these settings. Hence the iconSizeSettings and toolButtonStyleSettings arrays. 00080 00081 For instance, if you change the KDE-global default, whether this makes a change 00082 on a given toolbar depends on whether there are settings at Level_AppXML or Level_UserSettings. 00083 Only if there are no settings at those levels, should the change of KDEDefault make a difference. 00084 */ 00085 enum SettingLevel { Level_KDEDefault, Level_AppXML, Level_UserSettings, 00086 NSettingLevels }; 00087 enum { Unset = -1 }; 00088 00089 class KToolBar::Private 00090 { 00091 public: 00092 Private(KToolBar *qq) 00093 : q(qq), 00094 isMainToolBar(false), 00095 #ifndef KDE_NO_DEPRECATED 00096 enableContext(true), 00097 #endif 00098 unlockedMovable(true), 00099 xmlguiClient(0), 00100 contextLockAction(0), 00101 dropIndicatorAction(0), 00102 context(0), 00103 dragAction(0) 00104 { 00105 } 00106 00107 void slotAppearanceChanged(); 00108 void slotContextAboutToShow(); 00109 void slotContextAboutToHide(); 00110 void slotContextLeft(); 00111 void slotContextRight(); 00112 void slotContextTop(); 00113 void slotContextBottom(); 00114 void slotContextIcons(); 00115 void slotContextText(); 00116 void slotContextTextRight(); 00117 void slotContextTextUnder(); 00118 void slotContextIconSize(); 00119 void slotLockToolBars(bool lock); 00120 00121 void init(bool readConfig = true, bool isMainToolBar = false); 00122 QString getPositionAsString() const; 00123 KMenu *contextMenu(); 00124 void setLocked(bool locked); 00125 void adjustSeparatorVisibility(); 00126 void loadKDESettings(); 00127 void applyCurrentSettings(); 00128 00129 static Qt::ToolButtonStyle toolButtonStyleFromString(const QString& style); 00130 static QString toolButtonStyleToString(Qt::ToolButtonStyle); 00131 static Qt::ToolBarArea positionFromString(const QString& position); 00132 00133 KToolBar *q; 00134 bool isMainToolBar : 1; 00135 #ifndef KDE_NO_DEPRECATED 00136 bool enableContext : 1; 00137 #endif 00138 bool unlockedMovable : 1; 00139 static bool s_editable; 00140 static bool s_locked; 00141 00142 KXMLGUIClient *xmlguiClient; 00143 00144 QMenu* contextOrient; 00145 QMenu* contextMode; 00146 QMenu* contextSize; 00147 00148 QAction* contextTop; 00149 QAction* contextLeft; 00150 QAction* contextRight; 00151 QAction* contextBottom; 00152 QAction* contextIcons; 00153 QAction* contextTextRight; 00154 QAction* contextText; 00155 QAction* contextTextUnder; 00156 KToggleAction* contextLockAction; 00157 QMap<QAction*,int> contextIconSizes; 00158 00159 class IntSetting 00160 { 00161 public: 00162 IntSetting() { 00163 for (int level = 0; level < NSettingLevels; ++level) { 00164 values[level] = Unset; 00165 } 00166 } 00167 int currentValue() const { 00168 int val = Unset; 00169 for (int level = 0; level < NSettingLevels; ++level) { 00170 if (values[level] != Unset) 00171 val = values[level]; 00172 } 00173 return val; 00174 } 00175 // Default value as far as the user is concerned is kde-global + app-xml. 00176 // If currentValue()==defaultValue() then nothing to write into kconfig. 00177 int defaultValue() const { 00178 int val = Unset; 00179 for (int level = 0; level < Level_UserSettings; ++level) { 00180 if (values[level] != Unset) 00181 val = values[level]; 00182 } 00183 return val; 00184 } 00185 QString toString() const { 00186 QString str; 00187 for (int level = 0; level < NSettingLevels; ++level) { 00188 str += QString::number(values[level]) + ' '; 00189 } 00190 return str; 00191 } 00192 int& operator[](int index) { return values[index]; } 00193 private: 00194 int values[NSettingLevels]; 00195 }; 00196 IntSetting iconSizeSettings; 00197 IntSetting toolButtonStyleSettings; // either Qt::ToolButtonStyle or -1, hence "int". 00198 00199 QList<QAction*> actionsBeingDragged; 00200 QAction* dropIndicatorAction; 00201 00202 KMenu* context; 00203 KAction* dragAction; 00204 QPoint dragStartPosition; 00205 }; 00206 00207 bool KToolBar::Private::s_editable = false; 00208 bool KToolBar::Private::s_locked = true; 00209 00210 void KToolBar::Private::init(bool readConfig, bool _isMainToolBar) 00211 { 00212 isMainToolBar = _isMainToolBar; 00213 loadKDESettings(); 00214 00215 // also read in our configurable settings (for non-xmlgui toolbars) 00216 // KDE5: we can probably remove this, if people save settings then they load them too, e.g. using KMainWindow's autosave. 00217 if (readConfig) { 00218 KConfigGroup cg(KGlobal::config(), QString()); 00219 q->applySettings(cg); 00220 } 00221 00222 if (q->mainWindow()) { 00223 // Get notified when settings change 00224 connect(q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)), 00225 q->mainWindow(), SLOT(setSettingsDirty())); 00226 connect(q, SIGNAL(iconSizeChanged(const QSize&)), 00227 q->mainWindow(), SLOT(setSettingsDirty())); 00228 connect(q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), 00229 q->mainWindow(), SLOT(setSettingsDirty())); 00230 connect(q, SIGNAL(movableChanged(bool)), 00231 q->mainWindow(), SLOT(setSettingsDirty())); 00232 connect(q, SIGNAL(orientationChanged(Qt::Orientation)), 00233 q->mainWindow(), SLOT(setSettingsDirty())); 00234 } 00235 00236 if (!KAuthorized::authorize("movable_toolbars")) 00237 q->setMovable(false); 00238 else 00239 q->setMovable(!KToolBar::toolBarsLocked()); 00240 00241 connect(q, SIGNAL(movableChanged(bool)), 00242 q, SLOT(slotMovableChanged(bool))); 00243 00244 q->setAcceptDrops(true); 00245 00246 connect(KGlobalSettings::self(), SIGNAL(toolbarAppearanceChanged(int)), 00247 q, SLOT(slotAppearanceChanged())); 00248 connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()), 00249 q, SLOT(slotAppearanceChanged())); 00250 } 00251 00252 QString KToolBar::Private::getPositionAsString() const 00253 { 00254 // get all of the stuff to save 00255 switch (q->mainWindow()->toolBarArea(const_cast<KToolBar*>(q))) { 00256 case Qt::BottomToolBarArea: 00257 return "Bottom"; 00258 case Qt::LeftToolBarArea: 00259 return "Left"; 00260 case Qt::RightToolBarArea: 00261 return "Right"; 00262 case Qt::TopToolBarArea: 00263 default: 00264 return "Top"; 00265 } 00266 } 00267 00268 KMenu *KToolBar::Private::contextMenu() 00269 { 00270 if (!context) { 00271 context = new KMenu(q); 00272 context->addTitle(i18n("Toolbar Settings")); 00273 00274 contextOrient = new KMenu(i18n("Orientation"), context); 00275 00276 contextTop = contextOrient->addAction(i18nc("toolbar position string", "Top"), q, SLOT(slotContextTop())); 00277 contextTop->setChecked(true); 00278 contextLeft = contextOrient->addAction(i18nc("toolbar position string", "Left"), q, SLOT(slotContextLeft())); 00279 contextRight = contextOrient->addAction(i18nc("toolbar position string", "Right"), q, SLOT(slotContextRight())); 00280 contextBottom = contextOrient->addAction(i18nc("toolbar position string", "Bottom"), q, SLOT(slotContextBottom())); 00281 00282 QActionGroup* positionGroup = new QActionGroup(contextOrient); 00283 foreach (QAction* action, contextOrient->actions()) { 00284 action->setActionGroup(positionGroup); 00285 action->setCheckable(true); 00286 } 00287 00288 contextMode = new KMenu(i18n("Text Position"), context); 00289 00290 contextIcons = contextMode->addAction(i18n("Icons Only"), q, SLOT(slotContextIcons())); 00291 contextText = contextMode->addAction(i18n("Text Only"), q, SLOT(slotContextText())); 00292 contextTextRight = contextMode->addAction(i18n("Text Alongside Icons"), q, SLOT(slotContextTextRight())); 00293 contextTextUnder = contextMode->addAction(i18n("Text Under Icons"), q, SLOT(slotContextTextUnder())); 00294 00295 QActionGroup* textGroup = new QActionGroup(contextMode); 00296 foreach (QAction* action, contextMode->actions()) { 00297 action->setActionGroup(textGroup); 00298 action->setCheckable(true); 00299 } 00300 00301 contextSize = new KMenu(i18n("Icon Size"), context); 00302 00303 contextIconSizes.insert(contextSize->addAction(i18nc("@item:inmenu Icon size", "Default"), q, SLOT(slotContextIconSize())), 00304 iconSizeSettings.defaultValue()); 00305 00306 // Query the current theme for available sizes 00307 KIconTheme *theme = KIconLoader::global()->theme(); 00308 QList<int> avSizes; 00309 if (theme) { 00310 avSizes = theme->querySizes(isMainToolBar ? KIconLoader::MainToolbar : KIconLoader::Toolbar); 00311 } 00312 00313 qSort(avSizes); 00314 00315 if (avSizes.count() < 10) { 00316 // Fixed or threshold type icons 00317 foreach (int it, avSizes) { 00318 QString text; 00319 if (it < 19) 00320 text = i18n("Small (%1x%2)", it, it); 00321 else if (it < 25) 00322 text = i18n("Medium (%1x%2)", it, it); 00323 else if (it < 35) 00324 text = i18n("Large (%1x%2)", it, it); 00325 else 00326 text = i18n("Huge (%1x%2)", it, it); 00327 00328 // save the size in the contextIconSizes map 00329 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it); 00330 } 00331 } else { 00332 // Scalable icons. 00333 const int progression[] = { 16, 22, 32, 48, 64, 96, 128, 192, 256 }; 00334 00335 for (uint i = 0; i < 9; i++) { 00336 foreach (int it, avSizes) { 00337 if (it >= progression[ i ]) { 00338 QString text; 00339 if (it < 19) 00340 text = i18n("Small (%1x%2)", it, it); 00341 else if (it < 25) 00342 text = i18n("Medium (%1x%2)", it, it); 00343 else if (it < 35) 00344 text = i18n("Large (%1x%2)", it, it); 00345 else 00346 text = i18n("Huge (%1x%2)", it, it); 00347 00348 // save the size in the contextIconSizes map 00349 contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it); 00350 break; 00351 } 00352 } 00353 } 00354 } 00355 00356 QActionGroup* sizeGroup = new QActionGroup(contextSize); 00357 foreach (QAction* action, contextSize->actions()) { 00358 action->setActionGroup(sizeGroup); 00359 action->setCheckable(true); 00360 } 00361 00362 if (!q->toolBarsLocked() && !q->isMovable()) 00363 unlockedMovable = false; 00364 00365 delete contextLockAction; 00366 contextLockAction = new KToggleAction(KIcon("system-lock-screen"), i18n("Lock Toolbar Positions"), q); 00367 contextLockAction->setChecked(q->toolBarsLocked()); 00368 connect(contextLockAction, SIGNAL(toggled(bool)), q, SLOT(slotLockToolBars(bool))); 00369 00370 // Now add the actions to the menu 00371 context->addMenu(contextMode); 00372 context->addMenu(contextSize); 00373 context->addMenu(contextOrient); 00374 context->addSeparator(); 00375 00376 connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow())); 00377 } 00378 00379 contextOrient->menuAction()->setVisible(!q->toolBarsLocked()); 00380 // Unplugging a submenu from abouttohide leads to the popupmenu floating around 00381 // So better simply call that code from after exec() returns (DF) 00382 //connect(context, SIGNAL(aboutToHide()), this, SLOT(slotContextAboutToHide())); 00383 00384 return context; 00385 } 00386 00387 void KToolBar::Private::setLocked(bool locked) 00388 { 00389 if (unlockedMovable) 00390 q->setMovable(!locked); 00391 } 00392 00393 void KToolBar::Private::adjustSeparatorVisibility() 00394 { 00395 bool visibleNonSeparator = false; 00396 int separatorToShow = -1; 00397 00398 for (int index = 0; index < q->actions().count(); ++index) { 00399 QAction* action = q->actions()[ index ]; 00400 if (action->isSeparator()) { 00401 if (visibleNonSeparator) { 00402 separatorToShow = index; 00403 visibleNonSeparator = false; 00404 } else { 00405 action->setVisible(false); 00406 } 00407 } else if (!visibleNonSeparator) { 00408 if (action->isVisible()) { 00409 visibleNonSeparator = true; 00410 if (separatorToShow != -1) { 00411 q->actions()[ separatorToShow ]->setVisible(true); 00412 separatorToShow = -1; 00413 } 00414 } 00415 } 00416 } 00417 00418 if (separatorToShow != -1) 00419 q->actions()[ separatorToShow ]->setVisible(false); 00420 } 00421 00422 Qt::ToolButtonStyle KToolBar::Private::toolButtonStyleFromString(const QString & _style) 00423 { 00424 QString style = _style.toLower(); 00425 if (style == "textbesideicon" || style == "icontextright") 00426 return Qt::ToolButtonTextBesideIcon; 00427 else if (style == "textundericon" || style == "icontextbottom") 00428 return Qt::ToolButtonTextUnderIcon; 00429 else if (style == "textonly") 00430 return Qt::ToolButtonTextOnly; 00431 else 00432 return Qt::ToolButtonIconOnly; 00433 } 00434 00435 QString KToolBar::Private::toolButtonStyleToString(Qt::ToolButtonStyle style) 00436 { 00437 switch(style) 00438 { 00439 case Qt::ToolButtonIconOnly: 00440 default: 00441 return "IconOnly"; 00442 case Qt::ToolButtonTextBesideIcon: 00443 return "TextBesideIcon"; 00444 case Qt::ToolButtonTextOnly: 00445 return "TextOnly"; 00446 case Qt::ToolButtonTextUnderIcon: 00447 return "TextUnderIcon"; 00448 } 00449 } 00450 00451 Qt::ToolBarArea KToolBar::Private::positionFromString(const QString& position) 00452 { 00453 Qt::ToolBarArea newposition = Qt::TopToolBarArea; 00454 if (position == QLatin1String("left")) { 00455 newposition = Qt::LeftToolBarArea; 00456 } else if (position == QLatin1String("bottom")) { 00457 newposition = Qt::BottomToolBarArea; 00458 } else if (position == QLatin1String("right")) { 00459 newposition = Qt::RightToolBarArea; 00460 } 00461 return newposition; 00462 } 00463 00464 // Global setting was changed 00465 void KToolBar::Private::slotAppearanceChanged() 00466 { 00467 loadKDESettings(); 00468 applyCurrentSettings(); 00469 } 00470 00471 void KToolBar::Private::loadKDESettings() 00472 { 00473 iconSizeSettings[Level_KDEDefault] = q->iconSizeDefault(); 00474 00475 if (isMainToolBar) { 00476 toolButtonStyleSettings[Level_KDEDefault] = q->toolButtonStyleSetting(); 00477 } else { 00478 const QString fallBack = toolButtonStyleToString(Qt::ToolButtonTextBesideIcon); 00494 KConfigGroup group(KGlobal::config(), "Toolbar style"); 00495 const QString value = group.readEntry("ToolButtonStyleOtherToolbars", fallBack); 00496 toolButtonStyleSettings[Level_KDEDefault] = KToolBar::Private::toolButtonStyleFromString(value); 00497 } 00498 } 00499 00500 // Call this after changing something in d->iconSizeSettings or d->toolButtonStyleSettings 00501 void KToolBar::Private::applyCurrentSettings() 00502 { 00503 //kDebug() << q->objectName() << "iconSizeSettings:" << iconSizeSettings.toString() << "->" << iconSizeSettings.currentValue(); 00504 const int currentIconSize = iconSizeSettings.currentValue(); 00505 q->setIconSize(QSize(currentIconSize, currentIconSize)); 00506 //kDebug() << q->objectName() << "toolButtonStyleSettings:" << toolButtonStyleSettings.toString() << "->" << toolButtonStyleSettings.currentValue(); 00507 q->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(toolButtonStyleSettings.currentValue())); 00508 00509 // And remember to save the new look later 00510 KMainWindow *kmw = q->mainWindow(); 00511 if (kmw) 00512 kmw->setSettingsDirty(); 00513 } 00514 00515 void KToolBar::Private::slotContextAboutToShow() 00516 { 00525 KXmlGuiWindow *kmw = qobject_cast<KXmlGuiWindow *>(q->mainWindow()); 00526 00527 // try to find "configure toolbars" action 00528 QAction *configureAction = 0; 00529 const char* actionName = KStandardAction::name(KStandardAction::ConfigureToolbars); 00530 if (xmlguiClient) { 00531 configureAction = xmlguiClient->actionCollection()->action(actionName); 00532 } 00533 00534 if (!configureAction && kmw) { 00535 configureAction = kmw->actionCollection()->action(actionName); 00536 } 00537 00538 if (configureAction) { 00539 context->addAction(configureAction); 00540 } 00541 00542 context->addAction(contextLockAction); 00543 00544 if (kmw) { 00545 kmw->setupToolbarMenuActions(); 00546 // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar) 00547 QAction *tbAction = kmw->toolBarMenuAction(); 00548 if (!q->toolBarsLocked() && tbAction && tbAction->associatedWidgets().count() > 0) 00549 context->addAction(tbAction); 00550 } 00551 00552 KEditToolBar::setGlobalDefaultToolBar(q->QObject::objectName().toLatin1().constData()); 00553 00554 // Check the actions that should be checked 00555 switch (q->toolButtonStyle()) { 00556 case Qt::ToolButtonIconOnly: 00557 default: 00558 contextIcons->setChecked(true); 00559 break; 00560 case Qt::ToolButtonTextBesideIcon: 00561 contextTextRight->setChecked(true); 00562 break; 00563 case Qt::ToolButtonTextOnly: 00564 contextText->setChecked(true); 00565 break; 00566 case Qt::ToolButtonTextUnderIcon: 00567 contextTextUnder->setChecked(true); 00568 break; 00569 } 00570 00571 QMapIterator< QAction*, int > it = contextIconSizes; 00572 while (it.hasNext()) { 00573 it.next(); 00574 if (it.value() == q->iconSize().width()) { 00575 it.key()->setChecked(true); 00576 break; 00577 } 00578 } 00579 00580 switch (q->mainWindow()->toolBarArea(q)) { 00581 case Qt::BottomToolBarArea: 00582 contextBottom->setChecked(true); 00583 break; 00584 case Qt::LeftToolBarArea: 00585 contextLeft->setChecked(true); 00586 break; 00587 case Qt::RightToolBarArea: 00588 contextRight->setChecked(true); 00589 break; 00590 default: 00591 case Qt::TopToolBarArea: 00592 contextTop->setChecked(true); 00593 break; 00594 } 00595 } 00596 00597 void KToolBar::Private::slotContextAboutToHide() 00598 { 00599 // We have to unplug whatever slotContextAboutToShow plugged into the menu. 00600 // Unplug the toolbar menu action 00601 KXmlGuiWindow *kmw = qobject_cast<KXmlGuiWindow *>(q->mainWindow()); 00602 if (kmw && kmw->toolBarMenuAction()) { 00603 if (kmw->toolBarMenuAction()->associatedWidgets().count() > 1) { 00604 context->removeAction(kmw->toolBarMenuAction()); 00605 } 00606 } 00607 00608 // Unplug the configure toolbars action too, since it's afterwards anyway 00609 QAction *configureAction = 0; 00610 const char* actionName = KStandardAction::name(KStandardAction::ConfigureToolbars); 00611 if (xmlguiClient) { 00612 configureAction = xmlguiClient->actionCollection()->action(actionName); 00613 } 00614 00615 if (!configureAction && kmw) { 00616 configureAction = kmw->actionCollection()->action(actionName); 00617 } 00618 00619 if (configureAction) { 00620 context->removeAction(configureAction); 00621 } 00622 00623 context->removeAction(contextLockAction); 00624 } 00625 00626 void KToolBar::Private::slotContextLeft() 00627 { 00628 q->mainWindow()->addToolBar(Qt::LeftToolBarArea, q); 00629 } 00630 00631 void KToolBar::Private::slotContextRight() 00632 { 00633 q->mainWindow()->addToolBar(Qt::RightToolBarArea, q); 00634 } 00635 00636 void KToolBar::Private::slotContextTop() 00637 { 00638 q->mainWindow()->addToolBar(Qt::TopToolBarArea, q); 00639 } 00640 00641 void KToolBar::Private::slotContextBottom() 00642 { 00643 q->mainWindow()->addToolBar(Qt::BottomToolBarArea, q); 00644 } 00645 00646 void KToolBar::Private::slotContextIcons() 00647 { 00648 q->setToolButtonStyle(Qt::ToolButtonIconOnly); 00649 toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle(); 00650 } 00651 00652 void KToolBar::Private::slotContextText() 00653 { 00654 q->setToolButtonStyle(Qt::ToolButtonTextOnly); 00655 toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle(); 00656 } 00657 00658 void KToolBar::Private::slotContextTextUnder() 00659 { 00660 q->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 00661 toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle(); 00662 } 00663 00664 void KToolBar::Private::slotContextTextRight() 00665 { 00666 q->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 00667 toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle(); 00668 } 00669 00670 void KToolBar::Private::slotContextIconSize() 00671 { 00672 QAction* action = qobject_cast<QAction*>(q->sender()); 00673 if (action && contextIconSizes.contains(action)) { 00674 const int iconSize = contextIconSizes.value(action); 00675 q->setIconDimensions(iconSize); 00676 } 00677 } 00678 00679 void KToolBar::Private::slotLockToolBars(bool lock) 00680 { 00681 q->setToolBarsLocked(lock); 00682 } 00683 00684 00685 00686 KToolBar::KToolBar(QWidget *parent, bool isMainToolBar, bool readConfig) 00687 : QToolBar(parent), 00688 d(new Private(this)) 00689 { 00690 d->init(readConfig, isMainToolBar); 00691 00692 // KToolBar is auto-added to the top area of the main window if parent is a QMainWindow 00693 if (QMainWindow* mw = qobject_cast<QMainWindow*>(parent)) 00694 mw->addToolBar(this); 00695 } 00696 00697 KToolBar::KToolBar(const QString& objectName, QWidget *parent, bool readConfig) 00698 : QToolBar(parent), 00699 d(new Private(this)) 00700 { 00701 setObjectName(objectName); 00702 // mainToolBar -> isMainToolBar = true -> buttonStyle is configurable 00703 // others -> isMainToolBar = false -> ### hardcoded default for buttonStyle !!! should be configurable? -> hidden key added 00704 d->init(readConfig, objectName == "mainToolBar"); 00705 00706 // KToolBar is auto-added to the top area of the main window if parent is a QMainWindow 00707 if (QMainWindow* mw = qobject_cast<QMainWindow*>(parent)) 00708 mw->addToolBar(this); 00709 } 00710 00711 KToolBar::KToolBar(const QString& objectName, QMainWindow* parent, Qt::ToolBarArea area, 00712 bool newLine, bool isMainToolBar, bool readConfig) 00713 : QToolBar(parent), 00714 d(new Private(this)) 00715 { 00716 setObjectName(objectName); 00717 d->init(readConfig, isMainToolBar); 00718 00719 if (newLine) 00720 mainWindow()->addToolBarBreak(area); 00721 00722 mainWindow()->addToolBar(area, this); 00723 00724 if (newLine) 00725 mainWindow()->addToolBarBreak(area); 00726 } 00727 00728 KToolBar::~KToolBar() 00729 { 00730 delete d->contextLockAction; 00731 delete d; 00732 } 00733 00734 #ifndef KDE_NO_DEPRECATED 00735 void KToolBar::setContextMenuEnabled(bool enable) 00736 { 00737 d->enableContext = enable; 00738 } 00739 #endif 00740 00741 #ifndef KDE_NO_DEPRECATED 00742 bool KToolBar::contextMenuEnabled() const 00743 { 00744 return d->enableContext; 00745 } 00746 #endif 00747 00748 void KToolBar::saveSettings(KConfigGroup &cg) 00749 { 00750 Q_ASSERT(!cg.name().isEmpty()); 00751 00752 cg.deleteEntry("Hidden"); // remove old key to avoid bugs from the compat code in applySettings. KDE5: remove. 00753 00754 const int currentIconSize = iconSize().width(); 00755 //kDebug() << objectName() << currentIconSize << d->iconSizeSettings.toString() << "defaultValue=" << d->iconSizeSettings.defaultValue(); 00756 if (!cg.hasDefault("IconSize") && currentIconSize == d->iconSizeSettings.defaultValue()) { 00757 cg.revertToDefault("IconSize"); 00758 d->iconSizeSettings[Level_UserSettings] = Unset; 00759 } else { 00760 cg.writeEntry("IconSize", currentIconSize); 00761 d->iconSizeSettings[Level_UserSettings] = currentIconSize; 00762 } 00763 00764 const Qt::ToolButtonStyle currentToolButtonStyle = toolButtonStyle(); 00765 if (!cg.hasDefault("ToolButtonStyle") && currentToolButtonStyle == d->toolButtonStyleSettings.defaultValue()) { 00766 cg.revertToDefault("ToolButtonStyle"); 00767 d->toolButtonStyleSettings[Level_UserSettings] = Unset; 00768 } else { 00769 cg.writeEntry("ToolButtonStyle", d->toolButtonStyleToString(currentToolButtonStyle)); 00770 d->toolButtonStyleSettings[Level_UserSettings] = currentToolButtonStyle; 00771 } 00772 } 00773 00774 void KToolBar::setXMLGUIClient(KXMLGUIClient *client) 00775 { 00776 d->xmlguiClient = client; 00777 } 00778 00779 void KToolBar::contextMenuEvent(QContextMenuEvent* event) 00780 { 00781 #ifndef KDE_NO_DEPRECATED 00782 if (mainWindow() && d->enableContext) { 00783 QPointer<KToolBar> guard(this); 00784 d->contextMenu()->exec(event->globalPos()); 00785 00786 // "Configure Toolbars" recreates toolbars, so we might not exist anymore. 00787 if (guard) { 00788 d->slotContextAboutToHide(); 00789 } 00790 return; 00791 } 00792 #endif 00793 00794 QToolBar::contextMenuEvent(event); 00795 } 00796 00797 Qt::ToolButtonStyle KToolBar::toolButtonStyleSetting() 00798 { 00799 KConfigGroup group(KGlobal::config(), "Toolbar style"); 00800 const QString fallback = Private::toolButtonStyleToString(Qt::ToolButtonTextBesideIcon); 00801 return KToolBar::Private::toolButtonStyleFromString(group.readEntry("ToolButtonStyle", fallback)); 00802 } 00803 00804 void KToolBar::loadState(const QDomElement &element) 00805 { 00806 QMainWindow *mw = mainWindow(); 00807 if (!mw) 00808 return; 00809 00810 { 00811 QDomNode textNode = element.namedItem("text"); 00812 QByteArray text; 00813 QByteArray context; 00814 if (textNode.isElement()) 00815 { 00816 QDomElement textElement = textNode.toElement(); 00817 text = textElement.text().toUtf8(); 00818 context = textElement.attribute("context").toUtf8(); 00819 } 00820 else 00821 { 00822 textNode = element.namedItem("Text"); 00823 if (textNode.isElement()) 00824 { 00825 QDomElement textElement = textNode.toElement(); 00826 text = textElement.text().toUtf8(); 00827 context = textElement.attribute("context").toUtf8(); 00828 } 00829 } 00830 00831 QString i18nText; 00832 if (!text.isEmpty() && !context.isEmpty()) 00833 i18nText = i18nc(context, text); 00834 else if (!text.isEmpty()) 00835 i18nText = i18n(text); 00836 00837 if (!i18nText.isEmpty()) 00838 setWindowTitle(i18nText); 00839 } 00840 00841 /* 00842 This method is called in order to load toolbar settings from XML. 00843 However this can be used in two rather different cases: 00844 - for the initial loading of the app's XML. In that case the settings 00845 are only the defaults (Level_AppXML), the user's KConfig settings will override them 00846 00847 - for later re-loading when switching between parts in KXMLGUIFactory. 00848 In that case the XML contains the final settings, not the defaults. 00849 We do need the defaults, and the toolbar might have been completely 00850 deleted and recreated meanwhile. So we store the app-default settings 00851 into the XML. 00852 */ 00853 bool loadingAppDefaults = true; 00854 if (element.hasAttribute("tempXml")) { 00855 // this isn't the first time, so the app-xml defaults have been saved into the (in-memory) XML 00856 loadingAppDefaults = false; 00857 const QString iconSizeDefault = element.attribute("iconSizeDefault"); 00858 if (!iconSizeDefault.isEmpty()) { 00859 d->iconSizeSettings[Level_AppXML] = iconSizeDefault.toInt(); 00860 } 00861 const QString toolButtonStyleDefault = element.attribute("toolButtonStyleDefault"); 00862 if (!toolButtonStyleDefault.isEmpty()) { 00863 d->toolButtonStyleSettings[Level_AppXML] = d->toolButtonStyleFromString(toolButtonStyleDefault); 00864 } 00865 } else { 00866 // loading app defaults 00867 bool newLine = false; 00868 QString attrNewLine = element.attribute("newline").toLower(); 00869 if (!attrNewLine.isEmpty()) 00870 newLine = attrNewLine == "true"; 00871 if (newLine && mw) 00872 mw->insertToolBarBreak(this); 00873 } 00874 00875 int newIconSize = -1; 00876 if (element.hasAttribute("iconSize")) { 00877 bool ok; 00878 newIconSize = element.attribute("iconSize").trimmed().toInt(&ok); 00879 if (!ok) 00880 newIconSize = -1; 00881 } 00882 if (newIconSize != -1) 00883 d->iconSizeSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = newIconSize; 00884 00885 const QString newToolButtonStyle = element.attribute("iconText"); 00886 if (!newToolButtonStyle.isEmpty()) 00887 d->toolButtonStyleSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = d->toolButtonStyleFromString(newToolButtonStyle); 00888 00889 bool hidden = false; 00890 { 00891 QString attrHidden = element.attribute("hidden").toLower(); 00892 if (!attrHidden.isEmpty()) 00893 hidden = attrHidden == "true"; 00894 } 00895 00896 Qt::ToolBarArea pos = Qt::NoToolBarArea; 00897 { 00898 QString attrPosition = element.attribute("position").toLower(); 00899 if (!attrPosition.isEmpty()) 00900 pos = KToolBar::Private::positionFromString(attrPosition); 00901 } 00902 if (pos != Qt::NoToolBarArea) 00903 mw->addToolBar(pos, this); 00904 00905 setVisible(!hidden); 00906 00907 d->applyCurrentSettings(); 00908 } 00909 00910 // Called when switching between xmlgui clients, in order to find any unsaved settings 00911 // again when switching back to the current xmlgui client. 00912 void KToolBar::saveState(QDomElement ¤t) const 00913 { 00914 Q_ASSERT(!current.isNull()); 00915 00916 current.setAttribute("tempXml", "true"); 00917 00918 current.setAttribute("noMerge", "1"); 00919 current.setAttribute("position", d->getPositionAsString().toLower()); 00920 current.setAttribute("hidden", isHidden() ? "true" : "false"); 00921 00922 const int currentIconSize = iconSize().width(); 00923 if (currentIconSize == d->iconSizeSettings.defaultValue()) 00924 current.removeAttribute("iconSize"); 00925 else 00926 current.setAttribute("iconSize", iconSize().width()); 00927 00928 if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue()) 00929 current.removeAttribute("iconText"); 00930 else 00931 current.setAttribute("iconText", d->toolButtonStyleToString(toolButtonStyle())); 00932 00933 // Note: if this method is used by more than KXMLGUIBuilder, e.g. to save XML settings to *disk*, 00934 // then the stuff below shouldn't always be done. This is not the case currently though. 00935 if (d->iconSizeSettings[Level_AppXML] != Unset) { 00936 current.setAttribute("iconSizeDefault", d->iconSizeSettings[Level_AppXML]); 00937 } 00938 if (d->toolButtonStyleSettings[Level_AppXML] != Unset) { 00939 const Qt::ToolButtonStyle bs = static_cast<Qt::ToolButtonStyle>(d->toolButtonStyleSettings[Level_AppXML]); 00940 current.setAttribute("toolButtonStyleDefault", d->toolButtonStyleToString(bs)); 00941 } 00942 } 00943 00944 // called by KMainWindow::applyMainWindowSettings to read from the user settings 00945 void KToolBar::applySettings(const KConfigGroup &cg, bool forceGlobal) 00946 { 00947 Q_ASSERT(!cg.name().isEmpty()); 00948 Q_UNUSED(forceGlobal); // KDE5: remove 00949 00950 // a small leftover from kde3: separate bool for hidden/shown. But it's also part of saveMainWindowSettings, 00951 // it is not really useful anymore, except in the unlikely case where someone would call this by hand. 00952 // KDE5: remove the block below 00953 if (cg.hasKey("Hidden")) { 00954 const bool hidden = cg.readEntry("Hidden", false); 00955 if (hidden) 00956 hide(); 00957 else { 00958 show(); 00959 } 00960 } 00961 00962 if (cg.hasKey("IconSize")) { 00963 d->iconSizeSettings[Level_UserSettings] = cg.readEntry("IconSize", 0); 00964 } 00965 if (cg.hasKey("ToolButtonStyle")) { 00966 d->toolButtonStyleSettings[Level_UserSettings] = d->toolButtonStyleFromString(cg.readEntry("ToolButtonStyle", QString())); 00967 } 00968 00969 d->applyCurrentSettings(); 00970 } 00971 00972 KMainWindow * KToolBar::mainWindow() const 00973 { 00974 return qobject_cast<KMainWindow*>(const_cast<QObject*>(parent())); 00975 } 00976 00977 void KToolBar::setIconDimensions(int size) 00978 { 00979 QToolBar::setIconSize(QSize(size, size)); 00980 d->iconSizeSettings[Level_UserSettings] = size; 00981 } 00982 00983 int KToolBar::iconSizeDefault() const 00984 { 00985 return KIconLoader::global()->currentSize(d->isMainToolBar ? KIconLoader::MainToolbar : KIconLoader::Toolbar); 00986 } 00987 00988 void KToolBar::slotMovableChanged(bool movable) 00989 { 00990 if (movable && !KAuthorized::authorize("movable_toolbars")) 00991 setMovable(false); 00992 } 00993 00994 void KToolBar::dragEnterEvent(QDragEnterEvent *event) 00995 { 00996 if (toolBarsEditable() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction) && 00997 event->mimeData()->hasFormat("application/x-kde-action-list")) { 00998 QByteArray data = event->mimeData()->data("application/x-kde-action-list"); 00999 01000 QDataStream stream(data); 01001 01002 QStringList actionNames; 01003 01004 stream >> actionNames; 01005 01006 foreach (const QString& actionName, actionNames) { 01007 foreach (KActionCollection* ac, KActionCollection::allCollections()) { 01008 QAction* newAction = ac->action(actionName.toAscii().constData()); 01009 if (newAction) { 01010 d->actionsBeingDragged.append(newAction); 01011 break; 01012 } 01013 } 01014 } 01015 01016 if (d->actionsBeingDragged.count()) { 01017 QAction* overAction = actionAt(event->pos()); 01018 01019 QFrame* dropIndicatorWidget = new QFrame(this); 01020 dropIndicatorWidget->resize(8, height() - 4); 01021 dropIndicatorWidget->setFrameShape(QFrame::VLine); 01022 dropIndicatorWidget->setLineWidth(3); 01023 01024 d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget); 01025 01026 insertAction(overAction, d->dropIndicatorAction); 01027 01028 event->acceptProposedAction(); 01029 return; 01030 } 01031 } 01032 01033 QToolBar::dragEnterEvent(event); 01034 } 01035 01036 void KToolBar::dragMoveEvent(QDragMoveEvent *event) 01037 { 01038 if (toolBarsEditable()) 01039 forever { 01040 if (d->dropIndicatorAction) { 01041 QAction* overAction = 0L; 01042 foreach (QAction* action, actions()) { 01043 // want to make it feel that half way across an action you're dropping on the other side of it 01044 QWidget* widget = widgetForAction(action); 01045 if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) { 01046 overAction = action; 01047 break; 01048 } 01049 } 01050 01051 if (overAction != d->dropIndicatorAction) { 01052 // Check to see if the indicator is already in the right spot 01053 int dropIndicatorIndex = actions().indexOf(d->dropIndicatorAction); 01054 if (dropIndicatorIndex + 1 < actions().count()) { 01055 if (actions()[ dropIndicatorIndex + 1 ] == overAction) 01056 break; 01057 } else if (!overAction) { 01058 break; 01059 } 01060 01061 insertAction(overAction, d->dropIndicatorAction); 01062 } 01063 01064 event->accept(); 01065 return; 01066 } 01067 break; 01068 } 01069 01070 QToolBar::dragMoveEvent(event); 01071 } 01072 01073 void KToolBar::dragLeaveEvent(QDragLeaveEvent *event) 01074 { 01075 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey) 01076 delete d->dropIndicatorAction; 01077 d->dropIndicatorAction = 0L; 01078 d->actionsBeingDragged.clear(); 01079 01080 if (toolBarsEditable()) { 01081 event->accept(); 01082 return; 01083 } 01084 01085 QToolBar::dragLeaveEvent(event); 01086 } 01087 01088 void KToolBar::dropEvent(QDropEvent *event) 01089 { 01090 if (toolBarsEditable()) { 01091 foreach (QAction* action, d->actionsBeingDragged) { 01092 if (actions().contains(action)) 01093 removeAction(action); 01094 insertAction(d->dropIndicatorAction, action); 01095 } 01096 } 01097 01098 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey) 01099 delete d->dropIndicatorAction; 01100 d->dropIndicatorAction = 0L; 01101 d->actionsBeingDragged.clear(); 01102 01103 if (toolBarsEditable()) { 01104 event->accept(); 01105 return; 01106 } 01107 01108 QToolBar::dropEvent(event); 01109 } 01110 01111 void KToolBar::mousePressEvent(QMouseEvent *event) 01112 { 01113 if (toolBarsEditable() && event->button() == Qt::LeftButton) { 01114 if (KAction* action = qobject_cast<KAction*>(actionAt(event->pos()))) { 01115 d->dragAction = action; 01116 d->dragStartPosition = event->pos(); 01117 event->accept(); 01118 return; 01119 } 01120 } 01121 01122 QToolBar::mousePressEvent(event); 01123 } 01124 01125 void KToolBar::mouseMoveEvent(QMouseEvent *event) 01126 { 01127 if (!toolBarsEditable() || !d->dragAction) 01128 return QToolBar::mouseMoveEvent(event); 01129 01130 if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) { 01131 event->accept(); 01132 return; 01133 } 01134 01135 QDrag *drag = new QDrag(this); 01136 QMimeData *mimeData = new QMimeData; 01137 01138 QByteArray data; 01139 { 01140 QDataStream stream(&data, QIODevice::WriteOnly); 01141 01142 QStringList actionNames; 01143 actionNames << d->dragAction->objectName(); 01144 01145 stream << actionNames; 01146 } 01147 01148 mimeData->setData("application/x-kde-action-list", data); 01149 01150 drag->setMimeData(mimeData); 01151 01152 Qt::DropAction dropAction = drag->start(Qt::MoveAction); 01153 01154 if (dropAction == Qt::MoveAction) 01155 // Only remove from this toolbar if it was moved to another toolbar 01156 // Otherwise the receiver moves it. 01157 if (drag->target() != this) 01158 removeAction(d->dragAction); 01159 01160 d->dragAction = 0L; 01161 event->accept(); 01162 } 01163 01164 void KToolBar::mouseReleaseEvent(QMouseEvent *event) 01165 { 01166 // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey) 01167 if (d->dragAction) { 01168 d->dragAction = 0L; 01169 event->accept(); 01170 return; 01171 } 01172 01173 QToolBar::mouseReleaseEvent(event); 01174 } 01175 01176 bool KToolBar::eventFilter(QObject * watched, QEvent * event) 01177 { 01178 // Generate context menu events for disabled buttons too... 01179 if (event->type() == QEvent::MouseButtonPress) { 01180 QMouseEvent* me = static_cast<QMouseEvent*>(event); 01181 if (me->buttons() & Qt::RightButton) 01182 if (QWidget* ww = qobject_cast<QWidget*>(watched)) 01183 if (ww->parent() == this && !ww->isEnabled()) 01184 QCoreApplication::postEvent(this, new QContextMenuEvent(QContextMenuEvent::Mouse, me->pos(), me->globalPos())); 01185 01186 } else if (event->type() == QEvent::ParentChange) { 01187 // Make sure we're not leaving stale event filters around, 01188 // when a child is reparented somewhere else 01189 if (QWidget* ww = qobject_cast<QWidget*>(watched)) { 01190 if (!this->isAncestorOf(ww)) { 01191 // New parent is not a subwidget - remove event filter 01192 ww->removeEventFilter(this); 01193 foreach (QWidget* child, ww->findChildren<QWidget*>()) 01194 child->removeEventFilter(this); 01195 } 01196 } 01197 } 01198 01199 QToolButton* tb; 01200 if ((tb = qobject_cast<QToolButton*>(watched))) { 01201 const QList<QAction*> tbActions = tb->actions(); 01202 if (!tbActions.isEmpty()) { 01203 // Handle MMB on toolbar buttons 01204 if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) { 01205 QMouseEvent* me = static_cast<QMouseEvent*>(event); 01206 if (me->button() == Qt::MidButton /*&& 01207 act->receivers(SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)))*/) { 01208 QAction* act = tbActions.first(); 01209 if (me->type() == QEvent::MouseButtonPress) 01210 tb->setDown(act->isEnabled()); 01211 else { 01212 tb->setDown(false); 01213 if (act->isEnabled()) { 01214 QMetaObject::invokeMethod(act, "triggered", Qt::DirectConnection, 01215 Q_ARG(Qt::MouseButtons, me->button()), 01216 Q_ARG(Qt::KeyboardModifiers, QApplication::keyboardModifiers())); 01217 } 01218 } 01219 } 01220 } 01221 01222 // CJK languages use more verbose accelerator marker: they add a Latin 01223 // letter in parenthesis, and put accelerator on that. Hence, the default 01224 // removal of ampersand only may not be enough there, instead the whole 01225 // parenthesis construct should be removed. Use KLocale's method to do this. 01226 if (event->type() == QEvent::Show || event->type() == QEvent::Paint || event->type() == QEvent::EnabledChange) { 01227 QAction *act = tb->defaultAction(); 01228 if (act) { 01229 const QString text = KGlobal::locale()->removeAcceleratorMarker(act->iconText().isEmpty() ? act->text() : act->iconText()); 01230 const QString toolTip = KGlobal::locale()->removeAcceleratorMarker(act->toolTip()); 01231 // Filtering messages requested by translators (scripting). 01232 tb->setText(i18nc("@action:intoolbar Text label of toolbar button", "%1", text)); 01233 tb->setToolTip(i18nc("@info:tooltip Tooltip of toolbar button", "%1", toolTip)); 01234 } 01235 } 01236 } 01237 } 01238 01239 // Redirect mouse events to the toolbar when drag + drop editing is enabled 01240 if (toolBarsEditable()) { 01241 if (QWidget* ww = qobject_cast<QWidget*>(watched)) { 01242 switch (event->type()) { 01243 case QEvent::MouseButtonPress: { 01244 QMouseEvent* me = static_cast<QMouseEvent*>(event); 01245 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(), 01246 me->button(), me->buttons(), me->modifiers()); 01247 mousePressEvent(&newEvent); 01248 return true; 01249 } 01250 case QEvent::MouseMove: { 01251 QMouseEvent* me = static_cast<QMouseEvent*>(event); 01252 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(), 01253 me->button(), me->buttons(), me->modifiers()); 01254 mouseMoveEvent(&newEvent); 01255 return true; 01256 } 01257 case QEvent::MouseButtonRelease: { 01258 QMouseEvent* me = static_cast<QMouseEvent*>(event); 01259 QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(), 01260 me->button(), me->buttons(), me->modifiers()); 01261 mouseReleaseEvent(&newEvent); 01262 return true; 01263 } 01264 default: 01265 break; 01266 } 01267 } 01268 } 01269 01270 return QToolBar::eventFilter(watched, event); 01271 } 01272 01273 void KToolBar::actionEvent(QActionEvent * event) 01274 { 01275 if (event->type() == QEvent::ActionRemoved) { 01276 QWidget* widget = widgetForAction(event->action()); 01277 if (widget) { 01278 widget->removeEventFilter(this); 01279 01280 foreach (QWidget* child, widget->findChildren<QWidget*>()) 01281 child->removeEventFilter(this); 01282 } 01283 } 01284 01285 QToolBar::actionEvent(event); 01286 01287 if (event->type() == QEvent::ActionAdded) { 01288 QWidget* widget = widgetForAction(event->action()); 01289 if (widget) { 01290 widget->installEventFilter(this); 01291 01292 foreach (QWidget* child, widget->findChildren<QWidget*>()) 01293 child->installEventFilter(this); 01294 // Center widgets that do not have any use for more space. See bug 165274 01295 if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag) 01296 // ... but do not center when using text besides icon in vertical toolbar. See bug 243196 01297 && !(orientation() == Qt::Vertical && toolButtonStyle() == Qt::ToolButtonTextBesideIcon)) { 01298 const int index = layout()->indexOf(widget); 01299 if (index != -1) { 01300 layout()->itemAt(index)->setAlignment(Qt::AlignJustify); 01301 } 01302 } 01303 } 01304 } 01305 01306 d->adjustSeparatorVisibility(); 01307 } 01308 01309 bool KToolBar::toolBarsEditable() 01310 { 01311 return KToolBar::Private::s_editable; 01312 } 01313 01314 void KToolBar::setToolBarsEditable(bool editable) 01315 { 01316 if (KToolBar::Private::s_editable != editable) { 01317 KToolBar::Private::s_editable = editable; 01318 } 01319 } 01320 01321 void KToolBar::setToolBarsLocked(bool locked) 01322 { 01323 if (KToolBar::Private::s_locked != locked) { 01324 KToolBar::Private::s_locked = locked; 01325 01326 foreach (KMainWindow* mw, KMainWindow::memberList()) { 01327 foreach (KToolBar* toolbar, mw->findChildren<KToolBar*>()) { 01328 toolbar->d->setLocked(locked); 01329 } 01330 } 01331 } 01332 } 01333 01334 bool KToolBar::toolBarsLocked() 01335 { 01336 return KToolBar::Private::s_locked; 01337 } 01338 01339 #include "ktoolbar.moc"
KDE 4.6 API Reference