From 99b99cb2a4e42542e42b32b5f6687e7b8d22635d Mon Sep 17 00:00:00 2001 From: tianduanrui Date: Sat, 19 May 2018 15:43:07 +0800 Subject: [PATCH] add long click helper --- src/exquisite/clickwidgets/qqtclickhelper.cpp | 156 +++---------- src/exquisite/clickwidgets/qqtclickhelper.h | 30 +-- .../clickwidgets/qqtclicksoundhelper.cpp | 10 - .../clickwidgets/qqtclicksoundhelper.h | 44 ++-- .../clickwidgets/qqtdoubleclickhelper.cpp | 6 +- .../clickwidgets/qqtdoubleclickhelper.h | 20 +- .../clickwidgets/qqtlongclickhelper.cpp | 205 ++++++++++++++++++ .../clickwidgets/qqtlongclickhelper.h | 92 ++++++++ .../clickwidgets/qqtlongclicklabel.h | 4 +- .../clickwidgets/qqtlongclickwidget.h | 4 +- src/linux_cd_path.sh | 0 src/linux_cp_files.sh | 0 src/linux_cur_path.sh | 0 src/qqt_source.pri | 2 + test/QQtWidgetClickHelperTest/mainwindow.ui | 4 +- 15 files changed, 365 insertions(+), 212 deletions(-) create mode 100644 src/exquisite/clickwidgets/qqtlongclickhelper.cpp create mode 100644 src/exquisite/clickwidgets/qqtlongclickhelper.h mode change 100755 => 100644 src/linux_cd_path.sh mode change 100755 => 100644 src/linux_cp_files.sh mode change 100755 => 100644 src/linux_cur_path.sh diff --git a/src/exquisite/clickwidgets/qqtclickhelper.cpp b/src/exquisite/clickwidgets/qqtclickhelper.cpp index 4f0a19e6..0f232873 100644 --- a/src/exquisite/clickwidgets/qqtclickhelper.cpp +++ b/src/exquisite/clickwidgets/qqtclickhelper.cpp @@ -1,18 +1,11 @@ #include "qqtclickhelper.h" -QQtClickHelper::QQtClickHelper ( QObject* parent ) +QQtClickHelper::QQtClickHelper ( QObject* parent ) : QObject ( parent ) { - mLongClickInterval = longClickInterval; - - now_press = QTime::currentTime().addMSecs ( 1 ); - now_release = QTime::currentTime().addMSecs ( 2 ); - nClickNumWithCancel = 0; - nLongClickNumWithCancel = 0; nTotalClickNumWithCancel = 0; nClickNum = 0; - nLongClickNum = 0; nTotalClickNum = 0; mClickType = QQtNullClick; @@ -28,108 +21,44 @@ void QQtClickHelper::mousePressEvent ( QMouseEvent* event, QWidget* userWidget ) p2debug() << "press" << event->pos() << userWidget; mPoint = event->pos(); mClickType = QQtClick; - now_press = QTime::currentTime(); } void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget ) { p2debug() << "release" << event->pos() << userWidget; - //这一次 current click - QTime t2_release_preview = now_release; - now_release = QTime::currentTime(); - //这里加了个判断,其实肯定>=0 - if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) <= mLongClickInterval ) - { - //单击发生 - mClickType = QQtClick; - } - else if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) > mLongClickInterval ) - { - //长击发生 - mClickType = QQtLongClick; - //这次点击, - //上次的release竟然比press晚,说明press没发生,置位click - //第一次click, 上一次release=press也在这里被置位click - if ( t2_release_preview.msecsTo ( now_release ) >= 0 - && t2_release_preview.msecsTo ( now_press ) <= 0 ) + mClickType = QQtClick; + //计算点击数目 + checkClickNumWithCancel(); + + //修改状态 + mClickType = QQtNullClick; + + //如果手移开了,那么不发送. + //条件是用户传入了这个Widget为真. + if ( userWidget ) + { + p2debug() << userWidget << userWidget->rect() << event->pos() << userWidget->rect().contains ( event->pos() ); + if ( !userWidget->rect().contains ( event->pos() ) ) { - mClickType = QQtClick; + p2debug() << "send click canceled." ; + return; } - } - if ( mClickType == QQtLongClick ) - { - //计算点击数目 - checkClickNumWithCancel(); + checkClickNum ( QQtClick ); - //修改状态 - mClickType = QQtNullClick; - - //如果手移开了,那么不发送. - //条件是用户传入了这个Widget为真. - if ( userWidget ) - { - p2debug() << userWidget << userWidget->rect() << event->pos() << userWidget->rect().contains ( event->pos() ); - if ( !userWidget->rect().contains ( event->pos() ) ) - { - p2debug() << "send long click canceled." ; - return; - } - } - - checkClickNum ( QQtLongClick ); - - //发送长信号 - p2debug() << "send long click " ; - emit longClick(); - emit longClickWithPoint ( event->pos() ); - emit longClickWithPointF ( event->localPos() ); + //发送单击信号 + p2debug() << "send click." ; + emit click(); + emit clickWithPoint ( event->pos() ); + emit clickWithPointF ( event->localPos() ); #if 0 - emit longClick ( userWidget ); - emit longClickWithPoint ( event->pos(), userWidget ); - emit longClickWithPointF ( event->localPos(), userWidget ); + emit click ( userWidget ); + emit clickWithPoint ( event->pos(), userWidget ); + emit clickWithPointF ( event->localPos(), userWidget ); #endif - return; - } - else if ( mClickType == QQtClick ) - { - //计算点击数目 - checkClickNumWithCancel(); - - //修改状态 - mClickType = QQtNullClick; - - //如果手移开了,那么不发送. - //条件是用户传入了这个Widget为真. - if ( userWidget ) - { - p2debug() << userWidget << userWidget->rect() << event->pos() << userWidget->rect().contains ( event->pos() ); - if ( !userWidget->rect().contains ( event->pos() ) ) - { - p2debug() << "send click canceled." ; - return; - } - } - - checkClickNum ( QQtClick ); - - //发送单击信号 - p2debug() << "send click." ; - emit click(); - emit clickWithPoint ( event->pos() ); - emit clickWithPointF ( event->localPos() ); - -#if 0 - emit click ( userWidget ); - emit clickWithPoint ( event->pos(), userWidget ); - emit clickWithPointF ( event->localPos(), userWidget ); -#endif - - return; - } //修改状态 mClickType = QQtNullClick; @@ -146,17 +75,6 @@ void QQtClickHelper::mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWi mPoint = event->pos(); } -void QQtClickHelper::setLongClickInterval ( int millSecond ) -{ - mLongClickInterval = millSecond; -} - -int QQtClickHelper::getLongClickInterval() const -{ - return mLongClickInterval; -} - - void QQtClickHelper::checkClickNumWithCancel() { switch ( mClickType ) @@ -171,21 +89,11 @@ void QQtClickHelper::checkClickNumWithCancel() } } break; - case QQtLongClick: - { - nLongClickNumWithCancel++; - if ( nLongClickNumWithCancel >= 0xFFFFFFFF ) - { - p2debug() << "out......"; - nLongClickNumWithCancel = 0; - } - } - break; default: break; } - nTotalClickNumWithCancel = nClickNumWithCancel + nLongClickNumWithCancel; + nTotalClickNumWithCancel = nClickNumWithCancel; if ( nTotalClickNumWithCancel >= 0xFFFFFFFFFFFFFFFF ) { p2debug() << "out......"; @@ -207,21 +115,11 @@ void QQtClickHelper::checkClickNum ( QQtClickHelper::QQtClickType type ) } } break; - case QQtLongClick: - { - nLongClickNum++; - if ( nLongClickNum >= 0xFFFFFFFF ) - { - p2debug() << "out......"; - nLongClickNum = 0; - } - } - break; default: break; } - nTotalClickNum = nClickNum + nLongClickNum; + nTotalClickNum = nClickNum; if ( nTotalClickNum >= 0xFFFFFFFFFFFFFFFF ) { p2debug() << "out......"; diff --git a/src/exquisite/clickwidgets/qqtclickhelper.h b/src/exquisite/clickwidgets/qqtclickhelper.h index 44f6c23d..33b1f8d2 100644 --- a/src/exquisite/clickwidgets/qqtclickhelper.h +++ b/src/exquisite/clickwidgets/qqtclickhelper.h @@ -4,7 +4,7 @@ #include #include -#if 1 +#if 0 #define p2debug() p2line() #else #define p2debug() QNoDebug() @@ -35,15 +35,12 @@ public: //这些信号不区分Widget,谁发过来都发出去,不论Widget signals: void click(); - void longClick(); signals: void clickWithPoint ( QPoint point ); - void longClickWithPoint ( QPoint point ); signals: void clickWithPointF ( QPointF point ); - void longClickWithPointF ( QPointF point ); #if 0 //发给业务层 @@ -53,10 +50,6 @@ signals: void click ( QWidget* userWidget ); void clickWithPoint ( QPoint point, QWidget* userWidget ); void clickWithPointF ( QPointF point, QWidget* userWidget ); - - void longClick ( QWidget* userWidget ); - void longClickWithPoint ( QPoint point, QWidget* userWidget ); - void longClickWithPointF ( QPointF point, QWidget* userWidget ); #endif //调用于userWidget相对应的Event里 @@ -68,25 +61,16 @@ public: //optional public: - //设置longClick超时 default:1200ms - void setLongClickInterval ( int millSecond = longClickInterval ); - int getLongClickInterval() const; - inline const quint32 clickNum() const { return nClickNum; } - inline const quint32 longClickNum() const { return nLongClickNum; } inline const quint64 totalClickNum() const { return nTotalClickNum; } inline const quint32 clickNumWithCancel() const { return nClickNumWithCancel; } - inline const quint32 longClickNumWithCancel() const { return nLongClickNumWithCancel; } inline const quint64 totalClickNumWithCancel() const { return nTotalClickNumWithCancel; } /** * 以下用于内部 */ public: - Q_ENUMS ( QQtClickType ) - Q_PROPERTY ( int mLongClickInterval READ getLongClickInterval WRITE setLongClickInterval ) - typedef enum { QQtNullClick = 0, @@ -98,33 +82,23 @@ public: QQtMaxClick } QQtClickType; + Q_ENUMS ( QQtClickType ) protected: - //这个语法比较难,只有整型有特权. - static const int longClickInterval = 1200; - //用于记录点击到了什么状态. QQtClickType mClickType; //用于记录按钮的位置 QPoint mPoint; - int mLongClickInterval; - - //click 检测使用 - QTime now_press;//press relase - QTime now_release;//release - //click num virtual void checkClickNumWithCancel(); virtual void checkClickNum ( QQtClickType type ); quint32 nClickNum; - quint32 nLongClickNum; quint64 nTotalClickNum; quint32 nClickNumWithCancel; - quint32 nLongClickNumWithCancel; quint64 nTotalClickNumWithCancel; }; diff --git a/src/exquisite/clickwidgets/qqtclicksoundhelper.cpp b/src/exquisite/clickwidgets/qqtclicksoundhelper.cpp index ec9a05d1..52d9d05e 100644 --- a/src/exquisite/clickwidgets/qqtclicksoundhelper.cpp +++ b/src/exquisite/clickwidgets/qqtclicksoundhelper.cpp @@ -1,11 +1 @@ #include "qqtclicksoundhelper.h" - -QQtClickSoundHelper::QQtClickSoundHelper ( QObject* parent ) -{ - mClickHelper = 0; -} - -QQtClickSoundHelper::~QQtClickSoundHelper() -{ - -} diff --git a/src/exquisite/clickwidgets/qqtclicksoundhelper.h b/src/exquisite/clickwidgets/qqtclicksoundhelper.h index 98a2e9b6..b5f556cd 100644 --- a/src/exquisite/clickwidgets/qqtclicksoundhelper.h +++ b/src/exquisite/clickwidgets/qqtclicksoundhelper.h @@ -4,53 +4,41 @@ #include #include #include +#include /** * QQtClickSoundHelper * * 为Widget提供按键声音支持. * - * ClickSoundHelper和Widget共用ClickHelper,实现Widget按键同时能播放声音的能力 - * 依赖QQtClickHelper实现 + * 支持 + * click + * */ -class QQTSHARED_EXPORT QQtClickSoundHelper : public QObject +class QQTSHARED_EXPORT QQtClickSoundHelper : public QQtClickHelper { Q_OBJECT public: - explicit QQtClickSoundHelper ( QObject* parent = 0 ); + explicit QQtClickSoundHelper ( QObject* parent = 0 ) : QQtClickHelper ( parent ) { + connect ( this, SIGNAL ( click() ), this, SLOT ( slotClick() ) ); + } virtual ~QQtClickSoundHelper(); - void setClickSound(); - void setLongClickSound(); - -public: - //一般,调用widget的clickHelper,设置到这里. - inline void setClickHelper ( QQtClickHelper* helper ) { - uninstallClickHelper(); - mClickHelper = helper; - installClickHelper(); + void setClickSound ( const QString clickSoundFile ) { + this->clickSoundFile = clickSoundFile; } - inline const QQtClickHelper* clickHelper() const { - return mClickHelper; - } - -protected: - //允许重写 - virtual void installClickHelper() { - - } - virtual void uninstallClickHelper() { - - } - QQtClickHelper* mClickHelper; /** * 内部 */ public slots: - void slotClick() {} - void slotLongClick() {} + void slotClick() { + + } + +private: + QString clickSoundFile; }; #endif // QQTCLICKSOUNDHELPER_H diff --git a/src/exquisite/clickwidgets/qqtdoubleclickhelper.cpp b/src/exquisite/clickwidgets/qqtdoubleclickhelper.cpp index 21f5640d..44a0b78d 100644 --- a/src/exquisite/clickwidgets/qqtdoubleclickhelper.cpp +++ b/src/exquisite/clickwidgets/qqtdoubleclickhelper.cpp @@ -1,7 +1,7 @@ #include "qqtdoubleclickhelper.h" QQtDoubleClickHelper::QQtDoubleClickHelper ( QObject* parent ) : - QQtClickHelper ( parent ) + QQtLongClickHelper ( parent ) { mDoubleClickInterval = doubleClickInterval; @@ -275,7 +275,7 @@ void QQtDoubleClickHelper::slotDoubleClickTimeout() void QQtDoubleClickHelper::checkClickNumWithCancel() { - QQtClickHelper::checkClickNumWithCancel(); + QQtLongClickHelper::checkClickNumWithCancel(); switch ( mClickType ) { case QQtDoubleClick: @@ -303,7 +303,7 @@ void QQtDoubleClickHelper::checkClickNumWithCancel() void QQtDoubleClickHelper::checkClickNum ( QQtClickType type ) { - QQtClickHelper::checkClickNum ( type ); + QQtLongClickHelper::checkClickNum ( type ); switch ( type ) { case QQtDoubleClick: diff --git a/src/exquisite/clickwidgets/qqtdoubleclickhelper.h b/src/exquisite/clickwidgets/qqtdoubleclickhelper.h index e4e1c8b8..9a3a3edc 100644 --- a/src/exquisite/clickwidgets/qqtdoubleclickhelper.h +++ b/src/exquisite/clickwidgets/qqtdoubleclickhelper.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -12,6 +12,11 @@ /** * @brief The QQtDoubleClickHelper class * + * 支持 + * click + * longClick + * doubleClick + * * 原理 * release开始检测. * 发现longClick只发送longClick. @@ -28,7 +33,7 @@ * * DoubleClick检测是独立于系统的,用户可以在页面里实现多套独立的按键时延检测,一个widget一个时延系统也没问题. */ -class QQTSHARED_EXPORT QQtDoubleClickHelper : public QQtClickHelper +class QQTSHARED_EXPORT QQtDoubleClickHelper : public QQtLongClickHelper { Q_OBJECT @@ -54,9 +59,6 @@ signals: //optional public: - //这个语法比较难,只有整型有特权. - static const int doubleClickInterval = 200; - //设置双击检测时延 default: doubleClickInterval ms //不会影响系统默认时延 void setDoubleClickInterval ( int millSecond = doubleClickInterval ) { @@ -80,6 +82,9 @@ public slots: void slotDoubleClickTimeout(); protected: + //这个语法比较难,只有整型有特权. + static const int doubleClickInterval = 260; + //clickTimer QTimer* m_click_timer; //longClickTimer @@ -87,8 +92,6 @@ protected: //doubleClickTimer QTimer* m_double_click_timer; - //用于记录按钮的位置 - QPoint mPoint; //双击200ms. 这个比较符合双击舒适度.Qt内部的Timer慢一些,可能是计算了比较完整的时间. //在这个范围内的都 才 是双击 @@ -110,8 +113,9 @@ protected: QQtMouseEvent* mMouseEvent; //click num - virtual void checkClickNumWithCancel(); virtual void checkClickNum ( QQtClickType type ) override; + virtual void checkClickNumWithCancel() override; + quint32 nDoubleClickNum; quint32 nDoubleClickNumWithCancel; }; diff --git a/src/exquisite/clickwidgets/qqtlongclickhelper.cpp b/src/exquisite/clickwidgets/qqtlongclickhelper.cpp new file mode 100644 index 00000000..150ff4af --- /dev/null +++ b/src/exquisite/clickwidgets/qqtlongclickhelper.cpp @@ -0,0 +1,205 @@ +#include "qqtlongclickhelper.h" + +QQtLongClickHelper::QQtLongClickHelper ( QObject* parent ) : QQtClickHelper ( parent ) +{ + mLongClickInterval = longClickInterval; + + now_press = QTime::currentTime().addMSecs ( 1 ); + now_release = QTime::currentTime().addMSecs ( 2 ); + + nLongClickNum = 0; + nLongClickNumWithCancel = 0; +} + +QQtLongClickHelper::~QQtLongClickHelper() +{ + +} + +void QQtLongClickHelper::mousePressEvent ( QMouseEvent* event, QWidget* userWidget ) +{ + p2debug() << "press" << event->pos() << userWidget; + mPoint = event->pos(); + mClickType = QQtClick; + now_press = QTime::currentTime(); +} + +void QQtLongClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget ) +{ + p2debug() << "release" << event->pos() << userWidget; + //这一次 current click + QTime t2_release_preview = now_release; + now_release = QTime::currentTime(); + //这里加了个判断,其实肯定>=0 + if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) <= mLongClickInterval ) + { + //单击发生 + mClickType = QQtClick; + } + else if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) > mLongClickInterval ) + { + //长击发生 + mClickType = QQtLongClick; + + //这次点击, + //上次的release竟然比press晚,说明press没发生,置位click + //第一次click, 上一次release=press也在这里被置位click + if ( t2_release_preview.msecsTo ( now_release ) >= 0 + && t2_release_preview.msecsTo ( now_press ) <= 0 ) + { + mClickType = QQtClick; + } + + } + + if ( mClickType == QQtLongClick ) + { + //计算点击数目 + checkClickNumWithCancel(); + + //修改状态 + mClickType = QQtNullClick; + + //如果手移开了,那么不发送. + //条件是用户传入了这个Widget为真. + if ( userWidget ) + { + p2debug() << userWidget << userWidget->rect() << event->pos() << userWidget->rect().contains ( event->pos() ); + if ( !userWidget->rect().contains ( event->pos() ) ) + { + p2debug() << "send long click canceled." ; + return; + } + } + + checkClickNum ( QQtLongClick ); + + //发送长信号 + p2debug() << "send long click " ; + emit longClick(); + emit longClickWithPoint ( event->pos() ); + emit longClickWithPointF ( event->localPos() ); + +#if 0 + emit longClick ( userWidget ); + emit longClickWithPoint ( event->pos(), userWidget ); + emit longClickWithPointF ( event->localPos(), userWidget ); +#endif + return; + } + else if ( mClickType == QQtClick ) + { + //计算点击数目 + checkClickNumWithCancel(); + + //修改状态 + mClickType = QQtNullClick; + + //如果手移开了,那么不发送. + //条件是用户传入了这个Widget为真. + if ( userWidget ) + { + p2debug() << userWidget << userWidget->rect() << event->pos() << userWidget->rect().contains ( event->pos() ); + if ( !userWidget->rect().contains ( event->pos() ) ) + { + p2debug() << "send click canceled." ; + return; + } + } + + checkClickNum ( QQtClick ); + + //发送单击信号 + p2debug() << "send click." ; + emit click(); + emit clickWithPoint ( event->pos() ); + emit clickWithPointF ( event->localPos() ); + +#if 0 + emit click ( userWidget ); + emit clickWithPoint ( event->pos(), userWidget ); + emit clickWithPointF ( event->localPos(), userWidget ); +#endif + + return; + } + + //修改状态 + mClickType = QQtNullClick; + + //保存位置 + mPoint = event->pos(); + return; + +} + +void QQtLongClickHelper::mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget ) +{ + p2debug() << "double click" << event->pos() << userWidget; + mPoint = event->pos(); +} + +void QQtLongClickHelper::setLongClickInterval ( int millSecond ) +{ + mLongClickInterval = millSecond; +} + +int QQtLongClickHelper::getLongClickInterval() const +{ + return mLongClickInterval; +} + + +void QQtLongClickHelper::checkClickNumWithCancel() +{ + QQtClickHelper::checkClickNumWithCancel(); + switch ( mClickType ) + { + case QQtLongClick: + { + nLongClickNumWithCancel++; + if ( nLongClickNumWithCancel >= 0xFFFFFFFF ) + { + p2debug() << "out......"; + nLongClickNumWithCancel = 0; + } + } + break; + default: + break; + } + + nTotalClickNumWithCancel = nClickNumWithCancel + nLongClickNumWithCancel; + if ( nTotalClickNumWithCancel >= 0xFFFFFFFFFFFFFFFF ) + { + p2debug() << "out......"; + nTotalClickNumWithCancel = 0; + } +} + +void QQtLongClickHelper::checkClickNum ( QQtLongClickHelper::QQtClickType type ) +{ + QQtClickHelper::checkClickNum ( type ); + switch ( type ) + { + case QQtLongClick: + { + nLongClickNum++; + if ( nLongClickNum >= 0xFFFFFFFF ) + { + p2debug() << "out......"; + nLongClickNum = 0; + } + } + break; + default: + break; + } + + nTotalClickNum = nClickNum + nLongClickNum; + if ( nTotalClickNum >= 0xFFFFFFFFFFFFFFFF ) + { + p2debug() << "out......"; + nTotalClickNum = 0; + } +} diff --git a/src/exquisite/clickwidgets/qqtlongclickhelper.h b/src/exquisite/clickwidgets/qqtlongclickhelper.h new file mode 100644 index 00000000..5286f57d --- /dev/null +++ b/src/exquisite/clickwidgets/qqtlongclickhelper.h @@ -0,0 +1,92 @@ +#ifndef QQTLONGCLICKHELPER_H +#define QQTLONGCLICKHELPER_H + +#include + +#include +#include + +/** + * QQtLongClickHelper + * 这个Helper是给Widget响应按钮事件用的 + * 主要用于为QQtWidget系列添加按钮信号识别帮助 + * + * 支持 + * click + * longClick + * 不支持DoubleClick + * + * 可以统计按键次数 + */ +class QQTSHARED_EXPORT QQtLongClickHelper : public QQtClickHelper +{ + Q_OBJECT + +public: + explicit QQtLongClickHelper ( QObject* parent = 0 ); + virtual ~QQtLongClickHelper(); + + //发给业务层 + //发回界面层 + //这些信号不区分Widget,谁发过来都发出去,不论Widget +signals: + void click(); + void longClick(); + +signals: + void clickWithPoint ( QPoint point ); + void longClickWithPoint ( QPoint point ); + +signals: + void clickWithPointF ( QPointF point ); + void longClickWithPointF ( QPointF point ); + +#if 0 + //发给业务层 + //发回界面层 + //这里的信号都带着Widget指针,可以区分Widget +signals: + void longClick ( QWidget* userWidget ); + void longClickWithPoint ( QPoint point, QWidget* userWidget ); + void longClickWithPointF ( QPointF point, QWidget* userWidget ); +#endif + + //调用于userWidget相对应的Event里 + //允许重写 +public: + virtual void mousePressEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override; + virtual void mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override; + virtual void mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override; + + //optional +public: + //设置longClick超时 default:1200ms + void setLongClickInterval ( int millSecond = longClickInterval ); + int getLongClickInterval() const; + + inline const quint32 longClickNum() const { return nLongClickNum; } + inline const quint32 longClickNumWithCancel() const { return nLongClickNumWithCancel; } + + + /** + * 以下用于内部 + */ +protected: + //这个语法比较难,只有整型有特权. + static const int longClickInterval = 1200; + + int mLongClickInterval; + + //click 检测使用 + QTime now_press;//press relase + QTime now_release;//release + + //click num + virtual void checkClickNum ( QQtClickType type ) override; + virtual void checkClickNumWithCancel() override; + + quint32 nLongClickNum; + quint32 nLongClickNumWithCancel; +}; + +#endif // QQTLONGCLICKHELPER_H diff --git a/src/exquisite/clickwidgets/qqtlongclicklabel.h b/src/exquisite/clickwidgets/qqtlongclicklabel.h index 9c369859..e7f10006 100644 --- a/src/exquisite/clickwidgets/qqtlongclicklabel.h +++ b/src/exquisite/clickwidgets/qqtlongclicklabel.h @@ -2,7 +2,7 @@ #define QQTLONGCLICKLABEL_H #include -#include +#include #include #include @@ -19,7 +19,7 @@ public: explicit QQtLongClickLabel ( QWidget* parent = 0 ) : QQtLabel ( parent ) { mClickHelper = 0; - mClickHelper = new QQtClickHelper ( this ); + mClickHelper = new QQtLongClickHelper ( this ); installClickHelper ( mClickHelper ); } virtual ~QQtLongClickLabel() {} diff --git a/src/exquisite/clickwidgets/qqtlongclickwidget.h b/src/exquisite/clickwidgets/qqtlongclickwidget.h index bb5687ff..8d39fdcd 100644 --- a/src/exquisite/clickwidgets/qqtlongclickwidget.h +++ b/src/exquisite/clickwidgets/qqtlongclickwidget.h @@ -2,7 +2,7 @@ #define QQTLONGCLICKWIDGET_H #include -#include +#include #include #include @@ -19,7 +19,7 @@ public: explicit QQtLongClickWidget ( QWidget* parent = 0 ) : QQtWidget ( parent ) { mClickHelper = 0; - mClickHelper = new QQtClickHelper ( this ); + mClickHelper = new QQtLongClickHelper ( this ); installClickHelper ( mClickHelper ); } virtual ~QQtLongClickWidget() {} diff --git a/src/linux_cd_path.sh b/src/linux_cd_path.sh old mode 100755 new mode 100644 diff --git a/src/linux_cp_files.sh b/src/linux_cp_files.sh old mode 100755 new mode 100644 diff --git a/src/linux_cur_path.sh b/src/linux_cur_path.sh old mode 100755 new mode 100644 diff --git a/src/qqt_source.pri b/src/qqt_source.pri index 9e1969a6..a5548da4 100644 --- a/src/qqt_source.pri +++ b/src/qqt_source.pri @@ -334,9 +334,11 @@ contains (DEFINES, __EXQUISITE__) { SOURCES += \ $$PWD/exquisite/clickwidgets/qqtclickhelper.cpp \ + $$PWD/exquisite/clickwidgets/qqtlongclickhelper.cpp \ $$PWD/exquisite/clickwidgets/qqtdoubleclickhelper.cpp HEADERS += \ $$PWD/exquisite/clickwidgets/qqtclickhelper.h \ + $$PWD/exquisite/clickwidgets/qqtlongclickhelper.h \ $$PWD/exquisite/clickwidgets/qqtdoubleclickhelper.h SOURCES += \ diff --git a/test/QQtWidgetClickHelperTest/mainwindow.ui b/test/QQtWidgetClickHelperTest/mainwindow.ui index a905a5ef..12f19582 100644 --- a/test/QQtWidgetClickHelperTest/mainwindow.ui +++ b/test/QQtWidgetClickHelperTest/mainwindow.ui @@ -18,7 +18,7 @@ - 2 + 0 @@ -90,7 +90,7 @@ 0 0 816 - 39 + 17