Changeset View
Changeset View
Standalone View
Standalone View
src/ktoolbar.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 98 | #endif | |||
---|---|---|---|---|---|
106 | contextTop(nullptr), | 106 | contextTop(nullptr), | ||
107 | contextLeft(nullptr), | 107 | contextLeft(nullptr), | ||
108 | contextRight(nullptr), | 108 | contextRight(nullptr), | ||
109 | contextBottom(nullptr), | 109 | contextBottom(nullptr), | ||
110 | contextIcons(nullptr), | 110 | contextIcons(nullptr), | ||
111 | contextTextRight(nullptr), | 111 | contextTextRight(nullptr), | ||
112 | contextText(nullptr), | 112 | contextText(nullptr), | ||
113 | contextTextUnder(nullptr), | 113 | contextTextUnder(nullptr), | ||
114 | contextLockAction(nullptr), | 114 | contextEditModeAction(nullptr), | ||
115 | dropIndicatorAction(nullptr), | 115 | dropIndicatorAction(nullptr), | ||
116 | context(nullptr), | 116 | context(nullptr), | ||
117 | dragAction(nullptr) | 117 | dragAction(nullptr) | ||
118 | { | 118 | { | ||
119 | } | 119 | } | ||
120 | 120 | | |||
121 | void slotAppearanceChanged(); | 121 | void slotAppearanceChanged(); | ||
122 | void slotContextAboutToShow(); | 122 | void slotContextAboutToShow(); | ||
Show All 28 Lines | |||||
151 | KToolBar *q; | 151 | KToolBar *q; | ||
152 | bool isMainToolBar : 1; | 152 | bool isMainToolBar : 1; | ||
153 | #ifndef KXMLGUI_NO_DEPRECATED | 153 | #ifndef KXMLGUI_NO_DEPRECATED | ||
154 | bool enableContext : 1; | 154 | bool enableContext : 1; | ||
155 | #endif | 155 | #endif | ||
156 | bool unlockedMovable : 1; | 156 | bool unlockedMovable : 1; | ||
157 | static bool s_editable; | 157 | static bool s_editable; | ||
158 | static bool s_locked; | 158 | static bool s_locked; | ||
159 | static bool s_editMode; | ||||
159 | 160 | | |||
160 | QSet<KXMLGUIClient *> xmlguiClients; | 161 | QSet<KXMLGUIClient *> xmlguiClients; | ||
161 | 162 | | |||
162 | QMenu *contextOrient; | 163 | QMenu *contextOrient; | ||
163 | QMenu *contextMode; | 164 | QMenu *contextMode; | ||
164 | QMenu *contextSize; | 165 | QMenu *contextSize; | ||
165 | 166 | | |||
166 | QAction *contextButtonTitle; | 167 | QAction *contextButtonTitle; | ||
167 | QAction *contextShowText; | 168 | QAction *contextShowText; | ||
168 | QAction *contextButtonAction; | 169 | QAction *contextButtonAction; | ||
169 | QAction *contextTop; | 170 | QAction *contextTop; | ||
170 | QAction *contextLeft; | 171 | QAction *contextLeft; | ||
171 | QAction *contextRight; | 172 | QAction *contextRight; | ||
172 | QAction *contextBottom; | 173 | QAction *contextBottom; | ||
173 | QAction *contextIcons; | 174 | QAction *contextIcons; | ||
174 | QAction *contextTextRight; | 175 | QAction *contextTextRight; | ||
175 | QAction *contextText; | 176 | QAction *contextText; | ||
176 | QAction *contextTextUnder; | 177 | QAction *contextTextUnder; | ||
177 | KToggleAction *contextLockAction; | 178 | KToggleAction *contextEditModeAction; | ||
178 | QMap<QAction *, int> contextIconSizes; | 179 | QMap<QAction *, int> contextIconSizes; | ||
179 | 180 | | |||
180 | class IntSetting | 181 | class IntSetting | ||
181 | { | 182 | { | ||
182 | public: | 183 | public: | ||
183 | IntSetting() | 184 | IntSetting() | ||
184 | { | 185 | { | ||
185 | for (int level = 0; level < NSettingLevels; ++level) { | 186 | for (int level = 0; level < NSettingLevels; ++level) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
231 | 232 | | |||
232 | QMenu *context; | 233 | QMenu *context; | ||
233 | QAction *dragAction; | 234 | QAction *dragAction; | ||
234 | QPoint dragStartPosition; | 235 | QPoint dragStartPosition; | ||
235 | }; | 236 | }; | ||
236 | 237 | | |||
237 | bool KToolBar::Private::s_editable = false; | 238 | bool KToolBar::Private::s_editable = false; | ||
238 | bool KToolBar::Private::s_locked = true; | 239 | bool KToolBar::Private::s_locked = true; | ||
240 | bool KToolBar::Private::s_editMode = false; | ||||
239 | 241 | | |||
240 | void KToolBar::Private::init(bool readConfig, bool _isMainToolBar) | 242 | void KToolBar::Private::init(bool readConfig, bool _isMainToolBar) | ||
241 | { | 243 | { | ||
242 | isMainToolBar = _isMainToolBar; | 244 | isMainToolBar = _isMainToolBar; | ||
243 | loadKDESettings(); | 245 | loadKDESettings(); | ||
244 | 246 | | |||
245 | // also read in our configurable settings (for non-xmlgui toolbars) | 247 | // also read in our configurable settings (for non-xmlgui toolbars) | ||
246 | if (readConfig) { | 248 | if (readConfig) { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 297 | default: | |||
296 | return QStringLiteral("Top"); | 298 | return QStringLiteral("Top"); | ||
297 | } | 299 | } | ||
298 | } | 300 | } | ||
299 | 301 | | |||
300 | QMenu *KToolBar::Private::contextMenu(const QPoint &globalPos) | 302 | QMenu *KToolBar::Private::contextMenu(const QPoint &globalPos) | ||
301 | { | 303 | { | ||
302 | if (!context) { | 304 | if (!context) { | ||
303 | context = new QMenu(q); | 305 | context = new QMenu(q); | ||
306 | context->setToolTipsVisible(true); | ||||
304 | 307 | | |||
305 | contextButtonTitle = context->addSection(i18nc("@title:menu", "Show Text")); | 308 | contextButtonTitle = context->addSection(i18nc("@title:menu", "Show Text")); | ||
306 | contextShowText = context->addAction(QString(), q, SLOT(slotContextShowText())); | 309 | contextShowText = context->addAction(QString(), q, SLOT(slotContextShowText())); | ||
307 | 310 | | |||
308 | context->addSection(i18nc("@title:menu", "Toolbar Settings")); | 311 | context->addSection(i18nc("@title:menu", "Toolbar Settings")); | ||
309 | 312 | | |||
310 | contextOrient = new QMenu(i18nc("Toolbar orientation", "Orientation"), context); | 313 | contextOrient = new QMenu(i18nc("Toolbar orientation", "Orientation"), context); | ||
311 | 314 | | |||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 398 | Q_FOREACH (QAction *action, contextSize->actions()) { | |||
396 | action->setActionGroup(sizeGroup); | 399 | action->setActionGroup(sizeGroup); | ||
397 | action->setCheckable(true); | 400 | action->setCheckable(true); | ||
398 | } | 401 | } | ||
399 | 402 | | |||
400 | if (!q->toolBarsLocked() && !q->isMovable()) { | 403 | if (!q->toolBarsLocked() && !q->isMovable()) { | ||
401 | unlockedMovable = false; | 404 | unlockedMovable = false; | ||
402 | } | 405 | } | ||
403 | 406 | | |||
404 | delete contextLockAction; | 407 | delete contextEditModeAction; | ||
405 | contextLockAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("system-lock-screen")), i18n("Lock Toolbar Positions"), q); | 408 | contextEditModeAction = new KToggleAction(QIcon::fromTheme(QStringLiteral("document-edit")), i18n("Editable Toolbar"), q); | ||
406 | contextLockAction->setChecked(q->toolBarsLocked()); | 409 | contextEditModeAction->setToolTip(i18n("Enables dragging the whole toolbar as well as dragging any action within the toolbar.")); | ||
407 | connect(contextLockAction, SIGNAL(toggled(bool)), q, SLOT(slotLockToolBars(bool))); | 410 | contextEditModeAction->setChecked(s_editMode); | ||
411 | connect(contextEditModeAction, &QAction::toggled, q, [this](bool toggled) { | ||||
412 | s_editMode = toggled; | ||||
413 | q->setToolBarsLocked(!toggled); | ||||
414 | q->setToolBarsEditable(toggled); | ||||
415 | }); | ||||
408 | 416 | | |||
409 | // Now add the actions to the menu | 417 | // Now add the actions to the menu | ||
apol: Isn't it better to set a parent like for the other ona than use the QScopedPointer? | |||||
I'm also surprised by the inconsistency, and I bet future readers will be too. As to whether it should all be ported to QScopedPointer, I'm not convinced. Technically, I would bet that deletion by the parent is faster than deleting each children individually with e.g. QScopedPointer (because that will have to remove from the list of children in the parent, so it means N linear searches). dfaure: I'm also surprised by the inconsistency, and I bet future readers will be too.
As to whether… | |||||
410 | context->addMenu(contextMode); | 418 | context->addMenu(contextMode); | ||
411 | context->addMenu(contextSize); | 419 | context->addMenu(contextSize); | ||
Is this a case where &KToolBar::setToolBarsEditable would work, without the need for a lambda? dfaure: Is this a case where &KToolBar::setToolBarsEditable would work, without the need for a lambda? | |||||
412 | context->addMenu(contextOrient); | 420 | context->addMenu(contextOrient); | ||
413 | context->addSeparator(); | 421 | context->addSeparator(); | ||
414 | 422 | | |||
415 | connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow())); | 423 | connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow())); | ||
416 | } | 424 | } | ||
417 | 425 | | |||
418 | contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos)); | 426 | contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos)); | ||
419 | if (contextButtonAction) { | 427 | if (contextButtonAction) { | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 594 | { | |||
602 | if (!configureAction && kmw) { | 610 | if (!configureAction && kmw) { | ||
603 | configureAction = kmw->actionCollection()->action(QLatin1String(actionName)); | 611 | configureAction = kmw->actionCollection()->action(QLatin1String(actionName)); | ||
604 | } | 612 | } | ||
605 | 613 | | |||
606 | if (configureAction) { | 614 | if (configureAction) { | ||
607 | context->addAction(configureAction); | 615 | context->addAction(configureAction); | ||
608 | } | 616 | } | ||
609 | 617 | | |||
610 | context->addAction(contextLockAction); | 618 | context->addAction(contextEditModeAction); | ||
611 | 619 | | |||
612 | if (kmw) { | 620 | if (kmw) { | ||
613 | kmw->setupToolbarMenuActions(); | 621 | kmw->setupToolbarMenuActions(); | ||
614 | // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar) | 622 | // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar) | ||
615 | QAction *tbAction = kmw->toolBarMenuAction(); | 623 | QAction *tbAction = kmw->toolBarMenuAction(); | ||
616 | if (!q->toolBarsLocked() && tbAction && tbAction->associatedWidgets().count() > 0) { | 624 | if (!q->toolBarsLocked() && tbAction && tbAction->associatedWidgets().count() > 0) { | ||
617 | context->addAction(tbAction); | 625 | context->addAction(tbAction); | ||
618 | } | 626 | } | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 684 | { | |||
691 | if (!configureAction && kmw) { | 699 | if (!configureAction && kmw) { | ||
692 | configureAction = kmw->actionCollection()->action(QLatin1String(actionName)); | 700 | configureAction = kmw->actionCollection()->action(QLatin1String(actionName)); | ||
693 | } | 701 | } | ||
694 | 702 | | |||
695 | if (configureAction) { | 703 | if (configureAction) { | ||
696 | context->removeAction(configureAction); | 704 | context->removeAction(configureAction); | ||
697 | } | 705 | } | ||
698 | 706 | | |||
699 | context->removeAction(contextLockAction); | 707 | context->removeAction(contextEditModeAction); | ||
700 | } | 708 | } | ||
701 | 709 | | |||
702 | void KToolBar::Private::slotContextLeft() | 710 | void KToolBar::Private::slotContextLeft() | ||
703 | { | 711 | { | ||
704 | q->mainWindow()->addToolBar(Qt::LeftToolBarArea, q); | 712 | q->mainWindow()->addToolBar(Qt::LeftToolBarArea, q); | ||
705 | } | 713 | } | ||
706 | 714 | | |||
707 | void KToolBar::Private::slotContextRight() | 715 | void KToolBar::Private::slotContextRight() | ||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 830 | { | |||
831 | 839 | | |||
832 | if (newLine) { | 840 | if (newLine) { | ||
833 | mainWindow()->addToolBarBreak(area); | 841 | mainWindow()->addToolBarBreak(area); | ||
834 | } | 842 | } | ||
835 | } | 843 | } | ||
836 | 844 | | |||
837 | KToolBar::~KToolBar() | 845 | KToolBar::~KToolBar() | ||
838 | { | 846 | { | ||
839 | delete d->contextLockAction; | 847 | delete d->contextEditModeAction; | ||
840 | delete d; | 848 | delete d; | ||
841 | } | 849 | } | ||
842 | 850 | | |||
843 | #ifndef KXMLGUI_NO_DEPRECATED | 851 | #ifndef KXMLGUI_NO_DEPRECATED | ||
844 | void KToolBar::setContextMenuEnabled(bool enable) | 852 | void KToolBar::setContextMenuEnabled(bool enable) | ||
845 | { | 853 | { | ||
846 | d->enableContext = enable; | 854 | d->enableContext = enable; | ||
847 | } | 855 | } | ||
▲ Show 20 Lines • Show All 544 Lines • ▼ Show 20 Line(s) | 1383 | if (event->type() == QEvent::ActionAdded) { | |||
1392 | } | 1400 | } | ||
1393 | } | 1401 | } | ||
1394 | 1402 | | |||
1395 | d->adjustSeparatorVisibility(); | 1403 | d->adjustSeparatorVisibility(); | ||
1396 | } | 1404 | } | ||
1397 | 1405 | | |||
1398 | bool KToolBar::toolBarsEditable() | 1406 | bool KToolBar::toolBarsEditable() | ||
1399 | { | 1407 | { | ||
1400 | return KToolBar::Private::s_editable; | 1408 | return KToolBar::Private::s_editable || KToolBar::Private::s_editMode; | ||
1401 | } | 1409 | } | ||
1402 | 1410 | | |||
1403 | void KToolBar::setToolBarsEditable(bool editable) | 1411 | void KToolBar::setToolBarsEditable(bool editable) | ||
1404 | { | 1412 | { | ||
1405 | if (KToolBar::Private::s_editable != editable) { | 1413 | if (KToolBar::Private::s_editable != editable) { | ||
1406 | KToolBar::Private::s_editable = editable; | 1414 | KToolBar::Private::s_editable = editable; | ||
1407 | } | 1415 | } | ||
1408 | } | 1416 | } | ||
1409 | 1417 | | |||
1410 | void KToolBar::setToolBarsLocked(bool locked) | 1418 | void KToolBar::setToolBarsLocked(bool locked) | ||
1411 | { | 1419 | { | ||
1412 | if (KToolBar::Private::s_locked != locked) { | 1420 | if (KToolBar::Private::s_locked != locked) { | ||
1413 | KToolBar::Private::s_locked = locked; | 1421 | KToolBar::Private::s_locked = locked; | ||
1414 | 1422 | | |||
1415 | Q_FOREACH (KMainWindow *mw, KMainWindow::memberList()) { | 1423 | Q_FOREACH (KMainWindow *mw, KMainWindow::memberList()) { | ||
1416 | Q_FOREACH (KToolBar *toolbar, mw->findChildren<KToolBar *>()) { | 1424 | Q_FOREACH (KToolBar *toolbar, mw->findChildren<KToolBar *>()) { | ||
1417 | toolbar->d->setLocked(locked); | 1425 | toolbar->d->setLocked(locked); | ||
1418 | } | 1426 | } | ||
1419 | } | 1427 | } | ||
1420 | } | 1428 | } | ||
1421 | } | 1429 | } | ||
1422 | 1430 | | |||
1423 | bool KToolBar::toolBarsLocked() | 1431 | bool KToolBar::toolBarsLocked() | ||
1424 | { | 1432 | { | ||
1425 | return KToolBar::Private::s_locked; | 1433 | return KToolBar::Private::s_locked || !KToolBar::Private::s_editMode; | ||
1426 | } | 1434 | } | ||
1427 | 1435 | | |||
1428 | void KToolBar::emitToolbarStyleChanged() | 1436 | void KToolBar::emitToolbarStyleChanged() | ||
1429 | { | 1437 | { | ||
1430 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged")); | 1438 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged")); | ||
1431 | QDBusConnection::sessionBus().send(message); | 1439 | QDBusConnection::sessionBus().send(message); | ||
1432 | } | 1440 | } | ||
1433 | 1441 | | |||
1434 | #include "moc_ktoolbar.cpp" | 1442 | #include "moc_ktoolbar.cpp" |
Isn't it better to set a parent like for the other ona than use the QScopedPointer?