mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 15:38:11 +08:00
[UI] push button update
- Add child widget existency check when initializing UI - Prevent double triggering `onClick` signal - Add check on set child widget API
This commit is contained in:
parent
e88498cf20
commit
0bddabdf80
@ -23,9 +23,13 @@ void PushButton::initializeUI() {
|
||||
_stretchLayout->setContentsMargins(_contentMargin);
|
||||
_stretchLayout->setSpacing(0);
|
||||
_stretchLayout->setAlignment(Qt::AlignCenter);
|
||||
_stretchLayout->addWidget(_childWidget);
|
||||
setLayout(_stretchLayout);
|
||||
if (_childWidget) {
|
||||
// prevent adding a null widget
|
||||
_stretchLayout->addWidget(_childWidget);
|
||||
_childWidget->show();
|
||||
_childWidgetOriginalGeometry = _childWidget->geometry();
|
||||
}
|
||||
|
||||
// Initialize background widget
|
||||
_backgroundWidget = new QWidget(this);
|
||||
@ -241,6 +245,7 @@ void PushButton::mousePressEvent(QMouseEvent* event) {
|
||||
indicatorShrinkLength->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
_pressed = true;
|
||||
|
||||
emit onPressed();
|
||||
}
|
||||
|
||||
@ -291,9 +296,12 @@ void PushButton::mouseReleaseEvent(QMouseEvent* event) {
|
||||
}
|
||||
indicatorGrowLength->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
_pressed = false;
|
||||
|
||||
if (_pressed) {
|
||||
// prevent double trigger if mouse is first left and then released
|
||||
emit onClick();
|
||||
}
|
||||
|
||||
_pressed = false;
|
||||
}
|
||||
|
||||
void PushButton::resizeEvent(QResizeEvent* event) {
|
||||
@ -790,8 +798,11 @@ void PushButton::setChildWidget(QWidget* widget) {
|
||||
for (int i = 0; i < _stretchLayout->count(); i++) {
|
||||
_stretchLayout->removeItem(_stretchLayout->itemAt(i));
|
||||
}
|
||||
if (_childWidget != nullptr) {
|
||||
_stretchLayout->addWidget(_childWidget);
|
||||
_childWidget->show();
|
||||
_childWidgetOriginalGeometry = _childWidget->geometry();
|
||||
}
|
||||
}
|
||||
|
||||
bool PushButton::isSelected() const {
|
||||
|
||||
@ -19,12 +19,14 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
PushButton(QWidget* child, QWidget* parent = 0);
|
||||
PushButton(QWidget* child, QWidget* parent);
|
||||
~PushButton();
|
||||
|
||||
private:
|
||||
// Button Layout
|
||||
QWidget* _childWidget;
|
||||
QRect _childWidgetOriginalGeometry;
|
||||
const float _childWidgetShrinkRatio = 0.9;
|
||||
QHBoxLayout* _stretchLayout;
|
||||
QMargins _contentMargin = QMargins(12, 12, 12, 12);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user