diff --git a/components/qtmaterialtextfield.cpp b/components/qtmaterialtextfield.cpp index 4e1a8a3..97480c9 100644 --- a/components/qtmaterialtextfield.cpp +++ b/components/qtmaterialtextfield.cpp @@ -29,7 +29,7 @@ void QtMaterialTextFieldPrivate::init() label = 0; labelFontSize = 9.5; showLabel = false; - showUnderscore = true; + showUnderline = true; useThemeColors = true; q->setFrame(false); @@ -232,19 +232,24 @@ QColor QtMaterialTextField::underlineColor() const } } -void QtMaterialTextField::setShowUnderscore(bool value) +void QtMaterialTextField::setShowUnderline(bool value) { Q_D(QtMaterialTextField); - if (d->showUnderscore == value) { + if (d->showUnderline == value) { return; } - d->showUnderscore = value; - + d->showUnderline = value; update(); } +bool QtMaterialTextField::hasUnderline() const +{ + Q_D(const QtMaterialTextField); + + return d->showUnderline; +} /*! * \reimp @@ -289,8 +294,7 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event) const int y = height()-1; const int wd = width()-5; - - if( d->showUnderscore ) + if (d->showUnderline) { QPen pen; pen.setWidth(1); @@ -299,16 +303,16 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event) painter.setOpacity(1); painter.drawLine(2.5, y, wd, y); - QBrush brush; - brush.setStyle(Qt::SolidPattern); - brush.setColor(inkColor()); + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(inkColor()); - if (progress > 0) - { - painter.setPen(Qt::NoPen); - painter.setBrush(brush); - const int w = (1-progress)*static_cast(wd/2); - painter.drawRect(w+2.5, height()-2, wd-w*2, 2); - } + if (progress > 0) + { + painter.setPen(Qt::NoPen); + painter.setBrush(brush); + const int w = (1-progress)*static_cast(wd/2); + painter.drawRect(w+2.5, height()-2, wd-w*2, 2); + } } } diff --git a/components/qtmaterialtextfield.h b/components/qtmaterialtextfield.h index 6622515..d4a12f6 100644 --- a/components/qtmaterialtextfield.h +++ b/components/qtmaterialtextfield.h @@ -41,7 +41,9 @@ public: void setUnderlineColor(const QColor &color); QColor underlineColor() const; - void setShowUnderscore(bool value); + + void setShowUnderline(bool value); + bool hasUnderline() const; protected: bool event(QEvent *event) Q_DECL_OVERRIDE; diff --git a/components/qtmaterialtextfield_p.h b/components/qtmaterialtextfield_p.h index 7924a1d..51d7cc1 100644 --- a/components/qtmaterialtextfield_p.h +++ b/components/qtmaterialtextfield_p.h @@ -29,7 +29,7 @@ public: QString labelString; qreal labelFontSize; bool showLabel; - bool showUnderscore; + bool showUnderline; bool useThemeColors; };