Exemplo n.º 1
0
void CorePlugin::parseArguments(const QStringList &arguments)
{
    const Id settingsThemeId = Id::fromSetting(ICore::settings()->value(
                QLatin1String(Constants::SETTINGS_THEME), QLatin1String("default")));
    Id themeId = settingsThemeId;
    QColor overrideColor;
    bool presentationMode = false;

    for (int i = 0; i < arguments.size(); ++i) {
        if (arguments.at(i) == QLatin1String("-color")) {
            const QString colorcode(arguments.at(i + 1));
            overrideColor = QColor(colorcode);
            i++; // skip the argument
        }
        if (arguments.at(i) == QLatin1String("-presentationMode"))
            presentationMode = true;
        if (arguments.at(i) == QLatin1String("-theme")) {
            themeId = Id::fromString(arguments.at(i + 1));
            i++;
        }
    }
    const QList<ThemeEntry> availableThemes = ThemeEntry::availableThemes();
    int themeIndex = Utils::indexOf(availableThemes, Utils::equal(&ThemeEntry::id, themeId));
    if (themeIndex < 0) {
        themeIndex = Utils::indexOf(availableThemes,
                                    Utils::equal(&ThemeEntry::id, settingsThemeId));
    }
    if (themeIndex < 0)
        themeIndex = 0;
    if (themeIndex < availableThemes.size()) {
        const ThemeEntry themeEntry = availableThemes.at(themeIndex);
        QSettings themeSettings(themeEntry.filePath(), QSettings::IniFormat);
        Theme *theme = new Theme(themeEntry.id().toString(), qApp);
        theme->readSettings(themeSettings);
        if (theme->flag(Theme::ApplyThemePaletteGlobally))
            QApplication::setPalette(theme->palette());
        setCreatorTheme(theme);
    }

    // defer creation of these widgets until here,
    // because they need a valid theme set
    m_mainWindow = new MainWindow;
    ActionManager::setPresentationModeEnabled(presentationMode);
    m_findPlugin = new FindPlugin;
    m_locator = new Locator;

    if (overrideColor.isValid())
        m_mainWindow->setOverrideColor(overrideColor);
}
Exemplo n.º 2
0
void CorePlugin::parseArguments(const QStringList &arguments)
{
    const QString defaultTheme = QLatin1String("default");
    QString themeName = ICore::settings()->value(
                            QLatin1String(Constants::SETTINGS_THEME), defaultTheme).toString();
    QColor overrideColor;
    bool presentationMode = false;
    bool userProvidedTheme = false;

    for (int i = 0; i < arguments.size(); ++i) {
        if (arguments.at(i) == QLatin1String("-color")) {
            const QString colorcode(arguments.at(i + 1));
            overrideColor = QColor(colorcode);
            i++; // skip the argument
        }
        if (arguments.at(i) == QLatin1String("-presentationMode"))
            presentationMode = true;
        if (arguments.at(i) == QLatin1String("-theme")) {
            themeName = arguments.at(i + 1);
            userProvidedTheme = true;
            i++;
        }
    }

    QString themeURI = absoluteThemePath(themeName, userProvidedTheme);
    if (themeURI.isEmpty()) {
        themeName = defaultTheme;
        themeURI = QStringLiteral("%1/themes/%2.creatortheme").arg(ICore::resourcePath()).arg(themeName);
        if (themeURI.isEmpty()) {
            qCritical("%s", qPrintable(QCoreApplication::translate("Application", "No valid theme \"%1\"")
                                       .arg(themeName)));
        }
    }

    QSettings themeSettings(themeURI, QSettings::IniFormat);
    Theme *theme = new Theme(themeName, qApp);
    theme->readSettings(themeSettings);
    if (theme->flag(Theme::ApplyThemePaletteGlobally))
        QApplication::setPalette(theme->palette());
    setCreatorTheme(theme);

    // defer creation of these widgets until here,
    // because they need a valid theme set
    m_mainWindow = new MainWindow;
    ActionManager::setPresentationModeEnabled(presentationMode);

    if (overrideColor.isValid())
        m_mainWindow->setOverrideColor(overrideColor);
}
Exemplo n.º 3
0
void ThemeSettingsWidget::apply()
{
    const QString themeName = d->m_currentTheme.name();
    Theme *newTheme = new Theme(themeName);
    if (d->m_currentTheme.readOnly()) {
        QSettings themeSettings(d->m_currentTheme.filePath(), QSettings::IniFormat);
        newTheme->readSettings(themeSettings);
    } else {
        d->m_ui->editor->model()->toTheme(newTheme);
        newTheme->writeSettings(d->m_currentTheme.filePath());
    }
    setCreatorTheme(newTheme);
    emit ICore::instance()->themeChanged();
    QPalette pal = newTheme->flag(Theme::ApplyThemePaletteGlobally) ? newTheme->palette()
                                                                    : Theme::initialPalette();
    QApplication::setPalette(pal);
    if (ManhattanStyle *style = qobject_cast<ManhattanStyle *>(QApplication::style())) {
        QStyle *baseStyle = 0;
        foreach (const QString &s, creatorTheme()->preferredStyles()) {
            if ((baseStyle = QStyleFactory::create(s)))
                break;
        }
        style->setBaseStyle(baseStyle);
    }