From 0e70a1e85e3b3f05e6aed4f8d67360b29f777792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 18 Jun 2009 17:35:46 +0200 Subject: [PATCH] Moved editing of the color scheme into a separate dialog In preparation of being able to select from multiple color schemes. --- src/plugins/texteditor/colorscheme.h | 3 + .../texteditor/editcolorschemedialog.cpp | 215 ++++++++++++++++ .../texteditor/editcolorschemedialog.h | 81 ++++++ .../texteditor/editcolorschemedialog.ui | 231 ++++++++++++++++++ src/plugins/texteditor/fontsettings.h | 8 +- src/plugins/texteditor/fontsettingspage.cpp | 205 ++-------------- src/plugins/texteditor/fontsettingspage.h | 7 +- src/plugins/texteditor/fontsettingspage.ui | 204 +++++----------- src/plugins/texteditor/texteditor.pro | 9 +- 9 files changed, 631 insertions(+), 332 deletions(-) create mode 100644 src/plugins/texteditor/editcolorschemedialog.cpp create mode 100644 src/plugins/texteditor/editcolorschemedialog.h create mode 100644 src/plugins/texteditor/editcolorschemedialog.ui diff --git a/src/plugins/texteditor/colorscheme.h b/src/plugins/texteditor/colorscheme.h index e333d6b128a..cc327bdfcd8 100644 --- a/src/plugins/texteditor/colorscheme.h +++ b/src/plugins/texteditor/colorscheme.h @@ -81,6 +81,9 @@ class ColorScheme public: ColorScheme(); + inline bool isEmpty() const + { return m_formats.isEmpty(); } + bool contains(const QString &category) const; Format &formatFor(const QString &category); diff --git a/src/plugins/texteditor/editcolorschemedialog.cpp b/src/plugins/texteditor/editcolorschemedialog.cpp new file mode 100644 index 00000000000..0fc58ea21c3 --- /dev/null +++ b/src/plugins/texteditor/editcolorschemedialog.cpp @@ -0,0 +1,215 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** 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. +** +** GNU Lesser General Public License Usage +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#include "editcolorschemedialog.h" +#include "ui_editcolorschemedialog.h" + +#include + +using namespace TextEditor::Internal; + +static inline QString colorButtonStyleSheet(const QColor &bgColor) +{ + if (bgColor.isValid()) { + QString rc = QLatin1String("border: 2px solid black; border-radius: 2px; background:"); + rc += bgColor.name(); + return rc; + } + return QLatin1String("border: 2px dotted black; border-radius: 2px;"); +} + +EditColorSchemeDialog::EditColorSchemeDialog(const FormatDescriptions &fd, + const FontSettings &fontSettings, + const ColorScheme &scheme, + QWidget *parent) : + QDialog(parent), + m_descriptions(fd), + m_fontSettings(fontSettings), + m_scheme(scheme), + m_curItem(-1), + m_ui(new Ui::EditColorSchemeDialog) +{ + m_ui->setupUi(this); + + foreach (const FormatDescription &d, fd) + m_ui->itemListWidget->addItem(d.trName()); + + connect(m_ui->itemListWidget, SIGNAL(itemSelectionChanged()), SLOT(itemChanged())); + connect(m_ui->foregroundToolButton, SIGNAL(clicked()), SLOT(changeForeColor())); + connect(m_ui->backgroundToolButton, SIGNAL(clicked()), SLOT(changeBackColor())); + connect(m_ui->eraseBackgroundToolButton, SIGNAL(clicked()), SLOT(eraseBackColor())); + connect(m_ui->boldCheckBox, SIGNAL(toggled(bool)), SLOT(checkCheckBoxes())); + connect(m_ui->italicCheckBox, SIGNAL(toggled(bool)), SLOT(checkCheckBoxes())); + + if (!m_descriptions.empty()) + m_ui->itemListWidget->setCurrentRow(0); +} + +EditColorSchemeDialog::~EditColorSchemeDialog() +{ + delete m_ui; +} + +void EditColorSchemeDialog::itemChanged() +{ + QListWidgetItem *item = m_ui->itemListWidget->currentItem(); + if (!item) + return; + + const int numFormats = m_descriptions.size(); + for (int i = 0; i < numFormats; i++) { + if (m_descriptions[i].trName() == item->text()) { + m_curItem = i; + const Format &format = m_scheme.formatFor(m_descriptions[i].name()); + m_ui->foregroundToolButton->setStyleSheet(colorButtonStyleSheet(format.foreground())); + m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background())); + + m_ui->eraseBackgroundToolButton->setEnabled(i > 0 && format.background().isValid()); + + const bool boldBlocked = m_ui->boldCheckBox->blockSignals(true); + m_ui->boldCheckBox->setChecked(format.bold()); + m_ui->boldCheckBox->blockSignals(boldBlocked); + const bool italicBlocked = m_ui->italicCheckBox->blockSignals(true); + m_ui->italicCheckBox->setChecked(format.italic()); + m_ui->italicCheckBox->blockSignals(italicBlocked); + updatePreview(); + break; + } + } +} + +void EditColorSchemeDialog::changeForeColor() +{ + if (m_curItem == -1) + return; + QColor color = m_scheme.formatFor(m_descriptions[m_curItem].name()).foreground(); + const QColor newColor = QColorDialog::getColor(color, m_ui->boldCheckBox->window()); + if (!newColor.isValid()) + return; + QPalette p = m_ui->foregroundToolButton->palette(); + p.setColor(QPalette::Active, QPalette::Button, newColor); + m_ui->foregroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + + const int numFormats = m_descriptions.size(); + for (int i = 0; i < numFormats; i++) { + QList items = m_ui->itemListWidget->findItems(m_descriptions[i].trName(), Qt::MatchExactly); + if (!items.isEmpty() && items.first()->isSelected()) + m_scheme.formatFor(m_descriptions[i].name()).setForeground(newColor); + } + + updatePreview(); +} + +void EditColorSchemeDialog::changeBackColor() +{ + if (m_curItem == -1) + return; + QColor color = m_scheme.formatFor(m_descriptions[m_curItem].name()).background(); + const QColor newColor = QColorDialog::getColor(color, m_ui->boldCheckBox->window()); + if (!newColor.isValid()) + return; + m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + m_ui->eraseBackgroundToolButton->setEnabled(true); + + const int numFormats = m_descriptions.size(); + for (int i = 0; i < numFormats; i++) { + QList items = m_ui->itemListWidget->findItems(m_descriptions[i].trName(), Qt::MatchExactly); + if (!items.isEmpty() && items.first()->isSelected()) + m_scheme.formatFor(m_descriptions[i].name()).setBackground(newColor); + } + + updatePreview(); +} + +void EditColorSchemeDialog::eraseBackColor() +{ + if (m_curItem == -1) + return; + QColor newColor; + m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); + + const int numFormats = m_descriptions.size(); + for (int i = 0; i < numFormats; i++) { + QList items = m_ui->itemListWidget->findItems(m_descriptions[i].trName(), Qt::MatchExactly); + if (!items.isEmpty() && items.first()->isSelected()) + m_scheme.formatFor(m_descriptions[i].name()).setBackground(newColor); + } + m_ui->eraseBackgroundToolButton->setEnabled(false); + + updatePreview(); +} + +void EditColorSchemeDialog::checkCheckBoxes() +{ + if (m_curItem == -1) + return; + const int numFormats = m_descriptions.size(); + for (int i = 0; i < numFormats; i++) { + QList items = m_ui->itemListWidget->findItems(m_descriptions[i].trName(), Qt::MatchExactly); + if (!items.isEmpty() && items.first()->isSelected()) { + m_scheme.formatFor(m_descriptions[i].name()).setBold(m_ui->boldCheckBox->isChecked()); + m_scheme.formatFor(m_descriptions[i].name()).setItalic(m_ui->italicCheckBox->isChecked()); + } + } + updatePreview(); +} + +void EditColorSchemeDialog::updatePreview() +{ + if (m_curItem == -1) + return; + + const Format ¤tFormat = m_scheme.formatFor(m_descriptions[m_curItem].name()); + const Format &baseFormat = m_scheme.formatFor(QLatin1String("Text")); + + QPalette pal = QApplication::palette(); + if (baseFormat.foreground().isValid()) { + pal.setColor(QPalette::Text, baseFormat.foreground()); + pal.setColor(QPalette::Foreground, baseFormat.foreground()); + } + if (baseFormat.background().isValid()) + pal.setColor(QPalette::Base, baseFormat.background()); + + m_ui->previewTextEdit->setPalette(pal); + + QTextCharFormat format; + if (currentFormat.foreground().isValid()) + format.setForeground(QBrush(currentFormat.foreground())); + if (currentFormat.background().isValid()) + format.setBackground(QBrush(currentFormat.background())); + format.setFontFamily(m_fontSettings.family()); + format.setFontStyleStrategy(m_fontSettings.antialias() ? QFont::PreferAntialias : QFont::NoAntialias); + format.setFontPointSize(m_fontSettings.fontSize()); + format.setFontItalic(currentFormat.italic()); + if (currentFormat.bold()) + format.setFontWeight(QFont::Bold); + m_ui->previewTextEdit->setCurrentCharFormat(format); + + m_ui->previewTextEdit->setPlainText(tr("\n\tThis is only an example.")); +} diff --git a/src/plugins/texteditor/editcolorschemedialog.h b/src/plugins/texteditor/editcolorschemedialog.h new file mode 100644 index 00000000000..d727b2eb15d --- /dev/null +++ b/src/plugins/texteditor/editcolorschemedialog.h @@ -0,0 +1,81 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** 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. +** +** GNU Lesser General Public License Usage +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** +**************************************************************************/ + +#ifndef EDITCOLORSCHEMEDIALOG_H +#define EDITCOLORSCHEMEDIALOG_H + +#include "colorscheme.h" +#include "fontsettingspage.h" + +#include + +namespace TextEditor { +namespace Internal { + +namespace Ui { +class EditColorSchemeDialog; +} + +class EditColorSchemeDialog : public QDialog +{ + Q_OBJECT + +public: + EditColorSchemeDialog(const FormatDescriptions &fd, + const FontSettings &fontSettings, + const ColorScheme &scheme, + QWidget *parent = 0); + ~EditColorSchemeDialog(); + + ColorScheme colorScheme() const + { return m_scheme; } + +private slots: + void itemChanged(); + void changeForeColor(); + void changeBackColor(); + void eraseBackColor(); + void checkCheckBoxes(); + void updatePreview(); + +private: + const TextEditor::FormatDescriptions m_descriptions; + const FontSettings m_fontSettings; + + ColorScheme m_scheme; + int m_curItem; + + Ui::EditColorSchemeDialog *m_ui; +}; + + +} // namespace Internal +} // namespace TextEditor + +#endif // EDITCOLORSCHEMEDIALOG_H diff --git a/src/plugins/texteditor/editcolorschemedialog.ui b/src/plugins/texteditor/editcolorschemedialog.ui new file mode 100644 index 00000000000..4810a5c8d36 --- /dev/null +++ b/src/plugins/texteditor/editcolorschemedialog.ui @@ -0,0 +1,231 @@ + + + TextEditor::Internal::EditColorSchemeDialog + + + + 0 + 0 + 462 + 416 + + + + Edit Color Scheme + + + + + + + 0 + 1 + + + + Text Categories + + + + + + + 1 + 0 + + + + QAbstractItemView::ExtendedSelection + + + + + + + + + Bold + + + + + + + Italic + + + + + + + + 0 + 0 + + + + + + + + + + + + 0 + 0 + + + + Background: + + + + + + + + 0 + 0 + + + + Foreground: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + + + Erase background + + + x + + + Qt::LeftArrow + + + + + + + + + + + + + + Preview: + + + + + + + + 0 + 0 + + + + + 16777215 + 100 + + + + true + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + TextEditor::Internal::EditColorSchemeDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + TextEditor::Internal::EditColorSchemeDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h index 20eb325bebf..c74524b618c 100644 --- a/src/plugins/texteditor/fontsettings.h +++ b/src/plugins/texteditor/fontsettings.h @@ -59,7 +59,7 @@ public: FontSettings(); void clear(); - inline bool isEmpty() const { return m_formats.isEmpty(); } + inline bool isEmpty() const { return m_scheme.isEmpty(); } void toSettings(const QString &category, const FormatDescriptions &descriptions, @@ -103,6 +103,12 @@ public: */ Format &formatFor(const QString &category); + ColorScheme colorScheme() const + { return m_scheme; } + + void setColorScheme(const ColorScheme &scheme) + { m_scheme = scheme; } + bool equals(const FontSettings &f) const; static QString defaultFixedFontFamily(); diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index c19d950f517..6d5a5f4e2f7 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -28,6 +28,8 @@ **************************************************************************/ #include "fontsettingspage.h" + +#include "editcolorschemedialog.h" #include "fontsettings.h" #include "texteditorconstants.h" #include "ui_fontsettingspage.h" @@ -38,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -48,16 +49,6 @@ #include #include -static inline QString colorButtonStyleSheet(const QColor &bgColor) -{ - if (bgColor.isValid()) { - QString rc = QLatin1String("border: 2px solid black; border-radius: 2px; background:"); - rc += bgColor.name(); - return rc; - } - return QLatin1String("border: 2px dotted black; border-radius: 2px;"); -} - namespace TextEditor { namespace Internal { @@ -78,7 +69,6 @@ public: TextEditor::FormatDescriptions m_descriptions; FontSettings m_value; FontSettings m_lastValue; - int m_curItem; Ui::FontSettingsPage ui; }; @@ -90,8 +80,7 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescrip m_settingsGroup(Core::Utils::settingsKey(category)), m_category(category), m_trCategory(trCategory), - m_descriptions(fd), - m_curItem(-1) + m_descriptions(fd) { bool settingsFound = false; if (const QSettings *settings = Core::ICore::instance()->settings()) @@ -231,10 +220,9 @@ QWidget *FontSettingsPage::createPage(QWidget *parent) QWidget *w = new QWidget(parent); d_ptr->ui.setupUi(w); - d_ptr->ui.itemListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); - - foreach (const FormatDescription &d, d_ptr->m_descriptions) - d_ptr->ui.itemListWidget->addItem(d.trName()); + d_ptr->ui.schemeListWidget->addItem(tr("Default")); + d_ptr->ui.schemeListWidget->setCurrentIndex(d_ptr->ui.schemeListWidget->model()->index(0, 0)); + d_ptr->ui.editButton->setEnabled(true); QFontDatabase db; const QStringList families = db.families(); @@ -245,170 +233,13 @@ QWidget *FontSettingsPage::createPage(QWidget *parent) d_ptr->ui.antialias->setChecked(d_ptr->m_value.antialias()); connect(d_ptr->ui.familyComboBox, SIGNAL(activated(int)), this, SLOT(updatePointSizes())); - connect(d_ptr->ui.sizeComboBox, SIGNAL(activated(int)), this, SLOT(updatePreview())); - connect(d_ptr->ui.antialias, SIGNAL(toggled(bool)), this, SLOT(updatePreview())); - connect(d_ptr->ui.itemListWidget, SIGNAL(itemSelectionChanged()), - this, SLOT(itemChanged())); - connect(d_ptr->ui.foregroundToolButton, SIGNAL(clicked()), - this, SLOT(changeForeColor())); - connect(d_ptr->ui.backgroundToolButton, SIGNAL(clicked()), - this, SLOT(changeBackColor())); - connect(d_ptr->ui.eraseBackgroundToolButton, SIGNAL(clicked()), - this, SLOT(eraseBackColor())); - connect(d_ptr->ui.boldCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkCheckBoxes())); - connect(d_ptr->ui.italicCheckBox, SIGNAL(toggled(bool)), this, SLOT(checkCheckBoxes())); - - if (!d_ptr->m_descriptions.empty()) - d_ptr->ui.itemListWidget->setCurrentRow(0); + connect(d_ptr->ui.editButton, SIGNAL(clicked()), this, SLOT(editColorScheme())); updatePointSizes(); d_ptr->m_lastValue = d_ptr->m_value; return w; } -void FontSettingsPage::itemChanged() -{ - QListWidgetItem *item = d_ptr->ui.itemListWidget->currentItem(); - if (!item) - return; - - const int numFormats = d_ptr->m_descriptions.size(); - for (int i = 0; i < numFormats; i++) { - if (d_ptr->m_descriptions[i].trName() == item->text()) { - d_ptr->m_curItem = i; - const Format &format = d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()); - d_ptr->ui.foregroundToolButton->setStyleSheet(colorButtonStyleSheet(format.foreground())); - d_ptr->ui.backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background())); - - d_ptr->ui.eraseBackgroundToolButton->setEnabled(i > 0 && format.background().isValid()); - - const bool boldBlocked = d_ptr->ui.boldCheckBox->blockSignals(true); - d_ptr->ui.boldCheckBox->setChecked(format.bold()); - d_ptr->ui.boldCheckBox->blockSignals(boldBlocked); - const bool italicBlocked = d_ptr->ui.italicCheckBox->blockSignals(true); - d_ptr->ui.italicCheckBox->setChecked(format.italic()); - d_ptr->ui.italicCheckBox->blockSignals(italicBlocked); - updatePreview(); - break; - } - } -} - -void FontSettingsPage::changeForeColor() -{ - if (d_ptr->m_curItem == -1) - return; - QColor color = d_ptr->m_value.formatFor(d_ptr->m_descriptions[d_ptr->m_curItem].name()).foreground(); - const QColor newColor = QColorDialog::getColor(color, d_ptr->ui.boldCheckBox->window()); - if (!newColor.isValid()) - return; - QPalette p = d_ptr->ui.foregroundToolButton->palette(); - p.setColor(QPalette::Active, QPalette::Button, newColor); - d_ptr->ui.foregroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); - - const int numFormats = d_ptr->m_descriptions.size(); - for (int i = 0; i < numFormats; i++) { - QList items = d_ptr->ui.itemListWidget->findItems(d_ptr->m_descriptions[i].trName(), Qt::MatchExactly); - if (!items.isEmpty() && items.first()->isSelected()) - d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()).setForeground(newColor); - } - - updatePreview(); -} - -void FontSettingsPage::changeBackColor() -{ - if (d_ptr->m_curItem == -1) - return; - QColor color = d_ptr->m_value.formatFor(d_ptr->m_descriptions[d_ptr->m_curItem].name()).background(); - const QColor newColor = QColorDialog::getColor(color, d_ptr->ui.boldCheckBox->window()); - if (!newColor.isValid()) - return; - d_ptr->ui.backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); - d_ptr->ui.eraseBackgroundToolButton->setEnabled(true); - - const int numFormats = d_ptr->m_descriptions.size(); - for (int i = 0; i < numFormats; i++) { - QList items = d_ptr->ui.itemListWidget->findItems(d_ptr->m_descriptions[i].trName(), Qt::MatchExactly); - if (!items.isEmpty() && items.first()->isSelected()) - d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()).setBackground(newColor); - } - - updatePreview(); -} - -void FontSettingsPage::eraseBackColor() -{ - if (d_ptr->m_curItem == -1) - return; - QColor newColor; - d_ptr->ui.backgroundToolButton->setStyleSheet(colorButtonStyleSheet(newColor)); - - const int numFormats = d_ptr->m_descriptions.size(); - for (int i = 0; i < numFormats; i++) { - QList items = d_ptr->ui.itemListWidget->findItems(d_ptr->m_descriptions[i].trName(), Qt::MatchExactly); - if (!items.isEmpty() && items.first()->isSelected()) - d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()).setBackground(newColor); - } - d_ptr->ui.eraseBackgroundToolButton->setEnabled(false); - - updatePreview(); -} - -void FontSettingsPage::checkCheckBoxes() -{ - if (d_ptr->m_curItem == -1) - return; - const int numFormats = d_ptr->m_descriptions.size(); - for (int i = 0; i < numFormats; i++) { - QList items = d_ptr->ui.itemListWidget->findItems(d_ptr->m_descriptions[i].trName(), Qt::MatchExactly); - if (!items.isEmpty() && items.first()->isSelected()) { - d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()).setBold(d_ptr->ui.boldCheckBox->isChecked()); - d_ptr->m_value.formatFor(d_ptr->m_descriptions[i].name()).setItalic(d_ptr->ui.italicCheckBox->isChecked()); - } - } - updatePreview(); -} - -void FontSettingsPage::updatePreview() -{ - if (d_ptr->m_curItem == -1) - return; - - const Format ¤tFormat = d_ptr->m_value.formatFor(d_ptr->m_descriptions[d_ptr->m_curItem].name()); - const Format &baseFormat = d_ptr->m_value.formatFor(QLatin1String("Text")); - - QPalette pal = QApplication::palette(); - if (baseFormat.foreground().isValid()) { - pal.setColor(QPalette::Text, baseFormat.foreground()); - pal.setColor(QPalette::Foreground, baseFormat.foreground()); - } - if (baseFormat.background().isValid()) - pal.setColor(QPalette::Base, baseFormat.background()); - - d_ptr->ui.previewTextEdit->setPalette(pal); - - QTextCharFormat format; - if (currentFormat.foreground().isValid()) - format.setForeground(QBrush(currentFormat.foreground())); - if (currentFormat.background().isValid()) - format.setBackground(QBrush(currentFormat.background())); - format.setFontFamily(d_ptr->ui.familyComboBox->currentText()); - format.setFontStyleStrategy(d_ptr->ui.antialias->isChecked() ? QFont::PreferAntialias : QFont::NoAntialias); - bool ok; - int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok); - if (!ok) { - size = QFont().pointSize(); - } - format.setFontPointSize(size); - format.setFontItalic(currentFormat.italic()); - if (currentFormat.bold()) - format.setFontWeight(QFont::Bold); - d_ptr->ui.previewTextEdit->setCurrentCharFormat(format); - - d_ptr->ui.previewTextEdit->setPlainText(tr("\n\tThis is only an example.")); -} - void FontSettingsPage::updatePointSizes() { const int oldSize = d_ptr->m_value.fontSize(); @@ -424,14 +255,32 @@ void FontSettingsPage::updatePointSizes() const QList sizeLst = db.pointSizes(d_ptr->ui.familyComboBox->currentText()); int idx = 0; int i = 0; - for (; 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); - updatePreview(); +} + +void FontSettingsPage::editColorScheme() +{ + d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText()); + d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked()); + + bool ok = true; + const int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok); + if (ok) + d_ptr->m_value.setFontSize(size); + + EditColorSchemeDialog dialog(d_ptr->m_descriptions, + d_ptr->m_value, + d_ptr->m_value.colorScheme(), + d_ptr->ui.editButton->window()); + + if (dialog.exec() == QDialog::Accepted) + d_ptr->m_value.setColorScheme(dialog.colorScheme()); } void FontSettingsPage::delayedChange() diff --git a/src/plugins/texteditor/fontsettingspage.h b/src/plugins/texteditor/fontsettingspage.h index c9d1c3dcaa1..17e00a0f2d4 100644 --- a/src/plugins/texteditor/fontsettingspage.h +++ b/src/plugins/texteditor/fontsettingspage.h @@ -109,13 +109,8 @@ signals: private slots: void delayedChange(); - void itemChanged(); - void changeForeColor(); - void changeBackColor(); - void eraseBackColor(); - void checkCheckBoxes(); void updatePointSizes(); - void updatePreview(); + void editColorScheme(); private: Internal::FontSettingsPagePrivate *d_ptr; diff --git a/src/plugins/texteditor/fontsettingspage.ui b/src/plugins/texteditor/fontsettingspage.ui index 543dc5ce3cc..799c2c0a8f9 100644 --- a/src/plugins/texteditor/fontsettingspage.ui +++ b/src/plugins/texteditor/fontsettingspage.ui @@ -6,18 +6,18 @@ 0 0 - 572 - 471 + 391 + 344 - + Font - - + + @@ -30,7 +30,7 @@ - + @@ -40,7 +40,7 @@ - + Qt::Horizontal @@ -56,7 +56,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -79,14 +79,7 @@ - - - - Antialias - - - - + Qt::Horizontal @@ -99,148 +92,71 @@ + + + + Antialias + + + - - - 0 - 0 - - Color Scheme - - - - - - 1 - 0 - + + + + + false + + + Import - - - - - - Bold - - - - - - - Italic - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - Background: - - - - - - - - 0 - 0 - - - - Foreground: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - 0 - - - - - - - - - - - Erase background - - - x - - - Qt::LeftArrow - - - - - - + + + + false + + + Export + + + + + + + false + + + Edit + + + + + + + Qt::Vertical + + + + 20 + 87 + + + + + + - - - - Preview: - - - - - - - true - - - diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index 32a0867755b..2a97349b756 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -27,7 +27,8 @@ SOURCES += texteditorplugin.cpp \ texteditorsettings.cpp \ codecselector.cpp \ findincurrentfile.cpp \ - colorscheme.cpp + colorscheme.cpp \ + editcolorschemedialog.cpp HEADERS += texteditorplugin.h \ textfilewizard.h \ plaintexteditor.h \ @@ -58,9 +59,11 @@ HEADERS += texteditorplugin.h \ texteditorsettings.h \ codecselector.h \ findincurrentfile.h \ - colorscheme.h + colorscheme.h \ + editcolorschemedialog.h FORMS += behaviorsettingspage.ui \ displaysettingspage.ui \ - fontsettingspage.ui + fontsettingspage.ui \ + editcolorschemedialog.ui RESOURCES += texteditor.qrc OTHER_FILES += TextEditor.pluginspec