KXmlGui

ktoolbar.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1997, 1998 Stephan Kulow <[email protected]>
5  SPDX-FileCopyrightText: 1997, 1998 Mark Donohoe <[email protected]>
6  SPDX-FileCopyrightText: 1997, 1998 Sven Radej <[email protected]>
7  SPDX-FileCopyrightText: 1997, 1998 Matthias Ettrich <[email protected]>
8  SPDX-FileCopyrightText: 1999 Chris Schlaeger <[email protected]>
9  SPDX-FileCopyrightText: 1999 Kurt Granroth <[email protected]>
10  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
11 
12  SPDX-License-Identifier: LGPL-2.0-only
13 */
14 
15 #include "ktoolbar.h"
16 
17 #include <QPointer>
18 #include <QAction>
19 #include <QApplication>
20 #include <QDesktopWidget>
21 #include <QFrame>
22 #include <QLayout>
23 #include <QMenu>
24 #include <QMimeData>
25 #include <QDrag>
26 #include <QMouseEvent>
27 #include <QDomElement>
28 #ifdef QT_DBUS_LIB
29 #include <QDBusConnection>
30 #include <QDBusMessage>
31 #endif
32 
33 #include <kauthorized.h>
34 #include <kconfig.h>
35 #include <ksharedconfig.h>
36 #include <kicontheme.h>
37 #include <klocalizedstring.h>
38 #include <kstandardaction.h>
39 #include <ktoggleaction.h>
40 #include <kconfiggroup.h>
41 
42 #include "kactioncollection.h"
43 #include "kedittoolbar.h"
44 #include "kxmlguifactory.h"
45 #include "kxmlguiwindow.h"
46 
47 #include "ktoolbarhelper_p.h"
48 
49 /*
50  Toolbar settings (e.g. icon size or toolButtonStyle)
51  =====================================================
52 
53  We have the following stack of settings (in order of priority) :
54  - user-specified settings (loaded/saved in KConfig)
55  - developer-specified settings in the XMLGUI file (if using xmlgui) (cannot change at runtime)
56  - KDE-global default (user-configurable; can change at runtime)
57  and when switching between kparts, they are saved as xml in memory,
58  which, in the unlikely case of no-kmainwindow-autosaving, could be
59  different from the user-specified settings saved in KConfig and would have
60  priority over it.
61 
62  So, in summary, without XML:
63  Global config / User settings (loaded/saved in kconfig)
64  and with XML:
65  Global config / App-XML attributes / User settings (loaded/saved in kconfig)
66 
67  And all those settings (except the KDE-global defaults) have to be stored in memory
68  since we cannot retrieve them at random points in time, not knowing the xml document
69  nor config file that holds these settings. Hence the iconSizeSettings and toolButtonStyleSettings arrays.
70 
71  For instance, if you change the KDE-global default, whether this makes a change
72  on a given toolbar depends on whether there are settings at Level_AppXML or Level_UserSettings.
73  Only if there are no settings at those levels, should the change of KDEDefault make a difference.
74 */
75 enum SettingLevel { Level_KDEDefault, Level_AppXML, Level_UserSettings,
76  NSettingLevels
77  };
78 enum { Unset = -1 };
79 
80 class Q_DECL_HIDDEN KToolBar::Private
81 {
82 public:
83  Private(KToolBar *qq)
84  : q(qq),
85  isMainToolBar(false),
86 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
87  enableContext(true),
88 #endif
89  unlockedMovable(true),
90  contextOrient(nullptr),
91  contextMode(nullptr),
92  contextSize(nullptr),
93  contextButtonTitle(nullptr),
94  contextShowText(nullptr),
95  contextButtonAction(nullptr),
96  contextTop(nullptr),
97  contextLeft(nullptr),
98  contextRight(nullptr),
99  contextBottom(nullptr),
100  contextIcons(nullptr),
101  contextTextRight(nullptr),
102  contextText(nullptr),
103  contextTextUnder(nullptr),
104  contextLockAction(nullptr),
105  dropIndicatorAction(nullptr),
106  context(nullptr),
107  dragAction(nullptr)
108  {
109  }
110 
111  void slotAppearanceChanged();
112  void slotContextAboutToShow();
113  void slotContextAboutToHide();
114  void slotContextLeft();
115  void slotContextRight();
116  void slotContextShowText();
117  void slotContextTop();
118  void slotContextBottom();
119  void slotContextIcons();
120  void slotContextText();
121  void slotContextTextRight();
122  void slotContextTextUnder();
123  void slotContextIconSize();
124  void slotLockToolBars(bool lock);
125 
126  void init(bool readConfig = true, bool isMainToolBar = false);
127  QString getPositionAsString() const;
128  QMenu *contextMenu(const QPoint &globalPos);
129  void setLocked(bool locked);
130  void adjustSeparatorVisibility();
131  void loadKDESettings();
132  void applyCurrentSettings();
133 
134  QAction *findAction(const QString &actionName, KXMLGUIClient **client = nullptr) const;
135 
136  static Qt::ToolButtonStyle toolButtonStyleFromString(const QString &style);
137  static QString toolButtonStyleToString(Qt::ToolButtonStyle);
138  static Qt::ToolBarArea positionFromString(const QString &position);
139  static Qt::ToolButtonStyle toolButtonStyleSetting();
140 
141  KToolBar *const q;
142  bool isMainToolBar : 1;
143 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
144  bool enableContext : 1;
145 #endif
146  bool unlockedMovable : 1;
147  static bool s_editable;
148  static bool s_locked;
149 
150  QSet<KXMLGUIClient *> xmlguiClients;
151 
152  QMenu *contextOrient;
153  QMenu *contextMode;
154  QMenu *contextSize;
155 
156  QAction *contextButtonTitle;
157  QAction *contextShowText;
158  QAction *contextButtonAction;
159  QAction *contextTop;
160  QAction *contextLeft;
161  QAction *contextRight;
162  QAction *contextBottom;
163  QAction *contextIcons;
164  QAction *contextTextRight;
165  QAction *contextText;
166  QAction *contextTextUnder;
167  KToggleAction *contextLockAction;
168  QMap<QAction *, int> contextIconSizes;
169 
170  class IntSetting
171  {
172  public:
173  IntSetting()
174  {
175  for (int &value : values) {
176  value = Unset;
177  }
178  }
179  int currentValue() const
180  {
181  int val = Unset;
182  for (int value : values) {
183  if (value != Unset) {
184  val = value;
185  }
186  }
187  return val;
188  }
189  // Default value as far as the user is concerned is kde-global + app-xml.
190  // If currentValue()==defaultValue() then nothing to write into kconfig.
191  int defaultValue() const
192  {
193  int val = Unset;
194  for (int level = 0; level < Level_UserSettings; ++level) {
195  if (values[level] != Unset) {
196  val = values[level];
197  }
198  }
199  return val;
200  }
201  QString toString() const
202  {
203  QString str;
204  for (int value : values) {
205  str += QString::number(value) + QLatin1Char(' ');
206  }
207  return str;
208  }
209  int &operator[](int index)
210  {
211  return values[index];
212  }
213  private:
214  int values[NSettingLevels];
215  };
216  IntSetting iconSizeSettings;
217  IntSetting toolButtonStyleSettings; // either Qt::ToolButtonStyle or -1, hence "int".
218 
219  QList<QAction *> actionsBeingDragged;
220  QAction *dropIndicatorAction;
221 
222  QMenu *context;
223  QAction *dragAction;
224  QPoint dragStartPosition;
225 };
226 
227 bool KToolBar::Private::s_editable = false;
228 bool KToolBar::Private::s_locked = true;
229 
230 void KToolBar::Private::init(bool readConfig, bool _isMainToolBar)
231 {
232  isMainToolBar = _isMainToolBar;
233  loadKDESettings();
234 
235  // also read in our configurable settings (for non-xmlgui toolbars)
236  if (readConfig) {
238  q->applySettings(cg);
239  }
240 
241  if (q->mainWindow()) {
242  // Get notified when settings change
243  connect(q, &QToolBar::allowedAreasChanged,
245  connect(q, &QToolBar::iconSizeChanged,
249  connect(q, &QToolBar::movableChanged,
251  connect(q, &QToolBar::orientationChanged,
253  }
254 
255  if (!KAuthorized::authorize(QStringLiteral("movable_toolbars"))) {
256  q->setMovable(false);
257  } else {
259  }
260 
261  q->toggleViewAction()->setEnabled(KAuthorized::authorizeAction(QStringLiteral("options_show_toolbar")));
262 
263  connect(q, &QToolBar::movableChanged,
264  q, &KToolBar::slotMovableChanged);
265 
266  q->setAcceptDrops(true);
267 
268 #ifdef QT_DBUS_LIB
269  QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"),
270  QStringLiteral("styleChanged"), q, SLOT(slotAppearanceChanged()));
271 #endif
272  connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
273  q, SLOT(slotAppearanceChanged()));
274 }
275 
276 QString KToolBar::Private::getPositionAsString() const
277 {
278  // get all of the stuff to save
279  switch (q->mainWindow()->toolBarArea(const_cast<KToolBar *>(q))) {
281  return QStringLiteral("Bottom");
282  case Qt::LeftToolBarArea:
283  return QStringLiteral("Left");
285  return QStringLiteral("Right");
286  case Qt::TopToolBarArea:
287  default:
288  return QStringLiteral("Top");
289  }
290 }
291 
292 QMenu *KToolBar::Private::contextMenu(const QPoint &globalPos)
293 {
294  if (!context) {
295  context = new QMenu(q);
296 
297  contextButtonTitle = context->addSection(i18nc("@title:menu", "Show Text"));
298  contextShowText = context->addAction(QString(), q, SLOT(slotContextShowText()));
299 
300  context->addSection(i18nc("@title:menu", "Toolbar Settings"));
301 
302  contextOrient = new QMenu(i18nc("Toolbar orientation", "Orientation"), context);
303 
304  contextTop = contextOrient->addAction(i18nc("toolbar position string", "Top"), q, SLOT(slotContextTop()));
305  contextTop->setChecked(true);
306  contextLeft = contextOrient->addAction(i18nc("toolbar position string", "Left"), q, SLOT(slotContextLeft()));
307  contextRight = contextOrient->addAction(i18nc("toolbar position string", "Right"), q, SLOT(slotContextRight()));
308  contextBottom = contextOrient->addAction(i18nc("toolbar position string", "Bottom"), q, SLOT(slotContextBottom()));
309 
310  QActionGroup *positionGroup = new QActionGroup(contextOrient);
311  const auto orientActions = contextOrient->actions();
312  for (QAction *action : orientActions) {
313  action->setActionGroup(positionGroup);
314  action->setCheckable(true);
315  }
316 
317  contextMode = new QMenu(i18n("Text Position"), context);
318 
319  contextIcons = contextMode->addAction(i18nc("@item:inmenu", "Icons Only"), q, SLOT(slotContextIcons()));
320  contextText = contextMode->addAction(i18nc("@item:inmenu", "Text Only"), q, SLOT(slotContextText()));
321  contextTextRight = contextMode->addAction(i18nc("@item:inmenu", "Text Alongside Icons"), q, SLOT(slotContextTextRight()));
322  contextTextUnder = contextMode->addAction(i18nc("@item:inmenu", "Text Under Icons"), q, SLOT(slotContextTextUnder()));
323 
324  QActionGroup *textGroup = new QActionGroup(contextMode);
325  const auto modeActions = contextMode->actions();
326  for (QAction *action : modeActions) {
327  action->setActionGroup(textGroup);
328  action->setCheckable(true);
329  }
330 
331  contextSize = new QMenu(i18n("Icon Size"), context);
332 
333  contextIconSizes.insert(contextSize->addAction(i18nc("@item:inmenu Icon size", "Default"), q, SLOT(slotContextIconSize())),
334  iconSizeSettings.defaultValue());
335 
336  // Query the current theme for available sizes
337  KIconTheme *theme = KIconLoader::global()->theme();
338  QList<int> avSizes;
339  if (theme) {
340  avSizes = theme->querySizes(isMainToolBar ? KIconLoader::MainToolbar : KIconLoader::Toolbar);
341  }
342 
343  std::sort(avSizes.begin(), avSizes.end());
344 
345  if (avSizes.count() < 10) {
346  // Fixed or threshold type icons
347  for (int it : qAsConst(avSizes)) {
348  QString text;
349  if (it < 19) {
350  text = i18n("Small (%1x%2)", it, it);
351  } else if (it < 25) {
352  text = i18n("Medium (%1x%2)", it, it);
353  } else if (it < 35) {
354  text = i18n("Large (%1x%2)", it, it);
355  } else {
356  text = i18n("Huge (%1x%2)", it, it);
357  }
358 
359  // save the size in the contextIconSizes map
360  contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
361  }
362  } else {
363  // Scalable icons.
364  const int progression[] = { 16, 22, 32, 48, 64, 96, 128, 192, 256 };
365 
366  for (int p : progression) {
367  for (int it : qAsConst(avSizes)) {
368  if (it >= p) {
369  QString text;
370  if (it < 19) {
371  text = i18n("Small (%1x%2)", it, it);
372  } else if (it < 25) {
373  text = i18n("Medium (%1x%2)", it, it);
374  } else if (it < 35) {
375  text = i18n("Large (%1x%2)", it, it);
376  } else {
377  text = i18n("Huge (%1x%2)", it, it);
378  }
379 
380  // save the size in the contextIconSizes map
381  contextIconSizes.insert(contextSize->addAction(text, q, SLOT(slotContextIconSize())), it);
382  break;
383  }
384  }
385  }
386  }
387 
388  QActionGroup *sizeGroup = new QActionGroup(contextSize);
389  const auto sizeActions = contextSize->actions();
390  for (QAction *action : sizeActions) {
391  action->setActionGroup(sizeGroup);
392  action->setCheckable(true);
393  }
394 
395  if (!q->toolBarsLocked() && !q->isMovable()) {
396  unlockedMovable = false;
397  }
398 
399  delete contextLockAction;
400  contextLockAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("system-lock-screen")), i18n("Lock Toolbar Positions"), q);
401  contextLockAction->setChecked(q->toolBarsLocked());
402  connect(contextLockAction, SIGNAL(toggled(bool)), q, SLOT(slotLockToolBars(bool)));
403 
404  // Now add the actions to the menu
405  context->addMenu(contextMode);
406  context->addMenu(contextSize);
407  context->addMenu(contextOrient);
408  context->addSeparator();
409 
410  connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow()));
411  }
412 
413  contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos));
414  if (contextButtonAction) {
415  contextShowText->setText(contextButtonAction->text());
416  contextShowText->setIcon(contextButtonAction->icon());
417  contextShowText->setCheckable(true);
418  }
419 
420  contextOrient->menuAction()->setVisible(!q->toolBarsLocked());
421  // Unplugging a submenu from abouttohide leads to the popupmenu floating around
422  // So better simply call that code from after exec() returns (DF)
423  //connect(context, SIGNAL(aboutToHide()), this, SLOT(slotContextAboutToHide()));
424 
425  return context;
426 }
427 
428 void KToolBar::Private::setLocked(bool locked)
429 {
430  if (unlockedMovable) {
431  q->setMovable(!locked);
432  }
433 }
434 
435 void KToolBar::Private::adjustSeparatorVisibility()
436 {
437  bool visibleNonSeparator = false;
438  int separatorToShow = -1;
439 
440  for (int index = 0; index < q->actions().count(); ++index) {
441  QAction *action = q->actions().at(index);
442  if (action->isSeparator()) {
443  if (visibleNonSeparator) {
444  separatorToShow = index;
445  visibleNonSeparator = false;
446  } else {
447  action->setVisible(false);
448  }
449  } else if (!visibleNonSeparator) {
450  if (action->isVisible()) {
451  visibleNonSeparator = true;
452  if (separatorToShow != -1) {
453  q->actions().at(separatorToShow)->setVisible(true);
454  separatorToShow = -1;
455  }
456  }
457  }
458  }
459 
460  if (separatorToShow != -1) {
461  q->actions().at(separatorToShow)->setVisible(false);
462  }
463 }
464 
465 Qt::ToolButtonStyle KToolBar::Private::toolButtonStyleFromString(const QString &_style)
466 {
467  QString style = _style.toLower();
468  if (style == QLatin1String("textbesideicon") || style == QLatin1String("icontextright")) {
470  } else if (style == QLatin1String("textundericon") || style == QLatin1String("icontextbottom")) {
472  } else if (style == QLatin1String("textonly")) {
473  return Qt::ToolButtonTextOnly;
474  } else {
475  return Qt::ToolButtonIconOnly;
476  }
477 }
478 
479 QString KToolBar::Private::toolButtonStyleToString(Qt::ToolButtonStyle style)
480 {
481  switch (style) {
483  default:
484  return QStringLiteral("IconOnly");
486  return QStringLiteral("TextBesideIcon");
488  return QStringLiteral("TextOnly");
490  return QStringLiteral("TextUnderIcon");
491  }
492 }
493 
494 Qt::ToolBarArea KToolBar::Private::positionFromString(const QString &position)
495 {
496  Qt::ToolBarArea newposition = Qt::TopToolBarArea;
497  if (position == QLatin1String("left")) {
498  newposition = Qt::LeftToolBarArea;
499  } else if (position == QLatin1String("bottom")) {
500  newposition = Qt::BottomToolBarArea;
501  } else if (position == QLatin1String("right")) {
502  newposition = Qt::RightToolBarArea;
503  }
504  return newposition;
505 }
506 
507 // Global setting was changed
508 void KToolBar::Private::slotAppearanceChanged()
509 {
510  loadKDESettings();
511  applyCurrentSettings();
512 }
513 
514 Qt::ToolButtonStyle KToolBar::Private::toolButtonStyleSetting()
515 {
516  KConfigGroup group(KSharedConfig::openConfig(), "Toolbar style");
517  const QString fallback = KToolBar::Private::toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
518  return KToolBar::Private::toolButtonStyleFromString(group.readEntry("ToolButtonStyle", fallback));
519 }
520 
521 void KToolBar::Private::loadKDESettings()
522 {
523  iconSizeSettings[Level_KDEDefault] = q->iconSizeDefault();
524 
525  if (isMainToolBar) {
526  toolButtonStyleSettings[Level_KDEDefault] = toolButtonStyleSetting();
527  } else {
528  const QString fallBack = toolButtonStyleToString(Qt::ToolButtonTextBesideIcon);
544  KConfigGroup group(KSharedConfig::openConfig(), "Toolbar style");
545  const QString value = group.readEntry("ToolButtonStyleOtherToolbars", fallBack);
546  toolButtonStyleSettings[Level_KDEDefault] = KToolBar::Private::toolButtonStyleFromString(value);
547  }
548 }
549 
550 // Call this after changing something in d->iconSizeSettings or d->toolButtonStyleSettings
551 void KToolBar::Private::applyCurrentSettings()
552 {
553  //qCDebug(DEBUG_KXMLGUI) << q->objectName() << "iconSizeSettings:" << iconSizeSettings.toString() << "->" << iconSizeSettings.currentValue();
554  const int currentIconSize = iconSizeSettings.currentValue();
555  q->setIconSize(QSize(currentIconSize, currentIconSize));
556  //qCDebug(DEBUG_KXMLGUI) << q->objectName() << "toolButtonStyleSettings:" << toolButtonStyleSettings.toString() << "->" << toolButtonStyleSettings.currentValue();
557  q->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(toolButtonStyleSettings.currentValue()));
558 
559  // And remember to save the new look later
560  KMainWindow *kmw = q->mainWindow();
561  if (kmw) {
562  kmw->setSettingsDirty();
563  }
564 }
565 
566 QAction *KToolBar::Private::findAction(const QString &actionName, KXMLGUIClient **clientOut) const
567 {
568  for (KXMLGUIClient *client : xmlguiClients) {
569  QAction *action = client->actionCollection()->action(actionName);
570  if (action) {
571  if (clientOut) {
572  *clientOut = client;
573  }
574  return action;
575  }
576  }
577  return nullptr;
578 }
579 
580 void KToolBar::Private::slotContextAboutToShow()
581 {
590  KXmlGuiWindow *kmw = qobject_cast<KXmlGuiWindow *>(q->mainWindow());
591 
592  // try to find "configure toolbars" action
593  QAction *configureAction = nullptr;
595  configureAction = findAction(QLatin1String(actionName));
596 
597  if (!configureAction && kmw) {
598  configureAction = kmw->actionCollection()->action(QLatin1String(actionName));
599  }
600 
601  if (configureAction) {
602  context->addAction(configureAction);
603  }
604 
605  context->addAction(contextLockAction);
606 
607  if (kmw) {
609  // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar)
610  QAction *tbAction = kmw->toolBarMenuAction();
611  if (!q->toolBarsLocked() && tbAction && !tbAction->associatedWidgets().isEmpty()) {
612  context->addAction(tbAction);
613  }
614  }
615 
616  KEditToolBar::setGlobalDefaultToolBar(q->QObject::objectName().toLatin1().constData());
617 
618  // Check the actions that should be checked
619  switch (q->toolButtonStyle()) {
621  default:
622  contextIcons->setChecked(true);
623  break;
625  contextTextRight->setChecked(true);
626  break;
628  contextText->setChecked(true);
629  break;
631  contextTextUnder->setChecked(true);
632  break;
633  }
634 
635  QMapIterator< QAction *, int > it = contextIconSizes;
636  while (it.hasNext()) {
637  it.next();
638  if (it.value() == q->iconSize().width()) {
639  it.key()->setChecked(true);
640  break;
641  }
642  }
643 
644  switch (q->mainWindow()->toolBarArea(q)) {
646  contextBottom->setChecked(true);
647  break;
648  case Qt::LeftToolBarArea:
649  contextLeft->setChecked(true);
650  break;
652  contextRight->setChecked(true);
653  break;
654  default:
655  case Qt::TopToolBarArea:
656  contextTop->setChecked(true);
657  break;
658  }
659 
660  const bool showButtonSettings = contextButtonAction
661  && !contextShowText->text().isEmpty()
662  && contextTextRight->isChecked();
663  contextButtonTitle->setVisible(showButtonSettings);
664  contextShowText->setVisible(showButtonSettings);
665  if (showButtonSettings) {
666  contextShowText->setChecked(contextButtonAction->priority() >= QAction::NormalPriority);
667  }
668 }
669 
670 void KToolBar::Private::slotContextAboutToHide()
671 {
672  // We have to unplug whatever slotContextAboutToShow plugged into the menu.
673  // Unplug the toolbar menu action
674  KXmlGuiWindow *kmw = qobject_cast<KXmlGuiWindow *>(q->mainWindow());
675  if (kmw && kmw->toolBarMenuAction()) {
676  if (kmw->toolBarMenuAction()->associatedWidgets().count() > 1) {
677  context->removeAction(kmw->toolBarMenuAction());
678  }
679  }
680 
681  // Unplug the configure toolbars action too, since it's afterwards anyway
682  QAction *configureAction = nullptr;
684  configureAction = findAction(QLatin1String(actionName));
685 
686  if (!configureAction && kmw) {
687  configureAction = kmw->actionCollection()->action(QLatin1String(actionName));
688  }
689 
690  if (configureAction) {
691  context->removeAction(configureAction);
692  }
693 
694  context->removeAction(contextLockAction);
695 }
696 
697 void KToolBar::Private::slotContextLeft()
698 {
700 }
701 
702 void KToolBar::Private::slotContextRight()
703 {
705 }
706 
707 void KToolBar::Private::slotContextShowText()
708 {
709  Q_ASSERT(contextButtonAction);
710  const QAction::Priority priority = contextShowText->isChecked()
712  contextButtonAction->setPriority(priority);
713 
714  // Find to which xml file and componentData the action belongs to
715  QString componentName;
716  QString filename;
717  KXMLGUIClient *client;
718  if (findAction(contextButtonAction->objectName(), &client)) {
719  componentName = client->componentName();
720  filename = client->xmlFile();
721  }
722  if (filename.isEmpty()) {
723  componentName = QCoreApplication::applicationName();
724  filename = componentName + QLatin1String("ui.rc");
725  }
726 
727  // Save the priority state of the action
728  const QString configFile = KXMLGUIFactory::readConfigFile(filename, componentName);
729 
730  QDomDocument document;
731  document.setContent(configFile);
733  QDomElement actionElem = KXMLGUIFactory::findActionByName(elem, contextButtonAction->objectName(), true);
734  actionElem.setAttribute(QStringLiteral("priority"), priority);
735  KXMLGUIFactory::saveConfigFile(document, filename, componentName);
736 }
737 
738 void KToolBar::Private::slotContextTop()
739 {
741 }
742 
743 void KToolBar::Private::slotContextBottom()
744 {
746 }
747 
748 void KToolBar::Private::slotContextIcons()
749 {
751  toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle();
752 }
753 
754 void KToolBar::Private::slotContextText()
755 {
757  toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle();
758 }
759 
760 void KToolBar::Private::slotContextTextUnder()
761 {
763  toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle();
764 }
765 
766 void KToolBar::Private::slotContextTextRight()
767 {
769  toolButtonStyleSettings[Level_UserSettings] = q->toolButtonStyle();
770 }
771 
772 void KToolBar::Private::slotContextIconSize()
773 {
774  QAction *action = qobject_cast<QAction *>(q->sender());
775  if (action && contextIconSizes.contains(action)) {
776  const int iconSize = contextIconSizes.value(action);
777  q->setIconDimensions(iconSize);
778  }
779 }
780 
781 void KToolBar::Private::slotLockToolBars(bool lock)
782 {
783  q->setToolBarsLocked(lock);
784 }
785 
786 KToolBar::KToolBar(QWidget *parent, bool isMainToolBar, bool readConfig)
787  : QToolBar(parent),
788  d(new Private(this))
789 {
790  d->init(readConfig, isMainToolBar);
791 
792  // KToolBar is auto-added to the top area of the main window if parent is a QMainWindow
793  if (QMainWindow *mw = qobject_cast<QMainWindow *>(parent)) {
794  mw->addToolBar(this);
795  }
796 }
797 
799  : QToolBar(parent),
800  d(new Private(this))
801 {
802  setObjectName(objectName);
803  // mainToolBar -> isMainToolBar = true -> buttonStyle is configurable
804  // others -> isMainToolBar = false -> ### hardcoded default for buttonStyle !!! should be configurable? -> hidden key added
805  d->init(readConfig, (objectName == QLatin1String("mainToolBar")));
806 
807  // KToolBar is auto-added to the top area of the main window if parent is a QMainWindow
808  if (QMainWindow *mw = qobject_cast<QMainWindow *>(parent)) {
809  mw->addToolBar(this);
810  }
811 }
812 
814  bool newLine, bool isMainToolBar, bool readConfig)
815  : QToolBar(parent),
816  d(new Private(this))
817 {
818  setObjectName(objectName);
819  d->init(readConfig, isMainToolBar);
820 
821  if (newLine) {
822  mainWindow()->addToolBarBreak(area);
823  }
824 
825  mainWindow()->addToolBar(area, this);
826 
827  if (newLine) {
828  mainWindow()->addToolBarBreak(area);
829  }
830 }
831 
833 {
834  delete d->contextLockAction;
835  delete d;
836 }
837 
838 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
840 {
841  d->enableContext = enable;
842 }
843 #endif
844 
845 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
847 {
848  return d->enableContext;
849 }
850 #endif
851 
853 {
854  Q_ASSERT(!cg.name().isEmpty());
855 
856  const int currentIconSize = iconSize().width();
857  //qCDebug(DEBUG_KXMLGUI) << objectName() << currentIconSize << d->iconSizeSettings.toString() << "defaultValue=" << d->iconSizeSettings.defaultValue();
858  if (!cg.hasDefault("IconSize") && currentIconSize == d->iconSizeSettings.defaultValue()) {
859  cg.revertToDefault("IconSize");
860  d->iconSizeSettings[Level_UserSettings] = Unset;
861  } else {
862  cg.writeEntry("IconSize", currentIconSize);
863  d->iconSizeSettings[Level_UserSettings] = currentIconSize;
864  }
865 
866  const Qt::ToolButtonStyle currentToolButtonStyle = toolButtonStyle();
867  if (!cg.hasDefault("ToolButtonStyle") && currentToolButtonStyle == d->toolButtonStyleSettings.defaultValue()) {
868  cg.revertToDefault("ToolButtonStyle");
869  d->toolButtonStyleSettings[Level_UserSettings] = Unset;
870  } else {
871  cg.writeEntry("ToolButtonStyle", d->toolButtonStyleToString(currentToolButtonStyle));
872  d->toolButtonStyleSettings[Level_UserSettings] = currentToolButtonStyle;
873  }
874 }
875 
876 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
878 {
879  d->xmlguiClients.clear();
880  d->xmlguiClients << client;
881 }
882 #endif
883 
885 {
886  d->xmlguiClients << client;
887 }
888 
890 {
891  d->xmlguiClients.remove(client);
892 }
893 
894 void KToolBar::contextMenuEvent(QContextMenuEvent *event)
895 {
896 #if KXMLGUI_BUILD_DEPRECATED_SINCE(5, 0)
897  if (mainWindow() && d->enableContext) {
898  QPointer<KToolBar> guard(this);
899  const QPoint globalPos = event->globalPos();
900  d->contextMenu(globalPos)->exec(globalPos);
901 
902  // "Configure Toolbars" recreates toolbars, so we might not exist anymore.
903  if (guard) {
904  d->slotContextAboutToHide();
905  }
906  return;
907  }
908 #endif
909 
911 }
912 
913 void KToolBar::loadState(const QDomElement &element)
914 {
915  QMainWindow *mw = mainWindow();
916  if (!mw) {
917  return;
918  }
919 
920  {
921  const QString& i18nText = KToolbarHelper::i18nToolBarName(element);
922  if (!i18nText.isEmpty()) {
923  setWindowTitle(i18nText);
924  }
925  }
926 
927  /*
928  This method is called in order to load toolbar settings from XML.
929  However this can be used in two rather different cases:
930  - for the initial loading of the app's XML. In that case the settings
931  are only the defaults (Level_AppXML), the user's KConfig settings will override them
932 
933  - for later re-loading when switching between parts in KXMLGUIFactory.
934  In that case the XML contains the final settings, not the defaults.
935  We do need the defaults, and the toolbar might have been completely
936  deleted and recreated meanwhile. So we store the app-default settings
937  into the XML.
938  */
939  bool loadingAppDefaults = true;
940  if (element.hasAttribute(QStringLiteral("tempXml"))) {
941  // this isn't the first time, so the app-xml defaults have been saved into the (in-memory) XML
942  loadingAppDefaults = false;
943  const QString iconSizeDefault = element.attribute(QStringLiteral("iconSizeDefault"));
944  if (!iconSizeDefault.isEmpty()) {
945  d->iconSizeSettings[Level_AppXML] = iconSizeDefault.toInt();
946  }
947  const QString toolButtonStyleDefault = element.attribute(QStringLiteral("toolButtonStyleDefault"));
948  if (!toolButtonStyleDefault.isEmpty()) {
949  d->toolButtonStyleSettings[Level_AppXML] = d->toolButtonStyleFromString(toolButtonStyleDefault);
950  }
951  } else {
952  // loading app defaults
953  bool newLine = false;
954  QString attrNewLine = element.attribute(QStringLiteral("newline")).toLower();
955  if (!attrNewLine.isEmpty()) {
956  newLine = (attrNewLine == QLatin1String("true"));
957  }
958  if (newLine && mw) {
959  mw->insertToolBarBreak(this);
960  }
961  }
962 
963  int newIconSize = -1;
964  if (element.hasAttribute(QStringLiteral("iconSize"))) {
965  bool ok;
966  newIconSize = element.attribute(QStringLiteral("iconSize")).trimmed().toInt(&ok);
967  if (!ok) {
968  newIconSize = -1;
969  }
970  }
971  if (newIconSize != -1) {
972  d->iconSizeSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = newIconSize;
973  }
974 
975  const QString newToolButtonStyle = element.attribute(QStringLiteral("iconText"));
976  if (!newToolButtonStyle.isEmpty()) {
977  d->toolButtonStyleSettings[loadingAppDefaults ? Level_AppXML : Level_UserSettings] = d->toolButtonStyleFromString(newToolButtonStyle);
978  }
979 
980  bool hidden = false;
981  {
982  QString attrHidden = element.attribute(QStringLiteral("hidden")).toLower();
983  if (!attrHidden.isEmpty()) {
984  hidden = (attrHidden == QLatin1String("true"));
985  }
986  }
987 
989  {
990  QString attrPosition = element.attribute(QStringLiteral("position")).toLower();
991  if (!attrPosition.isEmpty()) {
992  pos = KToolBar::Private::positionFromString(attrPosition);
993  }
994  }
995  if (pos != Qt::NoToolBarArea) {
996  mw->addToolBar(pos, this);
997  }
998 
999  setVisible(!hidden);
1000 
1001  d->applyCurrentSettings();
1002 }
1003 
1004 // Called when switching between xmlgui clients, in order to find any unsaved settings
1005 // again when switching back to the current xmlgui client.
1006 void KToolBar::saveState(QDomElement &current) const
1007 {
1008  Q_ASSERT(!current.isNull());
1009 
1010  current.setAttribute(QStringLiteral("tempXml"), QStringLiteral("true"));
1011 
1012  current.setAttribute(QStringLiteral("noMerge"), QStringLiteral("1"));
1013  current.setAttribute(QStringLiteral("position"), d->getPositionAsString().toLower());
1014  current.setAttribute(QStringLiteral("hidden"), isHidden() ? QStringLiteral("true") : QStringLiteral("false"));
1015 
1016  const int currentIconSize = iconSize().width();
1017  if (currentIconSize == d->iconSizeSettings.defaultValue()) {
1018  current.removeAttribute(QStringLiteral("iconSize"));
1019  } else {
1020  current.setAttribute(QStringLiteral("iconSize"), iconSize().width());
1021  }
1022 
1023  if (toolButtonStyle() == d->toolButtonStyleSettings.defaultValue()) {
1024  current.removeAttribute(QStringLiteral("iconText"));
1025  } else {
1026  current.setAttribute(QStringLiteral("iconText"), d->toolButtonStyleToString(toolButtonStyle()));
1027  }
1028 
1029  // Note: if this method is used by more than KXMLGUIBuilder, e.g. to save XML settings to *disk*,
1030  // then the stuff below shouldn't always be done. This is not the case currently though.
1031  if (d->iconSizeSettings[Level_AppXML] != Unset) {
1032  current.setAttribute(QStringLiteral("iconSizeDefault"), d->iconSizeSettings[Level_AppXML]);
1033  }
1034  if (d->toolButtonStyleSettings[Level_AppXML] != Unset) {
1035  const Qt::ToolButtonStyle bs = static_cast<Qt::ToolButtonStyle>(d->toolButtonStyleSettings[Level_AppXML]);
1036  current.setAttribute(QStringLiteral("toolButtonStyleDefault"), d->toolButtonStyleToString(bs));
1037  }
1038 }
1039 
1040 // called by KMainWindow::applyMainWindowSettings to read from the user settings
1042 {
1043  Q_ASSERT(!cg.name().isEmpty());
1044 
1045  if (cg.hasKey("IconSize")) {
1046  d->iconSizeSettings[Level_UserSettings] = cg.readEntry("IconSize", 0);
1047  }
1048  if (cg.hasKey("ToolButtonStyle")) {
1049  d->toolButtonStyleSettings[Level_UserSettings] = d->toolButtonStyleFromString(cg.readEntry("ToolButtonStyle", QString()));
1050  }
1051 
1052  d->applyCurrentSettings();
1053 }
1054 
1056 {
1057  return qobject_cast<KMainWindow *>(const_cast<QObject *>(parent()));
1058 }
1059 
1061 {
1062  QToolBar::setIconSize(QSize(size, size));
1063  d->iconSizeSettings[Level_UserSettings] = size;
1064 }
1065 
1067 {
1069 }
1070 
1071 void KToolBar::slotMovableChanged(bool movable)
1072 {
1073  if (movable && !KAuthorized::authorize(QStringLiteral("movable_toolbars"))) {
1074  setMovable(false);
1075  }
1076 }
1077 
1078 void KToolBar::dragEnterEvent(QDragEnterEvent *event)
1079 {
1081  event->mimeData()->hasFormat(QStringLiteral("application/x-kde-action-list"))) {
1082  QByteArray data = event->mimeData()->data(QStringLiteral("application/x-kde-action-list"));
1083 
1084  QDataStream stream(data);
1085 
1086  QStringList actionNames;
1087 
1088  stream >> actionNames;
1089 
1090  const auto allCollections = KActionCollection::allCollections();
1091  for (const QString &actionName : qAsConst(actionNames)) {
1092  for (KActionCollection *ac : allCollections) {
1093  QAction *newAction = ac->action(actionName);
1094  if (newAction) {
1095  d->actionsBeingDragged.append(newAction);
1096  break;
1097  }
1098  }
1099  }
1100 
1101  if (!d->actionsBeingDragged.isEmpty()) {
1102  QAction *overAction = actionAt(event->pos());
1103 
1104  QFrame *dropIndicatorWidget = new QFrame(this);
1105  dropIndicatorWidget->resize(8, height() - 4);
1106  dropIndicatorWidget->setFrameShape(QFrame::VLine);
1107  dropIndicatorWidget->setLineWidth(3);
1108 
1109  d->dropIndicatorAction = insertWidget(overAction, dropIndicatorWidget);
1110 
1111  insertAction(overAction, d->dropIndicatorAction);
1112 
1113  event->acceptProposedAction();
1114  return;
1115  }
1116  }
1117 
1118  QToolBar::dragEnterEvent(event);
1119 }
1120 
1121 void KToolBar::dragMoveEvent(QDragMoveEvent *event)
1122 {
1123  if (toolBarsEditable())
1124  Q_FOREVER {
1125  if (d->dropIndicatorAction)
1126  {
1127  QAction *overAction = nullptr;
1128  const auto actions = this->actions();
1129  for (QAction *action : actions) {
1130  // want to make it feel that half way across an action you're dropping on the other side of it
1131  QWidget *widget = widgetForAction(action);
1132  if (event->pos().x() < widget->pos().x() + (widget->width() / 2)) {
1133  overAction = action;
1134  break;
1135  }
1136  }
1137 
1138  if (overAction != d->dropIndicatorAction) {
1139  // Check to see if the indicator is already in the right spot
1140  int dropIndicatorIndex = actions.indexOf(d->dropIndicatorAction);
1141  if (dropIndicatorIndex + 1 < actions.count()) {
1142  if (actions.at(dropIndicatorIndex + 1) == overAction) {
1143  break;
1144  }
1145  } else if (!overAction) {
1146  break;
1147  }
1148 
1149  insertAction(overAction, d->dropIndicatorAction);
1150  }
1151 
1152  event->accept();
1153  return;
1154  }
1155  break;
1156  }
1157 
1158  QToolBar::dragMoveEvent(event);
1159 }
1160 
1161 void KToolBar::dragLeaveEvent(QDragLeaveEvent *event)
1162 {
1163  // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey)
1164  delete d->dropIndicatorAction;
1165  d->dropIndicatorAction = nullptr;
1166  d->actionsBeingDragged.clear();
1167 
1168  if (toolBarsEditable()) {
1169  event->accept();
1170  return;
1171  }
1172 
1173  QToolBar::dragLeaveEvent(event);
1174 }
1175 
1176 void KToolBar::dropEvent(QDropEvent *event)
1177 {
1178  if (toolBarsEditable()) {
1179  for (QAction *action : qAsConst(d->actionsBeingDragged)) {
1180  if (actions().contains(action)) {
1181  removeAction(action);
1182  }
1183  insertAction(d->dropIndicatorAction, action);
1184  }
1185  }
1186 
1187  // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey)
1188  delete d->dropIndicatorAction;
1189  d->dropIndicatorAction = nullptr;
1190  d->actionsBeingDragged.clear();
1191 
1192  if (toolBarsEditable()) {
1193  event->accept();
1194  return;
1195  }
1196 
1197  QToolBar::dropEvent(event);
1198 }
1199 
1200 void KToolBar::mousePressEvent(QMouseEvent *event)
1201 {
1202  if (toolBarsEditable() && event->button() == Qt::LeftButton) {
1203  if (QAction *action = actionAt(event->pos())) {
1204  d->dragAction = action;
1205  d->dragStartPosition = event->pos();
1206  event->accept();
1207  return;
1208  }
1209  }
1210 
1212 }
1213 
1214 void KToolBar::mouseMoveEvent(QMouseEvent *event)
1215 {
1216  if (!toolBarsEditable() || !d->dragAction) {
1217  QToolBar::mouseMoveEvent(event);
1218  return;
1219  }
1220 
1221  if ((event->pos() - d->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) {
1222  event->accept();
1223  return;
1224  }
1225 
1226  QDrag *drag = new QDrag(this);
1227  QMimeData *mimeData = new QMimeData;
1228 
1229  QByteArray data;
1230  {
1231  QDataStream stream(&data, QIODevice::WriteOnly);
1232 
1233  QStringList actionNames;
1234  actionNames << d->dragAction->objectName();
1235 
1236  stream << actionNames;
1237  }
1238 
1239  mimeData->setData(QStringLiteral("application/x-kde-action-list"), data);
1240 
1241  drag->setMimeData(mimeData);
1242 
1243  Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
1244 
1245  if (dropAction == Qt::MoveAction)
1246  // Only remove from this toolbar if it was moved to another toolbar
1247  // Otherwise the receiver moves it.
1248  if (drag->target() != this) {
1249  removeAction(d->dragAction);
1250  }
1251 
1252  d->dragAction = nullptr;
1253  event->accept();
1254 }
1255 
1256 void KToolBar::mouseReleaseEvent(QMouseEvent *event)
1257 {
1258  // Want to clear this even if toolBarsEditable was changed mid-drag (unlikey)
1259  if (d->dragAction) {
1260  d->dragAction = nullptr;
1261  event->accept();
1262  return;
1263  }
1264 
1266 }
1267 
1268 bool KToolBar::eventFilter(QObject *watched, QEvent *event)
1269 {
1270  // Generate context menu events for disabled buttons too...
1271  if (event->type() == QEvent::MouseButtonPress) {
1272  QMouseEvent *me = static_cast<QMouseEvent *>(event);
1273  if (me->buttons() & Qt::RightButton)
1274  if (QWidget *ww = qobject_cast<QWidget *>(watched))
1275  if (ww->parent() == this && !ww->isEnabled()) {
1277  }
1278 
1279  } else if (event->type() == QEvent::ParentChange) {
1280  // Make sure we're not leaving stale event filters around,
1281  // when a child is reparented somewhere else
1282  if (QWidget *ww = qobject_cast<QWidget *>(watched)) {
1283  if (!this->isAncestorOf(ww)) {
1284  // New parent is not a subwidget - remove event filter
1285  ww->removeEventFilter(this);
1286  const auto children = ww->findChildren<QWidget *>();
1287  for (QWidget *child : children) {
1288  child->removeEventFilter(this);
1289  }
1290  }
1291  }
1292  }
1293 
1294  // Redirect mouse events to the toolbar when drag + drop editing is enabled
1295  if (toolBarsEditable()) {
1296  if (QWidget *ww = qobject_cast<QWidget *>(watched)) {
1297  switch (event->type()) {
1298  case QEvent::MouseButtonPress: {
1299  QMouseEvent *me = static_cast<QMouseEvent *>(event);
1300  QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1301  me->button(), me->buttons(), me->modifiers());
1302  mousePressEvent(&newEvent);
1303  return true;
1304  }
1305  case QEvent::MouseMove: {
1306  QMouseEvent *me = static_cast<QMouseEvent *>(event);
1307  QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1308  me->button(), me->buttons(), me->modifiers());
1309  mouseMoveEvent(&newEvent);
1310  return true;
1311  }
1313  QMouseEvent *me = static_cast<QMouseEvent *>(event);
1314  QMouseEvent newEvent(me->type(), mapFromGlobal(ww->mapToGlobal(me->pos())), me->globalPos(),
1315  me->button(), me->buttons(), me->modifiers());
1316  mouseReleaseEvent(&newEvent);
1317  return true;
1318  }
1319  default:
1320  break;
1321  }
1322  }
1323  }
1324 
1325  return QToolBar::eventFilter(watched, event);
1326 }
1327 
1328 void KToolBar::actionEvent(QActionEvent *event)
1329 {
1330  if (event->type() == QEvent::ActionRemoved) {
1331  QWidget *widget = widgetForAction(event->action());
1332  if (widget) {
1333  widget->removeEventFilter(this);
1334 
1335  const auto children = widget->findChildren<QWidget *>();
1336  for (QWidget *child : children) {
1337  child->removeEventFilter(this);
1338  }
1339  }
1340  }
1341 
1342  QToolBar::actionEvent(event);
1343 
1344  if (event->type() == QEvent::ActionAdded) {
1345  QWidget *widget = widgetForAction(event->action());
1346  if (widget) {
1347  widget->installEventFilter(this);
1348 
1349  const auto children = widget->findChildren<QWidget *>();
1350  for (QWidget *child : children) {
1351  child->installEventFilter(this);
1352  }
1353  // Center widgets that do not have any use for more space. See bug 165274
1354  if (!(widget->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag)
1355  // ... but do not center when using text besides icon in vertical toolbar. See bug 243196
1357  const int index = layout()->indexOf(widget);
1358  if (index != -1) {
1360  }
1361  }
1362  }
1363  }
1364 
1365  d->adjustSeparatorVisibility();
1366 }
1367 
1369 {
1370  return KToolBar::Private::s_editable;
1371 }
1372 
1374 {
1375  if (KToolBar::Private::s_editable != editable) {
1376  KToolBar::Private::s_editable = editable;
1377  }
1378 }
1379 
1381 {
1382  if (KToolBar::Private::s_locked != locked) {
1383  KToolBar::Private::s_locked = locked;
1384 
1385  const auto windows = KMainWindow::memberList();
1386  for (KMainWindow *mw : windows) {
1387  const auto toolbars = mw->findChildren<KToolBar *>();
1388  for (KToolBar *toolbar : toolbars) {
1389  toolbar->d->setLocked(locked);
1390  }
1391  }
1392  }
1393 }
1394 
1396 {
1397  return KToolBar::Private::s_locked;
1398 }
1399 
1401 {
1402 #ifdef QT_DBUS_LIB
1403  QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged"));
1404  QDBusConnection::sessionBus().send(message);
1405 #endif
1406 }
1407 
1408 #include "moc_ktoolbar.cpp"
QLayout * layout() const const
QAction * toolBarMenuAction()
Returns a pointer to the mainwindows action responsible for the toolbars menu.
void setText(const QString &text)
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
static QString readConfigFile(const QString &filename, const QString &componentName=QString())
A container for a set of QAction objects.
MouseButtonPress
QEvent::Type type() const const
virtual QLayoutItem * itemAt(int index) const const =0
virtual void dropEvent(QDropEvent *event)
int currentSize(KIconLoader::Group group) const
virtual ~KToolBar()
Destroys the toolbar.
Definition: ktoolbar.cpp:832
bool isHidden() const const
void setSettingsDirty()
Tell the main window that it should save its settings when being closed.
int width() const const
void orientationChanged(Qt::Orientation orientation)
static void setToolBarsLocked(bool locked)
Allows you to lock and unlock all toolbars (i.e., disallow/allow moving of the toobars).
Definition: ktoolbar.cpp:1380
bool contains(const Key &key) const const
virtual KActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
static void emitToolbarStyleChanged()
Emits a D-Bus signal to tell all toolbars in all applications, that the user settings have changed...
Definition: ktoolbar.cpp:1400
const QMimeData * mimeData() const const
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:38
void setAlignment(Qt::Alignment alignment)
void setMimeData(QMimeData *data)
void iconSizeChanged(const QSize &iconSize)
Qt::DropAction proposedAction() const const
QString attribute(const QString &name, const QString &defValue) const const
void saveSettings(KConfigGroup &cg)
Save the toolbar settings to group cg.
Definition: ktoolbar.cpp:852
virtual bool hasFormat(const QString &mimeType) const const
void allowedAreasChanged(Qt::ToolBarAreas allowedAreas)
bool hasDefault(const QString &key) const
QObject * sender() const const
void setChecked(bool)
virtual void dragLeaveEvent(QDragLeaveEvent *event)
virtual void dragEnterEvent(QDragEnterEvent *event)
static const QList< KActionCollection * > & allCollections()
Access the list of all action collections in existence for this app.
void setIcon(const QIcon &icon)
void setVisible(bool)
const T & at(int i) const const
const QObjectList & children() const const
QAction * actionAt(const QPoint &p) const const
QPoint pos() const const
virtual void setVisible(bool visible)
const char * name(StandardAction id)
LeftButton
void addToolBarBreak(Qt::ToolBarArea area)
bool isAncestorOf(const QWidget *child) const const
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
QDBusConnection sessionBus()
virtual QString componentName() const
virtual QString xmlFile() const
This will return the name of the XML file as set by setXMLFile().
virtual void dragMoveEvent(QDragMoveEvent *event)
Qt::MouseButtons buttons() const const
int iconSizeDefault() const
Returns the default size for this type of toolbar.
Definition: ktoolbar.cpp:1066
QAction * toggleViewAction() const const
virtual void mouseReleaseEvent(QMouseEvent *event)
bool eventFilter(QObject *watched, QEvent *event) override
Reimplemented to support context menu activation on disabled tool buttons.
Definition: ktoolbar.cpp:1268
static void setToolBarsEditable(bool editable)
Enable or disable toolbar editing via drag & drop of actions.
Definition: ktoolbar.cpp:1373
QAction * addAction(const QString &text)
AlignJustify
int x() const const
QList< int > querySizes(KIconLoader::Group group) const
void removeXMLGUIClient(KXMLGUIClient *client)
Removes an XML gui client that uses this toolbar.
Definition: ktoolbar.cpp:889
void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
ToolBarArea
QAction * action() const const
int width() const const
virtual int indexOf(QWidget *widget) const const
QList< T > findChildren(const QString &name, Qt::FindChildOptions options) const const
Qt::DropAction exec(Qt::DropActions supportedActions)
QSize size() const const
void insertAction(QAction *before, QAction *action)
QString number(int n, int base)
int count(const T &value) const const
QPoint globalPos() const const
virtual void contextMenuEvent(QContextMenuEvent *event)
Top level main window with predefined action layout.
Definition: kxmlguiwindow.h:45
bool isSeparator() const const
void installEventFilter(QObject *filterObj)
virtual void mousePressEvent(QMouseEvent *event)
bool hasAttribute(const QString &name) const const
Top level main window.
Definition: kmainwindow.h:96
QObject * target() const const
QMapIterator::Item next()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setAttribute(const QString &name, const QString &value)
QWidget * widgetForAction(QAction *action) const const
void setupToolbarMenuActions()
Qt::MouseButton button() const const
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
int toInt(bool *ok, int base) const const
bool isEmpty() const const
void setMovable(bool movable)
virtual void mouseMoveEvent(QMouseEvent *event)
bool send(const QDBusMessage &message) const const
bool isEmpty() const const
QString trimmed() const const
void setIconDimensions(int size)
Convenience function to set icon size.
Definition: ktoolbar.cpp:1060
void setContextMenuEnabled(bool enable=true)
This allows you to enable or disable the context menu.
Definition: ktoolbar.cpp:839
QPoint pos() const const
ToolButtonStyle
virtual bool eventFilter(QObject *watched, QEvent *event)
const Key & key() const const
const T & value() const const
static KIconLoader * global()
KIconTheme * theme() const
void setAcceptDrops(bool on)
Qt::KeyboardModifiers modifiers() const const
QList::iterator end()
QString toLower() const const
QAction * insertWidget(QAction *before, QWidget *widget)
QString name() const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void setCheckable(bool)
QCA_EXPORT void init()
bool hasKey(const QString &key) const
void addXMLGUIClient(KXMLGUIClient *client)
Adds an XML gui client that uses this toolbar.
Definition: ktoolbar.cpp:884
bool isNull() const const
KToolBar(QWidget *parent, bool isMainToolBar=false, bool readConfig=true)
Constructor.
Definition: ktoolbar.cpp:786
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const QString &componentName=QString())
QString i18n(const char *text, const TYPE &arg...)
if(recurs()&&!first)
static void setGlobalDefaultToolBar(const char *toolBarName)
Sets the default toolbar which will be auto-selected for all KEditToolBar instances.
char * toString(const T &value)
Floatable toolbar with auto resize.
Definition: ktoolbar.h:59
virtual bool event(QEvent *event) override
void insertToolBarBreak(QToolBar *before)
bool contextMenuEnabled() const
Returns the context menu enabled flag.
Definition: ktoolbar.cpp:846
Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const const
void setWindowTitle(const QString &)
QPoint mapFromGlobal(const QPoint &pos) const const
KCONFIGCORE_EXPORT bool authorize(const QString &action)
void removeAction(QAction *action)
QList< QWidget * > associatedWidgets() const const
char * data()
void loadState(const QDomElement &element)
Load state from an XML.
Definition: ktoolbar.cpp:913
QAction * action(int index) const
Return the QAction* at position index in the action collection.
QIcon fromTheme(const QString &name)
static bool toolBarsEditable()
Returns whether the toolbars are currently editable (drag & drop of actions).
Definition: ktoolbar.cpp:1368
QMap::iterator insert(const Key &key, const T &value)
void setIconSize(const QSize &iconSize)
QAction * menuAction() const const
void removeAttribute(const QString &name)
Vertical
void setData(const QString &mimeType, const QByteArray &data)
KMainWindow * mainWindow() const
Returns the main window that this toolbar is docked with.
Definition: ktoolbar.cpp:1055
QPoint pos() const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle)
KCONFIGCORE_EXPORT bool authorizeAction(const QString &action)
void postEvent(QObject *receiver, QEvent *event, int priority)
QList< QAction * > actions() const const
void movableChanged(bool movable)
T qobject_cast(QObject *object)
QObject * parent() const const
CopyAction
T readEntry(const QString &key, const T &aDefault) const
void revertToDefault(const QString &key)
QList::iterator begin()
static QDomElement actionPropertiesElement(QDomDocument &doc)
void setEnabled(bool)
void removeEventFilter(QObject *obj)
int height() const const
void applySettings(const KConfigGroup &cg)
Read the toolbar settings from group cg and apply them.
Definition: ktoolbar.cpp:1041
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)
void saveState(QDomElement &element) const
Save state into an XML.
Definition: ktoolbar.cpp:1006
static QList< KMainWindow * > memberList()
List of members of KMainWindow class.
bool hasNext() const const
static bool toolBarsLocked()
Returns whether the toolbars are locked (i.e., moving of the toobars disallowed). ...
Definition: ktoolbar.cpp:1395
void setXMLGUIClient(KXMLGUIClient *client)
Sets the XML gui client.
Definition: ktoolbar.cpp:877
QString applicationName()
Qt::Orientation orientation() const const
int startDragDistance()
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key, const T &defaultValue) const const
virtual void actionEvent(QActionEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:49:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.