mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
Merge branch 'dev-fact' of https://gitee.com/drabel/LibQQt into dev-fact
This commit is contained in:
commit
8c5118d726
@ -85,7 +85,8 @@ greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += demo/VegeTablesPrice
|
|||||||
#必开
|
#必开
|
||||||
#SUBDIRS += test/qqtdicttest2
|
#SUBDIRS += test/qqtdicttest2
|
||||||
#必开
|
#必开
|
||||||
#SUBDIRS += test/giftest
|
#
|
||||||
|
SUBDIRS += test/giftest
|
||||||
|
|
||||||
#必开 这两个例子是关于QQtAudio的最好展示
|
#必开 这两个例子是关于QQtAudio的最好展示
|
||||||
#SUBDIRS += examples/qqtaudioexample
|
#SUBDIRS += examples/qqtaudioexample
|
||||||
@ -115,3 +116,4 @@ greaterThan(QT_MAJOR_VERSION , 4):SUBDIRS += demo/VegeTablesPrice
|
|||||||
#SUBDIRS += demo/TouchMonitorServer
|
#SUBDIRS += demo/TouchMonitorServer
|
||||||
|
|
||||||
SUBDIRS += test/QQtWidgetClickHelperTest
|
SUBDIRS += test/QQtWidgetClickHelperTest
|
||||||
|
SUBDIRS += test/QQtWidgetClickSoundHelperTest
|
||||||
|
1
src/exquisite/clicksoundwidgets/qqtclicksoundhelper.cpp
Normal file
1
src/exquisite/clicksoundwidgets/qqtclicksoundhelper.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtclicksoundhelper.h"
|
47
src/exquisite/clicksoundwidgets/qqtclicksoundhelper.h
Normal file
47
src/exquisite/clicksoundwidgets/qqtclicksoundhelper.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef QQTCLICKSOUNDHELPER_H
|
||||||
|
#define QQTCLICKSOUNDHELPER_H
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
#include <qqtclickhelper.h>
|
||||||
|
#include <qqtsoundeffect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQtClickSoundHelper
|
||||||
|
*
|
||||||
|
* 为Widget提供按键声音支持.
|
||||||
|
*
|
||||||
|
* 支持
|
||||||
|
* click
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtClickSoundHelper : public QQtClickHelper
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QQtClickSoundHelper ( QObject* parent = 0 ) : QQtClickHelper ( parent ) {
|
||||||
|
connect ( this, SIGNAL ( click() ), this, SLOT ( slotClick() ) );
|
||||||
|
}
|
||||||
|
virtual ~QQtClickSoundHelper() {}
|
||||||
|
|
||||||
|
void setClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->clickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部
|
||||||
|
*/
|
||||||
|
public slots:
|
||||||
|
void slotClick() {
|
||||||
|
if ( clickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( clickSoundFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString clickSoundFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTCLICKSOUNDHELPER_H
|
1
src/exquisite/clicksoundwidgets/qqtclicksoundlabel.cpp
Normal file
1
src/exquisite/clicksoundwidgets/qqtclicksoundlabel.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtclicksoundlabel.h"
|
105
src/exquisite/clicksoundwidgets/qqtclicksoundlabel.h
Normal file
105
src/exquisite/clicksoundwidgets/qqtclicksoundlabel.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#ifndef QQTCLICKSOUNDLABEL_H
|
||||||
|
#define QQTCLICKSOUNDLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个basic类 提供click信号
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 提供MouseEvent响应
|
||||||
|
*
|
||||||
|
* 用户使用方法
|
||||||
|
* new ClickHelper
|
||||||
|
* installClickHelper
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtClickSoundLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtClickSoundLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtClickSoundLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTCLICKSOUNDLABEL_H
|
1
src/exquisite/clicksoundwidgets/qqtclicksoundwidget.cpp
Normal file
1
src/exquisite/clicksoundwidgets/qqtclicksoundwidget.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtclicksoundwidget.h"
|
103
src/exquisite/clicksoundwidgets/qqtclicksoundwidget.h
Normal file
103
src/exquisite/clicksoundwidgets/qqtclicksoundwidget.h
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#ifndef QQTCLICKSOUNDWIDGET_H
|
||||||
|
#define QQTCLICKSOUNDWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内置ClickHelper
|
||||||
|
*
|
||||||
|
* 添加了clickSound支持的QQtWidget
|
||||||
|
* 这个Widget表示了如何使用QQtClickSoundHelper和它的子类
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtClickSoundWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtClickSoundWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtClickSoundWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTCLICKSOUNDWIDGET_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtdoubleclicksoundhelper.h"
|
69
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundhelper.h
Normal file
69
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundhelper.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#ifndef QQTDOUBLECLICKSOUNDHELPER_H
|
||||||
|
#define QQTDOUBLECLICKSOUNDHELPER_H
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
#include <qqtdoubleclickhelper.h>
|
||||||
|
#include <qqtsoundeffect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQtDoubleClickSoundHelper
|
||||||
|
*
|
||||||
|
* 为Widget提供按键声音支持.
|
||||||
|
*
|
||||||
|
* 支持
|
||||||
|
* click
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtDoubleClickSoundHelper : public QQtDoubleClickHelper
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QQtDoubleClickSoundHelper ( QObject* parent = 0 ) : QQtDoubleClickHelper ( parent ) {
|
||||||
|
connect ( this, SIGNAL ( click() ), this, SLOT ( slotClick() ) );
|
||||||
|
connect ( this, SIGNAL ( longClick() ), this, SLOT ( slotLongClick() ) );
|
||||||
|
connect ( this, SIGNAL ( doubleClick() ), this, SLOT ( slotDoubleClick() ) );
|
||||||
|
}
|
||||||
|
virtual ~QQtDoubleClickSoundHelper() {}
|
||||||
|
|
||||||
|
void setClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->clickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
void setLongClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->longClickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
void setDoubleClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->doubleClickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部
|
||||||
|
*/
|
||||||
|
public slots:
|
||||||
|
void slotClick() {
|
||||||
|
if ( clickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( clickSoundFile );
|
||||||
|
}
|
||||||
|
void slotLongClick() {
|
||||||
|
if ( longClickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( longClickSoundFile );
|
||||||
|
}
|
||||||
|
void slotDoubleClick() {
|
||||||
|
if ( doubleClickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( doubleClickSoundFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString clickSoundFile;
|
||||||
|
QString longClickSoundFile;
|
||||||
|
QString doubleClickSoundFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTDOUBLECLICKSOUNDHELPER_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtdoubleclicksoundlabel.h"
|
112
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundlabel.h
Normal file
112
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundlabel.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#ifndef QQTDOUBLECLICKSOUNDLABEL_H
|
||||||
|
#define QQTDOUBLECLICKSOUNDLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtdoubleclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个虚类
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtDoubleClickSoundLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit QQtDoubleClickSoundLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtDoubleClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtDoubleClickSoundLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
void doubleClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
void doubleClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtDoubleClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtDoubleClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
||||||
|
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtDoubleClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTDOUBLECLICKSOUNDLABEL_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtdoubleclicksoundwidget.h"
|
115
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundwidget.h
Normal file
115
src/exquisite/clicksoundwidgets/qqtdoubleclicksoundwidget.h
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#ifndef QQTDOUBLECLICKSOUNDWIDGET_H
|
||||||
|
#define QQTDOUBLECLICKSOUNDWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtdoubleclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内置DoubleClickHelper
|
||||||
|
*
|
||||||
|
* 添加了doubleClick支持的QQtClickSoundSoundWidget
|
||||||
|
* 这个Widget表示了如何使用QQtWidgetClickHelper和它的子类
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtDoubleClickSoundWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtDoubleClickSoundWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtDoubleClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtDoubleClickSoundWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
void doubleClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
void doubleClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtDoubleClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtDoubleClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
||||||
|
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtDoubleClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTDOUBLECLICKSOUNDWIDGET_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtlongclicksoundhelper.h"
|
58
src/exquisite/clicksoundwidgets/qqtlongclicksoundhelper.h
Normal file
58
src/exquisite/clicksoundwidgets/qqtlongclicksoundhelper.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef QQTLONGCLICKSOUNDHELPER_H
|
||||||
|
#define QQTLONGCLICKSOUNDHELPER_H
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
#include <qqtlongclickhelper.h>
|
||||||
|
#include <qqtsoundeffect.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QQtLongClickSoundHelper
|
||||||
|
*
|
||||||
|
* 为Widget提供按键声音支持.
|
||||||
|
*
|
||||||
|
* 支持
|
||||||
|
* click
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtLongClickSoundHelper : public QQtLongClickHelper
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QQtLongClickSoundHelper ( QObject* parent = 0 ) : QQtLongClickHelper ( parent ) {
|
||||||
|
connect ( this, SIGNAL ( click() ), this, SLOT ( slotClick() ) );
|
||||||
|
connect ( this, SIGNAL ( longClick() ), this, SLOT ( slotLongClick() ) );
|
||||||
|
}
|
||||||
|
virtual ~QQtLongClickSoundHelper() {}
|
||||||
|
|
||||||
|
inline void setClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->clickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
inline void setLongClickSound ( const QString clickSoundFile ) {
|
||||||
|
this->longClickSoundFile = clickSoundFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部
|
||||||
|
*/
|
||||||
|
public slots:
|
||||||
|
void slotClick() {
|
||||||
|
if ( clickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( clickSoundFile );
|
||||||
|
}
|
||||||
|
void slotLongClick() {
|
||||||
|
if ( longClickSoundFile.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QQtWavSound ( longClickSoundFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString clickSoundFile;
|
||||||
|
QString longClickSoundFile;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTLONGCLICKSOUNDHELPER_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtlongclicksoundlabel.h"
|
108
src/exquisite/clicksoundwidgets/qqtlongclicksoundlabel.h
Normal file
108
src/exquisite/clicksoundwidgets/qqtlongclicksoundlabel.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#ifndef QQTLONGCLICKSOUNDLABEL_H
|
||||||
|
#define QQTLONGCLICKSOUNDLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtlongclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个虚类
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 为确定功能的子类Label服务
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtLongClickSoundLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtLongClickSoundLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtLongClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtLongClickSoundLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtLongClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtLongClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtLongClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTLONGCLICKSOUNDLABEL_H
|
@ -0,0 +1 @@
|
|||||||
|
#include "qqtlongclicksoundwidget.h"
|
107
src/exquisite/clicksoundwidgets/qqtlongclicksoundwidget.h
Normal file
107
src/exquisite/clicksoundwidgets/qqtlongclicksoundwidget.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifndef QQTLONGCLICKSOUNDWIDGET_H
|
||||||
|
#define QQTLONGCLICKSOUNDWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtlongclicksoundhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 为确定功能的子类Widget服务
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtLongClickSoundWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QQtLongClickSoundWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtLongClickSoundHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtLongClickSoundWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtLongClickSoundHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtLongClickSoundHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtLongClickSoundHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTLONGCLICKSOUNDWIDGET_H
|
128
src/exquisite/clickwidgets/qqtclickhelper.cpp
Normal file
128
src/exquisite/clickwidgets/qqtclickhelper.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
#include "qqtclickhelper.h"
|
||||||
|
|
||||||
|
QQtClickHelper::QQtClickHelper ( QObject* parent ) : QObject ( parent )
|
||||||
|
{
|
||||||
|
nClickNumWithCancel = 0;
|
||||||
|
nTotalClickNumWithCancel = 0;
|
||||||
|
|
||||||
|
nClickNum = 0;
|
||||||
|
nTotalClickNum = 0;
|
||||||
|
|
||||||
|
mClickType = QQtNullClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQtClickHelper::~QQtClickHelper()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QQtClickHelper::mousePressEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
|
{
|
||||||
|
p2debug() << "press" << event->pos() << userWidget;
|
||||||
|
mPoint = event->pos();
|
||||||
|
mClickType = QQtClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
|
{
|
||||||
|
p2debug() << "release" << event->pos() << userWidget;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
//修改状态
|
||||||
|
mClickType = QQtNullClick;
|
||||||
|
|
||||||
|
//保存位置
|
||||||
|
mPoint = event->pos();
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QQtClickHelper::mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
|
{
|
||||||
|
p2debug() << "double click" << event->pos() << userWidget;
|
||||||
|
mPoint = event->pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QQtClickHelper::checkClickNumWithCancel()
|
||||||
|
{
|
||||||
|
switch ( mClickType )
|
||||||
|
{
|
||||||
|
case QQtClick:
|
||||||
|
{
|
||||||
|
nClickNumWithCancel++;
|
||||||
|
if ( nClickNumWithCancel >= 0xFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nClickNumWithCancel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nTotalClickNumWithCancel = nClickNumWithCancel;
|
||||||
|
if ( nTotalClickNumWithCancel >= 0xFFFFFFFFFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nTotalClickNumWithCancel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QQtClickHelper::checkClickNum ( QQtClickHelper::QQtClickType type )
|
||||||
|
{
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case QQtClick:
|
||||||
|
{
|
||||||
|
nClickNum++;
|
||||||
|
if ( nClickNum >= 0xFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nClickNum = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nTotalClickNum = nClickNum;
|
||||||
|
if ( nTotalClickNum >= 0xFFFFFFFFFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nTotalClickNum = 0;
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,28 @@ public:
|
|||||||
explicit QQtClickHelper ( QObject* parent = 0 );
|
explicit QQtClickHelper ( QObject* parent = 0 );
|
||||||
virtual ~QQtClickHelper();
|
virtual ~QQtClickHelper();
|
||||||
|
|
||||||
|
//发给业务层
|
||||||
|
//发回界面层
|
||||||
|
//这些信号不区分Widget,谁发过来都发出去,不论Widget
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPointF ( QPointF point );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
//发给业务层
|
||||||
|
//发回界面层
|
||||||
|
//这里的信号都带着Widget指针,可以区分Widget
|
||||||
|
signals:
|
||||||
|
void click ( QWidget* userWidget );
|
||||||
|
void clickWithPoint ( QPoint point, QWidget* userWidget );
|
||||||
|
void clickWithPointF ( QPointF point, QWidget* userWidget );
|
||||||
|
#endif
|
||||||
|
|
||||||
//调用于userWidget相对应的Event里
|
//调用于userWidget相对应的Event里
|
||||||
//允许重写
|
//允许重写
|
||||||
public:
|
public:
|
||||||
@ -37,35 +59,18 @@ public:
|
|||||||
virtual void mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
virtual void mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
||||||
virtual void mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
||||||
|
|
||||||
signals:
|
|
||||||
void click();
|
|
||||||
void longClick();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPoint ( QPoint point );
|
|
||||||
void longClickWithPoint ( QPoint point );
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPointF ( QPointF point );
|
|
||||||
void longClickWithPointF ( QPointF point );
|
|
||||||
|
|
||||||
//optional
|
//optional
|
||||||
public:
|
public:
|
||||||
//设置longClick超时 default:1200ms
|
inline const quint32 clickNum() const { return nClickNum; }
|
||||||
void setLongClickInterval ( int millSecond = longClickInterval );
|
inline const quint64 totalClickNum() const { return nTotalClickNum; }
|
||||||
int getLongClickInterval() const;
|
|
||||||
|
|
||||||
quint32 clickNum() const;
|
inline const quint32 clickNumWithCancel() const { return nClickNumWithCancel; }
|
||||||
quint32 longClickNum() const;
|
inline const quint64 totalClickNumWithCancel() const { return nTotalClickNumWithCancel; }
|
||||||
quint64 totalClickNum() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以下用于内部
|
* 以下用于内部
|
||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
Q_ENUMS ( QQtClickType )
|
|
||||||
Q_PROPERTY ( int mLongClickInterval READ getLongClickInterval WRITE setLongClickInterval )
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
QQtNullClick = 0,
|
QQtNullClick = 0,
|
||||||
@ -77,29 +82,24 @@ public:
|
|||||||
|
|
||||||
QQtMaxClick
|
QQtMaxClick
|
||||||
} QQtClickType;
|
} QQtClickType;
|
||||||
|
Q_ENUMS ( QQtClickType )
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//这个语法比较难,只有整型有特权.
|
|
||||||
static const int longClickInterval = 1200;
|
|
||||||
|
|
||||||
//用于记录点击到了什么状态.
|
//用于记录点击到了什么状态.
|
||||||
QQtClickType mClickType;
|
QQtClickType mClickType;
|
||||||
|
|
||||||
//用于记录按钮的位置
|
//用于记录按钮的位置
|
||||||
QPoint mPoint;
|
QPoint mPoint;
|
||||||
|
|
||||||
int mLongClickInterval;
|
|
||||||
|
|
||||||
//click 检测使用
|
|
||||||
QTime t1;//press relase
|
|
||||||
QTime t2;//release
|
|
||||||
|
|
||||||
//click num
|
//click num
|
||||||
virtual void checkClickNum();
|
virtual void checkClickNumWithCancel();
|
||||||
|
virtual void checkClickNum ( QQtClickType type );
|
||||||
|
|
||||||
quint32 nClickNum;
|
quint32 nClickNum;
|
||||||
quint32 nLongClickNum;
|
|
||||||
quint64 nTotalClickNum;
|
quint64 nTotalClickNum;
|
||||||
|
|
||||||
|
quint32 nClickNumWithCancel;
|
||||||
|
quint64 nTotalClickNumWithCancel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QQTCLICKHELPER_H
|
#endif // QQTCLICKHELPER_H
|
1
src/exquisite/clickwidgets/qqtclicklabel.cpp
Normal file
1
src/exquisite/clickwidgets/qqtclicklabel.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtclicklabel.h"
|
105
src/exquisite/clickwidgets/qqtclicklabel.h
Normal file
105
src/exquisite/clickwidgets/qqtclicklabel.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#ifndef QQTCLICKLABEL_H
|
||||||
|
#define QQTCLICKLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个basic类 提供click信号
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 提供MouseEvent响应
|
||||||
|
*
|
||||||
|
* 用户使用方法
|
||||||
|
* new ClickHelper
|
||||||
|
* installClickHelper
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtClickLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtClickLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtClickLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTCLICKLABEL_H
|
1
src/exquisite/clickwidgets/qqtclickwidget.cpp
Normal file
1
src/exquisite/clickwidgets/qqtclickwidget.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtclickwidget.h"
|
103
src/exquisite/clickwidgets/qqtclickwidget.h
Normal file
103
src/exquisite/clickwidgets/qqtclickwidget.h
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#ifndef QQTCLICKWIDGET_H
|
||||||
|
#define QQTCLICKWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内置ClickHelper
|
||||||
|
*
|
||||||
|
* 添加了click支持的QQtWidget
|
||||||
|
* 这个Widget表示了如何使用QQtWidgetClickHelper和它的子类
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtClickWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtClickWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtClickWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTCLICKWIDGET_H
|
@ -1,16 +1,23 @@
|
|||||||
#include "qqtdoubleclickhelper.h"
|
#include "qqtdoubleclickhelper.h"
|
||||||
|
|
||||||
QQtDoubleClickHelper::QQtDoubleClickHelper ( QObject* parent ) :
|
QQtDoubleClickHelper::QQtDoubleClickHelper ( QObject* parent ) :
|
||||||
QQtClickHelper ( parent )
|
QQtLongClickHelper ( parent )
|
||||||
{
|
{
|
||||||
mDoubleClickInterval = doubleClickInterval;
|
mDoubleClickInterval = doubleClickInterval;
|
||||||
|
|
||||||
nDoubleClickNum = 0;
|
nDoubleClickNum = 0;
|
||||||
|
nDoubleClickNumWithCancel = 0;
|
||||||
|
|
||||||
|
prev_doubleclick = QTime::currentTime().addMSecs ( 3 );
|
||||||
|
now_doubleclick = QTime::currentTime().addMSecs ( 4 );
|
||||||
|
|
||||||
|
p2debug() << prev_doubleclick.msecsTo ( now_doubleclick );
|
||||||
|
|
||||||
|
prev_release = QTime::currentTime().addMSecs ( 5 );
|
||||||
|
now_release_initial = QTime::currentTime().addMSecs ( 6 );
|
||||||
|
|
||||||
mMouseEvent = new QQtMouseEvent;
|
mMouseEvent = new QQtMouseEvent;
|
||||||
|
|
||||||
mClickType = QQtNullClick;
|
|
||||||
|
|
||||||
m_click_timer = new QTimer ( this );
|
m_click_timer = new QTimer ( this );
|
||||||
m_click_timer->setSingleShot ( false );
|
m_click_timer->setSingleShot ( false );
|
||||||
//击发延迟20ms
|
//击发延迟20ms
|
||||||
@ -45,26 +52,44 @@ void QQtDoubleClickHelper::mousePressEvent ( QMouseEvent* event , QWidget* userW
|
|||||||
//mClickType = QQtNullClick;
|
//mClickType = QQtNullClick;
|
||||||
m_long_click_timer->start();
|
m_long_click_timer->start();
|
||||||
m_click_timer->stop();
|
m_click_timer->stop();
|
||||||
|
|
||||||
|
//复用一下t1_press t2_release 这里的实现和父类关系不太大
|
||||||
|
now_press = QTime::currentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget )
|
void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
{
|
{
|
||||||
p2debug() << "release" << event->pos() << userWidget;
|
p2debug() << "release" << event->pos() << userWidget;
|
||||||
|
|
||||||
|
//添加longClick检测, 更新longclick检测时间
|
||||||
|
prev_release = now_release;//记录上次的release
|
||||||
|
now_release = QTime::currentTime();
|
||||||
|
//在release-press>longclick暨click时钟判定为longclick后 加一次判断修复误判 防止用户不发press,引起click一直longclick.
|
||||||
|
// if ( t1_press.msecsTo ( t2_release ) >= mLongClickInterval
|
||||||
|
// && t2_doubleclick.msecsTo ( t2_release ) >= 0
|
||||||
|
// && t2_doubleclick.msecsTo ( t2_release ) < mLongClickInterval )
|
||||||
|
// {
|
||||||
|
// //单击发生
|
||||||
|
// mClickType = QQtClick;
|
||||||
|
// }
|
||||||
|
|
||||||
//doubleClick检测不依赖press,所以只要发release就会有doubleClick发生.
|
//doubleClick检测不依赖press,所以只要发release就会有doubleClick发生.
|
||||||
//检测方式: 两次release的间隔小于doubleClickInterval那么触发doubleClick.
|
//检测方式: 两次release的间隔小于doubleClickInterval那么触发doubleClick.
|
||||||
//这一次 current click
|
//这一次 current click
|
||||||
t1 = QTime::currentTime();
|
now_doubleclick = QTime::currentTime();
|
||||||
//这里有小技巧: 这里没有加 && mClickType != QQtClick
|
//这里有小技巧: 这里没有加 && mClickType != QQtClick
|
||||||
//难道不会和click时钟混淆吗?不会,因为click时钟那边用的startTime和nowTime两个变量, t2比startTime还早,t1比nowTime还晚,t1-t2绝对比nowTime-startTime还长.
|
//难道不会和click时钟混淆吗?不会,因为click时钟那边用的startTime和nowTime两个变量, t2比startTime还早,t1比nowTime还晚,t1-t2绝对比nowTime-startTime还长.
|
||||||
//如果是click,绝对不会混淆成doubleClick.
|
//如果是click,绝对不会混淆成doubleClick.
|
||||||
//正好mDoubleClickInterval ms代表双击 不代表单击.
|
//正好mDoubleClickInterval ms代表双击 不代表单击.
|
||||||
if ( t2.msecsTo ( t1 ) >= 0 && t2.msecsTo ( t1 ) <= mDoubleClickInterval )
|
p2debug() << prev_doubleclick << now_doubleclick << mClickType;
|
||||||
|
if ( prev_doubleclick.msecsTo ( now_doubleclick ) >= 0
|
||||||
|
&& prev_doubleclick.msecsTo ( now_doubleclick ) < mDoubleClickInterval )
|
||||||
{
|
{
|
||||||
//双击发生
|
//双击发生
|
||||||
mClickType = QQtDoubleClick;
|
mClickType = QQtDoubleClick;
|
||||||
}
|
}
|
||||||
//上一次 prev click
|
//上一次 prev click
|
||||||
t2 = QTime::currentTime();
|
prev_doubleclick = QTime::currentTime();
|
||||||
|
|
||||||
//梳理状态
|
//梳理状态
|
||||||
m_long_click_timer->stop();
|
m_long_click_timer->stop();
|
||||||
@ -73,7 +98,7 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
if ( mClickType == QQtLongClick )
|
if ( mClickType == QQtLongClick )
|
||||||
{
|
{
|
||||||
//计算点击数目
|
//计算点击数目
|
||||||
checkClickNum();
|
checkClickNumWithCancel();
|
||||||
|
|
||||||
//修改状态
|
//修改状态
|
||||||
mClickType = QQtNullClick;
|
mClickType = QQtNullClick;
|
||||||
@ -90,6 +115,8 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkClickNum ( QQtLongClick );
|
||||||
|
|
||||||
//发送长信号
|
//发送长信号
|
||||||
p2debug() << "send long click " ;
|
p2debug() << "send long click " ;
|
||||||
emit longClick();
|
emit longClick();
|
||||||
@ -101,7 +128,7 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
else if ( mClickType == QQtDoubleClick )
|
else if ( mClickType == QQtDoubleClick )
|
||||||
{
|
{
|
||||||
//计算点击数目
|
//计算点击数目
|
||||||
checkClickNum();
|
checkClickNumWithCancel();
|
||||||
|
|
||||||
//修改状态
|
//修改状态
|
||||||
mClickType = QQtNullClick;
|
mClickType = QQtNullClick;
|
||||||
@ -118,6 +145,8 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkClickNum ( QQtDoubleClick );
|
||||||
|
|
||||||
//发送双击信号
|
//发送双击信号
|
||||||
p2debug() << "send double click." ;
|
p2debug() << "send double click." ;
|
||||||
emit doubleClick();
|
emit doubleClick();
|
||||||
@ -129,7 +158,7 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
else if ( mClickType == QQtClick )
|
else if ( mClickType == QQtClick )
|
||||||
{
|
{
|
||||||
//计算点击数目
|
//计算点击数目
|
||||||
checkClickNum();
|
checkClickNumWithCancel();
|
||||||
|
|
||||||
//修改状态
|
//修改状态
|
||||||
mClickType = QQtNullClick;
|
mClickType = QQtNullClick;
|
||||||
@ -146,6 +175,8 @@ void QQtDoubleClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkClickNum ( QQtClick );
|
||||||
|
|
||||||
//发送单击信号
|
//发送单击信号
|
||||||
p2debug() << "send click." ;
|
p2debug() << "send click." ;
|
||||||
emit click();
|
emit click();
|
||||||
@ -191,8 +222,38 @@ void QQtDoubleClickHelper::slotClickTimeout()
|
|||||||
QTime nowTime = QTime::currentTime();
|
QTime nowTime = QTime::currentTime();
|
||||||
int t0 = startClickTime.msecsTo ( nowTime );
|
int t0 = startClickTime.msecsTo ( nowTime );
|
||||||
p2debug() << t0 << mDoubleClickInterval << qApp->doubleClickInterval();
|
p2debug() << t0 << mDoubleClickInterval << qApp->doubleClickInterval();
|
||||||
if ( t0 > mDoubleClickInterval/*qApp->doubleClickInterval()*/ )
|
if ( t0 >= mDoubleClickInterval/*qApp->doubleClickInterval()*/ )
|
||||||
{
|
{
|
||||||
|
//先判断是否为长击
|
||||||
|
//注意:必须和点击一样在超时的时候检测,否则和双击检测冲突,分不清是长击还是双击.导致长击必发.
|
||||||
|
//注意:必须press击发.
|
||||||
|
//不发press 发生误判 认为总是long click
|
||||||
|
if ( now_press.msecsTo ( now_release ) >= 0
|
||||||
|
&& now_press.msecsTo ( now_release ) >= mLongClickInterval )
|
||||||
|
{
|
||||||
|
//长击发生
|
||||||
|
mClickType = QQtLongClick;
|
||||||
|
|
||||||
|
//有误判, 未发press的时候, 这个一直都是longclick,其实还有click
|
||||||
|
//press比前一次release小的时候 其实是click
|
||||||
|
if ( prev_release.msecsTo ( now_release ) >= 0
|
||||||
|
&& prev_release.msecsTo ( now_press ) <= 0 )
|
||||||
|
{
|
||||||
|
mClickType = QQtClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
//initial press
|
||||||
|
if ( prev_release.msecsTo ( now_release ) >= 0
|
||||||
|
&& prev_release == now_release_initial )
|
||||||
|
{
|
||||||
|
mClickType = QQtClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
//经过以上两部fix,不发press过来,longclick绝不会发生.
|
||||||
|
mouseReleaseEvent ( mMouseEvent, mUserWidget );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mClickType = QQtClick;
|
mClickType = QQtClick;
|
||||||
mouseReleaseEvent ( mMouseEvent, mUserWidget );
|
mouseReleaseEvent ( mMouseEvent, mUserWidget );
|
||||||
return;
|
return;
|
||||||
@ -202,7 +263,8 @@ void QQtDoubleClickHelper::slotClickTimeout()
|
|||||||
void QQtDoubleClickHelper::slotLongClickTimeout()
|
void QQtDoubleClickHelper::slotLongClickTimeout()
|
||||||
{
|
{
|
||||||
//longclick超时,确认longclick.
|
//longclick超时,确认longclick.
|
||||||
mClickType = QQtLongClick;
|
//不再使用此处检测,而是改在click时钟检测.
|
||||||
|
//mClickType = QQtLongClick;
|
||||||
m_long_click_timer->stop();
|
m_long_click_timer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,10 +273,38 @@ void QQtDoubleClickHelper::slotDoubleClickTimeout()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtDoubleClickHelper::checkClickNum()
|
void QQtDoubleClickHelper::checkClickNumWithCancel()
|
||||||
{
|
{
|
||||||
QQtClickHelper::checkClickNum();
|
QQtLongClickHelper::checkClickNumWithCancel();
|
||||||
switch ( mClickType )
|
switch ( mClickType )
|
||||||
|
{
|
||||||
|
case QQtDoubleClick:
|
||||||
|
{
|
||||||
|
nDoubleClickNumWithCancel++;
|
||||||
|
if ( nDoubleClickNumWithCancel >= 0xFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nDoubleClickNumWithCancel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
nTotalClickNumWithCancel = nClickNumWithCancel + nLongClickNumWithCancel + nDoubleClickNumWithCancel;
|
||||||
|
if ( nTotalClickNumWithCancel >= 0xFFFFFFFFFFFFFFFF )
|
||||||
|
{
|
||||||
|
p2debug() << "out......";
|
||||||
|
nTotalClickNumWithCancel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QQtDoubleClickHelper::checkClickNum ( QQtClickType type )
|
||||||
|
{
|
||||||
|
QQtLongClickHelper::checkClickNum ( type );
|
||||||
|
switch ( type )
|
||||||
{
|
{
|
||||||
case QQtDoubleClick:
|
case QQtDoubleClick:
|
||||||
{
|
{
|
@ -4,7 +4,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <qqtevent.h>
|
#include <qqtevent.h>
|
||||||
#include <qqtclickhelper.h>
|
#include <qqtlongclickhelper.h>
|
||||||
|
|
||||||
#include <qqt-local.h>
|
#include <qqt-local.h>
|
||||||
#include <qqtcore.h>
|
#include <qqtcore.h>
|
||||||
@ -12,6 +12,11 @@
|
|||||||
/**
|
/**
|
||||||
* @brief The QQtDoubleClickHelper class
|
* @brief The QQtDoubleClickHelper class
|
||||||
*
|
*
|
||||||
|
* 支持
|
||||||
|
* click
|
||||||
|
* longClick
|
||||||
|
* doubleClick
|
||||||
|
*
|
||||||
* 原理
|
* 原理
|
||||||
* release开始检测.
|
* release开始检测.
|
||||||
* 发现longClick只发送longClick.
|
* 发现longClick只发送longClick.
|
||||||
@ -28,7 +33,7 @@
|
|||||||
*
|
*
|
||||||
* DoubleClick检测是独立于系统的,用户可以在页面里实现多套独立的按键时延检测,一个widget一个时延系统也没问题.
|
* DoubleClick检测是独立于系统的,用户可以在页面里实现多套独立的按键时延检测,一个widget一个时延系统也没问题.
|
||||||
*/
|
*/
|
||||||
class QQTSHARED_EXPORT QQtDoubleClickHelper : public QQtClickHelper
|
class QQTSHARED_EXPORT QQtDoubleClickHelper : public QQtLongClickHelper
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -39,9 +44,9 @@ public:
|
|||||||
//调用于userWidget相对应的Event里
|
//调用于userWidget相对应的Event里
|
||||||
//允许重写
|
//允许重写
|
||||||
public:
|
public:
|
||||||
virtual void mousePressEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
virtual void mousePressEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override;
|
||||||
virtual void mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
virtual void mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override;
|
||||||
virtual void mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget = 0 );
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget = 0 ) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void doubleClick();
|
void doubleClick();
|
||||||
@ -54,9 +59,6 @@ signals:
|
|||||||
|
|
||||||
//optional
|
//optional
|
||||||
public:
|
public:
|
||||||
//这个语法比较难,只有整型有特权.
|
|
||||||
static const int doubleClickInterval = 400;
|
|
||||||
|
|
||||||
//设置双击检测时延 default: doubleClickInterval ms
|
//设置双击检测时延 default: doubleClickInterval ms
|
||||||
//不会影响系统默认时延
|
//不会影响系统默认时延
|
||||||
void setDoubleClickInterval ( int millSecond = doubleClickInterval ) {
|
void setDoubleClickInterval ( int millSecond = doubleClickInterval ) {
|
||||||
@ -66,7 +68,8 @@ public:
|
|||||||
return mDoubleClickInterval;
|
return mDoubleClickInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 doubleClickNum() const { return nDoubleClickNum; }
|
inline const quint32 doubleClickNum() const { return nDoubleClickNum; }
|
||||||
|
inline const quint32 doubleClickNumWithCancel() const { return nDoubleClickNumWithCancel; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以下用于内部
|
* 以下用于内部
|
||||||
@ -79,6 +82,9 @@ public slots:
|
|||||||
void slotDoubleClickTimeout();
|
void slotDoubleClickTimeout();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
//这个语法比较难,只有整型有特权.
|
||||||
|
static const int doubleClickInterval = 260;
|
||||||
|
|
||||||
//clickTimer
|
//clickTimer
|
||||||
QTimer* m_click_timer;
|
QTimer* m_click_timer;
|
||||||
//longClickTimer
|
//longClickTimer
|
||||||
@ -86,8 +92,6 @@ protected:
|
|||||||
//doubleClickTimer
|
//doubleClickTimer
|
||||||
QTimer* m_double_click_timer;
|
QTimer* m_double_click_timer;
|
||||||
|
|
||||||
//用于记录按钮的位置
|
|
||||||
QPoint mPoint;
|
|
||||||
|
|
||||||
//双击200ms. 这个比较符合双击舒适度.Qt内部的Timer慢一些,可能是计算了比较完整的时间.
|
//双击200ms. 这个比较符合双击舒适度.Qt内部的Timer慢一些,可能是计算了比较完整的时间.
|
||||||
//在这个范围内的都 才 是双击
|
//在这个范围内的都 才 是双击
|
||||||
@ -96,13 +100,24 @@ protected:
|
|||||||
//click 检测使用
|
//click 检测使用
|
||||||
QTime startClickTime;
|
QTime startClickTime;
|
||||||
|
|
||||||
|
//double click检测用
|
||||||
|
QTime prev_doubleclick;
|
||||||
|
QTime now_doubleclick;
|
||||||
|
|
||||||
|
//long click用
|
||||||
|
QTime prev_release;
|
||||||
|
QTime now_release_initial;
|
||||||
|
|
||||||
//click 用
|
//click 用
|
||||||
QWidget* mUserWidget;
|
QWidget* mUserWidget;
|
||||||
QQtMouseEvent* mMouseEvent;
|
QQtMouseEvent* mMouseEvent;
|
||||||
|
|
||||||
//click num
|
//click num
|
||||||
virtual void checkClickNum();
|
virtual void checkClickNum ( QQtClickType type ) override;
|
||||||
|
virtual void checkClickNumWithCancel() override;
|
||||||
|
|
||||||
quint32 nDoubleClickNum;
|
quint32 nDoubleClickNum;
|
||||||
|
quint32 nDoubleClickNumWithCancel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QQTDOUBLECLICKHELPER_H
|
#endif // QQTDOUBLECLICKHELPER_H
|
1
src/exquisite/clickwidgets/qqtdoubleclicklabel.cpp
Normal file
1
src/exquisite/clickwidgets/qqtdoubleclicklabel.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtdoubleclicklabel.h"
|
112
src/exquisite/clickwidgets/qqtdoubleclicklabel.h
Normal file
112
src/exquisite/clickwidgets/qqtdoubleclicklabel.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#ifndef QQTDOUBLECLICKLABEL_H
|
||||||
|
#define QQTDOUBLECLICKLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtdoubleclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个虚类
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtDoubleClickLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit QQtDoubleClickLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtDoubleClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtDoubleClickLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
void doubleClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
void doubleClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtDoubleClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtDoubleClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
||||||
|
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtDoubleClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTDOUBLECLICKLABEL_H
|
1
src/exquisite/clickwidgets/qqtdoubleclickwidget.cpp
Normal file
1
src/exquisite/clickwidgets/qqtdoubleclickwidget.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtdoubleclickwidget.h"
|
115
src/exquisite/clickwidgets/qqtdoubleclickwidget.h
Normal file
115
src/exquisite/clickwidgets/qqtdoubleclickwidget.h
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#ifndef QQTDOUBLECLICKWIDGET_H
|
||||||
|
#define QQTDOUBLECLICKWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtdoubleclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内置DoubleClickHelper
|
||||||
|
*
|
||||||
|
* 添加了doubleClick支持的QQtClickWidget
|
||||||
|
* 这个Widget表示了如何使用QQtWidgetClickHelper和它的子类
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtDoubleClickWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtDoubleClickWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtDoubleClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtDoubleClickWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
void doubleClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
void doubleClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtDoubleClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtDoubleClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
||||||
|
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtDoubleClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTDOUBLECLICKWIDGET_H
|
@ -1,56 +1,61 @@
|
|||||||
#include "qqtclickhelper.h"
|
#include "qqtlongclickhelper.h"
|
||||||
|
|
||||||
QQtClickHelper::QQtClickHelper ( QObject* parent )
|
QQtLongClickHelper::QQtLongClickHelper ( QObject* parent ) : QQtClickHelper ( parent )
|
||||||
{
|
{
|
||||||
mLongClickInterval = longClickInterval;
|
mLongClickInterval = longClickInterval;
|
||||||
|
|
||||||
t1 = QTime::currentTime();
|
now_press = QTime::currentTime().addMSecs ( 1 );
|
||||||
t2 = QTime::currentTime();
|
now_release = QTime::currentTime().addMSecs ( 2 );
|
||||||
|
|
||||||
nClickNum = 0;
|
|
||||||
nLongClickNum = 0;
|
nLongClickNum = 0;
|
||||||
nTotalClickNum = 0;
|
nLongClickNumWithCancel = 0;
|
||||||
|
|
||||||
mClickType = QQtNullClick;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QQtClickHelper::~QQtClickHelper()
|
QQtLongClickHelper::~QQtLongClickHelper()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtClickHelper::mousePressEvent ( QMouseEvent* event, QWidget* userWidget )
|
void QQtLongClickHelper::mousePressEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
{
|
{
|
||||||
p2debug() << "press" << event->pos() << userWidget;
|
p2debug() << "press" << event->pos() << userWidget;
|
||||||
mPoint = event->pos();
|
mPoint = event->pos();
|
||||||
mClickType = QQtClick;
|
mClickType = QQtClick;
|
||||||
t1 = QTime::currentTime();
|
now_press = QTime::currentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget )
|
void QQtLongClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
{
|
{
|
||||||
p2debug() << "release" << event->pos() << userWidget;
|
p2debug() << "release" << event->pos() << userWidget;
|
||||||
//这一次 current click
|
//这一次 current click
|
||||||
t2 = QTime::currentTime();
|
QTime t2_release_preview = now_release;
|
||||||
|
now_release = QTime::currentTime();
|
||||||
//这里加了个判断,其实肯定>=0
|
//这里加了个判断,其实肯定>=0
|
||||||
if ( t1.msecsTo ( t2 ) >= 0 && t1.msecsTo ( t2 ) <= mLongClickInterval )
|
if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) <= mLongClickInterval )
|
||||||
{
|
{
|
||||||
//单击发生
|
//单击发生
|
||||||
mClickType = QQtClick;
|
mClickType = QQtClick;
|
||||||
}
|
}
|
||||||
else if ( t1.msecsTo ( t2 ) >= 0 && t1.msecsTo ( t2 ) > mLongClickInterval )
|
else if ( now_press.msecsTo ( now_release ) >= 0 && now_press.msecsTo ( now_release ) > mLongClickInterval )
|
||||||
{
|
{
|
||||||
//长击发生
|
//长击发生
|
||||||
mClickType = QQtLongClick;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//更新t1 防止用户忘记press,直接release.
|
|
||||||
//preview click
|
|
||||||
t1 = QTime::currentTime();
|
|
||||||
|
|
||||||
if ( mClickType == QQtLongClick )
|
if ( mClickType == QQtLongClick )
|
||||||
{
|
{
|
||||||
//计算点击数目
|
//计算点击数目
|
||||||
checkClickNum();
|
checkClickNumWithCancel();
|
||||||
|
|
||||||
//修改状态
|
//修改状态
|
||||||
mClickType = QQtNullClick;
|
mClickType = QQtNullClick;
|
||||||
@ -67,18 +72,25 @@ void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkClickNum ( QQtLongClick );
|
||||||
|
|
||||||
//发送长信号
|
//发送长信号
|
||||||
p2debug() << "send long click " ;
|
p2debug() << "send long click " ;
|
||||||
emit longClick();
|
emit longClick();
|
||||||
emit longClickWithPoint ( event->pos() );
|
emit longClickWithPoint ( event->pos() );
|
||||||
|
|
||||||
emit longClickWithPointF ( event->localPos() );
|
emit longClickWithPointF ( event->localPos() );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
emit longClick ( userWidget );
|
||||||
|
emit longClickWithPoint ( event->pos(), userWidget );
|
||||||
|
emit longClickWithPointF ( event->localPos(), userWidget );
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ( mClickType == QQtClick )
|
else if ( mClickType == QQtClick )
|
||||||
{
|
{
|
||||||
//计算点击数目
|
//计算点击数目
|
||||||
checkClickNum();
|
checkClickNumWithCancel();
|
||||||
|
|
||||||
//修改状态
|
//修改状态
|
||||||
mClickType = QQtNullClick;
|
mClickType = QQtNullClick;
|
||||||
@ -95,12 +107,20 @@ void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkClickNum ( QQtClick );
|
||||||
|
|
||||||
//发送单击信号
|
//发送单击信号
|
||||||
p2debug() << "send click." ;
|
p2debug() << "send click." ;
|
||||||
emit click();
|
emit click();
|
||||||
emit clickWithPoint ( event->pos() );
|
emit clickWithPoint ( event->pos() );
|
||||||
|
|
||||||
emit clickWithPointF ( event->localPos() );
|
emit clickWithPointF ( event->localPos() );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
emit click ( userWidget );
|
||||||
|
emit clickWithPoint ( event->pos(), userWidget );
|
||||||
|
emit clickWithPointF ( event->localPos(), userWidget );
|
||||||
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,42 +133,55 @@ void QQtClickHelper::mouseReleaseEvent ( QMouseEvent* event, QWidget* userWidget
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtClickHelper::mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget )
|
void QQtLongClickHelper::mouseDoubleClickEvent ( QMouseEvent* event, QWidget* userWidget )
|
||||||
{
|
{
|
||||||
p2debug() << "double click" << event->pos() << userWidget;
|
p2debug() << "double click" << event->pos() << userWidget;
|
||||||
mPoint = event->pos();
|
mPoint = event->pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QQtClickHelper::setLongClickInterval ( int millSecond )
|
void QQtLongClickHelper::setLongClickInterval ( int millSecond )
|
||||||
{
|
{
|
||||||
mLongClickInterval = millSecond;
|
mLongClickInterval = millSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QQtClickHelper::getLongClickInterval() const
|
int QQtLongClickHelper::getLongClickInterval() const
|
||||||
{
|
{
|
||||||
return mLongClickInterval;
|
return mLongClickInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QQtClickHelper::clickNum() const { return nClickNum; }
|
|
||||||
|
|
||||||
quint32 QQtClickHelper::longClickNum() const { return nLongClickNum; }
|
void QQtLongClickHelper::checkClickNumWithCancel()
|
||||||
|
|
||||||
quint64 QQtClickHelper::totalClickNum() const { return nTotalClickNum; }
|
|
||||||
|
|
||||||
void QQtClickHelper::checkClickNum()
|
|
||||||
{
|
{
|
||||||
|
QQtClickHelper::checkClickNumWithCancel();
|
||||||
switch ( mClickType )
|
switch ( mClickType )
|
||||||
{
|
{
|
||||||
case QQtClick:
|
case QQtLongClick:
|
||||||
{
|
{
|
||||||
nClickNum++;
|
nLongClickNumWithCancel++;
|
||||||
if ( nClickNum >= 0xFFFFFFFF )
|
if ( nLongClickNumWithCancel >= 0xFFFFFFFF )
|
||||||
{
|
{
|
||||||
p2debug() << "out......";
|
p2debug() << "out......";
|
||||||
nClickNum = 0;
|
nLongClickNumWithCancel = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case QQtLongClick:
|
||||||
{
|
{
|
||||||
nLongClickNum++;
|
nLongClickNum++;
|
92
src/exquisite/clickwidgets/qqtlongclickhelper.h
Normal file
92
src/exquisite/clickwidgets/qqtlongclickhelper.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#ifndef QQTLONGCLICKHELPER_H
|
||||||
|
#define QQTLONGCLICKHELPER_H
|
||||||
|
|
||||||
|
#include <qqtclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
1
src/exquisite/clickwidgets/qqtlongclicklabel.cpp
Normal file
1
src/exquisite/clickwidgets/qqtlongclicklabel.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtlongclicklabel.h"
|
108
src/exquisite/clickwidgets/qqtlongclicklabel.h
Normal file
108
src/exquisite/clickwidgets/qqtlongclicklabel.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#ifndef QQTLONGCLICKLABEL_H
|
||||||
|
#define QQTLONGCLICKLABEL_H
|
||||||
|
|
||||||
|
#include <qqtlabel.h>
|
||||||
|
#include <qqtlongclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个是个虚类
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 为确定功能的子类Label服务
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtLongClickLabel : public QQtLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QQtLongClickLabel ( QWidget* parent = 0 ) :
|
||||||
|
QQtLabel ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtLongClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtLongClickLabel() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtLongClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtLongClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtLongClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtLabel::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtLabel::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtLabel::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTLONGCLICKLABEL_H
|
1
src/exquisite/clickwidgets/qqtlongclickwidget.cpp
Normal file
1
src/exquisite/clickwidgets/qqtlongclickwidget.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "qqtlongclickwidget.h"
|
107
src/exquisite/clickwidgets/qqtlongclickwidget.h
Normal file
107
src/exquisite/clickwidgets/qqtlongclickwidget.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifndef QQTLONGCLICKWIDGET_H
|
||||||
|
#define QQTLONGCLICKWIDGET_H
|
||||||
|
|
||||||
|
#include <qqtwidget.h>
|
||||||
|
#include <qqtlongclickhelper.h>
|
||||||
|
|
||||||
|
#include <qqt-local.h>
|
||||||
|
#include <qqtcore.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供安装ClickHelper的能力
|
||||||
|
* 为确定功能的子类Widget服务
|
||||||
|
*/
|
||||||
|
class QQTSHARED_EXPORT QQtLongClickWidget : public QQtWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QQtLongClickWidget ( QWidget* parent = 0 ) :
|
||||||
|
QQtWidget ( parent ) {
|
||||||
|
mClickHelper = 0;
|
||||||
|
mClickHelper = new QQtLongClickHelper ( this );
|
||||||
|
installClickHelper ( mClickHelper );
|
||||||
|
}
|
||||||
|
virtual ~QQtLongClickWidget() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给App用信号
|
||||||
|
* 界面层内部直接处理
|
||||||
|
*/
|
||||||
|
signals:
|
||||||
|
void click();
|
||||||
|
void longClick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clickWithPoint ( QPoint point );
|
||||||
|
void longClickWithPoint ( QPoint point );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户可选使用
|
||||||
|
*/
|
||||||
|
public:
|
||||||
|
inline void installClickHelper ( QQtLongClickHelper* helper ) {
|
||||||
|
unConnectClickHelper();
|
||||||
|
mClickHelper = helper;
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
connectClickHelper();
|
||||||
|
}
|
||||||
|
inline QQtLongClickHelper* clickHelper() const {
|
||||||
|
return mClickHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类重写这两个函数,实现丰富的click能力
|
||||||
|
*/
|
||||||
|
// QQtWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void connectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void unConnectClickHelper() {
|
||||||
|
if ( !mClickHelper )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
||||||
|
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQtLongClickHelper* mClickHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子类不必重写MouseEvent函数,
|
||||||
|
* 这里实现对clickHelper的响应能力
|
||||||
|
*/
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
virtual void mousePressEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mousePressEvent ( event, this );
|
||||||
|
return QQtWidget::mousePressEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseReleaseEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseReleaseEvent ( event, this );
|
||||||
|
return QQtWidget::mouseReleaseEvent ( event );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) {
|
||||||
|
if ( mClickHelper )
|
||||||
|
mClickHelper->mouseDoubleClickEvent ( event, this );
|
||||||
|
return QQtWidget::mouseDoubleClickEvent ( event );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QQTLONGCLICKWIDGET_H
|
@ -1,35 +0,0 @@
|
|||||||
#include "qqtcanclicklabel.h"
|
|
||||||
|
|
||||||
QQtCanClickLabel::QQtCanClickLabel ( QWidget* parent ) :
|
|
||||||
QQtLabel ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtCanClickLabel::~QQtCanClickLabel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QQtCanClickLabel::mousePressEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mousePressEvent ( event, this );
|
|
||||||
return QQtLabel::mousePressEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtCanClickLabel::mouseReleaseEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mouseReleaseEvent ( event, this );
|
|
||||||
return QQtLabel::mouseReleaseEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtCanClickLabel::mouseDoubleClickEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mouseDoubleClickEvent ( event, this );
|
|
||||||
return QQtLabel::mouseDoubleClickEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
#ifndef QQTCANCLICKLABEL_H
|
|
||||||
#define QQTCANCLICKLABEL_H
|
|
||||||
|
|
||||||
#include <qqtlabel.h>
|
|
||||||
#include <qqtclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这个是个虚类
|
|
||||||
* 提供安装ClickHelper的能力
|
|
||||||
* 为确定功能的子类Label服务
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtCanClickLabel : public QQtLabel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtCanClickLabel ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtCanClickLabel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline void setClickHelper ( QQtClickHelper* helper ) {
|
|
||||||
uninstallClickHelper();
|
|
||||||
mClickHelper = helper;
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
inline const QQtClickHelper* clickHelper() const {
|
|
||||||
return mClickHelper;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
//需要重写
|
|
||||||
virtual void installClickHelper() {}
|
|
||||||
virtual void uninstallClickHelper() {}
|
|
||||||
QQtClickHelper* mClickHelper;
|
|
||||||
|
|
||||||
// QWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void mousePressEvent ( QMouseEvent* event ) override;
|
|
||||||
virtual void mouseReleaseEvent ( QMouseEvent* event ) override;
|
|
||||||
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTCANCLICKLABEL_H
|
|
@ -1,35 +0,0 @@
|
|||||||
#include "qqtcanclickwidget.h"
|
|
||||||
|
|
||||||
QQtCanClickWidget::QQtCanClickWidget ( QWidget* parent ) :
|
|
||||||
QQtWidget ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtCanClickWidget::~QQtCanClickWidget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void QQtCanClickWidget::mousePressEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mousePressEvent ( event, this );
|
|
||||||
return QQtWidget::mousePressEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtCanClickWidget::mouseReleaseEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mouseReleaseEvent ( event, this );
|
|
||||||
return QQtWidget::mouseReleaseEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtCanClickWidget::mouseDoubleClickEvent ( QMouseEvent* event )
|
|
||||||
{
|
|
||||||
if ( mClickHelper )
|
|
||||||
mClickHelper->mouseDoubleClickEvent ( event, this );
|
|
||||||
return QQtWidget::mouseDoubleClickEvent ( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
#ifndef QQTCANCLICKWIDGET_H
|
|
||||||
#define QQTCANCLICKWIDGET_H
|
|
||||||
|
|
||||||
#include <qqtwidget.h>
|
|
||||||
#include <qqtclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这个是个虚类
|
|
||||||
* 提供安装ClickHelper的能力
|
|
||||||
* 为确定功能的子类Widget服务
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtCanClickWidget : public QQtWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtCanClickWidget ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtCanClickWidget();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public:
|
|
||||||
inline void setClickHelper ( QQtClickHelper* helper ) {
|
|
||||||
uninstallClickHelper();
|
|
||||||
mClickHelper = helper;
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
inline const QQtClickHelper* clickHelper() const {
|
|
||||||
return mClickHelper;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
//需要重写
|
|
||||||
virtual void installClickHelper() {}
|
|
||||||
virtual void uninstallClickHelper() {}
|
|
||||||
QQtClickHelper* mClickHelper;
|
|
||||||
|
|
||||||
// QWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void mousePressEvent ( QMouseEvent* event ) override;
|
|
||||||
virtual void mouseReleaseEvent ( QMouseEvent* event ) override;
|
|
||||||
virtual void mouseDoubleClickEvent ( QMouseEvent* event ) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTCANCLICKWIDGET_H
|
|
@ -1,35 +0,0 @@
|
|||||||
#include "qqtclicklabel.h"
|
|
||||||
|
|
||||||
QQtClickLabel::QQtClickLabel ( QWidget* parent ) :
|
|
||||||
QQtCanClickLabel ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = new QQtClickHelper ( this );
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtClickLabel::~QQtClickLabel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtClickLabel::installClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
|
|
||||||
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtClickLabel::uninstallClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
#ifndef QQTCLICKLABEL_H
|
|
||||||
#define QQTCLICKLABEL_H
|
|
||||||
|
|
||||||
#include <qqtcanclicklabel.h>
|
|
||||||
#include <qqtclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这个是个虚类
|
|
||||||
* 提供安装ClickHelper的能力
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtClickLabel : public QQtCanClickLabel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtClickLabel ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtClickLabel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void click();
|
|
||||||
void longClick();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPoint ( QPoint point );
|
|
||||||
void longClickWithPoint ( QPoint point );
|
|
||||||
|
|
||||||
// QQtWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void installClickHelper() override;
|
|
||||||
virtual void uninstallClickHelper() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTCLICKLABEL_H
|
|
@ -1,35 +0,0 @@
|
|||||||
#include "qqtclickwidget.h"
|
|
||||||
|
|
||||||
QQtClickWidget::QQtClickWidget ( QWidget* parent ) :
|
|
||||||
QQtCanClickWidget ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = new QQtClickHelper ( this );
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtClickWidget::~QQtClickWidget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtClickWidget::installClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
|
|
||||||
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtClickWidget::uninstallClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
|||||||
#ifndef QQTCLICKWIDGET_H
|
|
||||||
#define QQTCLICKWIDGET_H
|
|
||||||
|
|
||||||
#include <qqtcanclickwidget.h>
|
|
||||||
#include <qqtclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加了longClick支持的QQtCanClickWidget
|
|
||||||
* 这个Widget表示了如何使用QQtWidgetClickHelper和它的子类
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtClickWidget : public QQtCanClickWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtClickWidget ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtClickWidget();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 按键功能支持者
|
|
||||||
*/
|
|
||||||
signals:
|
|
||||||
void click();
|
|
||||||
void longClick();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPoint ( QPoint point );
|
|
||||||
void longClickWithPoint ( QPoint point );
|
|
||||||
|
|
||||||
// QQtWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void installClickHelper() override;
|
|
||||||
virtual void uninstallClickHelper() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTCLICKWIDGET_H
|
|
@ -1,37 +0,0 @@
|
|||||||
#include "qqtdoubleclicklabel.h"
|
|
||||||
|
|
||||||
QQtDoubleClickLabel::QQtDoubleClickLabel ( QWidget* parent ) :
|
|
||||||
QQtCanClickLabel ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = new QQtDoubleClickHelper ( this );
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtDoubleClickLabel::~QQtDoubleClickLabel()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtDoubleClickLabel::installClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtDoubleClickLabel::uninstallClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
|
||||||
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#ifndef QQTDOUBLECLICKLABEL_H
|
|
||||||
#define QQTDOUBLECLICKLABEL_H
|
|
||||||
|
|
||||||
#include <qqtcanclicklabel.h>
|
|
||||||
#include <qqtdoubleclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这个是个虚类
|
|
||||||
* 提供安装ClickHelper的能力
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtDoubleClickLabel : public QQtCanClickLabel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtDoubleClickLabel ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtDoubleClickLabel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void click();
|
|
||||||
void longClick();
|
|
||||||
void doubleClick();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPoint ( QPoint point );
|
|
||||||
void longClickWithPoint ( QPoint point );
|
|
||||||
void doubleClickWithPoint ( QPoint point );
|
|
||||||
|
|
||||||
// QQtWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void installClickHelper() override;
|
|
||||||
virtual void uninstallClickHelper() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTDOUBLECLICKLABEL_H
|
|
@ -1,38 +0,0 @@
|
|||||||
#include "qqtdoubleclickwidget.h"
|
|
||||||
|
|
||||||
QQtDoubleClickWidget::QQtDoubleClickWidget ( QWidget* parent ) :
|
|
||||||
QQtCanClickWidget ( parent )
|
|
||||||
{
|
|
||||||
mClickHelper = new QQtDoubleClickHelper ( this );
|
|
||||||
installClickHelper();
|
|
||||||
}
|
|
||||||
|
|
||||||
QQtDoubleClickWidget::~QQtDoubleClickWidget()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtDoubleClickWidget::installClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
connect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
connect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this, SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QQtDoubleClickWidget::uninstallClickHelper()
|
|
||||||
{
|
|
||||||
if ( !mClickHelper )
|
|
||||||
return;
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( click() ), this, SIGNAL ( click() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClick() ), this, SIGNAL ( longClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( doubleClick() ), this, SIGNAL ( doubleClick() ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( clickWithPoint ( QPoint ) ), this, SIGNAL ( clickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( longClickWithPoint ( QPoint ) ), this, SIGNAL ( longClickWithPoint ( QPoint ) ) );
|
|
||||||
disconnect ( mClickHelper, SIGNAL ( doubleClickWithPoint ( QPoint ) ), this,
|
|
||||||
SIGNAL ( doubleClickWithPoint ( QPoint ) ) );
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
#ifndef QQTDOUBLECLICKWIDGET_H
|
|
||||||
#define QQTDOUBLECLICKWIDGET_H
|
|
||||||
|
|
||||||
#include <qqtcanclickwidget.h>
|
|
||||||
#include <qqtdoubleclickhelper.h>
|
|
||||||
|
|
||||||
#include <qqt-local.h>
|
|
||||||
#include <qqtcore.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加了doubleClick支持的QQtClickWidget
|
|
||||||
* 这个Widget表示了如何使用QQtWidgetClickHelper和它的子类
|
|
||||||
*/
|
|
||||||
class QQTSHARED_EXPORT QQtDoubleClickWidget : public QQtCanClickWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QQtDoubleClickWidget ( QWidget* parent = 0 );
|
|
||||||
virtual ~QQtDoubleClickWidget();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void click();
|
|
||||||
void longClick();
|
|
||||||
void doubleClick();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void clickWithPoint ( QPoint point );
|
|
||||||
void longClickWithPoint ( QPoint point );
|
|
||||||
void doubleClickWithPoint ( QPoint point );
|
|
||||||
|
|
||||||
// QQtWidget interface
|
|
||||||
protected:
|
|
||||||
virtual void installClickHelper() override;
|
|
||||||
virtual void uninstallClickHelper() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // QQTDOUBLECLICKWIDGET_H
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "qqtapplication.h"
|
#include "qqtapplication.h"
|
||||||
#ifdef __PLUGINSUPPORT__
|
#ifdef __PLUGINSUPPORT__
|
||||||
#include "qqtpluginwatcher.h"
|
#include "qqtpluginwatcher.h"
|
||||||
#endif
|
#endif
|
||||||
@ -49,14 +49,14 @@ QQtApplication::QQtApplication ( int& argc, char** argv ) :
|
|||||||
QDir::setCurrent ( qApp->applicationDirPath() );
|
QDir::setCurrent ( qApp->applicationDirPath() );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*在linux系统,不自动在当前目录寻找lib,需要命令行设置LD_LIBRARY_PATH,这里添加一下自动查找,不冲突。*/
|
|
||||||
addLibraryPath ( qApp->applicationDirPath() );//[qApp->]
|
|
||||||
|
|
||||||
pline() << "app root:" << qApp->applicationDirPath();
|
pline() << "app root:" << qApp->applicationDirPath();
|
||||||
pline() << "app work root:" << QDir::currentPath();
|
pline() << "app work root:" << QDir::currentPath();
|
||||||
pline() << "Qt version:" << QT_VERSION_STR;
|
pline() << "Qt version:" << QT_VERSION_STR;
|
||||||
pline() << "LibQQt version:" << STR ( QQT_VERSION );
|
pline() << "LibQQt version:" << STR ( QQT_VERSION );
|
||||||
|
|
||||||
|
/*在linux系统,不自动在当前目录寻找lib,需要命令行设置LD_LIBRARY_PATH,这里添加一下自动查找,不冲突。*/
|
||||||
|
addLibraryPath ( QDir::currentPath() );//[qApp->]
|
||||||
|
|
||||||
#ifdef __EMBEDDED_LINUX__
|
#ifdef __EMBEDDED_LINUX__
|
||||||
pline() << "QTDIR:" << QProcessEnvironment::systemEnvironment().value ( "QTDIR" );
|
pline() << "QTDIR:" << QProcessEnvironment::systemEnvironment().value ( "QTDIR" );
|
||||||
pline() << "TSLIB_TSDEVICE:" << QProcessEnvironment::systemEnvironment().value ( "TSLIB_TSDEVICE" );
|
pline() << "TSLIB_TSDEVICE:" << QProcessEnvironment::systemEnvironment().value ( "TSLIB_TSDEVICE" );
|
||||||
|
@ -343,6 +343,11 @@ contains (DEFINES, __EXQUISITE__) {
|
|||||||
#single color only widget
|
#single color only widget
|
||||||
DEFINES += __COLORWIDGETS__
|
DEFINES += __COLORWIDGETS__
|
||||||
|
|
||||||
|
#click widgets
|
||||||
|
DEFINES += __CLICKWIDGETS__
|
||||||
|
|
||||||
|
#click sound widgets
|
||||||
|
DEFINES += __CLICKSOUNDWIDGETS__
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -432,6 +437,8 @@ defineReplace(qqt_header){
|
|||||||
|
|
||||||
#exquisite widgets
|
#exquisite widgets
|
||||||
command += $${path}/exquisite
|
command += $${path}/exquisite
|
||||||
|
command += $${path}/exquisite/clicksoundwidgets
|
||||||
|
command += $${path}/exquisite/clickwidgets
|
||||||
command += $${path}/exquisite/svgwidgets
|
command += $${path}/exquisite/svgwidgets
|
||||||
command += $${path}/exquisite/gifwidgets
|
command += $${path}/exquisite/gifwidgets
|
||||||
command += $${path}/exquisite/openglwidgets
|
command += $${path}/exquisite/openglwidgets
|
||||||
|
@ -9,10 +9,29 @@
|
|||||||
|
|
||||||
#FileSystemName的终极状态是编译器_目标系统名,比如gcc_macOS, clang_macOS这样。
|
#FileSystemName的终极状态是编译器_目标系统名,比如gcc_macOS, clang_macOS这样。
|
||||||
|
|
||||||
#target arch type
|
#当工程编译目标相同,可是编译配置的Qt版本不同的时候,这个机制有一点点缺点,
|
||||||
|
#使用相同的中间编译目录吗? 很明显,这不合理?No,这很合理.Qt版本变化,引起链接库变化,但是,还是Qt,依然是Qt.程序中应当注意使用的Qt库(Qt4和Qt5库名字不太一样)和版本(版本号不一样,源代码会有点小区别,需要注意兼容性).
|
||||||
|
#比如桌面 gcc_64的Qt4 和 gcc_64的Qt5,不合适使用相同的中间编译目录,可是他们的FileSystemName都是Linux64,导致中间编译目录相同.
|
||||||
|
#为此,做出改进? No,用户请注意电脑上用Qt5开发就不要用Qt4,如果使用Qt4,请换电脑进行开发.(或者全部rebuild?其实Qt的版本之间引起的差异,如果不大,混用没什么问题,Qt库只能使用一个版本的)
|
||||||
|
#整体而言,Qt版本变化,引发的编译会比较多源文件.建议使用不同电脑开发.
|
||||||
|
|
||||||
|
#原理
|
||||||
|
#Qt Creator kit页的FileSystemName Creator自己用,忘记了传给qmake.(存储于Qt Creator配置区域)
|
||||||
|
#工程构建和配置页(存储于.pro.userxxx)里的环境变量QKIT给qmake用.
|
||||||
|
#如果用户在pro里面设置QMAKE.KIT QMAKE.SYSNAME,Qt Creator从qmake里读也挺好的.
|
||||||
|
|
||||||
#You need define a env variable QKIT=XX
|
#You need define a env variable QKIT=XX
|
||||||
|
#target arch type
|
||||||
|
#注释
|
||||||
|
#config += xxx qmake用配置开关
|
||||||
|
#$$(XXX) 环境变量XXX
|
||||||
|
#$${XXX} qmake用变量XXX
|
||||||
|
#XXX = AAA 给qmake用变量XXX赋值
|
||||||
|
#DEFINES += XXX 源代码用宏 和上边的XXX可以重名,但是是两回事,不干扰.
|
||||||
|
|
||||||
QKIT_PRIVATE = $$(QKIT)
|
QKIT_PRIVATE = $$(QKIT)
|
||||||
#处理文件内平台小差异
|
#源文件内平台小差异
|
||||||
|
#QKIT -> 源文件宏
|
||||||
#EMBEDDED __EMBEDDED_LINUX__
|
#EMBEDDED __EMBEDDED_LINUX__
|
||||||
#MIPS __MIPS_LINUX__
|
#MIPS __MIPS_LINUX__
|
||||||
#ARM __ARM_LINUX__
|
#ARM __ARM_LINUX__
|
||||||
@ -53,7 +72,7 @@ equals(QKIT_PRIVATE, EMBEDDED) {
|
|||||||
DEFINES += __ANDROID__
|
DEFINES += __ANDROID__
|
||||||
} else:equals(QKIT_PRIVATE, ANDROIDX86) {
|
} else:equals(QKIT_PRIVATE, ANDROIDX86) {
|
||||||
DEFINES += __ANDROID__
|
DEFINES += __ANDROID__
|
||||||
DEFINES += __ANDROIDX86__
|
DEFINES += __ANDROIDX86__ #可能废弃
|
||||||
}
|
}
|
||||||
|
|
||||||
#QMAKESPEC_NAME = $${QMAKESPEC}
|
#QMAKESPEC_NAME = $${QMAKESPEC}
|
||||||
|
@ -318,31 +318,6 @@ contains (DEFINES, __NETWORKSUPPORT__) {
|
|||||||
|
|
||||||
contains (DEFINES, __EXQUISITE__) {
|
contains (DEFINES, __EXQUISITE__) {
|
||||||
#exquisite
|
#exquisite
|
||||||
SOURCES += \
|
|
||||||
$$PWD/exquisite/qqtclickhelper.cpp \
|
|
||||||
$$PWD/exquisite/qqtdoubleclickhelper.cpp
|
|
||||||
HEADERS += \
|
|
||||||
$$PWD/exquisite/qqtclickhelper.h \
|
|
||||||
$$PWD/exquisite/qqtdoubleclickhelper.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
$$PWD/exquisite/qqtcanclickwidget.cpp \
|
|
||||||
$$PWD/exquisite/qqtclickwidget.cpp \
|
|
||||||
$$PWD/exquisite/qqtdoubleclickwidget.cpp
|
|
||||||
HEADERS += \
|
|
||||||
$$PWD/exquisite/qqtcanclickwidget.h \
|
|
||||||
$$PWD/exquisite/qqtclickwidget.h \
|
|
||||||
$$PWD/exquisite/qqtdoubleclickwidget.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
$$PWD/exquisite/qqtcanclicklabel.cpp \
|
|
||||||
$$PWD/exquisite/qqtclicklabel.cpp \
|
|
||||||
$$PWD/exquisite/qqtdoubleclicklabel.cpp
|
|
||||||
HEADERS += \
|
|
||||||
$$PWD/exquisite/qqtcanclicklabel.h \
|
|
||||||
$$PWD/exquisite/qqtclicklabel.h \
|
|
||||||
$$PWD/exquisite/qqtdoubleclicklabel.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/exquisite/qqtframelesshelper.cpp \
|
$$PWD/exquisite/qqtframelesshelper.cpp \
|
||||||
$$PWD/exquisite/qqtframelesshelperprivate.cpp
|
$$PWD/exquisite/qqtframelesshelperprivate.cpp
|
||||||
@ -350,6 +325,67 @@ contains (DEFINES, __EXQUISITE__) {
|
|||||||
$$PWD/exquisite/qqtframelesshelper.h \
|
$$PWD/exquisite/qqtframelesshelper.h \
|
||||||
$$PWD/exquisite/qqtframelesshelperprivate.h
|
$$PWD/exquisite/qqtframelesshelperprivate.h
|
||||||
|
|
||||||
|
#can click sound support widgets
|
||||||
|
contains (DEFINES, __CLICKSOUNDWIDGETS__) {
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundhelper.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundhelper.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundhelper.cpp
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundhelper.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundhelper.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundhelper.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundwidget.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundwidget.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundwidget.cpp
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundwidget.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundwidget.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundwidget.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundlabel.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundlabel.cpp \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundlabel.cpp
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtclicksoundlabel.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtlongclicksoundlabel.h \
|
||||||
|
$$PWD/exquisite/clicksoundwidgets/qqtdoubleclicksoundlabel.h
|
||||||
|
}
|
||||||
|
|
||||||
|
#can click support widgets
|
||||||
|
contains (DEFINES, __CLICKWIDGETS__) {
|
||||||
|
|
||||||
|
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 += \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtclickwidget.cpp \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtlongclickwidget.cpp \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtdoubleclickwidget.cpp
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtclickwidget.h \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtlongclickwidget.h \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtdoubleclickwidget.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtclicklabel.cpp \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtlongclicklabel.cpp \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtdoubleclicklabel.cpp
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtclicklabel.h \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtlongclicklabel.h \
|
||||||
|
$$PWD/exquisite/clickwidgets/qqtdoubleclicklabel.h
|
||||||
|
}
|
||||||
|
|
||||||
#dialog
|
#dialog
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/exquisite/qqtpopupdialog.cpp
|
$$PWD/exquisite/qqtpopupdialog.cpp
|
||||||
|
@ -21,6 +21,9 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
|||||||
this, SLOT ( set4Sum() ) );
|
this, SLOT ( set4Sum() ) );
|
||||||
connect ( ui->widget_2, SIGNAL ( longClick() ),
|
connect ( ui->widget_2, SIGNAL ( longClick() ),
|
||||||
this, SLOT ( set5Sum() ) );
|
this, SLOT ( set5Sum() ) );
|
||||||
|
|
||||||
|
connect ( ui->widget_3, SIGNAL ( click() ),
|
||||||
|
this, SLOT ( set6Sum() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -53,3 +56,8 @@ void MainWindow::set5Sum()
|
|||||||
{
|
{
|
||||||
ui->textBrowser_2->append ( QString ( "%1 long click" ).arg ( ui->widget_2->clickHelper()->totalClickNum() ) );;
|
ui->textBrowser_2->append ( QString ( "%1 long click" ).arg ( ui->widget_2->clickHelper()->totalClickNum() ) );;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::set6Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser_3->append ( QString ( "%1 click" ).arg ( ui->widget_3->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
@ -23,6 +23,8 @@ public slots:
|
|||||||
void set4Sum();
|
void set4Sum();
|
||||||
void set5Sum();
|
void set5Sum();
|
||||||
|
|
||||||
|
void set6Sum();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@ -42,14 +42,34 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="tab_2">
|
<widget class="QWidget" name="tab_2">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Click</string>
|
<string>LongClick</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextBrowser" name="textBrowser_2"/>
|
<widget class="QTextBrowser" name="textBrowser_2"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QQtClickWidget" name="widget_2" native="true">
|
<widget class="QQtLongClickWidget" name="widget_2" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Click</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="textBrowser_3"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QQtClickWidget" name="widget_3" native="true">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>200</width>
|
<width>200</width>
|
||||||
@ -70,7 +90,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>816</width>
|
<width>816</width>
|
||||||
<height>39</height>
|
<height>17</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -92,6 +112,12 @@
|
|||||||
<header>qqtdoubleclickwidget.h</header>
|
<header>qqtdoubleclickwidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QQtLongClickWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qqtlongclickwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QQtClickWidget</class>
|
<class>QQtClickWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
|
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/click.wav
Normal file
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/click.wav
Normal file
Binary file not shown.
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/doubleclick.wav
Normal file
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/doubleclick.wav
Normal file
Binary file not shown.
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/longclick.wav
Normal file
BIN
test/QQtWidgetClickSoundHelperTest/AppRoot/longclick.wav
Normal file
Binary file not shown.
@ -0,0 +1,40 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2018-03-28T19:21:56
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = QQtWidgetClickSoundHelperTest
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
# The following define makes your compiler emit warnings if you use
|
||||||
|
# any feature of Qt which as been marked as deprecated (the exact warnings
|
||||||
|
# depend on your compiler). Please consult the documentation of the
|
||||||
|
# deprecated API in order to know how to port your code away from it.
|
||||||
|
DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
|
# You can also make your code fail to compile if you use deprecated APIs.
|
||||||
|
# In order to do so, uncomment the following line.
|
||||||
|
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||||
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += main.cpp\
|
||||||
|
mainwindow.cpp
|
||||||
|
|
||||||
|
HEADERS += mainwindow.h
|
||||||
|
|
||||||
|
FORMS += mainwindow.ui
|
||||||
|
|
||||||
|
#促使qqt_deploy_config配置执行,没有这个变量不执行。
|
||||||
|
APP_CONFIG_PWD = $${PWD}/AppRoot
|
||||||
|
equals(QMAKE_HOST.os, Windows) {
|
||||||
|
APP_CONFIG_PWD ~=s,/,\\,g
|
||||||
|
}
|
||||||
|
|
||||||
|
system(touch main.cpp)
|
||||||
|
include (../../src/app_base_manager.pri)
|
11
test/QQtWidgetClickSoundHelperTest/main.cpp
Normal file
11
test/QQtWidgetClickSoundHelperTest/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "mainwindow.h"
|
||||||
|
#include <QQtApplication>
|
||||||
|
|
||||||
|
int main ( int argc, char* argv[] )
|
||||||
|
{
|
||||||
|
QQtApplication a ( argc, argv );
|
||||||
|
MainWindow w;
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
72
test/QQtWidgetClickSoundHelperTest/mainwindow.cpp
Normal file
72
test/QQtWidgetClickSoundHelperTest/mainwindow.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "mainwindow.h"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
#include "qqtcore.h"
|
||||||
|
#include <qqtframe.h>
|
||||||
|
|
||||||
|
MainWindow::MainWindow ( QWidget* parent ) :
|
||||||
|
QMainWindow ( parent ),
|
||||||
|
ui ( new Ui::MainWindow )
|
||||||
|
{
|
||||||
|
ui->setupUi ( this );
|
||||||
|
ui->widget;
|
||||||
|
ui->widget->setPixmap ( "" );
|
||||||
|
|
||||||
|
connect ( ui->widget, SIGNAL ( click() ),
|
||||||
|
this, SLOT ( setSum() ) );
|
||||||
|
connect ( ui->widget, SIGNAL ( doubleClick() ),
|
||||||
|
this, SLOT ( set2Sum() ) );
|
||||||
|
connect ( ui->widget, SIGNAL ( longClick() ),
|
||||||
|
this, SLOT ( set3Sum() ) );
|
||||||
|
|
||||||
|
ui->widget->clickHelper()->setClickSound ( qrc ( "click.wav" ) );
|
||||||
|
ui->widget->clickHelper()->setLongClickSound ( qrc ( "longclick.wav" ) );
|
||||||
|
ui->widget->clickHelper()->setDoubleClickSound ( qrc ( "doubleclick.wav" ) );
|
||||||
|
|
||||||
|
connect ( ui->widget_2, SIGNAL ( click() ),
|
||||||
|
this, SLOT ( set4Sum() ) );
|
||||||
|
connect ( ui->widget_2, SIGNAL ( longClick() ),
|
||||||
|
this, SLOT ( set5Sum() ) );
|
||||||
|
|
||||||
|
ui->widget_2->clickHelper()->setClickSound ( qrc ( "click.wav" ) );
|
||||||
|
ui->widget_2->clickHelper()->setLongClickSound ( qrc ( "longclick.wav" ) );
|
||||||
|
|
||||||
|
connect ( ui->widget_3, SIGNAL ( click() ),
|
||||||
|
this, SLOT ( set6Sum() ) );
|
||||||
|
ui->widget_3->clickHelper()->setClickSound ( qrc ( "click.wav" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setSum()
|
||||||
|
{
|
||||||
|
sender();
|
||||||
|
ui->textBrowser->append ( QString ( "%1 click" ).arg ( ui->widget->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::set2Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser->append ( QString ( "%1 double click" ).arg ( ui->widget->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::set3Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser->append ( QString ( "%1 long click" ).arg ( ui->widget->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::set4Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser_2->append ( QString ( "%1 click" ).arg ( ui->widget_2->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::set5Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser_2->append ( QString ( "%1 long click" ).arg ( ui->widget_2->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::set6Sum()
|
||||||
|
{
|
||||||
|
ui->textBrowser_3->append ( QString ( "%1 click" ).arg ( ui->widget_3->clickHelper()->totalClickNum() ) );;
|
||||||
|
}
|
32
test/QQtWidgetClickSoundHelperTest/mainwindow.h
Normal file
32
test/QQtWidgetClickSoundHelperTest/mainwindow.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class MainWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MainWindow ( QWidget* parent = 0 );
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setSum();
|
||||||
|
void set2Sum();
|
||||||
|
void set3Sum();
|
||||||
|
|
||||||
|
void set4Sum();
|
||||||
|
void set5Sum();
|
||||||
|
|
||||||
|
void set6Sum();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWindow* ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINWINDOW_H
|
130
test/QQtWidgetClickSoundHelperTest/mainwindow.ui
Normal file
130
test/QQtWidgetClickSoundHelperTest/mainwindow.ui
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>816</width>
|
||||||
|
<height>519</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Double Click</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="textBrowser"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QQtDoubleClickSoundWidget" name="widget" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>LongClick</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="textBrowser_2"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QQtLongClickSoundWidget" name="widget_2" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Click</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="textBrowser_3"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QQtClickSoundWidget" name="widget_3" native="true">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>200</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>816</width>
|
||||||
|
<height>17</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QQtDoubleClickSoundWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qqtdoubleclicksoundwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QQtLongClickSoundWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qqtlongclicksoundwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>QQtClickSoundWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qqtclicksoundwidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
x
Reference in New Issue
Block a user