chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -9,11 +9,9 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
ElaSpinBox::ElaSpinBox(QWidget* parent)
|
||||
: QSpinBox(parent), d_ptr(new ElaSpinBoxPrivate())
|
||||
{
|
||||
ElaSpinBox::ElaSpinBox(QWidget *parent) : QSpinBox(parent), d_ptr(new ElaSpinBoxPrivate()) {
|
||||
Q_D(ElaSpinBox);
|
||||
d->q_ptr = this;
|
||||
d->q_ptr = this;
|
||||
d->_pExpandMarkWidth = 0;
|
||||
setFixedSize(115, 35);
|
||||
d->_style = new ElaSpinBoxStyle(style());
|
||||
@@ -24,32 +22,26 @@ ElaSpinBox::ElaSpinBox(QWidget* parent)
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, d, &ElaSpinBoxPrivate::onThemeChanged);
|
||||
}
|
||||
|
||||
ElaSpinBox::~ElaSpinBox()
|
||||
{
|
||||
ElaSpinBox::~ElaSpinBox() {
|
||||
Q_D(ElaSpinBox);
|
||||
delete d->_style;
|
||||
}
|
||||
|
||||
void ElaSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode)
|
||||
{
|
||||
void ElaSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode) {
|
||||
Q_D(ElaSpinBox);
|
||||
if (minimumWidth() < 90)
|
||||
{
|
||||
if (minimumWidth() < 90) {
|
||||
setMinimumWidth(90);
|
||||
}
|
||||
d->_style->setButtonMode(buttonMode);
|
||||
switch (buttonMode)
|
||||
{
|
||||
case ElaSpinBoxType::Inline:
|
||||
{
|
||||
switch (buttonMode) {
|
||||
case ElaSpinBoxType::Inline: {
|
||||
lineEdit()->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
lineEdit()->setStyleSheet("background-color:transparent;padding-left:10px;padding-bottom:3px;");
|
||||
break;
|
||||
}
|
||||
case ElaSpinBoxType::Compact:
|
||||
case ElaSpinBoxType::Side:
|
||||
case ElaSpinBoxType::PMSide:
|
||||
{
|
||||
case ElaSpinBoxType::PMSide: {
|
||||
lineEdit()->setAlignment(Qt::AlignCenter);
|
||||
lineEdit()->setStyleSheet("background-color:transparent;padding-bottom:3px;");
|
||||
break;
|
||||
@@ -60,21 +52,16 @@ void ElaSpinBox::setButtonMode(ElaSpinBoxType::ButtonMode buttonMode)
|
||||
Q_EMIT pButtonModeChanged();
|
||||
}
|
||||
|
||||
ElaSpinBoxType::ButtonMode ElaSpinBox::getButtonMode() const
|
||||
{
|
||||
ElaSpinBoxType::ButtonMode ElaSpinBox::getButtonMode() const {
|
||||
Q_D(const ElaSpinBox);
|
||||
return d->_style->getButtonMode();
|
||||
}
|
||||
|
||||
void ElaSpinBox::focusInEvent(QFocusEvent* event)
|
||||
{
|
||||
void ElaSpinBox::focusInEvent(QFocusEvent *event) {
|
||||
Q_D(ElaSpinBox);
|
||||
if (event->reason() == Qt::MouseFocusReason)
|
||||
{
|
||||
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
|
||||
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
if (event->reason() == Qt::MouseFocusReason) {
|
||||
QPropertyAnimation *markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
|
||||
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
|
||||
markAnimation->setDuration(300);
|
||||
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
markAnimation->setStartValue(d->_pExpandMarkWidth);
|
||||
@@ -84,15 +71,11 @@ void ElaSpinBox::focusInEvent(QFocusEvent* event)
|
||||
QSpinBox::focusInEvent(event);
|
||||
}
|
||||
|
||||
void ElaSpinBox::focusOutEvent(QFocusEvent* event)
|
||||
{
|
||||
void ElaSpinBox::focusOutEvent(QFocusEvent *event) {
|
||||
Q_D(ElaSpinBox);
|
||||
if (event->reason() != Qt::PopupFocusReason)
|
||||
{
|
||||
QPropertyAnimation* markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
|
||||
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
if (event->reason() != Qt::PopupFocusReason) {
|
||||
QPropertyAnimation *markAnimation = new QPropertyAnimation(d, "pExpandMarkWidth");
|
||||
connect(markAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
|
||||
markAnimation->setDuration(300);
|
||||
markAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
markAnimation->setStartValue(d->_pExpandMarkWidth);
|
||||
@@ -102,11 +85,9 @@ void ElaSpinBox::focusOutEvent(QFocusEvent* event)
|
||||
QSpinBox::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void ElaSpinBox::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaSpinBox::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaSpinBox);
|
||||
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText))
|
||||
{
|
||||
if (palette().color(QPalette::Text) != ElaThemeColor(d->_themeMode, BasicText)) {
|
||||
d->onThemeChanged(d->_themeMode);
|
||||
}
|
||||
QSpinBox::paintEvent(event);
|
||||
@@ -119,36 +100,29 @@ void ElaSpinBox::paintEvent(QPaintEvent* event)
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
void ElaSpinBox::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
void ElaSpinBox::contextMenuEvent(QContextMenuEvent *event) {
|
||||
Q_D(ElaSpinBox);
|
||||
ElaMenu* menu = d->_createStandardContextMenu();
|
||||
if (!menu)
|
||||
{
|
||||
ElaMenu *menu = d->_createStandardContextMenu();
|
||||
if (!menu) {
|
||||
return;
|
||||
}
|
||||
menu->addSeparator();
|
||||
const uint se = stepEnabled();
|
||||
QAction* up = menu->addElaIconAction(ElaIconType::Plus, tr("增加"));
|
||||
QAction *up = menu->addElaIconAction(ElaIconType::Plus, tr("增加"));
|
||||
up->setEnabled(se & StepUpEnabled);
|
||||
QAction* down = menu->addElaIconAction(ElaIconType::Minus, tr("减少"));
|
||||
QAction *down = menu->addElaIconAction(ElaIconType::Minus, tr("减少"));
|
||||
down->setEnabled(se & StepDownEnabled);
|
||||
menu->addSeparator();
|
||||
|
||||
const QAbstractSpinBox* that = this;
|
||||
const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
|
||||
? event->globalPos()
|
||||
: mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
|
||||
const QAction* action = menu->exec(pos);
|
||||
const QAbstractSpinBox *that = this;
|
||||
const QPoint pos = (event->reason() == QContextMenuEvent::Mouse) ? event->globalPos()
|
||||
: mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
|
||||
const QAction *action = menu->exec(pos);
|
||||
delete menu;
|
||||
if (that && action)
|
||||
{
|
||||
if (action == up)
|
||||
{
|
||||
if (that && action) {
|
||||
if (action == up) {
|
||||
stepBy(1);
|
||||
}
|
||||
else if (action == down)
|
||||
{
|
||||
} else if (action == down) {
|
||||
stepBy(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user