This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
optiondialog.cpp
257 lines (218 loc) · 8.72 KB
/
optiondialog.cpp
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "optiondialog.h"
OptionDialog::OptionDialog(QWidget *parent) : QDialog(parent) {
setModal(true);
}
OptionDialog::~OptionDialog() {
delete tabWidget;
}
void OptionDialog::init() {
tabWidget = new QTabWidget;
generalTab = new QWidget;
displayTab = new QWidget;
dictTab = new QWidget;
//shortcutTab = new QWidget;
//voiceTab = new QWidget;
tabWidget->addTab(generalTab, tr("General"));
tabWidget->addTab(displayTab, tr("Display"));
tabWidget->addTab(dictTab, tr("Dictionaries"));
//tabWidget->addTab(shortcutTab, tr("Shortcut"));
//tabWidget->addTab(voiceTab, tr("Voice"));
createGeneralTab();
createDisplayTab();
createDictTab();
//createShortcutTab();
//createVoiceTab();
//Option dialog
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
QIcon icon(QPixmap(":xd.png"));
setWindowIcon(icon);
setWindowTitle(tr("Options"));
setFixedSize(400, 350);
}
void OptionDialog::createGeneralTab() {
QGroupBox *generalGroupBox = new QGroupBox(tr("General Settings"));
autoRunBox = new QCheckBox(tr("Auto run XD after boot"));
hideStartupBox = new QCheckBox(tr("Hide the XD window when starting XD"));
hideCloseBox = new QCheckBox(tr("Hide the XD window when close the XD window"));
showTopBox = new QCheckBox(tr("Show the XD window on top of other applications"));
QGridLayout *layout = new QGridLayout;
layout->addWidget(autoRunBox, 0, 0);
layout->addWidget(hideStartupBox, 1, 0);
layout->addWidget(hideCloseBox, 2, 0);
layout->addWidget(showTopBox, 3, 0);
generalGroupBox->setLayout(layout);
QGroupBox *historyGroupBox = new QGroupBox(tr("History Settings"));
QLabel *historyLabel = new QLabel(tr("Term History maximum:"));
wordHistoryMaxBox = new QSpinBox;
wordHistoryMaxBox->setRange(0, 999);
wordHistoryMaxBox->setSingleStep(1);
wordHistoryMaxBox->setValue(20);
QPushButton *clearButton = new QPushButton(tr("Clear History"));
connect(clearButton, SIGNAL(clicked()), parentWidget(), SLOT(clearHistory()));
QHBoxLayout *historyHLayout = new QHBoxLayout;
historyHLayout->addWidget(historyLabel);
historyHLayout->addStretch(1);
historyHLayout->addWidget(wordHistoryMaxBox);
historyHLayout->addWidget(clearButton);
historyGroupBox->setLayout(historyHLayout);
QGroupBox *indexGroupBox = new QGroupBox(tr("Index Settings"));
QLabel *indexLabel = new QLabel(tr("Index maximum:"));
indexMaxBox = new QSpinBox;
indexMaxBox->setRange(0, 999);
indexMaxBox->setSingleStep(1);
indexMaxBox->setValue(20);
QHBoxLayout *indexLayout = new QHBoxLayout;
indexLayout->addWidget(indexLabel);
indexLayout->addStretch(1);
indexLayout->addWidget(indexMaxBox);
indexGroupBox->setLayout(indexLayout);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(generalGroupBox);
mainLayout->addWidget(historyGroupBox);
mainLayout->addWidget(indexGroupBox);
generalTab->setLayout(mainLayout);
}
void OptionDialog::createDisplayTab() {
QGroupBox *mainGroupBox = new QGroupBox(tr("Window Display"));
QLabel *mainFontLabel = new QLabel(tr("Window Text Font:"));
QLabel *mainFontSizeLabel = new QLabel(tr("Window Font Size:"));
QLabel *mainLangLabel = new QLabel(tr("UI Language:"));
mainFontBox = createFontComboBox();
mainFontSizeBox = createFontSizeComboBox();
mainLangBox = new QComboBox;
mainLangBox->addItem(tr("English"));
mainLangBox->addItem(tr("Chinese"));
//mainLangBox->addItem(tr("Japanese"));
//mainLangBox->addItem(tr("Korean"));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(mainFontLabel, 0, 0);
mainLayout->addWidget(mainFontBox, 0, 1);
mainLayout->addWidget(mainFontSizeLabel, 1, 0);
mainLayout->addWidget(mainFontSizeBox, 1, 1);
mainLayout->addWidget(mainLangLabel, 2, 0);
mainLayout->addWidget(mainLangBox, 2, 1);
mainGroupBox->setLayout(mainLayout);
QGroupBox *resultGroupBox = new QGroupBox(tr("Result Display"));
QLabel *resultFontLabel = new QLabel(tr("Result Text Font:"));
QLabel *resultFontSizeLabel = new QLabel(tr("Result Font Size:"));
QLabel *phonFontLabel = new QLabel(tr("Phonetic Font:"));
resultFontBox = createFontComboBox();
resultFontSizeBox = createFontSizeComboBox();
phonFontBox = createFontComboBox();
QGridLayout *resultLayout = new QGridLayout;
resultLayout->addWidget(resultFontLabel, 0, 0);
resultLayout->addWidget(resultFontBox, 0, 1);
resultLayout->addWidget(resultFontSizeLabel, 1, 0);
resultLayout->addWidget(resultFontSizeBox, 1, 1);
resultLayout->addWidget(phonFontLabel, 2, 0);
resultLayout->addWidget(phonFontBox, 2, 1);
resultGroupBox->setLayout(resultLayout);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mainGroupBox);
layout->addWidget(resultGroupBox);
layout->addStretch(1);
displayTab->setLayout(layout);
}
void OptionDialog::createDictTab() {
QStringList headers;
headers << tr("Installed Dictionaries");
dictListWidget = new QTreeWidget();
dictListWidget->setHeaderLabels(headers);
dictListWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
dictListWidget->setAlternatingRowColors(true);
dictListWidget->setRootIsDecorated(false);
setDictNames(dictNameList);
QPushButton *moveTopButton = new QPushButton(tr("Move to Top"));
QPushButton *moveUpButton = new QPushButton(tr("Move Up"));
QPushButton *moveDownButton = new QPushButton(tr("Move Down"));
QPushButton *moveBottomButton = new QPushButton(tr("Move to Bottom"));
connect(moveTopButton, SIGNAL(clicked()), this, SLOT(moveToTop()));
connect(moveUpButton, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(moveDownButton, SIGNAL(clicked()), this, SLOT(moveDown()));
connect(moveBottomButton, SIGNAL(clicked()), this, SLOT(moveToBottom()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(moveTopButton);
buttonLayout->addWidget(moveUpButton);
buttonLayout->addWidget(moveDownButton);
buttonLayout->addWidget(moveBottomButton);
QVBoxLayout *dictListLayout = new QVBoxLayout;
dictListLayout->addWidget(dictListWidget);
dictListLayout->addLayout(buttonLayout);
dictTab->setLayout(dictListLayout);
}
void OptionDialog::createShortcutTab() {
}
void OptionDialog::createVoiceTab() {
}
QComboBox *OptionDialog::createFontComboBox() {
QFontDatabase database;
QComboBox *fontBox = new QComboBox;
fontBox->addItems(database.families());
return fontBox;
}
QComboBox *OptionDialog::createFontSizeComboBox() {
QComboBox *fontSizeBox = new QComboBox;
fontSizeBox->addItem(tr("8"));
fontSizeBox->addItem(tr("9"));
fontSizeBox->addItem(tr("10"));
fontSizeBox->addItem(tr("11"));
fontSizeBox->addItem(tr("12"));
fontSizeBox->addItem(tr("14"));
fontSizeBox->addItem(tr("16"));
fontSizeBox->addItem(tr("18"));
return fontSizeBox;
}
void OptionDialog::moveToTop() {
QTreeWidgetItem *currentItem = dictListWidget->currentItem();
qint32 currentIndex = dictListWidget->indexOfTopLevelItem(currentItem);
if (currentIndex > 0) {
QTreeWidgetItem *newItem = dictListWidget->takeTopLevelItem(currentIndex);
dictListWidget->insertTopLevelItem(0, newItem);
dictListWidget->setCurrentItem(newItem);
}
}
void OptionDialog::moveUp() {
QTreeWidgetItem *currentItem = dictListWidget->currentItem();
qint32 currentIndex = dictListWidget->indexOfTopLevelItem(currentItem);
if (currentIndex > 0) {
QTreeWidgetItem *newItem = dictListWidget->takeTopLevelItem(currentIndex);
dictListWidget->insertTopLevelItem(currentIndex - 1, newItem);
dictListWidget->setCurrentItem(newItem);
}
}
void OptionDialog::moveDown() {
QTreeWidgetItem *currentItem = dictListWidget->currentItem();
qint32 currentIndex = dictListWidget->indexOfTopLevelItem(currentItem);
if (currentIndex < dictListWidget->topLevelItemCount() - 1) {
QTreeWidgetItem *newItem = dictListWidget->takeTopLevelItem(currentIndex);
dictListWidget->insertTopLevelItem(currentIndex + 1, newItem);
dictListWidget->setCurrentItem(newItem);
}
}
void OptionDialog::moveToBottom() {
QTreeWidgetItem *currentItem = dictListWidget->currentItem();
qint32 currentIndex = dictListWidget->indexOfTopLevelItem(currentItem);
qint32 count = dictListWidget->topLevelItemCount();
if (currentIndex < count - 1) {
QTreeWidgetItem *newItem = dictListWidget->takeTopLevelItem(currentIndex);
dictListWidget->insertTopLevelItem(count - 1, newItem);
dictListWidget->setCurrentItem(newItem);
}
}
void OptionDialog::setDictNames(QStringList &list) {
dictListWidget->clear();
QList<QString>::iterator itr;
for (itr = list.begin(); itr != list.end(); itr++) {
QTreeWidgetItem *item = new QTreeWidgetItem(dictListWidget);
item->setText(0, *itr);
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
dictListWidget->addTopLevelItem(item);
}
}