Skip to content

Commit

Permalink
fix: the line edit widget border color on focus state
Browse files Browse the repository at this point in the history
Change-Id: I56396eb491bcafbc7bd716b29d3d753b4d3c70cb
  • Loading branch information
zccrs committed Mar 14, 2018
1 parent ece14cd commit 4718470
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
10 changes: 8 additions & 2 deletions dstyleplugin/comboboxhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "geometryutils.h"

namespace dstyle {
extern PaletteExtended::PseudoClassType lineEditStateToPseudoClassType(QStyle::State state);

void Style::drawComboBoxPopupFramePrimitive(const QStyleOption *option, QPainter *painter) const {
const QRect rect( option->rect );
Expand Down Expand Up @@ -58,15 +59,15 @@ bool Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, c
{

if( editable ) {
flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth );
/*flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth );
if ( flat ) {
const QColor background( palette.color( QPalette::Base ) );
painter->setBrush( background );
painter->setPen( Qt::NoPen );
painter->drawRect( rect );
} else {
} else*/ {
proxy()->drawPrimitive( PE_FrameLineEdit, option, painter, widget );
}

Expand Down Expand Up @@ -95,6 +96,11 @@ bool Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, c
QRect arrowRect( proxy()->subControlRect( CC_ComboBox, option, SC_ComboBoxArrow, widget ) );

fillBrush(painter, arrowRect, brush);

if (editable) {
painter->setPen(QPen(m_palette->brush(PaletteExtended::LineEdit_BorderBrush, lineEditStateToPseudoClassType(option->state)), 1));
painter->drawLine(arrowRect.topLeft() - QPoint(1, 1), arrowRect.bottomLeft() + QPoint(-1, 1));
}
}

return option->subControls & (SC_ComboBoxFrame | SC_ComboBoxArrow);
Expand Down
22 changes: 20 additions & 2 deletions dstyleplugin/lineedithelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,37 @@

DWIDGET_USE_NAMESPACE
#endif
#include <QDebug>


namespace dstyle {

PaletteExtended::PseudoClassType lineEditStateToPseudoClassType(QStyle::State state)
{
if (!state.testFlag(QStyle::State_Enabled)) {
return PaletteExtended::PseudoClass_Disabled;
}

if (state.testFlag(QStyle::State_ReadOnly)) {
return PaletteExtended::PseudoClass_ReadOnly;
}

if (state.testFlag(QStyle::State_HasFocus)) {
return PaletteExtended::PseudoClass_Focus;
}

return PaletteExtended::PseudoClass_Unspecified;
}

bool Style::drawFrameLineEditPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
Q_UNUSED(widget)

const QRect& rect( option->rect );

// render
const QBrush background(m_palette->brush(PaletteExtended::LineEdit_BackgroundBrush, option) );
QBrush outline(m_palette->brush(PaletteExtended::LineEdit_BorderBrush, option) );
const QBrush background(m_palette->brush(PaletteExtended::LineEdit_BackgroundBrush, lineEditStateToPseudoClassType(option->state)) );
QBrush outline(m_palette->brush(PaletteExtended::LineEdit_BorderBrush, lineEditStateToPseudoClassType(option->state)) );

#ifdef DTKWIDGET_CLASS_DLineEdit
if (const DLineEdit *edit = qobject_cast<const DLineEdit*>(widget)) {
Expand Down
4 changes: 3 additions & 1 deletion dstyleplugin/spinboxhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <QDebug>

namespace dstyle {
extern PaletteExtended::PseudoClassType lineEditStateToPseudoClassType(QStyle::State state);

bool Style::drawSpinBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
const QStyleOptionSpinBox *sb( qstyleoption_cast<const QStyleOptionSpinBox*>( option ) );
Expand Down Expand Up @@ -117,7 +119,7 @@ bool Style::drawSpinBoxComplexControl( const QStyleOptionComplex* option, QPaint
proxy()->drawPrimitive(pe, &copy, painter, widget);
}

painter->setPen(QPen(m_palette->brush(PaletteExtended::SpinBox_BorderColor, option), Metrics::Painter_PenWidth));
painter->setPen(QPen(m_palette->brush(PaletteExtended::SpinBox_BorderColor, lineEditStateToPseudoClassType(option->state)), Metrics::Painter_PenWidth));
QRect lineEditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget).adjusted(0, -1, 0, 1);
painter->drawLine(lineEditRect.topRight(), lineEditRect.bottomRight());

Expand Down

0 comments on commit 4718470

Please sign in to comment.