Commit 4e8b65c5 by gujin.wang

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

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