tools/qtconfig/mainwindow.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the tools applications of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #include "mainwindow.h"
00025 #include "colorbutton.h"
00026 #include "previewframe.h"
00027 #include "paletteeditoradvanced.h"
00028 
00029 #include <QLabel>
00030 #include <QApplication>
00031 #include <QComboBox>
00032 #include <QStyleFactory>
00033 #include <QFontDatabase>
00034 #include <QLineEdit>
00035 #include <QSpinBox>
00036 #include <QCheckBox>
00037 #include <QFileDialog>
00038 #include <QAction>
00039 #include <QStatusBar>
00040 #include <QSettings>
00041 #include <QMessageBox>
00042 #include <QStyle>
00043 #include <QtEvents>
00044 #include <Q3ValueList>
00045 #include <QtDebug>
00046 
00047 #include <stdlib.h>
00048 
00049 // from qapplication.cpp and qapplication_x11.cpp - These are NOT for
00050 // external use ignore them
00051 // extern bool Q_CORE_EXPORT qt_resolve_symlinks;
00052 
00053 static const char *appearance_text =
00054 "<p><b><font size+=2>Appearance</font></b></p>"
00055 "<hr>"
00056 "<p>Use this tab to customize the appearance of your Qt applications.</p>"
00057 "<p>You can select the default GUI Style from the drop down list and "
00058 "customize the colors.</p>"
00059 "<p>Any GUI Style plugins in your plugin path will automatically be added "
00060 "to the list of built-in Qt styles. (See the Library Paths tab for "
00061 "information on adding new plugin paths.)</p>"
00062 "<p>When you choose 3-D Effects and Window Background colors, the Qt "
00063 "Configuration program will automatically generate a palette for you. "
00064 "To customize colors further, press the Tune Palette button to open "
00065 "the advanced palette editor."
00066 "<p>The Preview Window shows what the selected Style and colors look "
00067 "like.";
00068 
00069 static const char *font_text =
00070 "<p><b><font size+=2>Fonts</font></b></p>"
00071 "<hr>"
00072 "<p>Use this tab to select the default font for your Qt applications. "
00073 "The selected font is shown (initially as 'Sample Text') in the line "
00074 "edit below the Family, "
00075 "Style and Point Size drop down lists.</p>"
00076 "<p>Qt has a powerful font substitution feature that allows you to "
00077 "specify a list of substitute fonts.  Substitute fonts are used "
00078 "when a font cannot be loaded, or if the specified font doesn't have "
00079 "a particular character."
00080 "<p>For example, if you select the font Lucida, which doesn't have Korean "
00081 "characters, but need to show some Korean text using the Mincho font family "
00082 "you can do so by adding Mincho to the list. Once Mincho is added, any "
00083 "Korean characters that are not found in the Lucida font will be taken "
00084 "from the Mincho font.  Because the font substitutions are "
00085 "lists, you can also select multiple families, such as Song Ti (for "
00086 "use with Chinese text).";
00087 
00088 static const char *interface_text =
00089 "<p><b><font size+=2>Interface</font></b></p>"
00090 "<hr>"
00091 "<p>Use this tab to customize the feel of your Qt applications.</p>"
00092 "<p>If the Resolve Symlinks checkbox is checked Qt will follow symlinks "
00093 "when handling URLs. For example, in the file dialog, if this setting is turned "
00094 "on and /usr/tmp is a symlink to /var/tmp, entering the /usr/tmp directory "
00095 "will cause the file dialog to change to /var/tmp.  With this setting turned "
00096 "off, symlinks are not resolved or followed.</p>"
00097 "<p>The Global Strut setting is useful for people who require a "
00098 "minimum size for all widgets (e.g. when using a touch panel or for users "
00099 "who are visually impaired).  Leaving the Global Strut width and height "
00100 "at 0 will disable the Global Strut feature</p>"
00101 "<p>XIM (Extended Input Methods) are used for entering characters in "
00102 "languages that have large character sets, for example, Chinese and "
00103 "Japanese.";
00104 // ### What does the 'Enhanced support for languages written R2L do?
00105 
00106 static const char *printer_text =
00107 "<p><b><font size+=2>Printer</font></b></p>"
00108 "<hr>"
00109 "<p>Use this tab to configure the way Qt generates output for the printer."
00110 "You can specify if Qt should try to embed fonts into its generated output."
00111 "If you enable font embedding, the resulting postscript will be more "
00112 "portable and will more accurately reflect the "
00113 "visual output on the screen; however the resulting postscript file "
00114 "size will be bigger."
00115 "<p>When using font embedding you can select additional directories where "
00116 "Qt should search for embeddable font files.  By default, the X "
00117 "server font path is used.";
00118 
00119 
00120 static QColorGroup::ColorRole centralFromItem( int item )
00121 {
00122     switch( item ) {
00123     case 0:  return QColorGroup::Window;
00124     case 1:  return QColorGroup::WindowText;
00125     case 2:  return QColorGroup::Button;
00126     case 3:  return QColorGroup::Base;
00127     case 4:  return QColorGroup::Text;
00128     case 5:  return QColorGroup::BrightText;
00129     case 6:  return QColorGroup::ButtonText;
00130     case 7:  return QColorGroup::Highlight;
00131     case 8:  return QColorGroup::HighlightedText;
00132     default: return QColorGroup::NColorRoles;
00133     }
00134 }
00135 
00136 
00137 static QColorGroup::ColorRole effectFromItem( int item )
00138 {
00139     switch( item ) {
00140     case 0:  return QColorGroup::Light;
00141     case 1:  return QColorGroup::Midlight;
00142     case 2:  return QColorGroup::Mid;
00143     case 3:  return QColorGroup::Dark;
00144     case 4:  return QColorGroup::Shadow;
00145     default: return QColorGroup::NColorRoles;
00146     }
00147 }
00148 
00149 
00150 static void setStyleHelper(QWidget *w, QStyle *s)
00151 {
00152     const QObjectList children = w->children();
00153     for (int i = 0; i < children.size(); ++i) {
00154         QObject *child = children.at(i);
00155         if (child->isWidgetType())
00156             setStyleHelper((QWidget *) child, s);
00157     }
00158     w->setStyle(s);
00159 }
00160 
00161 
00162 MainWindow::MainWindow()
00163     : MainWindowBase(0, "main window"),
00164       editPalette(palette()), previewPalette(palette()), previewstyle(0)
00165 {
00166     modified = true;
00167 
00168     QStringList gstyles = QStyleFactory::keys();
00169     gstyles.sort();
00170     gstylecombo->insertStringList(gstyles);
00171 
00172     QSettings settings("Trolltech");
00173     settings.beginGroup("Qt");
00174 
00175     QString currentstyle = settings.value("style").toString();
00176     if (currentstyle.isNull())
00177         currentstyle = QApplication::style()->name();
00178     {
00179         int s = 0;
00180         QStringList::Iterator git = gstyles.begin();
00181         while (git != gstyles.end()) {
00182             if ((*git).lower() == currentstyle.lower())
00183                 break;
00184             s++;
00185             git++;
00186         }
00187 
00188         if (s < gstylecombo->count()) {
00189             gstylecombo->setCurrentItem(s);
00190         } else {
00191             // no predefined style, try to find the closest match
00192             // class names usually contain the name of the style, so we
00193             // iterate over the items in the combobox, and use the one whose
00194             // name is contained in the classname of the style
00195             s = 0;
00196             git = gstyles.begin();
00197             while (git != gstyles.end()) {
00198                 if (currentstyle.contains(*git))
00199                     break;
00200                 s++;
00201                 git++;
00202             }
00203 
00204             if (s < gstylecombo->count()) {
00205                 gstylecombo->setCurrentItem(s);
00206             } else {
00207                 // we give up
00208                 gstylecombo->insertItem("Unknown");
00209                 gstylecombo->setCurrentItem(gstylecombo->count() - 1);
00210             }
00211         }
00212     }
00213 
00214     buttonMainColor->setColor(palette().color(QPalette::Active,
00215                                               QColorGroup::Button));
00216     buttonMainColor2->setColor(palette().color(QPalette::Active,
00217                                                QColorGroup::Window));
00218     connect(buttonMainColor, SIGNAL(colorChanged(QColor)),
00219                 this, SLOT(buildPalette()));
00220     connect(buttonMainColor2, SIGNAL(colorChanged(QColor)),
00221                 this, SLOT(buildPalette()));
00222 
00223     QFontDatabase db;
00224     QStringList families = db.families();
00225     familycombo->insertStringList(families);
00226 
00227     QStringList fs = families;
00228     QStringList fs2 = QFont::substitutions();
00229     QStringList::Iterator fsit = fs2.begin();
00230     while (fsit != fs2.end()) {
00231         if (! fs.contains(*fsit))
00232             fs += *fsit;
00233         fsit++;
00234     }
00235     fs.sort();
00236     familysubcombo->insertStringList(fs);
00237 
00238     choosesubcombo->insertStringList(families);
00239     Q3ValueList<int> sizes = db.standardSizes();
00240     Q3ValueList<int>::Iterator it = sizes.begin();
00241     while (it != sizes.end())
00242         psizecombo->insertItem(QString::number(*it++));
00243 
00244     dcispin->setValue(QApplication::doubleClickInterval());
00245     cfispin->setValue(QApplication::cursorFlashTime());
00246     wslspin->setValue(QApplication::wheelScrollLines());
00247     // #############
00248 //    resolvelinks->setChecked(qt_resolve_symlinks);
00249 
00250     effectcheckbox->setChecked(QApplication::isEffectEnabled(Qt::UI_General));
00251     effectbase->setEnabled(effectcheckbox->isChecked());
00252 
00253     if (QApplication::isEffectEnabled(Qt::UI_FadeMenu))
00254         menueffect->setCurrentItem(2);
00255     else if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu))
00256         menueffect->setCurrentItem(1);
00257 
00258     if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo))
00259         comboeffect->setCurrentItem(1);
00260 
00261     if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
00262         tooltipeffect->setCurrentItem(2);
00263     else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
00264         tooltipeffect->setCurrentItem(1);
00265 
00266     if ( QApplication::isEffectEnabled( Qt::UI_AnimateToolBox ) )
00267         toolboxeffect->setCurrentItem( 1 );
00268 
00269     QSize globalStrut = QApplication::globalStrut();
00270     strutwidth->setValue(globalStrut.width());
00271     strutheight->setValue(globalStrut.height());
00272 
00273     // find the default family
00274     QStringList::Iterator sit = families.begin();
00275     int i = 0, possible = -1;
00276     while (sit != families.end()) {
00277         if (*sit == QApplication::font().family())
00278             break;
00279         if ((*sit).contains(QApplication::font().family()))
00280             possible = i;
00281 
00282         i++;
00283         sit++;
00284     }
00285     if (sit == families.end())
00286         i = possible;
00287     if (i == -1) // no clue about the current font
00288         i = 0;
00289 
00290     familycombo->setCurrentItem(i);
00291 
00292     QStringList styles = db.styles(familycombo->currentText());
00293     stylecombo->insertStringList(styles);
00294 
00295     QString stylestring = db.styleString(QApplication::font());
00296     sit = styles.begin();
00297     i = 0;
00298     possible = -1;
00299     while (sit != styles.end()) {
00300         if (*sit == stylestring)
00301             break;
00302         if ((*sit).contains(stylestring))
00303             possible = i;
00304 
00305         i++;
00306         sit++;
00307     }
00308     if (sit == styles.end())
00309         i = possible;
00310     if (i == -1) // no clue about the current font
00311         i = 0;
00312     stylecombo->setCurrentItem(i);
00313 
00314     i = 0;
00315     for (int psize = QApplication::font().pointSize(); i < psizecombo->count(); ++i) {
00316         const int sz = psizecombo->text(i).toInt();
00317         if (sz == psize) {
00318             psizecombo->setCurrentItem(i);
00319             break;
00320         } else if(sz > psize) {
00321             psizecombo->insertItem(i, QString::number(psize));
00322             psizecombo->setCurrentItem(i);
00323             break;
00324         }
00325     }
00326 
00327     QStringList subs = QFont::substitutes(familysubcombo->currentText());
00328     sublistbox->clear();
00329     sublistbox->insertStringList(subs);
00330 
00331     rtlExtensions->setChecked(settings.value("useRtlExtensions", false).toBool());
00332 
00333 #ifdef Q_WS_X11
00334     inputStyle->setCurrentText(settings.value("XIMInputStyle", trUtf8("On The Spot")).toString());
00335 #else
00336     inputStyle->hide();
00337     inputStyleLabel->hide();
00338 #endif
00339 
00340     fontembeddingcheckbox->setChecked(settings.value("embedFonts", true).toBool());
00341     fontpaths = settings.value("fontPath").toStringList();
00342     fontpathlistbox->insertStringList(fontpaths);
00343 
00344     settings.endGroup(); // Qt
00345 
00346     helpview->setText(tr(appearance_text));
00347 
00348     setModified(false);
00349 }
00350 
00351 
00352 MainWindow::~MainWindow()
00353 {
00354 }
00355 
00356 #ifdef Q_WS_X11
00357 extern void qt_x11_apply_settings_in_all_apps();
00358 #endif
00359 
00360 void MainWindow::fileSave()
00361 {
00362     if (! modified) {
00363         statusBar()->showMessage("No changes to be saved.", 2000);
00364         return;
00365     }
00366 
00367     statusBar()->showMessage("Saving changes...");
00368 
00369     {
00370         QSettings settings("Trolltech");
00371         settings.beginGroup("Qt");
00372         QFontDatabase db;
00373         QFont font = db.font(familycombo->currentText(),
00374                              stylecombo->currentText(),
00375                              psizecombo->currentText().toInt());
00376 
00377         QStringList actcg, inactcg, discg;
00378         int i;
00379         for (i = 0; i < QColorGroup::NColorRoles; i++)
00380             actcg << editPalette.color(QPalette::Active,
00381                                        (QColorGroup::ColorRole) i).name();
00382         for (i = 0; i < QColorGroup::NColorRoles; i++)
00383             inactcg << editPalette.color(QPalette::Inactive,
00384                                          (QColorGroup::ColorRole) i).name();
00385         for (i = 0; i < QColorGroup::NColorRoles; i++)
00386             discg << editPalette.color(QPalette::Disabled,
00387                                        (QColorGroup::ColorRole) i).name();
00388 
00389         settings.setValue("font", font.toString());
00390         settings.setValue("Palette/active", actcg);
00391         settings.setValue("Palette/inactive", inactcg);
00392         settings.setValue("Palette/disabled", discg);
00393 
00394         settings.setValue("fontPath", fontpaths);
00395         settings.setValue("embedFonts", fontembeddingcheckbox->isChecked());
00396         settings.setValue("style", gstylecombo->currentText());
00397         settings.setValue("doubleClickInterval", dcispin->value());
00398         settings.setValue("cursorFlashTime", cfispin->value() == 9 ? 0 : cfispin->value() );
00399         settings.setValue("wheelScrollLines", wslspin->value());
00400         settings.setValue("resolveSymlinks", resolvelinks->isChecked());
00401 
00402         QSize strut(strutwidth->value(), strutheight->value());
00403         settings.setValue("globalStrut/width", strut.width());
00404         settings.setValue("globalStrut/height", strut.height());
00405 
00406         settings.setValue("useRtlExtensions", rtlExtensions->isChecked());
00407 
00408 #ifdef Q_WS_X11
00409         QString style = inputStyle->currentText();
00410         QString str = "On The Spot";
00411         if ( style == trUtf8( "Over The Spot" ) )
00412             str = "Over The Spot";
00413         else if ( style == trUtf8( "Off The Spot" ) )
00414             str = "Off The Spot";
00415         else if ( style == trUtf8( "Root" ) )
00416             str = "Root";
00417         settings.setValue( "XIMInputStyle", str );
00418 #endif
00419 
00420         QStringList effects;
00421         if (effectcheckbox->isChecked()) {
00422             effects << "general";
00423 
00424             switch (menueffect->currentItem()) {
00425             case 1: effects << "animatemenu"; break;
00426             case 2: effects << "fademenu"; break;
00427             }
00428 
00429             switch (comboeffect->currentItem()) {
00430             case 1: effects << "animatecombo"; break;
00431             }
00432 
00433             switch (tooltipeffect->currentItem()) {
00434             case 1: effects << "animatetooltip"; break;
00435             case 2: effects << "fadetooltip"; break;
00436             }
00437 
00438             switch ( toolboxeffect->currentItem() ) {
00439             case 1: effects << "animatetoolbox"; break;
00440             }
00441         } else
00442             effects << "none";
00443         settings.setValue("GUIEffects", effects);
00444 
00445         QStringList familysubs = QFont::substitutions();
00446         QStringList::Iterator fit = familysubs.begin();
00447         settings.beginGroup(QLatin1String("Font Substitutions"));
00448         while (fit != familysubs.end()) {
00449             QStringList subs = QFont::substitutes(*fit);
00450             settings.setValue(*fit, subs);
00451             fit++;
00452         }
00453         settings.endGroup(); // Font Substitutions
00454         settings.endGroup(); // Qt
00455     }
00456 
00457 #if defined(Q_WS_X11)
00458     qt_x11_apply_settings_in_all_apps();
00459 #endif // Q_WS_X11
00460 
00461     setModified(false);
00462     statusBar()->showMessage("Saved changes.");
00463 }
00464 
00465 
00466 void MainWindow::fileExit()
00467 {
00468     qApp->closeAllWindows();
00469 }
00470 
00471 
00472 void MainWindow::setModified(bool m)
00473 {
00474     if (modified == m)
00475         return;
00476 
00477     modified = m;
00478     fileSaveAction->setEnabled(m);
00479 }
00480 
00481 
00482 void MainWindow::buildPalette()
00483 {
00484     int i;
00485     QColorGroup cg;
00486     QColor btn = buttonMainColor->color();
00487     QColor back = buttonMainColor2->color();
00488     QPalette automake( btn, back );
00489 
00490     for (i = 0; i<9; i++)
00491         cg.setColor( centralFromItem(i), automake.active().color( centralFromItem(i) ) );
00492 
00493     editPalette.setActive( cg );
00494     buildActiveEffect();
00495 
00496     cg = editPalette.inactive();
00497 
00498     QPalette temp( editPalette.active().color( QColorGroup::Button ),
00499                    editPalette.active().color( QColorGroup::Window ) );
00500 
00501     for (i = 0; i<9; i++)
00502         cg.setColor( centralFromItem(i), temp.inactive().color( centralFromItem(i) ) );
00503 
00504     editPalette.setInactive( cg );
00505     buildInactiveEffect();
00506 
00507     cg = editPalette.disabled();
00508 
00509     for (i = 0; i<9; i++)
00510         cg.setColor( centralFromItem(i), temp.disabled().color( centralFromItem(i) ) );
00511 
00512     editPalette.setDisabled( cg );
00513     buildDisabledEffect();
00514 
00515     updateColorButtons();
00516 
00517     setModified(true);
00518 }
00519 
00520 
00521 void MainWindow::buildActiveEffect()
00522 {
00523     QColorGroup cg = editPalette.active();
00524     QColor btn = cg.color( QColorGroup::Button );
00525 
00526     QPalette temp( btn, btn );
00527 
00528     for (int i = 0; i<5; i++)
00529         cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
00530 
00531     editPalette.setActive( cg );
00532     setPreviewPalette( editPalette );
00533 
00534     updateColorButtons();
00535 }
00536 
00537 
00538 void MainWindow::buildInactive()
00539 {
00540     editPalette.setInactive( editPalette.active() );
00541     buildInactiveEffect();
00542 }
00543 
00544 
00545 void MainWindow::buildInactiveEffect()
00546 {
00547     QColorGroup cg = editPalette.inactive();
00548 
00549     QColor light, midlight, mid, dark, shadow;
00550     QColor btn = cg.color( QColorGroup::Button );
00551 
00552     light = btn.light(150);
00553     midlight = btn.light(115);
00554     mid = btn.dark(150);
00555     dark = btn.dark();
00556     shadow = Qt::black;
00557 
00558     cg.setColor( QColorGroup::Light, light );
00559     cg.setColor( QColorGroup::Midlight, midlight );
00560     cg.setColor( QColorGroup::Mid, mid );
00561     cg.setColor( QColorGroup::Dark, dark );
00562     cg.setColor( QColorGroup::Shadow, shadow );
00563 
00564     editPalette.setInactive( cg );
00565     setPreviewPalette( editPalette );
00566     updateColorButtons();
00567 }
00568 
00569 
00570 void MainWindow::buildDisabled()
00571 {
00572     QColorGroup cg = editPalette.active();
00573     cg.setColor( QColorGroup::ButtonText, Qt::darkGray );
00574     cg.setColor( QColorGroup::WindowText, Qt::darkGray );
00575     cg.setColor( QColorGroup::Text, Qt::darkGray );
00576     cg.setColor( QColorGroup::HighlightedText, Qt::darkGray );
00577     editPalette.setDisabled( cg );
00578 
00579     buildDisabledEffect();
00580 }
00581 
00582 
00583 void MainWindow::buildDisabledEffect()
00584 {
00585     QColorGroup cg = editPalette.disabled();
00586 
00587     QColor light, midlight, mid, dark, shadow;
00588     QColor btn = cg.color( QColorGroup::Button );
00589 
00590     light = btn.light(150);
00591     midlight = btn.light(115);
00592     mid = btn.dark(150);
00593     dark = btn.dark();
00594     shadow = Qt::black;
00595 
00596     cg.setColor( QColorGroup::Light, light );
00597     cg.setColor( QColorGroup::Midlight, midlight );
00598     cg.setColor( QColorGroup::Mid, mid );
00599     cg.setColor( QColorGroup::Dark, dark );
00600     cg.setColor( QColorGroup::Shadow, shadow );
00601 
00602     editPalette.setDisabled( cg );
00603     setPreviewPalette( editPalette );
00604     updateColorButtons();
00605 }
00606 
00607 
00608 void MainWindow::setPreviewPalette( const QPalette& pal )
00609 {
00610     QColorGroup cg;
00611 
00612     switch (paletteCombo->currentItem()) {
00613     case 0:
00614     default:
00615         cg = pal.active();
00616         break;
00617     case 1:
00618         cg = pal.inactive();
00619         break;
00620     case 2:
00621         cg = pal.disabled();
00622         break;
00623     }
00624     previewPalette.setActive( cg );
00625     previewPalette.setInactive( cg );
00626     previewPalette.setDisabled( cg );
00627 
00628     previewFrame->setPreviewPalette(previewPalette);
00629 }
00630 
00631 
00632 void MainWindow::updateColorButtons()
00633 {
00634     buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ));
00635     buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Window ));
00636 }
00637 
00638 
00639 void MainWindow::tunePalette()
00640 {
00641     bool ok;
00642     QPalette pal = PaletteEditorAdvanced::getPalette(&ok, editPalette,
00643                                                      backgroundMode(), this);
00644     if (! ok)
00645         return;
00646 
00647     editPalette = pal;
00648     setPreviewPalette(editPalette);
00649     setModified(true);
00650 }
00651 
00652 
00653 void MainWindow::paletteSelected(int)
00654 {
00655     setPreviewPalette(editPalette);
00656 }
00657 
00658 
00659 void MainWindow::styleSelected(const QString &stylename)
00660 {
00661     QStyle *style = QStyleFactory::create(stylename);
00662     if (! style)
00663         return;
00664 
00665     setStyleHelper(previewFrame, style);
00666     delete previewstyle;
00667     previewstyle = style;
00668 
00669     setModified(true);
00670 }
00671 
00672 
00673 void MainWindow::familySelected(const QString &family)
00674 {
00675     QFontDatabase db;
00676     QStringList styles = db.styles(family);
00677     stylecombo->clear();
00678     stylecombo->insertStringList(styles);
00679     familysubcombo->insertItem(family);
00680     buildFont();
00681 }
00682 
00683 
00684 void MainWindow::buildFont()
00685 {
00686     QFontDatabase db;
00687     QFont font = db.font(familycombo->currentText(),
00688                          stylecombo->currentText(),
00689                          psizecombo->currentText().toInt());
00690     samplelineedit->setFont(font);
00691     setModified(true);
00692 }
00693 
00694 
00695 void MainWindow::substituteSelected(const QString &family)
00696 {
00697     QStringList subs = QFont::substitutes(family);
00698     sublistbox->clear();
00699     sublistbox->insertStringList(subs);
00700 }
00701 
00702 
00703 void MainWindow::removeSubstitute()
00704 {
00705     if (sublistbox->currentItem() < 0 ||
00706         uint(sublistbox->currentItem()) > sublistbox->count())
00707         return;
00708 
00709     int item = sublistbox->currentItem();
00710     QStringList subs = QFont::substitutes(familysubcombo->currentText());
00711     subs.remove(subs.at(sublistbox->currentItem()));
00712     sublistbox->clear();
00713     sublistbox->insertStringList(subs);
00714     if (uint(item) > sublistbox->count())
00715         item = int(sublistbox->count()) - 1;
00716     sublistbox->setCurrentItem(item);
00717     QFont::removeSubstitution(familysubcombo->currentText());
00718     QFont::insertSubstitutions(familysubcombo->currentText(), subs);
00719     setModified(true);
00720 }
00721 
00722 
00723 void MainWindow::addSubstitute()
00724 {
00725     if (sublistbox->currentItem() < 0 ||
00726         uint(sublistbox->currentItem()) > sublistbox->count()) {
00727         QFont::insertSubstitution(familysubcombo->currentText(), choosesubcombo->currentText());
00728         QStringList subs = QFont::substitutes(familysubcombo->currentText());
00729         sublistbox->clear();
00730         sublistbox->insertStringList(subs);
00731         setModified(true);
00732         return;
00733     }
00734 
00735     int item = sublistbox->currentItem();
00736     QFont::insertSubstitution(familysubcombo->currentText(), choosesubcombo->currentText());
00737     QStringList subs = QFont::substitutes(familysubcombo->currentText());
00738     sublistbox->clear();
00739     sublistbox->insertStringList(subs);
00740     sublistbox->setCurrentItem(item);
00741     setModified(true);
00742 }
00743 
00744 
00745 void MainWindow::downSubstitute()
00746 {
00747     if (sublistbox->currentItem() < 0 ||
00748         uint(sublistbox->currentItem()) >= sublistbox->count())
00749         return;
00750 
00751     int item = sublistbox->currentItem();
00752     QStringList subs = QFont::substitutes(familysubcombo->currentText());
00753     QString fam = subs.at(item);
00754     subs.removeAt(item);
00755     subs.insert(item+1, fam);
00756     sublistbox->clear();
00757     sublistbox->insertStringList(subs);
00758     sublistbox->setCurrentItem(item + 1);
00759     QFont::removeSubstitution(familysubcombo->currentText());
00760     QFont::insertSubstitutions(familysubcombo->currentText(), subs);
00761     setModified(true);
00762 }
00763 
00764 
00765 void MainWindow::upSubstitute()
00766 {
00767     if (sublistbox->currentItem() < 1)
00768         return;
00769 
00770     int item = sublistbox->currentItem();
00771     QStringList subs = QFont::substitutes(familysubcombo->currentText());
00772     QString fam = subs.at(item);
00773     subs.removeAt(item);
00774     subs.insert(item-1, fam);
00775     sublistbox->clear();
00776     sublistbox->insertStringList(subs);
00777     sublistbox->setCurrentItem(item - 1);
00778     QFont::removeSubstitution(familysubcombo->currentText());
00779     QFont::insertSubstitutions(familysubcombo->currentText(), subs);
00780     setModified(true);
00781 }
00782 
00783 
00784 void MainWindow::removeFontpath()
00785 {
00786     if (fontpathlistbox->currentItem() < 0 ||
00787         uint(fontpathlistbox->currentItem()) > fontpathlistbox->count())
00788         return;
00789 
00790     int item = fontpathlistbox->currentItem();
00791     fontpaths.remove(fontpaths.at(fontpathlistbox->currentItem()));
00792     fontpathlistbox->clear();
00793     fontpathlistbox->insertStringList(fontpaths);
00794     if (uint(item) > fontpathlistbox->count())
00795         item = int(fontpathlistbox->count()) - 1;
00796     fontpathlistbox->setCurrentItem(item);
00797     setModified(true);
00798 }
00799 
00800 
00801 void MainWindow::addFontpath()
00802 {
00803     if (fontpathlineedit->text().isEmpty())
00804         return;
00805 
00806     if (fontpathlistbox->currentItem() < 0 ||
00807         uint(fontpathlistbox->currentItem()) > fontpathlistbox->count()) {
00808         fontpaths.append(fontpathlineedit->text());
00809         fontpathlistbox->clear();
00810         fontpathlistbox->insertStringList(fontpaths);
00811         setModified(true);
00812 
00813         return;
00814     }
00815 
00816     int item = fontpathlistbox->currentItem();
00817     fontpaths.insert(fontpathlistbox->currentItem()+1,
00818                      fontpathlineedit->text());
00819     fontpathlistbox->clear();
00820     fontpathlistbox->insertStringList(fontpaths);
00821     fontpathlistbox->setCurrentItem(item);
00822     setModified(true);
00823 }
00824 
00825 
00826 void MainWindow::downFontpath()
00827 {
00828     if (fontpathlistbox->currentItem() < 0 ||
00829         uint(fontpathlistbox->currentItem()) >= fontpathlistbox->count() - 1)
00830         return;
00831 
00832     int item = fontpathlistbox->currentItem();
00833     QString fam = fontpaths.at(item);
00834     fontpaths.removeAt(item);
00835     fontpaths.insert(item+1, fam);
00836     fontpathlistbox->clear();
00837     fontpathlistbox->insertStringList(fontpaths);
00838     fontpathlistbox->setCurrentItem(item + 1);
00839     setModified(true);
00840 }
00841 
00842 
00843 void MainWindow::upFontpath()
00844 {
00845     if (fontpathlistbox->currentItem() < 1)
00846         return;
00847 
00848     int item = fontpathlistbox->currentItem();
00849     QString fam = fontpaths.at(item);
00850     fontpaths.removeAt(item);
00851     fontpaths.insert(item-1, fam);
00852     fontpathlistbox->clear();
00853     fontpathlistbox->insertStringList(fontpaths);
00854     fontpathlistbox->setCurrentItem(item - 1);
00855     setModified(true);
00856 }
00857 
00858 
00859 void MainWindow::browseFontpath()
00860 {
00861     QString dirname = QFileDialog::getExistingDirectory(QString(), this, 0,
00862                                                         tr("Select a Directory"));
00863     if (dirname.isNull())
00864         return;
00865 
00866    fontpathlineedit->setText(dirname);
00867 }
00868 
00869 
00870 void MainWindow::somethingModified()
00871 {
00872     setModified(true);
00873 }
00874 
00875 
00876 void MainWindow::helpAbout()
00877 {
00878     QMessageBox box(this);
00879     box.setText(tr("<h3>%1</h3>"
00880                    "<br/>Version %2"
00881 #if QT_EDITION == QT_EDITION_OPENSOURCE
00882                    " Open Source Edition</center><p>"
00883                    "This version of Qt Configuration is part of the Qt Open Source Edition, for use "
00884                    "in the development of Open Source applications. "
00885                    "Qt is a comprehensive C++ framework for cross-platform application "
00886                    "development.<br/><br/>"
00887                    "You need a commercial Qt license for development of proprietary (closed "
00888                    "source) applications. Please see <tt>http://www.trolltech.com/company/model"
00889                    ".html</tt> for an overview of Qt licensing."
00890 #else
00891                    "</center><p>This program is licensed to you under the terms of the "
00892                    "Qt Commercial License Agreement. For details, see the file LICENSE "
00893                    "that came with this software distribution."
00894 #endif
00895                    "<br/><br/>Copyright (C) 2000-2006 Trolltech ASA. All rights reserved."
00896                    "<br/><br/>The program is provided AS IS with NO WARRANTY OF ANY KIND,"
00897                    " INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A"
00898                    " PARTICULAR PURPOSE.<br/> ")
00899                    .arg(tr("Qt Configuration")).arg(QT_VERSION_STR));
00900     box.setWindowTitle(tr("Qt Configuration"));
00901     box.setIcon(QMessageBox::NoIcon);
00902     box.exec();
00903 }
00904 
00905 
00906 void MainWindow::helpAboutQt()
00907 {
00908     QMessageBox::aboutQt(this, tr("Qt Configuration"));
00909 }
00910 
00911 
00912 void MainWindow::pageChanged(QWidget *page)
00913 {
00914     if (page == tab)
00915         helpview->setText(tr(appearance_text));
00916     else if (page == tab1)
00917         helpview->setText(tr(font_text));
00918     else if (page == tab2)
00919         helpview->setText(tr(interface_text));
00920     else if (page == tab3)
00921         helpview->setText(tr(printer_text));
00922 }
00923 
00924 
00925 void MainWindow::closeEvent(QCloseEvent *e)
00926 {
00927     if (modified) {
00928         switch(QMessageBox::warning(this, tr("Save Changes"),
00929                                     tr("Save changes to settings?"),
00930                                     tr("&Yes"), tr("&No"), tr("&Cancel"), 0, 2)) {
00931         case 0: // save
00932             qApp->processEvents();
00933             fileSave();
00934 
00935             // fall through intended
00936         case 1: // don't save
00937             e->accept();
00938             break;
00939 
00940         case 2: // cancel
00941             e->ignore();
00942             break;
00943 
00944         default: break;
00945         }
00946     } else
00947         e->accept();
00948 }

Generated on Thu Mar 15 12:00:50 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1