diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index d22e1bc2160eecd9b061248a803ed7073d68d4b2..e11e9c75a8892ef5c5a5a5df8f6c2b3db294130b 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, + FrameHints hints ) const { painter->setRenderHint( QPainter::Antialiasing ); @@ -541,6 +542,19 @@ namespace Breeze if( color.isValid() ) painter->setBrush( color ); else painter->setBrush( Qt::NoBrush ); + if (hints & FrameHint::DoubleRing) { + 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 a27284828402c9b3f6b2f48b3b465743f6395113..77c4d7d0ee883e93f1f36c3fc49a39dadef0487c 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() ) 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/breezemetrics.h b/kstyle/breezemetrics.h index 742bd4b9683825bffd0342f48eb72970fb0a8b8a..0d24a5ee8c1abf334f95ebec200c61e6cc01dae9 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 51baf9fc65bf61a193c9616785b2ab0312ac558c..f5e12188fb421d5e18c946ac9162335fde0c50e0 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,39 @@ 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); + } 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 ); + + 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 +910,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; @@ -3162,10 +3197,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 +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 ); + _helper->renderFrame( painter, rect, background, outline, hasFocus ? Helper::FrameHint::DoubleRing : Helper::FrameHint::None ); } diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index 29dbfd076c7c4db49e86d8c5d283ccc8bfaebb34..33884a68dc77e2ceb6837c6fda1ec35197f1ce19 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;