mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
drop support for a list of QKeySequence in QAction
a single QKeySequence actually is two shortcuts Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8f42407b20
commit
1ef52af92e
4 changed files with 5 additions and 129 deletions
|
@ -124,46 +124,11 @@ void QActionPrivate::redoGrab(QShortcutMap &map)
|
||||||
map.setShortcutAutoRepeat(false, shortcutId, q);
|
map.setShortcutAutoRepeat(false, shortcutId, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QActionPrivate::redoGrabAlternate(QShortcutMap &map)
|
|
||||||
{
|
|
||||||
Q_Q(QAction);
|
|
||||||
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
|
|
||||||
if (const int id = alternateShortcutIds.at(i))
|
|
||||||
map.removeShortcut(id, q);
|
|
||||||
}
|
|
||||||
alternateShortcutIds.clear();
|
|
||||||
if (alternateShortcuts.isEmpty())
|
|
||||||
return;
|
|
||||||
for(int i = 0; i < alternateShortcuts.count(); ++i) {
|
|
||||||
const QKeySequence& alternate = alternateShortcuts.at(i);
|
|
||||||
if (!alternate.isEmpty())
|
|
||||||
alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext));
|
|
||||||
else
|
|
||||||
alternateShortcutIds.append(0);
|
|
||||||
}
|
|
||||||
if (!enabled) {
|
|
||||||
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
|
|
||||||
const int id = alternateShortcutIds.at(i);
|
|
||||||
map.setShortcutEnabled(false, id, q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!autorepeat) {
|
|
||||||
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
|
|
||||||
const int id = alternateShortcutIds.at(i);
|
|
||||||
map.setShortcutAutoRepeat(false, id, q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
|
void QActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map)
|
||||||
{
|
{
|
||||||
Q_Q(QAction);
|
Q_Q(QAction);
|
||||||
if (shortcutId)
|
if (shortcutId)
|
||||||
map.setShortcutEnabled(enable, shortcutId, q);
|
map.setShortcutEnabled(enable, shortcutId, q);
|
||||||
for(int i = 0; i < alternateShortcutIds.count(); ++i) {
|
|
||||||
if (const int id = alternateShortcutIds.at(i))
|
|
||||||
map.setShortcutEnabled(enable, id, q);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // QT_NO_SHORTCUT
|
#endif // QT_NO_SHORTCUT
|
||||||
|
|
||||||
|
@ -389,52 +354,6 @@ void QAction::setShortcut(const QKeySequence &shortcut)
|
||||||
d->sendDataChanged();
|
d->sendDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\since 4.2
|
|
||||||
|
|
||||||
Sets \a shortcuts as the list of shortcuts that trigger the
|
|
||||||
action. The first element of the list is the primary shortcut.
|
|
||||||
|
|
||||||
\sa shortcut
|
|
||||||
*/
|
|
||||||
void QAction::setShortcuts(const QList<QKeySequence> &shortcuts)
|
|
||||||
{
|
|
||||||
Q_D(QAction);
|
|
||||||
|
|
||||||
QList <QKeySequence> listCopy = shortcuts;
|
|
||||||
|
|
||||||
QKeySequence primary;
|
|
||||||
if (!listCopy.isEmpty())
|
|
||||||
primary = listCopy.takeFirst();
|
|
||||||
|
|
||||||
if (d->shortcut == primary && d->alternateShortcuts == listCopy)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QAPP_CHECK("setShortcuts");
|
|
||||||
|
|
||||||
d->shortcut = primary;
|
|
||||||
d->alternateShortcuts = listCopy;
|
|
||||||
d->redoGrab(qApp->d_func()->shortcutMap);
|
|
||||||
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
|
|
||||||
d->sendDataChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\since 4.2
|
|
||||||
|
|
||||||
Sets a platform dependent list of shortcuts based on the \a key.
|
|
||||||
The result of calling this function will depend on the currently running platform.
|
|
||||||
Note that more than one shortcut can assigned by this action.
|
|
||||||
If only the primary shortcut is required, use setShortcut instead.
|
|
||||||
|
|
||||||
\sa QKeySequence::keyBindings()
|
|
||||||
*/
|
|
||||||
void QAction::setShortcuts(QKeySequence::StandardKey key)
|
|
||||||
{
|
|
||||||
QList <QKeySequence> list = QKeySequence::keyBindings(key);
|
|
||||||
setShortcuts(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the primary shortcut.
|
Returns the primary shortcut.
|
||||||
|
|
||||||
|
@ -446,25 +365,6 @@ QKeySequence QAction::shortcut() const
|
||||||
return d->shortcut;
|
return d->shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\since 4.2
|
|
||||||
|
|
||||||
Returns the list of shortcuts, with the primary shortcut as
|
|
||||||
the first element of the list.
|
|
||||||
|
|
||||||
\sa setShortcuts()
|
|
||||||
*/
|
|
||||||
QList<QKeySequence> QAction::shortcuts() const
|
|
||||||
{
|
|
||||||
Q_D(const QAction);
|
|
||||||
QList <QKeySequence> shortcuts;
|
|
||||||
if (!d->shortcut.isEmpty())
|
|
||||||
shortcuts << d->shortcut;
|
|
||||||
if (!d->alternateShortcuts.isEmpty())
|
|
||||||
shortcuts << d->alternateShortcuts;
|
|
||||||
return shortcuts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\property QAction::shortcutContext
|
\property QAction::shortcutContext
|
||||||
\brief the context for the action's shortcut
|
\brief the context for the action's shortcut
|
||||||
|
@ -480,7 +380,6 @@ void QAction::setShortcutContext(Qt::ShortcutContext context)
|
||||||
QAPP_CHECK("setShortcutContext");
|
QAPP_CHECK("setShortcutContext");
|
||||||
d->shortcutContext = context;
|
d->shortcutContext = context;
|
||||||
d->redoGrab(qApp->d_func()->shortcutMap);
|
d->redoGrab(qApp->d_func()->shortcutMap);
|
||||||
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
|
|
||||||
d->sendDataChanged();
|
d->sendDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +407,6 @@ void QAction::setAutoRepeat(bool on)
|
||||||
QAPP_CHECK("setAutoRepeat");
|
QAPP_CHECK("setAutoRepeat");
|
||||||
d->autorepeat = on;
|
d->autorepeat = on;
|
||||||
d->redoGrab(qApp->d_func()->shortcutMap);
|
d->redoGrab(qApp->d_func()->shortcutMap);
|
||||||
d->redoGrabAlternate(qApp->d_func()->shortcutMap);
|
|
||||||
d->sendDataChanged();
|
d->sendDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,10 +467,6 @@ QAction::~QAction()
|
||||||
#ifndef QT_NO_SHORTCUT
|
#ifndef QT_NO_SHORTCUT
|
||||||
if (d->shortcutId && qApp) {
|
if (d->shortcutId && qApp) {
|
||||||
qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);
|
qApp->d_func()->shortcutMap.removeShortcut(d->shortcutId, this);
|
||||||
for(int i = 0; i < d->alternateShortcutIds.count(); ++i) {
|
|
||||||
const int id = d->alternateShortcutIds.at(i);
|
|
||||||
qApp->d_func()->shortcutMap.removeShortcut(id, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,10 +112,6 @@ public:
|
||||||
void setShortcut(const QKeySequence &shortcut);
|
void setShortcut(const QKeySequence &shortcut);
|
||||||
QKeySequence shortcut() const;
|
QKeySequence shortcut() const;
|
||||||
|
|
||||||
void setShortcuts(const QList<QKeySequence> &shortcuts);
|
|
||||||
void setShortcuts(QKeySequence::StandardKey);
|
|
||||||
QList<QKeySequence> shortcuts() const;
|
|
||||||
|
|
||||||
void setShortcutContext(Qt::ShortcutContext context);
|
void setShortcutContext(Qt::ShortcutContext context);
|
||||||
Qt::ShortcutContext shortcutContext() const;
|
Qt::ShortcutContext shortcutContext() const;
|
||||||
|
|
||||||
|
|
|
@ -61,14 +61,10 @@ public:
|
||||||
QString tooltip;
|
QString tooltip;
|
||||||
QString statustip;
|
QString statustip;
|
||||||
QString whatsthis;
|
QString whatsthis;
|
||||||
#ifndef QT_NO_SHORTCUT
|
|
||||||
QKeySequence shortcut;
|
|
||||||
QList<QKeySequence> alternateShortcuts;
|
|
||||||
#endif
|
|
||||||
QVariant userData;
|
QVariant userData;
|
||||||
#ifndef QT_NO_SHORTCUT
|
#ifndef QT_NO_SHORTCUT
|
||||||
|
QKeySequence shortcut;
|
||||||
int shortcutId;
|
int shortcutId;
|
||||||
QList<int> alternateShortcutIds;
|
|
||||||
Qt::ShortcutContext shortcutContext;
|
Qt::ShortcutContext shortcutContext;
|
||||||
bool autorepeat;
|
bool autorepeat;
|
||||||
#endif
|
#endif
|
||||||
|
@ -89,7 +85,6 @@ public:
|
||||||
#endif
|
#endif
|
||||||
#ifndef QT_NO_SHORTCUT
|
#ifndef QT_NO_SHORTCUT
|
||||||
void redoGrab(QShortcutMap &map);
|
void redoGrab(QShortcutMap &map);
|
||||||
void redoGrabAlternate(QShortcutMap &map);
|
|
||||||
void setShortcutEnabled(bool enable, QShortcutMap &map);
|
void setShortcutEnabled(bool enable, QShortcutMap &map);
|
||||||
#endif // QT_NO_SHORTCUT
|
#endif // QT_NO_SHORTCUT
|
||||||
|
|
||||||
|
|
|
@ -209,22 +209,14 @@ void tst_QAction::actionEvent()
|
||||||
QCOMPARE(m_lastAction, &a);
|
QCOMPARE(m_lastAction, &a);
|
||||||
}
|
}
|
||||||
|
|
||||||
//basic testing of standard keys
|
// basic testing of standard keys
|
||||||
void tst_QAction::setStandardKeys()
|
void tst_QAction::setStandardKeys()
|
||||||
{
|
{
|
||||||
QAction act(0);
|
QAction act(0);
|
||||||
act.setShortcut(QKeySequence("CTRL+L"));
|
act.setShortcut(QKeySequence("CTRL+C"));
|
||||||
QList<QKeySequence> list;
|
QVERIFY(act.shortcut() == QKeySequence(QKeySequence::Copy));
|
||||||
act.setShortcuts(list);
|
|
||||||
act.setShortcuts(QKeySequence::Copy);
|
|
||||||
QVERIFY(act.shortcut() == act.shortcuts().first());
|
|
||||||
|
|
||||||
QList<QKeySequence> expected;
|
|
||||||
expected << QKeySequence("CTRL+C") << QKeySequence("F16") << QKeySequence("CTRL+INSERT");
|
|
||||||
QVERIFY(act.shortcuts() == expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void tst_QAction::alternateShortcuts()
|
void tst_QAction::alternateShortcuts()
|
||||||
{
|
{
|
||||||
//test the alternate shortcuts (by adding more than 1 shortcut)
|
//test the alternate shortcuts (by adding more than 1 shortcut)
|
||||||
|
@ -234,8 +226,7 @@ void tst_QAction::alternateShortcuts()
|
||||||
{
|
{
|
||||||
QAction act(wid);
|
QAction act(wid);
|
||||||
wid->addAction(&act);
|
wid->addAction(&act);
|
||||||
QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
|
act.setShortcut(QKeySequence("CTRL+A"));
|
||||||
act.setShortcuts(shlist);
|
|
||||||
|
|
||||||
QSignalSpy spy(&act, SIGNAL(triggered()));
|
QSignalSpy spy(&act, SIGNAL(triggered()));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue