Move MaxKeyCount from QKeySequenceEditPrivate to QKeySequencePrivate
Adjust users and add a static_cast that MaxKeyCount be 4. That is instead of adjusting all the code to use MaxKeyCount instead, some of which cannot be thus changed (e.g. where using the QKeySequence(int, int, int, int) constructor). This was requested in the original review, but never implemented. Change-Id: I3812340890f4d75257139f04e73e83083ca09760 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>bb10
parent
ee53530a0e
commit
6b745d6c63
|
|
@ -69,6 +69,7 @@ struct Q_AUTOTEST_EXPORT QKeyBinding
|
|||
class Q_AUTOTEST_EXPORT QKeySequencePrivate
|
||||
{
|
||||
public:
|
||||
enum { MaxKeyCount = 4 }; // used in QKeySequenceEdit
|
||||
inline QKeySequencePrivate() : ref(1)
|
||||
{
|
||||
key[0] = key[1] = key[2] = key[3] = 0;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
#ifndef QT_NO_KEYSEQUENCEEDIT
|
||||
|
||||
Q_STATIC_ASSERT(QKeySequencePrivate::MaxKeyCount == 4); // assumed by the code around here
|
||||
|
||||
void QKeySequenceEditPrivate::init()
|
||||
{
|
||||
Q_Q(QKeySequenceEdit);
|
||||
|
|
@ -280,7 +282,7 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
|
|||
return;
|
||||
}
|
||||
|
||||
if (d->keyNum >= QKeySequenceEditPrivate::MaxKeyCount)
|
||||
if (d->keyNum >= QKeySequencePrivate::MaxKeyCount)
|
||||
return;
|
||||
|
||||
nextKey |= d->translateModifiers(e->modifiers(), e->text());
|
||||
|
|
@ -291,7 +293,7 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
|
|||
QKeySequence key(d->key[0], d->key[1], d->key[2], d->key[3]);
|
||||
d->keySequence = key;
|
||||
QString text = key.toString(QKeySequence::NativeText);
|
||||
if (d->keyNum < QKeySequenceEditPrivate::MaxKeyCount) {
|
||||
if (d->keyNum < QKeySequencePrivate::MaxKeyCount) {
|
||||
//: This text is an "unfinished" shortcut, expands like "Ctrl+A, ..."
|
||||
text = tr("%1, ...").arg(text);
|
||||
}
|
||||
|
|
@ -307,7 +309,7 @@ void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)
|
|||
Q_D(QKeySequenceEdit);
|
||||
|
||||
if (d->prevKey == e->key()) {
|
||||
if (d->keyNum < QKeySequenceEditPrivate::MaxKeyCount)
|
||||
if (d->keyNum < QKeySequencePrivate::MaxKeyCount)
|
||||
d->releaseTimer = startTimer(1000);
|
||||
else
|
||||
d->finishEditing();
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#include "qkeysequenceedit.h"
|
||||
|
||||
#include <private/qwidget_p.h>
|
||||
#include <private/qkeysequence_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -57,8 +58,6 @@ class QKeySequenceEditPrivate : public QWidgetPrivate
|
|||
{
|
||||
Q_DECLARE_PUBLIC(QKeySequenceEdit)
|
||||
public:
|
||||
enum { MaxKeyCount = 4 };
|
||||
|
||||
void init();
|
||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||
void resetState();
|
||||
|
|
@ -67,7 +66,7 @@ public:
|
|||
QLineEdit *lineEdit;
|
||||
QKeySequence keySequence;
|
||||
int keyNum;
|
||||
int key[MaxKeyCount];
|
||||
int key[QKeySequencePrivate::MaxKeyCount];
|
||||
int prevKey;
|
||||
int releaseTimer;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue