summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-06-18 17:35:46 +0200
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-07-13 14:22:27 +0200
commit0e70a1e85e3b3f05e6aed4f8d67360b29f777792 (patch)
treea1a3043c357d4fb147b1ada63b480edacbc971ef
parentcc730442d6a74632219be96d8974db29955a913b (diff)
downloadqt-creator-0e70a1e85e3b3f05e6aed4f8d67360b29f777792.tar.gz
Moved editing of the color scheme into a separate dialog
In preparation of being able to select from multiple color schemes.
-rw-r--r--src/plugins/texteditor/colorscheme.h3
-rw-r--r--src/plugins/texteditor/editcolorschemedialog.cpp215
-rw-r--r--src/plugins/texteditor/editcolorschemedialog.h81
-rw-r--r--src/plugins/texteditor/editcolorschemedialog.ui231
-rw-r--r--src/plugins/texteditor/fontsettings.h8
-rw-r--r--src/plugins/texteditor/fontsettingspage.cpp205
-rw-r--r--src/plugins/texteditor/fontsettingspage.h7
-rw-r--r--src/plugins/texteditor/fontsettingspage.ui204
-rw-r--r--src/plugins/texteditor/texteditor.pro9
9 files changed, 631 insertions, 332 deletions
diff --git a/src/plugins/texteditor/colorscheme.h b/src/plugins/texteditor/colorscheme.h
index e333d6b128..cc327bdfcd 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 0000000000..0fc58ea21c
--- /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 <QtGui/QColorDialog>
+
+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<QListWidgetItem*> 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<QListWidgetItem*> 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<QListWidgetItem*> 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<QListWidgetItem*> 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 &currentFormat = 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 0000000000..d727b2eb15
--- /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 <QtGui/QDialog>
+
+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 0000000000..4810a5c8d3
--- /dev/null
+++ b/src/plugins/texteditor/editcolorschemedialog.ui
@@ -0,0 +1,231 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TextEditor::Internal::EditColorSchemeDialog</class>
+ <widget class="QDialog" name="TextEditor::Internal::EditColorSchemeDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>462</width>
+ <height>416</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Edit Color Scheme</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>1</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Text Categories</string>
+ </property>
+ <layout class="QHBoxLayout">
+ <item>
+ <widget class="QListWidget" name="itemListWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="_2">
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="boldCheckBox">
+ <property name="text">
+ <string>Bold</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="italicCheckBox">
+ <property name="text">
+ <string>Italic</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QToolButton" name="foregroundToolButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Background:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Foreground:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QToolButton" name="backgroundToolButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="eraseBackgroundToolButton">
+ <property name="toolTip">
+ <string>Erase background</string>
+ </property>
+ <property name="text">
+ <string>x</string>
+ </property>
+ <property name="arrowType">
+ <enum>Qt::LeftArrow</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Preview:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="previewTextEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>100</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>10</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>TextEditor::Internal::EditColorSchemeDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>TextEditor::Internal::EditColorSchemeDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h
index 20eb325beb..c74524b618 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 c19d950f51..6d5a5f4e2f 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 <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtGui/QCheckBox>
-#include <QtGui/QColorDialog>
#include <QtGui/QComboBox>
#include <QtGui/QFontDatabase>
#include <QtGui/QListWidget>
@@ -48,16 +49,6 @@
#include <QtGui/QTextEdit>
#include <QtGui/QToolButton>
-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<QListWidgetItem*> 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<QListWidgetItem*> 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<QListWidgetItem*> 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<QListWidgetItem*> 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 &currentFormat = 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<int> sizeLst = db.pointSizes(d_ptr->ui.familyComboBox->currentText());
int idx = 0;
int i = 0;
- for (; i<sizeLst.count(); ++i) {
+ for (; i < sizeLst.count(); ++i) {
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);
- 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 c9d1c3dcaa..17e00a0f2d 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 543dc5ce3c..799c2c0a8f 100644
--- a/src/plugins/texteditor/fontsettingspage.ui
+++ b/src/plugins/texteditor/fontsettingspage.ui
@@ -6,18 +6,18 @@
<rect>
<x>0</x>
<y>0</y>
- <width>572</width>
- <height>471</height>
+ <width>391</width>
+ <height>344</height>
</rect>
</property>
- <layout class="QVBoxLayout">
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Font</string>
</property>
- <layout class="QHBoxLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -30,7 +30,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="0" column="1">
<widget class="QComboBox" name="familyComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -40,7 +40,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="0" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -56,7 +56,7 @@
</property>
</spacer>
</item>
- <item>
+ <item row="0" column="3">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -69,7 +69,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="0" column="4">
<widget class="QComboBox" name="sizeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -79,14 +79,7 @@
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="antialias">
- <property name="text">
- <string>Antialias</string>
- </property>
- </widget>
- </item>
- <item>
+ <item row="0" column="5">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -99,148 +92,71 @@
</property>
</spacer>
</item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QCheckBox" name="antialias">
+ <property name="text">
+ <string>Antialias</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
<property name="title">
<string>Color Scheme</string>
</property>
- <layout class="QHBoxLayout">
- <item>
- <widget class="QListWidget" name="itemListWidget">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="1">
+ <widget class="QPushButton" name="importButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Import</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="exportButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Export</string>
</property>
</widget>
</item>
- <item>
- <layout class="QGridLayout">
- <item row="2" column="0">
- <widget class="QCheckBox" name="boldCheckBox">
- <property name="text">
- <string>Bold</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QCheckBox" name="italicCheckBox">
- <property name="text">
- <string>Italic</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QToolButton" name="foregroundToolButton">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_2">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Background:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Foreground:</string>
- </property>
- </widget>
- </item>
- <item row="3" column="1">
- <spacer>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="1" column="1">
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QToolButton" name="backgroundToolButton">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="eraseBackgroundToolButton">
- <property name="toolTip">
- <string>Erase background</string>
- </property>
- <property name="text">
- <string>x</string>
- </property>
- <property name="arrowType">
- <enum>Qt::LeftArrow</enum>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="editButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Edit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>87</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0" rowspan="4">
+ <widget class="QListWidget" name="schemeListWidget"/>
</item>
</layout>
</widget>
</item>
- <item>
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>Preview:</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QTextEdit" name="previewTextEdit">
- <property name="readOnly">
- <bool>true</bool>
- </property>
- </widget>
- </item>
</layout>
</widget>
<resources/>
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index 32a0867755..2a97349b75 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