Skip to content

Commit

Permalink
feat(style): draw alert border on DLineEdit
Browse files Browse the repository at this point in the history
Change-Id: Ib598ff9d74cf71fa23cdafd2fac16c458e98d9c7
  • Loading branch information
zccrs committed Mar 6, 2018
1 parent 8cf9a91 commit 810ebed
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions dstyleplugin/brushschemes/ddark.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ PushButton:flat:hover {
LineEdit {
BackgroundBrush: rgba(255,255,255,0.15);
BorderBrush: transparent;
AlertBorderBrush: "#FF8F00";
}

LineEdit:disabled {
Expand Down
1 change: 1 addition & 0 deletions dstyleplugin/brushschemes/dlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ PushButton:flat:pressed {
LineEdit {
BackgroundBrush: rgb(255,255,255);
BorderBrush: rgba(0,0,0,0.1);
AlertBorderBrush: "#FF8F00";
}

LineEdit:disabled {
Expand Down
1 change: 1 addition & 0 deletions dstyleplugin/brushschemes/dsemidark.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ PushButton:flat:hover {
LineEdit {
BackgroundBrush: rgba(255,255,255,0.15);
BorderBrush: transparent;
AlertBorderBrush: "#FF8F00";
}

LineEdit:disabled {
Expand Down
1 change: 1 addition & 0 deletions dstyleplugin/brushschemes/dsemilight.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ PushButton:flat:pressed {
LineEdit {
BackgroundBrush: rgb(255,255,255);
BorderBrush: rgba(0,0,0,0.1);
AlertBorderBrush: "#FF8F00";
}

LineEdit:disabled {
Expand Down
2 changes: 1 addition & 1 deletion dstyleplugin/commonhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void CommonHelper::renderFrame(QPainter *painter, const QRect &rect, const QBrus
painter->setBrush( brush );

// render
painter->drawRoundedRect( frameRect, radius, radius );
painter->drawRoundedRect( frameRect.adjusted(0.5, 0.5, -0.5, -0.5), radius, radius );
}

Style *CommonHelper::widgetStyle(const QWidget *widget)
Expand Down
34 changes: 32 additions & 2 deletions dstyleplugin/lineedithelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
#include "style.h"
#include "paletteextended.h"

#include <dtkwidget_config.h>
#ifdef DTKWIDGET_CLASS_DStyleOptionLineEdit
#include <DStyleOptionLineEdit>
#include <DLineEdit>

DWIDGET_USE_NAMESPACE
#endif


namespace dstyle {

bool Style::drawFrameLineEditPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const
Expand All @@ -30,8 +39,29 @@ bool Style::drawFrameLineEditPrimitive(const QStyleOption *option, QPainter *pai

// render
const QBrush background(m_palette->brush(PaletteExtended::LineEdit_BackgroundBrush, option) );
const QBrush outline(m_palette->brush(PaletteExtended::LineEdit_BorderBrush, option) );
CommonHelper::renderFrame( painter, rect, background, outline );
QBrush outline(m_palette->brush(PaletteExtended::LineEdit_BorderBrush, option) );

#ifdef DTKWIDGET_CLASS_DLineEdit
if (const DLineEdit *edit = qobject_cast<const DLineEdit*>(widget)) {
DStyleOptionLineEdit edit_option;
edit_option.init(const_cast<DLineEdit*>(edit));

if (edit_option.features.testFlag(DStyleOptionLineEdit::Alert))
outline = m_palette->brush(PaletteExtended::LineEdit_AlertBorderBrush, option, PaletteExtended::PseudoClass_Unknown, outline);

CommonHelper::renderFrame( painter, rect, background, outline );

if (edit_option.features.testFlag(DStyleOptionLineEdit::IconButton)) {
painter->save();
painter->setPen(QPen(outline, Metrics::Painter_PenWidth));
painter->drawLine(QPointF(edit_option.iconButtonRect.topLeft()) - QPointF(0.5, 0), QPointF(edit_option.iconButtonRect.bottomLeft()) + QPoint(-0.5, 1));
painter->restore();
}
} else
#endif
{
CommonHelper::renderFrame( painter, rect, background, outline );
}

return true;
}
Expand Down
1 change: 1 addition & 0 deletions dstyleplugin/paletteextended.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PaletteExtended : public QObject
PushButton_SuggestTextColor,

LineEdit_BorderBrush,
LineEdit_AlertBorderBrush,
LineEdit_BackgroundBrush,

Menu_SeparatorColor,
Expand Down

0 comments on commit 810ebed

Please sign in to comment.