Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #include "mainwindow.h" |
43 | #include "ui_mainwindow.h" |
44 | |
45 | #include "colorbutton.h" |
46 | #include "previewframe.h" |
47 | #include "paletteeditoradvanced.h" |
48 | |
49 | #include <QLabel> |
50 | #include <QApplication> |
51 | #include <QComboBox> |
52 | #include <QStyleFactory> |
53 | #include <QFontDatabase> |
54 | #include <QLineEdit> |
55 | #include <QSpinBox> |
56 | #include <QCheckBox> |
57 | #include <QFileDialog> |
58 | #include <QAction> |
59 | #include <QStatusBar> |
60 | #include <QSettings> |
61 | #include <QMessageBox> |
62 | #include <QStyle> |
63 | #include <QtEvents> |
64 | #include <QInputContext> |
65 | #include <QInputContextFactory> |
66 | #include <QtDebug> |
67 | #include <QPixmap> |
68 | |
69 | #include <stdlib.h> |
70 | |
71 | #ifndef QT_NO_GSTREAMER |
72 | #include <gst/gst.h> |
73 | #endif |
74 | #ifdef HAVE_PHONON |
75 | #include <phonon/phononnamespace.h> |
76 | #endif |
77 | |
78 | #ifdef Q_WS_X11 |
79 | #include <QtGui/private/qt_x11_p.h> |
80 | #endif |
81 | |
82 | QT_BEGIN_NAMESPACE |
83 | |
84 | // from qapplication.cpp and qapplication_x11.cpp - These are NOT for |
85 | // external use ignore them |
86 | // extern bool Q_CORE_EXPORT qt_resolve_symlinks; |
87 | |
88 | static const char *appearance_text = QT_TRANSLATE_NOOP("MainWindow", |
89 | "<p><b><font size+=2>Appearance</font></b></p>" |
90 | "<hr>" |
91 | "<p>Use this tab to customize the appearance of your Qt applications.</p>" |
92 | "<p>You can select the default GUI Style from the drop down list and " |
93 | "customize the colors.</p>" |
94 | "<p>Any GUI Style plugins in your plugin path will automatically be added " |
95 | "to the list of built-in Qt styles. (See the Library Paths tab for " |
96 | "information on adding new plugin paths.)</p>" |
97 | "<p>When you choose 3-D Effects and Window Background colors, the Qt " |
98 | "Configuration program will automatically generate a palette for you. " |
99 | "To customize colors further, press the Tune Palette button to open " |
100 | "the advanced palette editor." |
101 | "<p>The Preview Window shows what the selected Style and colors look " |
102 | "like."); |
103 | |
104 | static const char *font_text = QT_TRANSLATE_NOOP("MainWindow", |
105 | "<p><b><font size+=2>Fonts</font></b></p>" |
106 | "<hr>" |
107 | "<p>Use this tab to select the default font for your Qt applications. " |
108 | "The selected font is shown (initially as 'Sample Text') in the line " |
109 | "edit below the Family, " |
110 | "Style and Point Size drop down lists.</p>" |
111 | "<p>Qt has a powerful font substitution feature that allows you to " |
112 | "specify a list of substitute fonts. Substitute fonts are used " |
113 | "when a font cannot be loaded, or if the specified font doesn't have " |
114 | "a particular character." |
115 | "<p>For example, if you select the font Lucida, which doesn't have Korean " |
116 | "characters, but need to show some Korean text using the Mincho font family " |
117 | "you can do so by adding Mincho to the list. Once Mincho is added, any " |
118 | "Korean characters that are not found in the Lucida font will be taken " |
119 | "from the Mincho font. Because the font substitutions are " |
120 | "lists, you can also select multiple families, such as Song Ti (for " |
121 | "use with Chinese text)."); |
122 | |
123 | static const char *interface_text = QT_TRANSLATE_NOOP("MainWindow", |
124 | "<p><b><font size+=2>Interface</font></b></p>" |
125 | "<hr>" |
126 | "<p>Use this tab to customize the feel of your Qt applications.</p>" |
127 | "<p>If the Resolve Symlinks checkbox is checked Qt will follow symlinks " |
128 | "when handling URLs. For example, in the file dialog, if this setting is turned " |
129 | "on and /usr/tmp is a symlink to /var/tmp, entering the /usr/tmp directory " |
130 | "will cause the file dialog to change to /var/tmp. With this setting turned " |
131 | "off, symlinks are not resolved or followed.</p>" |
132 | "<p>The Global Strut setting is useful for people who require a " |
133 | "minimum size for all widgets (e.g. when using a touch panel or for users " |
134 | "who are visually impaired). Leaving the Global Strut width and height " |
135 | "at 0 will disable the Global Strut feature</p>" |
136 | "<p>XIM (Extended Input Methods) are used for entering characters in " |
137 | "languages that have large character sets, for example, Chinese and " |
138 | "Japanese."); |
139 | // ### What does the 'Enhanced support for languages written R2L do? |
140 | |
141 | static const char *printer_text = QT_TRANSLATE_NOOP("MainWindow", |
142 | "<p><b><font size+=2>Printer</font></b></p>" |
143 | "<hr>" |
144 | "<p>Use this tab to configure the way Qt generates output for the printer." |
145 | "You can specify if Qt should try to embed fonts into its generated output." |
146 | "If you enable font embedding, the resulting postscript will be more " |
147 | "portable and will more accurately reflect the " |
148 | "visual output on the screen; however the resulting postscript file " |
149 | "size will be bigger." |
150 | "<p>When using font embedding you can select additional directories where " |
151 | "Qt should search for embeddable font files. By default, the X " |
152 | "server font path is used."); |
153 | |
154 | static const char *phonon_text = QT_TRANSLATE_NOOP("MainWindow", |
155 | "<p><b><font size+=2>Phonon</font></b></p>" |
156 | "<hr>" |
157 | "<p>Use this tab to configure the Phonon GStreamer multimedia backend. " |
158 | "<p>It is reccommended to leave all settings on \"Auto\" to let " |
159 | "Phonon determine your settings automatically."); |
160 | |
161 | |
162 | QPalette::ColorGroup MainWindow::groupFromIndex(int item) |
163 | { |
164 | switch (item) { |
165 | case 0: |
166 | default: |
167 | return QPalette::Active; |
168 | case 1: |
169 | return QPalette::Inactive; |
170 | case 2: |
171 | return QPalette::Disabled; |
172 | } |
173 | } |
174 | |
175 | static void setStyleHelper(QWidget *w, QStyle *s) |
176 | { |
177 | const QObjectList children = w->children(); |
178 | for (int i = 0; i < children.size(); ++i) { |
179 | QObject *child = children.at(i); |
180 | if (child->isWidgetType()) |
181 | setStyleHelper((QWidget *) child, s); |
182 | } |
183 | w->setStyle(s); |
184 | } |
185 | |
186 | MainWindow::MainWindow() |
187 | : ui(new Ui::MainWindow), |
188 | editPalette(palette()), |
189 | previewPalette(palette()), |
190 | previewstyle(0) |
191 | { |
192 | ui->setupUi(this); |
193 | statusBar(); |
194 | |
195 | // signals and slots connections |
196 | connect(ui->fontPathLineEdit, SIGNAL(returnPressed()), SLOT(addFontpath())); |
197 | connect(ui->addFontPathButton, SIGNAL(clicked()), SLOT(addFontpath())); |
198 | connect(ui->addSubstitutionButton, SIGNAL(clicked()), SLOT(addSubstitute())); |
199 | connect(ui->browseFontPathButton, SIGNAL(clicked()), SLOT(browseFontpath())); |
200 | connect(ui->fontStyleCombo, SIGNAL(activated(int)), SLOT(buildFont())); |
201 | connect(ui->pointSizeCombo, SIGNAL(activated(int)), SLOT(buildFont())); |
202 | connect(ui->downFontpathButton, SIGNAL(clicked()), SLOT(downFontpath())); |
203 | connect(ui->downSubstitutionButton, SIGNAL(clicked()), SLOT(downSubstitute())); |
204 | connect(ui->fontFamilyCombo, SIGNAL(activated(QString)), SLOT(familySelected(QString))); |
205 | connect(ui->fileExitAction, SIGNAL(triggered()), SLOT(fileExit())); |
206 | connect(ui->fileSaveAction, SIGNAL(triggered()), SLOT(fileSave())); |
207 | connect(ui->helpAboutAction, SIGNAL(triggered()), SLOT(helpAbout())); |
208 | connect(ui->helpAboutQtAction, SIGNAL(triggered()), SLOT(helpAboutQt())); |
209 | connect(ui->mainTabWidget, SIGNAL(currentChanged(int)), SLOT(pageChanged(int))); |
210 | connect(ui->paletteCombo, SIGNAL(activated(int)), SLOT(paletteSelected(int))); |
211 | connect(ui->removeFontpathButton, SIGNAL(clicked()), SLOT(removeFontpath())); |
212 | connect(ui->removeSubstitutionButton, SIGNAL(clicked()), SLOT(removeSubstitute())); |
213 | connect(ui->toolBoxEffectCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
214 | connect(ui->doubleClickIntervalSpinBox, SIGNAL(valueChanged(int)), SLOT(somethingModified())); |
215 | connect(ui->cursorFlashTimeSpinBox, SIGNAL(valueChanged(int)), SLOT(somethingModified())); |
216 | connect(ui->wheelScrollLinesSpinBox, SIGNAL(valueChanged(int)), SLOT(somethingModified())); |
217 | connect(ui->menuEffectCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
218 | connect(ui->comboEffectCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
219 | connect(ui->audiosinkCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
220 | connect(ui->videomodeCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
221 | connect(ui->toolTipEffectCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
222 | connect(ui->strutWidthSpinBox, SIGNAL(valueChanged(int)), SLOT(somethingModified())); |
223 | connect(ui->strutHeightSpinBox, SIGNAL(valueChanged(int)), SLOT(somethingModified())); |
224 | connect(ui->effectsCheckBox, SIGNAL(toggled(bool)), SLOT(somethingModified())); |
225 | connect(ui->resolveLinksCheckBox, SIGNAL(toggled(bool)), SLOT(somethingModified())); |
226 | connect(ui->fontEmbeddingCheckBox, SIGNAL(clicked()), SLOT(somethingModified())); |
227 | connect(ui->rtlExtensionsCheckBox, SIGNAL(toggled(bool)), SLOT(somethingModified())); |
228 | connect(ui->inputStyleCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
229 | connect(ui->inputMethodCombo, SIGNAL(activated(int)), SLOT(somethingModified())); |
230 | connect(ui->guiStyleCombo, SIGNAL(activated(QString)), SLOT(styleSelected(QString))); |
231 | connect(ui->familySubstitutionCombo, SIGNAL(activated(QString)), SLOT(substituteSelected(QString))); |
232 | connect(ui->tunePaletteButton, SIGNAL(clicked()), SLOT(tunePalette())); |
233 | connect(ui->upFontpathButton, SIGNAL(clicked()), SLOT(upFontpath())); |
234 | connect(ui->upSubstitutionButton, SIGNAL(clicked()), SLOT(upSubstitute())); |
235 | |
236 | modified = true; |
237 | desktopThemeName = tr("Desktop Settings (Default)"); |
238 | setWindowIcon(QPixmap(":/trolltech/qtconfig/images/appicon.png")); |
239 | QStringList gstyles = QStyleFactory::keys(); |
240 | gstyles.sort(); |
241 | ui->guiStyleCombo->addItem(desktopThemeName); |
242 | ui->guiStyleCombo->setItemData(ui->guiStyleCombo->findText(desktopThemeName), |
243 | tr("Choose style and palette based on your desktop settings."), |
244 | Qt::ToolTipRole); |
245 | ui->guiStyleCombo->addItems(gstyles); |
246 | |
247 | QSettings settings(QLatin1String("Trolltech")); |
248 | settings.beginGroup(QLatin1String("Qt")); |
249 | |
250 | QString currentstyle = settings.value(QLatin1String("style")).toString(); |
251 | if (currentstyle.isEmpty()) { |
252 | ui->guiStyleCombo->setCurrentIndex(ui->guiStyleCombo->findText(desktopThemeName)); |
253 | currentstyle = QApplication::style()->objectName(); |
254 | } else { |
255 | int index = ui->guiStyleCombo->findText(currentstyle, Qt::MatchFixedString); |
256 | if (index != -1) { |
257 | ui->guiStyleCombo->setCurrentIndex(index); |
258 | } else { // we give up |
259 | ui->guiStyleCombo->addItem(tr("Unknown")); |
260 | ui->guiStyleCombo->setCurrentIndex(ui->guiStyleCombo->count() - 1); |
261 | } |
262 | } |
263 | ui->buttonMainColor->setColor(palette().color(QPalette::Active, QPalette::Button)); |
264 | ui->buttonWindowColor->setColor(palette().color(QPalette::Active, QPalette::Window)); |
265 | connect(ui->buttonMainColor, SIGNAL(colorChanged(QColor)), SLOT(buildPalette())); |
266 | connect(ui->buttonWindowColor, SIGNAL(colorChanged(QColor)), SLOT(buildPalette())); |
267 | |
268 | #ifdef Q_WS_X11 |
269 | if (X11->desktopEnvironment == DE_KDE) |
270 | ui->colorConfig->hide(); |
271 | else |
272 | ui->kdeNoteLabel->hide(); |
273 | #else |
274 | ui->colorConfig->hide(); |
275 | ui->kdeNoteLabel->hide(); |
276 | #endif |
277 | |
278 | QFontDatabase db; |
279 | QStringList families = db.families(); |
280 | ui->fontFamilyCombo->addItems(families); |
281 | |
282 | QStringList fs = families; |
283 | QStringList fs2 = QFont::substitutions(); |
284 | QStringList::Iterator fsit = fs2.begin(); |
285 | while (fsit != fs2.end()) { |
286 | if (!fs.contains(*fsit)) |
287 | fs += *fsit; |
288 | fsit++; |
289 | } |
290 | fs.sort(); |
291 | ui->familySubstitutionCombo->addItems(fs); |
292 | |
293 | ui->chooseSubstitutionCombo->addItems(families); |
294 | QList<int> sizes = db.standardSizes(); |
295 | foreach(int i, sizes) |
296 | ui->pointSizeCombo->addItem(QString::number(i)); |
297 | |
298 | ui->doubleClickIntervalSpinBox->setValue(QApplication::doubleClickInterval()); |
299 | ui->cursorFlashTimeSpinBox->setValue(QApplication::cursorFlashTime()); |
300 | ui->wheelScrollLinesSpinBox->setValue(QApplication::wheelScrollLines()); |
301 | // ############# |
302 | // resolveLinksCheckBox->setChecked(qt_resolve_symlinks); |
303 | |
304 | ui->effectsCheckBox->setChecked(QApplication::isEffectEnabled(Qt::UI_General)); |
305 | ui->effectsFrame->setEnabled(ui->effectsCheckBox->isChecked()); |
306 | |
307 | if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) |
308 | ui->menuEffectCombo->setCurrentIndex(2); |
309 | else if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) |
310 | ui->menuEffectCombo->setCurrentIndex(1); |
311 | |
312 | if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)) |
313 | ui->comboEffectCombo->setCurrentIndex(1); |
314 | |
315 | if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip)) |
316 | ui->toolTipEffectCombo->setCurrentIndex(2); |
317 | else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip)) |
318 | ui->toolTipEffectCombo->setCurrentIndex(1); |
319 | |
320 | if (QApplication::isEffectEnabled(Qt::UI_AnimateToolBox)) |
321 | ui->toolBoxEffectCombo->setCurrentIndex(1); |
322 | |
323 | QSize globalStrut = QApplication::globalStrut(); |
324 | ui->strutWidthSpinBox->setValue(globalStrut.width()); |
325 | ui->strutHeightSpinBox->setValue(globalStrut.height()); |
326 | |
327 | // find the default family |
328 | QStringList::Iterator sit = families.begin(); |
329 | int i = 0, possible = -1; |
330 | while (sit != families.end()) { |
331 | if (*sit == QApplication::font().family()) |
332 | break; |
333 | if ((*sit).contains(QApplication::font().family())) |
334 | possible = i; |
335 | |
336 | i++; |
337 | sit++; |
338 | } |
339 | if (sit == families.end()) |
340 | i = possible; |
341 | if (i == -1) // no clue about the current font |
342 | i = 0; |
343 | |
344 | ui->fontFamilyCombo->setCurrentIndex(i); |
345 | |
346 | QStringList styles = db.styles(ui->fontFamilyCombo->currentText()); |
347 | ui->fontStyleCombo->addItems(styles); |
348 | |
349 | QString stylestring = db.styleString(QApplication::font()); |
350 | sit = styles.begin(); |
351 | i = 0; |
352 | possible = -1; |
353 | while (sit != styles.end()) { |
354 | if (*sit == stylestring) |
355 | break; |
356 | if ((*sit).contains(stylestring)) |
357 | possible = i; |
358 | |
359 | i++; |
360 | sit++; |
361 | } |
362 | if (sit == styles.end()) |
363 | i = possible; |
364 | if (i == -1) // no clue about the current font |
365 | i = 0; |
366 | ui->fontStyleCombo->setCurrentIndex(i); |
367 | |
368 | i = 0; |
369 | for (int psize = QApplication::font().pointSize(); i < ui->pointSizeCombo->count(); ++i) { |
370 | const int sz = ui->pointSizeCombo->itemText(i).toInt(); |
371 | if (sz == psize) { |
372 | ui->pointSizeCombo->setCurrentIndex(i); |
373 | break; |
374 | } else if(sz > psize) { |
375 | ui->pointSizeCombo->insertItem(i, QString::number(psize)); |
376 | ui->pointSizeCombo->setCurrentIndex(i); |
377 | break; |
378 | } |
379 | } |
380 | |
381 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
382 | ui->substitutionsListBox->clear(); |
383 | ui->substitutionsListBox->insertItems(0, subs); |
384 | |
385 | ui->rtlExtensionsCheckBox->setChecked(settings.value(QLatin1String("useRtlExtensions"), false) |
386 | .toBool()); |
387 | |
388 | #ifdef Q_WS_X11 |
389 | QString settingsInputStyle = settings.value(QLatin1String("XIMInputStyle")).toString(); |
390 | if (!settingsInputStyle.isEmpty()) |
391 | ui->inputStyleCombo->setCurrentIndex(ui->inputStyleCombo->findText(settingsInputStyle)); |
392 | #else |
393 | ui->inputStyleCombo->hide(); |
394 | ui->inputStyleLabel->hide(); |
395 | #endif |
396 | |
397 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM) |
398 | QStringList inputMethodCombo = QInputContextFactory::keys(); |
399 | int inputMethodComboIndex = -1; |
400 | QString defaultInputMethod = settings.value(QLatin1String("DefaultInputMethod"), QLatin1String( "xim")).toString(); |
401 | for (int i = inputMethodCombo.size()-1; i >= 0; --i) { |
402 | const QString &im = inputMethodCombo.at(i); |
403 | if (im.contains(QLatin1String("imsw"))) { |
404 | inputMethodCombo.removeAt(i); |
405 | if (inputMethodComboIndex > i) |
406 | --inputMethodComboIndex; |
407 | } else if (im == defaultInputMethod) { |
408 | inputMethodComboIndex = i; |
409 | } |
410 | } |
411 | if (inputMethodComboIndex == -1 && !inputMethodCombo.isEmpty()) |
412 | inputMethodComboIndex = 0; |
413 | ui->inputMethodCombo->addItems(inputMethodCombo); |
414 | ui->inputMethodCombo->setCurrentIndex(inputMethodComboIndex); |
415 | #else |
416 | ui->inputMethodCombo->hide(); |
417 | ui->inputMethodLabel->hide(); |
418 | #endif |
419 | |
420 | ui->fontEmbeddingCheckBox->setChecked(settings.value(QLatin1String("embedFonts"), true) |
421 | .toBool()); |
422 | fontpaths = settings.value(QLatin1String("fontPath")).toStringList(); |
423 | ui->fontpathListBox->insertItems(0, fontpaths); |
424 | |
425 | ui->audiosinkCombo->addItem(tr("Auto (default)"), QLatin1String( "Auto")); |
426 | ui->audiosinkCombo->setItemData(ui->audiosinkCombo->findText(tr("Auto (default)")), |
427 | tr("Choose audio output automatically."), Qt::ToolTipRole); |
428 | ui->audiosinkCombo->addItem(tr("aRts"), QLatin1String( "artssink")); |
429 | ui->audiosinkCombo->setItemData(ui->audiosinkCombo->findText(tr("aRts")), |
430 | tr("Experimental aRts support for GStreamer."), |
431 | Qt::ToolTipRole); |
432 | #ifdef HAVE_PHONON |
433 | ui->phononVersionLabel->setText(QLatin1String(Phonon::phononVersion())); |
434 | #endif |
435 | #ifndef QT_NO_GSTREAMER |
436 | if (gst_init_check(0, 0, 0)) { |
437 | gchar *versionString = gst_version_string(); |
438 | ui->gstVersionLabel->setText(QLatin1String(versionString)); |
439 | g_free(versionString); |
440 | GList *factoryList = gst_registry_get_feature_list(gst_registry_get_default(), |
441 | GST_TYPE_ELEMENT_FACTORY); |
442 | QString name, klass, description; |
443 | for (GList *iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) { |
444 | GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data); |
445 | klass = QLatin1String(gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature))); |
446 | if (klass == QLatin1String("Sink/Audio")) { |
447 | name = QLatin1String(GST_PLUGIN_FEATURE_NAME(feature)); |
448 | if (name == QLatin1String("sfsink")) |
449 | continue; // useless to output audio to file when you cannot set the file path |
450 | else if (name == QLatin1String("autoaudiosink")) |
451 | continue; //This is used implicitly from the auto setting |
452 | GstElement *sink = gst_element_factory_make (qPrintable(name), NULL); |
453 | if (sink) { |
454 | description = QLatin1String(gst_element_factory_get_description(GST_ELEMENT_FACTORY(feature))); |
455 | ui->audiosinkCombo->addItem(name, name); |
456 | ui->audiosinkCombo->setItemData(ui->audiosinkCombo->findText(name), description, |
457 | Qt::ToolTipRole); |
458 | gst_object_unref (sink); |
459 | } |
460 | } |
461 | } |
462 | g_list_free(factoryList); |
463 | } |
464 | #else |
465 | ui->phononTab->setEnabled(false); |
466 | ui->phononLabel->setText(tr("Phonon GStreamer backend not available.")); |
467 | #endif |
468 | |
469 | ui->videomodeCombo->addItem(tr("Auto (default)"), QLatin1String( "Auto")); |
470 | ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("Auto (default)")), |
471 | tr("Choose render method automatically"), Qt::ToolTipRole); |
472 | #ifdef Q_WS_X11 |
473 | ui->videomodeCombo->addItem(tr("X11"), QLatin1String( "X11")); |
474 | ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("X11")), |
475 | tr("Use X11 Overlays"), Qt::ToolTipRole); |
476 | #endif |
477 | #ifndef QT_NO_OPENGL |
478 | ui->videomodeCombo->addItem(tr("OpenGL"), QLatin1String( "OpenGL")); |
479 | ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("OpenGL")), |
480 | tr("Use OpenGL if available"), Qt::ToolTipRole); |
481 | #endif |
482 | ui->videomodeCombo->addItem(tr("Software"), QLatin1String( "Software")); |
483 | ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("Software")), |
484 | tr("Use simple software rendering"), Qt::ToolTipRole); |
485 | |
486 | QString audioSink = settings.value(QLatin1String("audiosink"), QLatin1String( "Auto")).toString(); |
487 | QString videoMode = settings.value(QLatin1String("videomode"), QLatin1String( "Auto")).toString(); |
488 | ui->audiosinkCombo->setCurrentIndex(ui->audiosinkCombo->findData(audioSink)); |
489 | ui->videomodeCombo->setCurrentIndex(ui->videomodeCombo->findData(videoMode)); |
490 | |
491 | settings.endGroup(); // Qt |
492 | |
493 | ui->helpView->setText(tr(appearance_text)); |
494 | |
495 | setModified(false); |
496 | updateStyleLayout(); |
497 | } |
498 | |
499 | MainWindow::~MainWindow() |
500 | { |
501 | delete ui; |
502 | } |
503 | |
504 | #ifdef Q_WS_X11 |
505 | extern void qt_x11_apply_settings_in_all_apps(); |
506 | #endif |
507 | |
508 | void MainWindow::fileSave() |
509 | { |
510 | if (! modified) { |
511 | statusBar()->showMessage(tr("No changes to be saved."), 2000); |
512 | return; |
513 | } |
514 | |
515 | statusBar()->showMessage(tr("Saving changes...")); |
516 | |
517 | { |
518 | QSettings settings(QLatin1String("Trolltech")); |
519 | settings.beginGroup(QLatin1String("Qt")); |
520 | QFontDatabase db; |
521 | QFont font = db.font(ui->fontFamilyCombo->currentText(), |
522 | ui->fontStyleCombo->currentText(), |
523 | ui->pointSizeCombo->currentText().toInt()); |
524 | |
525 | QStringList actcg, inactcg, discg; |
526 | bool overrideDesktopSettings = (ui->guiStyleCombo->currentText() != desktopThemeName); |
527 | if (overrideDesktopSettings) { |
528 | int i; |
529 | for (i = 0; i < QPalette::NColorRoles; i++) |
530 | actcg << editPalette.color(QPalette::Active, |
531 | QPalette::ColorRole(i)).name(); |
532 | for (i = 0; i < QPalette::NColorRoles; i++) |
533 | inactcg << editPalette.color(QPalette::Inactive, |
534 | QPalette::ColorRole(i)).name(); |
535 | for (i = 0; i < QPalette::NColorRoles; i++) |
536 | discg << editPalette.color(QPalette::Disabled, |
537 | QPalette::ColorRole(i)).name(); |
538 | } |
539 | |
540 | settings.setValue(QLatin1String("font"), font.toString()); |
541 | settings.setValue(QLatin1String("Palette/active"), actcg); |
542 | settings.setValue(QLatin1String("Palette/inactive"), inactcg); |
543 | settings.setValue(QLatin1String("Palette/disabled"), discg); |
544 | |
545 | settings.setValue(QLatin1String("fontPath"), fontpaths); |
546 | settings.setValue(QLatin1String("embedFonts"), ui->fontEmbeddingCheckBox->isChecked()); |
547 | settings.setValue(QLatin1String("style"), |
548 | overrideDesktopSettings ? ui->guiStyleCombo->currentText() : QString()); |
549 | |
550 | settings.setValue(QLatin1String("doubleClickInterval"), ui->doubleClickIntervalSpinBox->value()); |
551 | settings.setValue(QLatin1String("cursorFlashTime"), |
552 | ui->cursorFlashTimeSpinBox->value() == 9 ? 0 : ui->cursorFlashTimeSpinBox->value()); |
553 | settings.setValue(QLatin1String("wheelScrollLines"), ui->wheelScrollLinesSpinBox->value()); |
554 | settings.setValue(QLatin1String("resolveSymlinks"), ui->resolveLinksCheckBox->isChecked()); |
555 | |
556 | QSize strut(ui->strutWidthSpinBox->value(), ui->strutHeightSpinBox->value()); |
557 | settings.setValue(QLatin1String("globalStrut/width"), strut.width()); |
558 | settings.setValue(QLatin1String("globalStrut/height"), strut.height()); |
559 | |
560 | settings.setValue(QLatin1String("useRtlExtensions"), ui->rtlExtensionsCheckBox->isChecked()); |
561 | |
562 | #ifdef Q_WS_X11 |
563 | QString style = ui->inputStyleCombo->currentText(); |
564 | QString str = QLatin1String("On The Spot"); |
565 | if (style == tr("Over The Spot")) |
566 | str = QLatin1String("Over The Spot"); |
567 | else if (style == tr("Off The Spot")) |
568 | str = QLatin1String("Off The Spot"); |
569 | else if (style == tr("Root")) |
570 | str = QLatin1String("Root"); |
571 | settings.setValue(QLatin1String("XIMInputStyle"), str); |
572 | #endif |
573 | #if defined(Q_WS_X11) && !defined(QT_NO_XIM) |
574 | settings.setValue(QLatin1String("DefaultInputMethod"), ui->inputMethodCombo->currentText()); |
575 | #endif |
576 | |
577 | QString audioSink = settings.value(QLatin1String("audiosink"), QLatin1String( "Auto")).toString(); |
578 | QString videoMode = settings.value(QLatin1String("videomode"), QLatin1String( "Auto")).toString(); |
579 | settings.setValue(QLatin1String("audiosink"), |
580 | ui->audiosinkCombo->itemData(ui->audiosinkCombo->currentIndex())); |
581 | settings.setValue(QLatin1String("videomode"), |
582 | ui->videomodeCombo->itemData(ui->videomodeCombo->currentIndex())); |
583 | |
584 | QStringList effects; |
585 | if (ui->effectsCheckBox->isChecked()) { |
586 | effects << QLatin1String("general"); |
587 | |
588 | switch (ui->menuEffectCombo->currentIndex()) { |
589 | case 1: effects << QLatin1String("animatemenu"); break; |
590 | case 2: effects << QLatin1String("fademenu"); break; |
591 | } |
592 | |
593 | switch (ui->comboEffectCombo->currentIndex()) { |
594 | case 1: effects << QLatin1String("animatecombo"); break; |
595 | } |
596 | |
597 | switch (ui->toolTipEffectCombo->currentIndex()) { |
598 | case 1: effects << QLatin1String("animatetooltip"); break; |
599 | case 2: effects << QLatin1String("fadetooltip"); break; |
600 | } |
601 | |
602 | switch (ui->toolBoxEffectCombo->currentIndex()) { |
603 | case 1: effects << QLatin1String("animatetoolbox"); break; |
604 | } |
605 | } else |
606 | effects << QLatin1String("none"); |
607 | settings.setValue(QLatin1String("GUIEffects"), effects); |
608 | |
609 | QStringList familysubs = QFont::substitutions(); |
610 | QStringList::Iterator fit = familysubs.begin(); |
611 | settings.beginGroup(QLatin1String("Font Substitutions")); |
612 | while (fit != familysubs.end()) { |
613 | QStringList subs = QFont::substitutes(*fit); |
614 | settings.setValue(*fit, subs); |
615 | fit++; |
616 | } |
617 | settings.endGroup(); // Font Substitutions |
618 | settings.endGroup(); // Qt |
619 | } |
620 | |
621 | #if defined(Q_WS_X11) |
622 | qt_x11_apply_settings_in_all_apps(); |
623 | #endif // Q_WS_X11 |
624 | |
625 | setModified(false); |
626 | statusBar()->showMessage(tr("Saved changes.")); |
627 | } |
628 | |
629 | void MainWindow::fileExit() |
630 | { |
631 | qApp->closeAllWindows(); |
632 | } |
633 | |
634 | void MainWindow::setModified(bool m) |
635 | { |
636 | if (modified == m) |
637 | return; |
638 | |
639 | modified = m; |
640 | ui->fileSaveAction->setEnabled(m); |
641 | } |
642 | |
643 | void MainWindow::buildPalette() |
644 | { |
645 | QPalette temp(ui->buttonMainColor->color(), ui->buttonWindowColor->color()); |
646 | for (int i = 0; i < QPalette::NColorGroups; i++) |
647 | temp = PaletteEditorAdvanced::buildEffect(QPalette::ColorGroup(i), temp); |
648 | |
649 | editPalette = temp; |
650 | setPreviewPalette(editPalette); |
651 | updateColorButtons(); |
652 | |
653 | setModified(true); |
654 | } |
655 | |
656 | void MainWindow::setPreviewPalette(const QPalette &pal) |
657 | { |
658 | QPalette::ColorGroup colorGroup = groupFromIndex(ui->paletteCombo->currentIndex()); |
659 | |
660 | for (int i = 0; i < QPalette::NColorGroups; i++) { |
661 | for (int j = 0; j < QPalette::NColorRoles; j++) { |
662 | QPalette::ColorGroup targetGroup = QPalette::ColorGroup(i); |
663 | QPalette::ColorRole targetRole = QPalette::ColorRole(j); |
664 | previewPalette.setColor(targetGroup, targetRole, pal.color(colorGroup, targetRole)); |
665 | } |
666 | } |
667 | |
668 | ui->previewFrame->setPreviewPalette(previewPalette); |
669 | } |
670 | |
671 | void MainWindow::updateColorButtons() |
672 | { |
673 | ui->buttonMainColor->setColor(editPalette.color(QPalette::Active, QPalette::Button)); |
674 | ui->buttonWindowColor->setColor(editPalette.color(QPalette::Active, QPalette::Window)); |
675 | } |
676 | |
677 | void MainWindow::tunePalette() |
678 | { |
679 | bool ok; |
680 | QPalette pal = PaletteEditorAdvanced::getPalette(&ok, editPalette, |
681 | backgroundRole(), this); |
682 | if (!ok) |
683 | return; |
684 | |
685 | editPalette = pal; |
686 | setPreviewPalette(editPalette); |
687 | setModified(true); |
688 | } |
689 | |
690 | void MainWindow::paletteSelected(int) |
691 | { |
692 | setPreviewPalette(editPalette); |
693 | } |
694 | |
695 | void MainWindow::updateStyleLayout() |
696 | { |
697 | QString currentStyle = ui->guiStyleCombo->currentText(); |
698 | bool autoStyle = (currentStyle == desktopThemeName); |
699 | ui->previewFrame->setPreviewVisible(!autoStyle); |
700 | ui->buildPaletteGroup->setEnabled(currentStyle.toLower() != QLatin1String("gtk") && !autoStyle); |
701 | } |
702 | |
703 | void MainWindow::styleSelected(const QString &stylename) |
704 | { |
705 | QStyle *style = 0; |
706 | if (stylename == desktopThemeName) { |
707 | setModified(true); |
708 | } else { |
709 | style = QStyleFactory::create(stylename); |
710 | if (!style) |
711 | return; |
712 | setStyleHelper(ui->previewFrame, style); |
713 | delete previewstyle; |
714 | previewstyle = style; |
715 | setModified(true); |
716 | } |
717 | updateStyleLayout(); |
718 | } |
719 | |
720 | void MainWindow::familySelected(const QString &family) |
721 | { |
722 | QFontDatabase db; |
723 | QStringList styles = db.styles(family); |
724 | ui->fontStyleCombo->clear(); |
725 | ui->fontStyleCombo->addItems(styles); |
726 | ui->familySubstitutionCombo->addItem(family); |
727 | buildFont(); |
728 | } |
729 | |
730 | void MainWindow::buildFont() |
731 | { |
732 | QFontDatabase db; |
733 | QFont font = db.font(ui->fontFamilyCombo->currentText(), |
734 | ui->fontStyleCombo->currentText(), |
735 | ui->pointSizeCombo->currentText().toInt()); |
736 | ui->sampleLineEdit->setFont(font); |
737 | setModified(true); |
738 | } |
739 | |
740 | void MainWindow::substituteSelected(const QString &family) |
741 | { |
742 | QStringList subs = QFont::substitutes(family); |
743 | ui->substitutionsListBox->clear(); |
744 | ui->substitutionsListBox->insertItems(0, subs); |
745 | } |
746 | |
747 | void MainWindow::removeSubstitute() |
748 | { |
749 | if (!ui->substitutionsListBox->currentItem()) |
750 | return; |
751 | |
752 | int row = ui->substitutionsListBox->currentRow(); |
753 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
754 | subs.removeAt(ui->substitutionsListBox->currentRow()); |
755 | ui->substitutionsListBox->clear(); |
756 | ui->substitutionsListBox->insertItems(0, subs); |
757 | if (row > ui->substitutionsListBox->count()) |
758 | row = ui->substitutionsListBox->count() - 1; |
759 | ui->substitutionsListBox->setCurrentRow(row); |
760 | QFont::removeSubstitution(ui->familySubstitutionCombo->currentText()); |
761 | QFont::insertSubstitutions(ui->familySubstitutionCombo->currentText(), subs); |
762 | setModified(true); |
763 | } |
764 | |
765 | void MainWindow::addSubstitute() |
766 | { |
767 | if (!ui->substitutionsListBox->currentItem()) { |
768 | QFont::insertSubstitution(ui->familySubstitutionCombo->currentText(), |
769 | ui->chooseSubstitutionCombo->currentText()); |
770 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
771 | ui->substitutionsListBox->clear(); |
772 | ui->substitutionsListBox->insertItems(0, subs); |
773 | setModified(true); |
774 | return; |
775 | } |
776 | |
777 | int row = ui->substitutionsListBox->currentRow(); |
778 | QFont::insertSubstitution(ui->familySubstitutionCombo->currentText(), ui->chooseSubstitutionCombo->currentText()); |
779 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
780 | ui->substitutionsListBox->clear(); |
781 | ui->substitutionsListBox->insertItems(0, subs); |
782 | ui->substitutionsListBox->setCurrentRow(row); |
783 | setModified(true); |
784 | } |
785 | |
786 | void MainWindow::downSubstitute() |
787 | { |
788 | if (!ui->substitutionsListBox->currentItem() || ui->substitutionsListBox->currentRow() >= ui->substitutionsListBox->count()) |
789 | return; |
790 | |
791 | int row = ui->substitutionsListBox->currentRow(); |
792 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
793 | QString fam = subs.at(row); |
794 | subs.removeAt(row); |
795 | subs.insert(row + 1, fam); |
796 | ui->substitutionsListBox->clear(); |
797 | ui->substitutionsListBox->insertItems(0, subs); |
798 | ui->substitutionsListBox->setCurrentRow(row + 1); |
799 | QFont::removeSubstitution(ui->familySubstitutionCombo->currentText()); |
800 | QFont::insertSubstitutions(ui->familySubstitutionCombo->currentText(), subs); |
801 | setModified(true); |
802 | } |
803 | |
804 | void MainWindow::upSubstitute() |
805 | { |
806 | if (!ui->substitutionsListBox->currentItem() || ui->substitutionsListBox->currentRow() < 1) |
807 | return; |
808 | |
809 | int row = ui->substitutionsListBox->currentRow(); |
810 | QStringList subs = QFont::substitutes(ui->familySubstitutionCombo->currentText()); |
811 | QString fam = subs.at(row); |
812 | subs.removeAt(row); |
813 | subs.insert(row-1, fam); |
814 | ui->substitutionsListBox->clear(); |
815 | ui->substitutionsListBox->insertItems(0, subs); |
816 | ui->substitutionsListBox->setCurrentRow(row - 1); |
817 | QFont::removeSubstitution(ui->familySubstitutionCombo->currentText()); |
818 | QFont::insertSubstitutions(ui->familySubstitutionCombo->currentText(), subs); |
819 | setModified(true); |
820 | } |
821 | |
822 | void MainWindow::removeFontpath() |
823 | { |
824 | if (!ui->fontpathListBox->currentItem()) |
825 | return; |
826 | |
827 | int row = ui->fontpathListBox->currentRow(); |
828 | fontpaths.removeAt(row); |
829 | ui->fontpathListBox->clear(); |
830 | ui->fontpathListBox->insertItems(0, fontpaths); |
831 | if (row > ui->fontpathListBox->count()) |
832 | row = ui->fontpathListBox->count() - 1; |
833 | ui->fontpathListBox->setCurrentRow(row); |
834 | setModified(true); |
835 | } |
836 | |
837 | void MainWindow::addFontpath() |
838 | { |
839 | if (ui->fontPathLineEdit->text().isEmpty()) |
840 | return; |
841 | |
842 | if (!ui->fontpathListBox->currentItem()) { |
843 | fontpaths.append(ui->fontPathLineEdit->text()); |
844 | ui->fontpathListBox->clear(); |
845 | ui->fontpathListBox->insertItems(0, fontpaths); |
846 | setModified(true); |
847 | |
848 | return; |
849 | } |
850 | |
851 | int row = ui->fontpathListBox->currentRow(); |
852 | fontpaths.insert(row + 1, ui->fontPathLineEdit->text()); |
853 | ui->fontpathListBox->clear(); |
854 | ui->fontpathListBox->insertItems(0, fontpaths); |
855 | ui->fontpathListBox->setCurrentRow(row); |
856 | setModified(true); |
857 | } |
858 | |
859 | void MainWindow::downFontpath() |
860 | { |
861 | if (!ui->fontpathListBox->currentItem() |
862 | || ui->fontpathListBox->currentRow() >= (ui->fontpathListBox->count() - 1)) { |
863 | return; |
864 | } |
865 | |
866 | int row = ui->fontpathListBox->currentRow(); |
867 | QString fam = fontpaths.at(row); |
868 | fontpaths.removeAt(row); |
869 | fontpaths.insert(row + 1, fam); |
870 | ui->fontpathListBox->clear(); |
871 | ui->fontpathListBox->insertItems(0, fontpaths); |
872 | ui->fontpathListBox->setCurrentRow(row + 1); |
873 | setModified(true); |
874 | } |
875 | |
876 | void MainWindow::upFontpath() |
877 | { |
878 | if (!ui->fontpathListBox->currentItem() || ui->fontpathListBox->currentRow() < 1) |
879 | return; |
880 | |
881 | int row = ui->fontpathListBox->currentRow(); |
882 | QString fam = fontpaths.at(row); |
883 | fontpaths.removeAt(row); |
884 | fontpaths.insert(row - 1, fam); |
885 | ui->fontpathListBox->clear(); |
886 | ui->fontpathListBox->insertItems(0, fontpaths); |
887 | ui->fontpathListBox->setCurrentRow(row - 1); |
888 | setModified(true); |
889 | } |
890 | |
891 | void MainWindow::browseFontpath() |
892 | { |
893 | QString dirname = QFileDialog::getExistingDirectory(this, tr("Select a Directory")); |
894 | if (dirname.isNull()) |
895 | return; |
896 | |
897 | ui->fontPathLineEdit->setText(dirname); |
898 | } |
899 | |
900 | void MainWindow::somethingModified() |
901 | { |
902 | setModified(true); |
903 | } |
904 | |
905 | void MainWindow::helpAbout() |
906 | { |
907 | QMessageBox box(this); |
908 | box.setText(tr("<h3>%1</h3>" |
909 | "<br/>Version %2" |
910 | "<br/><br/>Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).") |
911 | .arg(tr("Qt Configuration")).arg(QLatin1String(QT_VERSION_STR))); |
912 | box.setWindowTitle(tr("Qt Configuration")); |
913 | box.setIcon(QMessageBox::NoIcon); |
914 | box.exec(); |
915 | } |
916 | |
917 | void MainWindow::helpAboutQt() |
918 | { |
919 | QMessageBox::aboutQt(this, tr("Qt Configuration")); |
920 | } |
921 | |
922 | void MainWindow::pageChanged(int pageNumber) |
923 | { |
924 | QWidget *page = ui->mainTabWidget->widget(pageNumber); |
925 | if (page == ui->interfaceTab) |
926 | ui->helpView->setText(tr(interface_text)); |
927 | else if (page == ui->appearanceTab) |
928 | ui->helpView->setText(tr(appearance_text)); |
929 | else if (page == ui->fontsTab) |
930 | ui->helpView->setText(tr(font_text)); |
931 | else if (page == ui->printerTab) |
932 | ui->helpView->setText(tr(printer_text)); |
933 | else if (page == ui->phononTab) |
934 | ui->helpView->setText(tr(phonon_text)); |
935 | } |
936 | |
937 | void MainWindow::closeEvent(QCloseEvent *e) |
938 | { |
939 | if (modified) { |
940 | switch (QMessageBox::warning(this, tr("Save Changes"), |
941 | tr("Save changes to settings?"), |
942 | (QMessageBox::Yes | QMessageBox::No |
943 | | QMessageBox::Cancel))) { |
944 | case QMessageBox::Yes: // save |
945 | qApp->processEvents(); |
946 | fileSave(); |
947 | |
948 | // fall through intended |
949 | case QMessageBox::No: // don't save |
950 | e->accept(); |
951 | break; |
952 | |
953 | case QMessageBox::Cancel: // cancel |
954 | e->ignore(); |
955 | break; |
956 | |
957 | default: break; |
958 | } |
959 | } else |
960 | e->accept(); |
961 | } |
962 | |
963 | QT_END_NAMESPACE |
964 |
Warning: That file was not part of the compilation database. It may have many parsing errors.