+ fixes #0001719: Show current shortcuts (S) in menus and hover text.

This commit is contained in:
wmayer 2014-08-31 14:28:33 +02:00
parent 80e80fef83
commit ce528d1c4a
13 changed files with 141 additions and 66 deletions

View File

@ -772,6 +772,17 @@ UndoAction::~UndoAction()
void UndoAction::addTo (QWidget * w) void UndoAction::addTo (QWidget * w)
{ {
if (w->inherits("QToolBar")) { if (w->inherits("QToolBar")) {
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 // Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the // reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore. // result that it doesn't work anymore.
@ -780,11 +791,6 @@ void UndoAction::addTo (QWidget * w)
_toolAction->setStatusTip(_action->statusTip()); _toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis()); _toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon()); _toolAction->setIcon(_action->icon());
w->addAction(_toolAction);
}
else {
w->addAction(_action);
}
} }
void UndoAction::setEnabled(bool b) void UndoAction::setEnabled(bool b)
@ -819,6 +825,17 @@ RedoAction::~RedoAction()
void RedoAction::addTo ( QWidget * w ) void RedoAction::addTo ( QWidget * w )
{ {
if (w->inherits("QToolBar")) { if (w->inherits("QToolBar")) {
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 // Do NOT set the shortcut again for _toolAction since this is already
// reserved for _action. Otherwise we get an ambiguity of it with the // reserved for _action. Otherwise we get an ambiguity of it with the
// result that it doesn't work anymore. // result that it doesn't work anymore.
@ -827,11 +844,6 @@ void RedoAction::addTo ( QWidget * w )
_toolAction->setStatusTip(_action->statusTip()); _toolAction->setStatusTip(_action->statusTip());
_toolAction->setWhatsThis(_action->whatsThis()); _toolAction->setWhatsThis(_action->whatsThis());
_toolAction->setIcon(_action->icon()); _toolAction->setIcon(_action->icon());
w->addAction(_toolAction);
}
else {
w->addAction(_action);
}
} }
void RedoAction::setEnabled ( bool b ) void RedoAction::setEnabled ( bool b )

View File

@ -219,6 +219,9 @@ public:
void setEnabled(bool); void setEnabled(bool);
void setVisible(bool); void setVisible(bool);
private Q_SLOTS:
void actionChanged();
private: private:
QAction* _toolAction; QAction* _toolAction;
}; };
@ -241,6 +244,9 @@ public:
void setEnabled(bool); void setEnabled(bool);
void setVisible(bool); void setVisible(bool);
private Q_SLOTS:
void actionChanged();
private: private:
QAction* _toolAction; QAction* _toolAction;
}; };

View File

@ -557,35 +557,41 @@ const char * Command::endCmdHelp(void)
return "</body></html>\n\n"; return "</body></html>\n\n";
} }
void Command::applyCommandData(Action* action) void Command::applyCommandData(const char* context, Action* action)
{ {
action->setText(QCoreApplication::translate( action->setText(QCoreApplication::translate(
this->className(), sMenuText, 0, context, getMenuText(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
action->setToolTip(QCoreApplication::translate( action->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0, context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
if (sStatusTip) if (sStatusTip)
action->setStatusTip(QCoreApplication::translate( action->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0, context, getStatusTip(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
else else
action->setStatusTip(QCoreApplication::translate( action->setStatusTip(QCoreApplication::translate(
this->className(), sToolTipText, 0, context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
if (sWhatsThis) if (sWhatsThis)
action->setWhatsThis(QCoreApplication::translate( action->setWhatsThis(QCoreApplication::translate(
this->className(), sWhatsThis, 0, context, getWhatsThis(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
else else
action->setWhatsThis(QCoreApplication::translate( action->setWhatsThis(QCoreApplication::translate(
this->className(), sToolTipText, 0, context, getToolTipText(), 0,
QCoreApplication::UnicodeUTF8)); QCoreApplication::UnicodeUTF8));
QString accel = action->shortcut().toString(); QString accel = action->shortcut().toString(QKeySequence::NativeText);
if (!accel.isEmpty()) { 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()); .arg(accel).arg(action->statusTip());
action->setStatusTip(tip); action->setStatusTip(stip);
} }
} }
@ -647,10 +653,10 @@ Action * Command::createAction(void)
Action *pcAction; Action *pcAction;
pcAction = new Action(this,getMainWindow()); pcAction = new Action(this,getMainWindow());
applyCommandData(pcAction); pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap) if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction; return pcAction;
} }
@ -658,7 +664,7 @@ Action * Command::createAction(void)
void Command::languageChange() void Command::languageChange()
{ {
if (_pcAction) { if (_pcAction) {
applyCommandData(_pcAction); applyCommandData(this->className(), _pcAction);
} }
} }
@ -700,10 +706,26 @@ Action * MacroCommand::createAction(void)
pcAction->setText(QString::fromUtf8(sMenuText)); pcAction->setText(QString::fromUtf8(sMenuText));
pcAction->setToolTip(QString::fromUtf8(sToolTipText)); pcAction->setToolTip(QString::fromUtf8(sToolTipText));
pcAction->setStatusTip(QString::fromUtf8(sStatusTip)); pcAction->setStatusTip(QString::fromUtf8(sStatusTip));
if (pcAction->statusTip().isEmpty())
pcAction->setStatusTip(pcAction->toolTip());
pcAction->setWhatsThis(QString::fromUtf8(sWhatsThis)); pcAction->setWhatsThis(QString::fromUtf8(sWhatsThis));
if ( sPixmap ) if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(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; return pcAction;
} }
@ -854,12 +876,7 @@ bool PythonCommand::isActive(void)
void PythonCommand::languageChange() void PythonCommand::languageChange()
{ {
if (_pcAction) { if (_pcAction) {
_pcAction->setText (qApp->translate(getName(), getMenuText ())); applyCommandData(getName(), _pcAction);
_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()));
} }
} }
@ -879,16 +896,10 @@ Action * PythonCommand::createAction(void)
Action *pcAction; Action *pcAction;
pcAction = new Action(this,getMainWindow()); pcAction = new Action(this,getMainWindow());
pcAction->setShortcut(QString::fromAscii(getAccel()));
pcAction->setText (qApp->translate(getName(), getMenuText ())); applyCommandData(this->getName(), pcAction);
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()));
if (strcmp(getResource("Pixmap"),"") != 0) if (strcmp(getResource("Pixmap"),"") != 0)
pcAction->setIcon(Gui::BitmapFactory().pixmap(getResource("Pixmap"))); pcAction->setIcon(Gui::BitmapFactory().pixmap(getResource("Pixmap")));
pcAction->setShortcut (QString::fromAscii(getAccel()));
return pcAction; return pcAction;
} }

View File

@ -160,7 +160,7 @@ protected:
/// Creates the used Action /// Creates the used Action
virtual Action * createAction(void); virtual Action * createAction(void);
/// Applies the menu text, tool and status tip to the passed action object /// 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; const char* keySequenceToAccel(int) const;
void adjustCameraPosition(); void adjustCameraPosition();
//@} //@}

View File

@ -724,10 +724,10 @@ Action * StdCmdUndo::createAction(void)
Action *pcAction; Action *pcAction;
pcAction = new UndoAction(this,getMainWindow()); pcAction = new UndoAction(this,getMainWindow());
applyCommandData(pcAction); pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap) if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction; return pcAction;
} }
@ -767,10 +767,10 @@ Action * StdCmdRedo::createAction(void)
Action *pcAction; Action *pcAction;
pcAction = new RedoAction(this,getMainWindow()); pcAction = new RedoAction(this,getMainWindow());
applyCommandData(pcAction); pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap) if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction; return pcAction;
} }

View File

@ -125,10 +125,10 @@ Action * StdCmdWorkbench::createAction(void)
Action *pcAction; Action *pcAction;
pcAction = new WorkbenchGroup(this,getMainWindow()); pcAction = new WorkbenchGroup(this,getMainWindow());
applyCommandData(pcAction); pcAction->setShortcut(QString::fromAscii(sAccel));
applyCommandData(this->className(), pcAction);
if (sPixmap) if (sPixmap)
pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap)); pcAction->setIcon(Gui::BitmapFactory().pixmap(sPixmap));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction; return pcAction;
} }
@ -169,7 +169,7 @@ Action * StdCmdRecentFiles::createAction(void)
RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow()); RecentFilesAction* pcAction = new RecentFilesAction(this, getMainWindow());
pcAction->setObjectName(QLatin1String("recentFiles")); pcAction->setObjectName(QLatin1String("recentFiles"));
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
return pcAction; return pcAction;
} }

View File

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

View File

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

View File

@ -28,6 +28,7 @@
# include <QFileInfo> # include <QFileInfo>
# include <QHeaderView> # include <QHeaderView>
# include <QImageReader> # include <QImageReader>
# include <QKeySequence>
# include <QMessageBox> # include <QMessageBox>
# include <QTextStream> # include <QTextStream>
#endif #endif
@ -329,9 +330,22 @@ void DlgCustomActionsImp::on_buttonReplaceAction_clicked()
action->setToolTip(QString::fromUtf8(macro->getToolTipText())); action->setToolTip(QString::fromUtf8(macro->getToolTipText()));
action->setWhatsThis(QString::fromUtf8(macro->getWhatsThis())); action->setWhatsThis(QString::fromUtf8(macro->getWhatsThis()));
action->setStatusTip(QString::fromUtf8(macro->getStatusTip())); action->setStatusTip(QString::fromUtf8(macro->getStatusTip()));
if( macro->getPixmap() ) if (macro->getPixmap())
action->setIcon(Gui::BitmapFactory().pixmap(macro->getPixmap())); action->setIcon(Gui::BitmapFactory().pixmap(macro->getPixmap()));
action->setShortcut(QString::fromAscii(macro->getAccel())); 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 // emit signal to notify the container widget

View File

@ -198,11 +198,43 @@ void DlgCustomKeyboardImp::on_buttonAssign_clicked()
CommandManager & cCmdMgr = Application::Instance->commandManager(); CommandManager & cCmdMgr = Application::Instance->commandManager();
Command* cmd = cCmdMgr.getCommandByName(name.constData()); Command* cmd = cCmdMgr.getCommandByName(name.constData());
if (cmd && cmd->getAction()) { if (cmd && cmd->getAction()) {
Action* action = cmd->getAction();
QKeySequence shortcut = editShortcut->text(); QKeySequence shortcut = editShortcut->text();
cmd->getAction()->setShortcut(shortcut); action->setShortcut(shortcut);
accelLineEditShortcut->setText(editShortcut->text()); accelLineEditShortcut->setText(editShortcut->text());
editShortcut->clear(); editShortcut->clear();
// update the tool tip
QString accel = shortcut.toString(QKeySequence::NativeText);
QString toolTip = QCoreApplication::translate(cmd->className(),
cmd->getToolTipText(), 0, QCoreApplication::UnicodeUTF8);
if (!accel.isEmpty()) {
if (!toolTip.isEmpty()) {
QString tip = QString::fromLatin1("%1 (%2)")
.arg(toolTip).arg(accel);
action->setToolTip(tip);
}
}
else {
action->setToolTip(toolTip);
}
// update the status tip
QString statusTip = QCoreApplication::translate(cmd->className(),
cmd->getStatusTip(), 0, QCoreApplication::UnicodeUTF8);
if (statusTip.isEmpty())
statusTip = toolTip;
if (!accel.isEmpty()) {
if (!statusTip.isEmpty()) {
QString tip = QString::fromLatin1("(%1)\t%2")
.arg(accel).arg(statusTip);
action->setStatusTip(tip);
}
}
else {
action->setStatusTip(statusTip);
}
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut"); ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Shortcut");
hGrp->SetASCII(name.constData(), accelLineEditShortcut->text().toUtf8()); hGrp->SetASCII(name.constData(), accelLineEditShortcut->text().toUtf8());
buttonAssign->setEnabled(false); buttonAssign->setEnabled(false);

View File

@ -118,7 +118,7 @@ Gui::Action * CmdDrawingNewPage::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* defaultAction = 0; QAction* defaultAction = 0;
int defaultId = 0; int defaultId = 0;

View File

@ -355,7 +355,7 @@ Gui::Action * CmdRaytracingNewPovrayProject::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* defaultAction = 0; QAction* defaultAction = 0;
int defaultId = 0; int defaultId = 0;
@ -744,7 +744,7 @@ Gui::Action * CmdRaytracingNewLuxProject::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* defaultAction = 0; QAction* defaultAction = 0;
int defaultId = 0; int defaultId = 0;

View File

@ -1560,7 +1560,7 @@ Gui::Action * CmdSketcherCompCreateArc::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* arc1 = pcAction->addAction(QString()); QAction* arc1 = pcAction->addAction(QString());
arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateArc", QSize(24,24))); arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateArc", QSize(24,24)));
@ -2036,7 +2036,7 @@ Gui::Action * CmdSketcherCompCreateCircle::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* arc1 = pcAction->addAction(QString()); QAction* arc1 = pcAction->addAction(QString());
arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateCircle", QSize(24,24))); arc1->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateCircle", QSize(24,24)));
@ -3466,7 +3466,7 @@ Gui::Action * CmdSketcherCompCreateRegularPolygon::createAction(void)
{ {
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true); pcAction->setDropDownMenu(true);
applyCommandData(pcAction); applyCommandData(this->className(), pcAction);
QAction* triangle = pcAction->addAction(QString()); QAction* triangle = pcAction->addAction(QString());
triangle->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateTriangle", QSize(24,24))); triangle->setIcon(Gui::BitmapFactory().pixmapFromSvg("Sketcher_CreateTriangle", QSize(24,24)));