Update painter code to take into account text alignment
This commit is contained in:
parent
7c608fad0f
commit
f72cb03f0b
|
@ -694,7 +694,11 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon().isNull()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,7 +706,7 @@ void QtMaterialFlatButton::paintForeground(QPainter *painter)
|
||||||
QSize base(size()-textSize);
|
QSize base(size()-textSize);
|
||||||
|
|
||||||
const int iw = iconSize().width() + IconPadding;
|
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 textGeometry(pos + QPoint(0, base.height()/2), textSize);
|
||||||
QRect iconGeometry(pos + QPoint(0, (height()-iconSize().height())/2), iconSize());
|
QRect iconGeometry(pos + QPoint(0, (height()-iconSize().height())/2), iconSize());
|
||||||
|
|
|
@ -80,6 +80,15 @@ void FlatButtonSettingsEditor::setupForm()
|
||||||
break;
|
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->checkedCheckBox->setEnabled(m_button->isCheckable());
|
||||||
|
|
||||||
ui->disabledCheckBox->setChecked(!m_button->isEnabled());
|
ui->disabledCheckBox->setChecked(!m_button->isEnabled());
|
||||||
|
@ -155,6 +164,17 @@ void FlatButtonSettingsEditor::updateWidget()
|
||||||
break;
|
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->setDisabled(ui->disabledCheckBox->isChecked());
|
||||||
m_button->setCheckable(ui->checkableCheckBox->isChecked());
|
m_button->setCheckable(ui->checkableCheckBox->isChecked());
|
||||||
m_button->setChecked(ui->checkedCheckBox->isChecked());
|
m_button->setChecked(ui->checkedCheckBox->isChecked());
|
||||||
|
@ -213,6 +233,7 @@ void FlatButtonSettingsEditor::applyDefaultPreset()
|
||||||
m_button->setHaloVisible(true);
|
m_button->setHaloVisible(true);
|
||||||
m_button->setCheckable(false);
|
m_button->setCheckable(false);
|
||||||
m_button->setEnabled(true);
|
m_button->setEnabled(true);
|
||||||
|
m_button->setTextAlignment(Qt::AlignHCenter);
|
||||||
m_button->applyPreset(Material::FlatPreset);
|
m_button->applyPreset(Material::FlatPreset);
|
||||||
setupForm();
|
setupForm();
|
||||||
}
|
}
|
||||||
|
@ -231,6 +252,7 @@ void FlatButtonSettingsEditor::applyCheckablePreset()
|
||||||
m_button->setHaloVisible(true);
|
m_button->setHaloVisible(true);
|
||||||
m_button->setCheckable(true);
|
m_button->setCheckable(true);
|
||||||
m_button->setEnabled(true);
|
m_button->setEnabled(true);
|
||||||
|
m_button->setTextAlignment(Qt::AlignHCenter);
|
||||||
m_button->applyPreset(Material::CheckablePreset);
|
m_button->applyPreset(Material::CheckablePreset);
|
||||||
setupForm();
|
setupForm();
|
||||||
}
|
}
|
||||||
|
@ -269,6 +291,7 @@ void FlatButtonSettingsEditor::init()
|
||||||
connect(ui->rippleStyleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
|
connect(ui->rippleStyleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
|
||||||
connect(ui->hoverStyleComboBox, 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->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->cornerRadiusSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
|
||||||
connect(ui->overlayOpacityDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidget()));
|
connect(ui->overlayOpacityDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidget()));
|
||||||
connect(ui->iconSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
|
connect(ui->iconSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
|
||||||
|
|
Loading…
Reference in New Issue