summaryrefslogtreecommitdiffstats
path: root/tools/qtconfig/mainwindow.cpp
blob: 7301babd58979af074b9781eb8f44744d6803169 (plain)
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "colorbutton.h"
#include "previewframe.h"
#include "paletteeditoradvanced.h"

#include <QLabel>
#include <QApplication>
#include <QComboBox>
#include <QStyleFactory>
#include <QFontDatabase>
#include <QLineEdit>
#include <QSpinBox>
#include <QCheckBox>
#include <QFileDialog>
#include <QAction>
#include <QStatusBar>
#include <QSettings>
#include <QMessageBox>
#include <QStyle>
#include <QtEvents>
#include <QInputContext>
#include <QInputContextFactory>
#include <QtDebug>

#include <stdlib.h>

#ifndef QT_NO_GSTREAMER
#include <gst/gst.h>
#endif
#ifdef HAVE_PHONON
#include <phonon/phononnamespace.h>
#endif

#include <QtGui/private/qt_x11_p.h>

QT_BEGIN_NAMESPACE

// from qapplication.cpp and qapplication_x11.cpp - These are NOT for
// external use ignore them
// extern bool Q_CORE_EXPORT qt_resolve_symlinks;

static const char *appearance_text =
"<p><b><font size+=2>Appearance</font></b></p>"
"<hr>"
"<p>Use this tab to customize the appearance of your Qt applications.</p>"
"<p>You can select the default GUI Style from the drop down list and "
"customize the colors.</p>"
"<p>Any GUI Style plugins in your plugin path will automatically be added "
"to the list of built-in Qt styles. (See the Library Paths tab for "
"information on adding new plugin paths.)</p>"
"<p>When you choose 3-D Effects and Window Background colors, the Qt "
"Configuration program will automatically generate a palette for you. "
"To customize colors further, press the Tune Palette button to open "
"the advanced palette editor."
"<p>The Preview Window shows what the selected Style and colors look "
"like.";

static const char *font_text =
"<p><b><font size+=2>Fonts</font></b></p>"
"<hr>"
"<p>Use this tab to select the default font for your Qt applications. "
"The selected font is shown (initially as 'Sample Text') in the line "
"edit below the Family, "
"Style and Point Size drop down lists.</p>"
"<p>Qt has a powerful font substitution feature that allows you to "
"specify a list of substitute fonts.  Substitute fonts are used "
"when a font cannot be loaded, or if the specified font doesn't have "
"a particular character."
"<p>For example, if you select the font Lucida, which doesn't have Korean "
"characters, but need to show some Korean text using the Mincho font family "
"you can do so by adding Mincho to the list. Once Mincho is added, any "
"Korean characters that are not found in the Lucida font will be taken "
"from the Mincho font.  Because the font substitutions are "
"lists, you can also select multiple families, such as Song Ti (for "
"use with Chinese text).";

static const char *interface_text =
"<p><b><font size+=2>Interface</font></b></p>"
"<hr>"
"<p>Use this tab to customize the feel of your Qt applications.</p>"
"<p>If the Resolve Symlinks checkbox is checked Qt will follow symlinks "
"when handling URLs. For example, in the file dialog, if this setting is turned "
"on and /usr/tmp is a symlink to /var/tmp, entering the /usr/tmp directory "
"will cause the file dialog to change to /var/tmp.  With this setting turned "
"off, symlinks are not resolved or followed.</p>"
"<p>The Global Strut setting is useful for people who require a "
"minimum size for all widgets (e.g. when using a touch panel or for users "
"who are visually impaired).  Leaving the Global Strut width and height "
"at 0 will disable the Global Strut feature</p>"
"<p>XIM (Extended Input Methods) are used for entering characters in "
"languages that have large character sets, for example, Chinese and "
"Japanese.";
// ### What does the 'Enhanced support for languages written R2L do?

static const char *printer_text =
"<p><b><font size+=2>Printer</font></b></p>"
"<hr>"
"<p>Use this tab to configure the way Qt generates output for the printer."
"You can specify if Qt should try to embed fonts into its generated output."
"If you enable font embedding, the resulting postscript will be more "
"portable and will more accurately reflect the "
"visual output on the screen; however the resulting postscript file "
"size will be bigger."
"<p>When using font embedding you can select additional directories where "
"Qt should search for embeddable font files.  By default, the X "
"server font path is used.";

static const char *phonon_text =
"<p><b><font size+=2>Phonon</font></b></p>"
"<hr>"
"<p>Use this tab to configure the Phonon GStreamer multimedia backend. "
"<p>It is reccommended to leave all settings on \"Auto\" to let "
"Phonon determine your settings automatically.";


QPalette::ColorGroup MainWindow::groupFromIndex(int item)
{
    switch (item) {
    case 0:
    default:
        return QPalette::Active;
    case 1:
        return QPalette::Inactive;
    case 2:
        return QPalette::Disabled;
    }
}

static void setStyleHelper(QWidget *w, QStyle *s)
{
    const QObjectList children = w->children();
    for (int i = 0; i < children.size(); ++i) {
        QObject *child = children.at(i);
        if (child->isWidgetType())
            setStyleHelper((QWidget *) child, s);
    }
    w->setStyle(s);
}

MainWindow::MainWindow()
    : QMainWindow(), ui(new Ui::MainWindow), editPalette(palette()), previewPalette(palette()),
      previewstyle(0)
{
    ui->setupUi(this);
    statusBar();

    // signals and slots connections
    connect(ui->fontpathlineedit, SIGNAL(returnPressed()), SLOT(addFontpath()));
    connect(ui->PushButton15, SIGNAL(clicked()), SLOT(addFontpath()));
    connect(ui->PushButton1, SIGNAL(clicked()), SLOT(addSubstitute()));
    connect(ui->PushButton14, SIGNAL(clicked()), SLOT(browseFontpath()));
    connect(ui->stylecombo, SIGNAL(activated(int)), SLOT(buildFont()));
    connect(ui->psizecombo, SIGNAL(activated(int)), SLOT(buildFont()));
    connect(ui->PushButton12, SIGNAL(clicked()), SLOT(downFontpath()));
    connect(ui->PushButton3, SIGNAL(clicked()), SLOT(downSubstitute()));
    connect(ui->familycombo, SIGNAL(activated(QString)), SLOT(familySelected(QString)));
    connect(ui->fileExitAction, SIGNAL(activated()), SLOT(fileExit()));
    connect(ui->fileSaveAction, SIGNAL(activated()), SLOT(fileSave()));
    connect(ui->helpAboutAction, SIGNAL(activated()), SLOT(helpAbout()));
    connect(ui->helpAboutQtAction, SIGNAL(activated()), SLOT(helpAboutQt()));
    connect(ui->TabWidget3, SIGNAL(currentChanged(QWidget*)), SLOT(pageChanged(QWidget*)));
    connect(ui->paletteCombo, SIGNAL(activated(int)), SLOT(paletteSelected(int)));
    connect(ui->PushButton13, SIGNAL(clicked()), SLOT(removeFontpath()));
    connect(ui->PushButton4, SIGNAL(clicked()), SLOT(removeSubstitute()));
    connect(ui->toolboxeffect, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->dcispin, SIGNAL(valueChanged(int)), SLOT(somethingModified()));
    connect(ui->cfispin, SIGNAL(valueChanged(int)), SLOT(somethingModified()));
    connect(ui->wslspin, SIGNAL(valueChanged(int)), SLOT(somethingModified()));
    connect(ui->menueffect, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->comboeffect, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->audiosinkCombo, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->videomodeCombo, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->tooltipeffect, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->strutwidth, SIGNAL(valueChanged(int)), SLOT(somethingModified()));
    connect(ui->strutheight, SIGNAL(valueChanged(int)), SLOT(somethingModified()));
    connect(ui->effectcheckbox, SIGNAL(toggled(bool)), SLOT(somethingModified()));
    connect(ui->resolvelinks, SIGNAL(toggled(bool)), SLOT(somethingModified()));
    connect(ui->fontembeddingcheckbox, SIGNAL(clicked()), SLOT(somethingModified()));
    connect(ui->rtlExtensions, SIGNAL(toggled(bool)), SLOT(somethingModified()));
    connect(ui->inputStyle, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->inputMethod, SIGNAL(activated(int)), SLOT(somethingModified()));
    connect(ui->gstylecombo, SIGNAL(activated(QString)), SLOT(styleSelected(QString)));
    connect(ui->familysubcombo, SIGNAL(activated(QString)), SLOT(substituteSelected(QString)));
    connect(ui->btnAdvanced, SIGNAL(clicked()), SLOT(tunePalette()));
    connect(ui->PushButton11, SIGNAL(clicked()), SLOT(upFontpath()));
    connect(ui->PushButton2, SIGNAL(clicked()), SLOT(upSubstitute()));

    modified = true;
    desktopThemeName = tr("Desktop Settings (Default)");
    QStringList gstyles = QStyleFactory::keys();
    gstyles.sort();
    ui->gstylecombo->addItem(desktopThemeName);
    ui->gstylecombo->setItemData(ui->gstylecombo->findText(desktopThemeName),
                                 tr("Choose style and palette based on your desktop settings."),
                                 Qt::ToolTipRole);
    ui->gstylecombo->addItems(gstyles);

    QSettings settings(QLatin1String("Trolltech"));
    settings.beginGroup(QLatin1String("Qt"));

    QString currentstyle = settings.value(QLatin1String("style")).toString();
    if (currentstyle.isEmpty()) {
        ui->gstylecombo->setCurrentIndex(ui->gstylecombo->findText(desktopThemeName));
        currentstyle = QApplication::style()->objectName();
    } else {
        int index = ui->gstylecombo->findText(currentstyle, Qt::MatchFixedString);
        if (index != -1) {
            ui->gstylecombo->setCurrentIndex(index);
        } else { // we give up
            ui->gstylecombo->addItem(tr("Unknown"));
            ui->gstylecombo->setCurrentIndex(ui->gstylecombo->count() - 1);
        }
    }
    ui->buttonMainColor->setColor(palette().color(QPalette::Active, QPalette::Button));
    ui->buttonWindowColor->setColor(palette().color(QPalette::Active, QPalette::Window));
    connect(ui->buttonMainColor, SIGNAL(colorChanged(QColor)), SLOT(buildPalette()));
    connect(ui->buttonWindowColor, SIGNAL(colorChanged(QColor)), SLOT(buildPalette()));

    if (X11->desktopEnvironment == DE_KDE)
        ui->colorConfig->hide();
    else
        ui->labelKDENote->hide();

    QFontDatabase db;
    QStringList families = db.families();
    ui->familycombo->addItems(families);

    QStringList fs = families;
    QStringList fs2 = QFont::substitutions();
    QStringList::Iterator fsit = fs2.begin();
    while (fsit != fs2.end()) {
        if (!fs.contains(*fsit))
            fs += *fsit;
        fsit++;
    }
    fs.sort();
    ui->familysubcombo->addItems(fs);

    ui->choosesubcombo->addItems(families);
    QList<int> sizes = db.standardSizes();
    foreach(int i, sizes)
        ui->psizecombo->addItem(QString::number(i));

    ui->dcispin->setValue(QApplication::doubleClickInterval());
    ui->cfispin->setValue(QApplication::cursorFlashTime());
    ui->wslspin->setValue(QApplication::wheelScrollLines());
    // #############
//    resolvelinks->setChecked(qt_resolve_symlinks);

    ui->effectcheckbox->setChecked(QApplication::isEffectEnabled(Qt::UI_General));
    ui->effectbase->setEnabled(ui->effectcheckbox->isChecked());

    if (QApplication::isEffectEnabled(Qt::UI_FadeMenu))
        ui->menueffect->setCurrentIndex(2);
    else if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu))
        ui->menueffect->setCurrentIndex(1);

    if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo))
        ui->comboeffect->setCurrentIndex(1);

    if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
        ui->tooltipeffect->setCurrentIndex(2);
    else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
        ui->tooltipeffect->setCurrentIndex(1);

    if (QApplication::isEffectEnabled(Qt::UI_AnimateToolBox))
        ui->toolboxeffect->setCurrentIndex(1);

    QSize globalStrut = QApplication::globalStrut();
    ui->strutwidth->setValue(globalStrut.width());
    ui->strutheight->setValue(globalStrut.height());

    // find the default family
    QStringList::Iterator sit = families.begin();
    int i = 0, possible = -1;
    while (sit != families.end()) {
        if (*sit == QApplication::font().family())
            break;
        if ((*sit).contains(QApplication::font().family()))
            possible = i;

        i++;
        sit++;
    }
    if (sit == families.end())
        i = possible;
    if (i == -1) // no clue about the current font
        i = 0;

    ui->familycombo->setCurrentIndex(i);

    QStringList styles = db.styles(ui->familycombo->currentText());
    ui->stylecombo->addItems(styles);

    QString stylestring = db.styleString(QApplication::font());
    sit = styles.begin();
    i = 0;
    possible = -1;
    while (sit != styles.end()) {
        if (*sit == stylestring)
            break;
        if ((*sit).contains(stylestring))
            possible = i;

        i++;
        sit++;
    }
    if (sit == styles.end())
        i = possible;
    if (i == -1) // no clue about the current font
        i = 0;
    ui->stylecombo->setCurrentIndex(i);

    i = 0;
    for (int psize = QApplication::font().pointSize(); i < ui->psizecombo->count(); ++i) {
        const int sz = ui->psizecombo->itemText(i).toInt();
        if (sz == psize) {
            ui->psizecombo->setCurrentIndex(i);
            break;
        } else if(sz > psize) {
            ui->psizecombo->insertItem(i, QString::number(psize));
            ui->psizecombo->setCurrentIndex(i);
            break;
        }
    }

    QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);

    ui->rtlExtensions->setChecked(settings.value(QLatin1String("useRtlExtensions"), false)
                                  .toBool());

#ifdef Q_WS_X11
    QString settingsInputStyle = settings.value(QLatin1String("XIMInputStyle")).toString();
    if (!settingsInputStyle.isEmpty())
      ui->inputStyle->setCurrentIndex(ui->inputStyle->findText(settingsInputStyle));
#else
    ui->inputStyle->hide();
    ui->inputStyleLabel->hide();
#endif

#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
    QStringList inputMethods = QInputContextFactory::keys();
    int inputMethodIndex = -1;
    QString defaultInputMethod = settings.value(QLatin1String("DefaultInputMethod"), QLatin1String("xim")).toString();
    for (int i = inputMethods.size()-1; i >= 0; --i) {
        const QString &im = inputMethods.at(i);
        if (im.contains(QLatin1String("imsw"))) {
            inputMethods.removeAt(i);
            if (inputMethodIndex > i)
                --inputMethodIndex;
        } else if (im == defaultInputMethod) {
            inputMethodIndex = i;
        }
    }
    if (inputMethodIndex == -1 && !inputMethods.isEmpty())
        inputMethodIndex = 0;
    ui->inputMethod->addItems(inputMethods);
    ui->inputMethod->setCurrentIndex(inputMethodIndex);
#else
    ui->inputMethod->hide();
    ui->inputMethodLabel->hide();
#endif

    ui->fontembeddingcheckbox->setChecked(settings.value(QLatin1String("embedFonts"), true)
                                          .toBool());
    fontpaths = settings.value(QLatin1String("fontPath")).toStringList();
    ui->fontpathlistbox->insertItems(0, fontpaths);

    ui->audiosinkCombo->addItem(tr("Auto (default)"), QLatin1String("Auto"));
    ui->audiosinkCombo->setItemData(ui->audiosinkCombo->findText(tr("Auto (default)")),
                                    tr("Choose audio output automatically."), Qt::ToolTipRole);
    ui->audiosinkCombo->addItem(tr("aRts"), QLatin1String("artssink"));
    ui->audiosinkCombo->setItemData(ui->audiosinkCombo->findText(tr("aRts")),
                                    tr("Experimental aRts support for GStreamer."),
                                    Qt::ToolTipRole);
#ifdef HAVE_PHONON
    phononVersionLabel->setText(QLatin1String(Phonon::phononVersion()));
#endif
#ifndef QT_NO_GSTREAMER
    if (gst_init_check(0, 0, 0)) {
        gchar *versionString = gst_version_string();
        ui->gstversionLabel->setText(QLatin1String(versionString));
        g_free(versionString);
        GList *factoryList = gst_registry_get_feature_list(gst_registry_get_default(),
                                                           GST_TYPE_ELEMENT_FACTORY);
        QString name, klass, description;
        for (GList *iter = g_list_first(factoryList) ; iter != NULL ; iter = g_list_next(iter)) {
            GstPluginFeature *feature = GST_PLUGIN_FEATURE(iter->data);
            klass = QLatin1String(gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature)));
            if (klass == QLatin1String("Sink/Audio")) {
                name = QLatin1String(GST_PLUGIN_FEATURE_NAME(feature));
                if (name == QLatin1String("sfsink"))
                    continue; // useless to output audio to file when you cannot set the file path
                else if (name == QLatin1String("autoaudiosink"))
                    continue; //This is used implicitly from the auto setting
                GstElement *sink = gst_element_factory_make (qPrintable(name), NULL);
                if (sink) {
                    description = QLatin1String(gst_element_factory_get_description(GST_ELEMENT_FACTORY(feature)));
                    ui->audiosinkCombo->addItem(name, name);
                    ui->audiosinkCombo->setItemData(audiosinkCombo->findText(name), description,
                                                    Qt::ToolTipRole);
                    gst_object_unref (sink);
                }
            }
        }
        g_list_free(factoryList);
    }
#else
    ui->tab4->setEnabled(false);
    ui->phononLabel->setText(tr("Phonon GStreamer backend not available."));
#endif

    ui->videomodeCombo->addItem(tr("Auto (default)"), QLatin1String("Auto"));
    ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("Auto (default)")),
                                    tr("Choose render method automatically"), Qt::ToolTipRole);
#ifdef Q_WS_X11
    ui->videomodeCombo->addItem(tr("X11"), QLatin1String("X11"));
    ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("X11")),
                                    tr("Use X11 Overlays"), Qt::ToolTipRole);
#endif
#ifndef QT_NO_OPENGL
<<<<<<< HEAD
    videomodeCombo->addItem(tr("OpenGL"), QLatin1String("OpenGL"));
    videomodeCombo->setItemData(videomodeCombo->findText(tr("OpenGL")), tr("Use OpenGL if available"), Qt::ToolTipRole);
=======
    ui->videomodeCombo->addItem(tr("OpenGL"), QLatin1String("OpenGL"));
    ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("OpenGL")),
                                    tr("Use OpenGL if avaiable"), Qt::ToolTipRole);
>>>>>>> Removed inheritance from UI file in qtconfig's MainWindow
#endif
    ui->videomodeCombo->addItem(tr("Software"), QLatin1String("Software"));
    ui->videomodeCombo->setItemData(ui->videomodeCombo->findText(tr("Software")),
                                    tr("Use simple software rendering"), Qt::ToolTipRole);

    QString audioSink = settings.value(QLatin1String("audiosink"), QLatin1String("Auto")).toString();
    QString videoMode = settings.value(QLatin1String("videomode"), QLatin1String("Auto")).toString();
    ui->audiosinkCombo->setCurrentIndex(ui->audiosinkCombo->findData(audioSink));
    ui->videomodeCombo->setCurrentIndex(ui->videomodeCombo->findData(videoMode));

    settings.endGroup(); // Qt

    ui->helpview->setText(tr(appearance_text));

    setModified(false);
    updateStyleLayout();
}

MainWindow::~MainWindow()
{
    delete ui;
}

#ifdef Q_WS_X11
extern void qt_x11_apply_settings_in_all_apps();
#endif

void MainWindow::fileSave()
{
    if (! modified) {
        statusBar()->showMessage(tr("No changes to be saved."), 2000);
        return;
    }

    statusBar()->showMessage(tr("Saving changes..."));

    {
        QSettings settings(QLatin1String("Trolltech"));
        settings.beginGroup(QLatin1String("Qt"));
        QFontDatabase db;
        QFont font = db.font(ui->familycombo->currentText(),
                             ui->stylecombo->currentText(),
                             ui->psizecombo->currentText().toInt());

        QStringList actcg, inactcg, discg;
        bool overrideDesktopSettings = (ui->gstylecombo->currentText() != desktopThemeName);
        if (overrideDesktopSettings) {
            int i;
            for (i = 0; i < QPalette::NColorRoles; i++)
                actcg << editPalette.color(QPalette::Active,
                                           QPalette::ColorRole(i)).name();
            for (i = 0; i < QPalette::NColorRoles; i++)
                inactcg << editPalette.color(QPalette::Inactive,
                                             QPalette::ColorRole(i)).name();
            for (i = 0; i < QPalette::NColorRoles; i++)
                discg << editPalette.color(QPalette::Disabled,
                                           QPalette::ColorRole(i)).name();
        }

        settings.setValue(QLatin1String("font"), font.toString());
        settings.setValue(QLatin1String("Palette/active"), actcg);
        settings.setValue(QLatin1String("Palette/inactive"), inactcg);
        settings.setValue(QLatin1String("Palette/disabled"), discg);

        settings.setValue(QLatin1String("fontPath"), fontpaths);
        settings.setValue(QLatin1String("embedFonts"), ui->fontembeddingcheckbox->isChecked());
        settings.setValue(QLatin1String("style"),
                          overrideDesktopSettings ? ui->gstylecombo->currentText() : QString());

        settings.setValue(QLatin1String("doubleClickInterval"), ui->dcispin->value());
        settings.setValue(QLatin1String("cursorFlashTime"),
                          ui->cfispin->value() == 9 ? 0 : ui->cfispin->value());
        settings.setValue(QLatin1String("wheelScrollLines"), ui->wslspin->value());
        settings.setValue(QLatin1String("resolveSymlinks"), ui->resolvelinks->isChecked());

        QSize strut(ui->strutwidth->value(), ui->strutheight->value());
        settings.setValue(QLatin1String("globalStrut/width"), strut.width());
        settings.setValue(QLatin1String("globalStrut/height"), strut.height());

        settings.setValue(QLatin1String("useRtlExtensions"), ui->rtlExtensions->isChecked());

#ifdef Q_WS_X11
        QString style = ui->inputStyle->currentText();
        QString str = QLatin1String("On The Spot");
        if (style == tr("Over The Spot"))
            str = QLatin1String("Over The Spot");
        else if (style == tr("Off The Spot"))
            str = QLatin1String("Off The Spot");
        else if (style == tr("Root"))
            str = QLatin1String("Root");
        settings.setValue(QLatin1String("XIMInputStyle"), str);
#endif
#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
        settings.setValue(QLatin1String("DefaultInputMethod"), ui->inputMethod->currentText());
#endif

        QString audioSink = settings.value(QLatin1String("audiosink"), QLatin1String("Auto")).toString();
        QString videoMode = settings.value(QLatin1String("videomode"), QLatin1String("Auto")).toString();
        settings.setValue(QLatin1String("audiosink"),
                          ui->audiosinkCombo->itemData(ui->audiosinkCombo->currentIndex()));
        settings.setValue(QLatin1String("videomode"),
                          ui->videomodeCombo->itemData(ui->videomodeCombo->currentIndex()));

        QStringList effects;
        if (ui->effectcheckbox->isChecked()) {
            effects << QLatin1String("general");

            switch (ui->menueffect->currentIndex()) {
            case 1: effects << QLatin1String("animatemenu"); break;
            case 2: effects << QLatin1String("fademenu"); break;
            }

            switch (ui->comboeffect->currentIndex()) {
            case 1: effects << QLatin1String("animatecombo"); break;
            }

            switch (ui->tooltipeffect->currentIndex()) {
            case 1: effects << QLatin1String("animatetooltip"); break;
            case 2: effects << QLatin1String("fadetooltip"); break;
            }

            switch (ui->toolboxeffect->currentIndex()) {
            case 1: effects << QLatin1String("animatetoolbox"); break;
            }
        } else
            effects << QLatin1String("none");
        settings.setValue(QLatin1String("GUIEffects"), effects);

        QStringList familysubs = QFont::substitutions();
        QStringList::Iterator fit = familysubs.begin();
        settings.beginGroup(QLatin1String("Font Substitutions"));
        while (fit != familysubs.end()) {
            QStringList subs = QFont::substitutes(*fit);
            settings.setValue(*fit, subs);
            fit++;
        }
        settings.endGroup(); // Font Substitutions
        settings.endGroup(); // Qt
    }

#if defined(Q_WS_X11)
    qt_x11_apply_settings_in_all_apps();
#endif // Q_WS_X11

    setModified(false);
    statusBar()->showMessage(tr("Saved changes."));
}

void MainWindow::fileExit()
{
    qApp->closeAllWindows();
}

void MainWindow::setModified(bool m)
{
    if (modified == m)
        return;

    modified = m;
    ui->fileSaveAction->setEnabled(m);
}

void MainWindow::buildPalette()
{
    QPalette temp(ui->buttonMainColor->color(), ui->buttonWindowColor->color());
    for (int i = 0; i < QPalette::NColorGroups; i++)
        temp = PaletteEditorAdvanced::buildEffect(QPalette::ColorGroup(i), temp);

    editPalette = temp;
    setPreviewPalette(editPalette);
    updateColorButtons();

    setModified(true);
}

void MainWindow::setPreviewPalette(const QPalette &pal)
{
    QPalette::ColorGroup colorGroup = groupFromIndex(ui->paletteCombo->currentIndex());

    for (int i = 0; i < QPalette::NColorGroups; i++) {
        for (int j = 0; j < QPalette::NColorRoles; j++) {
            QPalette::ColorGroup targetGroup = QPalette::ColorGroup(i);
            QPalette::ColorRole targetRole = QPalette::ColorRole(j);
            previewPalette.setColor(targetGroup, targetRole, pal.color(colorGroup, targetRole));
        }
    }

    ui->previewFrame->setPreviewPalette(previewPalette);
}

void MainWindow::updateColorButtons()
{
    ui->buttonMainColor->setColor(editPalette.color(QPalette::Active, QPalette::Button));
    ui->buttonWindowColor->setColor(editPalette.color(QPalette::Active, QPalette::Window));
}

void MainWindow::tunePalette()
{
    bool ok;
    QPalette pal = PaletteEditorAdvanced::getPalette(&ok, editPalette,
                                                     backgroundRole(), this);
    if (!ok)
        return;

    editPalette = pal;
    setPreviewPalette(editPalette);
    setModified(true);
}

void MainWindow::paletteSelected(int)
{
    setPreviewPalette(editPalette);
}

void MainWindow::updateStyleLayout()
{
    QString currentStyle = ui->gstylecombo->currentText();
    bool autoStyle = (currentStyle == desktopThemeName);
    ui->previewFrame->setPreviewVisible(!autoStyle);
    ui->groupAutoPalette->setEnabled(currentStyle.toLower() != QLatin1String("gtk") && !autoStyle);
}

void MainWindow::styleSelected(const QString &stylename)
{
    QStyle *style = 0;
    if (stylename == desktopThemeName) {
        setModified(true);
    } else {
        style = QStyleFactory::create(stylename);
        if (!style)
            return;
        setStyleHelper(ui->previewFrame, style);
        delete previewstyle;
        previewstyle = style;
        setModified(true);
    }
    updateStyleLayout();
}

void MainWindow::familySelected(const QString &family)
{
    QFontDatabase db;
    QStringList styles = db.styles(family);
    ui->stylecombo->clear();
    ui->stylecombo->addItems(styles);
    ui->familysubcombo->addItem(family);
    buildFont();
}

void MainWindow::buildFont()
{
    QFontDatabase db;
    QFont font = db.font(ui->familycombo->currentText(),
                         ui->stylecombo->currentText(),
                         ui->psizecombo->currentText().toInt());
    ui->samplelineedit->setFont(font);
    setModified(true);
}

void MainWindow::substituteSelected(const QString &family)
{
    QStringList subs = QFont::substitutes(family);
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);
}

void MainWindow::removeSubstitute()
{
    if (!ui->sublistbox->currentItem())
        return;

    int row = ui->sublistbox->currentRow();
    QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
    subs.removeAt(ui->sublistbox->currentRow());
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);
    if (row > ui->sublistbox->count())
        row = ui->sublistbox->count() - 1;
    ui->sublistbox->setCurrentRow(row);
    QFont::removeSubstitution(ui->familysubcombo->currentText());
    QFont::insertSubstitutions(ui->familysubcombo->currentText(), subs);
    setModified(true);
}

void MainWindow::addSubstitute()
{
    if (!ui->sublistbox->currentItem()) {
        QFont::insertSubstitution(ui->familysubcombo->currentText(),
                                  ui->choosesubcombo->currentText());
        QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
        ui->sublistbox->clear();
        ui->sublistbox->insertItems(0, subs);
        setModified(true);
        return;
    }

    int row = ui->sublistbox->currentRow();
    QFont::insertSubstitution(ui->familysubcombo->currentText(), ui->choosesubcombo->currentText());
    QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);
    ui->sublistbox->setCurrentRow(row);
    setModified(true);
}

void MainWindow::downSubstitute()
{
    if (!ui->sublistbox->currentItem() || ui->sublistbox->currentRow() >= ui->sublistbox->count())
        return;

    int row = ui->sublistbox->currentRow();
    QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
    QString fam = subs.at(row);
    subs.removeAt(row);
    subs.insert(row + 1, fam);
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);
    ui->sublistbox->setCurrentRow(row + 1);
    QFont::removeSubstitution(ui->familysubcombo->currentText());
    QFont::insertSubstitutions(ui->familysubcombo->currentText(), subs);
    setModified(true);
}

void MainWindow::upSubstitute()
{
    if (!ui->sublistbox->currentItem() || ui->sublistbox->currentRow() < 1)
        return;

    int row = ui->sublistbox->currentRow();
    QStringList subs = QFont::substitutes(ui->familysubcombo->currentText());
    QString fam = subs.at(row);
    subs.removeAt(row);
    subs.insert(row-1, fam);
    ui->sublistbox->clear();
    ui->sublistbox->insertItems(0, subs);
    ui->sublistbox->setCurrentRow(row - 1);
    QFont::removeSubstitution(ui->familysubcombo->currentText());
    QFont::insertSubstitutions(ui->familysubcombo->currentText(), subs);
    setModified(true);
}

void MainWindow::removeFontpath()
{
    if (!ui->fontpathlistbox->currentItem())
        return;

    int row = ui->fontpathlistbox->currentRow();
    fontpaths.removeAt(row);
    ui->fontpathlistbox->clear();
    ui->fontpathlistbox->insertItems(0, fontpaths);
    if (row > ui->fontpathlistbox->count())
        row = ui->fontpathlistbox->count() - 1;
    ui->fontpathlistbox->setCurrentRow(row);
    setModified(true);
}

void MainWindow::addFontpath()
{
    if (ui->fontpathlineedit->text().isEmpty())
        return;

    if (!ui->fontpathlistbox->currentItem()) {
        fontpaths.append(ui->fontpathlineedit->text());
        ui->fontpathlistbox->clear();
        ui->fontpathlistbox->insertItems(0, fontpaths);
        setModified(true);

        return;
    }

    int row = ui->fontpathlistbox->currentRow();
    fontpaths.insert(row + 1, ui->fontpathlineedit->text());
    ui->fontpathlistbox->clear();
    ui->fontpathlistbox->insertItems(0, fontpaths);
    ui->fontpathlistbox->setCurrentRow(row);
    setModified(true);
}

void MainWindow::downFontpath()
{
    if (!ui->fontpathlistbox->currentItem()
        || ui->fontpathlistbox->currentRow() >= (ui->fontpathlistbox->count() - 1)) {
        return;
    }

    int row = ui->fontpathlistbox->currentRow();
    QString fam = fontpaths.at(row);
    fontpaths.removeAt(row);
    fontpaths.insert(row + 1, fam);
    ui->fontpathlistbox->clear();
    ui->fontpathlistbox->insertItems(0, fontpaths);
    ui->fontpathlistbox->setCurrentRow(row + 1);
    setModified(true);
}

void MainWindow::upFontpath()
{
    if (!ui->fontpathlistbox->currentItem() || ui->fontpathlistbox->currentRow() < 1)
        return;

    int row = ui->fontpathlistbox->currentRow();
    QString fam = fontpaths.at(row);
    fontpaths.removeAt(row);
    fontpaths.insert(row - 1, fam);
    ui->fontpathlistbox->clear();
    ui->fontpathlistbox->insertItems(0, fontpaths);
    ui->fontpathlistbox->setCurrentRow(row - 1);
    setModified(true);
}

void MainWindow::browseFontpath()
{
    QString dirname = QFileDialog::getExistingDirectory(this, tr("Select a Directory"));
    if (dirname.isNull())
        return;

   ui->fontpathlineedit->setText(dirname);
}

void MainWindow::somethingModified()
{
    setModified(true);
}

void MainWindow::helpAbout()
{
    QMessageBox box(this);
    box.setText(tr("<h3>%1</h3>"
                   "<br/>Version %2"
                   "<br/><br/>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).")
                   .arg(tr("Qt Configuration")).arg(QLatin1String(QT_VERSION_STR)));
    box.setWindowTitle(tr("Qt Configuration"));
    box.setIcon(QMessageBox::NoIcon);
    box.exec();
}

void MainWindow::helpAboutQt()
{
    QMessageBox::aboutQt(this, tr("Qt Configuration"));
}

void MainWindow::pageChanged(QWidget *page)
{
    if (page == ui->tab)
        ui->helpview->setText(tr(interface_text));
    else if (page == ui->tab1)
        ui->helpview->setText(tr(appearance_text));
    else if (page == ui->tab2)
        ui->helpview->setText(tr(font_text));
    else if (page == ui->tab3)
        ui->helpview->setText(tr(printer_text));
    else if (page == ui->tab4)
        ui->helpview->setText(tr(phonon_text));
}

void MainWindow::closeEvent(QCloseEvent *e)
{
    if (modified) {
        switch (QMessageBox::warning(this, tr("Save Changes"),
                                     tr("Save changes to settings?"),
                                     (QMessageBox::Yes | QMessageBox::No
                                     | QMessageBox::Cancel))) {
        case QMessageBox::Yes: // save
            qApp->processEvents();
            fileSave();

            // fall through intended
        case QMessageBox::No: // don't save
            e->accept();
            break;

        case QMessageBox::Cancel: // cancel
            e->ignore();
            break;

        default: break;
        }
    } else
        e->accept();
}

QT_END_NAMESPACE