FancyLineEdit: Visualize the disabled state

The painting code path for flat themes did not handle the disabled
state. This change catches up on that, and also suppresses the painting
of the hover border in disabled state.

Change-Id: I29d50be4549c81a25f976c61f6d4541862d2925e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alessandro Portale
2016-04-27 12:16:30 +02:00
parent 15543d5957
commit d7f8af9392

View File

@@ -454,6 +454,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
// Fill the line edit background // Fill the line edit background
QRectF backgroundRect = option->rect; QRectF backgroundRect = option->rect;
const bool enabled = option->state & State_Enabled;
if (Utils::creatorTheme()->widgetStyle() == Utils::Theme::StyleDefault) { if (Utils::creatorTheme()->widgetStyle() == Utils::Theme::StyleDefault) {
backgroundRect.adjust(1, 1, -1, -1); backgroundRect.adjust(1, 1, -1, -1);
painter->setBrushOrigin(backgroundRect.topLeft()); painter->setBrushOrigin(backgroundRect.topLeft());
@@ -464,15 +465,18 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
static const QImage bg_disabled(StyleHelper::dpiSpecificImageFile( static const QImage bg_disabled(StyleHelper::dpiSpecificImageFile(
QLatin1String(":/core/images/inputfield_disabled.png"))); QLatin1String(":/core/images/inputfield_disabled.png")));
const bool enabled = option->state & State_Enabled;
StyleHelper::drawCornerImage(enabled ? bg : bg_disabled, StyleHelper::drawCornerImage(enabled ? bg : bg_disabled,
painter, option->rect, 5, 5, 5, 5); painter, option->rect, 5, 5, 5, 5);
} else { } else {
painter->save();
if (!enabled)
painter->setOpacity(0.75);
painter->fillRect(backgroundRect, option->palette.base()); painter->fillRect(backgroundRect, option->palette.base());
painter->restore();
} }
const bool hasFocus = state & State_HasFocus; const bool hasFocus = state & State_HasFocus;
if (hasFocus || state & State_MouseOver) { if (enabled && (hasFocus || state & State_MouseOver)) {
QColor hover = StyleHelper::baseColor(); QColor hover = StyleHelper::baseColor();
hover.setAlpha(hasFocus ? 100 : 50); hover.setAlpha(hasFocus ? 100 : 50);
painter->setPen(QPen(hover, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); painter->setPen(QPen(hover, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));