Commit 4e8b65c5 by gujin.wang

为各核销界面添加拖动功能;修复一个指针判空bug

parent 6222412f
...@@ -29,4 +29,26 @@ void ConsumOkDialog::showConsumOk(const QString& act_name, const QString& code_n ...@@ -29,4 +29,26 @@ void ConsumOkDialog::showConsumOk(const QString& act_name, const QString& code_n
v.ui->labTime->setText( time_name); v.ui->labTime->setText( time_name);
v.ui->labCodeName->setText( code_name); v.ui->labCodeName->setText( code_name);
v.exec(); v.exec();
} }
\ No newline at end of file
void ConsumOkDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void ConsumOkDialog::mouseMoveEvent(QMouseEvent *e)
{
if(mouse_pressed && (e->buttons() & Qt::LeftButton) && (e->globalPos() - movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos() - movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void ConsumOkDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = true;
}
#ifndef CONSUMOKDIALOG_H #ifndef CONSUMOKDIALOG_H
#define CONSUMOKDIALOG_H #define CONSUMOKDIALOG_H
#include <QDialog> #include <QDialog>
#include <QMouseEvent>
namespace Ui { namespace Ui {
class ConsumOkDialog; class ConsumOkDialog;
...@@ -16,8 +17,15 @@ public: ...@@ -16,8 +17,15 @@ public:
~ConsumOkDialog(); ~ConsumOkDialog();
static void showConsumOk(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent = 0); static void showConsumOk(const QString& act_name, const QString& code_name, const QString& time_name, const QString& coupon, QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
private: private:
Ui::ConsumOkDialog *ui; Ui::ConsumOkDialog *ui;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // CONSUMOKDIALOG_H #endif // CONSUMOKDIALOG_H
...@@ -20,10 +20,13 @@ ConsumptionDialog::ConsumptionDialog(QWidget * parent, Qt::WindowFlags f) : ...@@ -20,10 +20,13 @@ ConsumptionDialog::ConsumptionDialog(QWidget * parent, Qt::WindowFlags f) :
ConsumptionDialog::~ConsumptionDialog() ConsumptionDialog::~ConsumptionDialog()
{ {
if(timer->isActive()) if(timer)
timer->stop(); {
timer->deleteLater(); if(timer->isActive())
timer = Q_NULLPTR; timer->stop();
timer->deleteLater();
timer = Q_NULLPTR;
}
delete ui; delete ui;
} }
...@@ -105,4 +108,28 @@ void ConsumptionDialog::setData(const QString& act_name, const QString& code_nam ...@@ -105,4 +108,28 @@ void ConsumptionDialog::setData(const QString& act_name, const QString& code_nam
ui->labCodeName->setText( code_name); ui->labCodeName->setText( code_name);
ui->labActName->setText( act_name); ui->labActName->setText( act_name);
ui->labTime->setText( time_name); ui->labTime->setText( time_name);
}
void ConsumptionDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void ConsumptionDialog::mouseMoveEvent(QMouseEvent *e)
{
if (mouse_pressed && (e->buttons() & Qt::LeftButton)
&& (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos()-movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void ConsumptionDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
return QDialog::mouseReleaseEvent(e);
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <QDialog> #include <QDialog>
#include <QTimer> #include <QTimer>
class WorkObject; #include <QMouseEvent>
namespace Ui { namespace Ui {
class ConsumptionDialog; class ConsumptionDialog;
...@@ -26,6 +26,11 @@ public: ...@@ -26,6 +26,11 @@ public:
private slots: private slots:
void OnTimeout(); void OnTimeout();
protected:
void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e);
signals: signals:
void sgBtnOk(); void sgBtnOk();
void sgBtnCannel(); void sgBtnCannel();
...@@ -33,6 +38,8 @@ signals: ...@@ -33,6 +38,8 @@ signals:
private: private:
Ui::ConsumptionDialog *ui; Ui::ConsumptionDialog *ui;
QTimer* timer; QTimer* timer;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // CONSUMPTIONDIALOG_H #endif // CONSUMPTIONDIALOG_H
...@@ -161,9 +161,9 @@ ...@@ -161,9 +161,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>105</y> <y>30</y>
<width>330</width> <width>330</width>
<height>80</height> <height>150</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
...@@ -175,14 +175,14 @@ ...@@ -175,14 +175,14 @@
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>330</width> <width>330</width>
<height>80</height> <height>150</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>查询中...</string> <string>查询中...</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignHCenter|Qt::AlignTop</set>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="labTime"> <widget class="QLabel" name="labTime">
......
#include "couponkeypad.h" #include "couponkeypad.h"
#include "ui_couponkeypad.h" #include "ui_couponkeypad.h"
CouponKeypad::CouponKeypad(QWidget *parent, Qt::WindowFlags f) : CouponKeypad::CouponKeypad(QWidget *parent, Qt::WindowFlags f) :
...@@ -52,4 +52,27 @@ void CouponKeypad::onDigitClicked() ...@@ -52,4 +52,27 @@ void CouponKeypad::onDigitClicked()
{ {
QPushButton *btn = qobject_cast<QPushButton*>(sender()); QPushButton *btn = qobject_cast<QPushButton*>(sender());
ui->text->setText(ui->text->text() + btn->text()); ui->text->setText(ui->text->text() + btn->text());
}
void CouponKeypad::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void CouponKeypad::mouseMoveEvent(QMouseEvent *e)
{
if (mouse_pressed && (e->buttons() & Qt::LeftButton)
&& (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos()-movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void CouponKeypad::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
} }
\ No newline at end of file
#ifndef COUPONKEYPAD_H #ifndef COUPONKEYPAD_H
#define COUPONKEYPAD_H #define COUPONKEYPAD_H
#include <QDialog> #include <QDialog>
#include <QMouseEvent>
namespace Ui { namespace Ui {
class CouponKeypad; class CouponKeypad;
...@@ -21,12 +22,19 @@ public slots: ...@@ -21,12 +22,19 @@ public slots:
void on_btnDelete_clicked(); void on_btnDelete_clicked();
void on_btnClear_clicked(); void on_btnClear_clicked();
void onDigitClicked(); void onDigitClicked();
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
public: public:
QString code; QString code;
private: private:
Ui::CouponKeypad *ui; Ui::CouponKeypad *ui;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // COUPONKEYPAD_H #endif // COUPONKEYPAD_H
...@@ -92,3 +92,26 @@ void ErrCodeDialog::showForMismatch(const QString &coupon, const QString &mess, ...@@ -92,3 +92,26 @@ void ErrCodeDialog::showForMismatch(const QString &coupon, const QString &mess,
v.exec(); v.exec();
} }
void ErrCodeDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void ErrCodeDialog::mouseMoveEvent(QMouseEvent *e)
{
if (mouse_pressed && (e->buttons() & Qt::LeftButton)
&& (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos()-movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void ErrCodeDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
}
\ No newline at end of file
#ifndef ERRCODEDIALOG_H #ifndef ERRCODEDIALOG_H
#define ERRCODEDIALOG_H #define ERRCODEDIALOG_H
#include <QDialog> #include <QDialog>
#include <QMouseEvent>
namespace Ui { namespace Ui {
class ErrCodeDialog; class ErrCodeDialog;
...@@ -20,8 +21,15 @@ public: ...@@ -20,8 +21,15 @@ public:
static void showForErr(const QString& coupon, const QString& mess, QWidget *parent = 0); static void showForErr(const QString& coupon, const QString& mess, QWidget *parent = 0);
static void showForMismatch(const QString& coupon, const QString& mess, QWidget *parent = 0); static void showForMismatch(const QString& coupon, const QString& mess, QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private: private:
Ui::ErrCodeDialog *ui; Ui::ErrCodeDialog *ui;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // ERRCODEDIALOG_H #endif // ERRCODEDIALOG_H
...@@ -300,7 +300,7 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json) ...@@ -300,7 +300,7 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
transactions.append(transaction); transactions.append(transaction);
_redeem_json["transactions"] = transactions; _redeem_json["transactions"] = transactions;
} }
if( couponType == 1){ //代金券 else if( couponType == 1){ //代金券
QJsonObject transaction; QJsonObject transaction;
transaction["code"] = coupon; transaction["code"] = coupon;
transaction["ebcode"] = ebcode; transaction["ebcode"] = ebcode;
...@@ -310,7 +310,7 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json) ...@@ -310,7 +310,7 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
_redeem_json["transactions"] = transactions; _redeem_json["transactions"] = transactions;
} }
if(couponType == 3){ //折扣券 else if(couponType == 3){ //折扣券
QJsonObject transaction; QJsonObject transaction;
transaction["code"] = coupon; transaction["code"] = coupon;
transaction["ebcode"] = ebcode; transaction["ebcode"] = ebcode;
...@@ -318,6 +318,9 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json) ...@@ -318,6 +318,9 @@ QJsonObject FMPRedeem::ShowForUnConsum(QJsonObject json)
transactions.append(transaction); transactions.append(transaction);
_redeem_json["transactions"] = transactions; _redeem_json["transactions"] = transactions;
} }
else{
FMP_DEBUG() << "unknown coupon type";
}
QByteArray reqData = QJsonDocument(_redeem_json).toJson(); QByteArray reqData = QJsonDocument(_redeem_json).toJson();
reqData = CheckSendArray(reqData); reqData = CheckSendArray(reqData);
......
...@@ -11,11 +11,8 @@ ScanningDialog::ScanningDialog(QWidget * parent, Qt::WindowFlags f) : ...@@ -11,11 +11,8 @@ ScanningDialog::ScanningDialog(QWidget * parent, Qt::WindowFlags f) :
ui(new Ui::ScanningDialog) ui(new Ui::ScanningDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
//setGeometry(0, 0, 350, 470);
setWindowTitle(QString::fromLocal8Bit("非码卡券")); setWindowTitle(QString::fromLocal8Bit("非码卡券"));
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
//setWindowFlags(Qt::FramelessWindowHint);
//setAutoFillBackground(false); //这个不设置的话就背景变黑
setAttribute(Qt::WA_TranslucentBackground,true); setAttribute(Qt::WA_TranslucentBackground,true);
setAttribute(Qt::WA_QuitOnClose, false); setAttribute(Qt::WA_QuitOnClose, false);
...@@ -79,7 +76,6 @@ void ScanningDialog::onClose() ...@@ -79,7 +76,6 @@ void ScanningDialog::onClose()
void ScanningDialog::timeOut() void ScanningDialog::timeOut()
{ {
qDebug() << "activateWindow";
FMP_DEBUG() << "activateWindow"; FMP_DEBUG() << "activateWindow";
HWND hForeWnd = ::GetForegroundWindow(); HWND hForeWnd = ::GetForegroundWindow();
DWORD dwForeID = ::GetWindowThreadProcessId(hForeWnd,NULL); DWORD dwForeID = ::GetWindowThreadProcessId(hForeWnd,NULL);
...@@ -101,4 +97,27 @@ void ScanningDialog::timeOut() ...@@ -101,4 +97,27 @@ void ScanningDialog::timeOut()
ScanningDialog::~ScanningDialog() ScanningDialog::~ScanningDialog()
{ {
delete ui; delete ui;
}
void ScanningDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void ScanningDialog::mouseMoveEvent(QMouseEvent *e)
{
if (mouse_pressed && (e->buttons() & Qt::LeftButton)
&& (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos()-movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void ScanningDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
} }
\ No newline at end of file
#ifndef SCANNINGDIALOG_H #ifndef SCANNINGDIALOG_H
#define SCANNINGDIALOG_H #define SCANNINGDIALOG_H
#include <QDialog> #include <QDialog>
...@@ -21,6 +21,11 @@ public: ...@@ -21,6 +21,11 @@ public:
protected: protected:
void keyPressEvent(QKeyEvent* e); void keyPressEvent(QKeyEvent* e);
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private slots: private slots:
void animationEnd(); void animationEnd();
...@@ -35,6 +40,8 @@ private: ...@@ -35,6 +40,8 @@ private:
Ui::ScanningDialog *ui; Ui::ScanningDialog *ui;
QPropertyAnimation *scanningBar; QPropertyAnimation *scanningBar;
bool animationUp; bool animationUp;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // SCANNINGDIALOG_H #endif // SCANNINGDIALOG_H
...@@ -135,3 +135,26 @@ void StoreDialog::CloseKeyBoard() ...@@ -135,3 +135,26 @@ void StoreDialog::CloseKeyBoard()
keyboard->HideKeyBoard(); keyboard->HideKeyBoard();
this->reject(); this->reject();
} }
void StoreDialog::mousePressEvent(QMouseEvent *e)
{
mouse_pressed = true;
movePosition = e->globalPos() - pos();
return QDialog::mousePressEvent(e);
}
void StoreDialog::mouseMoveEvent(QMouseEvent *e)
{
if (mouse_pressed && (e->buttons() & Qt::LeftButton)
&& (e->globalPos()-movePosition).manhattanLength() > QApplication::startDragDistance())
{
move(e->globalPos()-movePosition);
movePosition = e->globalPos() - pos();
}
return QDialog::mouseMoveEvent(e);
}
void StoreDialog::mouseReleaseEvent(QMouseEvent *e)
{
mouse_pressed = false;
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define STOREDIALOG_H #define STOREDIALOG_H
#include <QDialog> #include <QDialog>
#include <QMouseEvent>
namespace Ui { namespace Ui {
class StoreDialog; class StoreDialog;
...@@ -17,6 +18,10 @@ public: ...@@ -17,6 +18,10 @@ public:
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private slots: private slots:
void ShowKeyBoard(); void ShowKeyBoard();
...@@ -33,6 +38,8 @@ public: ...@@ -33,6 +38,8 @@ public:
private: private:
Ui::StoreDialog *ui; Ui::StoreDialog *ui;
bool _is_show; bool _is_show;
bool mouse_pressed;
QPoint movePosition;
}; };
#endif // STOREDIALOG_H #endif // STOREDIALOG_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment