Commit 6b7aeec9 authored by Peter Penz's avatar Peter Penz
Browse files

Toolbar-buttons: Allow easier configuration of text-visibility

When "Text Alongside Icons" is selected it is possible already to configure for each toolbar-button whether the text should be shown. However the configuration setting is quite hidden under Configure Toolbars... -> Change Text... -> [x] "Hide text when toolbar shows text alongside icons" and some users where not aware about such a setting at all (see bug 257918 and duplicates).

The patch provides an additional entry in the context-menu that allows to switch the text-visibility of a button by one click.

CCBUG: 257918
parent 1ed8e4ca
......@@ -97,6 +97,20 @@ class KToolBar::Private
#endif
unlockedMovable(true),
xmlguiClient(0),
contextOrient(0),
contextMode(0),
contextSize(0),
contextButtonTitle(0),
contextShowText(0),
contextButtonAction(0),
contextTop(0),
contextLeft(0),
contextRight(0),
contextBottom(0),
contextIcons(0),
contextTextRight(0),
contextText(0),
contextTextUnder(0),
contextLockAction(0),
dropIndicatorAction(0),
context(0),
......@@ -109,6 +123,7 @@ class KToolBar::Private
void slotContextAboutToHide();
void slotContextLeft();
void slotContextRight();
void slotContextShowText();
void slotContextTop();
void slotContextBottom();
void slotContextIcons();
......@@ -120,7 +135,7 @@ class KToolBar::Private
void init(bool readConfig = true, bool isMainToolBar = false);
QString getPositionAsString() const;
KMenu *contextMenu();
KMenu *contextMenu(const QPoint &globalPos);
void setLocked(bool locked);
void adjustSeparatorVisibility();
void loadKDESettings();
......@@ -145,6 +160,9 @@ class KToolBar::Private
QMenu* contextMode;
QMenu* contextSize;
QAction* contextButtonTitle;
QAction* contextShowText;
QAction* contextButtonAction;
QAction* contextTop;
QAction* contextLeft;
QAction* contextRight;
......@@ -265,11 +283,15 @@ QString KToolBar::Private::getPositionAsString() const
}
}
KMenu *KToolBar::Private::contextMenu()
KMenu *KToolBar::Private::contextMenu(const QPoint &globalPos)
{
if (!context) {
context = new KMenu(q);
context->addTitle(i18n("Toolbar Settings"));
contextButtonTitle = context->addTitle(i18nc("@title:menu", "Show Text"));
contextShowText = context->addAction(QString(), q, SLOT(slotContextShowText()));
context->addTitle(i18nc("@title:menu", "Toolbar Settings"));
contextOrient = new KMenu(i18n("Orientation"), context);
......@@ -376,6 +398,13 @@ KMenu *KToolBar::Private::contextMenu()
connect(context, SIGNAL(aboutToShow()), q, SLOT(slotContextAboutToShow()));
}
contextButtonAction = q->actionAt(q->mapFromGlobal(globalPos));
if (contextButtonAction) {
contextShowText->setText(contextButtonAction->text());
contextShowText->setIcon(contextButtonAction->icon());
contextShowText->setCheckable(true);
}
contextOrient->menuAction()->setVisible(!q->toolBarsLocked());
// Unplugging a submenu from abouttohide leads to the popupmenu floating around
// So better simply call that code from after exec() returns (DF)
......@@ -592,6 +621,13 @@ void KToolBar::Private::slotContextAboutToShow()
contextTop->setChecked(true);
break;
}
const bool showButtonSettings = contextButtonAction && contextTextRight->isChecked();
contextButtonTitle->setVisible(showButtonSettings);
contextShowText->setVisible(showButtonSettings);
if (showButtonSettings) {
contextShowText->setChecked(contextButtonAction->priority() >= QAction::NormalPriority);
}
}
void KToolBar::Private::slotContextAboutToHide()
......@@ -633,6 +669,26 @@ void KToolBar::Private::slotContextRight()
q->mainWindow()->addToolBar(Qt::RightToolBarArea, q);
}
void KToolBar::Private::slotContextShowText()
{
Q_ASSERT(contextButtonAction);
const QAction::Priority priority = contextShowText->isChecked()
? QAction::NormalPriority : QAction::LowPriority;
contextButtonAction->setPriority(priority);
// Save the priority state of the action
const KComponentData& componentData = KGlobal::mainComponent();
const QString componentName = componentData.componentName() + "ui.rc";
const QString configFile = KXMLGUIFactory::readConfigFile(componentName, componentData);
QDomDocument document;
document.setContent(configFile);
QDomElement elem = KXMLGUIFactory::actionPropertiesElement(document);
QDomElement actionElem = KXMLGUIFactory::findActionByName(elem, contextButtonAction->objectName(), true);
actionElem.setAttribute("priority", priority);
KXMLGUIFactory::saveConfigFile(document, componentName, componentData);
}
void KToolBar::Private::slotContextTop()
{
q->mainWindow()->addToolBar(Qt::TopToolBarArea, q);
......@@ -781,7 +837,8 @@ void KToolBar::contextMenuEvent(QContextMenuEvent* event)
#ifndef KDE_NO_DEPRECATED
if (mainWindow() && d->enableContext) {
QPointer<KToolBar> guard(this);
d->contextMenu()->exec(event->globalPos());
const QPoint globalPos = event->globalPos();
d->contextMenu(globalPos)->exec(globalPos);
// "Configure Toolbars" recreates toolbars, so we might not exist anymore.
if (guard) {
......
......@@ -234,6 +234,7 @@ public:
Q_PRIVATE_SLOT( d, void slotContextAboutToHide() )
Q_PRIVATE_SLOT( d, void slotContextLeft() )
Q_PRIVATE_SLOT( d, void slotContextRight() )
Q_PRIVATE_SLOT( d, void slotContextShowText() )
Q_PRIVATE_SLOT( d, void slotContextTop() )
Q_PRIVATE_SLOT( d, void slotContextBottom() )
Q_PRIVATE_SLOT( d, void slotContextIcons() )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment