Manual shortcut test: Arrange in QGridLayout
Change-Id: I93264bec8810f4dd1e2c010cc4dd35df93f31102 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
parent
30874fb2df
commit
370cd37cea
@ -28,6 +28,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
@ -36,200 +37,123 @@
|
||||
class ShortcutTester : public QWidget
|
||||
{
|
||||
public:
|
||||
ShortcutTester() {
|
||||
ShortcutTester()
|
||||
{
|
||||
const QString title = QLatin1String(QT_VERSION_STR) + QLatin1Char(' ')
|
||||
+ qApp->platformName();
|
||||
setWindowTitle(title);
|
||||
setupLayout();
|
||||
}
|
||||
protected:
|
||||
void setupLayout()
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
QLabel *testPurpose = new QLabel();
|
||||
testPurpose->setWordWrap(true);
|
||||
testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
|
||||
testPurpose->setText("This test come in handy to verify shortcuts under different "
|
||||
"keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc.");
|
||||
layout->addWidget(testPurpose);
|
||||
private:
|
||||
void setupLayout();
|
||||
void addToGrid(QWidget *w, int &row, int col);
|
||||
void addShortcutToGrid(const QKeySequence &k, int &row, int col);
|
||||
void addShortcutToGrid(int key, int &row, int col)
|
||||
{ addShortcutToGrid(QKeySequence(key), row, col); }
|
||||
|
||||
QKeySequence altShiftG(Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G);
|
||||
QPushButton *_altShiftG = new QPushButton(altShiftG.toString());
|
||||
_altShiftG->setShortcut(altShiftG);
|
||||
layout->addWidget(_altShiftG);
|
||||
|
||||
QKeySequence altG(Qt::AltModifier + Qt::Key_G);
|
||||
QPushButton *_altG = new QPushButton(altG.toString());
|
||||
_altG->setShortcut(altG);
|
||||
layout->addWidget(_altG);
|
||||
|
||||
QKeySequence ctrlShiftR(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R);
|
||||
QPushButton *_ctrlShiftR = new QPushButton(ctrlShiftR.toString());
|
||||
_ctrlShiftR->setShortcut(ctrlShiftR);
|
||||
layout->addWidget(_ctrlShiftR);
|
||||
|
||||
QKeySequence ctrlR(Qt::ControlModifier + Qt::Key_R);
|
||||
QPushButton *_ctrlR = new QPushButton(ctrlR.toString());
|
||||
_ctrlR->setShortcut(ctrlR);
|
||||
layout->addWidget(_ctrlR);
|
||||
|
||||
QKeySequence ctrlReturn(Qt::ControlModifier + Qt::Key_Return);
|
||||
QPushButton *_ctrlReturn = new QPushButton(ctrlReturn.toString());
|
||||
_ctrlReturn->setShortcut(ctrlReturn);
|
||||
layout->addWidget(_ctrlReturn);
|
||||
|
||||
QKeySequence ctrlEnter(Qt::ControlModifier + Qt::Key_Enter);
|
||||
QPushButton *_ctrlEnter = new QPushButton(ctrlEnter.toString());
|
||||
_ctrlEnter->setShortcut(ctrlEnter);
|
||||
layout->addWidget(_ctrlEnter);
|
||||
|
||||
QKeySequence ctrlShiftAltR(Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R);
|
||||
QPushButton *_ctrlShiftAltR = new QPushButton(ctrlShiftAltR.toString());
|
||||
_ctrlShiftAltR->setShortcut(ctrlShiftAltR);
|
||||
layout->addWidget(_ctrlShiftAltR);
|
||||
|
||||
QKeySequence shift5(Qt::ShiftModifier + Qt::Key_5);
|
||||
QPushButton *_shift5 = new QPushButton(shift5.toString());
|
||||
_shift5->setShortcut(shift5);
|
||||
layout->addWidget(_shift5);
|
||||
|
||||
QKeySequence shiftPercent(Qt::ShiftModifier + Qt::Key_Percent);
|
||||
QPushButton *_shiftPercent = new QPushButton(shiftPercent.toString());
|
||||
_shiftPercent->setShortcut(shiftPercent);
|
||||
layout->addWidget(_shiftPercent);
|
||||
|
||||
QKeySequence percent(Qt::Key_Percent);
|
||||
QPushButton *_percent = new QPushButton(percent.toString());
|
||||
_percent->setShortcut(percent);
|
||||
layout->addWidget(_percent);
|
||||
|
||||
QKeySequence key5(Qt::Key_5);
|
||||
QPushButton *_key5 = new QPushButton(key5.toString());
|
||||
_key5->setShortcut(key5);
|
||||
layout->addWidget(_key5);
|
||||
|
||||
QKeySequence keyQ(Qt::Key_Q);
|
||||
QPushButton *_keyQ = new QPushButton(keyQ.toString());
|
||||
_keyQ->setShortcut(keyQ);
|
||||
layout->addWidget(_keyQ);
|
||||
|
||||
QKeySequence ctrlPercent(Qt::ControlModifier + Qt::Key_Percent);
|
||||
QPushButton *_ctrlPercent = new QPushButton(ctrlPercent.toString());
|
||||
_ctrlPercent->setShortcut(ctrlPercent);
|
||||
layout->addWidget(_ctrlPercent);
|
||||
|
||||
QKeySequence ctrlShift5(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5);
|
||||
QPushButton *_ctrlShift5 = new QPushButton(ctrlShift5.toString());
|
||||
_ctrlShift5->setShortcut(ctrlShift5);
|
||||
layout->addWidget(_ctrlShift5);
|
||||
|
||||
QKeySequence ctrl5(Qt::ControlModifier + Qt::Key_5);
|
||||
QPushButton *_ctrl5 = new QPushButton(ctrl5.toString());
|
||||
_ctrl5->setShortcut(ctrl5);
|
||||
layout->addWidget(_ctrl5);
|
||||
|
||||
QKeySequence alt5(Qt::AltModifier + Qt::Key_5);
|
||||
QPushButton *_alt5 = new QPushButton(alt5.toString());
|
||||
_alt5->setShortcut(alt5);
|
||||
layout->addWidget(_alt5);
|
||||
|
||||
QKeySequence ctrlPlus(Qt::ControlModifier + Qt::Key_Plus);
|
||||
QPushButton *_ctrlPlus = new QPushButton(ctrlPlus.toString());
|
||||
_ctrlPlus->setShortcut(ctrlPlus);
|
||||
layout->addWidget(_ctrlPlus);
|
||||
|
||||
QKeySequence ctrlShiftPlus(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus);
|
||||
QPushButton *_ctrlShiftPlus = new QPushButton(ctrlShiftPlus.toString());
|
||||
_ctrlShiftPlus->setShortcut(ctrlShiftPlus);
|
||||
layout->addWidget(_ctrlShiftPlus);
|
||||
|
||||
QKeySequence ctrlY(Qt::ControlModifier + Qt::Key_Y);
|
||||
QPushButton *_ctrlY = new QPushButton(ctrlY.toString());
|
||||
_ctrlY->setShortcut(ctrlY);
|
||||
layout->addWidget(_ctrlY);
|
||||
|
||||
QKeySequence shiftComma(Qt::ShiftModifier + Qt::Key_Comma);
|
||||
QPushButton *_shiftComma = new QPushButton(shiftComma.toString());
|
||||
_shiftComma->setShortcut(shiftComma);
|
||||
layout->addWidget(_shiftComma);
|
||||
|
||||
QKeySequence ctrlComma(Qt::ControlModifier + Qt::Key_Comma);
|
||||
QPushButton *_ctrlComma = new QPushButton(ctrlComma.toString());
|
||||
_ctrlComma->setShortcut(ctrlComma);
|
||||
layout->addWidget(_ctrlComma);
|
||||
|
||||
QKeySequence ctrlSlash(Qt::ControlModifier + Qt::Key_Slash);
|
||||
QPushButton *_ctrlSlash = new QPushButton(ctrlSlash.toString());
|
||||
_ctrlSlash->setShortcut(ctrlSlash);
|
||||
layout->addWidget(_ctrlSlash);
|
||||
|
||||
QKeySequence ctrlBackslash(Qt::ControlModifier + Qt::Key_Backslash);
|
||||
QPushButton *_ctrlBackslash = new QPushButton(ctrlBackslash.toString());
|
||||
_ctrlBackslash->setShortcut(ctrlBackslash);
|
||||
layout->addWidget(_ctrlBackslash);
|
||||
|
||||
QKeySequence metaShiftA(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A);
|
||||
QPushButton *_metaShiftA = new QPushButton(metaShiftA.toString());
|
||||
_metaShiftA->setShortcut(metaShiftA);
|
||||
layout->addWidget(_metaShiftA);
|
||||
|
||||
QKeySequence metaShift5(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5);
|
||||
QPushButton *_metaShift5 = new QPushButton(metaShift5.toString());
|
||||
_metaShift5->setShortcut(metaShift5);
|
||||
layout->addWidget(_metaShift5);
|
||||
|
||||
QKeySequence ctrlBracketRigth(Qt::ControlModifier + Qt::Key_BracketRight);
|
||||
QPushButton *_ctrlBracketRigth = new QPushButton(ctrlBracketRigth.toString());
|
||||
_ctrlBracketRigth->setShortcut(ctrlBracketRigth);
|
||||
layout->addWidget(_ctrlBracketRigth);
|
||||
|
||||
QKeySequence shiftF3(Qt::ShiftModifier + Qt::Key_F3);
|
||||
QPushButton *_shiftF3 = new QPushButton(shiftF3.toString());
|
||||
_shiftF3->setShortcut(shiftF3);
|
||||
layout->addWidget(_shiftF3);
|
||||
|
||||
QKeySequence ctrlF3(Qt::ControlModifier + Qt::Key_F3);
|
||||
QPushButton *_ctrlF3 = new QPushButton(ctrlF3.toString());
|
||||
_ctrlF3->setShortcut(ctrlF3);
|
||||
layout->addWidget(_ctrlF3);
|
||||
|
||||
QKeySequence euro(0x20AC); // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level
|
||||
QPushButton *_euro = new QPushButton(euro.toString());
|
||||
_euro->setShortcut(euro);
|
||||
layout->addWidget(_euro);
|
||||
|
||||
QKeySequence ctrlEuro(Qt::ControlModifier + 0x20AC);
|
||||
QPushButton *_ctrlEuro = new QPushButton(ctrlEuro.toString());
|
||||
_ctrlEuro->setShortcut(ctrlEuro);
|
||||
layout->addWidget(_ctrlEuro);
|
||||
|
||||
// with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I
|
||||
QKeySequence greekPsi(QString(QStringLiteral("\u03A8")));
|
||||
QPushButton *_greekPsi = new QPushButton(greekPsi.toString());
|
||||
_greekPsi->setShortcut(greekPsi);
|
||||
layout->addWidget(_greekPsi);
|
||||
|
||||
layout->addWidget(new QLabel("Norwegian layout"));
|
||||
// LATIN SMALL LETTER O WITH STROKE
|
||||
QKeySequence norwegianO(QString(QStringLiteral("\u00F8")));
|
||||
QPushButton *_norwegianO = new QPushButton(norwegianO.toString());
|
||||
_norwegianO->setShortcut(norwegianO);
|
||||
layout->addWidget(_norwegianO);
|
||||
|
||||
layout->addWidget(new QLabel("Russian layout"));
|
||||
// CYRILLIC SMALL LETTER ZHE
|
||||
QKeySequence zhe(QString(QStringLiteral("\u0436")));
|
||||
QPushButton *_zhe = new QPushButton(zhe.toString());
|
||||
_zhe->setShortcut(zhe);
|
||||
layout->addWidget(_zhe);
|
||||
|
||||
// for sequence definitons see qplatformtheme.cpp
|
||||
layout->addWidget(new QLabel("QKeySequence::StandardKey(s)"));
|
||||
QPushButton *_open = new QPushButton("Open");
|
||||
_open->setShortcut(QKeySequence::Open); // Qt::CTRL | Qt::Key_O
|
||||
layout->addWidget(_open);
|
||||
}
|
||||
QGridLayout *m_gridLayout = new QGridLayout;
|
||||
};
|
||||
|
||||
inline void ShortcutTester::addToGrid(QWidget *w, int &row, int col)
|
||||
{
|
||||
m_gridLayout->addWidget(w, row++, col);
|
||||
}
|
||||
|
||||
void ShortcutTester::addShortcutToGrid(const QKeySequence &k, int &row, int col)
|
||||
{
|
||||
QPushButton *button = new QPushButton(k.toString());
|
||||
button->setShortcut(k);
|
||||
addToGrid(button, row, col);
|
||||
}
|
||||
|
||||
void addShortcutToGrid(int key, int &row, int col);
|
||||
|
||||
void ShortcutTester::setupLayout()
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
QLabel *testPurpose = new QLabel();
|
||||
testPurpose->setWordWrap(true);
|
||||
testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
|
||||
testPurpose->setText("This test come in handy to verify shortcuts under different "
|
||||
"keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc.");
|
||||
layout->addWidget(testPurpose);
|
||||
|
||||
layout->addLayout(m_gridLayout);
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
const int keys1[] = {
|
||||
Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G,
|
||||
Qt::AltModifier + Qt::Key_G,
|
||||
Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R,
|
||||
Qt::ControlModifier + Qt::Key_R,
|
||||
Qt::ControlModifier + Qt::Key_Return, Qt::ControlModifier + Qt::Key_Enter,
|
||||
Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R,
|
||||
Qt::ShiftModifier + Qt::Key_5, Qt::ShiftModifier + Qt::Key_Percent,
|
||||
Qt::Key_Percent, Qt::Key_5, Qt::Key_Q
|
||||
};
|
||||
|
||||
for (int k : keys1)
|
||||
addShortcutToGrid(k, row, col);
|
||||
|
||||
row = 0;
|
||||
col++;
|
||||
|
||||
const int keys2[] = {
|
||||
Qt::ControlModifier + Qt::Key_Percent,
|
||||
Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5,
|
||||
Qt::ControlModifier + Qt::Key_5, Qt::AltModifier + Qt::Key_5,
|
||||
Qt::ControlModifier + Qt::Key_Plus,
|
||||
Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus,
|
||||
Qt::ControlModifier + Qt::Key_Y, Qt::ShiftModifier + Qt::Key_Comma,
|
||||
Qt::ControlModifier + Qt::Key_Comma, Qt::ControlModifier + Qt::Key_Slash,
|
||||
Qt::ControlModifier + Qt::Key_Backslash
|
||||
};
|
||||
|
||||
for (int k : keys2)
|
||||
addShortcutToGrid(k, row, col);
|
||||
|
||||
row = 0;
|
||||
col++;
|
||||
|
||||
const int keys3[] = {
|
||||
Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A,
|
||||
Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5,
|
||||
Qt::ControlModifier + Qt::Key_BracketRight,
|
||||
Qt::ShiftModifier + Qt::Key_F3,
|
||||
Qt::ControlModifier + Qt::Key_F3,
|
||||
0x20AC, // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level
|
||||
Qt::ControlModifier + 0x20AC
|
||||
};
|
||||
|
||||
for (int k : keys3)
|
||||
addShortcutToGrid(k, row, col);
|
||||
|
||||
// with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I
|
||||
const QKeySequence greekPsi(QString(QStringLiteral("\u03A8")));
|
||||
addShortcutToGrid(greekPsi, row, col);
|
||||
|
||||
row = 0;
|
||||
col++;
|
||||
|
||||
addToGrid(new QLabel("Norwegian layout"), row, col);
|
||||
// LATIN SMALL LETTER O WITH STROKE
|
||||
QKeySequence norwegianO(QString(QStringLiteral("\u00F8")));
|
||||
addShortcutToGrid(norwegianO, row, col);
|
||||
|
||||
addToGrid(new QLabel("Russian layout"), row, col);
|
||||
// CYRILLIC SMALL LETTER ZHE
|
||||
QKeySequence zhe(QString(QStringLiteral("\u0436")));
|
||||
addShortcutToGrid(zhe, row, col);
|
||||
|
||||
// for sequence definitons see qplatformtheme.cpp
|
||||
addToGrid(new QLabel("QKeySequence::StandardKey(s)"), row, col);
|
||||
addShortcutToGrid(QKeySequence(QKeySequence::Open), row, col); // Qt::CTRL | Qt::Key_O
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user