Merge branch 'fperillo-textfield-underscore'

This commit is contained in:
johanneshilden 2017-10-05 17:39:28 +03:00
commit 64bbeae93e
6 changed files with 62 additions and 16 deletions

View File

@ -29,6 +29,7 @@ void QtMaterialTextFieldPrivate::init()
label = 0;
labelFontSize = 9.5;
showLabel = false;
showUnderline = true;
useThemeColors = true;
q->setFrame(false);
@ -231,6 +232,25 @@ QColor QtMaterialTextField::underlineColor() const
}
}
void QtMaterialTextField::setShowUnderline(bool value)
{
Q_D(QtMaterialTextField);
if (d->showUnderline == value) {
return;
}
d->showUnderline = value;
update();
}
bool QtMaterialTextField::hasUnderline() const
{
Q_D(const QtMaterialTextField);
return d->showUnderline;
}
/*!
* \reimp
*/
@ -274,22 +294,25 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event)
const int y = height()-1;
const int wd = width()-5;
QPen pen;
pen.setWidth(1);
pen.setColor(underlineColor());
painter.setPen(pen);
painter.setOpacity(1);
painter.drawLine(2.5, y, wd, y);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(inkColor());
if (progress > 0)
if (d->showUnderline)
{
painter.setPen(Qt::NoPen);
painter.setBrush(brush);
const int w = (1-progress)*static_cast<qreal>(wd/2);
painter.drawRect(w+2.5, height()-2, wd-w*2, 2);
QPen pen;
pen.setWidth(1);
pen.setColor(underlineColor());
painter.setPen(pen);
painter.setOpacity(1);
painter.drawLine(2.5, y, wd, y);
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<qreal>(wd/2);
painter.drawRect(w+2.5, height()-2, wd-w*2, 2);
}
}
}

View File

@ -42,6 +42,9 @@ public:
void setUnderlineColor(const QColor &color);
QColor underlineColor() const;
void setShowUnderline(bool value);
bool hasUnderline() const;
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

View File

@ -29,6 +29,7 @@ public:
QString labelString;
qreal labelFontSize;
bool showLabel;
bool showUnderline;
bool useThemeColors;
};

View File

@ -41,6 +41,7 @@ TextFieldSettingsEditor::TextFieldSettingsEditor(QWidget *parent)
connect(ui->inkColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->underlineColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->labelColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->underlineCheckBox, SIGNAL(toggled(bool)), this, SLOT(setShowUnderline()));
connect(m_textField, SIGNAL(textChanged(QString)), this, SLOT(setupForm()));
}
@ -58,6 +59,7 @@ void TextFieldSettingsEditor::setupForm()
ui->labelCheckBox->setChecked(m_textField->hasLabel());
ui->labelTextLineEdit->setText(m_textField->label());
ui->useThemeColorsCheckBox->setChecked(m_textField->useThemeColors());
ui->underlineCheckBox->setChecked(m_textField->hasUnderline());
}
void TextFieldSettingsEditor::updateWidget()
@ -68,6 +70,7 @@ void TextFieldSettingsEditor::updateWidget()
m_textField->setLabel(ui->labelTextLineEdit->text());
m_textField->setShowLabel(ui->labelCheckBox->isChecked());
m_textField->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked());
m_textField->setShowUnderline(ui->underlineCheckBox->isChecked());
}
void TextFieldSettingsEditor::selectColor()
@ -92,3 +95,8 @@ void TextFieldSettingsEditor::selectColor()
}
setupForm();
}
void TextFieldSettingsEditor::setShowUnderline()
{
m_textField->setShowUnderline( ui->underlineCheckBox->isChecked() );
}

View File

@ -18,6 +18,7 @@ protected slots:
void setupForm();
void updateWidget();
void selectColor();
void setShowUnderline();
private:
Ui::TextFieldSettingsForm *const ui;

View File

@ -167,6 +167,16 @@
</item>
</layout>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelShowUnderline">
<property name="text">
<string>Underline</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="underlineCheckBox"/>
</item>
</layout>
</widget>
</widget>