Commit 10ba8584 by NitefullWind

1. 加入访问网络类。 2. 修改了几张按钮图片。

parent fd808f65
#include "fmnetwork.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QEventLoop>
#include <QTimer>
#include <QDebug>
FMNetwork::FMNetwork(QObject *parent) :
QObject(parent),
_nam(new QNetworkAccessManager),
_req(new QNetworkRequest)
{
}
FMNetwork::~FMNetwork()
{
delete _nam;
delete _req;
}
bool FMNetwork::post(const QString *url, const QByteArray *reqData, QByteArray *rspData)
{
qDebug() << "Post Url: " << *url;
qDebug() << "Post Data: " << *reqData;
_req->setUrl(*url);
// 设置请求头
_req->setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
_req->setHeader(QNetworkRequest::ContentLengthHeader, reqData->length());
auto reply = _nam->post(*_req, *reqData);
// 使用定时器处理超时
QEventLoop loop;
connect(_nam, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
QTimer timer;
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()),&loop,SLOT(quit()));
timer.start(1000 * 30);
loop.exec();
if(timer.isActive())
{
timer.stop();
if (reply->error() == QNetworkReply::NoError) {
*rspData = reply->readAll();
qDebug() << tr("Recv data: %1") << *rspData;
} else {
_errorString = reply->errorString();
qDebug() << tr("Network error: %1").arg(_errorString);
return false;
}
}else{
_errorString = "Time out";
qDebug() << tr("Network error: %1").arg(_errorString);
return false;
}
return true;
}
#ifndef FMNETWORK_H
#define FMNETWORK_H
#include <QObject>
class QNetworkAccessManager;
class QNetworkRequest;
class FMNetwork : public QObject
{
Q_OBJECT
public:
explicit FMNetwork(QObject *parent = 0);
~FMNetwork();
/**
* @brief post
* @param url 请求地址
* @param reqData 请求数据
* @param rspData 返回数据
* @return 是否有错误
*/
bool post(const QString *url, const QByteArray *reqData, QByteArray *rspData);
QString errorString() const { return _errorString;}
private:
QNetworkAccessManager *_nam;
QNetworkRequest *_req;
QString _errorString;
};
#endif // FMNETWORK_H
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
TEMPLATE = lib TEMPLATE = lib
QT += core gui QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11 CONFIG += c++11
...@@ -19,7 +19,8 @@ SOURCES +=\ ...@@ -19,7 +19,8 @@ SOURCES +=\
menubutton.cpp \ menubutton.cpp \
fmp_wnd.cpp \ fmp_wnd.cpp \
fmp_login.cpp \ fmp_login.cpp \
fmp_num_pad.cpp fmp_num_pad.cpp \
fmnetwork.cpp
HEADERS += fmp_home.h \ HEADERS += fmp_home.h \
fmp_home_plugin_p.h \ fmp_home_plugin_p.h \
...@@ -29,7 +30,8 @@ HEADERS += fmp_home.h \ ...@@ -29,7 +30,8 @@ HEADERS += fmp_home.h \
fmp_wnd.h \ fmp_wnd.h \
fmp_login.h \ fmp_login.h \
menubutton.h \ menubutton.h \
fmp_num_pad.h fmp_num_pad.h \
fmnetwork.h
FORMS += \ FORMS += \
fmp_home_navwindow.ui \ fmp_home_navwindow.ui \
......
...@@ -18,7 +18,7 @@ NavWindow::NavWindow(QWidget *parent) : ...@@ -18,7 +18,7 @@ NavWindow::NavWindow(QWidget *parent) :
btns.push_back("payment"); btns.push_back("payment");
btns.push_back("tool"); btns.push_back("tool");
MenuUiProp.distance = 80; MenuUiProp.distance = 100;
MenuUiProp.beginAngle = -(PI*0.45); MenuUiProp.beginAngle = -(PI*0.45);
MenuUiProp.endAngle = (PI*0.45); MenuUiProp.endAngle = (PI*0.45);
...@@ -48,7 +48,7 @@ void NavWindow::setNavStatus(const NavStatus status) ...@@ -48,7 +48,7 @@ void NavWindow::setNavStatus(const NavStatus status)
break; break;
case Spread: case Spread:
spreadMenus(true); spreadMenus(true);
ui->navMainBtn->setStyleSheet("#navMainBtn{ border-image: url(:fm-icon_01)}"); ui->navMainBtn->setStyleSheet("#navMainBtn{ border-image: url(:fm-icon_02)}");
break; break;
case Message: case Message:
ui->navMainBtn->setStyleSheet("#navMainBtn{ border-image: url(:xiaoxi)}"); ui->navMainBtn->setStyleSheet("#navMainBtn{ border-image: url(:xiaoxi)}");
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">#navMainBtn { <string notr="true">#navMainBtn {
min-width: 185px; min-height:185px;
max-width: 185px; max-height:185px;
border-image: url(:fm-icon_01) border-image: url(:fm-icon_01)
} }
...@@ -32,6 +34,9 @@ QPushButton:hover { ...@@ -32,6 +34,9 @@ QPushButton:hover {
#tool:pressed { #tool:pressed {
border-image: url(:tool); border-image: url(:tool);
} }
#tool:pressed {
border-image: url(:tool_onclick);
}
#payment { #payment {
border-image: url(:payment); border-image: url(:payment);
} }
...@@ -42,10 +47,10 @@ QPushButton:hover { ...@@ -42,10 +47,10 @@ QPushButton:hover {
<widget class="MenuButton" name="navMainBtn" native="true"> <widget class="MenuButton" name="navMainBtn" native="true">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>140</x> <x>110</x>
<y>90</y> <y>60</y>
<width>111</width> <width>185</width>
<height>111</height> <height>185</height>
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDesktopWidget> #include <QDesktopWidget>
#include "fmp_num_pad.h" #include "fmp_num_pad.h"
#include "fmnetwork.h"
#include <QDebug> #include <QDebug>
FMPLogin::FMPLogin(QDialog *parent) : FMPLogin::FMPLogin(QDialog *parent) :
...@@ -27,7 +28,15 @@ FMPLogin::~FMPLogin() ...@@ -27,7 +28,15 @@ FMPLogin::~FMPLogin()
void FMPLogin::on_login_btn_clicked() void FMPLogin::on_login_btn_clicked()
{ {
_numPad->close(); _numPad->close();
QMessageBox::information(this, "", tr("Login"), QMessageBox::Ok); QString url = "http://115.159.142.32:30001/api/user/login";
QByteArray reqData = "{\"StoreId\": \"123\",\"PartnerId\": \"123\",\"UserId\": \"123\",\"Pwd\": \"123\",\"ClassNo\": \"123\",\"DeviceId\": \"\"}";
QByteArray rspData;
FMNetwork net;
if(net.post(&url, &reqData, &rspData)) {
QMessageBox::information(this, "Login", QString(rspData));
} else {
QMessageBox::critical(this, "Login", net.errorString());
}
this->close(); this->close();
} }
......
...@@ -8,5 +8,7 @@ ...@@ -8,5 +8,7 @@
<file alias="payment_onclick">img/fm-icon_payment_onclick.png</file> <file alias="payment_onclick">img/fm-icon_payment_onclick.png</file>
<file alias="tool">img/fm-icon_tool.png</file> <file alias="tool">img/fm-icon_tool.png</file>
<file>img/btn_alert_close.png</file> <file>img/btn_alert_close.png</file>
<file alias="fm-icon_02">img/fm-icon_02.png</file>
<file alias="tool_onclick">img/fm-icon_tool_onclick.png</file>
</qresource> </qresource>
</RCC> </RCC>
fmp_home/res/img/fm-icon_01.png

10.3 KB | W: | H:

fmp_home/res/img/fm-icon_01.png

10.7 KB | W: | H:

fmp_home/res/img/fm-icon_01.png
fmp_home/res/img/fm-icon_01.png
fmp_home/res/img/fm-icon_01.png
fmp_home/res/img/fm-icon_01.png
  • 2-up
  • Swipe
  • Onion skin
fmp_home/res/img/fm-icon_tool.png

5.64 KB | W: | H:

fmp_home/res/img/fm-icon_tool.png

5.41 KB | W: | H:

fmp_home/res/img/fm-icon_tool.png
fmp_home/res/img/fm-icon_tool.png
fmp_home/res/img/fm-icon_tool.png
fmp_home/res/img/fm-icon_tool.png
  • 2-up
  • Swipe
  • Onion skin
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