Update painter code to take into account text alignment

This commit is contained in:
johanneshilden 2017-10-12 09:51:53 +03:00
parent 7c608fad0f
commit f72cb03f0b
2 changed files with 29 additions and 2 deletions

View File

@ -694,7 +694,11 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter)
}
if (icon().isNull()) {
painter->drawText(rect(), Qt::AlignCenter, text());
if (Qt::AlignLeft == d->textAlignment) {
painter->drawText(rect().adjusted(12, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text());
} else {
painter->drawText(rect(), Qt::AlignCenter, text());
}
return;
}
@ -702,7 +706,7 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter)
QSize base(size()-textSize);
const int iw = iconSize().width() + IconPadding;
QPoint pos((base.width()-iw)/2, 0);
QPoint pos(Qt::AlignLeft == d->textAlignment ? 12 : (base.width()-iw)/2, 0);
QRect textGeometry(pos + QPoint(0, base.height()/2), textSize);
QRect iconGeometry(pos + QPoint(0, (height()-iconSize().height())/2), iconSize());

View File

@ -80,6 +80,15 @@ void FlatButtonSettingsEditor::setupForm()
break;
}
switch (ui->textAlignmentComboBox->currentIndex())
{
case Qt::AlignLeft:
ui->textAlignmentComboBox->setCurrentIndex(0);
break;
default:
ui->textAlignmentComboBox->setCurrentIndex(1);
}
ui->checkedCheckBox->setEnabled(m_button->isCheckable());
ui->disabledCheckBox->setChecked(!m_button->isEnabled());
@ -155,6 +164,17 @@ void FlatButtonSettingsEditor::updateWidget()
break;
}
switch (ui->textAlignmentComboBox->currentIndex())
{
case 0:
m_button->setTextAlignment(Qt::AlignLeft);
break;
case 1:
default:
m_button->setTextAlignment(Qt::AlignHCenter);
break;
}
m_button->setDisabled(ui->disabledCheckBox->isChecked());
m_button->setCheckable(ui->checkableCheckBox->isChecked());
m_button->setChecked(ui->checkedCheckBox->isChecked());
@ -213,6 +233,7 @@ void FlatButtonSettingsEditor::applyDefaultPreset()
m_button->setHaloVisible(true);
m_button->setCheckable(false);
m_button->setEnabled(true);
m_button->setTextAlignment(Qt::AlignHCenter);
m_button->applyPreset(Material::FlatPreset);
setupForm();
}
@ -231,6 +252,7 @@ void FlatButtonSettingsEditor::applyCheckablePreset()
m_button->setHaloVisible(true);
m_button->setCheckable(true);
m_button->setEnabled(true);
m_button->setTextAlignment(Qt::AlignHCenter);
m_button->applyPreset(Material::CheckablePreset);
setupForm();
}
@ -269,6 +291,7 @@ void FlatButtonSettingsEditor::init()
connect(ui->rippleStyleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->hoverStyleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->iconPlacementComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->textAlignmentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->cornerRadiusSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
connect(ui->overlayOpacityDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidget()));
connect(ui->iconSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));