Commit 2f351fe1 authored by Janet Blackquill's avatar Janet Blackquill 🌈
Browse files

[kstyle]: Add double-ringed focus for text fields

parent 3be21543
......@@ -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 );
......
......@@ -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;
......
......@@ -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
......
......@@ -39,6 +39,7 @@
#include <QPushButton>
#include <QRadioButton>
#include <QScrollBar>
#include <QSpinBox>
#include <QItemDelegate>
#include <QSplitterHandle>
#include <QTextEdit>
......@@ -518,14 +519,14 @@ namespace Breeze
// frame width
case PM_DefaultFrameWidth:
if( qobject_cast<const QMenu*>( widget ) ) return Metrics::Menu_FrameWidth;
if( qobject_cast<const QLineEdit*>( widget ) ) return Metrics::LineEdit_FrameWidth;
if( qobject_cast<const QLineEdit*>( 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<QSpinBox*>(wid->parent()) || qobject_cast<QComboBox*>(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<const QLineEdit*>(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 );
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment