KXmlGui

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

KDE's Doxygen guidelines are available online.