Commit 51ed0da5 authored by Marco Bubke's avatar Marco Bubke Committed by David Schulz

TextEditor: Add fine control over the color scheme settings

You have seen always all setting but some settings had no meaning
because
only the foreground color is used. Now you can disable this settings so
it
is more clear what you can change.

Change-Id: I0fdd2ac6f40e27b5160a2c54a512289457674dae
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent b8ae9fd4
......@@ -83,7 +83,7 @@ public:
int rowCount(const QModelIndex &parent) const
{
return (parent.isValid() || !m_descriptions) ? 0 : m_descriptions->size();
return (parent.isValid() || !m_descriptions) ? 0 : int(m_descriptions->size());
}
QVariant data(const QModelIndex &index, int role) const
......@@ -132,7 +132,7 @@ public:
// If the text category changes, all indexes might have changed
if (i.row() == 0)
emit dataChanged(i, index(m_descriptions->size() - 1));
emit dataChanged(i, index(int(m_descriptions->size()) - 1));
else
emit dataChanged(i, i);
}
......@@ -244,28 +244,83 @@ void ColorSchemeEdit::currentItemChanged(const QModelIndex &index)
void ColorSchemeEdit::updateControls()
{
const Format &format = m_scheme.formatFor(m_descriptions[m_curItem].id());
updateForegroundControls();
updateBackgroundControls();
updateFontControls();
updateUnderlineControls();
}
void ColorSchemeEdit::updateForegroundControls()
{
const auto &formatDescription = m_descriptions[m_curItem];
const Format &format = m_scheme.formatFor(formatDescription.id());
bool isVisble = formatDescription.showControl(FormatDescription::ShowForegroundControl);
m_ui->foregroundLabel->setVisible(isVisble);
m_ui->foregroundToolButton->setVisible(isVisble);
m_ui->eraseForegroundToolButton->setVisible(isVisble);
m_ui->foregroundToolButton->setStyleSheet(colorButtonStyleSheet(format.foreground()));
m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background()));
m_ui->eraseForegroundToolButton->setEnabled(!m_readOnly
&& m_curItem > 0
&& format.foreground().isValid());
}
void ColorSchemeEdit::updateBackgroundControls()
{
const auto formatDescription = m_descriptions[m_curItem];
const Format &format = m_scheme.formatFor(formatDescription.id());
bool isVisble = formatDescription.showControl(FormatDescription::ShowBackgroundControl);
m_ui->backgroundLabel->setVisible(isVisble);
m_ui->backgroundToolButton->setVisible(isVisble);
m_ui->eraseBackgroundToolButton->setVisible(isVisble);
m_ui->backgroundToolButton->setStyleSheet(colorButtonStyleSheet(format.background()));
m_ui->eraseBackgroundToolButton->setEnabled(!m_readOnly
&& m_curItem > 0
&& format.background().isValid());
m_ui->eraseForegroundToolButton->setEnabled(!m_readOnly
&& m_curItem > 0
&& format.foreground().isValid());
}
void ColorSchemeEdit::updateFontControls()
{
const auto formatDescription = m_descriptions[m_curItem];
const Format &format = m_scheme.formatFor(formatDescription.id());
QSignalBlocker boldSignalBlocker(m_ui->boldCheckBox);
m_ui->boldCheckBox->setChecked(format.bold());
QSignalBlocker italicSignalBlocker(m_ui->italicCheckBox);
bool isVisble= formatDescription.showControl(FormatDescription::ShowFontControls);
m_ui->boldCheckBox->setVisible(isVisble);
m_ui->italicCheckBox->setVisible(isVisble);
m_ui->boldCheckBox->setChecked(format.bold());
m_ui->italicCheckBox->setChecked(format.italic());
}
void ColorSchemeEdit::updateUnderlineControls()
{
const auto formatDescription = m_descriptions[m_curItem];
const Format &format = m_scheme.formatFor(formatDescription.id());
QSignalBlocker comboBoxSignalBlocker(m_ui->underlineComboBox);
bool isVisble= formatDescription.showControl(FormatDescription::ShowFontControls);
m_ui->underlineLabel->setVisible(isVisble);
m_ui->underlineColorToolButton->setVisible(isVisble);
m_ui->eraseUnderlineColorToolButton->setVisible(isVisble);
m_ui->underlineComboBox->setVisible(isVisble);
m_ui->underlineColorToolButton->setStyleSheet(colorButtonStyleSheet(format.underlineColor()));
m_ui->eraseUnderlineColorToolButton->setEnabled(!m_readOnly
&& m_curItem > 0
&& format.underlineColor().isValid());
int index = m_ui->underlineComboBox->findData(QVariant::fromValue(int(format.underlineStyle())));
QSignalBlocker comboBoxSignalBlocker(m_ui->underlineComboBox);
m_ui->underlineComboBox->setCurrentIndex(index);
}
......
......@@ -78,6 +78,10 @@ private slots:
private:
void updateControls();
void updateForegroundControls();
void updateBackgroundControls();
void updateFontControls();
void updateUnderlineControls();
void setItemListBackground(const QColor &color);
void populateUnderlineStyleComboBox();
......
......@@ -56,7 +56,7 @@ class FormatDescription;
class TEXTEDITOR_EXPORT FontSettings
{
public:
typedef QList<FormatDescription> FormatDescriptions;
typedef std::vector<FormatDescription> FormatDescriptions;
FontSettings();
void clear();
......
......@@ -227,19 +227,29 @@ FontSettingsPagePrivate::~FontSettingsPagePrivate()
// ------- FormatDescription
FormatDescription::FormatDescription(TextStyle id, const QString &displayName, const QString &tooltipText, const QColor &foreground) :
m_id(id),
m_displayName(displayName),
m_tooltipText(tooltipText)
FormatDescription::FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const QColor &foreground,
FormatDescription::ShowControls showControls)
: m_id(id),
m_displayName(displayName),
m_tooltipText(tooltipText),
m_showControls(showControls)
{
m_format.setForeground(foreground);
}
FormatDescription::FormatDescription(TextStyle id, const QString &displayName, const QString &tooltipText, const Format &format) :
m_id(id),
m_format(format),
m_displayName(displayName),
m_tooltipText(tooltipText)
FormatDescription::FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const Format &format,
FormatDescription::ShowControls showControls)
: m_id(id),
m_format(format),
m_displayName(displayName),
m_tooltipText(tooltipText),
m_showControls(showControls)
{
}
......@@ -247,10 +257,12 @@ FormatDescription::FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const QColor &underlineColor,
const QTextCharFormat::UnderlineStyle underlineStyle)
const QTextCharFormat::UnderlineStyle underlineStyle,
FormatDescription::ShowControls showControls)
: m_id(id),
m_displayName(displayName),
m_tooltipText(tooltipText)
m_tooltipText(tooltipText),
m_showControls(showControls)
{
m_format.setForeground(QColor());
m_format.setBackground(QColor());
......@@ -258,6 +270,17 @@ FormatDescription::FormatDescription(TextStyle id,
m_format.setUnderlineStyle(underlineStyle);
}
FormatDescription::FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
FormatDescription::ShowControls showControls)
: m_id(id),
m_displayName(displayName),
m_tooltipText(tooltipText),
m_showControls(showControls)
{
}
QColor FormatDescription::foreground() const
{
if (m_id == C_LINE_NUMBER) {
......@@ -331,6 +354,11 @@ QColor FormatDescription::background() const
return QColor(); // invalid color
}
bool FormatDescription::showControl(FormatDescription::ShowControls showControl) const
{
return m_showControls & showControl;
}
// ------------ FontSettingsPage
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
Core::Id id,
......
......@@ -57,19 +57,37 @@ namespace Internal { class FontSettingsPagePrivate; }
class TEXTEDITOR_EXPORT FormatDescription
{
public:
enum ShowControls {
ShowForegroundControl = 0x1,
ShowBackgroundControl = 0x2,
ShowFontControls = 0x4,
ShowUnderlineControl = 0x8,
AllControls = 0xF,
AllControlsExceptUnderline = AllControls & ~ShowUnderlineControl,
};
FormatDescription() = default;
FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
ShowControls showControls = AllControls);
FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const QColor &foreground = Qt::black);
const QColor &foreground,
ShowControls showControls = AllControls);
FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const Format &format);
const Format &format,
ShowControls showControls = AllControls);
FormatDescription(TextStyle id,
const QString &displayName,
const QString &tooltipText,
const QColor &underlineColor,
const QTextCharFormat::UnderlineStyle underlineStyle);
const QTextCharFormat::UnderlineStyle underlineStyle,
ShowControls showControls = AllControls);
TextStyle id() const { return m_id; }
......@@ -85,14 +103,17 @@ public:
QString tooltipText() const
{ return m_tooltipText; }
bool showControl(ShowControls showControl) const;
private:
TextStyle m_id; // Name of the category
Format m_format; // Default format
QString m_displayName; // Displayed name of the category
QString m_tooltipText; // Description text for category
ShowControls m_showControls = AllControls;
};
typedef QList<FormatDescription> FormatDescriptions;
typedef std::vector<FormatDescription> FormatDescriptions;
class TEXTEDITOR_EXPORT FontSettingsPage : public TextEditorOptionsPage
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment