fontsettingspage.cpp 21.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
#include "fontsettingspage.h"
31

32
#include "colorschemeedit.h"
con's avatar
con committed
33 34 35 36
#include "fontsettings.h"
#include "texteditorconstants.h"
#include "ui_fontsettingspage.h"

37
#include <coreplugin/icore.h>
38
#include <utils/stringutils.h>
39
#include <utils/qtcassert.h>
con's avatar
con committed
40

41
#include <QtCore/QDebug>
con's avatar
con committed
42 43 44 45
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
46
#include <QtGui/QFileDialog>
con's avatar
con committed
47
#include <QtGui/QFontDatabase>
48
#include <QtGui/QInputDialog>
49
#include <QtGui/QListWidget>
50
#include <QtGui/QMessageBox>
con's avatar
con committed
51
#include <QtGui/QPalette>
52 53 54 55
#include <QtGui/QPalette>
#include <QtGui/QTextCharFormat>
#include <QtGui/QTextEdit>
#include <QtGui/QToolButton>
con's avatar
con committed
56 57 58 59

namespace TextEditor {
namespace Internal {

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
struct ColorSchemeEntry
{
    ColorSchemeEntry(const QString &fileName,
                     bool readOnly):
        fileName(fileName),
        name(ColorScheme::readNameOfScheme(fileName)),
        readOnly(readOnly)
    { }

    QString fileName;
    QString name;
    bool readOnly;
};


class SchemeListModel : public QAbstractListModel
{
public:
    SchemeListModel(QObject *parent = 0):
        QAbstractListModel(parent)
    {
    }

    int rowCount(const QModelIndex &parent) const
    { return parent.isValid() ? 0 : m_colorSchemes.size(); }

    QVariant data(const QModelIndex &index, int role) const
    {
        if (role == Qt::DisplayRole)
            return m_colorSchemes.at(index.row()).name;

        return QVariant();
    }

    void removeColorScheme(int index)
    {
        beginRemoveRows(QModelIndex(), index, index);
        m_colorSchemes.removeAt(index);
        endRemoveRows();
    }

    void setColorSchemes(const QList<ColorSchemeEntry> &colorSchemes)
    {
        m_colorSchemes = colorSchemes;
        reset();
    }

    const ColorSchemeEntry &colorSchemeAt(int index) const
    { return m_colorSchemes.at(index); }

private:
    QList<ColorSchemeEntry> m_colorSchemes;
};


con's avatar
con committed
115 116 117 118 119 120
class FontSettingsPagePrivate
{
public:
    FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
                            const QString &name,
                            const QString &category,
121
                            const QString &trCategory);
122
    ~FontSettingsPagePrivate();
con's avatar
con committed
123

124
public:
con's avatar
con committed
125 126 127 128 129 130 131 132 133
    const QString m_name;
    const QString m_settingsGroup;
    const QString m_category;
    const QString m_trCategory;

    TextEditor::FormatDescriptions m_descriptions;
    FontSettings m_value;
    FontSettings m_lastValue;
    Ui::FontSettingsPage ui;
134
    SchemeListModel *m_schemeListModel;
135
    bool m_refreshingSchemeList;
136
    QString m_searchKeywords;
137 138 139 140 141 142 143 144
};

} // namespace Internal
} // namespace TextEditor

using namespace TextEditor;
using namespace TextEditor::Internal;

145 146 147 148 149 150 151
static QString customStylesPath()
{
    QString path = QFileInfo(Core::ICore::instance()->settings()->fileName()).path();
    path.append(QLatin1String("/qtcreator/styles/"));
    return path;
}

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
static QString createColorSchemeFileName(const QString &pattern)
{
    const QString stylesPath = customStylesPath();
    QString baseFileName = stylesPath;
    baseFileName += pattern;

    // Find an available file name
    int i = 1;
    QString fileName;
    do {
        fileName = baseFileName.arg((i == 1) ? QString() : QString::number(i));
        ++i;
    } while (QFile::exists(fileName));

    // Create the base directory when it doesn't exist
    if (!QFile::exists(stylesPath) && !QDir().mkpath(stylesPath)) {
        qWarning() << "Failed to create color scheme directory:" << stylesPath;
        return QString();
    }

    return fileName;
}
174 175

// ------- FontSettingsPagePrivate
con's avatar
con committed
176 177 178
FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
                                                 const QString &name,
                                                 const QString &category,
179
                                                 const QString &trCategory) :
con's avatar
con committed
180
    m_name(name),
181
    m_settingsGroup(Utils::settingsKey(category)),
con's avatar
con committed
182 183
    m_category(category),
    m_trCategory(trCategory),
184
    m_descriptions(fd),
185 186
    m_schemeListModel(new SchemeListModel),
    m_refreshingSchemeList(false)
con's avatar
con committed
187 188
{
    bool settingsFound = false;
189 190
    QSettings *settings = Core::ICore::instance()->settings();
    if (settings)
191
        settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
192

con's avatar
con committed
193 194 195
    if (!settingsFound) { // Apply defaults
        foreach (const FormatDescription &f, m_descriptions) {
            const QString name = f.name();
196

con's avatar
con committed
197 198
            m_value.formatFor(name).setForeground(f.foreground());
            m_value.formatFor(name).setBackground(f.background());
199 200
            m_value.formatFor(name).setBold(f.format().bold());
            m_value.formatFor(name).setItalic(f.format().italic());
con's avatar
con committed
201
        }
202 203 204 205 206 207 208 209 210 211 212 213
    } else if (m_value.colorSchemeFileName().isEmpty()) {
        // No color scheme was loaded, but one might be imported from the ini file
        ColorScheme defaultScheme;
        foreach (const FormatDescription &f, m_descriptions) {
            const QString name = f.name();
            defaultScheme.formatFor(name).setForeground(f.foreground());
            defaultScheme.formatFor(name).setBackground(f.background());
            defaultScheme.formatFor(name).setBold(f.format().bold());
            defaultScheme.formatFor(name).setItalic(f.format().italic());
        }
        if (m_value.colorScheme() != defaultScheme) {
            // Save it as a color scheme file
214 215
            QString schemeFileName = createColorSchemeFileName(QLatin1String("customized%1.xml"));
            if (!schemeFileName.isEmpty()) {
216 217 218 219
                if (m_value.saveColorScheme(schemeFileName) && settings)
                    m_value.toSettings(m_category, settings);
            }
        }
con's avatar
con committed
220 221 222 223 224
    }

    m_lastValue = m_value;
}

225 226 227 228 229
FontSettingsPagePrivate::~FontSettingsPagePrivate()
{
    delete m_schemeListModel;
}

con's avatar
con committed
230 231 232 233 234 235 236 237 238 239 240

// ------- FormatDescription
FormatDescription::FormatDescription(const QString &name, const QString &trName, const QColor &color) :
    m_name(name),
    m_trName(trName)
{
    m_format.setForeground(color);
}

QColor FormatDescription::foreground() const
{
241 242 243 244 245 246 247 248 249 250 251 252 253 254
    if (m_name == QLatin1String(Constants::C_LINE_NUMBER)) {
        const QColor bg = QApplication::palette().background().color();
        if (bg.value() < 128) {
            return QApplication::palette().foreground().color();
        } else {
            return QApplication::palette().dark().color();
        }
    } else if (m_name == QLatin1String(Constants::C_CURRENT_LINE_NUMBER)) {
        const QColor bg = QApplication::palette().background().color();
        if (bg.value() < 128) {
            return QApplication::palette().foreground().color();
        } else {
            return m_format.foreground();
        }
Roberto Raggi's avatar
Roberto Raggi committed
255 256
    } else if (m_name == QLatin1String(Constants::C_OCCURRENCES_UNUSED)) {
        return Qt::lightGray;
257
    } else if (m_name == QLatin1String(Constants::C_PARENTHESES)) {
con's avatar
con committed
258
        return QColor(Qt::red);
259
    }
con's avatar
con committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    return m_format.foreground();
}

QColor FormatDescription::background() const
{
    if (m_name == QLatin1String(Constants::C_TEXT))
        return Qt::white;
    else if (m_name == QLatin1String(Constants::C_LINE_NUMBER))
        return QApplication::palette().background().color();
    else if (m_name == QLatin1String(Constants::C_SEARCH_RESULT))
        return QColor(0xffef0b);
    else if (m_name == QLatin1String(Constants::C_PARENTHESES))
        return QColor(0xb4, 0xee, 0xb4);
    else if (m_name == QLatin1String(Constants::C_CURRENT_LINE)
             || m_name == QLatin1String(Constants::C_SEARCH_SCOPE)) {
        const QPalette palette = QApplication::palette();
        const QColor &fg = palette.color(QPalette::Highlight);
        const QColor &bg = palette.color(QPalette::Base);

        qreal smallRatio;
        qreal largeRatio;
        if (m_name == QLatin1String(Constants::C_CURRENT_LINE)) {
            smallRatio = .15;
            largeRatio = .3;
        } else {
            smallRatio = .05;
            largeRatio = .4;
        }
        const qreal ratio = ((palette.color(QPalette::Text).value() < 128)
                             ^ (palette.color(QPalette::HighlightedText).value() < 128)) ? smallRatio : largeRatio;

        const QColor &col = QColor::fromRgbF(fg.redF() * ratio + bg.redF() * (1 - ratio),
                                             fg.greenF() * ratio + bg.greenF() * (1 - ratio),
                                             fg.blueF() * ratio + bg.blueF() * (1 - ratio));
        return col;
    } else if (m_name == QLatin1String(Constants::C_SELECTION)) {
        const QPalette palette = QApplication::palette();
        return palette.color(QPalette::Highlight);
298
    } else if (m_name == QLatin1String(Constants::C_OCCURRENCES)) {
299
        return QColor(180, 180, 180);
300
    } else if (m_name == QLatin1String(Constants::C_OCCURRENCES_RENAME)) {
301
        return QColor(255, 180, 180);
302 303
    } else if (m_name == QLatin1String(Constants::C_DISABLED_CODE)) {
        return QColor(239, 239, 239);
con's avatar
con committed
304 305 306 307 308 309 310 311 312 313 314
    }
    return QColor(); // invalid color
}


//  ------------ FontSettingsPage
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
                                   const QString &category,
                                   const QString &trCategory,
                                   QObject *parent) :
    Core::IOptionsPage(parent),
315
    d_ptr(new FontSettingsPagePrivate(fd, tr("Font & Colors"), category, trCategory))
con's avatar
con committed
316 317 318 319 320 321 322 323
{
}

FontSettingsPage::~FontSettingsPage()
{
    delete d_ptr;
}

324 325 326 327 328 329
QString FontSettingsPage::id() const
{
    return d_ptr->m_name;
}

QString FontSettingsPage::trName() const
con's avatar
con committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
{
    return d_ptr->m_name;
}

QString FontSettingsPage::category() const
{
    return d_ptr->m_category;
}

QString FontSettingsPage::trCategory() const
{
    return d_ptr->m_trCategory;
}

QWidget *FontSettingsPage::createPage(QWidget *parent)
{
    QWidget *w = new QWidget(parent);
    d_ptr->ui.setupUi(w);
348
    d_ptr->ui.schemeComboBox->setModel(d_ptr->m_schemeListModel);
con's avatar
con committed
349 350 351 352 353 354 355

    QFontDatabase db;
    const QStringList families = db.families();
    d_ptr->ui.familyComboBox->addItems(families);
    const int idx = families.indexOf(d_ptr->m_value.family());
    d_ptr->ui.familyComboBox->setCurrentIndex(idx);

356 357
    d_ptr->ui.antialias->setChecked(d_ptr->m_value.antialias());

358 359 360 361 362 363
    d_ptr->ui.schemeEdit->setFormatDescriptions(d_ptr->m_descriptions);
    d_ptr->ui.schemeEdit->setBaseFont(d_ptr->m_value.font());
    d_ptr->ui.schemeEdit->setColorScheme(d_ptr->m_value.colorScheme());

    connect(d_ptr->ui.familyComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(fontFamilySelected(QString)));
    connect(d_ptr->ui.sizeComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(fontSizeSelected(QString)));
364
    connect(d_ptr->ui.schemeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(colorSchemeSelected(int)));
365
    connect(d_ptr->ui.copyButton, SIGNAL(clicked()), this, SLOT(copyColorScheme()));
366
    connect(d_ptr->ui.deleteButton, SIGNAL(clicked()), this, SLOT(confirmDeleteColorScheme()));
con's avatar
con committed
367 368

    updatePointSizes();
369
    refreshColorSchemeList();
con's avatar
con committed
370
    d_ptr->m_lastValue = d_ptr->m_value;
371 372
    if (d_ptr->m_searchKeywords.isEmpty())
        d_ptr->m_searchKeywords = d_ptr->ui.fontGroupBox->title() + QLatin1Char(' ') + d_ptr->ui.colorSchemeGroupBox->title();
con's avatar
con committed
373 374 375
    return w;
}

376 377
void FontSettingsPage::fontFamilySelected(const QString &family)
{
378
    d_ptr->m_value.setFamily(family);
379 380 381 382
    d_ptr->ui.schemeEdit->setBaseFont(d_ptr->m_value.font());
    updatePointSizes();
}

con's avatar
con committed
383 384
void FontSettingsPage::updatePointSizes()
{
385
    // Update point sizes
con's avatar
con committed
386 387 388 389 390 391 392 393 394 395 396 397 398
    const int oldSize = d_ptr->m_value.fontSize();
    if (d_ptr->ui.sizeComboBox->count()) {
        const QString curSize = d_ptr->ui.sizeComboBox->currentText();
        bool ok = true;
        int oldSize = curSize.toInt(&ok);
        if (!ok)
            oldSize = d_ptr->m_value.fontSize();
        d_ptr->ui.sizeComboBox->clear();
    }
    QFontDatabase db;
    const QList<int> sizeLst = db.pointSizes(d_ptr->ui.familyComboBox->currentText());
    int idx = 0;
    int i = 0;
399
    for (; i < sizeLst.count(); ++i) {
con's avatar
con committed
400 401 402 403 404 405
        if (idx == 0 && sizeLst.at(i) >= oldSize)
            idx = i;
        d_ptr->ui.sizeComboBox->addItem(QString::number(sizeLst.at(i)));
    }
    if (d_ptr->ui.sizeComboBox->count())
        d_ptr->ui.sizeComboBox->setCurrentIndex(idx);
406 407
}

408 409 410 411 412 413 414 415 416 417
void FontSettingsPage::fontSizeSelected(const QString &sizeString)
{
    bool ok = true;
    const int size = sizeString.toInt(&ok);
    if (ok) {
        d_ptr->m_value.setFontSize(size);
        d_ptr->ui.schemeEdit->setBaseFont(d_ptr->m_value.font());
    }
}

418
void FontSettingsPage::colorSchemeSelected(int index)
419
{
420
    bool readOnly = true;
421
    if (index != -1) {
422 423 424 425
        // Check whether we're switching away from a changed color scheme
        if (!d_ptr->m_refreshingSchemeList)
            maybeSaveColorScheme();

426
        const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
427 428 429
        readOnly = entry.readOnly;
        d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions);
        d_ptr->ui.schemeEdit->setColorScheme(d_ptr->m_value.colorScheme());
430
    }
431 432 433
    d_ptr->ui.copyButton->setEnabled(index != -1);
    d_ptr->ui.deleteButton->setEnabled(!readOnly);
    d_ptr->ui.schemeEdit->setReadOnly(readOnly);
434 435
}

436
void FontSettingsPage::copyColorScheme()
437 438 439 440 441 442 443 444 445 446 447 448 449
{
    QInputDialog *dialog = new QInputDialog(d_ptr->ui.copyButton->window());
    dialog->setAttribute(Qt::WA_DeleteOnClose);
    dialog->setInputMode(QInputDialog::TextInput);
    dialog->setWindowTitle(tr("Copy Color Scheme"));
    dialog->setLabelText(tr("Color Scheme name:"));
    dialog->setTextValue(tr("%1 (copy)").arg(d_ptr->m_value.colorScheme().name()));

    connect(dialog, SIGNAL(textValueSelected(QString)), this, SLOT(copyColorScheme(QString)));
    dialog->open();
}

void FontSettingsPage::copyColorScheme(const QString &name)
450
{
451 452
    int index = d_ptr->ui.schemeComboBox->currentIndex();
    if (index == -1)
453 454
        return;

455
    const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
456

457 458 459
    QString baseFileName = QFileInfo(entry.fileName).completeBaseName();
    baseFileName += QLatin1String("_copy%1.xml");
    QString fileName = createColorSchemeFileName(baseFileName);
460

461
    if (!fileName.isEmpty()) {
462 463 464 465 466 467
        // Ask about saving any existing modifactions
        maybeSaveColorScheme();

        // Make sure we're copying the current version
        d_ptr->m_value.setColorScheme(d_ptr->ui.schemeEdit->colorScheme());

468
        ColorScheme scheme = d_ptr->m_value.colorScheme();
469
        scheme.setName(name);
470 471
        scheme.save(fileName);
        d_ptr->m_value.setColorSchemeFileName(fileName);
472

473
        refreshColorSchemeList();
474
    }
475 476
}

477
void FontSettingsPage::confirmDeleteColorScheme()
478
{
479
    const int index = d_ptr->ui.schemeComboBox->currentIndex();
480
    if (index == -1)
481 482
        return;

483
    const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
484 485
    if (entry.readOnly)
        return;
486

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    QMessageBox *messageBox = new QMessageBox(QMessageBox::Warning,
                                              tr("Delete Color Scheme"),
                                              tr("Are you sure you want to delete this color scheme permanently?"),
                                              QMessageBox::Discard | QMessageBox::Cancel,
                                              d_ptr->ui.deleteButton->window());

    // Change the text and role of the discard button
    QPushButton *deleteButton = static_cast<QPushButton*>(messageBox->button(QMessageBox::Discard));
    deleteButton->setText(tr("Delete"));
    messageBox->addButton(deleteButton, QMessageBox::AcceptRole);
    messageBox->setDefaultButton(deleteButton);

    connect(deleteButton, SIGNAL(clicked()), messageBox, SLOT(accept()));
    connect(messageBox, SIGNAL(accepted()), this, SLOT(deleteColorScheme()));
    messageBox->setAttribute(Qt::WA_DeleteOnClose);
    messageBox->open();
}
504

505 506 507 508 509 510 511 512 513 514
void FontSettingsPage::deleteColorScheme()
{
    const int index = d_ptr->ui.schemeComboBox->currentIndex();
    QTC_ASSERT(index != -1, return)

    const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
    QTC_ASSERT(!entry.readOnly, return)

    if (QFile::remove(entry.fileName))
        d_ptr->m_schemeListModel->removeColorScheme(index);
515 516
}

517
void FontSettingsPage::maybeSaveColorScheme()
518
{
519
    if (d_ptr->m_value.colorScheme() == d_ptr->ui.schemeEdit->colorScheme())
520 521
        return;

522 523 524 525 526 527 528 529 530 531 532 533 534 535
    QMessageBox *messageBox = new QMessageBox(QMessageBox::Warning,
                                              tr("Color Scheme Changed"),
                                              tr("The color scheme \"%1\" was modified, do you want to save the changes?")
                                                  .arg(d_ptr->ui.schemeEdit->colorScheme().name()),
                                              QMessageBox::Discard | QMessageBox::Save,
                                              d_ptr->ui.schemeComboBox->window());

    // Change the text of the discard button
    QPushButton *discardButton = static_cast<QPushButton*>(messageBox->button(QMessageBox::Discard));
    discardButton->setText(tr("Discard"));
    messageBox->addButton(discardButton, QMessageBox::DestructiveRole);
    messageBox->setDefaultButton(QMessageBox::Save);

    if (messageBox->exec() == QMessageBox::Save) {
536 537
        const ColorScheme &scheme = d_ptr->ui.schemeEdit->colorScheme();
        scheme.save(d_ptr->m_value.colorSchemeFileName());
538 539 540
    }
}

541 542
void FontSettingsPage::refreshColorSchemeList()
{
543
    QList<ColorSchemeEntry> colorSchemes;
544 545 546 547 548 549

    QString resourcePath = Core::ICore::instance()->resourcePath();
    QDir styleDir(resourcePath + QLatin1String("/styles"));
    styleDir.setNameFilters(QStringList() << QLatin1String("*.xml"));
    styleDir.setFilter(QDir::Files);

550 551
    int selected = 0;

552
    foreach (const QString &file, styleDir.entryList()) {
553 554
        const QString fileName = styleDir.absoluteFilePath(file);
        if (d_ptr->m_value.colorSchemeFileName() == fileName)
555 556
            selected = colorSchemes.size();
        colorSchemes.append(ColorSchemeEntry(fileName, true));
557 558
    }

559 560 561
    if (colorSchemes.isEmpty())
        qWarning() << "Warning: no color schemes found in path:" << styleDir.path();

562 563 564 565 566
    styleDir.setPath(customStylesPath());

    foreach (const QString &file, styleDir.entryList()) {
        const QString fileName = styleDir.absoluteFilePath(file);
        if (d_ptr->m_value.colorSchemeFileName() == fileName)
567 568
            selected = colorSchemes.size();
        colorSchemes.append(ColorSchemeEntry(fileName, false));
569
    }
570

571
    d_ptr->m_refreshingSchemeList = true;
572 573
    d_ptr->m_schemeListModel->setColorSchemes(colorSchemes);
    d_ptr->ui.schemeComboBox->setCurrentIndex(selected);
574
    d_ptr->m_refreshingSchemeList = false;
575 576
}

con's avatar
con committed
577 578 579 580 581
void FontSettingsPage::delayedChange()
{
    emit changed(d_ptr->m_value);
}

582
void FontSettingsPage::apply()
con's avatar
con committed
583
{
584
    d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked());
con's avatar
con committed
585

586 587 588 589 590 591 592
    if (d_ptr->m_value.colorScheme() != d_ptr->ui.schemeEdit->colorScheme()) {
        // Update the scheme and save it under the name it already has
        d_ptr->m_value.setColorScheme(d_ptr->ui.schemeEdit->colorScheme());
        const ColorScheme &scheme = d_ptr->m_value.colorScheme();
        scheme.save(d_ptr->m_value.colorSchemeFileName());
    }

593 594 595
    int index = d_ptr->ui.schemeComboBox->currentIndex();
    if (index != -1) {
        const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
596 597
        if (entry.fileName != d_ptr->m_value.colorSchemeFileName())
            d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions);
598 599
    }

600 601
    saveSettings();
}
con's avatar
con committed
602

603 604
void FontSettingsPage::saveSettings()
{
con's avatar
con committed
605
    if (d_ptr->m_value != d_ptr->m_lastValue) {
Roberto Raggi's avatar
Roberto Raggi committed
606 607 608
        d_ptr->m_lastValue = d_ptr->m_value;
        if (QSettings *settings = Core::ICore::instance()->settings())
            d_ptr->m_value.toSettings(d_ptr->m_settingsGroup, settings);
con's avatar
con committed
609

Roberto Raggi's avatar
Roberto Raggi committed
610
        QTimer::singleShot(0, this, SLOT(delayedChange()));
con's avatar
con committed
611 612 613
    }
}

614 615 616 617 618 619
void FontSettingsPage::finish()
{
    // If changes were applied, these are equal. Otherwise restores last value.
    d_ptr->m_value = d_ptr->m_lastValue;
}

con's avatar
con committed
620 621 622 623
const FontSettings &FontSettingsPage::fontSettings() const
{
    return d_ptr->m_value;
}
624 625 626 627 628

bool FontSettingsPage::matches(const QString &s) const
{
    return d_ptr->m_searchKeywords.contains(s, Qt::CaseInsensitive);
}