~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/qtconfig/mainwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the qtconfig application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "mainwindow.h"
 
30
#include "colorbutton.h"
 
31
#include "previewframe.h"
 
32
#include "paletteeditoradvanced.h"
 
33
 
 
34
#include <qlabel.h>
 
35
#include <qapplication.h>
 
36
#include <qcombobox.h>
 
37
#include <qstylefactory.h>
 
38
#include <qfontdatabase.h>
 
39
#include <qlineedit.h>
 
40
#include <qspinbox.h>
 
41
#include <qcheckbox.h>
 
42
#include <qfiledialog.h>
 
43
#include <qaction.h>
 
44
#include <qstatusbar.h>
 
45
#include <qsettings.h>
 
46
#include <qmessagebox.h>
 
47
#include <qstyle.h>
 
48
#include <qevent.h>
 
49
#include <q3valuelist.h>
 
50
#include <qdebug.h>
 
51
 
 
52
#include <stdlib.h>
 
53
 
 
54
 
 
55
// from qapplication.cpp and qapplication_x11.cpp - These are NOT for
 
56
// external use ignore them
 
57
// extern bool Q_CORE_EXPORT qt_resolve_symlinks;
 
58
 
 
59
 
 
60
static const char *appearance_text =
 
61
"<p><b><font size+=2>Appearance</font></b></p>"
 
62
"<hr>"
 
63
"<p>Use this tab to customize the appearance of your Qt applications.</p>"
 
64
"<p>You can select the default GUI Style from the drop down list and "
 
65
"customize the colors.</p>"
 
66
"<p>Any GUI Style plugins in your plugin path will automatically be added "
 
67
"to the list of built-in Qt styles. (See the Library Paths tab for "
 
68
"information on adding new plugin paths.)</p>"
 
69
"<p>When you choose 3-D Effects and Background colors, the Qt Configuration "
 
70
"program will automatically generate a palette for you.  To customize "
 
71
"colors further, press the Tune Palette button to open the advanced "
 
72
"palette editor."
 
73
"<p>The Preview Window shows what the selected Style and colors look "
 
74
"like.";
 
75
 
 
76
static const char *font_text =
 
77
"<p><b><font size+=2>Fonts</font></b></p>"
 
78
"<hr>"
 
79
"<p>Use this tab to select the default font for your Qt applications. "
 
80
"The selected font is shown (initially as 'Sample Text') in the line "
 
81
"edit below the Family, "
 
82
"Style and Point Size drop down lists.</p>"
 
83
"<p>Qt has a powerful font substitution feature that allows you to "
 
84
"specify a list of substitute fonts.  Substitute fonts are used "
 
85
"when a font cannot be loaded, or if the specified font doesn't have "
 
86
"a particular character."
 
87
"<p>For example, if you select the font Lucida, which doesn't have Korean "
 
88
"characters, but need to show some Korean text using the Mincho font family "
 
89
"you can do so by adding Mincho to the list. Once Mincho is added, any "
 
90
"Korean characters that are not found in the Lucida font will be taken "
 
91
"from the Mincho font.  Because the font substitutions are "
 
92
"lists, you can also select multiple families, such as Song Ti (for "
 
93
"use with Chinese text).";
 
94
 
 
95
static const char *interface_text =
 
96
"<p><b><font size+=2>Interface</font></b></p>"
 
97
"<hr>"
 
98
"<p>Use this tab to customize the feel of your Qt applications.</p>"
 
99
"<p>If the Resolve Symlinks checkbox is checked Qt will follow symlinks "
 
100
"when handling URLs. For example, in the file dialog, if this setting is turned "
 
101
"on and /usr/tmp is a symlink to /var/tmp, entering the /usr/tmp directory "
 
102
"will cause the file dialog to change to /var/tmp.  With this setting turned "
 
103
"off, symlinks are not resolved or followed.</p>"
 
104
"<p>The Global Strut setting is useful for people who require a "
 
105
"minimum size for all widgets (e.g. when using a touch panel or for users "
 
106
"who are visually impaired).  Leaving the Global Strut width and height "
 
107
"at 0 will disable the Global Strut feature</p>"
 
108
"<p>XIM (Extended Input Methods) are used for entering characters in "
 
109
"languages that have large character sets, for example, Chinese and "
 
110
"Japanese.";
 
111
// ### What does the 'Enhanced support for languages written R2L do?
 
112
 
 
113
static const char *printer_text =
 
114
"<p><b><font size+=2>Printer</font></b></p>"
 
115
"<hr>"
 
116
"<p>Use this tab to configure the way Qt generates output for the printer."
 
117
"You can specify if Qt should try to embed fonts into its generated output."
 
118
"If you enable font embedding, the resulting postscript will be more "
 
119
"portable and will more accurately reflect the "
 
120
"visual output on the screen; however the resulting postscript file "
 
121
"size will be bigger."
 
122
"<p>When using font embedding you can select additional directories where "
 
123
"Qt should search for embeddable font files.  By default, the X "
 
124
"server font path is used.";
 
125
 
 
126
static const char *about_text =
 
127
"<p><b><font size=+2>Qt Configuration</font></b></p>"
 
128
"<p>A graphical configuration tool for programs using Qt</p>"
 
129
"<p>Version 1.0</p>"
 
130
"<p>Copyright (C) 2001-2005 Trolltech AS. All rights reserved.</p>"
 
131
"<p></p>"
 
132
"<p>This program is licensed to you under the terms of the GNU General "
 
133
"Public License Version 2 as published by the Free Software Foundation. This "
 
134
"gives you legal permission to copy, distribute and/or modify this software "
 
135
"under certain conditions. For details, see the file 'LICENSE.GPL' that came with "
 
136
"this software distribution. If you did not get the file, send email to "
 
137
"info@trolltech.com.</p>\n\n<p>The program is provided AS IS with NO WARRANTY "
 
138
"OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
 
139
"FOR A PARTICULAR PURPOSE.</p>";
 
140
 
 
141
 
 
142
static QColorGroup::ColorRole centralFromItem( int item )
 
143
{
 
144
    switch( item ) {
 
145
    case 0:  return QColorGroup::Background;
 
146
    case 1:  return QColorGroup::Foreground;
 
147
    case 2:  return QColorGroup::Button;
 
148
    case 3:  return QColorGroup::Base;
 
149
    case 4:  return QColorGroup::Text;
 
150
    case 5:  return QColorGroup::BrightText;
 
151
    case 6:  return QColorGroup::ButtonText;
 
152
    case 7:  return QColorGroup::Highlight;
 
153
    case 8:  return QColorGroup::HighlightedText;
 
154
    default: return QColorGroup::NColorRoles;
 
155
    }
 
156
}
 
157
 
 
158
 
 
159
static QColorGroup::ColorRole effectFromItem( int item )
 
160
{
 
161
    switch( item ) {
 
162
    case 0:  return QColorGroup::Light;
 
163
    case 1:  return QColorGroup::Midlight;
 
164
    case 2:  return QColorGroup::Mid;
 
165
    case 3:  return QColorGroup::Dark;
 
166
    case 4:  return QColorGroup::Shadow;
 
167
    default: return QColorGroup::NColorRoles;
 
168
    }
 
169
}
 
170
 
 
171
 
 
172
static void setStyleHelper(QWidget *w, QStyle *s)
 
173
{
 
174
    w->setStyle(s);
 
175
 
 
176
    const QObjectList children = w->children();
 
177
    for (int i = 0; i < children.size(); ++i) {
 
178
        QObject *child = children.at(i);
 
179
        if (child->isWidgetType())
 
180
            setStyleHelper((QWidget *) child, s);
 
181
    }
 
182
}
 
183
 
 
184
 
 
185
MainWindow::MainWindow()
 
186
    : MainWindowBase(0, "main window"),
 
187
      editPalette(palette()), previewPalette(palette()), previewstyle(0)
 
188
{
 
189
    modified = true;
 
190
 
 
191
    QStringList gstyles = QStyleFactory::keys();
 
192
    gstyles.sort();
 
193
    gstylecombo->insertStringList(gstyles);
 
194
 
 
195
    QSettings settings("Trolltech");
 
196
    settings.beginGroup("Qt");
 
197
 
 
198
    QString currentstyle = settings.value("style").toString();
 
199
    if (currentstyle.isNull())
 
200
        currentstyle = QApplication::style()->className();
 
201
    {
 
202
        int s = 0;
 
203
        QStringList::Iterator git = gstyles.begin();
 
204
        while (git != gstyles.end()) {
 
205
            if (*git == currentstyle)
 
206
                break;
 
207
            s++;
 
208
            git++;
 
209
        }
 
210
 
 
211
        if (s < gstylecombo->count()) {
 
212
            gstylecombo->setCurrentItem(s);
 
213
        } else {
 
214
            // no predefined style, try to find the closest match
 
215
            // class names usually contain the name of the style, so we
 
216
            // iterate over the items in the combobox, and use the one whose
 
217
            // name is contained in the classname of the style
 
218
            s = 0;
 
219
            git = gstyles.begin();
 
220
            while (git != gstyles.end()) {
 
221
                if (currentstyle.contains(*git))
 
222
                    break;
 
223
                s++;
 
224
                git++;
 
225
            }
 
226
 
 
227
            if (s < gstylecombo->count()) {
 
228
                gstylecombo->setCurrentItem(s);
 
229
            } else {
 
230
                // we give up
 
231
                gstylecombo->insertItem("Unknown");
 
232
                gstylecombo->setCurrentItem(gstylecombo->count() - 1);
 
233
            }
 
234
        }
 
235
    }
 
236
 
 
237
    buttonMainColor->setColor(palette().color(QPalette::Active,
 
238
                                              QColorGroup::Button));
 
239
    buttonMainColor2->setColor(palette().color(QPalette::Active,
 
240
                                               QColorGroup::Background));
 
241
    connect(buttonMainColor, SIGNAL(colorChanged(QColor)),
 
242
                this, SLOT(buildPalette()));
 
243
    connect(buttonMainColor2, SIGNAL(colorChanged(QColor)),
 
244
                this, SLOT(buildPalette()));
 
245
 
 
246
    QFontDatabase db;
 
247
    QStringList families = db.families();
 
248
    familycombo->insertStringList(families);
 
249
 
 
250
    QStringList fs = families;
 
251
    QStringList fs2 = QFont::substitutions();
 
252
    QStringList::Iterator fsit = fs2.begin();
 
253
    while (fsit != fs2.end()) {
 
254
        if (! fs.contains(*fsit))
 
255
            fs += *fsit;
 
256
        fsit++;
 
257
    }
 
258
    fs.sort();
 
259
    familysubcombo->insertStringList(fs);
 
260
 
 
261
    choosesubcombo->insertStringList(families);
 
262
    Q3ValueList<int> sizes = db.standardSizes();
 
263
    Q3ValueList<int>::Iterator it = sizes.begin();
 
264
    while (it != sizes.end())
 
265
        psizecombo->insertItem(QString::number(*it++));
 
266
 
 
267
    dcispin->setValue(QApplication::doubleClickInterval());
 
268
    cfispin->setValue(QApplication::cursorFlashTime());
 
269
    wslspin->setValue(QApplication::wheelScrollLines());
 
270
    // #############
 
271
//    resolvelinks->setChecked(qt_resolve_symlinks);
 
272
 
 
273
    effectcheckbox->setChecked(QApplication::isEffectEnabled(Qt::UI_General));
 
274
    effectbase->setEnabled(effectcheckbox->isChecked());
 
275
 
 
276
    if (QApplication::isEffectEnabled(Qt::UI_FadeMenu))
 
277
        menueffect->setCurrentItem(2);
 
278
    else if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu))
 
279
        menueffect->setCurrentItem(1);
 
280
 
 
281
    if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo))
 
282
        comboeffect->setCurrentItem(1);
 
283
 
 
284
    if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
 
285
        tooltipeffect->setCurrentItem(2);
 
286
    else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
 
287
        tooltipeffect->setCurrentItem(1);
 
288
 
 
289
    if ( QApplication::isEffectEnabled( Qt::UI_AnimateToolBox ) )
 
290
        toolboxeffect->setCurrentItem( 1 );
 
291
 
 
292
    QSize globalStrut = QApplication::globalStrut();
 
293
    strutwidth->setValue(globalStrut.width());
 
294
    strutheight->setValue(globalStrut.height());
 
295
 
 
296
    // find the default family
 
297
    QStringList::Iterator sit = families.begin();
 
298
    int i = 0, possible = -1;
 
299
    while (sit != families.end()) {
 
300
        if (*sit == QApplication::font().family())
 
301
            break;
 
302
        if ((*sit).contains(QApplication::font().family()))
 
303
            possible = i;
 
304
 
 
305
        i++;
 
306
        sit++;
 
307
    }
 
308
    if (sit == families.end())
 
309
        i = possible;
 
310
    if (i == -1) // no clue about the current font
 
311
        i = 0;
 
312
 
 
313
    familycombo->setCurrentItem(i);
 
314
 
 
315
    QStringList styles = db.styles(familycombo->currentText());
 
316
    stylecombo->insertStringList(styles);
 
317
 
 
318
    QString stylestring = db.styleString(QApplication::font());
 
319
    sit = styles.begin();
 
320
    i = 0;
 
321
    possible = -1;
 
322
    while (sit != styles.end()) {
 
323
        if (*sit == stylestring)
 
324
            break;
 
325
        if ((*sit).contains(stylestring))
 
326
            possible = i;
 
327
 
 
328
        i++;
 
329
        sit++;
 
330
    }
 
331
    if (sit == styles.end())
 
332
        i = possible;
 
333
    if (i == -1) // no clue about the current font
 
334
        i = 0;
 
335
    stylecombo->setCurrentItem(i);
 
336
 
 
337
    i = 0;
 
338
    while (i < psizecombo->count()) {
 
339
        if (psizecombo->text(i) == QString::number(QApplication::font().pointSize())) {
 
340
            psizecombo->setCurrentItem(i);
 
341
            break;
 
342
        }
 
343
 
 
344
        i++;
 
345
    }
 
346
 
 
347
    QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
348
    sublistbox->clear();
 
349
    sublistbox->insertStringList(subs);
 
350
 
 
351
    rtlExtensions->setChecked(settings.value("useRtlExtensions", false).toBool());
 
352
 
 
353
#ifdef Q_WS_X11
 
354
    inputStyle->setCurrentText(settings.value("XIMInputStyle", trUtf8("On The Spot")).toString());
 
355
#else
 
356
    inputStyle->hide();
 
357
    inputStyleLabel->hide();
 
358
#endif
 
359
 
 
360
    fontembeddingcheckbox->setChecked(settings.value("embedFonts", true).toBool());
 
361
    fontpaths = settings.value("fontPath").toStringList();
 
362
    fontpathlistbox->insertStringList(fontpaths);
 
363
 
 
364
    settings.endGroup(); // Qt
 
365
 
 
366
    setModified(false);
 
367
}
 
368
 
 
369
 
 
370
MainWindow::~MainWindow()
 
371
{
 
372
}
 
373
 
 
374
 
 
375
void MainWindow::fileSave()
 
376
{
 
377
    if (! modified) {
 
378
        statusBar()->showMessage("No changes to be saved.", 2000);
 
379
        return;
 
380
    }
 
381
 
 
382
    statusBar()->showMessage("Saving changes...");
 
383
 
 
384
    {
 
385
        QSettings settings("Trolltech");
 
386
        settings.beginGroup("Qt");
 
387
        QFontDatabase db;
 
388
        QFont font = db.font(familycombo->currentText(),
 
389
                             stylecombo->currentText(),
 
390
                             psizecombo->currentText().toInt());
 
391
 
 
392
        QStringList actcg, inactcg, discg;
 
393
        int i;
 
394
        for (i = 0; i < QColorGroup::NColorRoles; i++)
 
395
            actcg << editPalette.color(QPalette::Active,
 
396
                                       (QColorGroup::ColorRole) i).name();
 
397
        for (i = 0; i < QColorGroup::NColorRoles; i++)
 
398
            inactcg << editPalette.color(QPalette::Inactive,
 
399
                                         (QColorGroup::ColorRole) i).name();
 
400
        for (i = 0; i < QColorGroup::NColorRoles; i++)
 
401
            discg << editPalette.color(QPalette::Disabled,
 
402
                                       (QColorGroup::ColorRole) i).name();
 
403
 
 
404
        settings.setValue("font", font.toString());
 
405
        settings.setValue("Palette/active", actcg);
 
406
        settings.setValue("Palette/inactive", inactcg);
 
407
        settings.setValue("Palette/disabled", discg);
 
408
 
 
409
        settings.setValue("fontPath", fontpaths);
 
410
        settings.setValue("embedFonts", fontembeddingcheckbox->isChecked());
 
411
        settings.setValue("style", gstylecombo->currentText());
 
412
        settings.setValue("doubleClickInterval", dcispin->value());
 
413
        settings.setValue("cursorFlashTime", cfispin->value() == 9 ? 0 : cfispin->value() );
 
414
        settings.setValue("wheelScrollLines", wslspin->value());
 
415
        settings.setValue("resolveSymlinks", resolvelinks->isChecked());
 
416
 
 
417
        QSize strut(strutwidth->value(), strutheight->value());
 
418
        settings.setValue("globalStrut/width", strut.width());
 
419
        settings.setValue("globalStrut/height", strut.height());
 
420
 
 
421
        settings.setValue("useRtlExtensions", rtlExtensions->isChecked());
 
422
 
 
423
#ifdef Q_WS_X11
 
424
        QString style = inputStyle->currentText();
 
425
        QString str = "On The Spot";
 
426
        if ( style == trUtf8( "Over The Spot" ) )
 
427
            str = "Over The Spot";
 
428
        else if ( style == trUtf8( "Off The Spot" ) )
 
429
            str = "Off The Spot";
 
430
        else if ( style == trUtf8( "Root" ) )
 
431
            str = "Root";
 
432
        settings.setValue( "XIMInputStyle", str );
 
433
#endif
 
434
 
 
435
        QStringList effects;
 
436
        if (effectcheckbox->isChecked()) {
 
437
            effects << "general";
 
438
 
 
439
            switch (menueffect->currentItem()) {
 
440
            case 1: effects << "animatemenu"; break;
 
441
            case 2: effects << "fademenu"; break;
 
442
            }
 
443
 
 
444
            switch (comboeffect->currentItem()) {
 
445
            case 1: effects << "animatecombo"; break;
 
446
            }
 
447
 
 
448
            switch (tooltipeffect->currentItem()) {
 
449
            case 1: effects << "animatetooltip"; break;
 
450
            case 2: effects << "fadetooltip"; break;
 
451
            }
 
452
 
 
453
            switch ( toolboxeffect->currentItem() ) {
 
454
            case 1: effects << "animatetoolbox"; break;
 
455
            }
 
456
        } else
 
457
            effects << "none";
 
458
        settings.setValue("GUIEffects", effects);
 
459
 
 
460
        QStringList familysubs = QFont::substitutions();
 
461
        QStringList::Iterator fit = familysubs.begin();
 
462
        settings.beginGroup("Font Substitutions");
 
463
        while (fit != familysubs.end()) {
 
464
            QStringList subs = QFont::substitutes(*fit);
 
465
            settings.setValue(*fit, subs);
 
466
            fit++;
 
467
        }
 
468
        settings.endGroup(); // Font Substitutions
 
469
        settings.endGroup(); // Qt
 
470
    }
 
471
 
 
472
#if defined(Q_WS_X11)
 
473
    // ###### use _QT_SETTINGS_TIMESTAMP_
 
474
//    QApplication::x11_apply_settings();
 
475
#endif // Q_WS_X11
 
476
 
 
477
    setModified(false);
 
478
    statusBar()->showMessage("Saved changes.");
 
479
}
 
480
 
 
481
 
 
482
void MainWindow::fileExit()
 
483
{
 
484
    qApp->closeAllWindows();
 
485
}
 
486
 
 
487
 
 
488
void MainWindow::setModified(bool m)
 
489
{
 
490
    if (modified == m)
 
491
        return;
 
492
 
 
493
    modified = m;
 
494
    fileSaveAction->setEnabled(m);
 
495
}
 
496
 
 
497
 
 
498
void MainWindow::buildPalette()
 
499
{
 
500
    int i;
 
501
    QColorGroup cg;
 
502
    QColor btn = buttonMainColor->color();
 
503
    QColor back = buttonMainColor2->color();
 
504
    QPalette automake( btn, back );
 
505
 
 
506
    for (i = 0; i<9; i++)
 
507
        cg.setColor( centralFromItem(i), automake.active().color( centralFromItem(i) ) );
 
508
 
 
509
    editPalette.setActive( cg );
 
510
    buildActiveEffect();
 
511
 
 
512
    cg = editPalette.inactive();
 
513
 
 
514
    QPalette temp( editPalette.active().color( QColorGroup::Button ),
 
515
                   editPalette.active().color( QColorGroup::Background ) );
 
516
 
 
517
    for (i = 0; i<9; i++)
 
518
        cg.setColor( centralFromItem(i), temp.inactive().color( centralFromItem(i) ) );
 
519
 
 
520
    editPalette.setInactive( cg );
 
521
    buildInactiveEffect();
 
522
 
 
523
    cg = editPalette.disabled();
 
524
 
 
525
    for (i = 0; i<9; i++)
 
526
        cg.setColor( centralFromItem(i), temp.disabled().color( centralFromItem(i) ) );
 
527
 
 
528
    editPalette.setDisabled( cg );
 
529
    buildDisabledEffect();
 
530
 
 
531
    updateColorButtons();
 
532
 
 
533
    setModified(true);
 
534
}
 
535
 
 
536
 
 
537
void MainWindow::buildActiveEffect()
 
538
{
 
539
    QColorGroup cg = editPalette.active();
 
540
    QColor btn = cg.color( QColorGroup::Button );
 
541
 
 
542
    QPalette temp( btn, btn );
 
543
 
 
544
    for (int i = 0; i<5; i++)
 
545
        cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
 
546
 
 
547
    editPalette.setActive( cg );
 
548
    setPreviewPalette( editPalette );
 
549
 
 
550
    updateColorButtons();
 
551
}
 
552
 
 
553
 
 
554
void MainWindow::buildInactive()
 
555
{
 
556
    editPalette.setInactive( editPalette.active() );
 
557
    buildInactiveEffect();
 
558
}
 
559
 
 
560
 
 
561
void MainWindow::buildInactiveEffect()
 
562
{
 
563
    QColorGroup cg = editPalette.inactive();
 
564
 
 
565
    QColor light, midlight, mid, dark, shadow;
 
566
    QColor btn = cg.color( QColorGroup::Button );
 
567
 
 
568
    light = btn.light(150);
 
569
    midlight = btn.light(115);
 
570
    mid = btn.dark(150);
 
571
    dark = btn.dark();
 
572
    shadow = Qt::black;
 
573
 
 
574
    cg.setColor( QColorGroup::Light, light );
 
575
    cg.setColor( QColorGroup::Midlight, midlight );
 
576
    cg.setColor( QColorGroup::Mid, mid );
 
577
    cg.setColor( QColorGroup::Dark, dark );
 
578
    cg.setColor( QColorGroup::Shadow, shadow );
 
579
 
 
580
    editPalette.setInactive( cg );
 
581
    setPreviewPalette( editPalette );
 
582
    updateColorButtons();
 
583
}
 
584
 
 
585
 
 
586
void MainWindow::buildDisabled()
 
587
{
 
588
    QColorGroup cg = editPalette.active();
 
589
    cg.setColor( QColorGroup::ButtonText, Qt::darkGray );
 
590
    cg.setColor( QColorGroup::Foreground, Qt::darkGray );
 
591
    cg.setColor( QColorGroup::Text, Qt::darkGray );
 
592
    cg.setColor( QColorGroup::HighlightedText, Qt::darkGray );
 
593
    editPalette.setDisabled( cg );
 
594
 
 
595
    buildDisabledEffect();
 
596
}
 
597
 
 
598
 
 
599
void MainWindow::buildDisabledEffect()
 
600
{
 
601
    QColorGroup cg = editPalette.disabled();
 
602
 
 
603
    QColor light, midlight, mid, dark, shadow;
 
604
    QColor btn = cg.color( QColorGroup::Button );
 
605
 
 
606
    light = btn.light(150);
 
607
    midlight = btn.light(115);
 
608
    mid = btn.dark(150);
 
609
    dark = btn.dark();
 
610
    shadow = Qt::black;
 
611
 
 
612
    cg.setColor( QColorGroup::Light, light );
 
613
    cg.setColor( QColorGroup::Midlight, midlight );
 
614
    cg.setColor( QColorGroup::Mid, mid );
 
615
    cg.setColor( QColorGroup::Dark, dark );
 
616
    cg.setColor( QColorGroup::Shadow, shadow );
 
617
 
 
618
    editPalette.setDisabled( cg );
 
619
    setPreviewPalette( editPalette );
 
620
    updateColorButtons();
 
621
}
 
622
 
 
623
 
 
624
void MainWindow::setPreviewPalette( const QPalette& pal )
 
625
{
 
626
    QColorGroup cg;
 
627
 
 
628
    switch (paletteCombo->currentItem()) {
 
629
    case 0:
 
630
    default:
 
631
        cg = pal.active();
 
632
        break;
 
633
    case 1:
 
634
        cg = pal.inactive();
 
635
        break;
 
636
    case 2:
 
637
        cg = pal.disabled();
 
638
        break;
 
639
    }
 
640
    previewPalette.setActive( cg );
 
641
    previewPalette.setInactive( cg );
 
642
    previewPalette.setDisabled( cg );
 
643
 
 
644
    previewFrame->setPreviewPalette(previewPalette);
 
645
}
 
646
 
 
647
 
 
648
void MainWindow::updateColorButtons()
 
649
{
 
650
    buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ));
 
651
    buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ));
 
652
}
 
653
 
 
654
 
 
655
void MainWindow::tunePalette()
 
656
{
 
657
    bool ok;
 
658
    QPalette pal = PaletteEditorAdvanced::getPalette(&ok, editPalette,
 
659
                                                     backgroundMode(), this);
 
660
    if (! ok)
 
661
        return;
 
662
 
 
663
    editPalette = pal;
 
664
    setPreviewPalette(editPalette);
 
665
    setModified(true);
 
666
}
 
667
 
 
668
 
 
669
void MainWindow::paletteSelected(int)
 
670
{
 
671
    setPreviewPalette(editPalette);
 
672
}
 
673
 
 
674
 
 
675
void MainWindow::styleSelected(const QString &stylename)
 
676
{
 
677
    QStyle *style = QStyleFactory::create(stylename);
 
678
    if (! style)
 
679
        return;
 
680
 
 
681
    setStyleHelper(previewFrame, style);
 
682
    delete previewstyle;
 
683
    previewstyle = style;
 
684
 
 
685
    setModified(true);
 
686
}
 
687
 
 
688
 
 
689
void MainWindow::familySelected(const QString &family)
 
690
{
 
691
    QFontDatabase db;
 
692
    QStringList styles = db.styles(family);
 
693
    stylecombo->clear();
 
694
    stylecombo->insertStringList(styles);
 
695
    familysubcombo->insertItem(family);
 
696
    buildFont();
 
697
}
 
698
 
 
699
 
 
700
void MainWindow::buildFont()
 
701
{
 
702
    QFontDatabase db;
 
703
    QFont font = db.font(familycombo->currentText(),
 
704
                         stylecombo->currentText(),
 
705
                         psizecombo->currentText().toInt());
 
706
    samplelineedit->setFont(font);
 
707
    setModified(true);
 
708
}
 
709
 
 
710
 
 
711
void MainWindow::substituteSelected(const QString &family)
 
712
{
 
713
    QStringList subs = QFont::substitutes(family);
 
714
    sublistbox->clear();
 
715
    sublistbox->insertStringList(subs);
 
716
}
 
717
 
 
718
 
 
719
void MainWindow::removeSubstitute()
 
720
{
 
721
    if (sublistbox->currentItem() < 0 ||
 
722
        uint(sublistbox->currentItem()) > sublistbox->count())
 
723
        return;
 
724
 
 
725
    int item = sublistbox->currentItem();
 
726
    QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
727
    subs.remove(subs.at(sublistbox->currentItem()));
 
728
    sublistbox->clear();
 
729
    sublistbox->insertStringList(subs);
 
730
    if (uint(item) > sublistbox->count())
 
731
        item = int(sublistbox->count()) - 1;
 
732
    sublistbox->setCurrentItem(item);
 
733
    QFont::removeSubstitution(familysubcombo->currentText());
 
734
    QFont::insertSubstitutions(familysubcombo->currentText(), subs);
 
735
    setModified(true);
 
736
}
 
737
 
 
738
 
 
739
void MainWindow::addSubstitute()
 
740
{
 
741
    if (sublistbox->currentItem() < 0 ||
 
742
        uint(sublistbox->currentItem()) > sublistbox->count()) {
 
743
        QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
744
        subs.append(choosesubcombo->currentText());
 
745
        sublistbox->clear();
 
746
        sublistbox->insertStringList(subs);
 
747
        QFont::removeSubstitution(familysubcombo->currentText());
 
748
        QFont::insertSubstitutions(familysubcombo->currentText(), subs);
 
749
        setModified(true);
 
750
 
 
751
        return;
 
752
    }
 
753
 
 
754
    int item = sublistbox->currentItem();
 
755
    QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
756
    subs.insert(sublistbox->currentItem()+1, choosesubcombo->currentText());
 
757
    sublistbox->clear();
 
758
    sublistbox->insertStringList(subs);
 
759
    sublistbox->setCurrentItem(item);
 
760
    QFont::removeSubstitution(familysubcombo->currentText());
 
761
    QFont::insertSubstitutions(familysubcombo->currentText(), subs);
 
762
    setModified(true);
 
763
}
 
764
 
 
765
 
 
766
void MainWindow::downSubstitute()
 
767
{
 
768
    if (sublistbox->currentItem() < 0 ||
 
769
        uint(sublistbox->currentItem()) >= sublistbox->count())
 
770
        return;
 
771
 
 
772
    int item = sublistbox->currentItem();
 
773
    QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
774
    QString fam = subs.at(item);
 
775
    subs.removeAt(item);
 
776
    subs.insert(item+1, fam);
 
777
    sublistbox->clear();
 
778
    sublistbox->insertStringList(subs);
 
779
    sublistbox->setCurrentItem(item + 1);
 
780
    QFont::removeSubstitution(familysubcombo->currentText());
 
781
    QFont::insertSubstitutions(familysubcombo->currentText(), subs);
 
782
    setModified(true);
 
783
}
 
784
 
 
785
 
 
786
void MainWindow::upSubstitute()
 
787
{
 
788
    if (sublistbox->currentItem() < 1)
 
789
        return;
 
790
 
 
791
    int item = sublistbox->currentItem();
 
792
    QStringList subs = QFont::substitutes(familysubcombo->currentText());
 
793
    QString fam = subs.at(item);
 
794
    subs.removeAt(item);
 
795
    subs.insert(item-1, fam);
 
796
    sublistbox->clear();
 
797
    sublistbox->insertStringList(subs);
 
798
    sublistbox->setCurrentItem(item - 1);
 
799
    QFont::removeSubstitution(familysubcombo->currentText());
 
800
    QFont::insertSubstitutions(familysubcombo->currentText(), subs);
 
801
    setModified(true);
 
802
}
 
803
 
 
804
 
 
805
void MainWindow::removeFontpath()
 
806
{
 
807
    if (fontpathlistbox->currentItem() < 0 ||
 
808
        uint(fontpathlistbox->currentItem()) > fontpathlistbox->count())
 
809
        return;
 
810
 
 
811
    int item = fontpathlistbox->currentItem();
 
812
    fontpaths.remove(fontpaths.at(fontpathlistbox->currentItem()));
 
813
    fontpathlistbox->clear();
 
814
    fontpathlistbox->insertStringList(fontpaths);
 
815
    if (uint(item) > fontpathlistbox->count())
 
816
        item = int(fontpathlistbox->count()) - 1;
 
817
    fontpathlistbox->setCurrentItem(item);
 
818
    setModified(true);
 
819
}
 
820
 
 
821
 
 
822
void MainWindow::addFontpath()
 
823
{
 
824
    if (fontpathlineedit->text().isEmpty())
 
825
        return;
 
826
 
 
827
    if (fontpathlistbox->currentItem() < 0 ||
 
828
        uint(fontpathlistbox->currentItem()) > fontpathlistbox->count()) {
 
829
        fontpaths.append(fontpathlineedit->text());
 
830
        fontpathlistbox->clear();
 
831
        fontpathlistbox->insertStringList(fontpaths);
 
832
        setModified(true);
 
833
 
 
834
        return;
 
835
    }
 
836
 
 
837
    int item = fontpathlistbox->currentItem();
 
838
    fontpaths.insert(fontpathlistbox->currentItem()+1,
 
839
                     fontpathlineedit->text());
 
840
    fontpathlistbox->clear();
 
841
    fontpathlistbox->insertStringList(fontpaths);
 
842
    fontpathlistbox->setCurrentItem(item);
 
843
    setModified(true);
 
844
}
 
845
 
 
846
 
 
847
void MainWindow::downFontpath()
 
848
{
 
849
    if (fontpathlistbox->currentItem() < 0 ||
 
850
        uint(fontpathlistbox->currentItem()) >= fontpathlistbox->count() - 1)
 
851
        return;
 
852
 
 
853
    int item = fontpathlistbox->currentItem();
 
854
    QString fam = fontpaths.at(item);
 
855
    fontpaths.removeAt(item);
 
856
    fontpaths.insert(item+1, fam);
 
857
    fontpathlistbox->clear();
 
858
    fontpathlistbox->insertStringList(fontpaths);
 
859
    fontpathlistbox->setCurrentItem(item + 1);
 
860
    setModified(true);
 
861
}
 
862
 
 
863
 
 
864
void MainWindow::upFontpath()
 
865
{
 
866
    if (fontpathlistbox->currentItem() < 1)
 
867
        return;
 
868
 
 
869
    int item = fontpathlistbox->currentItem();
 
870
    QString fam = fontpaths.at(item);
 
871
    fontpaths.removeAt(item);
 
872
    fontpaths.insert(item-1, fam);
 
873
    fontpathlistbox->clear();
 
874
    fontpathlistbox->insertStringList(fontpaths);
 
875
    fontpathlistbox->setCurrentItem(item - 1);
 
876
    setModified(true);
 
877
}
 
878
 
 
879
 
 
880
void MainWindow::browseFontpath()
 
881
{
 
882
    QString dirname = QFileDialog::getExistingDirectory(QString(), this, 0,
 
883
                                                        tr("Select a Directory"));
 
884
    if (dirname.isNull())
 
885
        return;
 
886
 
 
887
   fontpathlineedit->setText(dirname);
 
888
}
 
889
 
 
890
 
 
891
void MainWindow::somethingModified()
 
892
{
 
893
    setModified(true);
 
894
}
 
895
 
 
896
 
 
897
void MainWindow::helpAbout()
 
898
{
 
899
    QMessageBox::about(this, tr("Qt Configuration"),
 
900
                       tr(about_text));
 
901
}
 
902
 
 
903
 
 
904
void MainWindow::helpAboutQt()
 
905
{
 
906
    QMessageBox::aboutQt(this, tr("Qt Configuration"));
 
907
}
 
908
 
 
909
 
 
910
void MainWindow::pageChanged(QWidget *page)
 
911
{
 
912
    if (page == tab)
 
913
        helpview->setText(tr(appearance_text));
 
914
    else if (page == tab1)
 
915
        helpview->setText(tr(font_text));
 
916
    else if (page == tab2)
 
917
        helpview->setText(tr(interface_text));
 
918
    else if (page == tab3)
 
919
        helpview->setText(tr(printer_text));
 
920
}
 
921
 
 
922
 
 
923
void MainWindow::closeEvent(QCloseEvent *e)
 
924
{
 
925
    if (modified) {
 
926
        switch(QMessageBox::warning(this, tr("Save Changes"),
 
927
                                    tr("Save changes to settings?"),
 
928
                                    tr("&Yes"), tr("&No"), tr("&Cancel"), 0, 2)) {
 
929
        case 0: // save
 
930
            qApp->processEvents();
 
931
            fileSave();
 
932
 
 
933
            // fall through intended
 
934
        case 1: // don't save
 
935
            e->accept();
 
936
            break;
 
937
 
 
938
        case 2: // cancel
 
939
            e->ignore();
 
940
            break;
 
941
 
 
942
        default: break;
 
943
        }
 
944
    } else
 
945
        e->accept();
 
946
}