Skip to content

Commit

Permalink
+ fixes #1719: Show current shortcuts (S) in menus and hover text.
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 31, 2014
1 parent 80e80fe commit ce528d1
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 66 deletions.
44 changes: 28 additions & 16 deletions src/Gui/Action.cpp
Expand Up @@ -772,21 +772,27 @@ UndoAction::~UndoAction()
void UndoAction::addTo (QWidget * w)
{
if (w->inherits("QToolBar")) {
// Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore.
_toolAction->setText(_action->text());
_toolAction->setToolTip(_action->toolTip());
_toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon());
actionChanged();
connect(_action, SIGNAL(changed()), this, SLOT(actionChanged()));
w->addAction(_toolAction);
}
else {
w->addAction(_action);
}
}

void UndoAction::actionChanged()
{
// Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore.
_toolAction->setText(_action->text());
_toolAction->setToolTip(_action->toolTip());
_toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon());
}

void UndoAction::setEnabled(bool b)
{
Action::setEnabled(b);
Expand Down Expand Up @@ -819,21 +825,27 @@ RedoAction::~RedoAction()
void RedoAction::addTo ( QWidget * w )
{
if (w->inherits("QToolBar")) {
// Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore.
_toolAction->setText(_action->text());
_toolAction->setToolTip(_action->toolTip());
_toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon());
actionChanged();
connect(_action, SIGNAL(changed()), this, SLOT(actionChanged()));
w->addAction(_toolAction);
}
else {
w->addAction(_action);
}
}

void RedoAction::actionChanged()
{
// Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore.
_toolAction->setText(_action->text());
_toolAction->setToolTip(_action->toolTip());
_toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon());
}

void RedoAction::setEnabled ( bool b )
{
Action::setEnabled(b);
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/Action.h
Expand Up @@ -219,6 +219,9 @@ class GuiExport UndoAction : public Action
void setEnabled(bool);
void setVisible(bool);

private Q_SLOTS:
void actionChanged();

private:
QAction* _toolAction;
};
Expand All @@ -241,6 +244,9 @@ class GuiExport RedoAction : public Action
void setEnabled(bool);
void setVisible(bool);

private Q_SLOTS:
void actionChanged();

private:
QAction* _toolAction;
};
Expand Down
69 changes: 40 additions & 29 deletions src/Gui/Command.cpp
Expand Up @@ -557,35 +557,41 @@ const char * Command::endCmdHelp(void)
return "</body></html>\n\n";
}

void Command::applyCommandData(Action* action)
void Command::applyCommandData(const char* context, Action* action)
{
action->setText(QCoreApplication::translate(
this->className(), sMenuText, 0,
context, getMenuText(), 0,
QCoreApplication::UnicodeUTF8));
action->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8));
if (sStatusTip)
action->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0,
context, getStatusTip(), 0,
QCoreApplication::UnicodeUTF8));
else
action->setStatusTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8));
if (sWhatsThis)
action->setWhatsThis(QCoreApplication::translate(
this->className(), sWhatsThis, 0,
context, getWhatsThis(), 0,
QCoreApplication::UnicodeUTF8));
else
action->setWhatsThis(QCoreApplication::translate(
this->className(), sToolTipText, 0,
context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8));
QString accel = action->shortcut().toString();
QString accel = action->shortcut().toString(QKeySequence::NativeText);
if (!accel.isEmpty()) {
QString tip = QString::fromAscii("(%1)\t%2")
// show shortcut inside tooltip
QString ttip = QString::fromLatin1("%1 (%2)")
.arg(action->toolTip()).arg(accel);
action->setToolTip(ttip);

// show shortcut inside status tip
QString stip = QString::fromLatin1("(%1)\t%2")
.arg(accel).arg(action->statusTip());
action->setStatusTip(tip);
action->setStatusTip(stip);
}
}

Expand Down Expand Up @@ -647,18 +653,18 @@ Action * Command::createAction(void)
Action *pcAction;

pcAction = new Action(this,getMainWindow());
applyCommandData(pcAction);
pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));

return pcAction;
}

void Command::languageChange()
{
if (_pcAction) {
applyCommandData(_pcAction);
applyCommandData(this->className(), _pcAction);
}
}

Expand Down Expand Up @@ -700,10 +706,26 @@ Action * MacroCommand::createAction(void)
pcAction->setText(QString::fromUtf8(sMenuText));
pcAction->setToolTip(QString::fromUtf8(sToolTipText));
pcAction->setStatusTip(QString::fromUtf8(sStatusTip));
if (pcAction->statusTip().isEmpty())
pcAction->setStatusTip(pcAction->toolTip());
pcAction->setWhatsThis(QString::fromUtf8(sWhatsThis));
if ( sPixmap )
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
pcAction->setShortcut(QString::fromAscii(sAccel));

QString accel = pcAction->shortcut().toString(QKeySequence::NativeText);
if (!accel.isEmpty()) {
// show shortcut inside tooltip
QString ttip = QString::fromLatin1("%1 (%2)")
.arg(pcAction->toolTip()).arg(accel);
pcAction->setToolTip(ttip);

// show shortcut inside status tip
QString stip = QString::fromLatin1("(%1)\t%2")
.arg(accel).arg(pcAction->statusTip());
pcAction->setStatusTip(stip);
}

return pcAction;
}

Expand Down Expand Up @@ -854,12 +876,7 @@ bool PythonCommand::isActive(void)
void PythonCommand::languageChange()
{
if (_pcAction) {
_pcAction->setText (qApp->translate(getName(), getMenuText ()));
_pcAction->setToolTip (qApp->translate(getName(), getToolTipText()));
_pcAction->setStatusTip (qApp->translate(getName(), getStatusTip ()));
_pcAction->setWhatsThis (qApp->translate(getName(), getWhatsThis ()));
if (_pcAction->statusTip().isEmpty())
_pcAction->setStatusTip(qApp->translate(getName(), getToolTipText()));
applyCommandData(getName(), _pcAction);
}
}

Expand All @@ -879,16 +896,10 @@ Action * PythonCommand::createAction(void)
Action *pcAction;

pcAction = new Action(this,getMainWindow());

pcAction->setText (qApp->translate(getName(), getMenuText ()));
pcAction->setToolTip (qApp->translate(getName(), getToolTipText()));
pcAction->setStatusTip (qApp->translate(getName(), getStatusTip ()));
pcAction->setWhatsThis (qApp->translate(getName(), getWhatsThis ()));
if (pcAction->statusTip().isEmpty())
pcAction->setStatusTip(qApp->translate(getName(), getToolTipText()));
pcAction->setShortcut(QString::fromAscii(getAccel()));
applyCommandData(this->getName(), pcAction);
if (strcmp(getResource("Pixmap"),"") != 0)
pcAction->setIcon(Gui::BitmapFactory().pixmap(getResource("Pixmap")));
pcAction->setShortcut (QString::fromAscii(getAccel()));

return pcAction;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Command.h
Expand Up @@ -160,7 +160,7 @@ class GuiExport Command : public CommandBase
/// Creates the used Action
virtual Action * createAction(void);
/// Applies the menu text, tool and status tip to the passed action object
void applyCommandData(Action* );
void applyCommandData(const char* context, Action* );
const char* keySequenceToAccel(int) const;
void adjustCameraPosition();
//@}
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/CommandDoc.cpp
Expand Up @@ -724,10 +724,10 @@ Action * StdCmdUndo::createAction(void)
Action *pcAction;

pcAction = new UndoAction(this,getMainWindow());
applyCommandData(pcAction);
pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));

return pcAction;
}
Expand Down Expand Up @@ -767,10 +767,10 @@ Action * StdCmdRedo::createAction(void)
Action *pcAction;

pcAction = new RedoAction(this,getMainWindow());
applyCommandData(pcAction);
pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));

return pcAction;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/CommandStd.cpp
Expand Up @@ -125,10 +125,10 @@ Action * StdCmdWorkbench::createAction(void)
Action *pcAction;

pcAction = new WorkbenchGroup(this,getMainWindow());
applyCommandData(pcAction);
pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));

return pcAction;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ Action * StdCmdRecentFiles::createAction(void)
RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow());
pcAction->setObjectName(QLatin1String("recentFiles"));
pcAction->setDropDownMenu(true);
applyCommandData(pcAction);
applyCommandData(this->className(), pcAction);
return pcAction;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Gui/CommandView.cpp
Expand Up @@ -224,7 +224,7 @@ Action * StdCmdFreezeViews::createAction(void)
{
ActionGroup* pcAction = new ActionGroup(this, getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(pcAction);
applyCommandData(this->className(), pcAction);

// add the action items
saveView = pcAction->addAction(QObject::tr("Save views..."));
Expand Down Expand Up @@ -559,7 +559,7 @@ Gui::Action * StdCmdDrawStyle::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(pcAction);
applyCommandData(this->className(), pcAction);

QAction* a0 = pcAction->addAction(QString());
a0->setCheckable(true);
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/CommandWindow.cpp
Expand Up @@ -316,7 +316,7 @@ Action * StdCmdDockViewMenu::createAction(void)
{
Action *pcAction;
pcAction = new DockWidgetAction(this, getMainWindow());
applyCommandData(pcAction);
applyCommandData(this->className(), pcAction);
return pcAction;
}

Expand Down Expand Up @@ -351,7 +351,7 @@ Action * StdCmdToolBarMenu::createAction(void)
{
Action *pcAction;
pcAction = new ToolBarAction(this, getMainWindow());
applyCommandData(pcAction);
applyCommandData(this->className(), pcAction);
return pcAction;
}

Expand Down
18 changes: 16 additions & 2 deletions src/Gui/DlgActionsImp.cpp
Expand Up @@ -28,6 +28,7 @@
# include <QFileInfo>
# include <QHeaderView>
# include <QImageReader>
# include <QKeySequence>
# include <QMessageBox>
# include <QTextStream>
#endif
Expand Down Expand Up @@ -261,7 +262,7 @@ void DlgCustomActionsImp::on_buttonAddAction_clicked()
m_sPixmap = QString::null;

if (!actionAccel->text().isEmpty()) {
macro->setAccel(actionAccel->text().toAscii());
macro->setAccel(actionAccel->text().toAscii());
}
actionAccel->clear();

Expand Down Expand Up @@ -329,9 +330,22 @@ void DlgCustomActionsImp::on_buttonReplaceAction_clicked()
action->setToolTip(QString::fromUtf8(macro->getToolTipText()));
action->setWhatsThis(QString::fromUtf8(macro->getWhatsThis()));
action->setStatusTip(QString::fromUtf8(macro->getStatusTip()));
if( macro->getPixmap() )
if (macro->getPixmap())
action->setIcon(Gui::BitmapFactory().pixmap(macro->getPixmap()));
action->setShortcut(QString::fromAscii(macro->getAccel()));

QString accel = action->shortcut().toString(QKeySequence::NativeText);
if (!accel.isEmpty()) {
// show shortcut inside tooltip
QString ttip = QString::fromLatin1("%1 (%2)")
.arg(action->toolTip()).arg(accel);
action->setToolTip(ttip);

// show shortcut inside status tip
QString stip = QString::fromLatin1("(%1)\t%2")
.arg(accel).arg(action->statusTip());
action->setStatusTip(stip);
}
}

// emit signal to notify the container widget
Expand Down

0 comments on commit ce528d1

Please sign in to comment.