Changeset 115 in tspsg-svn for trunk/src/mainwindow.cpp


Ignore:
Timestamp:
Apr 30, 2010, 5:59:09 PM (15 years ago)
Author:
laleppa
Message:

+ Added support for switching between available Qt Styles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mainwindow.cpp

    r114 r115  
    3636        settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this);
    3737
     38        if (settings->contains("Style")) {
     39QStyle *s = QStyleFactory::create(settings->value("Style").toString());
     40                if (s != NULL)
     41                        QApplication::setStyle(s);
     42                else
     43                        settings->remove("Style");
     44        }
     45
    3846        loadLanguage();
    3947        setupUi();
     
    6674        connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
    6775        connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *)));
     76        connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool)));
     77        connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*)));
    6878        connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
    6979        connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered()));
     
    337347        if (checked) {
    338348                settings->remove("Language");
    339                 QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next application start."));
     349                QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QApplication::applicationName()));
    340350        } else
    341351                settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString());
     
    367377                if (!solutionText->document()->isEmpty())
    368378                        QMessageBox::information(this, tr("Settings Changed"), tr("You have changed the application language.\nTo get current solution output in the new language\nyou need to re-run the solution process."));
     379        }
     380}
     381
     382void MainWindow::actionSettingsStyleSystemTriggered(bool checked)
     383{
     384        if (checked) {
     385                settings->remove("Style");
     386                QMessageBox::information(this, tr("Style Change"), tr("To apply the default style you need to restart %1.").arg(QApplication::applicationName()));
     387        } else {
     388                settings->setValue("Style", groupSettingsStyleList->checkedAction()->text());
     389        }
     390}
     391
     392void MainWindow::groupSettingsStyleListTriggered(QAction *action)
     393{
     394QStyle *s = QStyleFactory::create(action->text());
     395        if (s != NULL) {
     396                QApplication::setStyle(s);
     397                settings->setValue("Style", action->text());
     398                actionSettingsStyleSystem->setChecked(false);
    369399        }
    370400}
     
    443473        lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    444474#ifndef HANDHELD
    445         lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name()));
     475        lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name()));
    446476#endif // HANDHELD
    447477
     
    449479        lblIcon->setAlignment(Qt::AlignVCenter);
    450480#ifndef HANDHELD
    451         lblIcon->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().windowText().color().name()));
     481        lblIcon->setStyleSheet(QString("QLabel {background-color: white; border-color: %1; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().windowText().color().name()));
    452482#endif // HANDHELD
    453483
     
    460490        txtAbout->moveCursor(QTextCursor::Start);
    461491#ifndef HANDHELD
    462         txtAbout->setStyleSheet(QString("QTextBrowser {border-color: %1; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().shadow().color().name()));
     492        txtAbout->setStyleSheet(QString("QTextBrowser {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().base().color().name(), palette().shadow().color().name()));
    463493#endif // HANDHELD
    464494
     
    471501                lblTranslated->setOpenExternalLinks(true);
    472502#ifndef HANDHELD
    473                 lblTranslated->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px;}").arg(palette().window().color().name(), palette().shadow().color().name()));
     503                lblTranslated->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 3px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name()));
    474504#endif // HANDHELD
    475505                hb2->addWidget(lblTranslated);
     
    489519
    490520        dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
    491         dlg->setWindowTitle(tr("About TSPSG"));
     521        dlg->setWindowTitle(tr("About %1").arg(QApplication::applicationName()));
    492522        dlg->setLayout(vb);
    493523
     
    942972                        name = t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here.");
    943973                        a = menuSettingsLanguage->addAction(name);
    944                         a->setStatusTip(tr("Set application language to %1").arg(name));
     974                        a->setStatusTip(t.translate("MainWindow", "Set application language to %1", "").arg(name));
    945975                        a->setData(lang.completeBaseName().mid(6));
    946976                        a->setCheckable(true);
     
    10111041        }
    10121042        return true;
     1043}
     1044
     1045void MainWindow::loadStyleList()
     1046{
     1047        menuSettingsStyle->clear();
     1048QStringList styles = QStyleFactory::keys();
     1049        menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem);
     1050        actionSettingsStyleSystem->setChecked(!settings->contains("Style"));
     1051        menuSettingsStyle->addSeparator();
     1052QAction *a;
     1053        foreach (QString style, styles) {
     1054                a = menuSettingsStyle->addAction(style);
     1055                a->setData(false);
     1056                a->setStatusTip(tr("Set application style to %1").arg(style));
     1057                a->setCheckable(true);
     1058                a->setActionGroup(groupSettingsStyleList);
     1059                if ((style == settings->value("Style").toString())
     1060                        || QString(QApplication::style()->metaObject()->className()).contains(QRegExp(QString("^Q?%1(Style)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive))) {
     1061                        a->setChecked(true);
     1062                }
     1063        }
    10131064}
    10141065
     
    10791130        if (all)
    10801131                Ui::MainWindow::retranslateUi(this);
     1132
     1133        loadStyleList();
    10811134
    10821135        actionSettingsLanguageEnglish->setStatusTip(tr("Set application language to %1").arg("English"));
     
    11971250        menuSettings->insertSeparator(actionSettingsPreferences);
    11981251
     1252        groupSettingsLanguageList = new QActionGroup(this);
     1253        actionSettingsLanguageEnglish->setData("en");
     1254        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
     1255        loadLangList();
     1256        actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
     1257
     1258        actionSettingsStyleSystem->setData(true);
     1259        groupSettingsStyleList = new QActionGroup(this);
     1260
    11991261#ifdef Q_OS_WIN32
    12001262        actionHelpCheck4Updates = new QAction(this);
     
    12031265        menuHelp->insertSeparator(actionHelpAboutQt);
    12041266#endif // Q_OS_WIN32
    1205 
    1206         groupSettingsLanguageList = new QActionGroup(this);
    1207         actionSettingsLanguageEnglish->setData("en");
    1208         actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
    1209         loadLangList();
    1210         actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty());
    12111267
    12121268        spinCities->setMaximum(MAX_NUM_CITIES);
Note: See TracChangeset for help on using the changeset viewer.