diff options
author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-07-17 17:24:32 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-07-20 17:08:02 +0200 |
commit | 60905c485fb132b2c949605eb2248c3ed86abc87 (patch) | |
tree | 914c266a9405bfaaa516d2c4f883018c4c318d4a /src/plugins | |
parent | 68c920d1d4a0792214c632d93f87dcdbd82e7d0a (diff) | |
download | qt-creator-60905c485fb132b2c949605eb2248c3ed86abc87.tar.gz |
Embedded the color scheme editor in the options dialog again
With the new representation it fits fine, and this is a bit more
convenient for the user.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/texteditor/colorscheme.cpp | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/colorscheme.h | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/colorschemeedit.cpp (renamed from src/plugins/texteditor/editcolorschemedialog.cpp) | 137 | ||||
-rw-r--r-- | src/plugins/texteditor/colorschemeedit.h (renamed from src/plugins/texteditor/editcolorschemedialog.h) | 37 | ||||
-rw-r--r-- | src/plugins/texteditor/colorschemeedit.ui | 157 | ||||
-rw-r--r-- | src/plugins/texteditor/editcolorschemedialog.ui | 217 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettings.cpp | 1 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettings.h | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.cpp | 114 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.h | 8 | ||||
-rw-r--r-- | src/plugins/texteditor/fontsettingspage.ui | 56 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.pro | 6 |
12 files changed, 367 insertions, 373 deletions
diff --git a/src/plugins/texteditor/colorscheme.cpp b/src/plugins/texteditor/colorscheme.cpp index e937d15f05..cb298f102c 100644 --- a/src/plugins/texteditor/colorscheme.cpp +++ b/src/plugins/texteditor/colorscheme.cpp @@ -128,7 +128,7 @@ void ColorScheme::clear() m_formats.clear(); } -bool ColorScheme::save(const QString &fileName) +bool ColorScheme::save(const QString &fileName) const { QFile file(fileName); if (!file.open(QIODevice::WriteOnly)) diff --git a/src/plugins/texteditor/colorscheme.h b/src/plugins/texteditor/colorscheme.h index 692692c499..0b4e726d17 100644 --- a/src/plugins/texteditor/colorscheme.h +++ b/src/plugins/texteditor/colorscheme.h @@ -99,7 +99,7 @@ public: void clear(); - bool save(const QString &fileName); + bool save(const QString &fileName) const; bool load(const QString &fileName); inline bool equals(const ColorScheme &cs) const diff --git a/src/plugins/texteditor/editcolorschemedialog.cpp b/src/plugins/texteditor/colorschemeedit.cpp index 207cd50e43..07b4020ef0 100644 --- a/src/plugins/texteditor/editcolorschemedialog.cpp +++ b/src/plugins/texteditor/colorschemeedit.cpp @@ -27,8 +27,8 @@ ** **************************************************************************/ -#include "editcolorschemedialog.h" -#include "ui_editcolorschemedialog.h" +#include "colorschemeedit.h" +#include "ui_colorschemeedit.h" #include "texteditorconstants.h" @@ -54,42 +54,64 @@ namespace Internal { class FormatsModel : public QAbstractListModel { public: - FormatsModel(const FormatDescriptions &fd, - const FontSettings &fontSettings, - const ColorScheme &scheme, - QObject *parent = 0): + FormatsModel(QObject *parent = 0): QAbstractListModel(parent), - m_fd(fd), - m_scheme(scheme), - m_baseFont(fontSettings.family(), fontSettings.fontSize()) + m_descriptions(0), + m_scheme(0) { } + void setFormatDescriptions(const FormatDescriptions *descriptions) + { + m_descriptions = descriptions; + reset(); + } + + void setBaseFont(const QFont &font) + { + emit layoutAboutToBeChanged(); // So the view adjust to new item height + m_baseFont = font; + emit layoutChanged(); + emitDataChanged(index(0)); + } + + void setColorScheme(const ColorScheme *scheme) + { + m_scheme = scheme; + emitDataChanged(index(0)); + } + int rowCount(const QModelIndex &parent) const - { return parent.isValid() ? 0 : m_fd.size(); } + { + return (parent.isValid() || !m_descriptions) ? 0 : m_descriptions->size(); + } QVariant data(const QModelIndex &index, int role) const { - const FormatDescription &description = m_fd.at(index.row()); + if (!m_descriptions || !m_scheme) + return QVariant(); + + const FormatDescription &description = m_descriptions->at(index.row()); + switch (role) { case Qt::DisplayRole: return description.trName(); case Qt::ForegroundRole: { - QColor foreground = m_scheme.formatFor(description.name()).foreground(); + QColor foreground = m_scheme->formatFor(description.name()).foreground(); if (foreground.isValid()) return foreground; else - return m_scheme.formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).foreground(); + return m_scheme->formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).foreground(); } case Qt::BackgroundRole: { - QColor background = m_scheme.formatFor(description.name()).background(); + QColor background = m_scheme->formatFor(description.name()).background(); if (background.isValid()) return background; } case Qt::FontRole: { QFont font = m_baseFont; - font.setBold(m_scheme.formatFor(description.name()).bold()); - font.setItalic(m_scheme.formatFor(description.name()).italic()); + font.setBold(m_scheme->formatFor(description.name()).bold()); + font.setItalic(m_scheme->formatFor(description.name()).italic()); return font; } } @@ -98,69 +120,98 @@ public: void emitDataChanged(const QModelIndex &i) { + if (!m_descriptions) + return; + // If the text category changes, all indexes might have changed if (i.row() == 0) - emit dataChanged(i, index(m_fd.size() - 1)); + emit dataChanged(i, index(m_descriptions->size() - 1)); else emit dataChanged(i, i); } private: - const FormatDescriptions &m_fd; - const ColorScheme &m_scheme; - const QFont m_baseFont; + const FormatDescriptions *m_descriptions; + const ColorScheme *m_scheme; + QFont m_baseFont; }; } // namespace Internal } // namespace TextEditor -EditColorSchemeDialog::EditColorSchemeDialog(const FormatDescriptions &fd, - const FontSettings &fontSettings, - QWidget *parent) : - QDialog(parent), - m_descriptions(fd), - m_fontSettings(fontSettings), - m_scheme(fontSettings.colorScheme()), +ColorSchemeEdit::ColorSchemeEdit(QWidget *parent) : + QWidget(parent), m_curItem(-1), - m_ui(new Ui::EditColorSchemeDialog), - m_formatsModel(new FormatsModel(m_descriptions, m_fontSettings, m_scheme, this)) + m_ui(new Ui::ColorSchemeEdit), + m_formatsModel(new FormatsModel(this)) { m_ui->setupUi(this); - m_ui->nameEdit->setText(m_scheme.name()); m_ui->itemList->setModel(m_formatsModel); connect(m_ui->itemList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - SLOT(itemChanged(QModelIndex))); + SLOT(currentItemChanged(QModelIndex))); 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())); +} + +ColorSchemeEdit::~ColorSchemeEdit() +{ + delete m_ui; +} + +void ColorSchemeEdit::setFormatDescriptions(const FormatDescriptions &descriptions) +{ + m_descriptions = descriptions; + m_formatsModel->setFormatDescriptions(&m_descriptions); if (!m_descriptions.empty()) m_ui->itemList->setCurrentIndex(m_formatsModel->index(0)); +} - setItemListBackground(m_scheme.formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).background()); +void ColorSchemeEdit::setBaseFont(const QFont &font) +{ + m_formatsModel->setBaseFont(font); } -EditColorSchemeDialog::~EditColorSchemeDialog() +void ColorSchemeEdit::setReadOnly(bool readOnly) { - delete m_ui; + const bool enabled = !readOnly; + m_ui->foregroundLabel->setEnabled(enabled); + m_ui->foregroundToolButton->setEnabled(enabled); + m_ui->backgroundLabel->setEnabled(enabled); + m_ui->backgroundToolButton->setEnabled(enabled); + m_ui->eraseBackgroundToolButton->setEnabled(enabled); + m_ui->boldCheckBox->setEnabled(enabled); + m_ui->italicCheckBox->setEnabled(enabled); } -void EditColorSchemeDialog::accept() +void ColorSchemeEdit::setColorScheme(const ColorScheme &colorScheme) { - m_scheme.setName(m_ui->nameEdit->text()); - QDialog::accept(); + m_scheme = colorScheme; + m_formatsModel->setColorScheme(&m_scheme); + setItemListBackground(m_scheme.formatFor(QLatin1String(TextEditor::Constants::C_TEXT)).background()); + updateControls(); } -void EditColorSchemeDialog::itemChanged(const QModelIndex &index) +const ColorScheme &ColorSchemeEdit::colorScheme() const +{ + return m_scheme; +} + +void ColorSchemeEdit::currentItemChanged(const QModelIndex &index) { if (!index.isValid()) return; m_curItem = index.row(); + updateControls(); +} +void ColorSchemeEdit::updateControls() +{ const Format &format = m_scheme.formatFor(m_descriptions[m_curItem].name()); m_ui->foregroundToolButton->setStyleSheet(colorButtonStyleSheet(format.foreground())); m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background())); @@ -175,7 +226,7 @@ void EditColorSchemeDialog::itemChanged(const QModelIndex &index) m_ui->italicCheckBox->blockSignals(italicBlocked); } -void EditColorSchemeDialog::changeForeColor() +void ColorSchemeEdit::changeForeColor() { if (m_curItem == -1) return; @@ -194,7 +245,7 @@ void EditColorSchemeDialog::changeForeColor() } } -void EditColorSchemeDialog::changeBackColor() +void ColorSchemeEdit::changeBackColor() { if (m_curItem == -1) return; @@ -215,7 +266,7 @@ void EditColorSchemeDialog::changeBackColor() } } -void EditColorSchemeDialog::eraseBackColor() +void ColorSchemeEdit::eraseBackColor() { if (m_curItem == -1) return; @@ -230,7 +281,7 @@ void EditColorSchemeDialog::eraseBackColor() } } -void EditColorSchemeDialog::checkCheckBoxes() +void ColorSchemeEdit::checkCheckBoxes() { if (m_curItem == -1) return; @@ -243,7 +294,7 @@ void EditColorSchemeDialog::checkCheckBoxes() } } -void EditColorSchemeDialog::setItemListBackground(const QColor &color) +void ColorSchemeEdit::setItemListBackground(const QColor &color) { QPalette pal = m_ui->itemList->palette(); pal.setColor(QPalette::Base, color); diff --git a/src/plugins/texteditor/editcolorschemedialog.h b/src/plugins/texteditor/colorschemeedit.h index ef637aea54..f3a89a3ada 100644 --- a/src/plugins/texteditor/editcolorschemedialog.h +++ b/src/plugins/texteditor/colorschemeedit.h @@ -27,8 +27,8 @@ ** **************************************************************************/ -#ifndef EDITCOLORSCHEMEDIALOG_H -#define EDITCOLORSCHEMEDIALOG_H +#ifndef COLORSCHEMEEDIT_H +#define COLORSCHEMEEDIT_H #include "colorscheme.h" #include "fontsettingspage.h" @@ -43,43 +43,44 @@ namespace TextEditor { namespace Internal { namespace Ui { -class EditColorSchemeDialog; +class ColorSchemeEdit; } class FormatsModel; -class EditColorSchemeDialog : public QDialog +/*! + A widget for editing a color scheme. Used in the FontSettingsPage. + */ +class ColorSchemeEdit : public QWidget { Q_OBJECT public: - EditColorSchemeDialog(const FormatDescriptions &fd, - const FontSettings &fontSettings, - QWidget *parent = 0); - ~EditColorSchemeDialog(); + ColorSchemeEdit(QWidget *parent = 0); + ~ColorSchemeEdit(); - ColorScheme colorScheme() const - { return m_scheme; } + void setFormatDescriptions(const FormatDescriptions &descriptions); + void setBaseFont(const QFont &font); + void setReadOnly(bool readOnly); - void accept(); + void setColorScheme(const ColorScheme &colorScheme); + const ColorScheme &colorScheme() const; private slots: - void itemChanged(const QModelIndex &index); + void currentItemChanged(const QModelIndex &index); void changeForeColor(); void changeBackColor(); void eraseBackColor(); void checkCheckBoxes(); private: + void updateControls(); void setItemListBackground(const QColor &color); - const TextEditor::FormatDescriptions m_descriptions; - const FontSettings m_fontSettings; - + TextEditor::FormatDescriptions m_descriptions; ColorScheme m_scheme; int m_curItem; - - Ui::EditColorSchemeDialog *m_ui; + Ui::ColorSchemeEdit *m_ui; FormatsModel *m_formatsModel; }; @@ -87,4 +88,4 @@ private: } // namespace Internal } // namespace TextEditor -#endif // EDITCOLORSCHEMEDIALOG_H +#endif // COLORSCHEMEEDIT_H diff --git a/src/plugins/texteditor/colorschemeedit.ui b/src/plugins/texteditor/colorschemeedit.ui new file mode 100644 index 0000000000..d9f342d439 --- /dev/null +++ b/src/plugins/texteditor/colorschemeedit.ui @@ -0,0 +1,157 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TextEditor::Internal::ColorSchemeEdit</class> + <widget class="QWidget" name="TextEditor::Internal::ColorSchemeEdit"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>435</width> + <height>210</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QListView" name="itemList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + <property name="uniformItemSizes"> + <bool>true</bool> + </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="backgroundLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Background:</string> + </property> + <property name="buddy"> + <cstring>backgroundToolButton</cstring> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="foregroundLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Foreground:</string> + </property> + <property name="buddy"> + <cstring>foregroundToolButton</cstring> + </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> + <tabstops> + <tabstop>itemList</tabstop> + <tabstop>foregroundToolButton</tabstop> + <tabstop>backgroundToolButton</tabstop> + <tabstop>eraseBackgroundToolButton</tabstop> + <tabstop>boldCheckBox</tabstop> + <tabstop>italicCheckBox</tabstop> + </tabstops> + <resources/> + <connections/> +</ui> diff --git a/src/plugins/texteditor/editcolorschemedialog.ui b/src/plugins/texteditor/editcolorschemedialog.ui deleted file mode 100644 index a23d8e2ca2..0000000000 --- a/src/plugins/texteditor/editcolorschemedialog.ui +++ /dev/null @@ -1,217 +0,0 @@ -<?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>461</width> - <height>352</height> - </rect> - </property> - <property name="windowTitle"> - <string>Edit Color Scheme</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Name</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLineEdit" name="nameEdit"/> - </item> - </layout> - </widget> - </item> - <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="QListView" name="itemList"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>1</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - <property name="uniformItemSizes"> - <bool>true</bool> - </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="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> - <tabstops> - <tabstop>nameEdit</tabstop> - <tabstop>itemList</tabstop> - <tabstop>foregroundToolButton</tabstop> - <tabstop>backgroundToolButton</tabstop> - <tabstop>eraseBackgroundToolButton</tabstop> - <tabstop>boldCheckBox</tabstop> - <tabstop>italicCheckBox</tabstop> - <tabstop>buttonBox</tabstop> - </tabstops> - <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.cpp b/src/plugins/texteditor/fontsettings.cpp index 5ad025d815..cc71afbbba 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -258,6 +258,7 @@ bool FontSettings::loadColorScheme(const QString &fileName, if (!m_scheme.load(m_schemeFileName)) { loaded = false; + m_schemeFileName.clear(); qWarning() << "Failed to load color scheme:" << fileName; } diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h index 9e55aed5b0..c32fc78c9c 100644 --- a/src/plugins/texteditor/fontsettings.h +++ b/src/plugins/texteditor/fontsettings.h @@ -77,6 +77,9 @@ public: int fontSize() const; void setFontSize(int size); + QFont font() const + { return QFont(family(), fontSize()); } + bool antialias() const; void setAntialias(bool antialias); diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index b6f371594e..bbadbfacf3 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -29,7 +29,7 @@ #include "fontsettingspage.h" -#include "editcolorschemedialog.h" +#include "colorschemeedit.h" #include "fontsettings.h" #include "texteditorconstants.h" #include "ui_fontsettingspage.h" @@ -130,6 +130,7 @@ public: FontSettings m_lastValue; Ui::FontSettingsPage ui; SchemeListModel *m_schemeListModel; + bool m_refreshingSchemeList; }; } // namespace Internal @@ -178,7 +179,8 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescrip m_category(category), m_trCategory(trCategory), m_descriptions(fd), - m_schemeListModel(new SchemeListModel) + m_schemeListModel(new SchemeListModel), + m_refreshingSchemeList(false) { bool settingsFound = false; QSettings *settings = Core::ICore::instance()->settings(); @@ -346,10 +348,14 @@ 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())); + 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))); connect(d_ptr->ui.schemeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(colorSchemeSelected(int))); - connect(d_ptr->ui.cloneButton, SIGNAL(clicked()), this, SLOT(cloneColorScheme())); - connect(d_ptr->ui.editButton, SIGNAL(clicked()), this, SLOT(editColorScheme())); + connect(d_ptr->ui.copyButton, SIGNAL(clicked()), this, SLOT(copyColorScheme())); connect(d_ptr->ui.deleteButton, SIGNAL(clicked()), this, SLOT(deleteColorScheme())); updatePointSizes(); @@ -358,8 +364,16 @@ QWidget *FontSettingsPage::createPage(QWidget *parent) return w; } +void FontSettingsPage::fontFamilySelected(const QString &family) +{ + d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText()); + d_ptr->ui.schemeEdit->setBaseFont(d_ptr->m_value.font()); + updatePointSizes(); +} + void FontSettingsPage::updatePointSizes() { + // Update point sizes const int oldSize = d_ptr->m_value.fontSize(); if (d_ptr->ui.sizeComboBox->count()) { const QString curSize = d_ptr->ui.sizeComboBox->currentText(); @@ -382,19 +396,35 @@ void FontSettingsPage::updatePointSizes() d_ptr->ui.sizeComboBox->setCurrentIndex(idx); } +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()); + } +} + void FontSettingsPage::colorSchemeSelected(int index) { - bool modifiable = false; + bool readOnly = true; if (index != -1) { + // Check whether we're switching away from a changed color scheme + if (!d_ptr->m_refreshingSchemeList) + maybeSaveColorScheme(); + const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index); - modifiable = !entry.readOnly; + readOnly = entry.readOnly; + d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions); + d_ptr->ui.schemeEdit->setColorScheme(d_ptr->m_value.colorScheme()); } - d_ptr->ui.cloneButton->setEnabled(index != -1); - d_ptr->ui.deleteButton->setEnabled(modifiable); - d_ptr->ui.editButton->setEnabled(modifiable); + d_ptr->ui.copyButton->setEnabled(index != -1); + d_ptr->ui.deleteButton->setEnabled(!readOnly); + d_ptr->ui.schemeEdit->setReadOnly(readOnly); } -void FontSettingsPage::cloneColorScheme() +void FontSettingsPage::copyColorScheme() { int index = d_ptr->ui.schemeComboBox->currentIndex(); if (index == -1) @@ -402,15 +432,17 @@ void FontSettingsPage::cloneColorScheme() const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index); - // Load the currently selected color scheme - if (!d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions)) - return; - QString baseFileName = QFileInfo(entry.fileName).completeBaseName(); baseFileName += QLatin1String("_copy%1.xml"); QString fileName = createColorSchemeFileName(baseFileName); if (!fileName.isEmpty()) { + // 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()); + ColorScheme scheme = d_ptr->m_value.colorScheme(); scheme.setName(tr("%1 (copy)").arg(scheme.name())); scheme.save(fileName); @@ -439,37 +471,19 @@ void FontSettingsPage::deleteColorScheme() } } -void FontSettingsPage::editColorScheme() +void FontSettingsPage::maybeSaveColorScheme() { - int index = d_ptr->ui.schemeComboBox->currentIndex(); - if (index == -1) + if (d_ptr->m_value.colorScheme() == d_ptr->ui.schemeEdit->colorScheme()) return; - const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index); - - if (entry.readOnly) - return; - - 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); - - if (!d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions)) - return; - - EditColorSchemeDialog dialog(d_ptr->m_descriptions, - d_ptr->m_value, - d_ptr->ui.editButton->window()); - - if (dialog.exec() == QDialog::Accepted) { - ColorScheme newColorScheme = dialog.colorScheme(); - newColorScheme.save(entry.fileName); - d_ptr->m_value.setColorScheme(newColorScheme); - refreshColorSchemeList(); + int ret = QMessageBox::warning(d_ptr->ui.schemeComboBox->window(), + 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, QMessageBox::Save); + if (ret == QMessageBox::Save) { + const ColorScheme &scheme = d_ptr->ui.schemeEdit->colorScheme(); + scheme.save(d_ptr->m_value.colorSchemeFileName()); } } @@ -500,8 +514,10 @@ void FontSettingsPage::refreshColorSchemeList() colorSchemes.append(ColorSchemeEntry(fileName, false)); } + d_ptr->m_refreshingSchemeList = true; d_ptr->m_schemeListModel->setColorSchemes(colorSchemes); d_ptr->ui.schemeComboBox->setCurrentIndex(selected); + d_ptr->m_refreshingSchemeList = false; } void FontSettingsPage::delayedChange() @@ -511,9 +527,15 @@ void FontSettingsPage::delayedChange() void FontSettingsPage::apply() { - d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText()); d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked()); + 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()); + } + int index = d_ptr->ui.schemeComboBox->currentIndex(); if (index != -1) { const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index); @@ -521,10 +543,6 @@ void FontSettingsPage::apply() d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions); } - bool ok = true; - const int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok); - if (ok) - d_ptr->m_value.setFontSize(size); saveSettings(); } diff --git a/src/plugins/texteditor/fontsettingspage.h b/src/plugins/texteditor/fontsettingspage.h index 5ffc34218c..1d71c88b16 100644 --- a/src/plugins/texteditor/fontsettingspage.h +++ b/src/plugins/texteditor/fontsettingspage.h @@ -109,13 +109,15 @@ signals: private slots: void delayedChange(); - void updatePointSizes(); + void fontFamilySelected(const QString &family); + void fontSizeSelected(const QString &sizeString); void colorSchemeSelected(int index); - void cloneColorScheme(); + void copyColorScheme(); void deleteColorScheme(); - void editColorScheme(); private: + void maybeSaveColorScheme(); + void updatePointSizes(); void refreshColorSchemeList(); Internal::FontSettingsPagePrivate *d_ptr; diff --git a/src/plugins/texteditor/fontsettingspage.ui b/src/plugins/texteditor/fontsettingspage.ui index 2ff5268962..3bf055ccfc 100644 --- a/src/plugins/texteditor/fontsettingspage.ui +++ b/src/plugins/texteditor/fontsettingspage.ui @@ -121,9 +121,9 @@ </widget> </item> <item> - <widget class="QPushButton" name="cloneButton"> + <widget class="QPushButton" name="copyButton"> <property name="text"> - <string>Clone</string> + <string>Copy</string> </property> </widget> </item> @@ -140,50 +140,28 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QPushButton" name="editButton"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Edit</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>87</height> - </size> + <widget class="TextEditor::Internal::ColorSchemeEdit" name="schemeEdit" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> + <horstretch>0</horstretch> + <verstretch>1</verstretch> + </sizepolicy> </property> - </spacer> + </widget> </item> </layout> </widget> </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>TextEditor::Internal::ColorSchemeEdit</class> + <extends>QWidget</extends> + <header>colorschemeedit.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> <connections/> </ui> diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index 2a97349b75..38c5861d0b 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -28,7 +28,7 @@ SOURCES += texteditorplugin.cpp \ codecselector.cpp \ findincurrentfile.cpp \ colorscheme.cpp \ - editcolorschemedialog.cpp + colorschemeedit.cpp HEADERS += texteditorplugin.h \ textfilewizard.h \ plaintexteditor.h \ @@ -60,10 +60,10 @@ HEADERS += texteditorplugin.h \ codecselector.h \ findincurrentfile.h \ colorscheme.h \ - editcolorschemedialog.h + colorschemeedit.h FORMS += behaviorsettingspage.ui \ displaysettingspage.ui \ fontsettingspage.ui \ - editcolorschemedialog.ui + colorschemeedit.ui RESOURCES += texteditor.qrc OTHER_FILES += TextEditor.pluginspec |