物流定位系统项目qt代码

头文件
#ifndef USER_INTERFACE_H
#define USER_INTERFACE_H

#include <QWidget>
#include <QLabel>
#include <QMouseEvent>
#include <qpropertyanimation.h>
#include <QProcess>
#include <QTimer>
#include <QString>
#include <QDebug>
#include <QTime>
#include <QUdpSocket>
#include <QtSql>
#include <stdio.h>//标准io定义
#include <fcntl.h>//文件控制定义
#include <unistd.h>//unix标准函数定义
#include <stdlib.h>//标准函数库定义
#include <termios.h>//PPSIX终端控制定义
#include <sys/types.h>
#include <sys/time.h>//kill函数需要用到的头文件
#include <signal.h>//kill函数需要用到的头文件
#include <errno.h>//错误号定义
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <QThread>
#include <QMessageBox>
#include <QtNetwork/QUdpSocket>
#include <malloc.h>

void gps_open(void);//打开gps模块
void gps_set_serial(int fd, int speed, int bits, char event, int stop);//gps模块串口参数设置
void gps_close(void);//关闭gps模块
void gsm_open(void);//打开gsm模块设备节点
void gsm_close(void);//关闭gsm模块设备节点
void gsm_set_serial(int fd, int speed, int bit, char event, int stop);//设置串口参数
void gsm_read(void);//读取gsm模块信息
void gsm_calling(void);//打电话
void gsm_cut(void);//挂断电话
void gsm_apn_set(void);//设置APN无线接入点
void gsm_ppp_dialing(void);//进行ppp拨号,实现PDP激活和TCPIP的初始化
void gsm_ip_open(void);//打开一条TCP或UDP连接
void gsm_data_send(char *p);//发送数据
void gsm_ip_close(void);//关闭连接
void gsm_iomode(void);//设置数据模式
char *gsm_data_transfer(char *data);//转换发送数据为数据ascii码对应的十六进制数
void socket_send(char *time,char *latitude,char *N_S ,char *longitude,char *E_W,char *satellite);//发送经纬度
void socket_close(void);//关闭socket
void socket_open(void);//创建socket

namespace Ui {
class user_interface;
class MyThread;
}

class MyThread : public QThread
{
    Q_OBJECT
public:
    int flag_thread;//线程标志位

protected:

private:
    void run();//线程函数
    QUdpSocket *udpsocket_sender;//发送卫星号信息
    QUdpSocket *udpsocket_sender_traffic;//发送预警信息
};

class user_interface : public QWidget
{
    Q_OBJECT
    
public:
    explicit user_interface(QWidget *parent = 0);
    ~user_interface();

private slots:
    /******************************home界面槽函数******************************/
    void on_button_home_clicked();//home按钮槽函数
    void on_button_music_clicked();//music按钮槽函数
    void on_button_gps_clicked();//gps按钮槽函数

    /******************************gps界面槽函数******************************/
    void read_pending_datagrams_1();//获取经纬度槽函数
    void read_pending_datagrams_2();//获取卫星号槽函数
    void on_button_run_clicked();//run按钮槽函数

    /******************************music界面槽函数******************************/
    void timer_traffic_slot();//预警计时器槽函数
    void timer_music_slot();//从预警播放跳回音乐播放计时器槽函数
    void catch_output();//进度条滚动槽函数
    void get_current_time();//获取当前播放时间槽函数
    void read_pending_datagrams();//获取预警信号槽函数
    void on_button_play_clicked();//play按钮槽函数
    void on_button_last_clicked();//last按钮槽函数
    void on_button_next_clicked();//next按钮槽函数
    void on_button_down_clicked();//down按钮槽函数
    void on_button_up_clicked();//up按钮槽函数
    void on_timeline_sliderMoved(int position);//歌曲进度条槽函数

private:
    /******************************home界面******************************/
    Ui::user_interface *ui;//ui界面指针
    QPropertyAnimation *propertyanimation_home;//home按钮动画指针
    QPropertyAnimation *propertyanimation_music;//music按钮动画指针
    QPropertyAnimation *propertyanimation_gps;//gps按钮动画指针
    void mousePressEvent(QMouseEvent *);//鼠标点击时间函数
    void time_show();//显示系统时间函数
    void home_show();//显示home界面函数
    void home_hide();//隐藏home界面函数
    int flag_event;

    /******************************gps界面******************************/
    MyThread *thread;  //创建一个线程,用于执行有关采集gps的信息函数,若直接使用会导致界面卡死
    QUdpSocket *udpsocket_receiver1;//创建一个receiver用于接收自己发出去的经纬度信息
    QUdpSocket *udpsocket_receiver2;//创建一个receiver用于接受自己发出去的卫星号和卫星强度信息
    void gps_show();//显示gps界面函数
    void gps_hide();//隐藏gps界面函数
    int flag_run;//run按钮标志位
    int flag_strength;//卫星强度标志位

    /******************************music界面******************************/
    QProcess *process_music;//音乐进程
    QProcess *process_record;//录音进程,即预警信息
    QTimer *timer_timeline;//音乐时间滑动条计时器
    QTimer *timer_traffic;//预警计时器
    QTimer *timer_music;//音乐计时器
    QString string_player;//
    QString string_name;
    QString time_transfer(int string_time);
    QUdpSocket *udpsocket_receiver;
    QStringList stringlist_song;
    QStringList stringlist_event;
    QStringList stringlist_record;
    QSqlDatabase db;
    QSqlQuery *query;
    QFileInfoList fileinfolist;
    int flag_play;
    int flag_loop;
    int flag_name;
    int time;
    int int_current_time;
    char back_name[20];
    char back_time[10];
    void music_show();//显示music界面函数
    void music_hide();//隐藏music界面函数
    void traffic_warning();//预警播放初始化函数
};

#endif // USER_INTERFACE_H


函数实现

#include "user_interface.h"
#include "ui_user_interface.h"
#define SIZE 1024
#define IP "127.0.0.1"
#define PORT1 10000
#define PORT2 20000
#define PORT3 30000
#define GPS "/dev/ttyUSB0"
#define GSM "/dev/ttyUSB1"

int gps_fd;//gps设备文件描述符
int gsm_fd;//gsm模块句柄
char a[100];//用于保存转码后的gps数据
int socket_fd;

user_interface::user_interface(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::user_interface)
{
    /******************************home界面******************************/
    ui->setupUi(this);
    home_show();//显示出home界面
    time_show();//显示实时时间
    flag_event = 0;//鼠标事件标志位

    propertyanimation_home = new QPropertyAnimation(ui->button_home, "geometry");
    propertyanimation_music = new QPropertyAnimation(ui->button_music, "geometry");
    propertyanimation_gps = new QPropertyAnimation(ui->button_gps, "geometry");

    /******************************gps界面******************************/
    thread = new MyThread();//为线程开辟空间并且初始化

    udpsocket_receiver1 = new QUdpSocket(this);//为udpsocket开辟空间并且初始化
    udpsocket_receiver1->bind(PORT1, QUdpSocket::ShareAddress);//绑定端口
    connect(udpsocket_receiver1, SIGNAL(readyRead()),this, SLOT(read_pending_datagrams_1()));

    udpsocket_receiver2 = new QUdpSocket(this);//为udpsocket开辟空间并且初始化
    udpsocket_receiver2->bind(PORT2, QUdpSocket::ShareAddress);//绑定端口
    connect(udpsocket_receiver2, SIGNAL(readyRead()),this, SLOT(read_pending_datagrams_2()));

    ui->strength1->setValue(0);
    ui->strength1->setRange(0, 99);
    ui->strength2->setValue(0);
    ui->strength2->setRange(0, 99);
    ui->strength3->setValue(0);
    ui->strength3->setRange(0, 99);
    ui->strength4->setValue(0);
    ui->strength4->setRange(0, 99);
    ui->strength5->setValue(0);
    ui->strength5->setRange(0, 99);
    ui->strength6->setValue(0);
    ui->strength6->setRange(0, 99);

    flag_run = 0;
    flag_strength = 0;

    gps_open();//打开gps模块设备节点
    gsm_open();//打开gsm模块设备节点
    socket_open();
    gps_set_serial(gps_fd, 4800, 8, 'N', 1);//设置gps串口参数
    gsm_set_serial(gsm_fd, 9600, 8, 'N', 1);//设置gsm串口参数
    thread->flag_thread = 1;
    thread->start();

    /******************************music界面******************************/
    udpsocket_receiver = new QUdpSocket(this);
    udpsocket_receiver->bind(PORT3, QUdpSocket::ShareAddress);
    connect(udpsocket_receiver, SIGNAL(readyRead()),this, SLOT(read_pending_datagrams()));

    process_music = new QProcess(this);
    connect(process_music, SIGNAL(readyReadStandardOutput()), this, SLOT(catch_output()));

    timer_timeline = new QTimer(this);
    connect(timer_timeline, SIGNAL(timeout()), this, SLOT(get_current_time()));

    process_record = new QProcess(this);

    timer_traffic = new QTimer(this);
    connect(timer_traffic, SIGNAL(timeout()), this, SLOT(timer_traffic_slot()));

    timer_music = new QTimer(this);
    connect(timer_music, SIGNAL(timeout()), this, SLOT(timer_music_slot()));

    flag_play = 0;
    flag_loop = 1;
    time = 0;

    traffic_warning();
}

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

void user_interface::on_button_home_clicked()
{
    music_hide();
    gps_hide();
    home_show();

    flag_event = 0;
}

void user_interface::on_button_music_clicked()
{
    home_hide();
    gps_hide();
    music_show();

    flag_event = 0;
}

void user_interface::on_button_gps_clicked()
{
    home_hide();
    music_hide();
    gps_show();

    flag_event = 0;
}

void user_interface::time_show()
{
    QTime time_current = QTime::currentTime();
    QString string_time = time_current.toString("hh:mm ");
    QPalette palette_time;
    palette_time.setColor(QPalette::WindowText,Qt::black);//配置颜色
    ui->time->setPalette(palette_time);//设置颜色
    ui->time->setFont(QFont( "Timers" , 30 ,  QFont::Bold) );//设置字体
    ui->time->setText (string_time);

    QDate date_date = QDate::currentDate();
    QString string_date = date_date.toString("dddd");
    palette_time.setColor(QPalette::WindowText,Qt::black);//配置颜色
    ui->day->setPalette(palette_time);//设置颜色
    QFont font_date("Timers" , 15 ,  QFont::Light);//配置字体
    ui->day->setFont(font_date);//设置字体
    ui->day->setText(string_date);
    ui->date->setPalette(palette_time);
    ui->date->setFont(QFont( "Timers" , 15 ,  QFont::Light));//设置字体
    string_date = date_date.toString("MM/dd");
    ui->date->setText(string_date);
}

void user_interface::home_show()
{
    ui->time->show();//显示时间
    ui->time->setGeometry(QRect(30, 30, 121, 35));

    ui->date->show();//显示日期
    ui->date->setGeometry(QRect(30, 60, 61, 31));

    ui->day->show();//显示星期几
    ui->day->setGeometry(QRect(85, 60, 100, 31));

    ui->background->show();//显示背景
    ui->background->setStyleSheet("border-image: url(./image/home_background.png);");
    ui->background->setGeometry(QRect(0, 0, 480, 272));

    ui->sun->show();//显示太阳
    ui->sun->setStyleSheet("border-image: url(./image/sun.png);");
    ui->sun->setGeometry(QRect(340, 5, 128, 128));

    ui->temperature->show();//显示温度
    ui->temperature->setGeometry(QRect(385, 45, 50, 50));
    ui->temperature->setText("18");
    ui->temperature->setStyleSheet("color:white");
    QFont font_temperature;
    font_temperature.setPointSize(30);
    ui->temperature->setFont(font_temperature);
}

void user_interface::home_hide()//隐藏home界面
{
    ui->time->hide();
    ui->date->hide();
    ui->day->hide();
    ui->sun->hide();
    ui->temperature->hide();
    ui->button_gps->hide();
    ui->button_home->hide();
    ui->button_music->hide();
    ui->background_mh->hide();
}

void user_interface::mousePressEvent(QMouseEvent *)//鼠标点击事件槽函数
{
    if( flag_event==0 ){
        ui->button_home->show();
        ui->button_home->setStyleSheet("QPushButton{border-image: url(./image/home.png);}"
                                       "QPushButton:hover{border-image: url(./image/home.png);}"
                                       "QPushButton:pressed{border-image: url(./image/home1.png);}");
        ui->button_home->setFocusPolicy(Qt::NoFocus);
        propertyanimation_home->setDuration(100);
        propertyanimation_home->setStartValue(QRect(176, -128, 128, 128));
        propertyanimation_home->setEndValue(QRect(176, 72, 128, 128));
        propertyanimation_home->start();

        ui->button_music->show();
        ui->button_music->setStyleSheet("QPushButton{border-image: url(./image/music.png);}"
                                        "QPushButton:hover{border-image: url(./image/music.png);}"
                                        "QPushButton:pressed{border-image: url(./image/music1.png);}");
        ui->button_music->setFocusPolicy(Qt::NoFocus);
        propertyanimation_music->setDuration(100);
        propertyanimation_music->setStartValue(QRect(-128, 72, 128, 128));
        propertyanimation_music->setEndValue(QRect(18, 72, 128, 128));
        propertyanimation_music->start();

        ui->button_gps->show();
        ui->button_gps->setStyleSheet("QPushButton{border-image: url(./image/gps.png);}"
                                      "QPushButton:hover{border-image: url(./image/gps.png);}"
                                      "QPushButton:pressed{border-image: url(./image/gps1.png);}");
        ui->button_gps->setFocusPolicy(Qt::NoFocus);
        propertyanimation_gps->setDuration(100);
        propertyanimation_gps->setStartValue(QRect(608, 72, 128, 128));
        propertyanimation_gps->setEndValue(QRect(334, 72, 128, 128));
        propertyanimation_gps->start();

        ui->background_mh->show();
        ui->background_mh->setStyleSheet("border-image: url(./image/home_background_mh.png);");
        ui->background_mh->setGeometry(QRect(0, 0, 480, 272));

        flag_event = 1;
    }else{
        ui->button_gps->hide();
        ui->button_home->hide();
        ui->button_music->hide();
        ui->background_mh->hide();

        flag_event = 0;
    }
}


void user_interface::on_button_play_clicked()
{
    int i = 0;
    QDir dir("music");
    QFileInfo fileinfo;
    QString string_song;

    if( flag_play==0 )
    {
        string_player = "mplayer";

        stringlist_song &
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值