Skip to content

Commit

Permalink
增加触摸滑动支持
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingBlazer committed May 10, 2014
1 parent 3e58bd9 commit e18ffdf
Show file tree
Hide file tree
Showing 22 changed files with 786 additions and 145 deletions.
18 changes: 13 additions & 5 deletions buaayz-WAC.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += core gui network androidextras
QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Expand All @@ -20,7 +20,10 @@ SOURCES += main.cpp\
login.cpp \
clientinfo.cpp \
utils.cpp \
clientinfocollector.cpp
clientinfocollector.cpp \
selectcar.cpp \
showclientinfo.cpp \
touchablescrollarea.cpp

HEADERS += mainwindow.h \
sampledialog.h \
Expand All @@ -29,15 +32,20 @@ HEADERS += mainwindow.h \
settings.h \
clientinfo.h \
utils.h \
clientinfocollector.h
clientinfocollector.h \
selectcar.h \
showclientinfo.h \
touchablescrollarea.h

FORMS += mainwindow.ui \
sampledialog.ui \
sign.ui \
login.ui \
clientinfocollector.ui
clientinfocollector.ui \
selectcar.ui \
showclientinfo.ui

CONFIG += mobility
CONFIG += mobility c++11
MOBILITY =

OTHER_FILES += \
Expand Down
118 changes: 76 additions & 42 deletions clientinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,74 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkRequest>
#include <QMessageBox>
#include <QDir>

ClientInfo ClientInfo::Instance;
ClientInfo *ClientInfo::Instance=0;

ClientInfo &ClientInfo::getInstance()
ClientInfo *ClientInfo::getInstance(QObject *parent)
{
return Instance;
if(Instance!=0)
return Instance;
else
return (Instance=new ClientInfo(parent));
}

ClientInfo &ClientInfo::newClient(QString username, QString email, QString token)
ClientInfo *ClientInfo::newClient(QString username, QString email, QString token, QObject *parent)
{
Instance.Name=username;
Instance.Email=email;
Instance.Token=token;
Instance.inputClientInfo();
Instance.saveToFile();
if(Instance!=0)
delete Instance;
Instance=new ClientInfo(parent);
Instance->Name=username;
Instance->Email=email;
Instance->Token=token;
Instance->inputClientInfo();
Instance->save();
return Instance;
}

ClientInfo::ClientInfo(QObject *parent) :
QObject(parent)
QObject(parent),setting("buaa.GBK","WAC")
{
if(!QFile::exists(getExternalStorageDirectory()+"/WAC/user.dat"))
{
Data.setFileName(getExternalStorageDirectory()+"/WAC/user.dat");
Data.open(QIODevice::ReadWrite);
State=NotLogin;
return;
}
Data.setFileName(getExternalStorageDirectory()+"/WAC/user.dat");
Data.open(QIODevice::ReadWrite);
readFromFile();
State=NotLogin;
read();
}

ClientInfo::ClientInfo(ClientInfo &c) :
QObject(c.parent()),setting("buaa.GBK","WAC")
{

}

QString ClientInfo::getSex() const
{
return Sex;
}

void ClientInfo::setSex(const QString &value)
{
Sex = value;
}

QByteArray ClientInfo::getAvatarBase64() const
QString ClientInfo::getIncome() const
{
return AvatarBase64;
return Income;
}

void ClientInfo::setAvatarBase64(const QByteArray &value)
void ClientInfo::setIncome(const QString &value)
{
AvatarBase64 = value;
Income = value;
}

QString ClientInfo::getEducation() const
{
return Education;
}

void ClientInfo::setEducation(const QString &value)
{
Education = value;
}

QString ClientInfo::getEmail() const
{
Expand All @@ -66,7 +91,7 @@ void ClientInfo::setUid(long id)
{
uid=id;
refresh();
saveToFile();
save();
}

QString ClientInfo::getToken() const
Expand Down Expand Up @@ -123,36 +148,45 @@ void ClientInfo::setClientInfo(QNetworkReply *reply)
QJsonObject JObj=QJsonDocument::fromJson(raw).object();
Name=JObj["Name"].toString();
Nickname=JObj["Nickname"].toString();
AvatarBase64=JObj["Avatar"].toString().toLocal8Bit();
emit finished();
}

void ClientInfo::readFromFile()
void ClientInfo::read()
{
QByteArray data=QByteArray::fromBase64(Data.readAll());
QJsonObject JObj=QJsonDocument::fromJson(data).object();
Name=JObj["Name"].toString();
Nickname=JObj["Nickname"].toString();
AvatarBase64=JObj["Avatar"].toString().toLocal8Bit();
State=HasLogin;
setting.beginGroup("ClientInfo");
if(setting.contains("Token"))
{
Name=setting.value("Name").toString();
Nickname=setting.value("Nickname").toString();
Token=setting.value("Token").toString();
Sex=setting.value("Sex").toString();
Income=setting.value("Income").toString();
Education=setting.value("Education").toString();
State=HasLogin;
}
setting.endGroup();
}

void ClientInfo::saveToFile()
void ClientInfo::save()
{
QJsonObject JObj;
JObj.insert("Name",QJsonValue(Name));
JObj.insert("NickName",QJsonValue(Nickname));
JObj.insert("Avatar",QJsonValue(QString(AvatarBase64.toBase64())));
QByteArray d=QJsonDocument(JObj).toJson();
Data.write(d);
setting.beginGroup("ClientInfo");
setting.setValue("Name",Name);
setting.setValue("Nickname",Nickname);
setting.setValue("Token",Token);
setting.setValue("Sex",Sex);
setting.setValue("Income",Income);
setting.setValue("Education",Education);
setting.endGroup();
}

void ClientInfo::inputClientInfo()
{
ClientInfoCollector cic;
connect(&cic,&ClientInfoCollector::data,[this](QString nickname,QByteArray picdata){
connect(&cic,&ClientInfoCollector::data,[this](QString nickname,QString sex,QString income,QString education){
Nickname=nickname;
AvatarBase64=picdata;
Sex=sex;
Income=income;
Education=education;
});
cic.exec();
}
28 changes: 20 additions & 8 deletions clientinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QFile>
#include <QSettings>

class ClientInfo : public QObject
{
Q_OBJECT
public:
static ClientInfo &getInstance();
static ClientInfo &newClient(QString username,QString email,QString token);
static ClientInfo *getInstance(QObject *parent=0);
static ClientInfo *newClient(QString username, QString email, QString token, QObject *parent=0);

ClientInfo(ClientInfo&);

enum LoginState
{
Expand All @@ -36,8 +39,14 @@ class ClientInfo : public QObject
QString getEmail() const;
void setEmail(const QString &value);

QByteArray getAvatarBase64() const;
void setAvatarBase64(const QByteArray &value);
QString getEducation() const;
void setEducation(const QString &value);

QString getIncome() const;
void setIncome(const QString &value);

QString getSex() const;
void setSex(const QString &value);

public slots:
void refresh();
Expand All @@ -47,23 +56,26 @@ public slots:
void finished();

private:
static ClientInfo Instance;
static ClientInfo *Instance;

ClientInfo(QObject *parent = 0);

LoginState State;
QSettings setting;

long uid;
QString Name;
QString Nickname;
QString Email;
QString Token;
QByteArray AvatarBase64;
QString Sex;
QString Income;
QString Education;

QFile Data;

void saveToFile();
void readFromFile();
void save();
void read();
void inputClientInfo();

private slots:
Expand Down
28 changes: 16 additions & 12 deletions clientinfocollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,44 @@
#include "ui_clientinfocollector.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QProcessEnvironment>
#include <QDesktopWidget>

ClientInfoCollector::ClientInfoCollector(QWidget *parent) :
QDialog(parent),
ui(new Ui::ClientInfoCollector)
{
ui->setupUi(this);
if(QProcessEnvironment::systemEnvironment().value("OS")!=QString("Windows_NT"))
{
QRect applicationGeometry=QApplication::desktop()->availableGeometry();
this->setFixedSize(applicationGeometry.size());
}
}

ClientInfoCollector::~ClientInfoCollector()
{
delete ui;
}

void ClientInfoCollector::on_selectButton_clicked()
{
QString path=QFileDialog::getOpenFileName(this,tr("选择头像"),"/",tr("图片文件 (*.png *.xpm *.jpg)"));
QFile pic(path);
pic.open(QIODevice::ReadOnly);
PicData=pic.readAll().toBase64();
pic.close();
}

void ClientInfoCollector::on_okButton_clicked()
{
if(ui->nicknameInput->text().length()==0)
{
QMessageBox::warning(this,tr("错误"),tr("请填写昵称"));
return;
}
if(PicData.isEmpty())
if(ui->incomeInput->text().length()==0)
{
QMessageBox::warning(this,tr("错误"),tr("请填写月收入"));
return;
}
if(ui->educationInput->text().length()==0)
{
QMessageBox::warning(this,tr("错误"),tr("请选择头像"));
QMessageBox::warning(this,tr("错误"),tr("请填写学历"));
return;
}
emit data(ui->nicknameInput->text(),PicData);
emit data(ui->nicknameInput->text(),ui->sexInput->currentText(),
ui->incomeInput->text(),ui->educationInput->text());
accept();
}
4 changes: 1 addition & 3 deletions clientinfocollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ class ClientInfoCollector : public QDialog
~ClientInfoCollector();

signals:
void data(QString nickname,QByteArray avatar);
void data(QString, QString, QString, QString);

private slots:
void on_selectButton_clicked();

void on_okButton_clicked();

private:
Expand Down
Loading

0 comments on commit e18ffdf

Please sign in to comment.