1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QMainWindow>
#include <QApplication>
#include <QColorDialog>
#include <QFileDialog>
#include <QFontDialog>
#include <QInputDialog>
#include <QMessageBox>
#include "ui_keypadnavigation.h"
class KeypadNavigation : public QMainWindow
{
Q_OBJECT
public:
KeypadNavigation(QWidget *parent = nullptr)
: QMainWindow(parent)
, ui(new Ui_KeypadNavigation)
{
ui->setupUi(this);
const struct {
QAction *action;
QWidget *page;
} layoutMappings[] = {
{ui->m_actionLayoutVerticalSimple, ui->m_pageVerticalSimple},
{ui->m_actionLayoutVerticalComplex, ui->m_pageVerticalComplex},
{ui->m_actionLayoutTwoDimensional, ui->m_pageTwoDimensional},
{ui->m_actionLayoutSliderMagic, ui->m_pageSliderMagic},
{ui->m_actionLayoutChaos, ui->m_pageChaos},
{ui->m_actionLayoutDialogs, ui->m_pageDialogs}
};
for (auto layoutMapping : layoutMappings) {
const auto page = layoutMapping.page;
connect(layoutMapping.action, &QAction::triggered, ui->m_stackWidget,
[this, page]()
{ ui->m_stackWidget->setCurrentWidget(page); });
}
#ifdef QT_KEYPAD_NAVIGATION
const struct {
QAction *action;
Qt::NavigationMode mode;
} modeMappings[] = {
{ui->m_actionModeNone, Qt::NavigationModeNone},
{ui->m_actionModeKeypadTabOrder, Qt::NavigationModeKeypadTabOrder},
{ui->m_actionModeKeypadDirectional, Qt::NavigationModeKeypadDirectional},
{ui->m_actionModeCursorAuto, Qt::NavigationModeCursorAuto},
{ui->m_actionModeCursorForceVisible, Qt::NavigationModeCursorForceVisible}
};
for (auto modeMapping : modeMappings) {
const auto mode = modeMapping.mode;
connect(modeMapping.action, &QAction::triggered, this,
[this, mode]() { setNavigationMode(mode); });
}
#else // QT_KEYPAD_NAVIGATION
ui->m_menuNavigation_mode->deleteLater();
#endif // QT_KEYPAD_NAVIGATION
const struct {
QPushButton *button;
Dialog dialog;
} openDialogMappings[] = {
{ui->m_buttonGetOpenFileName, DialogGetOpenFileName},
{ui->m_buttonGetSaveFileName, DialogGetSaveFileName},
{ui->m_buttonGetExistingDirectory, DialogGetExistingDirectory},
{ui->m_buttonGetColor, DialogGetColor},
{ui->m_buttonGetFont, DialogGetFont},
{ui->m_buttonQuestion, DialogQuestion},
{ui->m_buttonAboutQt, DialogAboutQt},
{ui->m_buttonGetItem, DialogGetItem}
};
for (auto openDialogMapping : openDialogMappings) {
const auto dialog = openDialogMapping.dialog;
connect(openDialogMapping.button, &QPushButton::clicked, this,
[this, dialog]() { openDialog(dialog); });
}
}
~KeypadNavigation()
{
delete ui;
}
protected slots:
#ifdef QT_KEYPAD_NAVIGATION
void setNavigationMode(int mode)
{
QApplication::setNavigationMode(Qt::NavigationMode(mode));
}
#endif // QT_KEYPAD_NAVIGATION
void openDialog(int dialog)
{
switch (Dialog(dialog)) {
case DialogGetOpenFileName:
QFileDialog::getOpenFileName(this, QLatin1String("getOpenFileName"));
break;
case DialogGetSaveFileName:
QFileDialog::getSaveFileName(this, QLatin1String("getSaveFileName"));
break;
case DialogGetExistingDirectory:
QFileDialog::getExistingDirectory(this, QLatin1String("getExistingDirectory"));
break;
case DialogGetColor:
QColorDialog::getColor(QColor(Qt::green), this, QLatin1String("getColor"));
break;
case DialogGetFont:
QFontDialog::getFont(0, this);
break;
case DialogQuestion:
QMessageBox::question(this, QLatin1String("question"), QLatin1String("\xbfHola, que tal?"));
break;
case DialogAboutQt:
QMessageBox::aboutQt(this);
break;
case DialogGetItem:
QInputDialog::getItem(this, QLatin1String("getItem"), QLatin1String("Choose a color"), QColor::colorNames());
break;
default:
break;
}
}
private:
enum Dialog {
DialogGetOpenFileName,
DialogGetSaveFileName,
DialogGetExistingDirectory,
DialogGetColor,
DialogGetFont,
DialogQuestion,
DialogAboutQt,
DialogGetItem
};
Ui_KeypadNavigation *ui;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
KeypadNavigation w;
w.show();
return a.exec();
}
#include "main.moc"
|