From 897a393627a764b354475887ee7cff9fcb4360eb Mon Sep 17 00:00:00 2001 From: Carson Black Date: Tue, 1 Sep 2020 18:22:07 -0400 Subject: [PATCH 1/4] [kstyle]: Add double-ringed focus for text fields --- kstyle/breezehelper.cpp | 16 +++++++++++++- kstyle/breezehelper.h | 2 +- kstyle/breezemetrics.h | 9 ++++++-- kstyle/breezestyle.cpp | 49 +++++++++++++++++++++++++++++++++++------ kstyle/breezestyle.h | 1 + 5 files changed, 66 insertions(+), 11 deletions(-) diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index d22e1bc2..35fe444b 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -515,7 +515,8 @@ namespace Breeze //______________________________________________________________________________ void Helper::renderFrame( QPainter* painter, const QRect& rect, - const QColor& color, const QColor& outline ) const + const QColor& color, const QColor& outline, + bool doubleRinged ) const { painter->setRenderHint( QPainter::Antialiasing ); @@ -541,6 +542,19 @@ namespace Breeze if( color.isValid() ) painter->setBrush( color ); else painter->setBrush( Qt::NoBrush ); + if ( doubleRinged ) { + painter->save(); + { + auto rect2 = frameRect.adjusted( -2, -2, 2, 2 ); + painter->setPen( Qt::NoPen ); + painter->setBrush( outline ); + painter->setOpacity( 0.4 ); + + painter->drawRoundedRect(rect2, radius*2, radius*2); + } + painter->restore(); + } + // render painter->drawRoundedRect( frameRect, radius, radius ); diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index a2728482..96642a11 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -165,7 +165,7 @@ namespace Breeze void renderFocusLine( QPainter*, const QRect&, const QColor& ) const; //* generic frame - void renderFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline = QColor() ) const; + void renderFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline = QColor(), bool doubleRinged = false ) const; //* side panel frame void renderSidePanelFrame( QPainter*, const QRect&, const QColor& outline, Side ) const; diff --git a/kstyle/breezemetrics.h b/kstyle/breezemetrics.h index 742bd4b9..0d24a5ee 100644 --- a/kstyle/breezemetrics.h +++ b/kstyle/breezemetrics.h @@ -44,7 +44,12 @@ namespace Breeze static constexpr int Layout_DefaultSpacing = 6; // line editors - static constexpr int LineEdit_FrameWidth = 6; + struct LineEdit { + static constexpr int FrameWidth = 6; + static constexpr int Margin = 2; + + static constexpr int TotalExpansion = FrameWidth + Margin; + }; // menu items static constexpr int Menu_FrameWidth = 0; @@ -58,7 +63,7 @@ namespace Breeze static constexpr int ComboBox_FrameWidth = 6; // spinbox - static constexpr int SpinBox_FrameWidth = LineEdit_FrameWidth; + static constexpr int SpinBox_FrameWidth = LineEdit::TotalExpansion; static constexpr int SpinBox_ArrowButtonWidth = 20; // groupbox title margin diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 51baf9fc..a11ed690 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -518,14 +519,14 @@ namespace Breeze // frame width case PM_DefaultFrameWidth: if( qobject_cast( widget ) ) return Metrics::Menu_FrameWidth; - if( qobject_cast( widget ) ) return Metrics::LineEdit_FrameWidth; + if( qobject_cast( widget ) ) return Metrics::LineEdit::TotalExpansion; else if( isQtQuickControl( option, widget ) ) { const QString &elementType = option->styleObject->property( "elementType" ).toString(); if( elementType == QLatin1String( "edit" ) || elementType == QLatin1String( "spinbox" ) ) { - return Metrics::LineEdit_FrameWidth; + return Metrics::LineEdit::TotalExpansion; } else if( elementType == QLatin1String( "combobox" ) ) { @@ -540,7 +541,7 @@ namespace Breeze case PM_ComboBoxFrameWidth: { const auto comboBoxOption( qstyleoption_cast< const QStyleOptionComboBox*>( option ) ); - return comboBoxOption && comboBoxOption->editable ? Metrics::LineEdit_FrameWidth : Metrics::ComboBox_FrameWidth; + return comboBoxOption && comboBoxOption->editable ? Metrics::LineEdit::TotalExpansion : Metrics::ComboBox_FrameWidth; } case PM_SpinBoxFrameWidth: return Metrics::SpinBox_FrameWidth; @@ -864,6 +865,37 @@ namespace Breeze } + bool Style::drawPanelLineEditPrimitive( const QStyleOption* opts, QPainter* painter, const QWidget* wid ) const + { + if (wid != nullptr) { + if (qobject_cast(wid->parent()) || qobject_cast(wid->parent())) { + return true; + } + } + + + auto rect = opts->rect.adjusted( Metrics::LineEdit::Margin, Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin ); + auto palette = opts->palette; + + if (qobject_cast(wid)) { + rect.adjust(1, 1, -1, -1); + } + + auto radius = _helper->frameRadius( PenWidth::NoPen, -1 ); + + painter->save(); + { + painter->setPen(QPen(palette.button().color())); + painter->setBrush(palette.button()); + painter->drawRoundedRect(rect, radius, radius); + } + painter->restore(); + + drawFrameLineEditPrimitive(opts, painter, wid); + + return true; + } + //______________________________________________________________ void Style::drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { @@ -876,6 +908,7 @@ namespace Breeze case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break; case PE_PanelScrollAreaCorner: fcn = &Style::drawPanelScrollAreaCornerPrimitive; break; case PE_PanelMenu: fcn = &Style::drawPanelMenuPrimitive; break; + case PE_PanelLineEdit: fcn = &Style::drawPanelLineEditPrimitive; break; case PE_PanelTipLabel: fcn = &Style::drawPanelTipLabelPrimitive; break; case PE_PanelItemViewItem: fcn = &Style::drawPanelItemViewItemPrimitive; break; case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break; @@ -3149,7 +3182,7 @@ namespace Breeze const auto background( isTitleWidget ? palette.color( widget->backgroundRole() ):QColor() ); const auto outline( _helper->frameOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); - _helper->renderFrame( painter, rect, background, outline ); + _helper->renderFrame( painter, rect, background, outline, hasFocus ); } @@ -3162,10 +3195,12 @@ namespace Breeze { // copy palette and rect const auto& palette( option->palette ); - const auto& rect( option->rect ); + auto rect( option->rect ); + + rect.adjust( Metrics::LineEdit::Margin, Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin ); // make sure there is enough room to render frame - if( rect.height() < 2*Metrics::LineEdit_FrameWidth + option->fontMetrics.height()) + if( rect.height() < 2*Metrics::LineEdit::FrameWidth + option->fontMetrics.height()) { const auto &background = palette.color( QPalette::Base ); @@ -3194,7 +3229,7 @@ namespace Breeze // render const auto &background = palette.color( QPalette::Base ); const auto outline( hasHighlightNeutral( widget, option, mouseOver, hasFocus ) ? _helper->neutralText( palette ) : _helper->frameOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); - _helper->renderFrame( painter, rect, background, outline ); + _helper->renderFrame( painter, rect, background, outline, hasFocus ); } diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index 29dbfd07..33884a68 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -234,6 +234,7 @@ namespace Breeze { return true; } bool drawFramePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawPanelLineEditPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameLineEditPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameFocusRectPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; -- GitLab From 1e4a67c69dbb7317b28350390b4150e6906ae2b7 Mon Sep 17 00:00:00 2001 From: Carson Black Date: Tue, 1 Sep 2020 21:57:12 -0400 Subject: [PATCH 2/4] Don't render double ring for frames in general --- kstyle/breezestyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index a11ed690..0bedca74 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -3182,7 +3182,7 @@ namespace Breeze const auto background( isTitleWidget ? palette.color( widget->backgroundRole() ):QColor() ); const auto outline( _helper->frameOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); - _helper->renderFrame( painter, rect, background, outline, hasFocus ); + _helper->renderFrame( painter, rect, background, outline ); } -- GitLab From 56e82d65ad74428257e758d223b4f54e017263bd Mon Sep 17 00:00:00 2001 From: Carson Black Date: Tue, 1 Sep 2020 22:37:04 -0400 Subject: [PATCH 3/4] Adjust rectangle on QML correctly --- kstyle/breezestyle.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 0bedca74..06a76a43 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -879,6 +879,8 @@ namespace Breeze if (qobject_cast(wid)) { rect.adjust(1, 1, -1, -1); + } else if (wid == nullptr) { + rect.adjust(Metrics::LineEdit::Margin, Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin, -Metrics::LineEdit::Margin); } auto radius = _helper->frameRadius( PenWidth::NoPen, -1 ); -- GitLab From 8d157c806f1504d254e7242da975fc7d9fd7e8b8 Mon Sep 17 00:00:00 2001 From: Carson Black Date: Wed, 18 Nov 2020 14:41:15 -0500 Subject: [PATCH 4/4] flags --- kstyle/breezehelper.cpp | 4 ++-- kstyle/breezehelper.h | 10 +++++++++- kstyle/breezestyle.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index 35fe444b..e11e9c75 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -516,7 +516,7 @@ namespace Breeze void Helper::renderFrame( QPainter* painter, const QRect& rect, const QColor& color, const QColor& outline, - bool doubleRinged ) const + FrameHints hints ) const { painter->setRenderHint( QPainter::Antialiasing ); @@ -542,7 +542,7 @@ namespace Breeze if( color.isValid() ) painter->setBrush( color ); else painter->setBrush( Qt::NoBrush ); - if ( doubleRinged ) { + if (hints & FrameHint::DoubleRing) { painter->save(); { auto rect2 = frameRect.adjusted( -2, -2, 2, 2 ); diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index 96642a11..77c4d7d0 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -33,6 +33,14 @@ namespace Breeze public: + enum class FrameHint { + None = 0, + DoubleRing = 1, + }; + + Q_ENUM(FrameHint) + Q_DECLARE_FLAGS(FrameHints, FrameHint) + //* constructor explicit Helper( KSharedConfig::Ptr, QObject *parent = nullptr ); @@ -165,7 +173,7 @@ namespace Breeze void renderFocusLine( QPainter*, const QRect&, const QColor& ) const; //* generic frame - void renderFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline = QColor(), bool doubleRinged = false ) const; + void renderFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline = QColor(), FrameHints hints = FrameHint::None ) const; //* side panel frame void renderSidePanelFrame( QPainter*, const QRect&, const QColor& outline, Side ) const; diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 06a76a43..f5e12188 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -3231,7 +3231,7 @@ namespace Breeze // render const auto &background = palette.color( QPalette::Base ); const auto outline( hasHighlightNeutral( widget, option, mouseOver, hasFocus ) ? _helper->neutralText( palette ) : _helper->frameOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); - _helper->renderFrame( painter, rect, background, outline, hasFocus ); + _helper->renderFrame( painter, rect, background, outline, hasFocus ? Helper::FrameHint::DoubleRing : Helper::FrameHint::None ); } -- GitLab