From a260a77d9d6b7856278e2ee9b42623c469479d4e Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 22 Mar 2010 21:14:39 +0100 Subject: Fixing keypad navigation focus frame The QFocusFrame drawing code in QS60Style incorrectly assumed that PM_LayoutSpacing is always equal to PM_FocusFrameMargin. When these values diverged, the focus frame broke as described in task QTBUG-8036. The fix makes the drawing more robust. The focus frame width is never thicker than PM_LayoutSpacing and PM_FocusFrameMargin. And instead of drawing a roundRect with calculated pen width, we are now filling a roundRect. That makes the focusFrame more apparent. Task-number: QTBUG-8036 Reviewed-by: Sami Merila --- src/gui/styles/qs60style.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 750e19f..86812a6 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1964,11 +1964,6 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_MenuScroller: break; case CE_FocusFrame: { - // The pen width should nearly fill the layoutspacings around the widget - const int penWidth = - qMin(pixelMetric(QS60Style::PM_LayoutVerticalSpacing), pixelMetric(QS60Style::PM_LayoutHorizontalSpacing)) - - 2; // But keep 1 pixel distance to the focus widget and 1 pixel to the adjacent widgets - #ifdef QT_KEYPAD_NAVIGATION bool editFocus = false; if (const QFocusFrame *focusFrame = qobject_cast(widget)) { @@ -1979,25 +1974,27 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, #else const qreal opacity = 0.5; #endif - // Because of Qts coordinate system, we need to tweak the rect by .5 pixels, otherwise it gets blurred. - const qreal rectAdjustment = (penWidth % 2) ? -.5 : 0; - - // Make sure that the pen stroke is inside the rect - const QRectF adjustedRect = - QRectF(option->rect).adjusted( - rectAdjustment + penWidth, - rectAdjustment + penWidth, - -rectAdjustment - penWidth, - -rectAdjustment - penWidth - ); - - const qreal roundRectRadius = penWidth * goldenRatio; + // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin + // Otherwise, we would overlay adjacent widgets. + const int frameHeightReduction = + qMin(0, pixelMetric(QStyle::PM_LayoutVerticalSpacing) + - pixelMetric(QStyle::PM_FocusFrameVMargin)); + const int frameWidthReduction = + qMin(0, pixelMetric(QStyle::PM_LayoutHorizontalSpacing) + - pixelMetric(QStyle::PM_FocusFrameHMargin)); + const int rounding = + qMin(pixelMetric(QStyle::PM_FocusFrameVMargin), + pixelMetric(QStyle::PM_LayoutVerticalSpacing)); + const QRect frameRect = + option->rect.adjusted(-frameWidthReduction, -frameHeightReduction, + frameWidthReduction, frameHeightReduction); + QPainterPath framePath; + framePath.addRoundedRect(frameRect, rounding, rounding); painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->setOpacity(opacity); - painter->setPen(QPen(option->palette.color(QPalette::Text), penWidth)); - painter->drawRoundedRect(adjustedRect, roundRectRadius, roundRectRadius); + painter->fillPath(framePath, option->palette.color(QPalette::Text)); painter->restore(); } break; -- cgit v0.12 From 9b363e44f372fee183290e010ceecf9e75282ce2 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 22 Mar 2010 21:36:54 +0100 Subject: Increase KeypadNavigation focus visibility The focus frame was drawn with a low opacity. That was intended meant to increase aesthetics but in reality decreased usability. Now, the opacity is higher. But still with a difference between navigation mode and edit mode. Task-number: QT-826 Reviewed-by: Sami Merila --- src/gui/styles/qs60style.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 86812a6..6448417 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -1970,9 +1970,9 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, if (focusFrame->widget() && focusFrame->widget()->hasEditFocus()) editFocus = true; } - const qreal opacity = editFocus ? 0.65 : 0.45; // Trial and error factors. Feel free to improve. + const qreal opacity = editFocus ? 1 : 0.75; // Trial and error factors. Feel free to improve. #else - const qreal opacity = 0.5; + const qreal opacity = 0.85; #endif // We need to reduce the focus frame size if LayoutSpacing is smaller than FocusFrameMargin // Otherwise, we would overlay adjacent widgets. -- cgit v0.12