Commit 6a3fc58c authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Add read/save support for keyboard shortcuts.

- Store toolbar actions into action collection of class KXMLGUIClient,
  which is required to be listed in the shortcuts settings dialog.
  To be able to access tool bar actions with tbb_... constants, save
  tool bar actions in WorkToolBar::m_actions, which makes WorkToolBar::m_toolButtons
  and class ToolButton obsolate; tool bar related cursors are stored in
  WorkToolBar::m_cursors.
- Save changed shortcuts in [Shortcuts] section of umbrello settings file 'umbrellorc'
- Show tool bar button shortcut in button tooltip.

CCBUG:124804
parent 94d0b31a
......@@ -936,6 +936,9 @@ void UMLApp::saveOptions()
m_toolsbar->saveSettings(workBarConfig);
fileOpenRecent->saveEntries(m_config->group("Recent Files"));
KConfigGroup shortcutConfig(m_config, "Shortcuts");
actionCollection()->writeSettings(&shortcutConfig, false);
UmbrelloSettings::setGeometry(size());
Settings::OptionState& optionState = Settings::optionState();
......@@ -1063,6 +1066,10 @@ void UMLApp::readOptions()
size = QApplication::desktop()->screenGeometry().size();
resize(size);
enableUndo(Settings::optionState().generalState.undo);
KConfigGroup shortCutConfig(m_config, "Shortcuts");
actionCollection()->readSettings(&shortCutConfig);
m_toolsbar->setupActions();
}
/**
......
......@@ -20,9 +20,10 @@
// kde include files
#include <klocale.h>
#include <KAction>
#include <KActionCollection>
// qt include files
#include <QAction>
#include <QToolButton>
/**
......@@ -64,9 +65,8 @@ WorkToolBar::~WorkToolBar()
*/
QAction* WorkToolBar::insertHotBtn(ToolBar_Buttons tbb)
{
QAction* action = addAction(QIcon(m_ToolButtons[tbb].Symbol), m_ToolButtons[tbb].Label,
/*receiver*/this, /*member*/m_ToolButtons[tbb].Slot);
m_actions[tbb] = action;
KAction *action = m_actions[tbb];
addAction(action);
action->setChecked(true);
return action;
}
......@@ -243,7 +243,7 @@ void WorkToolBar::buttonChanged(int b)
*/
QCursor WorkToolBar::currentCursor()
{
return m_ToolButtons[m_CurrentButtonID].Cursor;
return m_cursors[m_CurrentButtonID];
}
/**
......@@ -305,7 +305,7 @@ void WorkToolBar::loadPixmaps()
const Icon_Utils::IconType icon;
const char *slotName;
} buttonInfo[] = {
{ tbb_Arrow, i18nc("selection arrow", "Select"), Icon_Utils::it_Arrow, SLOT(slotArrow()) },
{ tbb_Object, i18n("Object"), Icon_Utils::it_Object, SLOT(slotObject()) },
{ tbb_Seq_Message_Synchronous, i18n("Synchronous Message"), Icon_Utils::it_Message_Sync, SLOT(slotSeq_Message_Synchronous()) },
{ tbb_Seq_Message_Asynchronous, i18n("Asynchronous Message"), Icon_Utils::it_Message_Async, SLOT(slotSeq_Message_Asynchronous()) },
......@@ -372,26 +372,20 @@ void WorkToolBar::loadPixmaps()
};
const size_t n_buttonInfos = sizeof(buttonInfo) / sizeof(ButtonInfo);
/* m_ToolButtons.insert(tbb_Undefined,
ToolButton(i18n("UNDEFINED"),
Icon_Utils::BarIcon(Icon_Utils::Arrow),
QCursor(),
SLOT(slotArrow()))); */
m_ToolButtons.insert(tbb_Arrow,
ToolButton(i18nc("selection arrow", "Select"),
Icon_Utils::BarIcon(Icon_Utils::it_Arrow),
QCursor(),
SLOT(slotArrow())));
KActionCollection *collection = UMLApp::app()->actionCollection();
for (uint i = 0; i < n_buttonInfos; ++i) {
const ButtonInfo& info = buttonInfo[i];
m_ToolButtons.insert(info.tbb,
ToolButton(info.btnName,
Icon_Utils::BarIcon(info.icon),
Icon_Utils::Cursor(info.icon),
info.slotName));
QString key = QLatin1String(ENUM_NAME(WorkToolBar, ToolBar_Buttons, info.tbb));
KAction *action = collection->addAction(key, this, info.slotName);
action->setIcon(KIcon(Icon_Utils::BarIcon(info.icon)));
action->setText(info.btnName);
m_actions[info.tbb] = action;
m_cursors[info.tbb] = Icon_Utils::Cursor(info.icon);
}
// umbrello code use qt provided arrow cursor
m_cursors[tbb_Arrow] = defaultCursor();
setupActions();
}
/**
......@@ -461,4 +455,18 @@ void WorkToolBar::slotCategory() { buttonChanged(tbb_Category);
void WorkToolBar::slotCategory2Parent() { buttonChanged(tbb_Category2Parent); }
void WorkToolBar::slotChild2Category() { buttonChanged(tbb_Child2Category); }
/**
* Setup actions after reading shortcuts from settings
*/
void WorkToolBar::setupActions()
{
foreach(QAction *action, m_actions) {
if (!action->shortcut().isEmpty()) {
action->setToolTip(action->text() + "\t[" + action->shortcut().toString() + "]");
}
else
action->setToolTip(action->text());
}
}
#include "worktoolbar.moc"
......@@ -20,7 +20,7 @@
#include <QPixmap>
class QMainWindow;
class QAction;
class KAction;
/**
* This is the toolbar that is displayed on the right-hand side of the program
......@@ -49,6 +49,8 @@ public:
void setOldTool();
void setDefaultTool();
void setupActions();
/**
* Enumeration of all available toolbar buttons.
*/
......@@ -121,29 +123,13 @@ public:
private:
typedef QMap<Uml::DiagramType::Enum, ToolBar_Buttons> OldToolMap;
/**
* This inner class holds label, symbol, and cursor of a tool button.
*/
class ToolButton
{
public:
QString Label;
QPixmap Symbol;
QCursor Cursor;
const char* Slot;
ToolButton() : Label(QString("?")), Symbol(QPixmap()), Cursor(QCursor()), Slot("") { }
ToolButton(const QString& lbl, const QPixmap& smb, const QCursor& cur, const char* slot) :
Label(lbl), Symbol(smb), Cursor(cur), Slot(slot) { }
};
typedef QMap<ToolBar_Buttons, ToolButton> ToolButtonMap;
typedef QMap<ToolBar_Buttons, QAction*> ActionsMap;
typedef QMap<ToolBar_Buttons, QCursor> CursorMap;
typedef QMap<ToolBar_Buttons, KAction*> ActionsMap;
ToolBar_Buttons m_CurrentButtonID;
OldToolMap m_map;
Uml::DiagramType::Enum m_Type;
ToolButtonMap m_ToolButtons;
CursorMap m_cursors;
ActionsMap m_actions;
void loadPixmaps();
......
Markdown is supported
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