添加模型分割
This commit is contained in:
52
client/gui/widgets/LongPressSwitchToolButton.cpp
Normal file
52
client/gui/widgets/LongPressSwitchToolButton.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "widgets/LongPressSwitchToolButton.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QTimer>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
LongPressSwitchToolButton::LongPressSwitchToolButton(QWidget* parent)
|
||||
: QToolButton(parent) {
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(true);
|
||||
m_timer->setInterval(m_intervalMs);
|
||||
connect(m_timer, &QTimer::timeout, this, [this]() {
|
||||
if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
|
||||
return;
|
||||
}
|
||||
m_longPressEmittedForThisPress = true;
|
||||
emit longPressTriggered();
|
||||
});
|
||||
}
|
||||
|
||||
void LongPressSwitchToolButton::setLongPressInterval(int ms) {
|
||||
m_intervalMs = std::max(50, ms);
|
||||
if (m_timer) {
|
||||
m_timer->setInterval(m_intervalMs);
|
||||
}
|
||||
}
|
||||
|
||||
void LongPressSwitchToolButton::mousePressEvent(QMouseEvent* event) {
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_longPressEmittedForThisPress = false;
|
||||
m_timer->start();
|
||||
}
|
||||
QToolButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void LongPressSwitchToolButton::mouseReleaseEvent(QMouseEvent* event) {
|
||||
const bool left = (event->button() == Qt::LeftButton);
|
||||
if (left && m_timer->isActive()) {
|
||||
m_timer->stop();
|
||||
}
|
||||
const bool hadLongPress = left && m_longPressEmittedForThisPress;
|
||||
QToolButton::mouseReleaseEvent(event);
|
||||
if (hadLongPress) {
|
||||
m_longPressEmittedForThisPress = false;
|
||||
if (isDown()) {
|
||||
setDown(false);
|
||||
}
|
||||
update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user