Delay show and hide of macro controls

This commit is contained in:
WarmUpTill 2022-01-29 03:36:59 +01:00 committed by WarmUpTill
parent 7a34c334bd
commit 487c735e13
4 changed files with 33 additions and 2 deletions

View File

@ -23,6 +23,7 @@ signals:
void Down();
private:
bool _visible = false;
QPushButton *_add;
QPushButton *_remove;
QPushButton *_up;

View File

@ -1,5 +1,6 @@
#pragma once
#include <QWidget>
#include <QTimer>
#include <obs.hpp>
class Macro;
@ -46,6 +47,8 @@ protected slots:
void Up();
void Down();
void Collapsed(bool);
void ShowControls();
void HideControls();
signals:
void MacroAdded(const QString &name);
void MacroRemoved(const QString &name);
@ -67,6 +70,8 @@ protected:
MacroEntryControls *_controls;
private:
QTimer _enterTimer;
QTimer _leaveTimer;
virtual MacroSegment *Data() = 0;
};

View File

@ -64,7 +64,11 @@ MacroEntryControls::MacroEntryControls(const int animationDuration,
void MacroEntryControls::Show(bool visible)
{
if (_visible == visible) {
return;
}
_animation->setDirection(visible ? QAbstractAnimation::Forward
: QAbstractAnimation::Backward);
_animation->start();
_visible = visible;
}

View File

@ -46,6 +46,11 @@ MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent)
_headerInfo = new QLabel();
_controls = new MacroEntryControls();
_enterTimer.setSingleShot(true);
_enterTimer.setInterval(1000);
_leaveTimer.setSingleShot(true);
_leaveTimer.setInterval(1000);
QWidget::connect(_section, &Section::Collapsed, this,
&MacroSegmentEdit::Collapsed);
@ -78,6 +83,10 @@ MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent)
&MacroSegmentEdit::Up);
QWidget::connect(_controls, &MacroEntryControls::Down, this,
&MacroSegmentEdit::Down);
QWidget::connect(&_enterTimer, &QTimer::timeout, this,
&MacroSegmentEdit::ShowControls);
QWidget::connect(&_leaveTimer, &QTimer::timeout, this,
&MacroSegmentEdit::HideControls);
}
void MacroSegmentEdit::HeaderInfoChanged(const QString &text)
@ -122,16 +131,28 @@ void MacroSegmentEdit::Collapsed(bool collapsed)
}
}
void MacroSegmentEdit::enterEvent(QEvent *)
void MacroSegmentEdit::ShowControls()
{
_controls->Show(true);
}
void MacroSegmentEdit::leaveEvent(QEvent *)
void MacroSegmentEdit::HideControls()
{
_controls->Show(false);
}
void MacroSegmentEdit::enterEvent(QEvent *)
{
_enterTimer.start();
_leaveTimer.stop();
}
void MacroSegmentEdit::leaveEvent(QEvent *)
{
_enterTimer.stop();
_leaveTimer.start();
}
void MacroSegmentEdit::SetFocusPolicyOfWidgets()
{
QList<QWidget *> widgets = this->findChildren<QWidget *>();