QmlJSEditor: refining the QuickToolBar for text

If font.bold/font.italic etc. are set to anything,
but a literal boolean, the button gets disabled, now.
This prevents the user from accidentally overiding
bindinds.
This commit is contained in:
Thomas Hartmann
2010-08-13 14:01:30 +02:00
parent abdda35966
commit 502ac08edb

View File

@@ -86,6 +86,11 @@ ContextPaneTextWidget::ContextPaneTextWidget(QWidget *parent) :
connect(ui->styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onStyleComboBoxChanged(QString))); connect(ui->styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onStyleComboBoxChanged(QString)));
} }
static inline bool checkIfBoolean(QVariant v)
{
return (v.toString() == "true" || v.toString() == "false");
}
void ContextPaneTextWidget::setProperties(QmlJS::PropertyReader *propertyReader) void ContextPaneTextWidget::setProperties(QmlJS::PropertyReader *propertyReader)
{ {
if (propertyReader->hasProperty(QLatin1String("font.pointSize"))) { if (propertyReader->hasProperty(QLatin1String("font.pointSize"))) {
@@ -113,26 +118,46 @@ void ContextPaneTextWidget::setProperties(QmlJS::PropertyReader *propertyReader)
ui->fontSizeSpinBox->setIsPixelSize(true); ui->fontSizeSpinBox->setIsPixelSize(true);
} }
ui->boldButton->setEnabled(true);
if (propertyReader->hasProperty(QLatin1String("font.bold"))) { if (propertyReader->hasProperty(QLatin1String("font.bold"))) {
ui->boldButton->setChecked(propertyReader->readProperty(QLatin1String("font.bold")).toBool()); QVariant v = propertyReader->readProperty(QLatin1String("font.bold"));
if (checkIfBoolean(v))
ui->boldButton->setChecked(v.toBool());
else
ui->boldButton->setEnabled(false);
} else { } else {
ui->boldButton->setChecked(false); ui->boldButton->setChecked(false);
} }
ui->italicButton->setEnabled(true);
if (propertyReader->hasProperty(QLatin1String("font.italic"))) { if (propertyReader->hasProperty(QLatin1String("font.italic"))) {
ui->italicButton->setChecked(propertyReader->readProperty(QLatin1String("font.italic")).toBool()); QVariant v = propertyReader->readProperty(QLatin1String("font.italic"));
if (checkIfBoolean(v))
ui->italicButton->setChecked(v.toBool());
else
ui->italicButton->setEnabled(false);
} else { } else {
ui->italicButton->setChecked(false); ui->italicButton->setChecked(false);
} }
ui->underlineButton->setEnabled(true);
if (propertyReader->hasProperty(QLatin1String("font.underline"))) { if (propertyReader->hasProperty(QLatin1String("font.underline"))) {
ui->underlineButton->setChecked(propertyReader->readProperty(QLatin1String("font.underline")).toBool()); QVariant v = propertyReader->readProperty(QLatin1String("font.underline"));
if (checkIfBoolean(v))
ui->underlineButton->setChecked(v.toBool());
else
ui->underlineButton->setEnabled(false);
} else { } else {
ui->underlineButton->setChecked(false); ui->underlineButton->setChecked(false);
} }
ui->strikeoutButton->setEnabled(true);
if (propertyReader->hasProperty(QLatin1String("font.strikeout"))) { if (propertyReader->hasProperty(QLatin1String("font.strikeout"))) {
ui->strikeoutButton->setChecked(propertyReader->readProperty(QLatin1String("font.strikeout")).toBool()); QVariant v = propertyReader->readProperty(QLatin1String("font.strikeout"));
if (checkIfBoolean(v))
ui->strikeoutButton->setChecked(v.toBool());
else
ui->strikeoutButton->setEnabled(false);
} else { } else {
ui->strikeoutButton->setChecked(false); ui->strikeoutButton->setChecked(false);
} }