Enable dragging macro segment by header

This commit is contained in:
WarmUpTill 2023-02-17 23:19:50 +01:00 committed by WarmUpTill
parent f8b2dea270
commit 46eaada0c4
2 changed files with 29 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <QMouseEvent>
#include <QLabel>
#include <QScrollBar>
#include <QApplication>
MacroSegment::MacroSegment(Macro *m, bool supportsVariableValue)
: _macro(m), _supportsVariableValue(supportsVariableValue)
@ -182,11 +183,37 @@ MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent)
SetSelected(false);
ShowDropLine(DropLineState::NONE);
// Enable dragging while clicking on the header text
_headerInfo->installEventFilter(this);
_timer.setInterval(1500);
connect(&_timer, SIGNAL(timeout()), this, SLOT(Highlight()));
_timer.start();
}
bool MacroSegmentEdit::eventFilter(QObject *obj, QEvent *ev)
{
if (obj == _headerInfo && ev->type() == QEvent::MouseMove) {
if (!parentWidget()) {
return QWidget::eventFilter(obj, ev);
}
// Generate a mouse move event for the MacroSegmentList
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(ev);
QMouseEvent *newEvent = new QMouseEvent(
mouseEvent->type(),
_headerInfo->mapTo(this, mouseEvent->pos()),
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
mouseEvent->globalPos(),
#else
mouseEvent->globalPosition(),
#endif
mouseEvent->button(), mouseEvent->buttons(),
mouseEvent->modifiers());
QApplication::sendEvent(parentWidget(), newEvent);
}
return QWidget::eventFilter(obj, ev);
}
void MacroSegmentEdit::HeaderInfoChanged(const QString &text)
{
_headerInfo->setVisible(!text.isEmpty());

View File

@ -75,6 +75,8 @@ signals:
void SceneGroupRenamed(const QString &oldName, const QString newName);
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
Section *_section;
QLabel *_headerInfo;
QWidget *_frame;