Changeset e3533af1cf in tspsg for src


Ignore:
Timestamp:
Apr 30, 2010, 5:59:09 PM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
2bbe924ad8
Parents:
e51c78af27
git-author:
Oleksii Serdiuk <contacts@…> (04/30/10 17:59:09)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:41:42)
Message:

+ Added support for switching between available Qt Styles.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    re51c78af27 re3533af1cf  
    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);
  • src/mainwindow.h

    re51c78af27 re3533af1cf  
    6464        void actionSettingsLanguageAutodetectTriggered(bool checked);
    6565        void groupSettingsLanguageListTriggered(QAction *action);
     66        void actionSettingsStyleSystemTriggered(bool checked);
     67        void groupSettingsStyleListTriggered(QAction *action);
    6668#ifdef Q_OS_WIN32
    6769        void actionHelpCheck4UpdatesTriggered();
     
    8890        QString fileName;
    8991        QActionGroup *groupSettingsLanguageList;
     92        QActionGroup *groupSettingsStyleList;
    9093#ifndef QT_NO_PRINTER
    9194        QPrinter *printer;
     
    122125        void loadLangList();
    123126        bool loadLanguage(const QString &lang = QString());
     127        void loadStyleList();
    124128        bool maybeSave();
    125129        void outputMatrix(QTextCursor &cur, const TMatrix &matrix);
Note: See TracChangeset for help on using the changeset viewer.