├── GAS.pro ├── api ├── api.cpp ├── api.h ├── api.pri ├── app.cpp ├── app.h ├── appinit.cpp ├── appinit.h ├── applive.cpp ├── applive.h ├── applog.cpp ├── applog.h ├── checktaskthread.cpp ├── checktaskthread.h ├── dbapi.cpp ├── dbapi.h ├── dbhelper.cpp ├── dbhelper.h ├── ds7400_com.cpp ├── ds7400_com.h ├── excelapi.cpp ├── excelapi.h ├── gsmapi.cpp ├── gsmapi.h ├── hostapi.cpp ├── hostapi.h ├── iconhelper.cpp ├── iconhelper.h ├── loadthread.cpp ├── loadthread.h ├── myhelper.h ├── ntpapi.cpp ├── ntpapi.h ├── pdfapi.cpp ├── pdfapi.h ├── printapi.cpp ├── printapi.h ├── screenapi.cpp ├── screenapi.h ├── sendemailthread.cpp ├── sendemailthread.h ├── sendmsgthread.cpp ├── sendmsgthread.h ├── showcpumemory.cpp ├── showcpumemory.h ├── showdatetime.cpp ├── showdatetime.h ├── showdevicesize.cpp ├── showdevicesize.h ├── vista128_com.cpp └── vista128_com.h ├── frmabout.cpp ├── frmabout.h ├── frmabout.ui ├── frmalarm.cpp ├── frmalarm.h ├── frmalarm.ui ├── frmconfig.cpp ├── frmconfig.h ├── frmconfig.ui ├── frmdefencelot.cpp ├── frmdefencelot.h ├── frmdefencelot.ui ├── frmgateway.cpp ├── frmgateway.h ├── frmgateway.ui ├── frmmain.cpp ├── frmmain.h ├── frmmain.ui ├── frmselect.cpp ├── frmselect.h ├── frmselect.ui ├── frmvisitor.cpp ├── frmvisitor.h ├── frmvisitor.ui ├── inputnew ├── frminputnew.cpp ├── frminputnew.h ├── frminputnew.ui ├── image │ ├── close_black.png │ ├── close_white.png │ ├── delete_black.png │ ├── delete_white.png │ ├── enter_black.png │ ├── enter_white.png │ ├── handwriting_black.png │ ├── handwriting_white.png │ ├── mini_black.png │ ├── mini_white.png │ ├── space_black.png │ ├── space_white.png │ ├── upper_black.png │ └── upper_white.png ├── inputnew.pri └── inputnew.qrc ├── main.cpp ├── other ├── banner │ ├── about.png │ ├── main_about.png │ ├── main_company.png │ ├── main_config.png │ ├── main_data.png │ ├── main_exit.png │ ├── main_help.png │ ├── main_person.png │ ├── tree_child.png │ └── tree_parent.png ├── help.txt ├── image │ ├── add_bottom.png │ ├── add_bottom_blue.png │ ├── add_bottom_dev.png │ ├── add_left.png │ ├── add_left_blue.png │ ├── add_left_dev.png │ ├── add_right.png │ ├── add_right_blue.png │ ├── add_right_dev.png │ ├── add_top.png │ ├── add_top_blue.png │ ├── add_top_dev.png │ ├── btn_add.png │ ├── btn_check_off.png │ ├── btn_check_on.png │ ├── btn_close.png │ ├── btn_delete.png │ ├── btn_email.png │ ├── btn_excel.png │ ├── btn_input.png │ ├── btn_move.png │ ├── btn_ok.png │ ├── btn_open.png │ ├── btn_out.png │ ├── btn_pause_normal.png │ ├── btn_pause_press.png │ ├── btn_pdf.png │ ├── btn_play_normal.png │ ├── btn_play_press.png │ ├── btn_print.png │ ├── btn_pwd.png │ ├── btn_save.png │ ├── checkbox_checked.png │ ├── checkbox_unchecked.png │ ├── fontawesome-webfont.ttf │ ├── image_next.png │ ├── image_prev.png │ ├── msg_error.png │ ├── msg_info.png │ ├── msg_question.png │ ├── qt_zh_CN.qm │ ├── radio_normal.png │ └── radio_selected.png ├── main.ico ├── qss │ ├── black.css │ ├── blue.css │ ├── brown.css │ ├── darkgray.css │ ├── dev.css │ ├── gray.css │ ├── lightgray.css │ └── silvery.css └── rc.qrc ├── qemail ├── emailaddress.cpp ├── emailaddress.h ├── mimeattachment.cpp ├── mimeattachment.h ├── mimecontentformatter.cpp ├── mimecontentformatter.h ├── mimefile.cpp ├── mimefile.h ├── mimehtml.cpp ├── mimehtml.h ├── mimeinlinefile.cpp ├── mimeinlinefile.h ├── mimemessage.cpp ├── mimemessage.h ├── mimemultipart.cpp ├── mimemultipart.h ├── mimepart.cpp ├── mimepart.h ├── mimetext.cpp ├── mimetext.h ├── qemail.pri ├── quotedprintable.cpp ├── quotedprintable.h ├── smtpclient.cpp ├── smtpclient.h └── smtpmime.h ├── qextserialport ├── qextserialport.cpp ├── qextserialport.h ├── qextserialport.pri ├── qextserialport_global.h ├── qextserialport_p.h ├── qextserialport_unix.cpp └── qextserialport_win.cpp └── usercontrol ├── combobox.cpp ├── combobox.h ├── defencebutton.cpp ├── defencebutton.h ├── frminputbox.cpp ├── frminputbox.h ├── frminputbox.ui ├── frmmessagebox.cpp ├── frmmessagebox.h ├── frmmessagebox.ui ├── imageview.cpp ├── imageview.h ├── qdelegate.cpp ├── qdelegate.h ├── switchbutton.cpp ├── switchbutton.h └── usercontrol.pri /GAS.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-08-15T14:34:50 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network sql xml 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport multimedia 10 | 11 | TARGET = GAS 12 | TEMPLATE = app 13 | 14 | include($$PWD/api/api.pri) 15 | include($$PWD/qemail/qemail.pri) 16 | include($$PWD/inputnew/inputnew.pri) 17 | include($$PWD/usercontrol/usercontrol.pri) 18 | include($$PWD/qextserialport/qextserialport.pri) 19 | 20 | SOURCES += main.cpp\ 21 | frmmain.cpp \ 22 | frmvisitor.cpp \ 23 | frmalarm.cpp \ 24 | frmdefencelot.cpp \ 25 | frmabout.cpp \ 26 | frmselect.cpp \ 27 | frmgateway.cpp \ 28 | frmconfig.cpp 29 | 30 | HEADERS += frmmain.h \ 31 | frmvisitor.h \ 32 | frmalarm.h \ 33 | frmdefencelot.h \ 34 | frmabout.h \ 35 | frmselect.h \ 36 | frmgateway.h \ 37 | frmconfig.h 38 | 39 | FORMS += frmmain.ui \ 40 | frmvisitor.ui \ 41 | frmalarm.ui \ 42 | frmdefencelot.ui \ 43 | frmabout.ui \ 44 | frmselect.ui \ 45 | frmgateway.ui \ 46 | frmconfig.ui 47 | 48 | INCLUDEPATH += $$PWD 49 | INCLUDEPATH += $$PWD/usercontrol 50 | 51 | MOC_DIR = temp/moc 52 | RCC_DIR = temp/rcc 53 | UI_DIR = temp/ui 54 | OBJECTS_DIR = temp/obj 55 | DESTDIR = bin 56 | win32:RC_FILE = other/main.rc 57 | PRECOMPILED_HEADER = api/myhelper.h 58 | 59 | RESOURCES += \ 60 | other/rc.qrc 61 | 62 | CONFIG += qt warn_off release 63 | -------------------------------------------------------------------------------- /api/api.h: -------------------------------------------------------------------------------- 1 | #ifndef API_H 2 | #define API_H 3 | 4 | #include 5 | #include "usercontrol/defencebutton.h" 6 | 7 | class QFrame; 8 | class QTableWidget; 9 | class QTreeWidget; 10 | class QListWidget; 11 | 12 | class API : public QObject 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit API(QObject *parent = 0); 17 | 18 | //添加快捷提示信息 19 | static void AddMessage(QString message); 20 | 21 | //设置控件(必须最前面设置) 22 | static void SetControl(QFrame *BoxMain, QTableWidget *TableWidget, 23 | QTreeWidget *TreeWidget, QListWidget *ListWidget); 24 | 25 | //初始化所有防区及当前防区 26 | static void InitDefenceAll(QFrame *boxMain); 27 | static void InitDefenceCurrent(QFrame *boxMain); 28 | static void InitDefenceAll(); 29 | static void InitDefenceCurrent(); 30 | 31 | //初始化主机防区树状图/防区缩略图 32 | static void InitTreeWidget(); 33 | static void InitTreeWidget(QTreeWidget *treeWidget); 34 | static void InitListWidget(); 35 | 36 | //主机上线下线及错误处理 37 | static void Connect(); 38 | static void DisConnect(); 39 | static void Error(QString error); 40 | 41 | //布防撤防操作 42 | static void BuFang(); 43 | static void BuFang(int subSystem); 44 | static void CheFang(); 45 | static void CheFang(int subSystem); 46 | 47 | //主机及防区旁路/防区报警/防区断开及故障/防区恢复及软件复位操作 48 | static void PangLu(); 49 | static void PangLu(QString defenceID); 50 | static void BaoJing(QString defenceID); 51 | static void GuZhang(QString defenceID); 52 | static void HuiFu(QString defenceID); 53 | 54 | }; 55 | 56 | #endif // API_H 57 | -------------------------------------------------------------------------------- /api/api.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/api.h \ 3 | $$PWD/app.h \ 4 | $$PWD/appinit.h \ 5 | $$PWD/applive.h \ 6 | $$PWD/applog.h \ 7 | $$PWD/checktaskthread.h \ 8 | $$PWD/dbapi.h \ 9 | $$PWD/dbhelper.h \ 10 | $$PWD/ds7400_com.h \ 11 | $$PWD/excelapi.h \ 12 | $$PWD/gsmapi.h \ 13 | $$PWD/hostapi.h \ 14 | $$PWD/iconhelper.h \ 15 | $$PWD/loadthread.h \ 16 | $$PWD/myhelper.h \ 17 | $$PWD/ntpapi.h \ 18 | $$PWD/pdfapi.h \ 19 | $$PWD/printapi.h \ 20 | $$PWD/sendemailthread.h \ 21 | $$PWD/sendmsgthread.h \ 22 | $$PWD/showdatetime.h \ 23 | $$PWD/vista128_com.h \ 24 | $$PWD/showcpumemory.h \ 25 | $$PWD/showdevicesize.h \ 26 | $$PWD/screenapi.h 27 | 28 | SOURCES += \ 29 | $$PWD/api.cpp \ 30 | $$PWD/app.cpp \ 31 | $$PWD/appinit.cpp \ 32 | $$PWD/applive.cpp \ 33 | $$PWD/applog.cpp \ 34 | $$PWD/checktaskthread.cpp \ 35 | $$PWD/dbapi.cpp \ 36 | $$PWD/dbhelper.cpp \ 37 | $$PWD/ds7400_com.cpp \ 38 | $$PWD/excelapi.cpp \ 39 | $$PWD/gsmapi.cpp \ 40 | $$PWD/hostapi.cpp \ 41 | $$PWD/iconhelper.cpp \ 42 | $$PWD/loadthread.cpp \ 43 | $$PWD/ntpapi.cpp \ 44 | $$PWD/pdfapi.cpp \ 45 | $$PWD/printapi.cpp \ 46 | $$PWD/sendemailthread.cpp \ 47 | $$PWD/sendmsgthread.cpp \ 48 | $$PWD/showdatetime.cpp \ 49 | $$PWD/vista128_com.cpp \ 50 | $$PWD/showcpumemory.cpp \ 51 | $$PWD/showdevicesize.cpp \ 52 | $$PWD/screenapi.cpp 53 | -------------------------------------------------------------------------------- /api/app.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_H 2 | #define APP_H 3 | 4 | #include 5 | 6 | class App 7 | { 8 | public: 9 | static QString AppName; //应用程序英文名称 10 | static QString AppPath; //应用程序路径 11 | static int DeskWidth; //运行环境桌面宽度 12 | static int DeskHeight; //运行环境桌面高度 13 | 14 | static int IcoMain; //左上角图标 15 | static int IcoMenu; //下来菜单图标 16 | static int IcoMin; //最小化图标 17 | static int IcoMax; //最大化图标 18 | static int IcoNormal; //正常图标 19 | static int IcoClose; //关闭图标 20 | 21 | static QString CurrentImage; //当前防区对应地图 22 | static bool IsMove; //防区是否可以移动 23 | static QString CurrentUserName; //当前用户名 24 | static QString CurrentUserPwd; //当前用户密码 25 | static QString CurrentUserType; //当前用户类型(值班员、管理员) 26 | static QString PaletteColor; //画板背景色 27 | static QString TextColor; //文字颜色 28 | 29 | static QString KeyData; //注册码密文 30 | static bool KeyUseDate; //是否启用运行日期时间限制 31 | static QString KeyDate; //到期时间字符串 32 | static bool KeyUseRun; //是否启用可运行时间限制 33 | static int KeyRun; //可运行时间 34 | static bool KeyUseCount; //是否启用设备数量限制 35 | static int KeyCount; //设备限制数量 36 | 37 | static bool SaveLog; //输出日志文件 38 | static bool UseStyle; //启用样式 39 | static QString StyleName; //应用程序样式 40 | static int FontSize; //应用程序字体大小 41 | static QString FontName; //应用程序字体名称 42 | 43 | static bool UseInput; //是否启用输入法 44 | static QString InputPosition; //输入法显示位置 45 | static QString Title; //应用程序标题 46 | static QString Version; //应用程序版本 47 | static QString Author; //版权所有 48 | 49 | static QString HostType; //主机类型 50 | static QString HostCom; //主机通信端口 51 | static QString AlarmServerIP; //报警上传IP 52 | static int AlarmServerPort; //报警上传端口 53 | static int MsgCount; //临时警情条数 54 | static QString SnapPath; //抓拍图像保存路径 55 | static QString VideoPath; //联动视频保存路径 56 | 57 | static bool AutoBuFang; //是否启用自动布防 58 | static bool VideoLink; //是否启用视频联动 59 | static bool NetLink; //是否启用报警上传 60 | static bool SnapLink; //是否启用报警抓拍 61 | static bool PrintLink; //是否启用警情打印 62 | 63 | static bool UseNTP; //是否启用NTP校时 64 | static QString NTPIP; //NTP IP地址 65 | static int NTPInterval; //校时间隔 66 | 67 | static QString MsgPortName; //短信猫通信串口号 68 | static int MsgBaudRate; //短信猫通信波特率 69 | static int MsgInterval; //短信告警间隔 70 | static QString MsgTel; //告警短信接收号码 71 | 72 | static QString SendEmailAddr; //发件人地址 73 | static QString SendEmailPwd; //发件人密码 74 | static int EmailInterval; //邮件告警间隔 75 | static QString EmailAddr; //告警邮件接收地址 76 | 77 | static void ReadConfig(); //读取配置文件,在main函数最开始加载程序载入 78 | static void WriteConfig(); //写入配置文件,在更改配置文件程序关闭时调用 79 | 80 | static void WriteError(QString str);//写入错误信息 81 | static void WriteStartTime(); //写入启动时间 82 | static void NewDir(QString dirName);//新建目录 83 | 84 | static QList TaskList; //待处理操作任务链表 85 | static QList SnapList; //待保存的抓拍告警图像名称 86 | static QList EmailList; //待发送告警邮件链表 87 | static QList MsgList; //待发送告警邮件链表 88 | static void AppendTask(QString task); //插入待处理操作任务 89 | static void AppendSnap(QString snap); //插入待保存告警图像名称队列 90 | static void AppendEmail(QString email); //插入待发送告警邮件链表 91 | static void AppendMsg(QString msg); //插入待发送告警邮件链表 92 | 93 | }; 94 | 95 | #endif // APP_H 96 | -------------------------------------------------------------------------------- /api/appinit.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "appinit.h" 6 | #include "myhelper.h" 7 | #include "applog.h" 8 | #include "inputnew/frminputnew.h" 9 | 10 | AppInit *AppInit::_instance = 0; 11 | AppInit::AppInit(QObject *parent) : QObject(parent) 12 | { 13 | } 14 | 15 | bool AppInit::eventFilter(QObject *obj, QEvent *evt) 16 | { 17 | QWidget *w = (QWidget *)obj; 18 | if (!w->property("CanMove").toBool()) { 19 | return QObject::eventFilter(obj, evt); 20 | } 21 | 22 | static QPoint mousePoint; 23 | static bool mousePressed = false; 24 | 25 | QMouseEvent *event = static_cast(evt); 26 | if (event->type() == QEvent::MouseButtonPress) { 27 | if (event->button() == Qt::LeftButton) { 28 | mousePressed = true; 29 | mousePoint = event->globalPos() - w->pos(); 30 | return true; 31 | } 32 | } else if (event->type() == QEvent::MouseButtonRelease) { 33 | mousePressed = false; 34 | return true; 35 | } else if (event->type() == QEvent::MouseMove) { 36 | if (mousePressed && (event->buttons() && Qt::LeftButton)) { 37 | w->move(event->globalPos() - mousePoint); 38 | return true; 39 | } 40 | } 41 | 42 | return QObject::eventFilter(obj, evt); 43 | } 44 | 45 | void AppInit::Start() 46 | { 47 | myHelper::SetUTF8Code(); 48 | myHelper::SetChinese(); 49 | 50 | App::AppPath = QApplication::applicationDirPath(); 51 | App::DeskWidth = qApp->desktop()->availableGeometry().width(); 52 | App::DeskHeight = qApp->desktop()->availableGeometry().height(); 53 | App::ReadConfig(); 54 | myHelper::SetFont(); 55 | 56 | App::NewDir("image_screen"); 57 | 58 | if (App::UseStyle) { 59 | qApp->installEventFilter(this); 60 | myHelper::SetStyle(App::StyleName); 61 | } 62 | 63 | QFile key(App::AppPath + "/db/key.dll"); 64 | key.open(QFile::ReadOnly); 65 | App::KeyData = key.readLine(); 66 | key.close(); 67 | 68 | //将从注册码文件中的密文解密,与当前时间比较是否到期 69 | App::KeyData = myHelper::getXorEncryptDecrypt(App::KeyData, 110); 70 | QStringList data = App::KeyData.split("|"); 71 | if (data.count() != 6) { 72 | myHelper::ShowMessageBoxError("注册码文件已损坏,程序将自动关闭!"); 73 | exit(0); 74 | } 75 | 76 | App::KeyUseDate = (data.at(0) == "1" ? true : false); 77 | App::KeyDate = data.at(1); 78 | App::KeyUseRun = (data.at(2) == "1" ? true : false); 79 | App::KeyRun = data.at(3).toInt(); 80 | App::KeyUseCount = (data.at(4) == "1" ? true : false); 81 | App::KeyCount = data.at(5).toInt(); 82 | 83 | //如果启用了时间限制 84 | if (App::KeyUseDate) { 85 | QString nowDate = QDate::currentDate().toString("yyyy-MM-dd"); 86 | if (nowDate > App::KeyDate) { 87 | myHelper::ShowMessageBoxError("软件已到期,请联系供应商更新注册码!"); 88 | exit(0); 89 | } 90 | } 91 | 92 | //程序启动后打开数据库连接,在任何窗体需要的地方调用数据库 93 | QSqlDatabase DbConn; 94 | DbConn = QSqlDatabase::addDatabase("QSQLITE"); 95 | QString dbFile = App::AppPath + "/db/GAS.db"; 96 | 97 | if (!myHelper::FileIsExist(dbFile)) { 98 | myHelper::ShowMessageBoxError("数据库文件不存在!"); 99 | exit(0); 100 | } 101 | 102 | DbConn.setDatabaseName(dbFile); 103 | if (!DbConn.open()) { 104 | myHelper::ShowMessageBoxError("数据库文件打开失败!"); 105 | exit(0); 106 | } 107 | 108 | #ifdef __arm__ 109 | frmInputNew::Instance()->init(App::InputPosition, "black", App::FontSize + 2, App::FontSize - 2, 800, 230, 20, 20, 6, 45); 110 | #else 111 | frmInputNew::Instance()->init(App::InputPosition, "black", App::FontSize + 2, App::FontSize, 700, 230, 20, 20, 6, 45); 112 | #endif 113 | 114 | if (App::SaveLog) { 115 | AppLog::Instance()->Start(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /api/appinit.h: -------------------------------------------------------------------------------- 1 | #ifndef APPINIT_H 2 | #define APPINIT_H 3 | 4 | #include 5 | #include 6 | 7 | class AppInit : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AppInit(QObject *parent = 0); 12 | static AppInit *Instance() 13 | { 14 | static QMutex mutex; 15 | 16 | if (!_instance) { 17 | QMutexLocker locker(&mutex); 18 | 19 | if (!_instance) { 20 | _instance = new AppInit; 21 | } 22 | } 23 | 24 | return _instance; 25 | } 26 | 27 | void Start(); 28 | 29 | protected: 30 | bool eventFilter(QObject *obj, QEvent *evt); 31 | 32 | private: 33 | static AppInit *_instance; 34 | 35 | }; 36 | 37 | #endif // APPINIT_H 38 | -------------------------------------------------------------------------------- /api/applive.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "applive.h" 6 | #include "myhelper.h" 7 | 8 | AppLive *AppLive::_instance = 0; 9 | AppLive::AppLive(QObject *parent) : QObject(parent) 10 | { 11 | udpServer = new QUdpSocket(this); 12 | } 13 | 14 | bool AppLive::Start(int port) 15 | { 16 | bool ok = udpServer->bind(port); 17 | 18 | if (ok) { 19 | connect(udpServer, SIGNAL(readyRead()), this, SLOT(ReadData())); 20 | qDebug() << TIMEMS << "Start AppLive Ok"; 21 | } 22 | 23 | return ok; 24 | } 25 | 26 | void AppLive::Stop() 27 | { 28 | udpServer->abort(); 29 | disconnect(udpServer, SIGNAL(readyRead()), this, SLOT(ReadData())); 30 | } 31 | 32 | void AppLive::ReadData() 33 | { 34 | QByteArray tempData; 35 | 36 | do { 37 | tempData.resize(udpServer->pendingDatagramSize()); 38 | QHostAddress sender; 39 | quint16 senderPort; 40 | udpServer->readDatagram(tempData.data(), tempData.size(), &sender, &senderPort); 41 | QString data = QLatin1String(tempData); 42 | 43 | if (data == "hello") { 44 | udpServer->writeDatagram(QString("%1OK").arg(App::AppName).toLatin1(), sender, senderPort); 45 | } 46 | } while (udpServer->hasPendingDatagrams()); 47 | } 48 | -------------------------------------------------------------------------------- /api/applive.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLIVE_H 2 | #define APPLIVE_H 3 | 4 | #include 5 | #include 6 | 7 | class QUdpSocket; 8 | 9 | class AppLive : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit AppLive(QObject *parent = 0); 14 | static AppLive *Instance() 15 | { 16 | static QMutex mutex; 17 | 18 | if (!_instance) { 19 | QMutexLocker locker(&mutex); 20 | 21 | if (!_instance) { 22 | _instance = new AppLive; 23 | } 24 | } 25 | 26 | return _instance; 27 | } 28 | 29 | bool Start(int port); 30 | void Stop(); 31 | 32 | private slots: 33 | void ReadData(); 34 | 35 | private: 36 | static AppLive *_instance; 37 | QUdpSocket *udpServer; 38 | 39 | signals: 40 | 41 | public slots: 42 | }; 43 | 44 | #endif // APPLIVE_H 45 | -------------------------------------------------------------------------------- /api/applog.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "applog.h" 6 | #include "myhelper.h" 7 | 8 | //输出所有打印调试信息到日志文件 9 | #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) 10 | void Log(QtMsgType type, const char *msg) 11 | { 12 | QString content; 13 | 14 | switch (type) { 15 | case QtDebugMsg: 16 | content = QString("%1").arg(msg); 17 | break; 18 | 19 | case QtWarningMsg: 20 | content = QString("%1").arg(msg); 21 | break; 22 | 23 | case QtCriticalMsg: 24 | content = QString("%1").arg(msg); 25 | break; 26 | 27 | case QtFatalMsg: 28 | content = QString("%1").arg(msg); 29 | exit(0); 30 | } 31 | 32 | if (content.startsWith("libpng")) { 33 | return; 34 | } 35 | 36 | QString logFile = QString("%1/log/%2_Log_%3.txt").arg(App::AppPath).arg(App::AppName).arg(QDATE); 37 | QFile log(logFile); 38 | log.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text); 39 | QTextStream logStream(&log); 40 | logStream << content << "\n"; 41 | } 42 | #else 43 | void Log(QtMsgType type, const QMessageLogContext &, const QString &msg) 44 | { 45 | QString content; 46 | 47 | switch (type) { 48 | case QtDebugMsg: 49 | content = QString("%1").arg(msg); 50 | break; 51 | 52 | case QtWarningMsg: 53 | content = QString("%1").arg(msg); 54 | break; 55 | 56 | case QtCriticalMsg: 57 | content = QString("%1").arg(msg); 58 | break; 59 | 60 | case QtFatalMsg: 61 | content = QString("%1").arg(msg); 62 | exit(0); 63 | } 64 | 65 | if (content.startsWith("libpng")) { 66 | return; 67 | } 68 | 69 | QString logFile = QString("%1/log/%2_Log_%3.txt").arg(App::AppPath).arg(App::AppName).arg(QDATE); 70 | QFile log(logFile); 71 | log.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text); 72 | QTextStream logStream(&log); 73 | logStream << content << "\n"; 74 | } 75 | #endif 76 | 77 | AppLog *AppLog::_instance = 0; 78 | AppLog::AppLog(QObject *parent) : QObject(parent) 79 | { 80 | } 81 | 82 | //安装日志钩子,输出调试信息到文件,便于调试 83 | void AppLog::Start() 84 | { 85 | #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) 86 | qInstallMsgHandler(Log); 87 | #else 88 | qInstallMessageHandler(Log); 89 | #endif 90 | } 91 | 92 | //卸载日志钩子 93 | void AppLog::Stop() 94 | { 95 | #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) 96 | qInstallMsgHandler(0); 97 | #else 98 | qInstallMessageHandler(0); 99 | #endif 100 | } 101 | -------------------------------------------------------------------------------- /api/applog.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLOG_H 2 | #define APPLOG_H 3 | 4 | #include 5 | #include 6 | 7 | class AppLog : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit AppLog(QObject *parent = 0); 12 | static AppLog *Instance() 13 | { 14 | static QMutex mutex; 15 | 16 | if (!_instance) { 17 | QMutexLocker locker(&mutex); 18 | 19 | if (!_instance) { 20 | _instance = new AppLog; 21 | } 22 | } 23 | 24 | return _instance; 25 | } 26 | 27 | void Start(); 28 | void Stop(); 29 | 30 | private: 31 | static AppLog *_instance; 32 | 33 | signals: 34 | 35 | public slots: 36 | }; 37 | 38 | #endif // APPLOG_H 39 | -------------------------------------------------------------------------------- /api/checktaskthread.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "checktaskthread.h" 6 | #include "api/myhelper.h" 7 | #include "api/api.h" 8 | #include "api/dbhelper.h" 9 | 10 | CheckTaskThread::CheckTaskThread(QObject *parent) : QThread(parent) 11 | { 12 | stopped = false; 13 | } 14 | 15 | void CheckTaskThread::stop() 16 | { 17 | stopped = true; 18 | } 19 | 20 | void CheckTaskThread::run() 21 | { 22 | while(!stopped) { 23 | int taskCount = App::TaskList.count(); 24 | if (taskCount > 0) { 25 | mutex.lock(); 26 | //每次取出一个任务进行处理 27 | QString task = App::TaskList.takeFirst(); 28 | mutex.unlock(); 29 | qDebug() << TIMEMS << "task:" << task; 30 | QStringList list = task.split("|"); 31 | QString type = list.at(0); 32 | if (type == "Print") { 33 | QString str = QString("防区:%1[%2]\n类型:%3\n时间:%4") 34 | .arg(list.at(2)).arg(list.at(1)).arg(list.at(3)).arg(list.at(4)); 35 | //调用打印函数 36 | 37 | API::AddMessage("打印警情"); 38 | DBHelper::AddEventInfoUser("打印警情"); 39 | } else if (type == "Snap") { 40 | int snapCount = App::SnapList.count(); 41 | //只有告警图像名称存在时 42 | if (snapCount > 0) { 43 | mutex.lock(); 44 | QString fileName = App::SnapList.takeFirst(); 45 | mutex.unlock(); 46 | 47 | //抓拍告警联动图像 48 | Snap(list.at(1), list.at(2), list.at(4), fileName); 49 | 50 | API::AddMessage("告警抓拍图像"); 51 | DBHelper::AddEventInfoUser("告警抓拍图像"); 52 | } 53 | } else if (type == "Video") { 54 | //弹出告警联动视频 55 | 56 | API::AddMessage("告警联动视频"); 57 | DBHelper::AddEventInfoUser("告警联动视频"); 58 | } 59 | } 60 | 61 | msleep(100); 62 | } 63 | stopped = false; 64 | } 65 | 66 | QByteArray CheckTaskThread::GetHtml(QString url) 67 | { 68 | QNetworkAccessManager *manager = new QNetworkAccessManager(); 69 | QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url))); 70 | QEventLoop eventLoop; 71 | QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit())); 72 | eventLoop.exec(); 73 | return reply->readAll(); 74 | } 75 | 76 | void CheckTaskThread::Snap(QString ip, QString ch, QString time, QString fileName) 77 | { 78 | //判断文件夹是否存在,不存在则先创建 79 | #ifdef __arm__ 80 | QString savePath = QString("%1/%2") 81 | .arg(App::SnapPath) 82 | .arg(QDate::currentDate().toString("yyyy-MM-dd")); 83 | #else 84 | QString savePath = QString("%1%2/%3") 85 | .arg(App::AppPath) 86 | .arg(App::SnapPath) 87 | .arg(QDate::currentDate().toString("yyyy-MM-dd")); 88 | #endif 89 | 90 | QDir dir(savePath); 91 | if (!dir.exists()) { 92 | dir.mkpath(savePath); 93 | } 94 | 95 | //构建抓拍告警图像url地址 96 | QString url = QString("http://%1/doSnapshot?channel=%2&stream=%3&timeago=%4") 97 | .arg(ip).arg(ch).arg(1).arg(time); 98 | 99 | QImage image; 100 | image.loadFromData(GetHtml(url)); 101 | image.save(fileName, "jpg"); 102 | } 103 | -------------------------------------------------------------------------------- /api/checktaskthread.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECKTASKTHREAD_H 2 | #define CHECKTASKTHREAD_H 3 | 4 | #include 5 | #include 6 | 7 | class CheckTaskThread : public QThread 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CheckTaskThread(QObject *parent = 0); 12 | 13 | void stop(); 14 | 15 | protected: 16 | void run(); 17 | 18 | private: 19 | QMutex mutex; 20 | volatile bool stopped; 21 | 22 | QByteArray GetHtml(QString url); 23 | void Snap(QString ip, QString ch, QString time, QString fileName); 24 | 25 | }; 26 | 27 | #endif // CHECKTASKTHREAD_H 28 | -------------------------------------------------------------------------------- /api/dbapi.h: -------------------------------------------------------------------------------- 1 | #ifndef DBAPI_H 2 | #define DBAPI_H 3 | 4 | #include 5 | #include 6 | 7 | class QtSql; 8 | class QTableView; 9 | class QLabel; 10 | class QAbstractButton; 11 | class QComboBox; 12 | class QSqlQueryModel; 13 | 14 | class DBAPI : public QObject 15 | { 16 | Q_OBJECT 17 | private: 18 | explicit DBAPI(QObject *parent = 0); 19 | static DBAPI *_instance; 20 | 21 | void BindData(QString sql); 22 | 23 | int startIndex; //分页开始索引,每次翻页都变动 24 | QString tempSql; //临时SQL语句 25 | QString sql; 26 | QSqlQueryModel *queryModel; //查询模型 27 | 28 | QLabel *labPageCount; //总页数 29 | QLabel *labPageCurrent; //当前页 30 | QLabel *labResultCount; //总记录数 31 | QLabel *labResultCurrent; //每页记录数 32 | QLabel *labInfo; //总页数当前页总记录数每页记录数 33 | 34 | QTableView *tableView; //显示数据的表格对象 35 | QAbstractButton *btnFirst; //第一页按钮对象 36 | QAbstractButton *btnPre; //上一页按钮对象 37 | QAbstractButton *btnNext; //下一页按钮对象 38 | QAbstractButton *btnLast; //末一页按钮对象 39 | 40 | int resultCurrent; //每页显示记录数 41 | int resultCount; //总记录数 42 | int pageCount; //总页数 43 | int pageCurrent; //当前第几页 44 | 45 | public: 46 | static DBAPI *Instance() { 47 | static QMutex mutex; 48 | if (!_instance) { 49 | QMutexLocker locker(&mutex); 50 | if (!_instance) { 51 | _instance = new DBAPI; 52 | } 53 | } 54 | return _instance; 55 | } 56 | 57 | //设置需要显示数据的表格,数据翻页对应的按钮 58 | void SetControl(QTableView *tableView, QLabel *labInfo, 59 | QAbstractButton *btnFirst, QAbstractButton *btnPre, 60 | QAbstractButton *btnNext, QAbstractButton *btnLast); 61 | 62 | void SetControl(QTableView *tableView, QLabel *labPageCount, QLabel *labPageCurrent, 63 | QLabel *labResultCount, QLabel *labResultCurrent, 64 | QAbstractButton *btnFirst, QAbstractButton *btnPre, 65 | QAbstractButton *btnNext, QAbstractButton *btnLast); 66 | 67 | //绑定查询数据,带分页/行数/条件/排序/列名/列宽 68 | void BindDataSelect(QString tableName, QString orderSql, QString where, int resultCurrent, 69 | QList columnNames, QList columnWidths); 70 | 71 | //绑定数据到下拉框 72 | void BindData(QString columnName, QString orderColumn, QString tableName, QComboBox *cbox); 73 | void BindData(QString columnName, QString orderColumn, QString tableName, QList cboxs); 74 | 75 | signals: 76 | 77 | private slots: 78 | void first(); //第一页 79 | void previous(); //上一页 80 | void next(); //下一页 81 | void last(); //末一页 82 | 83 | }; 84 | 85 | #endif // DBAPI_H 86 | -------------------------------------------------------------------------------- /api/dbhelper.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "dbhelper.h" 6 | #include "myhelper.h" 7 | 8 | DBHelper::DBHelper(QObject *parent) : 9 | QObject(parent) 10 | { 11 | } 12 | 13 | void DBHelper::AddEventInfo(QString triggerType, QString triggerContent, QString defenceID, QString defenceName) 14 | { 15 | QString sql = "insert into EventInfo(TriggerTime,TriggerType,TriggerContent,DefenceID,DefenceName) values('"; 16 | sql += QString("%1").arg(DATETIME) + "','"; 17 | sql += triggerType + "','"; 18 | sql += triggerContent + "','"; 19 | sql += defenceID + "','"; 20 | sql += defenceName + "')"; 21 | 22 | QSqlQuery query; 23 | query.prepare(sql); 24 | query.exec(); 25 | } 26 | 27 | void DBHelper::AddEventInfoUser(QString triggerContent) 28 | { 29 | AddEventInfo("用户操作", triggerContent, "000", "000"); 30 | } 31 | 32 | void DBHelper::AddEventInfoHost(QString triggerContent) 33 | { 34 | AddEventInfo("主机上报", triggerContent, "000", "000"); 35 | } 36 | 37 | bool DBHelper::IsExistDefence(QString defenceID) 38 | { 39 | QSqlQuery query; 40 | QString sql = QString("select DefenceName from DefenceInfo where DefenceID='%1'").arg(defenceID); 41 | query.exec(sql); 42 | return query.next(); 43 | } 44 | 45 | void DBHelper::GetDefenceInfo(QString defenceID, QString &defenceName, QString &defenceSound) 46 | { 47 | QSqlQuery query; 48 | QString sql = QString("select DefenceName,DefenceSound from DefenceInfo where DefenceID='%1'").arg(defenceID); 49 | query.exec(sql); 50 | query.next(); 51 | defenceName = query.value(0).toString(); 52 | defenceSound = query.value(1).toString(); 53 | } 54 | 55 | bool DBHelper::IsExistLink(QString linkName) 56 | { 57 | QString sql = QString("select LinkName from LinkInfo where LinkName='%1'").arg(linkName); 58 | QSqlQuery query; 59 | query.exec(sql); 60 | return query.next(); 61 | } 62 | -------------------------------------------------------------------------------- /api/dbhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef DBHELPER_H 2 | #define DBHELPER_H 3 | 4 | #include 5 | 6 | class DBHelper : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit DBHelper(QObject *parent = 0); 11 | 12 | //添加日志记录 13 | static void AddEventInfo(QString triggerType, QString triggerContent, QString defenceID, QString defenceName); 14 | static void AddEventInfoUser(QString triggerContent); 15 | static void AddEventInfoHost(QString triggerContent); 16 | 17 | //防区是否已经存在 18 | static bool IsExistDefence(QString defenceID); 19 | 20 | //根据防区号获取防区名称和告警声音 21 | static void GetDefenceInfo(QString defenceID, QString &defenceName, QString &defenceSound); 22 | 23 | //当前联动预案是否存在 24 | static bool IsExistLink(QString linkName); 25 | 26 | signals: 27 | 28 | public slots: 29 | 30 | }; 31 | 32 | #endif // DBHELPER_H 33 | -------------------------------------------------------------------------------- /api/ds7400_com.h: -------------------------------------------------------------------------------- 1 | #ifndef DS7400_COM_H 2 | #define DS7400_COM_H 3 | 4 | #include 5 | #include "qextserialport/qextserialport.h" 6 | #include 7 | #include 8 | 9 | /* 说明:DS7400主机操作头文件 10 | * 功能:动态识别主机上线下线及布防撤防报警等信号 11 | * 作者:刘典武 QQ:517216493 12 | * 时间:2014-1-5 检查:2014-1-10 13 | */ 14 | class DS7400_COM : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit DS7400_COM(QObject *parent = 0); 19 | 20 | //设置和获取主机类型 21 | void SetHostType(QString hostType) { 22 | this->hostType = hostType; 23 | } 24 | QString HostType()const { 25 | return hostType; 26 | } 27 | 28 | //设置和获取主机ID 29 | void SetHostID(QString hostID) { 30 | this->hostID = hostID; 31 | } 32 | QString HostID()const { 33 | return hostID; 34 | } 35 | 36 | //设置和获取主机名称 37 | void SetHostName(QString hostName) { 38 | this->hostName = hostName; 39 | } 40 | QString HostName()const { 41 | return hostName; 42 | } 43 | 44 | //设置和获取主机通讯参数1 45 | void SetHostConnectValue1(QString hostConnectValue1) { 46 | this->hostConnectValue1 = hostConnectValue1; 47 | } 48 | QString HostConnectValue1()const { 49 | return hostConnectValue1; 50 | } 51 | 52 | //设置和获取主机通讯参数2 53 | void SetHostConnectValue2(QString hostConnectValue2) { 54 | this->hostConnectValue2 = hostConnectValue2; 55 | } 56 | QString HostConnectValue2()const { 57 | return hostConnectValue2; 58 | } 59 | 60 | bool Open(); 61 | bool IsOpen()const { 62 | return isOpen; 63 | } 64 | void Close(); 65 | 66 | private: 67 | QextSerialPort *hostCOM; 68 | 69 | bool isOpen; //打开状态 70 | bool isOnLine; //在线状态,初始值为假 71 | bool isCheckOnline; //检测下线状态,初始值为真 72 | 73 | QDateTime lastHeartTime; //存储最后一次心跳时间 74 | QTimer *timerOnLine; //定时器检测主机上线 75 | QTimer *timerRead; //定时器读取数据 76 | 77 | QString hostType; //主机类型 78 | QString hostID; //主机编号 79 | QString hostName; //主机名称 80 | QString hostConnectValue1; //主机参数1 81 | QString hostConnectValue2; //主机参数2 82 | 83 | bool errorAC; //交流电源故障 84 | bool errorDC; //备用电池故障 85 | bool errorCode; //报告发送故障 86 | bool errorControl; //控制故障 87 | bool error485; //总线故障 88 | bool errorWifi; //无线接收故障 89 | bool errorPower; //辅助电源故障 90 | bool errorDevice; //设备故障 91 | 92 | void CheckCode(QString code); 93 | QString GetDefenceID(int tempID); 94 | 95 | private slots: 96 | void ReadData(); //读取数据槽函数 97 | void CheckOnLine(); //检测在线状态槽函数 98 | 99 | signals: 100 | void HostConnect(QString hostID, QString hostName); //主机上线 101 | void HostDisConnect(QString hostID, QString hostName); //主机下线 102 | void HostError(QString hostID, QString hostName, QString error); //主机错误,例如电池掉电 103 | void HostBuFangSubSystem(QString hostID, QString hostName, int subSystem); //主机子系统布防 104 | void HostCheFangSubSystem(QString hostID, QString hostName, int subSystem); //主机子系统撤防 105 | void DefenceBaoJing(QString hostID, QString hostName, QString defenceID); //防区报警 106 | void DefencePangLu(QString hostID, QString hostName, QString defenceID); //防区旁路 107 | void DefenceGuZhang(QString hostID, QString hostName, QString defenceID); //防区故障 108 | void DefenceHuiFu(QString hostID, QString hostName, QString defenceID); //防区恢复 109 | 110 | void HostReceiveData(QString hostID, QString hostName, QString data); //主机收到数据信号 111 | void HostHeart(QString hostID, QString hostName); //主机心跳信号 112 | 113 | public slots: 114 | 115 | }; 116 | 117 | #endif // DS7400_COM_H 118 | -------------------------------------------------------------------------------- /api/excelapi.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEL_H 2 | #define EXCEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class ExcelAPI : public QObject 9 | { 10 | Q_OBJECT 11 | private: 12 | explicit ExcelAPI(QObject *parent = 0); 13 | static ExcelAPI *_instance; 14 | QStringList html; 15 | 16 | void checkBorder(bool border); 17 | 18 | public: 19 | static ExcelAPI *Instance() { 20 | static QMutex mutex; 21 | if (!_instance) { 22 | QMutexLocker locker(&mutex); 23 | if (!_instance) { 24 | _instance = new ExcelAPI; 25 | } 26 | } 27 | return _instance; 28 | } 29 | 30 | void ToExcel(QString fileName, QString sheetName, QString title, QString subTitle, 31 | QList columnNames, QList columnWidths, 32 | QStringList content, bool border, bool check); 33 | 34 | void ToExcel(QString fileName, QString sheetName, QString title, 35 | QList columnNames, QList columnWidths, 36 | QStringList subTitle1, QStringList subTitle2, 37 | QStringList content, bool border, bool check); 38 | 39 | }; 40 | 41 | #endif // EXCEL_H 42 | -------------------------------------------------------------------------------- /api/gsmapi.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "gsmapi.h" 6 | #include "myhelper.h" 7 | #include "api.h" 8 | #include "dbhelper.h" 9 | #include "sendmsgthread.h" 10 | 11 | GSMAPI::GSMAPI(QObject *parent) : 12 | QObject(parent) 13 | { 14 | portName = "COM1"; 15 | isOpen = false; 16 | isLive = false; 17 | 18 | timerTask = new QTimer(this); 19 | timerTask->setInterval(10000); 20 | connect(timerTask, SIGNAL(timeout()), this, SLOT(DoTask())); 21 | timerTask->start(); 22 | } 23 | 24 | void GSMAPI::SetPortName(QString portName) 25 | { 26 | this->portName = portName; 27 | } 28 | 29 | bool GSMAPI::Open() 30 | { 31 | headMsg = "端口:短信端口"; 32 | 33 | GSM_COM = new QextSerialPort(portName); 34 | isOpen = GSM_COM->open(QIODevice::ReadWrite); 35 | if (isOpen) { 36 | GSM_COM->flush(); 37 | GSM_COM->setBaudRate(BAUD9600); 38 | GSM_COM->setDataBits(DATA_8); 39 | GSM_COM->setParity(PAR_NONE); 40 | GSM_COM->setStopBits(STOP_1); 41 | GSM_COM->setFlowControl(FLOW_OFF); 42 | GSM_COM->setTimeout(10); 43 | } 44 | return isOpen; 45 | } 46 | 47 | void GSMAPI::Init() 48 | { 49 | if (Islive()) { 50 | //设置短信模式为PDU模式 51 | SendAT("AT+CMGF=0", 100); 52 | } 53 | } 54 | 55 | bool GSMAPI::Islive() 56 | { 57 | if (isOpen) { 58 | GSM_COM->write(QString("%1\r").arg("AT").toLatin1()); 59 | myHelper::Sleep(300); 60 | QString data = GSM_COM->readAll(); 61 | data = data.replace(" ", ""); 62 | data = data.replace("\r", ""); 63 | data = data.replace("\n", ""); 64 | //收到返回ATOK说明短信猫连接成功 65 | if (data == "ATOK") { 66 | isLive = true; 67 | } else { 68 | isLive = false; 69 | } 70 | } else { 71 | isLive = false; 72 | } 73 | return isLive; 74 | } 75 | 76 | void GSMAPI::Close() 77 | { 78 | GSM_COM->close(); 79 | GSM_COM = 0; 80 | isLive = false; 81 | isOpen = false; 82 | } 83 | 84 | QString GSMAPI::SendAT(QString cmd, int sleep) 85 | { 86 | if (!isOpen || !isLive) { 87 | return ""; 88 | } 89 | 90 | GSM_COM->flush(); 91 | GSM_COM->write(QString("%1\r").arg(cmd).toLatin1()); 92 | myHelper::Sleep(sleep); 93 | QString data = GSM_COM->readAll(); 94 | data = data.replace(" ", ""); 95 | data = data.replace("\r", ""); 96 | data = data.replace("\n", ""); 97 | 98 | return data; 99 | } 100 | 101 | //对于多个号码,将号码分割开来,如果短信内容超过70个字符则分割成小于70个字符的短信 102 | void GSMAPI::SendMsgAll(QString tels, QStringList msgs) 103 | { 104 | QStringList t = tels.split(";"); 105 | foreach (QString tel, t) { 106 | foreach (QString msg, msgs) { 107 | task.append(QString("%1|%2").arg(tel).arg(msg)); 108 | } 109 | } 110 | } 111 | 112 | void GSMAPI::SendMsgOne(QString tel, QString msg) 113 | { 114 | qDebug() << TIME << headMsg << "命令解析:" << "发送告警短信" << "号码:" << tel << "内容:" << msg; 115 | 116 | SendMsgThread *sendMsgThread = new SendMsgThread(this); 117 | connect(sendMsgThread, SIGNAL(finished()), sendMsgThread, SLOT(deleteLater())); 118 | sendMsgThread->SetPar(this, tel, msg); 119 | sendMsgThread->start(); 120 | } 121 | 122 | QString GSMAPI::GetGSMType() 123 | { 124 | QString result = SendAT("AT+CGMI", 300); 125 | QString type = ""; 126 | //如果成功会返回 AT+CGMISIEMENSOK,对应类型要减去开头7位和末尾2位 127 | if (result.right(2) == "OK") { 128 | type = result.mid(7, result.length() - 7 - 2); 129 | } 130 | return type; 131 | } 132 | 133 | QString GSMAPI::GetGSMCenterNum() 134 | { 135 | QString result = SendAT("AT+CSCA?", 300); 136 | QString num = ""; 137 | //如果成功会返回 AT+CSCA?+CSCA:"+8613010314500",145OK 138 | if (result.right(2) == "OK") { 139 | num = result.split("\"")[1]; 140 | } 141 | return num; 142 | } 143 | 144 | void GSMAPI::DoTask() 145 | { 146 | int count = task.count(); 147 | if (count <= 0) { 148 | return; 149 | } 150 | 151 | QString str = task.takeFirst(); 152 | QStringList list = str.split("|"); 153 | QString tel = list.at(0); 154 | QString msg = list.at(1); 155 | SendMsgOne(tel, msg); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /api/gsmapi.h: -------------------------------------------------------------------------------- 1 | #ifndef GSMAPI_H 2 | #define GSMAPI_H 3 | 4 | #include 5 | #include "qextserialport/qextserialport.h" 6 | 7 | class QTimer; 8 | 9 | class GSMAPI : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit GSMAPI(QObject *parent = 0); 14 | 15 | void SetPortName(QString portName); //设置串口号 16 | bool Open(); //打开串口 17 | bool IsOpen()const { 18 | return isOpen; //串口是否打开 19 | } 20 | void Init(); //初始化短信猫 21 | bool Islive(); //检测短信猫是否活着 22 | void Close(); //关闭串口 23 | 24 | QString SendAT(QString cmd, int sleep); //执行命令 25 | void SendMsgOne(QString tel, QString msg); //单个号码发送短信 26 | void SendMsgAll(QString tels, QStringList msgs); //批量号码长短信发送 27 | 28 | QString GetGSMType(); //获取短信猫厂商标识 29 | QString GetGSMCenterNum(); //获取短信中心号码 30 | 31 | private: 32 | QextSerialPort *GSM_COM; //短信猫通信串口对象 33 | QString portName; //串口号 34 | bool isOpen; //串口是否打开 35 | bool isLive; //短信猫是否活着 36 | QString headMsg; //打印消息头部内容 37 | 38 | QTimer *timerTask; //处理读取短信队列 39 | QList task; //读取短信和删除短信队列 40 | 41 | private slots: 42 | void DoTask(); //处理任务队列 43 | 44 | }; 45 | 46 | #endif // GSMAPI_H 47 | -------------------------------------------------------------------------------- /api/hostapi.h: -------------------------------------------------------------------------------- 1 | #ifndef HOSTAPI_H 2 | #define HOSTAPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "ds7400_com.h" 8 | #include "vista128_com.h" 9 | #include "api/gsmapi.h" 10 | #include "api/sendemailthread.h" 11 | #include "api/checktaskthread.h" 12 | 13 | class HostAPI : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit HostAPI(QObject *parent = 0); 18 | ~HostAPI(); 19 | 20 | static HostAPI *Instance() { 21 | static QMutex mutex; 22 | if (!_instance) { 23 | QMutexLocker locker(&mutex); 24 | if (!_instance) { 25 | _instance = new HostAPI; 26 | } 27 | } 28 | return _instance; 29 | } 30 | 31 | void Init(); 32 | void BuFang(); 33 | void BuFang(int subSystem); 34 | void CheFang(); 35 | void CheFang(int subSystem); 36 | void PangLu(QString defenceID); 37 | void HuiFu(QString defenceID); 38 | 39 | private: 40 | static HostAPI *_instance; 41 | 42 | VISTA128_COM *vista128_com; //VISTA128主机处理类 43 | DS7400_COM *ds7400_com; //DS7400主机处理类 44 | GSMAPI *GSM; //短信告警处理类 45 | CheckTaskThread *checkTaskThread; //任务处理线程 46 | QSound *sound; //报警声音对象 47 | 48 | QTimer *timerNTP; //NTP服务定时器 49 | QTimer *timer128; //128主机连续布防撤防 50 | QStringList task; //临时任务队列处理 51 | 52 | //短信告警邮件告警算法 53 | //定时器取出每次将所有告警信息一次性发出 54 | QTimer *timerMsg; 55 | QTimer *timerEmail; 56 | 57 | private slots: 58 | //定时器校时 59 | void CheckTime(); 60 | void ReceiveTime(QDateTime dateTime); 61 | //定时器处理短信告警 62 | void CheckMsg(); 63 | //定时器处理邮件告警 64 | void CheckEmail(); 65 | //定时器处理队列任务 66 | void CheckTask(); 67 | 68 | signals: 69 | void HostReceiveData(QString hostID, QString hostName, QString data); //主机收到数据信号 70 | 71 | public slots: 72 | void HostConnect(QString, QString); //主机上线 73 | void HostDisConnect(QString, QString); //主机下线 74 | void HostError(QString, QString, QString error); //主机错误,例如电池掉电 75 | void HostBuFang(QString, QString); //主机布防 76 | void HostCheFang(QString, QString); //主机撤防 77 | void HostBuFangSubSystem(QString, QString, int subSystem); //主机子系统布防 78 | void HostCheFangSubSystem(QString, QString, int subSystem); //主机子系统撤防 79 | void DefenceBaoJing(QString, QString, QString defenceID); //防区报警 80 | void DefencePangLu(QString, QString, QString defenceID); //防区旁路 81 | void DefenceGuZhang(QString, QString, QString defenceID); //防区故障 82 | void DefenceHuiFu(QString, QString, QString defenceID); //防区恢复 83 | 84 | void SetNTPInterval(); 85 | void SetMsgInterval(); 86 | void SetEmailInterval(); 87 | 88 | }; 89 | 90 | #endif // HOSTAPI_H 91 | -------------------------------------------------------------------------------- /api/iconhelper.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "iconhelper.h" 6 | #include "myhelper.h" 7 | 8 | IconHelper *IconHelper::_instance = 0; 9 | IconHelper::IconHelper(QObject *): 10 | QObject(qApp) 11 | { 12 | int fontId = QFontDatabase::addApplicationFont(":/image/fontawesome-webfont.ttf"); 13 | QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0); 14 | iconFont = QFont(fontName); 15 | 16 | icoSize = QSize(16, 16); 17 | icoTextColor = Qt::red; 18 | icoTextSize = App::FontSize; 19 | } 20 | 21 | void IconHelper::SetIcon(QLabel *lab, QChar c) 22 | { 23 | SetIcon(lab, c, App::FontSize); 24 | } 25 | 26 | void IconHelper::SetIcon(QAbstractButton *btn, QChar c) 27 | { 28 | SetIcon(btn, c, App::FontSize); 29 | } 30 | 31 | void IconHelper::SetIcon(QLabel *lab, QChar c, int size) 32 | { 33 | iconFont.setPointSize(size); 34 | lab->setFont(iconFont); 35 | lab->setText(c); 36 | } 37 | 38 | void IconHelper::SetIcon(QAbstractButton *btn, QChar c, int size) 39 | { 40 | iconFont.setPointSize(size); 41 | btn->setFont(iconFont); 42 | btn->setText(c); 43 | } 44 | 45 | void IconHelper::SetIcoMain(QLabel *labMain) 46 | { 47 | SetIcoMain(labMain, App::FontSize); 48 | } 49 | 50 | void IconHelper::SetIcoMenu(QAbstractButton *btnMenu) 51 | { 52 | SetIcoMenu(btnMenu, App::FontSize); 53 | } 54 | 55 | void IconHelper::SetIcoMin(QAbstractButton *btnMin) 56 | { 57 | SetIcoMin(btnMin, App::FontSize); 58 | } 59 | 60 | void IconHelper::SetIcoMax(QAbstractButton *btnMax) 61 | { 62 | SetIcoMax(btnMax, App::FontSize); 63 | } 64 | 65 | void IconHelper::SetIcoNormal(QAbstractButton *btnNormal) 66 | { 67 | SetIcoNormal(btnNormal, App::FontSize); 68 | } 69 | 70 | void IconHelper::SetIcoClose(QAbstractButton *btnClose) 71 | { 72 | SetIcoClose(btnClose, App::FontSize); 73 | } 74 | 75 | void IconHelper::SetIcoMain(QLabel *labMain, int size) 76 | { 77 | iconFont.setPointSize(size); 78 | labMain->setFont(iconFont); 79 | labMain->setText(QChar(App::IcoMain)); 80 | } 81 | 82 | void IconHelper::SetIcoMenu(QAbstractButton *btnMenu, int size) 83 | { 84 | iconFont.setPointSize(size); 85 | btnMenu->setFont(iconFont); 86 | btnMenu->setText(QChar(App::IcoMenu)); 87 | } 88 | 89 | void IconHelper::SetIcoMin(QAbstractButton *btnMin, int size) 90 | { 91 | iconFont.setPointSize(size); 92 | btnMin->setFont(iconFont); 93 | btnMin->setText(QChar(App::IcoMin)); 94 | } 95 | 96 | void IconHelper::SetIcoMax(QAbstractButton *btnMax, int size) 97 | { 98 | iconFont.setPointSize(size); 99 | btnMax->setFont(iconFont); 100 | btnMax->setText(QChar(App::IcoMax)); 101 | } 102 | 103 | void IconHelper::SetIcoNormal(QAbstractButton *btnNormal, int size) 104 | { 105 | iconFont.setPointSize(size); 106 | btnNormal->setFont(iconFont); 107 | btnNormal->setText(QChar(App::IcoNormal)); 108 | } 109 | 110 | void IconHelper::SetIcoClose(QAbstractButton *btnClose, int size) 111 | { 112 | iconFont.setPointSize(size); 113 | btnClose->setFont(iconFont); 114 | btnClose->setText(QChar(App::IcoClose)); 115 | } 116 | 117 | QIcon IconHelper::IcoMenu() 118 | { 119 | return Ico(QChar(App::IcoMenu), icoTextSize); 120 | } 121 | 122 | QIcon IconHelper::IcoMin() 123 | { 124 | return Ico(QChar(App::IcoMin), icoTextSize); 125 | } 126 | 127 | QIcon IconHelper::IcoMax() 128 | { 129 | return Ico(QChar(App::IcoMax), icoTextSize); 130 | } 131 | 132 | QIcon IconHelper::IcoNormal() 133 | { 134 | return Ico(QChar(App::IcoNormal), icoTextSize); 135 | } 136 | 137 | QIcon IconHelper::IcoClose() 138 | { 139 | return Ico(QChar(App::IcoClose), icoTextSize); 140 | } 141 | 142 | QIcon IconHelper::Ico(QChar c) 143 | { 144 | return Ico(c, icoTextSize); 145 | } 146 | 147 | QIcon IconHelper::Ico(QChar c, int size) 148 | { 149 | QImage image(icoSize, QImage::Format_ARGB32); 150 | QPainter painter(&image); 151 | painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); 152 | 153 | QPen pen = painter.pen(); 154 | pen.setColor(icoTextColor); 155 | iconFont.setPixelSize(size); 156 | painter.setPen(pen); 157 | painter.setFont(iconFont); 158 | 159 | painter.drawText(image.rect(), Qt::AlignCenter, c); 160 | return QIcon(QPixmap::fromImage(image)); 161 | } 162 | -------------------------------------------------------------------------------- /api/iconhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONHELPER_H 2 | #define ICONHELPER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class IconHelper : public QObject 14 | { 15 | private: 16 | explicit IconHelper(QObject *parent = 0); 17 | 18 | static IconHelper *_instance; 19 | 20 | QFont iconFont; 21 | QSize icoSize; 22 | QColor icoTextColor; 23 | int icoTextSize; 24 | 25 | public: 26 | static IconHelper *Instance() { 27 | static QMutex mutex; 28 | if (!_instance) { 29 | QMutexLocker locker(&mutex); 30 | if (!_instance) { 31 | _instance = new IconHelper; 32 | } 33 | } 34 | return _instance; 35 | } 36 | 37 | void SetIcon(QLabel *lab, QChar c); 38 | void SetIcon(QAbstractButton *btn, QChar c); 39 | 40 | void SetIcon(QLabel *lab, QChar c, int size); 41 | void SetIcon(QAbstractButton *btn, QChar c, int size); 42 | 43 | void SetIcoMain(QLabel *labMain); 44 | void SetIcoMenu(QAbstractButton *btnMenu); 45 | void SetIcoMin(QAbstractButton *btnMin); 46 | void SetIcoMax(QAbstractButton *btnMax); 47 | void SetIcoNormal(QAbstractButton *btnNormal); 48 | void SetIcoClose(QAbstractButton *btnClose); 49 | 50 | void SetIcoMain(QLabel *labMain, int size); 51 | void SetIcoMenu(QAbstractButton *btnMenu, int size); 52 | void SetIcoMin(QAbstractButton *btnMin, int size); 53 | void SetIcoMax(QAbstractButton *btnMax, int size); 54 | void SetIcoNormal(QAbstractButton *btnNormal, int size); 55 | void SetIcoClose(QAbstractButton *btnClose, int size); 56 | 57 | void SetIcoSize(QSize icoSize) { 58 | this->icoSize = icoSize; 59 | } 60 | 61 | void SetIcoTextColor(QColor icoTextColor) { 62 | this->icoTextColor = icoTextColor; 63 | } 64 | 65 | void SetIcoTextSize(int icoTextSize) { 66 | this->icoTextSize = icoTextSize; 67 | } 68 | 69 | QIcon IcoMenu(); 70 | QIcon IcoMin(); 71 | QIcon IcoMax(); 72 | QIcon IcoNormal(); 73 | QIcon IcoClose(); 74 | 75 | QIcon IcoMenu(QChar c); 76 | QIcon IcoMin(QChar c); 77 | QIcon IcoMax(QChar c); 78 | QIcon IcoNormal(QChar c); 79 | QIcon IcoClose(QChar c); 80 | 81 | QIcon Ico(QChar c); 82 | QIcon Ico(QChar c, int size); 83 | 84 | }; 85 | 86 | #endif // ICONHELPER_H 87 | -------------------------------------------------------------------------------- /api/loadthread.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "loadthread.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | LoadThread::LoadThread(QObject *parent) : QThread(parent) 12 | { 13 | stopped = false; 14 | } 15 | 16 | void LoadThread::stop() 17 | { 18 | stopped = true; 19 | } 20 | 21 | void LoadThread::run() 22 | { 23 | QMovie *movie = new QMovie(":/image/loading.gif"); 24 | QLabel *label = new QLabel("", 0); 25 | 26 | label->setAttribute(Qt::WA_DeleteOnClose); 27 | label->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); 28 | label->setScaledContents(true); 29 | label->setMovie(movie); 30 | movie->start(); 31 | label->show(); 32 | 33 | int frmX = label->width(); 34 | int frmY = label->height(); 35 | QDesktopWidget w; 36 | int deskWidth = w.availableGeometry().width(); 37 | int deskHeight = w.availableGeometry().height(); 38 | QPoint movePoint(deskWidth / 2 - frmX / 2, deskHeight / 2 - frmY / 2); 39 | label->move(movePoint); 40 | 41 | while(!stopped) { 42 | qApp->processEvents(); 43 | msleep(10); 44 | } 45 | 46 | label->close(); 47 | delete movie; 48 | } 49 | -------------------------------------------------------------------------------- /api/loadthread.h: -------------------------------------------------------------------------------- 1 | #ifndef LOADTHREAD_H 2 | #define LOADTHREAD_H 3 | 4 | #include 5 | 6 | class LoadThread : public QThread 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit LoadThread(QObject *parent = 0); 11 | 12 | void stop(); 13 | 14 | protected: 15 | void run(); 16 | 17 | private: 18 | volatile bool stopped; 19 | 20 | }; 21 | 22 | #endif // LOADTHREAD_H 23 | -------------------------------------------------------------------------------- /api/ntpapi.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "ntpapi.h" 6 | 7 | NTPAPI *NTPAPI::_instance = 0; 8 | NTPAPI::NTPAPI(QObject *parent) : QObject(parent) 9 | { 10 | udpSocket = 0; 11 | } 12 | 13 | void NTPAPI::GetTime(QString ntpIP) 14 | { 15 | udpSocket = new QUdpSocket(this); 16 | connect(udpSocket, SIGNAL(connected()), this, SLOT(SendData())); 17 | connect(udpSocket, SIGNAL(readyRead()), this, SLOT(ReadData())); 18 | udpSocket->connectToHost(ntpIP, 123); 19 | } 20 | 21 | void NTPAPI::SendData() 22 | { 23 | qint8 LI = 0; 24 | qint8 VN = 3; 25 | qint8 MODE = 3; 26 | qint8 STRATUM = 0; 27 | qint8 POLL = 4; 28 | qint8 PREC = -6; 29 | QDateTime Epoch(QDate(1900, 1, 1)); 30 | qint32 second = quint32(Epoch.secsTo(QDateTime::currentDateTime())); 31 | 32 | qint32 temp = 0; 33 | QByteArray timeRequest(48, 0); 34 | timeRequest[0] = (LI << 6) | (VN << 3) | (MODE); 35 | timeRequest[1] = STRATUM; 36 | timeRequest[2] = POLL; 37 | timeRequest[3] = PREC & 0xff; 38 | timeRequest[5] = 1; 39 | timeRequest[9] = 1; 40 | timeRequest[40] = (temp = (second & 0xff000000) >> 24); 41 | temp = 0; 42 | timeRequest[41] = (temp = (second & 0x00ff0000) >> 16); 43 | temp = 0; 44 | timeRequest[42] = (temp = (second & 0x0000ff00) >> 8); 45 | temp = 0; 46 | timeRequest[43] = ((second & 0x000000ff)); 47 | 48 | udpSocket->flush(); 49 | udpSocket->write(timeRequest); 50 | udpSocket->flush(); 51 | } 52 | 53 | void NTPAPI::ReadData() 54 | { 55 | QByteArray newTime; 56 | QDateTime Epoch(QDate(1900, 1, 1)); 57 | QDateTime unixStart(QDate(1970, 1, 1)); 58 | 59 | do { 60 | newTime.resize(udpSocket->pendingDatagramSize()); 61 | udpSocket->read(newTime.data(), newTime.size()); 62 | } while (udpSocket->hasPendingDatagrams()); 63 | 64 | QByteArray TransmitTimeStamp ; 65 | TransmitTimeStamp = newTime.right(8); 66 | quint32 seconds = TransmitTimeStamp.at(0); 67 | quint8 temp = 0; 68 | 69 | for (int i = 1; i <= 3; i++) { 70 | seconds = (seconds << 8); 71 | temp = TransmitTimeStamp.at(i); 72 | seconds = seconds + temp; 73 | } 74 | 75 | QDateTime dateTime; 76 | dateTime.setTime_t(seconds - Epoch.secsTo(unixStart)); 77 | 78 | #ifdef __arm__ 79 | //dateTime = dateTime.addSecs(60 * 60 * 8); 80 | #endif 81 | udpSocket->disconnectFromHost(); 82 | udpSocket->close(); 83 | udpSocket = 0; 84 | 85 | emit ReceiveTime(dateTime); 86 | } 87 | -------------------------------------------------------------------------------- /api/ntpapi.h: -------------------------------------------------------------------------------- 1 | #ifndef NTPAPI_H 2 | #define NTPAPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class NTPAPI : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit NTPAPI(QObject *parent = 0); 14 | static NTPAPI *Instance() 15 | { 16 | static QMutex mutex; 17 | 18 | if (!_instance) { 19 | QMutexLocker locker(&mutex); 20 | 21 | if (!_instance) { 22 | _instance = new NTPAPI; 23 | } 24 | } 25 | 26 | return _instance; 27 | } 28 | 29 | private: 30 | static NTPAPI *_instance; 31 | QUdpSocket *udpSocket; 32 | 33 | private slots: 34 | void ReadData(); 35 | void SendData(); 36 | 37 | signals: 38 | void ReceiveTime(QDateTime dateTime); 39 | 40 | public slots: 41 | void GetTime(QString ntpIP); 42 | 43 | }; 44 | 45 | #endif // NTPAPI_H 46 | -------------------------------------------------------------------------------- /api/pdfapi.h: -------------------------------------------------------------------------------- 1 | #ifndef PDFAPI_H 2 | #define PDFAPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class PdfAPI : public QObject 10 | { 11 | Q_OBJECT 12 | private: 13 | explicit PdfAPI(QObject *parent = 0); 14 | static PdfAPI *_instance; 15 | QStringList html; 16 | 17 | public: 18 | static PdfAPI *Instance() { 19 | static QMutex mutex; 20 | if (!_instance) { 21 | QMutexLocker locker(&mutex); 22 | if (!_instance) { 23 | _instance = new PdfAPI; 24 | } 25 | } 26 | return _instance; 27 | } 28 | 29 | void SavePdf(QString fileName, QString title, QString subTitle, 30 | QList columnNames, QList columnWidths, 31 | QStringList content, bool landscape, bool check, 32 | QPrinter::PageSize pageSize = QPrinter::A4); 33 | 34 | void SavePdf(QString fileName, QString title, 35 | QList columnNames, QList columnWidths, 36 | QStringList subTitle1, QStringList subTitle2, 37 | QStringList content, bool landscape, bool check, 38 | QPrinter::PageSize pageSize = QPrinter::A4); 39 | 40 | }; 41 | 42 | #endif // PDFAPI_H 43 | -------------------------------------------------------------------------------- /api/printapi.h: -------------------------------------------------------------------------------- 1 | #ifndef PRINTAPI_H 2 | #define PRINTAPI_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class QPrinter; 10 | 11 | class PrintAPI : public QObject 12 | { 13 | Q_OBJECT 14 | private: 15 | explicit PrintAPI(QObject *parent = 0); 16 | static PrintAPI *_instance; 17 | QStringList html; 18 | 19 | public: 20 | static PrintAPI *Instance() { 21 | static QMutex mutex; 22 | if (!_instance) { 23 | QMutexLocker locker(&mutex); 24 | if (!_instance) { 25 | _instance = new PrintAPI; 26 | } 27 | } 28 | return _instance; 29 | } 30 | 31 | void PrintA4(QString title, QString subTitle, 32 | QList columnNames, QList columnWidths, 33 | QStringList content, bool landscape, bool check, 34 | QPrinter::PageSize pageSize = QPrinter::A4); 35 | 36 | void PrintA4(QString title, QList columnNames, QList columnWidths, 37 | QStringList subTitle1, QStringList subTitle2, 38 | QStringList content, bool landscape, bool check, 39 | QPrinter::PageSize pageSize = QPrinter::A4); 40 | 41 | signals: 42 | 43 | private slots: 44 | void printView(QPrinter *printer); 45 | 46 | }; 47 | 48 | #endif // PRINTAPI_H 49 | -------------------------------------------------------------------------------- /api/screenapi.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "screenapi.h" 6 | #include "myhelper.h" 7 | 8 | ScreenAPI::ScreenAPI(QSize size) 9 | { 10 | maxWidth = size.width(); 11 | maxHeight = size.height(); 12 | 13 | startPos = QPoint(-1, -1); 14 | endPos = startPos; 15 | leftUpPos = startPos; 16 | rightDownPos = startPos; 17 | status = SELECT; 18 | } 19 | 20 | int ScreenAPI::width() 21 | { 22 | return maxWidth; 23 | } 24 | 25 | int ScreenAPI::height() 26 | { 27 | return maxHeight; 28 | } 29 | 30 | ScreenAPI::STATUS ScreenAPI::getStatus() 31 | { 32 | return status; 33 | } 34 | 35 | void ScreenAPI::setStatus(STATUS status) 36 | { 37 | this->status = status; 38 | } 39 | 40 | void ScreenAPI::setEnd(QPoint pos) 41 | { 42 | endPos = pos; 43 | leftUpPos = startPos; 44 | rightDownPos = endPos; 45 | cmpPoint(leftUpPos, rightDownPos); 46 | } 47 | 48 | void ScreenAPI::setStart(QPoint pos) 49 | { 50 | startPos = pos; 51 | } 52 | 53 | QPoint ScreenAPI::getEnd() 54 | { 55 | return endPos; 56 | } 57 | 58 | QPoint ScreenAPI::getStart() 59 | { 60 | return startPos; 61 | } 62 | 63 | QPoint ScreenAPI::getLeftUp() 64 | { 65 | return leftUpPos; 66 | } 67 | 68 | QPoint ScreenAPI::getRightDown() 69 | { 70 | return rightDownPos; 71 | } 72 | 73 | bool ScreenAPI::isInArea(QPoint pos) 74 | { 75 | if (pos.x() > leftUpPos.x() && pos.x() < rightDownPos.x() && pos.y() > leftUpPos.y() && pos.y() < rightDownPos.y()) { 76 | return true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | void ScreenAPI::move(QPoint p) 83 | { 84 | int lx = leftUpPos.x() + p.x(); 85 | int ly = leftUpPos.y() + p.y(); 86 | int rx = rightDownPos.x() + p.x(); 87 | int ry = rightDownPos.y() + p.y(); 88 | 89 | if (lx < 0) { 90 | lx = 0; 91 | rx -= p.x(); 92 | } 93 | 94 | if (ly < 0) { 95 | ly = 0; 96 | ry -= p.y(); 97 | } 98 | 99 | if (rx > maxWidth) { 100 | rx = maxWidth; 101 | lx -= p.x(); 102 | } 103 | 104 | if (ry > maxHeight) { 105 | ry = maxHeight; 106 | ly -= p.y(); 107 | } 108 | 109 | leftUpPos = QPoint(lx, ly); 110 | rightDownPos = QPoint(rx, ry); 111 | startPos = leftUpPos; 112 | endPos = rightDownPos; 113 | } 114 | 115 | void ScreenAPI::cmpPoint(QPoint &leftTop, QPoint &rightDown) 116 | { 117 | QPoint l = leftTop; 118 | QPoint r = rightDown; 119 | 120 | if (l.x() <= r.x()) { 121 | if (l.y() <= r.y()) { 122 | ; 123 | } else { 124 | leftTop.setY(r.y()); 125 | rightDown.setY(l.y()); 126 | } 127 | } else { 128 | if (l.y() < r.y()) { 129 | leftTop.setX(r.x()); 130 | rightDown.setX(l.x()); 131 | } else { 132 | QPoint tmp; 133 | tmp = leftTop; 134 | leftTop = rightDown; 135 | rightDown = tmp; 136 | } 137 | } 138 | } 139 | 140 | 141 | frmScreen *frmScreen::_instance = 0; 142 | frmScreen::frmScreen(QWidget *parent) : QDialog(parent) 143 | { 144 | this->InitForm(); 145 | } 146 | 147 | void frmScreen::InitForm() 148 | { 149 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); 150 | 151 | menu = new QMenu(this); 152 | menu->addAction("保存截图", this, SLOT(SaveScreen())); 153 | menu->addAction("截图另存为", this, SLOT(SaveScreenOther())); 154 | menu->addAction("全屏截图", this, SLOT(SaveFullScreen())); 155 | menu->addAction("退出截图", this, SLOT(hide())); 156 | 157 | //取得屏幕大小 158 | screen = new ScreenAPI(QApplication::desktop()->size()); 159 | 160 | //保存全屏 161 | fullScreen = new QPixmap(); 162 | } 163 | 164 | void frmScreen::paintEvent(QPaintEvent *) 165 | { 166 | int x = screen->getLeftUp().x(); 167 | int y = screen->getLeftUp().y(); 168 | int w = screen->getRightDown().x() - x; 169 | int h = screen->getRightDown().y() - y; 170 | 171 | QPainter painter(this); 172 | 173 | QPen pen; 174 | pen.setColor(Qt::green); 175 | pen.setWidth(2); 176 | pen.setStyle(Qt::DotLine); 177 | painter.setPen(pen); 178 | 179 | QFont font; 180 | font.setFamily(App::FontName); 181 | font.setPointSize(App::FontSize + 2); 182 | painter.setFont(font); 183 | 184 | painter.drawPixmap(0, 0, *bgScreen); 185 | 186 | if (w != 0 && h != 0) { 187 | painter.drawPixmap(x, y, fullScreen->copy(x, y, w, h)); 188 | } 189 | 190 | painter.drawRect(x, y, w, h); 191 | 192 | pen.setColor(Qt::yellow); 193 | painter.setPen(pen); 194 | painter.drawText(x + 2, y - 8, tr("截图范围:( %1 x %2 ) - ( %3 x %4 ) 图片大小:( %5 x %6 )") 195 | .arg(x).arg(y).arg(x + w).arg(y + h).arg(w).arg(h)); 196 | } 197 | 198 | void frmScreen::showEvent(QShowEvent *) 199 | { 200 | QPoint point(-1, -1); 201 | screen->setStart(point); 202 | screen->setEnd(point); 203 | 204 | *fullScreen = QPixmap::grabWindow(QApplication::desktop()->winId(), 0, 0, screen->width(), screen->height()); 205 | 206 | //设置透明度实现模糊背景 207 | QPixmap pix(screen->width(), screen->height()); 208 | pix.fill((QColor(160, 160, 160, 200))); 209 | bgScreen = new QPixmap(*fullScreen); 210 | QPainter p(bgScreen); 211 | p.drawPixmap(0, 0, pix); 212 | } 213 | 214 | void frmScreen::SaveScreenOther() 215 | { 216 | QString fileName = QFileDialog::getSaveFileName(this, "保存图片", STRDATETIME, "JPEG Files (*.jpg)"); 217 | 218 | if (fileName.length() > 0) { 219 | int x = screen->getLeftUp().x(); 220 | int y = screen->getLeftUp().y(); 221 | int w = screen->getRightDown().x() - x; 222 | int h = screen->getRightDown().y() - y; 223 | 224 | fullScreen->copy(x, y, w, h).save(fileName, "jpg"); 225 | 226 | close(); 227 | } 228 | } 229 | 230 | void frmScreen::SaveScreen() 231 | { 232 | int x = screen->getLeftUp().x(); 233 | int y = screen->getLeftUp().y(); 234 | int w = screen->getRightDown().x() - x; 235 | int h = screen->getRightDown().y() - y; 236 | 237 | QString fileName = QString("%1/image_screen/screen_%2.jpg").arg(App::AppPath).arg(STRDATETIME); 238 | fullScreen->copy(x, y, w, h).save(fileName, "jpg"); 239 | 240 | close(); 241 | } 242 | 243 | void frmScreen::SaveFullScreen() 244 | { 245 | QString fileName = QString("%1/image_screen/full_%2.jpg").arg(App::AppPath).arg(STRDATETIME); 246 | fullScreen->save(fileName, "jpg"); 247 | 248 | close(); 249 | } 250 | 251 | void frmScreen::mouseMoveEvent(QMouseEvent *e) 252 | { 253 | if (screen->getStatus() == ScreenAPI::SELECT) { 254 | screen->setEnd(e->pos()); 255 | } else if (screen->getStatus() == ScreenAPI::MOV) { 256 | QPoint p(e->x() - movPos.x(), e->y() - movPos.y()); 257 | screen->move(p); 258 | movPos = e->pos(); 259 | } 260 | 261 | update(); 262 | } 263 | 264 | void frmScreen::mousePressEvent(QMouseEvent *e) 265 | { 266 | int status = screen->getStatus(); 267 | 268 | if (status == ScreenAPI::SELECT) { 269 | screen->setStart(e->pos()); 270 | } else if (status == ScreenAPI::MOV) { 271 | if (screen->isInArea(e->pos()) == false) { 272 | screen->setStart(e->pos()); 273 | screen->setStatus(ScreenAPI::SELECT); 274 | } else { 275 | movPos = e->pos(); 276 | this->setCursor(Qt::SizeAllCursor); 277 | } 278 | } 279 | 280 | update(); 281 | } 282 | 283 | void frmScreen::mouseReleaseEvent(QMouseEvent *) 284 | { 285 | if (screen->getStatus() == ScreenAPI::SELECT) { 286 | screen->setStatus(ScreenAPI::MOV); 287 | } else if (screen->getStatus() == ScreenAPI::MOV) { 288 | this->setCursor(Qt::ArrowCursor); 289 | } 290 | } 291 | 292 | void frmScreen::contextMenuEvent(QContextMenuEvent *) 293 | { 294 | this->setCursor(Qt::ArrowCursor); 295 | menu->exec(cursor().pos()); 296 | } 297 | -------------------------------------------------------------------------------- /api/screenapi.h: -------------------------------------------------------------------------------- 1 | #ifndef SCREENAPI_H 2 | #define SCREENAPI_H 3 | 4 | #ifndef FRMSCREEN_H 5 | #define FRMSCREEN_H 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | class ScreenAPI 15 | { 16 | public: 17 | enum STATUS {SELECT, MOV, SET_W_H}; 18 | ScreenAPI() {} 19 | ScreenAPI(QSize size); 20 | 21 | void setStart(QPoint pos); 22 | void setEnd(QPoint pos); 23 | QPoint getStart(); 24 | QPoint getEnd(); 25 | 26 | QPoint getLeftUp(); 27 | QPoint getRightDown(); 28 | 29 | STATUS getStatus(); 30 | void setStatus(STATUS status); 31 | 32 | int width(); 33 | int height(); 34 | bool isInArea(QPoint pos); // 检测pos是否在截图区域内 35 | void move(QPoint p); // 按 p 移动截图区域 36 | 37 | private: 38 | QPoint leftUpPos, rightDownPos; //记录 截图区域 左上角、右下角 39 | QPoint startPos, endPos; //记录 鼠标开始位置、结束位置 40 | int maxWidth, maxHeight; //记录屏幕大小 41 | STATUS status; //三个状态 : 选择区域、移动区域、设置width height 42 | 43 | void cmpPoint(QPoint &s, QPoint &e);//比较两位置,判断左上角、右下角 44 | }; 45 | 46 | #endif // SCREENAPI_H 47 | 48 | class frmScreen : public QDialog 49 | { 50 | Q_OBJECT 51 | 52 | public: 53 | explicit frmScreen(QWidget *parent = 0); 54 | static frmScreen *Instance() 55 | { 56 | static QMutex mutex; 57 | 58 | if (!_instance) { 59 | QMutexLocker locker(&mutex); 60 | 61 | if (!_instance) { 62 | _instance = new frmScreen; 63 | } 64 | } 65 | 66 | return _instance; 67 | } 68 | 69 | private: 70 | static frmScreen *_instance; 71 | QMenu *menu; //右键菜单对象 72 | ScreenAPI *screen; //截屏对象 73 | QPixmap *fullScreen; //保存全屏图像 74 | QPixmap *bgScreen; //模糊背景图 75 | QPoint movPos; //坐标 76 | 77 | protected: 78 | void contextMenuEvent(QContextMenuEvent *); 79 | void mousePressEvent(QMouseEvent *); 80 | void mouseMoveEvent(QMouseEvent *); 81 | void mouseReleaseEvent(QMouseEvent *); 82 | void paintEvent(QPaintEvent *); 83 | void showEvent(QShowEvent *); 84 | 85 | private slots: 86 | void InitForm(); 87 | void SaveScreen(); 88 | void SaveScreenOther(); 89 | void SaveFullScreen(); 90 | 91 | }; 92 | 93 | #endif // FRMSCREEN_H 94 | 95 | -------------------------------------------------------------------------------- /api/sendemailthread.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | #include "sendemailthread.h" 5 | #include "myhelper.h" 6 | #include "api.h" 7 | #include "dbhelper.h" 8 | #include "qemail/smtpmime.h" 9 | 10 | SendEmailThread::SendEmailThread(QObject *parent) : QThread(parent) 11 | { 12 | content = ""; 13 | headMsg = "端口:邮件端口"; 14 | } 15 | 16 | void SendEmailThread::SetContent(QString content) 17 | { 18 | this->content = content; 19 | } 20 | 21 | void SendEmailThread::SetFileName(QString fileName) 22 | { 23 | this->fileName = fileName; 24 | } 25 | 26 | void SendEmailThread::run() 27 | { 28 | QString str; 29 | 30 | //发送告警邮件 31 | //实例化发送邮件对象 32 | QStringList list = App::SendEmailAddr.split("@"); 33 | if (list.count() < 2) { 34 | str = "发件人邮箱格式错误"; 35 | } else { 36 | QString tempSMTP = list.at(1).split(".").at(0); 37 | int tempPort = 25; 38 | //QQ邮箱端口号为465,必须启用SSL协议. 39 | if (tempSMTP.toUpper() == "QQ") { 40 | tempPort = 465; 41 | } 42 | 43 | SmtpClient smtp(QString("smtp.%1.com").arg(tempSMTP), tempPort, 44 | tempPort == 25 ? SmtpClient::TcpConnection : SmtpClient::SslConnection); 45 | 46 | smtp.setUser(App::SendEmailAddr); 47 | smtp.setPassword(App::SendEmailPwd); 48 | 49 | //构建邮件主题,包含发件人收件人附件等. 50 | MimeMessage message; 51 | message.setSender(new EmailAddress(App::SendEmailAddr)); 52 | 53 | //逐个添加收件人 54 | QStringList receiver = App::EmailAddr.split(';'); 55 | for (int i = 0; i < receiver.size(); i++) { 56 | message.addRecipient(new EmailAddress(receiver.at(i))); 57 | } 58 | 59 | //构建邮件标题 60 | message.setSubject(App::Title + "告警邮件"); 61 | 62 | //构建邮件正文 63 | MimeHtml text; 64 | text.setHtml(content); 65 | message.addPart(&text); 66 | 67 | //构建附件-告警图像 68 | if (fileName.length() > 0) { 69 | QStringList attas = fileName.split(";"); 70 | foreach (QString tempAtta, attas) { 71 | QFile *file = new QFile(tempAtta); 72 | if (file->exists()) { 73 | message.addPart(new MimeAttachment(file)); 74 | } 75 | } 76 | } 77 | 78 | if (!smtp.connectToHost()) { 79 | str = "邮件服务器连接失败"; 80 | } else { 81 | if (!smtp.login()) { 82 | str = "邮件用户登录失败"; 83 | } else { 84 | if (!smtp.sendMail(message)) { 85 | str = "告警邮件发送失败"; 86 | } else { 87 | str = "告警邮件发送成功"; 88 | } 89 | } 90 | } 91 | 92 | smtp.quit(); 93 | } 94 | 95 | qDebug() << TIME << headMsg << "命令解析:" << str; 96 | API::AddMessage(str); 97 | DBHelper::AddEventInfoUser(str); 98 | } 99 | -------------------------------------------------------------------------------- /api/sendemailthread.h: -------------------------------------------------------------------------------- 1 | #ifndef SENDEMAILTHREAD_H 2 | #define SENDEMAILTHREAD_H 3 | 4 | #include 5 | 6 | class SendEmailThread : public QThread 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit SendEmailThread(QObject *parent = 0); 11 | 12 | void SetContent(QString content); 13 | void SetFileName(QString fileName); 14 | 15 | protected: 16 | void run(); 17 | 18 | private: 19 | QString content; //告警邮件内容 20 | QString fileName; //附件-告警图像 21 | QString headMsg; //打印消息头部内容 22 | 23 | signals: 24 | 25 | public slots: 26 | }; 27 | 28 | #endif // SENDEMAILTHREAD_H 29 | -------------------------------------------------------------------------------- /api/sendmsgthread.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "sendmsgthread.h" 6 | #include "myhelper.h" 7 | #include "api.h" 8 | #include "dbhelper.h" 9 | 10 | SendMsgThread::SendMsgThread(QObject *parent) : QThread(parent) 11 | { 12 | gsm = 0; 13 | tel = "18001797656"; 14 | msg = "hello"; 15 | headMsg = "端口:短信端口"; 16 | } 17 | 18 | void SendMsgThread::SetPar(GSMAPI *gsm, QString tel, QString msg) 19 | { 20 | this->gsm = gsm; 21 | this->tel = tel; 22 | this->msg = msg; 23 | } 24 | 25 | void SendMsgThread::run() 26 | { 27 | QString str; 28 | 29 | if (gsm->Islive()) { 30 | str = "告警短信发送失败"; 31 | char ctrlz = 26; 32 | QString msgContent = QString("%1%2%3%4%5") 33 | .arg("0011000D91") 34 | .arg(getTel(tel)) 35 | .arg("000801") 36 | .arg(getMsgHex(msg)) 37 | .arg(ctrlz); 38 | int len = getMsgLen(msg); 39 | 40 | //首先进入发送短信状态 41 | QString result = gsm->SendAT(QString("AT+CMGS=%1\r").arg(len), 300); 42 | 43 | //返回结果最末一位为 > 后输入短信内容编码 44 | if (result.right(1) == ">") { 45 | //发送短信正文 46 | result = gsm->SendAT(msgContent, 8000); 47 | if (result.right(2) == "OK") { 48 | str = "告警短信发送成功"; 49 | } 50 | } 51 | } else { 52 | str = "短信猫通讯故障"; 53 | } 54 | 55 | qDebug() << TIME << headMsg << "命令解析:" << str; 56 | API::AddMessage(str); 57 | DBHelper::AddEventInfoUser(str); 58 | } 59 | 60 | int SendMsgThread::getMsgLen(QString msg) 61 | { 62 | int len = msg.length() * 2; 63 | len += 15; 64 | return len; 65 | } 66 | 67 | QString SendMsgThread::getTel(QString tel) 68 | { 69 | QString temp = ""; 70 | //检查手机号码是否按照标准格式写,如果不是则补上 71 | if (tel.mid(0, 2) != "86") { 72 | temp = QString("86%1F").arg(tel); 73 | } 74 | 75 | QByteArray ba = temp.toLatin1(); 76 | QString str = ""; 77 | //按照内存编码格式,将每两位的顺序调换 78 | for (int i = 0; i < 13; i = i + 2) { 79 | str += QString("%1%2").arg(ba[i + 1]).arg(ba[i]); 80 | } 81 | return str; 82 | } 83 | 84 | QString SendMsgThread::getMsgHex(QString msg) 85 | { 86 | int len = msg.length(); 87 | wchar_t *buffer = new wchar_t[len]; 88 | msg.toWCharArray((wchar_t *)buffer); 89 | 90 | QStringList data; 91 | for (int i = 0; i < len; i++) { 92 | QString temp = QString::number(buffer[i], 16); 93 | if (temp.length() == 2) { 94 | temp = "00" + temp; 95 | } 96 | data.append(temp); 97 | } 98 | //将长度及短信内容的unicode编码格式内容拼接 99 | QString str = QString("%1%2") 100 | .arg(QString::number(len * 2, 16).toUpper()) 101 | .arg(data.join("").toUpper()); 102 | 103 | delete [] buffer; 104 | return str; 105 | } 106 | 107 | QString SendMsgThread::unicodeToTel(QString unicode) 108 | { 109 | QString tel = ""; 110 | //按照内存编码格式,将每两位的顺序调换 111 | for (int i = 0; i < 12; i = i + 2) { 112 | tel += QString("%1%2").arg(unicode[i + 1]).arg(unicode[i]); 113 | } 114 | //去除最后一位 F 115 | tel = tel.remove("F"); 116 | return tel; 117 | } 118 | 119 | QString SendMsgThread::unicodeToTime(QString unicode) 120 | { 121 | QString time = ""; 122 | //按照内存编码格式,将每两位的顺序调换 123 | for (int i = 0; i < 12; i = i + 2) { 124 | time += QString("%1%2").arg(unicode[i + 1]).arg(unicode[i]); 125 | } 126 | time = QString("20%1-%2-%3 %4:%5:%6") 127 | .arg(time.mid(0, 2)) 128 | .arg(time.mid(2, 2)) 129 | .arg(time.mid(4, 2)) 130 | .arg(time.mid(6, 2)) 131 | .arg(time.mid(8, 2)) 132 | .arg(time.mid(10, 2)); 133 | return time; 134 | } 135 | 136 | QString SendMsgThread::unicodeToMsg(QString unicode) 137 | { 138 | QString msg = ""; 139 | QTextCodec *codec = QTextCodec::codecForName("utf-8"); 140 | 141 | QStringList str; 142 | for(int i = 0; i < unicode.length(); i = i + 4) { 143 | str.append(unicode.mid(i, 4)); 144 | } 145 | 146 | QString s; 147 | foreach (const QString & unicode, str) { 148 | s.append(unicode.toUShort(0, 16)); 149 | } 150 | 151 | msg = codec->fromUnicode(s); 152 | return msg; 153 | } 154 | -------------------------------------------------------------------------------- /api/sendmsgthread.h: -------------------------------------------------------------------------------- 1 | #ifndef SENDMSGTHREAD_H 2 | #define SENDMSGTHREAD_H 3 | 4 | #include 5 | #include "gsmapi.h" 6 | 7 | class SendMsgThread : public QThread 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SendMsgThread(QObject *parent = 0); 12 | 13 | void SetPar(GSMAPI *gsm, QString tel, QString msg); 14 | 15 | protected: 16 | void run(); 17 | 18 | private: 19 | GSMAPI *gsm; 20 | QString tel; 21 | QString msg; 22 | QString headMsg; //打印消息头部内容 23 | 24 | QString getTel(QString tel); //获取手机号码(内存编码) 25 | int getMsgLen(QString msg); //获取短信内容长度 26 | QString getMsgHex(QString msg); //获取汉字16进制格式表示 27 | 28 | QString unicodeToTel(QString unicode); //unicode编码转为号码字符串 29 | QString unicodeToTime(QString unicode); //unicode编码转为时间字符串 30 | QString unicodeToMsg(QString unicode); //unicode编码转为中文字符串 31 | 32 | signals: 33 | 34 | public slots: 35 | }; 36 | 37 | #endif // SENDMSGTHREAD_H 38 | -------------------------------------------------------------------------------- /api/showcpumemory.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "showcpumemory.h" 6 | #include "myhelper.h" 7 | 8 | #ifdef Q_OS_WIN 9 | #ifndef _WIN32_WINNT 10 | #define _WIN32_WINNT 0x502 11 | #endif 12 | #include "windows.h" 13 | #endif 14 | #define MB (1024 * 1024) 15 | #define KB (1024) 16 | 17 | ShowCPUMemory::ShowCPUMemory(QObject *parent) : QObject(parent) 18 | { 19 | totalNew = idleNew = totalOld = idleOld = 0; 20 | cpuPercent = 0; 21 | 22 | memoryPercent = 0; 23 | memoryAll = 0; 24 | memoryUse = 0; 25 | labCPUMemory = 0; 26 | 27 | timerCPU = new QTimer(this); 28 | connect(timerCPU, SIGNAL(timeout()), this, SLOT(GetCPU())); 29 | 30 | timerMemory = new QTimer(this); 31 | connect(timerMemory, SIGNAL(timeout()), this, SLOT(GetMemory())); 32 | 33 | process = new QProcess(this); 34 | connect(process, SIGNAL(readyRead()), this, SLOT(ReadData())); 35 | } 36 | 37 | void ShowCPUMemory::SetLab(QLabel *labCPUMemory) 38 | { 39 | this->labCPUMemory = labCPUMemory; 40 | GetCPU(); 41 | myHelper::Sleep(200); 42 | GetMemory(); 43 | } 44 | 45 | void ShowCPUMemory::Start(int interval) 46 | { 47 | timerCPU->start(interval); 48 | timerMemory->start(interval + 200); 49 | } 50 | 51 | void ShowCPUMemory::Stop() 52 | { 53 | timerCPU->stop(); 54 | timerMemory->stop(); 55 | } 56 | 57 | void ShowCPUMemory::GetCPU() 58 | { 59 | #ifdef Q_OS_WIN 60 | static FILETIME preidleTime; 61 | static FILETIME prekernelTime; 62 | static FILETIME preuserTime; 63 | 64 | FILETIME idleTime; 65 | FILETIME kernelTime; 66 | FILETIME userTime; 67 | 68 | GetSystemTimes(&idleTime, &kernelTime, &userTime); 69 | 70 | quint64 a, b; 71 | int idle, kernel, user; 72 | 73 | a = (preidleTime.dwHighDateTime << 31) | preidleTime.dwLowDateTime; 74 | b = (idleTime.dwHighDateTime << 31) | idleTime.dwLowDateTime; 75 | idle = b - a; 76 | 77 | a = (prekernelTime.dwHighDateTime << 31) | prekernelTime.dwLowDateTime; 78 | b = (kernelTime.dwHighDateTime << 31) | kernelTime.dwLowDateTime; 79 | kernel = b - a; 80 | 81 | a = (preuserTime.dwHighDateTime << 31) | preuserTime.dwLowDateTime; 82 | b = (userTime.dwHighDateTime << 31) | userTime.dwLowDateTime; 83 | user = b - a; 84 | 85 | cpuPercent = (kernel + user - idle) * 100 / (kernel + user); 86 | 87 | preidleTime = idleTime; 88 | prekernelTime = kernelTime; 89 | preuserTime = userTime ; 90 | 91 | QString msg = QString("CPU : %1% 内存 : %2% ( 已用 %3 MB / 共 %4 MB )") 92 | .arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll); 93 | labCPUMemory->setText(msg); 94 | #else 95 | 96 | if (process->state() == QProcess::NotRunning) { 97 | totalNew = idleNew = 0; 98 | process->start("cat /proc/stat"); 99 | } 100 | 101 | #endif 102 | } 103 | 104 | void ShowCPUMemory::GetMemory() 105 | { 106 | #ifdef Q_OS_WIN 107 | #if (QT_VERSION >= QT_VERSION_CHECK(4,8,7)) 108 | MEMORYSTATUSEX statex; 109 | statex.dwLength = sizeof(statex); 110 | GlobalMemoryStatusEx(&statex); 111 | memoryPercent = statex.dwMemoryLoad; 112 | memoryAll = statex.ullTotalPhys / MB; 113 | memoryFree = statex.ullAvailPhys / MB; 114 | memoryUse = memoryAll - memoryFree; 115 | 116 | QString msg = QString("CPU : %1% 内存 : %2% ( 已用 %3 MB / 共 %4 MB )") 117 | .arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll); 118 | labCPUMemory->setText(msg); 119 | 120 | if (memoryPercent > 80) { 121 | App::WriteError("Memory High"); 122 | } 123 | 124 | #endif 125 | #else 126 | 127 | if (process->state() == QProcess::NotRunning) { 128 | process->start("cat /proc/meminfo"); 129 | } 130 | 131 | #endif 132 | } 133 | 134 | void ShowCPUMemory::ReadData() 135 | { 136 | while (!process->atEnd()) { 137 | QString s = QLatin1String(process->readLine()); 138 | 139 | if (s.startsWith("cpu")) { 140 | QStringList list = s.split(" "); 141 | idleNew = list.at(5).toInt(); 142 | 143 | foreach (QString value, list) { 144 | totalNew += value.toInt(); 145 | } 146 | 147 | int total = totalNew - totalOld; 148 | int idle = idleNew - idleOld; 149 | cpuPercent = 100 * (total - idle) / total; 150 | totalOld = totalNew; 151 | idleOld = idleNew; 152 | break; 153 | } else if (s.startsWith("MemTotal")) { 154 | s = s.replace(" ", ""); 155 | s = s.split(":").at(1); 156 | memoryAll = s.left(s.length() - 3).toInt() / KB; 157 | } else if (s.startsWith("MemFree")) { 158 | s = s.replace(" ", ""); 159 | s = s.split(":").at(1); 160 | memoryFree = s.left(s.length() - 3).toInt() / KB; 161 | } else if (s.startsWith("Buffers")) { 162 | s = s.replace(" ", ""); 163 | s = s.split(":").at(1); 164 | memoryFree += s.left(s.length() - 3).toInt() / KB; 165 | } else if (s.startsWith("Cached")) { 166 | s = s.replace(" ", ""); 167 | s = s.split(":").at(1); 168 | memoryFree += s.left(s.length() - 3).toInt() / KB; 169 | memoryUse = memoryAll - memoryFree; 170 | memoryPercent = 100 * memoryUse / memoryAll; 171 | break; 172 | } 173 | } 174 | 175 | QString msg = QString("CPU : %1% 内存 : %2% ( 已用 %3 MB / 共 %4 MB )") 176 | .arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll); 177 | labCPUMemory->setText(msg); 178 | 179 | if (memoryPercent > 80) { 180 | App::WriteError("Memory High"); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /api/showcpumemory.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWCPUMEMORY_H 2 | #define SHOWCPUMEMORY_H 3 | 4 | #include 5 | 6 | class QLabel; 7 | class QTimer; 8 | class QProcess; 9 | 10 | class ShowCPUMemory : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit ShowCPUMemory(QObject *parent = 0); 15 | 16 | void SetLab(QLabel *labCPUMemory); 17 | void Start(int interval); 18 | void Stop(); 19 | 20 | private: 21 | int totalNew, idleNew, totalOld, idleOld; 22 | int cpuPercent; 23 | 24 | int memoryPercent; 25 | int memoryAll; 26 | int memoryUse; 27 | int memoryFree; 28 | 29 | QTimer *timerCPU; //定时器获取CPU信息 30 | QTimer *timerMemory; //定时器获取内存信息 31 | QLabel *labCPUMemory; //显示CPU内存信息的控件 32 | QProcess *process; 33 | 34 | private slots: 35 | void GetCPU(); 36 | void GetMemory(); 37 | void ReadData(); 38 | 39 | signals: 40 | 41 | public slots: 42 | }; 43 | 44 | #endif // SHOWCPUMEMORY_H 45 | -------------------------------------------------------------------------------- /api/showdatetime.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "showdatetime.h" 6 | #include "myhelper.h" 7 | 8 | ShowDateTime::ShowDateTime(QObject *parent) : QObject(parent) 9 | { 10 | labDateTime = 0; 11 | labLive = 0; 12 | lcdNumber = 0; 13 | 14 | day = 0; 15 | hour = 0; 16 | minute = 0; 17 | seconds = 0; 18 | 19 | timer = new QTimer(this); 20 | connect(timer, SIGNAL(timeout()), this, SLOT(ShowTime())); 21 | } 22 | 23 | ShowDateTime::~ShowDateTime() 24 | { 25 | 26 | } 27 | 28 | void ShowDateTime::SetLab(QLabel *labDateTime, QLabel *labLive) 29 | { 30 | this->labDateTime = labDateTime; 31 | this->labLive = labLive; 32 | this->SetTimeInfo(); 33 | } 34 | 35 | void ShowDateTime::SetLcdNumber(QLCDNumber *lcdNumber) 36 | { 37 | this->lcdNumber = lcdNumber; 38 | this->SetTimeInfo(); 39 | } 40 | 41 | void ShowDateTime::Start(int interval) 42 | { 43 | timer->start(interval); 44 | } 45 | 46 | void ShowDateTime::Stop() 47 | { 48 | timer->stop(); 49 | } 50 | 51 | void ShowDateTime::ShowTime() 52 | { 53 | seconds++; 54 | 55 | if (seconds == 60) { 56 | minute++; 57 | seconds = 0; 58 | } 59 | 60 | if (minute == 60) { 61 | hour++; 62 | minute = 0; 63 | } 64 | 65 | if (hour == 24) { 66 | day++; 67 | hour = 0; 68 | } 69 | 70 | SetTimeInfo(); 71 | } 72 | 73 | void ShowDateTime::SetTimeInfo() 74 | { 75 | QDateTime now = QDateTime::currentDateTime(); 76 | this->labLive->setText(QString("已运行: %1天%2时%3分%4秒").arg(day).arg(hour).arg(minute).arg(seconds)); 77 | this->labDateTime->setText(now.toString("当前时间: yyyy年MM月dd日 HH:mm:ss")); 78 | 79 | if (lcdNumber != 0) { 80 | lcdNumber->display(now.toString("yyyy-MM-dd hh:mm:ss")); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /api/showdatetime.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWDATETIME_H 2 | #define SHOWDATETIME_H 3 | 4 | #include 5 | 6 | class QLabel; 7 | class QLCDNumber; 8 | class QTimer; 9 | 10 | class ShowDateTime : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit ShowDateTime(QObject *parent = 0); 15 | ~ShowDateTime(); 16 | 17 | void SetLab(QLabel *labDateTime, QLabel *labLive); 18 | void SetLcdNumber(QLCDNumber *lcdNumber); 19 | void Start(int interval); 20 | void Stop(); 21 | 22 | private: 23 | int day; //天数 24 | int hour; //时钟数 25 | int minute; //分钟数 26 | int seconds; //秒钟数 27 | QTimer *timer; //定时器获取时间 28 | QLabel *labDateTime; //显示日期时间的载体 29 | QLabel *labLive; //显示已运行 30 | QLCDNumber *lcdNumber; //显示日期时间的LCD控件 31 | 32 | private slots: 33 | void SetTimeInfo(); 34 | void ShowTime(); 35 | 36 | signals: 37 | 38 | public slots: 39 | }; 40 | 41 | #endif // SHOWDATETIME_H 42 | -------------------------------------------------------------------------------- /api/showdevicesize.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "showdevicesize.h" 6 | #include "myhelper.h" 7 | 8 | #ifdef Q_OS_WIN 9 | #include "windows.h" 10 | #endif 11 | #define GB (1024 * 1024 * 1024) 12 | #define MB (1024 * 1024) 13 | #define KB (1024) 14 | 15 | ShowDeviceSize *ShowDeviceSize::_instance = 0; 16 | ShowDeviceSize::ShowDeviceSize(QObject *parent) : QObject(parent) 17 | { 18 | process = new QProcess(this); 19 | connect(process, SIGNAL(readyRead()), this, SLOT(ReadData())); 20 | } 21 | 22 | void ShowDeviceSize::SetTableWidget(QTableWidget *tableWidget) 23 | { 24 | this->tableWidget = tableWidget; 25 | this->tableWidget->clear(); 26 | 27 | //设置列数和列宽 28 | this->tableWidget->setColumnCount(5); 29 | this->tableWidget->setColumnWidth(0, 100); 30 | this->tableWidget->setColumnWidth(1, 100); 31 | this->tableWidget->setColumnWidth(2, 100); 32 | this->tableWidget->setColumnWidth(3, 100); 33 | this->tableWidget->setColumnWidth(4, 150); 34 | 35 | this->tableWidget->setStyleSheet("QTableWidget::item{padding:0px;}"); 36 | 37 | QStringList headText; 38 | headText << "盘符" << "已用空间" << "可用空间" << "总大小" << "已用百分比" ; 39 | this->tableWidget->setHorizontalHeaderLabels(headText); 40 | this->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); 41 | this->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); 42 | this->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); 43 | this->tableWidget->verticalHeader()->setVisible(true); 44 | this->tableWidget->horizontalHeader()->setStretchLastSection(true); 45 | } 46 | 47 | void ShowDeviceSize::Load() 48 | { 49 | //清空原有数据 50 | int row = this->tableWidget->rowCount(); 51 | 52 | for (int i = 0; i < row; i++) { 53 | this->tableWidget->removeRow(0); 54 | } 55 | 56 | #ifdef Q_OS_WIN 57 | QFileInfoList list = QDir::drives(); 58 | 59 | foreach (QFileInfo dir, list) { 60 | QString dirName = dir.absolutePath(); 61 | LPCWSTR lpcwstrDriver = (LPCWSTR)dirName.utf16(); 62 | ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes; 63 | 64 | if (GetDiskFreeSpaceEx(lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes)) { 65 | QString use = QString::number((double)(liTotalBytes.QuadPart - liTotalFreeBytes.QuadPart) / GB, 'f', 1); 66 | use += "G"; 67 | QString free = QString::number((double) liTotalFreeBytes.QuadPart / GB, 'f', 1); 68 | free += "G"; 69 | QString all = QString::number((double) liTotalBytes.QuadPart / GB, 'f', 1); 70 | all += "G"; 71 | int percent = 100 - ((double)liTotalFreeBytes.QuadPart / liTotalBytes.QuadPart) * 100; 72 | 73 | InsertSize(dirName, use, free, all, percent); 74 | } 75 | } 76 | 77 | #else 78 | process->start("df -h"); 79 | #endif 80 | } 81 | 82 | void ShowDeviceSize::ReadData() 83 | { 84 | while (!process->atEnd()) { 85 | QString result = QLatin1String(process->readLine()); 86 | #ifdef __arm__ 87 | 88 | if (result.startsWith("/dev/root")) { 89 | CheckSize(result, "本地存储"); 90 | } else if (result.startsWith("/dev/mmcblk1p1")) { 91 | CheckSize(result, "SD卡"); 92 | } else if (result.startsWith("/dev/sda1")) { 93 | CheckSize(result, "U盘"); 94 | } 95 | 96 | #else 97 | 98 | if (result.startsWith("/dev/sda")) { 99 | CheckSize(result, ""); 100 | } 101 | 102 | #endif 103 | } 104 | } 105 | 106 | void ShowDeviceSize::CheckSize(QString result, QString name) 107 | { 108 | QString dev, use, free, all; 109 | int percent = 0; 110 | QStringList list = result.split(" "); 111 | int index = 0; 112 | 113 | for (int i = 0; i < list.count(); i++) { 114 | QString s = list.at(i).trimmed(); 115 | 116 | if (s == "") { 117 | continue; 118 | } 119 | 120 | index++; 121 | 122 | if (index == 1) { 123 | dev = s; 124 | } else if (index == 2) { 125 | all = s; 126 | } else if (index == 3) { 127 | use = s; 128 | } else if (index == 4) { 129 | free = s; 130 | } else if (index == 5) { 131 | percent = s.left(s.length() - 1).toInt(); 132 | break; 133 | } 134 | } 135 | 136 | if (name.length() > 0) { 137 | dev = name; 138 | } 139 | 140 | InsertSize(dev, use, free, all, percent); 141 | } 142 | 143 | void ShowDeviceSize::InsertSize(QString name, QString use, QString free, QString all, int percent) 144 | { 145 | int row = this->tableWidget->rowCount(); 146 | this->tableWidget->insertRow(row); 147 | this->tableWidget->setRowHeight(row, 28); 148 | 149 | QTableWidgetItem *itemname = new QTableWidgetItem(name); 150 | QTableWidgetItem *itemuse = new QTableWidgetItem(use); 151 | itemuse->setTextAlignment(Qt::AlignCenter); 152 | QTableWidgetItem *itemfree = new QTableWidgetItem(free); 153 | itemfree->setTextAlignment(Qt::AlignCenter); 154 | QTableWidgetItem *itemall = new QTableWidgetItem(all); 155 | itemall->setTextAlignment(Qt::AlignCenter); 156 | 157 | this->tableWidget->setItem(row, 0, itemname); 158 | this->tableWidget->setItem(row, 1, itemuse); 159 | this->tableWidget->setItem(row, 2, itemfree); 160 | this->tableWidget->setItem(row, 3, itemall); 161 | 162 | QProgressBar *bar = new QProgressBar; 163 | bar->setRange(0, 100); 164 | bar->setValue(percent); 165 | 166 | QString qss; 167 | 168 | if (percent < 50) { 169 | qss = "QProgressBar{border-width:0px;border-radius:0px;color:#000000;}" 170 | "QProgressBar::chunk{background:rgb(60, 140, 220);}"; 171 | } else if (percent < 90) { 172 | qss = "QProgressBar{border-width:0px;border-radius:0px;color:#FFFFFF;}" 173 | "QProgressBar::chunk{background:rgb(60, 140, 220);}"; 174 | } else { 175 | qss = "QProgressBar{border-width:0px;border-radius:0px;color:#FFFFFF;}" 176 | "QProgressBar::chunk{background:rgb(215, 19, 69);}"; 177 | } 178 | 179 | bar->setStyleSheet(qss); 180 | this->tableWidget->setCellWidget(row, 4, bar); 181 | } 182 | -------------------------------------------------------------------------------- /api/showdevicesize.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWDEVICESIZE_H 2 | #define SHOWDEVICESIZE_H 3 | 4 | #include 5 | #include 6 | 7 | class QTableWidget; 8 | class QProcess; 9 | 10 | class ShowDeviceSize : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit ShowDeviceSize(QObject *parent = 0); 15 | static ShowDeviceSize *Instance() 16 | { 17 | static QMutex mutex; 18 | 19 | if (!_instance) { 20 | QMutexLocker locker(&mutex); 21 | 22 | if (!_instance) { 23 | _instance = new ShowDeviceSize; 24 | } 25 | } 26 | 27 | return _instance; 28 | } 29 | 30 | void SetTableWidget(QTableWidget *tableWidget); 31 | void Load(); 32 | 33 | private: 34 | static ShowDeviceSize *_instance; 35 | QTableWidget *tableWidget; 36 | QProcess *process; 37 | 38 | private slots: 39 | void ReadData(); 40 | void CheckSize(QString result, QString name); 41 | void InsertSize(QString name, QString use, QString free, QString all, int percent); 42 | 43 | signals: 44 | 45 | public slots: 46 | }; 47 | 48 | #endif // SHOWDEVICESIZE_H 49 | -------------------------------------------------------------------------------- /api/vista128_com.h: -------------------------------------------------------------------------------- 1 | #ifndef VISTA128_COM_H 2 | #define VISTA128_COM_H 3 | 4 | #include 5 | #include "qextserialport/qextserialport.h" 6 | #include 7 | #include 8 | 9 | class VISTA128_COM : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit VISTA128_COM(QObject *parent = 0); 14 | 15 | //设置和获取主机类型 16 | void SetHostType(QString hostType) { 17 | this->hostType = hostType; 18 | } 19 | QString HostType()const { 20 | return hostType; 21 | } 22 | 23 | //设置和获取主机ID 24 | void SetHostID(QString hostID) { 25 | this->hostID = hostID; 26 | } 27 | QString HostID()const { 28 | return hostID; 29 | } 30 | 31 | //设置和获取主机名称 32 | void SetHostName(QString hostName) { 33 | this->hostName = hostName; 34 | } 35 | QString HostName()const { 36 | return hostName; 37 | } 38 | 39 | //设置和获取主机通讯参数1 40 | void SetHostConnectValue1(QString hostConnectValue1) { 41 | this->hostConnectValue1 = hostConnectValue1; 42 | } 43 | QString HostConnectValue1()const { 44 | return hostConnectValue1; 45 | } 46 | 47 | //设置和获取主机通讯参数2 48 | void SetHostConnectValue2(QString hostConnectValue2) { 49 | this->hostConnectValue2 = hostConnectValue2; 50 | } 51 | QString HostConnectValue2()const { 52 | return hostConnectValue2; 53 | } 54 | 55 | bool Open(); 56 | bool IsOpen()const { 57 | return isOpen; 58 | } 59 | void Close(); 60 | 61 | void BuFang(int subSystem); 62 | void CheFang(int subSystem); 63 | 64 | void PangLu(QString defenceID); 65 | void HuiFu(QString defenceID); 66 | QString GetCode(QString defenceID); 67 | 68 | private: 69 | QextSerialPort *hostCOM; 70 | 71 | QTimer *timerHeart; //定时器发送询问心跳 72 | QTimer *timerStatus; //定时器发送询问状态 73 | 74 | bool isOpen; //打开状态 75 | bool isOnLine; //在线状态,初始值为假 76 | bool isCheckOnline; //检测下线状态,初始值为真 77 | QDateTime lastHeartTime; //存储最后一次心跳时间 78 | QTimer *timerOnLine; //定时器检测主机上线 79 | 80 | QString hostType; //主机类型 81 | QString hostID; //主机编号 82 | QString hostName; //主机名称 83 | QString hostConnectValue1; //主机参数1 84 | QString hostConnectValue2; //主机参数2 85 | 86 | bool subSystemError[8]; 87 | bool subSystemBuFang[8]; 88 | 89 | private slots: 90 | void ReadData(); //读取数据槽函数 91 | void CheckOnLine(); //检测在线状态槽函数 92 | void SendHeartData(); //发送询问心跳命令 93 | void SendStatusData(); //发送询问防区状态命令 94 | 95 | signals: 96 | void HostConnect(QString hostID, QString hostName); //主机上线 97 | void HostDisConnect(QString hostID, QString hostName); //主机下线 98 | void HostError(QString hostID, QString hostName, QString error); //主机错误,例如电池掉电 99 | void HostBuFangSubSystem(QString hostID, QString hostName, int subSystem); //主机子系统布防 100 | void HostCheFangSubSystem(QString hostID, QString hostName, int subSystem); //主机子系统撤防 101 | void DefenceBaoJing(QString hostID, QString hostName, QString defenceID); //防区报警 102 | void DefencePangLu(QString hostID, QString hostName, QString defenceID); //防区旁路 103 | void DefenceGuZhang(QString hostID, QString hostName, QString defenceID); //防区故障 104 | void DefenceHuiFu(QString hostID, QString hostName, QString defenceID); //防区恢复 105 | 106 | void HostReceiveData(QString hostID, QString hostName, QString data); //主机收到数据信号 107 | void HostHeart(QString hostID, QString hostName); //主机心跳信号 108 | void DefenceStatus(QString hostID, QString hostName); //所有防区状态信号 109 | 110 | public slots: 111 | 112 | }; 113 | 114 | #endif // VISTA128_COM_H 115 | -------------------------------------------------------------------------------- /frmabout.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmabout.h" 6 | #include "ui_frmabout.h" 7 | #include "api/myhelper.h" 8 | 9 | frmAbout::frmAbout(QWidget *parent) : 10 | QDialog(parent), 11 | ui(new Ui::frmAbout) 12 | { 13 | ui->setupUi(this); 14 | this->InitForm(); 15 | myHelper::FormInCenter(this); 16 | } 17 | 18 | frmAbout::~frmAbout() 19 | { 20 | delete ui; 21 | } 22 | 23 | void frmAbout::InitForm() 24 | { 25 | ui->labTitle->setText(App::Title); 26 | ui->lab_Title->setText(QString("关于%1").arg(App::Title)); 27 | ui->labVesion->setText(QString("版本 : %1").arg(App::Version)); 28 | ui->labHttp->setText("" 29 | "网址 : http://www.ecan-system.com"); 30 | ui->labAuthor->setText(QString("版权 : %1").arg(App::Author)); 31 | 32 | this->setProperty("CanMove", true); 33 | this->setWindowTitle(ui->lab_Title->text()); 34 | this->setAttribute(Qt::WA_TranslucentBackground); 35 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); 36 | IconHelper::Instance()->SetIcoMain(ui->lab_Ico, 15); 37 | IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close); 38 | connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close())); 39 | } 40 | -------------------------------------------------------------------------------- /frmabout.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMABOUT_H 2 | #define FRMABOUT_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmAbout; 9 | } 10 | 11 | class frmAbout : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmAbout(QWidget *parent = 0); 17 | ~frmAbout(); 18 | 19 | private: 20 | Ui::frmAbout *ui; 21 | 22 | void InitForm(); 23 | 24 | }; 25 | 26 | #endif // FRMABOUT_H 27 | -------------------------------------------------------------------------------- /frmabout.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | frmAbout 4 | 5 | 6 | 7 | 0 8 | 0 9 | 724 10 | 293 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 34 | 35 | QWidget#widget_about{ 36 | border:0px solid #FF0000; 37 | border-radius:5px; 38 | background-image: url(:/banner/about.png); 39 | } 40 | QLabel,QPushButton{ 41 | color: rgb(255, 255, 255); 42 | border-radius:5px; 43 | } 44 | 45 | 46 | 47 | 48 | 50 49 | 9 50 | 281 51 | 31 52 | 53 | 54 | 55 | font: 75 italic; 56 | 57 | 58 | 关于 59 | 60 | 61 | 62 | 63 | 64 | 52 65 | 155 66 | 301 67 | 31 68 | 69 | 70 | 71 | 网址 : http://www.ecan-system.com 72 | 73 | 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 52 81 | 60 82 | 401 83 | 51 84 | 85 | 86 | 87 | font: 20pt; 88 | 89 | 90 | 组合认证及报警管理系统 91 | 92 | 93 | 94 | 95 | 96 | 52 97 | 190 98 | 301 99 | 31 100 | 101 | 102 | 103 | 版权 : 上海宝学电子信息技术有限公司 104 | 105 | 106 | 107 | 108 | 109 | 12 110 | 9 111 | 31 112 | 30 113 | 114 | 115 | 116 | 117 | 0 118 | 0 119 | 120 | 121 | 122 | 123 | 31 124 | 0 125 | 126 | 127 | 128 | 129 | 130 | 131 | Qt::AlignCenter 132 | 133 | 134 | 135 | 136 | 137 | 52 138 | 120 139 | 301 140 | 31 141 | 142 | 143 | 144 | 版本 : V1.0 145 | 146 | 147 | 148 | 149 | 150 | 689 151 | 2 152 | 33 153 | 30 154 | 155 | 156 | 157 | 158 | 0 159 | 0 160 | 161 | 162 | 163 | ArrowCursor 164 | 165 | 166 | Qt::NoFocus 167 | 168 | 169 | 关闭 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | true 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /frmalarm.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMALARM_H 2 | #define FRMALARM_H 3 | 4 | #include 5 | 6 | class QListWidgetItem; 7 | class QTreeWidgetItem; 8 | class QMenu; 9 | class QModelIndex; 10 | 11 | namespace Ui 12 | { 13 | class frmAlarm; 14 | } 15 | 16 | class frmAlarm : public QWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit frmAlarm(QWidget *parent = 0); 22 | ~frmAlarm(); 23 | 24 | protected: 25 | bool eventFilter(QObject *obj, QEvent *event); 26 | 27 | public slots: 28 | void HostReceiveData(QString, QString hostName, QString data); 29 | 30 | private slots: 31 | void button_clicked(); 32 | 33 | void Init(); 34 | void AutoBuFang(); 35 | 36 | void BuFang(); 37 | void CheFang(); 38 | void PangLu(); 39 | void HuiFu(); 40 | 41 | void SaveConfig(); 42 | void LoadDefenceInfo(); 43 | 44 | void on_listWidget_itemClicked(QListWidgetItem *item); 45 | void on_treeWidget_itemPressed(QTreeWidgetItem *item, int); 46 | 47 | void on_btnBuFang_clicked(); //用户布防 48 | void on_btnCheFang_clicked(); //用户撤防 49 | 50 | void on_btnAdd_clicked(); //添加防区 51 | void on_btnDelete_clicked(); //删除防区 52 | void on_btnUpdate_clicked(); //修改防区 53 | void on_btnMap_clicked(); //导入地图 54 | void on_btnMove_clicked(); //移动防区 55 | void on_btnLot_clicked(); //批量添加防区 56 | 57 | void on_treeDefence_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *); 58 | void on_cboxDefenceID_currentIndexChanged(const QString &arg1); 59 | void on_cboxDefenceSound_currentIndexChanged(const QString &arg1); 60 | void on_cboxDefenceImage_currentIndexChanged(const QString &arg1); 61 | 62 | void on_btnSelect_clicked(); //数据查询 63 | void on_btnDeleteData_clicked();//删除数据 64 | void on_btnPrint_clicked(); //打印数据 65 | void on_btnPdf_clicked(); //导出数据到PDF 66 | void on_btnExcel_clicked(); //导出数据到excel 67 | 68 | void on_ckDefenceName_toggled(bool checked); 69 | void on_ckType_toggled(bool checked); 70 | void on_ckContent_toggled(bool checked); 71 | void on_ckTime_toggled(bool checked); 72 | void on_cboxPageCount_currentIndexChanged(const QString &arg1); 73 | 74 | void LoadLinkInfo(); 75 | void on_btnAddLink_clicked(); 76 | void on_btnDeleteLink_clicked(); 77 | void on_btnUpdateLink_clicked(); 78 | void on_btnClearLink_clicked(); 79 | void on_listLink_pressed(const QModelIndex &index); 80 | void on_cboxSnapTime_currentIndexChanged(const QString &arg1); 81 | 82 | void on_btnSelectVideo_clicked(); 83 | void on_btnSaveVideo_clicked(); 84 | void on_listVideoPath_doubleClicked(const QModelIndex &index); 85 | void on_cboxVideoType_currentIndexChanged(const QString &arg1); 86 | void on_ckFill_stateChanged(int arg1); 87 | void on_ckFade_stateChanged(int arg1); 88 | 89 | private: 90 | Ui::frmAlarm *ui; 91 | 92 | void InitForm(); //初始化窗体数据 93 | void LoadImageFile(); //加载地图目录下所有图片文件 94 | void LoadSoundFile(); //加载声音目录下所有声音文件 95 | 96 | bool defenceChange; //防区信息是否改过 97 | QString tempDefenceID; //临时防区号,用于修改和删除防区 98 | QString defenceID; //鼠标按下处的防区号 99 | QMenu *menu; //右键菜单 100 | int debugLogCount; //当前打印调试信息条数 101 | 102 | int pageCount; //每页记录条数 103 | QString whereSql; //查询条件语句 104 | 105 | QList columnNames; //字段名集合 106 | QList columnWidths; //字段宽度集合 107 | 108 | //获取需要导出和打印的数据 109 | QStringList GetContent(); 110 | 111 | //修改防区位置坐标信息 112 | void UpdateDefenceInfo(QString defenceID, int defenceX, int defenceY); 113 | 114 | //拷贝文件夹 115 | bool CopyDir(const QString &fromDir, const QString &toDir, bool cover); 116 | 117 | }; 118 | 119 | #endif // FRMALARM_H 120 | -------------------------------------------------------------------------------- /frmconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMCONFIG_H 2 | #define FRMCONFIG_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui 8 | { 9 | class frmConfig; 10 | } 11 | 12 | class frmConfig : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit frmConfig(QWidget *parent = 0); 18 | ~frmConfig(); 19 | 20 | private slots: 21 | void SaveConfig(); 22 | void ReceiveTime(QDateTime dateTime); 23 | void button_clicked(); 24 | void on_btnSetTime_clicked(); 25 | void on_btnSetNet_clicked(); 26 | void on_btnNTP_clicked(); 27 | 28 | private: 29 | Ui::frmConfig *ui; 30 | 31 | void InitForm(); 32 | 33 | }; 34 | 35 | #endif // FRMCONFIG_H 36 | -------------------------------------------------------------------------------- /frmdefencelot.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmdefencelot.h" 6 | #include "ui_frmdefencelot.h" 7 | #include "api/myhelper.h" 8 | #include "api/dbhelper.h" 9 | 10 | frmDefenceLot::frmDefenceLot(QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::frmDefenceLot) 13 | { 14 | ui->setupUi(this); 15 | this->InitStyle(); 16 | this->InitForm(); 17 | myHelper::FormInCenter(this); 18 | } 19 | 20 | void frmDefenceLot::SetSubSystem(QString subSystem) 21 | { 22 | this->subSystem = subSystem; 23 | } 24 | 25 | frmDefenceLot::~frmDefenceLot() 26 | { 27 | delete ui; 28 | } 29 | 30 | void frmDefenceLot::InitStyle() 31 | { 32 | this->setProperty("Form", true); 33 | this->setProperty("CanMove", true); 34 | this->setWindowTitle(ui->lab_Title->text()); 35 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); 36 | IconHelper::Instance()->SetIcoMain(ui->lab_Ico); 37 | IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close); 38 | connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close())); 39 | connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close())); 40 | } 41 | 42 | void frmDefenceLot::InitForm() 43 | { 44 | subSystem = "1"; 45 | 46 | //填充防区号 47 | for (int i = 1; i <= 255; i++) { 48 | if (i < 10) { 49 | ui->cboxDefenceIDStart->addItem(QString("00%1").arg(i)); 50 | ui->cboxDefenceIDEnd->addItem(QString("00%1").arg(i)); 51 | continue; 52 | } 53 | if (i < 100) { 54 | ui->cboxDefenceIDStart->addItem(QString("0%1").arg(i)); 55 | ui->cboxDefenceIDEnd->addItem(QString("0%1").arg(i)); 56 | continue; 57 | } 58 | if (i < 1000) { 59 | ui->cboxDefenceIDStart->addItem(QString("%1").arg(i)); 60 | ui->cboxDefenceIDEnd->addItem(QString("%1").arg(i)); 61 | continue; 62 | } 63 | } 64 | } 65 | 66 | void frmDefenceLot::on_btnAdd_clicked() 67 | { 68 | int defenceIDStart = ui->cboxDefenceIDStart->currentIndex() + 1; 69 | int defenceIDEnd = ui->cboxDefenceIDEnd->currentIndex() + 1; 70 | 71 | if (defenceIDStart > defenceIDEnd) { 72 | myHelper::ShowMessageBoxError("防区开始编号不能大于防区结束编号!"); 73 | return; 74 | } 75 | 76 | int count = 0; 77 | int defenceX = 5; 78 | int defenceY = 5; 79 | 80 | //开启数据库事务,加快执行速度 81 | QSqlDatabase::database().transaction(); 82 | 83 | //根据选择的防区编号范围,逐个添加防区 84 | for (int i = defenceIDStart; i <= defenceIDEnd; i++) { 85 | QString defenceID; 86 | if (i < 10) { 87 | defenceID = QString("00%1").arg(i); 88 | } else if (i < 100) { 89 | defenceID = QString("0%1").arg(i); 90 | } else if(i < 1000) { 91 | defenceID = QString("%1").arg(i); 92 | } 93 | 94 | //判断防区是否已经存在,存在则continue 95 | if (DBHelper::IsExistDefence(defenceID)) { 96 | continue; 97 | } 98 | 99 | QSqlQuery query; 100 | QString sql = "insert into DefenceInfo(DefenceID,DefenceName,SubSystem,DefenceSound,DefenceImage,DefenceX,DefenceY) values('"; 101 | sql += defenceID + "','"; 102 | sql += QString("%1防区").arg(defenceID) + "','"; 103 | sql += subSystem + "','"; 104 | sql += "无','"; 105 | sql += App::CurrentImage + "','"; 106 | sql += QString::number(defenceX) + "','"; 107 | sql += QString::number(defenceY) + "')"; 108 | query.exec(sql); 109 | 110 | //动态改变防区坐标 111 | defenceX = defenceX + 30; 112 | count++; 113 | if (count == 25) { 114 | defenceY = defenceY + 30; 115 | defenceX = 5; 116 | count = 0; 117 | } 118 | } 119 | 120 | //结束事务处理,提交事务 121 | QSqlDatabase::database().commit(); 122 | 123 | //发送批量添加防区信号给防区管理界面,及时更新界面数据 124 | emit AddDefence(); 125 | 126 | } 127 | -------------------------------------------------------------------------------- /frmdefencelot.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMDEFENCELOT_H 2 | #define FRMDEFENCELOT_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmDefenceLot; 9 | } 10 | 11 | class frmDefenceLot : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmDefenceLot(QWidget *parent = 0); 17 | ~frmDefenceLot(); 18 | 19 | void SetSubSystem(QString subSystem); 20 | 21 | private slots: 22 | void on_btnAdd_clicked(); 23 | 24 | signals: 25 | void AddDefence(); 26 | 27 | private: 28 | Ui::frmDefenceLot *ui; 29 | 30 | QString subSystem; //子系统 31 | void InitStyle(); //初始化无边框窗体 32 | void InitForm(); //初始化窗体数据 33 | 34 | }; 35 | 36 | #endif // FRMDEFENCELOT_H 37 | -------------------------------------------------------------------------------- /frmgateway.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmgateway.h" 6 | #include "ui_frmgateway.h" 7 | 8 | frmGateway::frmGateway(QWidget *parent) : 9 | QWidget(parent), 10 | ui(new Ui::frmGateway) 11 | { 12 | ui->setupUi(this); 13 | this->InitForm(); 14 | } 15 | 16 | frmGateway::~frmGateway() 17 | { 18 | delete ui; 19 | } 20 | 21 | void frmGateway::InitForm() 22 | { 23 | #ifdef __arm__ 24 | ui->widget_left->setMinimumWidth(150); 25 | ui->widget_left->setMaximumWidth(150); 26 | #endif 27 | 28 | QList btns = ui->widget_left->findChildren(); 29 | foreach (QPushButton * btn, btns) { 30 | connect(btn, SIGNAL(clicked()), this, SLOT(button_clicked())); 31 | } 32 | 33 | ui->btnConfig->click(); 34 | } 35 | 36 | void frmGateway::button_clicked() 37 | { 38 | QPushButton *btn = (QPushButton *)sender(); 39 | QString name = btn->text(); 40 | QList btns = ui->widget_left->findChildren(); 41 | foreach (QPushButton * b, btns) { 42 | b->setChecked(false); 43 | } 44 | btn->setChecked(true); 45 | 46 | if (name == "系统设置") { 47 | ui->stackedWidget->setCurrentIndex(0); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /frmgateway.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMGATEWAY_H 2 | #define FRMGATEWAY_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmGateway; 9 | } 10 | 11 | class frmGateway : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmGateway(QWidget *parent = 0); 17 | ~frmGateway(); 18 | 19 | private slots: 20 | void button_clicked(); 21 | 22 | private: 23 | Ui::frmGateway *ui; 24 | 25 | void InitForm(); 26 | 27 | }; 28 | 29 | #endif // FRMGATEWAY_H 30 | -------------------------------------------------------------------------------- /frmgateway.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | frmGateway 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 34 | 35 | 36 | 90 37 | 0 38 | 39 | 40 | 41 | 42 | 90 43 | 16777215 44 | 45 | 46 | 47 | 48 | 0 49 | 50 | 51 | 0 52 | 53 | 54 | 0 55 | 56 | 57 | 0 58 | 59 | 60 | 0 61 | 62 | 63 | 64 | 65 | 系统设置 66 | 67 | 68 | true 69 | 70 | 71 | false 72 | 73 | 74 | 75 | 76 | 77 | 78 | Qt::Vertical 79 | 80 | 81 | 82 | 20 83 | 40 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /frmmain.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMMAIN_H 2 | #define FRMMAIN_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmMain; 9 | } 10 | 11 | class frmMain : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmMain(QWidget *parent = 0); 17 | ~frmMain(); 18 | 19 | protected: 20 | void reject(); 21 | 22 | private slots: 23 | void button_clicked(); 24 | void action_clicked(); 25 | void Screen(); //截图 26 | 27 | private: 28 | Ui::frmMain *ui; 29 | 30 | void InitStyle(); //初始化无边框窗体 31 | void InitForm(); //初始化窗体数据 32 | 33 | }; 34 | 35 | #endif // FRMMAIN_H 36 | -------------------------------------------------------------------------------- /frmselect.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmselect.h" 6 | #include "ui_frmselect.h" 7 | #include "api/myhelper.h" 8 | 9 | frmSelect::frmSelect(QWidget *parent) : 10 | QDialog(parent), 11 | ui(new Ui::frmSelect) 12 | { 13 | ui->setupUi(this); 14 | this->InitStyle(); 15 | myHelper::FormInCenter(this); 16 | } 17 | 18 | frmSelect::~frmSelect() 19 | { 20 | delete ui; 21 | } 22 | 23 | void frmSelect::InitStyle() 24 | { 25 | this->setWindowTitle(ui->lab_Title->text()); 26 | this->setProperty("Form", true); 27 | this->setProperty("CanMove", true); 28 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); 29 | IconHelper::Instance()->SetIcoMain(ui->lab_Ico, App::FontSize + 2); 30 | IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close); 31 | connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close())); 32 | connect(ui->btnClose, SIGNAL(clicked()), this, SLOT(close())); 33 | 34 | int width = 20; 35 | #ifdef __arm__ 36 | width = 25; 37 | #endif 38 | QString qss = QString("QComboBox::drop-down,QDateEdit::drop-down,QTimeEdit::drop-down,QDateTimeEdit::drop-down{width:%1px;}").arg(width); 39 | this->setStyleSheet(qss); 40 | 41 | ui->dateStart->setDate(QDate::currentDate()); 42 | ui->dateEnd->setDate(QDate::currentDate().addDays(1)); 43 | 44 | ui->dateStart->calendarWidget()->setLocale(QLocale::Chinese); 45 | ui->dateEnd->calendarWidget()->setLocale(QLocale::Chinese); 46 | } 47 | 48 | void frmSelect::on_btnOk_clicked() 49 | { 50 | if (ui->dateStart->dateTime() > ui->dateEnd->dateTime()) { 51 | myHelper::ShowMessageBoxErrorX("开始时间不能大于结束时间!"); 52 | return; 53 | } 54 | 55 | this->selectStartDateTime = ui->dateStart->dateTime().toString("yyyy-MM-dd HH:mm:ss"); 56 | this->selectEndDateTime = ui->dateEnd->dateTime().toString("yyyy-MM-dd HH:mm:ss"); 57 | 58 | done(1); 59 | this->close(); 60 | } 61 | -------------------------------------------------------------------------------- /frmselect.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMSELECT_H 2 | #define FRMSELECT_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmSelect; 9 | } 10 | 11 | class frmSelect : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmSelect(QWidget *parent = 0); 17 | ~frmSelect(); 18 | 19 | //获取当前选择的开始时间和结束时间 20 | QString SelectStartDateTime() const 21 | { 22 | return selectStartDateTime; 23 | } 24 | QString SelectEndDateTime() const 25 | { 26 | return selectEndDateTime; 27 | } 28 | 29 | private slots: 30 | void on_btnOk_clicked();//按下确定按钮 31 | 32 | private: 33 | Ui::frmSelect *ui; 34 | 35 | QString selectStartDateTime;//开始时间 36 | QString selectEndDateTime; //结束时间 37 | void InitStyle(); //初始化无边框窗体 38 | 39 | }; 40 | 41 | #endif // FRMSELECT_H 42 | -------------------------------------------------------------------------------- /frmvisitor.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmvisitor.h" 6 | #include "ui_frmvisitor.h" 7 | #include "api/myhelper.h" 8 | 9 | frmVisitor::frmVisitor(QWidget *parent) : 10 | QWidget(parent), 11 | ui(new Ui::frmVisitor) 12 | { 13 | ui->setupUi(this); 14 | this->InitForm(); 15 | } 16 | 17 | frmVisitor::~frmVisitor() 18 | { 19 | delete ui; 20 | } 21 | 22 | void frmVisitor::InitForm() 23 | { 24 | #ifdef __arm__ 25 | ui->widget_left->setMinimumWidth(150); 26 | ui->widget_left->setMaximumWidth(150); 27 | #endif 28 | 29 | QList btns = ui->widget_left->findChildren(); 30 | foreach (QPushButton * btn, btns) { 31 | connect(btn, SIGNAL(clicked()), this, SLOT(button_clicked())); 32 | } 33 | 34 | ui->btnMain->click(); 35 | } 36 | 37 | void frmVisitor::button_clicked() 38 | { 39 | QPushButton *btn = (QPushButton *)sender(); 40 | QString name = btn->text(); 41 | QList btns = ui->widget_left->findChildren(); 42 | foreach (QPushButton * b, btns) { 43 | b->setChecked(false); 44 | } 45 | btn->setChecked(true); 46 | 47 | if (name == "主界面") { 48 | ui->stackedWidget->setCurrentIndex(0); 49 | } else if (name == "记录查询") { 50 | ui->stackedWidget->setCurrentIndex(1); 51 | } else if (name == "系统设置") { 52 | ui->stackedWidget->setCurrentIndex(2); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /frmvisitor.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMVISITOR_H 2 | #define FRMVISITOR_H 3 | 4 | #include 5 | 6 | namespace Ui 7 | { 8 | class frmVisitor; 9 | } 10 | 11 | class frmVisitor : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit frmVisitor(QWidget *parent = 0); 17 | ~frmVisitor(); 18 | 19 | private slots: 20 | void button_clicked(); 21 | 22 | private: 23 | Ui::frmVisitor *ui; 24 | 25 | void InitForm(); 26 | 27 | }; 28 | 29 | #endif // FRMVISITOR_H 30 | -------------------------------------------------------------------------------- /frmvisitor.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | frmVisitor 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 34 | 35 | 36 | 90 37 | 0 38 | 39 | 40 | 41 | 42 | 90 43 | 16777215 44 | 45 | 46 | 47 | 48 | 0 49 | 50 | 51 | 0 52 | 53 | 54 | 0 55 | 56 | 57 | 0 58 | 59 | 60 | 0 61 | 62 | 63 | 64 | 65 | 主界面 66 | 67 | 68 | true 69 | 70 | 71 | false 72 | 73 | 74 | 75 | 76 | 77 | 78 | 记录查询 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | 87 | 88 | 系统设置 89 | 90 | 91 | true 92 | 93 | 94 | 95 | 96 | 97 | 98 | Qt::Vertical 99 | 100 | 101 | 102 | 20 103 | 40 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 1 115 | 116 | 117 | 118 | 119 | 120 | QGroupBox{ 121 | margin-top:3ex; 122 | } 123 | QGroupBox::title { 124 | subcontrol-origin: margin; 125 | position: relative; 126 | left: 1px; 127 | } 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /inputnew/frminputnew.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMINPUTNEW_H 2 | #define FRMINPUTNEW_H 3 | 4 | #include 5 | #include 6 | #if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) 7 | #include 8 | #endif 9 | 10 | namespace Ui 11 | { 12 | class frmInputNew; 13 | } 14 | 15 | class frmInputNew : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit frmInputNew(QWidget *parent = 0); 21 | ~frmInputNew(); 22 | 23 | //单例模式,保证一个程序只存在一个输入法实例对象 24 | static frmInputNew *Instance() 25 | { 26 | if (!_self) { 27 | static QMutex mutex; 28 | QMutexLocker locker(&mutex); 29 | 30 | if (!_self) { 31 | _self = new frmInputNew; 32 | } 33 | } 34 | 35 | return _self; 36 | } 37 | 38 | //初始化面板状态,包括字体大小 39 | void init(QString position, QString style, int btnFontSize, int labFontSize, 40 | int frmWidth, int frmHeight, int icoWidth, int icoHeight, 41 | int spacing, int topHeight); 42 | void init(QString position); 43 | 44 | protected: 45 | //事件过滤器,处理鼠标在汉字标签处单击操作 46 | bool eventFilter(QObject *obj, QEvent *event); 47 | //鼠标拖动事件 48 | void mouseMoveEvent(QMouseEvent *e); 49 | //鼠标按下事件 50 | void mousePressEvent(QMouseEvent *e); 51 | //鼠标松开事件 52 | void mouseReleaseEvent(QMouseEvent *); 53 | 54 | private slots: 55 | //焦点改变事件槽函数处理 56 | void focusChanged(QWidget *oldWidget, QWidget *nowWidget); 57 | //改变输入法面板样式 58 | void changeStyle(QString mainBackgroundColor, QString mainTextColor, QString btnBackgroundColor, 59 | QString btnHoveColor, QString btnHoveTextColor, QString labHoveColor, QString labHoveTextColor); 60 | //输入法面板按键处理 61 | void btnClicked(); 62 | //定时器处理退格键 63 | void reClicked(); 64 | 65 | private: 66 | Ui::frmInputNew *ui; 67 | static frmInputNew *_self; //实例对象 68 | 69 | int frmWidth; //窗体宽度 70 | int frmHeight; //窗体高度 71 | int icoWidth; //图标宽度 72 | int icoHeight; //图标高度 73 | int spacing; //按钮间隔 74 | int topHeight; //汉字显示区域高度 75 | 76 | int deskWidth; //桌面宽度 77 | int deskHeight; //桌面高度 78 | 79 | QPoint mousePoint; //鼠标拖动自定义标题栏时的坐标 80 | bool mousePressed; //鼠标是否按下 81 | 82 | bool isPress; //是否长按退格键 83 | QPushButton *btnPress; //长按按钮 84 | QTimer *timerPress; //退格键定时器 85 | bool checkPress(); //校验当前长按的按钮 86 | 87 | bool isFirst; //是否首次加载 88 | void initForm(); //初始化窗体数据 89 | void initProperty(); //初始化属性 90 | void changeStyle(); //改变样式 91 | void changeSize(); //改变大小 92 | void showPanel(); //显示输入法面板 93 | 94 | QWidget *currentWidget; //当前焦点的对象 95 | QLineEdit *currentLineEdit; //当前焦点的单行文本框 96 | QTextEdit *currentTextEdit; //当前焦点的多行文本框 97 | QPlainTextEdit *currentPlain; //当前焦点的富文本框 98 | QTextBrowser *currentBrowser; //当前焦点的文本浏览框 99 | 100 | QString currentEditType; //当前焦点控件的类型 101 | QString currentPosition; //当前输入法面板位置类型 102 | QString currentStyle; //当前输入法面板样式 103 | int btnFontSize; //当前输入法面板按钮字体大小 104 | int labFontSize; //当前输入法面板标签字体大小 105 | void insertValue(QString value);//插入值到当前焦点控件 106 | void deleteValue(); //删除当前焦点控件的一个字符 107 | 108 | bool upper; //当前大小写状态 109 | QString currentType; //当前输入法类型 110 | void changeType(QString type); //改变输入法类型 111 | void changeLetter(bool isUpper);//改变字母大小写 112 | void changeChar(bool isChar); //按钮改变成特殊字符 113 | 114 | QListlabCh; //汉字标签数组 115 | QStringList allPY; //所有拼音链表 116 | QStringList currentPY; //当前拼音链表 117 | int currentPY_index; //当前拼音索引 118 | int currentPY_count; //当前拼音数量 119 | void selectChinese(); //查询汉字 120 | void showChinese(); //显示查询到的汉字 121 | void setChinese(int index); //设置当前汉字 122 | void clearChinese(); //清空当前汉字信息 123 | 124 | }; 125 | 126 | #endif // FRMINPUTNEW_H 127 | -------------------------------------------------------------------------------- /inputnew/image/close_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/close_black.png -------------------------------------------------------------------------------- /inputnew/image/close_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/close_white.png -------------------------------------------------------------------------------- /inputnew/image/delete_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/delete_black.png -------------------------------------------------------------------------------- /inputnew/image/delete_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/delete_white.png -------------------------------------------------------------------------------- /inputnew/image/enter_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/enter_black.png -------------------------------------------------------------------------------- /inputnew/image/enter_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/enter_white.png -------------------------------------------------------------------------------- /inputnew/image/handwriting_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/handwriting_black.png -------------------------------------------------------------------------------- /inputnew/image/handwriting_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/handwriting_white.png -------------------------------------------------------------------------------- /inputnew/image/mini_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/mini_black.png -------------------------------------------------------------------------------- /inputnew/image/mini_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/mini_white.png -------------------------------------------------------------------------------- /inputnew/image/space_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/space_black.png -------------------------------------------------------------------------------- /inputnew/image/space_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/space_white.png -------------------------------------------------------------------------------- /inputnew/image/upper_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/upper_black.png -------------------------------------------------------------------------------- /inputnew/image/upper_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/inputnew/image/upper_white.png -------------------------------------------------------------------------------- /inputnew/inputnew.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/frminputnew.h 3 | 4 | SOURCES += \ 5 | $$PWD/frminputnew.cpp 6 | 7 | FORMS += \ 8 | $$PWD/frminputnew.ui 9 | 10 | RESOURCES += \ 11 | $$PWD/inputnew.qrc 12 | -------------------------------------------------------------------------------- /inputnew/inputnew.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | image/close_black.png 4 | image/close_white.png 5 | image/delete_black.png 6 | image/delete_white.png 7 | image/enter_black.png 8 | image/enter_white.png 9 | image/handwriting_black.png 10 | image/handwriting_white.png 11 | image/mini_black.png 12 | image/mini_white.png 13 | image/space_black.png 14 | image/space_white.png 15 | image/upper_black.png 16 | image/upper_white.png 17 | 18 | 19 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "frmmain.h" 2 | #include 3 | #include "api/appinit.h" 4 | #include "api/myhelper.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | 10 | #if (QT_VERSION >= QT_VERSION_CHECK(5,6,0)) 11 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 12 | #endif 13 | 14 | a.setApplicationName(App::AppName); 15 | a.setApplicationVersion("1.0"); 16 | a.setWindowIcon(QIcon(":/main.ico")); 17 | 18 | AppInit::Instance()->Start(); 19 | 20 | frmMain w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /other/banner/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/about.png -------------------------------------------------------------------------------- /other/banner/main_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_about.png -------------------------------------------------------------------------------- /other/banner/main_company.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_company.png -------------------------------------------------------------------------------- /other/banner/main_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_config.png -------------------------------------------------------------------------------- /other/banner/main_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_data.png -------------------------------------------------------------------------------- /other/banner/main_exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_exit.png -------------------------------------------------------------------------------- /other/banner/main_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_help.png -------------------------------------------------------------------------------- /other/banner/main_person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/main_person.png -------------------------------------------------------------------------------- /other/banner/tree_child.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/tree_child.png -------------------------------------------------------------------------------- /other/banner/tree_parent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/banner/tree_parent.png -------------------------------------------------------------------------------- /other/help.txt: -------------------------------------------------------------------------------- 1 | onvif摄像机rtsp视频流格式: 2 | 备注:以下rtsp地址为通用格式,只需要替换IP地址部分即可,如果不能正常显示实时画面,请将码流改成256,间隔改为10帧,变码流。暂不支持需要用户名和密码认证的rtsp视频流,如果有请将用户名和密码认证去掉。 3 | 4 | 海康/泰杰/通用格式: 5 | 主码流:rtsp://192.168.1.128:554/0 6 | 子码流:rtsp://192.168.1.128:554/1 7 | 8 | 大华: 9 | 主码流:rtsp://192.168.1.128:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif 10 | 子码流:rtsp://192.168.1.128:554/cam/realmonitor?channel=1&subtype=1&unicast=true&proto=Onvif 11 | 12 | 宇视: 13 | 主码流:rtsp://192.168.1.128/media/video1 14 | 子码流:rtsp://192.168.1.128/media/video2 15 | 16 | 公开测试视频流: 17 | 车站:rtsp://218.204.223.237:554/live/1/0547424F573B085C/gsfp90ef4k0a6iap.sdp 18 | 机场:rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp 19 | 20 | VISTA128主机串口通信编程 21 | 41408000→*05→1→*14→1→*94→1→*70→5个1→*78→1→*79→5个1→*80→1→*99→*99→*99 22 | 去掉布防后滴滴声: 23 | 41408000→*09→00→*10→00→*11→00→*12→00→*99 24 | 25 | DS7400报警主机编程 26 | 编程前请认真阅读主机说明书,正确接好连线(正确接好连线是键盘正确编程的前提)如果是第一次使用DS7400主机,在编程完成前,建议安装技术人员不要将探测器接入主机,只需要将线尾电阻和拓展模块接在主机上就可以,将主机调试好后,再将探测器接入主机,这样如果系统有故障,有利于工程技术人员判断是主机系统故障还是探测器故障。 27 | 一:初始化:9876#0 4058 01# *(4秒) 28 | 二:正常布防:1234+布防 29 | 三:撤防和消警:1234+撤防 30 | 四:强制布防:1234+布防+旁路(没有交流电或者有未准备的防区时用这种方法布防) 31 | 五:防区旁路:1234+旁路+XXX(三位防区号,例如009) 32 | 六:旁路恢复:1234+旁路+XXX(三位防区号,例如009) 33 | 七:恢复所有旁路防区:1234+旁路+* 34 | 八:进入编程和退出编程:9876#0(进入编程)*四秒钟(退出编程) 35 | 九:防区编程:0031-0278为防区编程地址,其中0031-0038为主机自带八防区,默认即可,从第9防区开始编程,地址为0039,如果将第九防区设置为即时防区,则把0039中的数据改为03(01为延时防区,03为即时防区,07为24小时防区) 36 | 9876#0(进入编程) 37 | 0039(第九防区地址) 38 | 03#(设置为即时防区) 39 | 0040(第十防区地址) 40 | 07#(设置为24小时防区) 41 | 0041(第十一防区地址) 42 | 03#(设置为即时防区) 43 | ------依此类推 44 | *4秒钟(退出编程) 45 | 十:系统分区编程:即VISTA120主机中的子系统,可以分别对子系统进行布撤防 46 | 9876#0(进入编程) 47 | 3420(系统分区编程地址) 48 | 10#(数据1为分区数,默认为0即1个分区,1为两个分区,数据2表示有无公共分区,默认为0,如果有两个分区则输入10#,三个分区输入20#,依此类推,最多8个分区) 49 | *4秒钟(退出编程) 50 | 十一:防区分区编程:划分了分区后,要确定防区属于哪些分区,编程地址为0287-0410,0287代表第一二防区,0288第三四防区,总共可以设置248个防区(第九防区从0291开始)数据1代表前面一个防区,数据2代表后面一个防区,数据1,2可以设定为0-7,代表1分区到8分区(一般情况下不分区,此项不用编程) 51 | 9876#0(进入编程) 52 | 0291(进入第9,10防区分区编程地址) 53 | 00#(9防区为1分区,10防区为1分区) 54 | 0292(进入第11,12防区分区编程地址) 55 | 01#(11防区为1分区,12防区为2分区) 56 | 0293(进入第13,14防区分区编程地址) 57 | 11#(11防区为2分区,12防区为2分区) 58 | *4秒钟(退出编程) 59 | 十二:分区布撤防:1234+##进入第一分区,再按##进入第二分区,依此类推直到找到所想操作的分区,例如对第二分区布防,1234+##+##+##,此时键盘显示Armed area 3,接着按布防就可以,撤防也一样,先进入分区在撤防,1234+##+##+##+撤防 60 | 十三:修改编程密码:9876#0 7589 4567 *(4秒) 这样就将编程密码改为4567 61 | 十四:修改主操作密码:9876#0 7592 4567 *(4秒) 这样就将主操作密码改为4567 62 | 十五:强制布防和接地故障:编程地址为2731,数据1表示可以强制布防多少个防区,数据2表示系统是否检查接地故障,出厂值1。,如果接地有问题则设置为0 63 | 十六:键盘设置为主键盘:9876#0 3131 30# *(4秒) 64 | 65 | 简单周界报警(DS7400主机+DS7436(DS7430)总线驱动器+DS7447液晶键盘+DS7457I单防区模块+DX4010串口转换模块+报警软件) 66 | 例如:总共3个防区,所有防区设置为即时防区 67 | 恢复出厂:9876#0 4058 01# *(4秒) 68 | 防区编程:9876#0 0039 03# 0040 03# 0041 03# *(4秒) 69 | 通讯编程:9876#0 4019 18# 4020 20# *(4秒) 70 | 软件设置:串口号设置为DX4010串口转换模块连接计算机使用的串口号。 71 | 如果通信成功则DX4010模块红色灯闪烁,报警软件打开显示连上。 -------------------------------------------------------------------------------- /other/image/add_bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_bottom.png -------------------------------------------------------------------------------- /other/image/add_bottom_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_bottom_blue.png -------------------------------------------------------------------------------- /other/image/add_bottom_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_bottom_dev.png -------------------------------------------------------------------------------- /other/image/add_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_left.png -------------------------------------------------------------------------------- /other/image/add_left_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_left_blue.png -------------------------------------------------------------------------------- /other/image/add_left_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_left_dev.png -------------------------------------------------------------------------------- /other/image/add_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_right.png -------------------------------------------------------------------------------- /other/image/add_right_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_right_blue.png -------------------------------------------------------------------------------- /other/image/add_right_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_right_dev.png -------------------------------------------------------------------------------- /other/image/add_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_top.png -------------------------------------------------------------------------------- /other/image/add_top_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_top_blue.png -------------------------------------------------------------------------------- /other/image/add_top_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/add_top_dev.png -------------------------------------------------------------------------------- /other/image/btn_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_add.png -------------------------------------------------------------------------------- /other/image/btn_check_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_check_off.png -------------------------------------------------------------------------------- /other/image/btn_check_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_check_on.png -------------------------------------------------------------------------------- /other/image/btn_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_close.png -------------------------------------------------------------------------------- /other/image/btn_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_delete.png -------------------------------------------------------------------------------- /other/image/btn_email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_email.png -------------------------------------------------------------------------------- /other/image/btn_excel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_excel.png -------------------------------------------------------------------------------- /other/image/btn_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_input.png -------------------------------------------------------------------------------- /other/image/btn_move.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_move.png -------------------------------------------------------------------------------- /other/image/btn_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_ok.png -------------------------------------------------------------------------------- /other/image/btn_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_open.png -------------------------------------------------------------------------------- /other/image/btn_out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_out.png -------------------------------------------------------------------------------- /other/image/btn_pause_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_pause_normal.png -------------------------------------------------------------------------------- /other/image/btn_pause_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_pause_press.png -------------------------------------------------------------------------------- /other/image/btn_pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_pdf.png -------------------------------------------------------------------------------- /other/image/btn_play_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_play_normal.png -------------------------------------------------------------------------------- /other/image/btn_play_press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_play_press.png -------------------------------------------------------------------------------- /other/image/btn_print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_print.png -------------------------------------------------------------------------------- /other/image/btn_pwd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_pwd.png -------------------------------------------------------------------------------- /other/image/btn_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/btn_save.png -------------------------------------------------------------------------------- /other/image/checkbox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/checkbox_checked.png -------------------------------------------------------------------------------- /other/image/checkbox_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/checkbox_unchecked.png -------------------------------------------------------------------------------- /other/image/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /other/image/image_next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/image_next.png -------------------------------------------------------------------------------- /other/image/image_prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/image_prev.png -------------------------------------------------------------------------------- /other/image/msg_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/msg_error.png -------------------------------------------------------------------------------- /other/image/msg_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/msg_info.png -------------------------------------------------------------------------------- /other/image/msg_question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/msg_question.png -------------------------------------------------------------------------------- /other/image/qt_zh_CN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/qt_zh_CN.qm -------------------------------------------------------------------------------- /other/image/radio_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/radio_normal.png -------------------------------------------------------------------------------- /other/image/radio_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/image/radio_selected.png -------------------------------------------------------------------------------- /other/main.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github188/GAS/b8f3c4be5ab97ffd118342d951db49e7875573aa/other/main.ico -------------------------------------------------------------------------------- /other/rc.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.ico 4 | help.txt 5 | qss/black.css 6 | qss/blue.css 7 | qss/brown.css 8 | qss/darkgray.css 9 | qss/dev.css 10 | qss/gray.css 11 | qss/lightgray.css 12 | qss/silvery.css 13 | banner/about.png 14 | banner/main_about.png 15 | banner/main_company.png 16 | banner/main_config.png 17 | banner/main_data.png 18 | banner/main_exit.png 19 | banner/main_help.png 20 | banner/main_person.png 21 | banner/tree_child.png 22 | banner/tree_parent.png 23 | image/add_bottom.png 24 | image/add_bottom_blue.png 25 | image/add_bottom_dev.png 26 | image/add_left.png 27 | image/add_left_blue.png 28 | image/add_left_dev.png 29 | image/add_right.png 30 | image/add_right_blue.png 31 | image/add_right_dev.png 32 | image/add_top.png 33 | image/add_top_blue.png 34 | image/add_top_dev.png 35 | image/btn_add.png 36 | image/btn_check_off.png 37 | image/btn_check_on.png 38 | image/btn_close.png 39 | image/btn_delete.png 40 | image/btn_email.png 41 | image/btn_excel.png 42 | image/btn_input.png 43 | image/btn_move.png 44 | image/btn_ok.png 45 | image/btn_open.png 46 | image/btn_out.png 47 | image/btn_pause_normal.png 48 | image/btn_pause_press.png 49 | image/btn_pdf.png 50 | image/btn_play_normal.png 51 | image/btn_play_press.png 52 | image/btn_print.png 53 | image/btn_pwd.png 54 | image/btn_save.png 55 | image/checkbox_checked.png 56 | image/checkbox_unchecked.png 57 | image/fontawesome-webfont.ttf 58 | image/image_next.png 59 | image/image_prev.png 60 | image/msg_error.png 61 | image/msg_info.png 62 | image/msg_question.png 63 | image/qt_zh_CN.qm 64 | image/radio_normal.png 65 | image/radio_selected.png 66 | 67 | 68 | -------------------------------------------------------------------------------- /qemail/emailaddress.cpp: -------------------------------------------------------------------------------- 1 | #include "emailaddress.h" 2 | 3 | EmailAddress::EmailAddress(const QString &address, const QString &name) 4 | { 5 | this->address = address; 6 | this->name = name; 7 | } 8 | 9 | EmailAddress::~EmailAddress() 10 | { 11 | } 12 | 13 | void EmailAddress::setName(const QString &name) 14 | { 15 | this->name = name; 16 | } 17 | 18 | void EmailAddress::setAddress(const QString &address) 19 | { 20 | this->address = address; 21 | } 22 | 23 | const QString &EmailAddress::getName() const 24 | { 25 | return name; 26 | } 27 | 28 | const QString &EmailAddress::getAddress() const 29 | { 30 | return address; 31 | } 32 | -------------------------------------------------------------------------------- /qemail/emailaddress.h: -------------------------------------------------------------------------------- 1 | #ifndef EMAILADDRESS_H 2 | #define EMAILADDRESS_H 3 | 4 | #include 5 | 6 | class EmailAddress : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | 11 | EmailAddress(); 12 | EmailAddress(const QString &address, const QString &name = ""); 13 | 14 | ~EmailAddress(); 15 | 16 | void setName(const QString &name); 17 | void setAddress(const QString &address); 18 | 19 | const QString &getName() const; 20 | const QString &getAddress() const; 21 | 22 | private: 23 | QString name; 24 | QString address; 25 | 26 | }; 27 | 28 | #endif // EMAILADDRESS_H 29 | -------------------------------------------------------------------------------- /qemail/mimeattachment.cpp: -------------------------------------------------------------------------------- 1 | #include "mimeattachment.h" 2 | #include 3 | 4 | MimeAttachment::MimeAttachment(QFile *file) 5 | : MimeFile(file) 6 | { 7 | } 8 | 9 | MimeAttachment::~MimeAttachment() 10 | { 11 | } 12 | 13 | void MimeAttachment::prepare() 14 | { 15 | this->header += "Content-disposition: attachment\r\n"; 16 | MimeFile::prepare(); 17 | } 18 | -------------------------------------------------------------------------------- /qemail/mimeattachment.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEATTACHMENT_H 2 | #define MIMEATTACHMENT_H 3 | 4 | #include 5 | #include "mimepart.h" 6 | #include "mimefile.h" 7 | 8 | class MimeAttachment : public MimeFile 9 | { 10 | Q_OBJECT 11 | public: 12 | MimeAttachment(QFile *file); 13 | ~MimeAttachment(); 14 | 15 | protected: 16 | virtual void prepare(); 17 | 18 | }; 19 | 20 | #endif // MIMEATTACHMENT_H 21 | -------------------------------------------------------------------------------- /qemail/mimecontentformatter.cpp: -------------------------------------------------------------------------------- 1 | #include "mimecontentformatter.h" 2 | 3 | MimeContentFormatter::MimeContentFormatter(int max_length) : 4 | max_length(max_length) 5 | {} 6 | 7 | QString MimeContentFormatter::format(const QString &content, bool quotedPrintable) const 8 | { 9 | QString out; 10 | 11 | int chars = 0; 12 | 13 | for (int i = 0; i < content.length() ; ++i) { 14 | chars++; 15 | 16 | if (!quotedPrintable) { 17 | if (chars > max_length) { 18 | out.append("\r\n"); 19 | chars = 1; 20 | } 21 | } else { 22 | if (content.at(i) == '\n') { // new line 23 | out.append(content.at(i)); 24 | chars = 0; 25 | continue; 26 | } 27 | 28 | if ((chars > max_length - 1) 29 | || ((content.at(i) == '=') && (chars > max_length - 3))) { 30 | out.append('='); 31 | out.append("\r\n"); 32 | chars = 1; 33 | } 34 | 35 | } 36 | 37 | out.append(content.at(i)); 38 | } 39 | 40 | return out; 41 | } 42 | 43 | void MimeContentFormatter::setMaxLength(int l) 44 | { 45 | max_length = l; 46 | } 47 | 48 | int MimeContentFormatter::getMaxLength() const 49 | { 50 | return max_length; 51 | } 52 | -------------------------------------------------------------------------------- /qemail/mimecontentformatter.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMECONTENTFORMATTER_H 2 | #define MIMECONTENTFORMATTER_H 3 | 4 | #include 5 | #include 6 | 7 | class MimeContentFormatter : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | MimeContentFormatter(int max_length = 76); 12 | 13 | void setMaxLength(int l); 14 | int getMaxLength() const; 15 | 16 | QString format(const QString &content, bool quotedPrintable = false) const; 17 | 18 | protected: 19 | int max_length; 20 | 21 | }; 22 | 23 | #endif // MIMECONTENTFORMATTER_H 24 | -------------------------------------------------------------------------------- /qemail/mimefile.cpp: -------------------------------------------------------------------------------- 1 | #include "mimefile.h" 2 | #include 3 | 4 | MimeFile::MimeFile(QFile *file) 5 | { 6 | this->file = file; 7 | this->cType = "application/octet-stream"; 8 | this->cName = QFileInfo(*file).fileName(); 9 | this->cEncoding = Base64; 10 | } 11 | 12 | MimeFile::~MimeFile() 13 | { 14 | delete file; 15 | } 16 | 17 | void MimeFile::prepare() 18 | { 19 | file->open(QIODevice::ReadOnly); 20 | this->content = file->readAll(); 21 | file->close(); 22 | MimePart::prepare(); 23 | } 24 | -------------------------------------------------------------------------------- /qemail/mimefile.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEFILE_H 2 | #define MIMEFILE_H 3 | 4 | #include "mimepart.h" 5 | #include 6 | 7 | class MimeFile : public MimePart 8 | { 9 | Q_OBJECT 10 | public: 11 | 12 | MimeFile(QFile *f); 13 | ~MimeFile(); 14 | 15 | protected: 16 | QFile *file; 17 | virtual void prepare(); 18 | 19 | }; 20 | 21 | #endif // MIMEFILE_H 22 | -------------------------------------------------------------------------------- /qemail/mimehtml.cpp: -------------------------------------------------------------------------------- 1 | #include "mimehtml.h" 2 | 3 | MimeHtml::MimeHtml(const QString &html) : MimeText(html) 4 | { 5 | this->cType = "text/html"; 6 | } 7 | 8 | MimeHtml::~MimeHtml() {} 9 | 10 | void MimeHtml::setHtml(const QString &html) 11 | { 12 | this->text = html; 13 | } 14 | 15 | const QString &MimeHtml::getHtml() const 16 | { 17 | return text; 18 | } 19 | 20 | void MimeHtml::prepare() 21 | { 22 | MimeText::prepare(); 23 | } 24 | -------------------------------------------------------------------------------- /qemail/mimehtml.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEHTML_H 2 | #define MIMEHTML_H 3 | 4 | #include "mimetext.h" 5 | 6 | class MimeHtml : public MimeText 7 | { 8 | Q_OBJECT 9 | public: 10 | MimeHtml(const QString &html = ""); 11 | ~MimeHtml(); 12 | 13 | void setHtml(const QString &html); 14 | const QString &getHtml() const; 15 | 16 | protected: 17 | virtual void prepare(); 18 | 19 | }; 20 | 21 | #endif // MIMEHTML_H 22 | -------------------------------------------------------------------------------- /qemail/mimeinlinefile.cpp: -------------------------------------------------------------------------------- 1 | #include "mimeinlinefile.h" 2 | 3 | MimeInlineFile::MimeInlineFile(QFile *f) 4 | : MimeFile(f) 5 | { 6 | } 7 | 8 | MimeInlineFile::~MimeInlineFile() 9 | {} 10 | 11 | void MimeInlineFile::prepare() 12 | { 13 | this->header += "Content-Disposition: inline\r\n"; 14 | MimeFile::prepare(); 15 | } 16 | -------------------------------------------------------------------------------- /qemail/mimeinlinefile.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEINLINEFILE_H 2 | #define MIMEINLINEFILE_H 3 | 4 | #include "mimefile.h" 5 | 6 | class MimeInlineFile : public MimeFile 7 | { 8 | public: 9 | 10 | MimeInlineFile(QFile *f); 11 | ~MimeInlineFile(); 12 | 13 | protected: 14 | virtual void prepare(); 15 | 16 | }; 17 | 18 | #endif // MIMEINLINEFILE_H 19 | -------------------------------------------------------------------------------- /qemail/mimemessage.cpp: -------------------------------------------------------------------------------- 1 | #include "mimemessage.h" 2 | 3 | #include 4 | #include "quotedprintable.h" 5 | #include 6 | 7 | MimeMessage::MimeMessage(bool createAutoMimeContent) : 8 | hEncoding(MimePart::_8Bit) 9 | { 10 | if (createAutoMimeContent) { 11 | this->content = new MimeMultiPart(); 12 | } 13 | } 14 | 15 | MimeMessage::~MimeMessage() 16 | { 17 | } 18 | 19 | MimePart &MimeMessage::getContent() 20 | { 21 | return *content; 22 | } 23 | 24 | void MimeMessage::setContent(MimePart *content) 25 | { 26 | this->content = content; 27 | } 28 | 29 | void MimeMessage::setSender(EmailAddress *e) 30 | { 31 | this->sender = e; 32 | } 33 | 34 | void MimeMessage::addRecipient(EmailAddress *rcpt, RecipientType type) 35 | { 36 | switch (type) { 37 | case To: 38 | recipientsTo << rcpt; 39 | break; 40 | 41 | case Cc: 42 | recipientsCc << rcpt; 43 | break; 44 | 45 | case Bcc: 46 | recipientsBcc << rcpt; 47 | break; 48 | } 49 | } 50 | 51 | void MimeMessage::addTo(EmailAddress *rcpt) 52 | { 53 | this->recipientsTo << rcpt; 54 | } 55 | 56 | void MimeMessage::addCc(EmailAddress *rcpt) 57 | { 58 | this->recipientsCc << rcpt; 59 | } 60 | 61 | void MimeMessage::addBcc(EmailAddress *rcpt) 62 | { 63 | this->recipientsBcc << rcpt; 64 | } 65 | 66 | void MimeMessage::setSubject(const QString &subject) 67 | { 68 | this->subject = subject; 69 | } 70 | 71 | void MimeMessage::addPart(MimePart *part) 72 | { 73 | if (typeid(*content) == typeid(MimeMultiPart)) { 74 | ((MimeMultiPart *) content)->addPart(part); 75 | }; 76 | } 77 | 78 | void MimeMessage::setHeaderEncoding(MimePart::Encoding hEnc) 79 | { 80 | this->hEncoding = hEnc; 81 | } 82 | 83 | const EmailAddress &MimeMessage::getSender() const 84 | { 85 | return *sender; 86 | } 87 | 88 | const QList &MimeMessage::getRecipients(RecipientType type) const 89 | { 90 | switch (type) { 91 | default: 92 | case To: 93 | return recipientsTo; 94 | 95 | case Cc: 96 | return recipientsCc; 97 | 98 | case Bcc: 99 | return recipientsBcc; 100 | } 101 | } 102 | 103 | const QString &MimeMessage::getSubject() const 104 | { 105 | return subject; 106 | } 107 | 108 | const QList &MimeMessage::getParts() const 109 | { 110 | if (typeid(*content) == typeid(MimeMultiPart)) { 111 | return ((MimeMultiPart *) content)->getParts(); 112 | } else { 113 | QList *res = new QList(); 114 | res->append(content); 115 | return *res; 116 | } 117 | } 118 | 119 | QString MimeMessage::toString() 120 | { 121 | QString mime; 122 | 123 | mime = "From:"; 124 | 125 | if (sender->getName() != "") { 126 | switch (hEncoding) { 127 | case MimePart::Base64: 128 | mime += " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?="; 129 | break; 130 | 131 | case MimePart::QuotedPrintable: 132 | mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(sender->getName())).replace(' ', "_").replace(':', "=3A") + "?="; 133 | break; 134 | 135 | default: 136 | mime += " " + sender->getName(); 137 | } 138 | } 139 | 140 | mime += " <" + sender->getAddress() + ">\r\n"; 141 | 142 | mime += "To:"; 143 | QList::iterator it; 144 | int i; 145 | 146 | for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) { 147 | if (i != 0) { 148 | mime += ","; 149 | } 150 | 151 | if ((*it)->getName() != "") { 152 | switch (hEncoding) { 153 | case MimePart::Base64: 154 | mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; 155 | break; 156 | 157 | case MimePart::QuotedPrintable: 158 | mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':', "=3A") + "?="; 159 | break; 160 | 161 | default: 162 | mime += " " + (*it)->getName(); 163 | } 164 | } 165 | 166 | mime += " <" + (*it)->getAddress() + ">"; 167 | } 168 | 169 | mime += "\r\n"; 170 | 171 | if (recipientsCc.size() != 0) { 172 | mime += "Cc:"; 173 | } 174 | 175 | for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) { 176 | if (i != 0) { 177 | mime += ","; 178 | } 179 | 180 | if ((*it)->getName() != "") { 181 | switch (hEncoding) { 182 | case MimePart::Base64: 183 | mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; 184 | break; 185 | 186 | case MimePart::QuotedPrintable: 187 | mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':', "=3A") + "?="; 188 | break; 189 | 190 | default: 191 | mime += " " + (*it)->getName(); 192 | } 193 | } 194 | 195 | mime += " <" + (*it)->getAddress() + ">"; 196 | } 197 | 198 | if (recipientsCc.size() != 0) { 199 | mime += "\r\n"; 200 | } 201 | 202 | mime += "Subject: "; 203 | 204 | switch (hEncoding) { 205 | case MimePart::Base64: 206 | mime += "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?="; 207 | break; 208 | 209 | case MimePart::QuotedPrintable: 210 | mime += "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject)).replace(' ', "_").replace(':', "=3A") + "?="; 211 | break; 212 | 213 | default: 214 | mime += subject; 215 | } 216 | 217 | mime += "\r\n"; 218 | mime += "MIME-Version: 1.0\r\n"; 219 | 220 | mime += content->toString(); 221 | return mime; 222 | } 223 | -------------------------------------------------------------------------------- /qemail/mimemessage.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEMESSAGE_H 2 | #define MIMEMESSAGE_H 3 | 4 | #include "mimepart.h" 5 | #include "mimemultipart.h" 6 | #include "emailaddress.h" 7 | #include 8 | 9 | class MimeMessage : public QObject 10 | { 11 | public: 12 | 13 | enum RecipientType { 14 | To, // primary 15 | Cc, // carbon copy 16 | Bcc // blind carbon copy 17 | }; 18 | 19 | 20 | MimeMessage(bool createAutoMimeConent = true); 21 | ~MimeMessage(); 22 | 23 | void setSender(EmailAddress *e); 24 | void addRecipient(EmailAddress *rcpt, RecipientType type = To); 25 | void addTo(EmailAddress *rcpt); 26 | void addCc(EmailAddress *rcpt); 27 | void addBcc(EmailAddress *rcpt); 28 | void setSubject(const QString &subject); 29 | void addPart(MimePart *part); 30 | 31 | void setHeaderEncoding(MimePart::Encoding); 32 | 33 | const EmailAddress &getSender() const; 34 | const QList &getRecipients(RecipientType type = To) const; 35 | const QString &getSubject() const; 36 | const QList &getParts() const; 37 | 38 | MimePart &getContent(); 39 | void setContent(MimePart *content); 40 | 41 | virtual QString toString(); 42 | 43 | 44 | protected: 45 | EmailAddress *sender; 46 | QList recipientsTo, recipientsCc, recipientsBcc; 47 | QString subject; 48 | MimePart *content; 49 | 50 | MimePart::Encoding hEncoding; 51 | 52 | }; 53 | 54 | #endif // MIMEMESSAGE_H 55 | -------------------------------------------------------------------------------- /qemail/mimemultipart.cpp: -------------------------------------------------------------------------------- 1 | #include "mimemultipart.h" 2 | #include 3 | #include 4 | 5 | const QString MULTI_PART_NAMES[] = { 6 | "multipart/mixed", // Mixed 7 | "multipart/digest", // Digest 8 | "multipart/alternative", // Alternative 9 | "multipart/related", // Related 10 | "multipart/report", // Report 11 | "multipart/signed", // Signed 12 | "multipart/encrypted" // Encrypted 13 | }; 14 | 15 | MimeMultiPart::MimeMultiPart(MultiPartType type) 16 | { 17 | this->type = type; 18 | this->cType = MULTI_PART_NAMES[this->type]; 19 | this->cEncoding = _8Bit; 20 | 21 | QCryptographicHash md5(QCryptographicHash::Md5); 22 | md5.addData(QByteArray().append(qrand())); 23 | cBoundary = md5.result().toHex(); 24 | } 25 | 26 | MimeMultiPart::~MimeMultiPart() 27 | { 28 | 29 | } 30 | 31 | void MimeMultiPart::addPart(MimePart *part) 32 | { 33 | parts.append(part); 34 | } 35 | 36 | const QList &MimeMultiPart::getParts() const 37 | { 38 | return parts; 39 | } 40 | 41 | void MimeMultiPart::prepare() 42 | { 43 | QList::iterator it; 44 | 45 | content = ""; 46 | 47 | for (it = parts.begin(); it != parts.end(); it++) { 48 | content += "--" + cBoundary + "\r\n"; 49 | (*it)->prepare(); 50 | content += (*it)->toString(); 51 | }; 52 | 53 | content += "--" + cBoundary + "--\r\n"; 54 | 55 | MimePart::prepare(); 56 | } 57 | 58 | void MimeMultiPart::setMimeType(const MultiPartType type) 59 | { 60 | this->type = type; 61 | this->cType = MULTI_PART_NAMES[type]; 62 | } 63 | 64 | MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const 65 | { 66 | return type; 67 | } 68 | -------------------------------------------------------------------------------- /qemail/mimemultipart.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEMULTIPART_H 2 | #define MIMEMULTIPART_H 3 | 4 | #include "mimepart.h" 5 | 6 | class MimeMultiPart : public MimePart 7 | { 8 | Q_OBJECT 9 | public: 10 | enum MultiPartType { 11 | Mixed = 0, // RFC 2046, section 5.1.3 12 | Digest = 1, // RFC 2046, section 5.1.5 13 | Alternative = 2, // RFC 2046, section 5.1.4 14 | Related = 3, // RFC 2387 15 | Report = 4, // RFC 6522 16 | Signed = 5, // RFC 1847, section 2.1 17 | Encrypted = 6 // RFC 1847, section 2.2 18 | }; 19 | 20 | MimeMultiPart(const MultiPartType type = Related); 21 | ~MimeMultiPart(); 22 | 23 | void setMimeType(const MultiPartType type); 24 | MultiPartType getMimeType() const; 25 | 26 | const QList &getParts() const; 27 | 28 | void addPart(MimePart *part); 29 | virtual void prepare(); 30 | 31 | protected: 32 | QList parts; 33 | MultiPartType type; 34 | 35 | }; 36 | 37 | #endif // MIMEMULTIPART_H 38 | -------------------------------------------------------------------------------- /qemail/mimepart.cpp: -------------------------------------------------------------------------------- 1 | #include "mimepart.h" 2 | #include "quotedprintable.h" 3 | 4 | MimePart::MimePart() 5 | { 6 | cEncoding = _7Bit; 7 | prepared = false; 8 | cBoundary = ""; 9 | } 10 | 11 | MimePart::~MimePart() 12 | { 13 | return; 14 | } 15 | 16 | void MimePart::setContent(const QByteArray &content) 17 | { 18 | this->content = content; 19 | } 20 | 21 | void MimePart::setHeader(const QString &header) 22 | { 23 | this->header = header; 24 | } 25 | 26 | void MimePart::addHeaderLine(const QString &line) 27 | { 28 | this->header += line + "\r\n"; 29 | } 30 | 31 | const QString &MimePart::getHeader() const 32 | { 33 | return header; 34 | } 35 | 36 | const QByteArray &MimePart::getContent() const 37 | { 38 | return content; 39 | } 40 | 41 | void MimePart::setContentId(const QString &cId) 42 | { 43 | this->cId = cId; 44 | } 45 | 46 | const QString &MimePart::getContentId() const 47 | { 48 | return this->cId; 49 | } 50 | 51 | void MimePart::setContentName(const QString &cName) 52 | { 53 | this->cName = cName; 54 | } 55 | 56 | const QString &MimePart::getContentName() const 57 | { 58 | return this->cName; 59 | } 60 | 61 | void MimePart::setContentType(const QString &cType) 62 | { 63 | this->cType = cType; 64 | } 65 | 66 | const QString &MimePart::getContentType() const 67 | { 68 | return this->cType; 69 | } 70 | 71 | void MimePart::setCharset(const QString &charset) 72 | { 73 | this->cCharset = charset; 74 | } 75 | 76 | const QString &MimePart::getCharset() const 77 | { 78 | return this->cCharset; 79 | } 80 | 81 | void MimePart::setEncoding(Encoding enc) 82 | { 83 | this->cEncoding = enc; 84 | } 85 | 86 | MimePart::Encoding MimePart::getEncoding() const 87 | { 88 | return this->cEncoding; 89 | } 90 | 91 | MimeContentFormatter &MimePart::getContentFormatter() 92 | { 93 | return this->formatter; 94 | } 95 | 96 | QString MimePart::toString() 97 | { 98 | if (!prepared) { 99 | prepare(); 100 | } 101 | 102 | return mimeString; 103 | } 104 | 105 | void MimePart::prepare() 106 | { 107 | mimeString = QString(); 108 | 109 | mimeString.append("Content-Type: ").append(cType); 110 | 111 | if (cName != "") { 112 | mimeString.append("; name=\"").append(cName).append("\""); 113 | } 114 | 115 | if (cCharset != "") { 116 | mimeString.append("; charset=").append(cCharset); 117 | } 118 | 119 | if (cBoundary != "") { 120 | mimeString.append("; boundary=").append(cBoundary); 121 | } 122 | 123 | mimeString.append("\r\n"); 124 | 125 | mimeString.append("Content-Transfer-Encoding: "); 126 | 127 | switch (cEncoding) { 128 | case _7Bit: 129 | mimeString.append("7bit\r\n"); 130 | break; 131 | 132 | case _8Bit: 133 | mimeString.append("8bit\r\n"); 134 | break; 135 | 136 | case Base64: 137 | mimeString.append("base64\r\n"); 138 | break; 139 | 140 | case QuotedPrintable: 141 | mimeString.append("quoted-printable\r\n"); 142 | break; 143 | } 144 | 145 | if (cId != 0) { 146 | mimeString.append("Content-ID: <").append(cId).append(">\r\n"); 147 | } 148 | 149 | mimeString.append(header).append("\r\n"); 150 | 151 | switch (cEncoding) { 152 | case _7Bit: 153 | mimeString.append(QString(content).toLatin1()); 154 | break; 155 | 156 | case _8Bit: 157 | mimeString.append(content); 158 | break; 159 | 160 | case Base64: 161 | mimeString.append(formatter.format(content.toBase64())); 162 | break; 163 | 164 | case QuotedPrintable: 165 | mimeString.append(formatter.format(QuotedPrintable::encode(content), true)); 166 | break; 167 | } 168 | 169 | mimeString.append("\r\n"); 170 | prepared = true; 171 | } 172 | -------------------------------------------------------------------------------- /qemail/mimepart.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEPART_H 2 | #define MIMEPART_H 3 | 4 | #include 5 | #include "mimecontentformatter.h" 6 | 7 | class MimePart : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | enum Encoding { 12 | _7Bit, 13 | _8Bit, 14 | Base64, 15 | QuotedPrintable 16 | }; 17 | 18 | MimePart(); 19 | ~MimePart(); 20 | 21 | const QString &getHeader() const; 22 | const QByteArray &getContent() const; 23 | 24 | void setContent(const QByteArray &content); 25 | void setHeader(const QString &header); 26 | 27 | void addHeaderLine(const QString &line); 28 | 29 | void setContentId(const QString &cId); 30 | const QString &getContentId() const; 31 | 32 | void setContentName(const QString &cName); 33 | const QString &getContentName() const; 34 | 35 | void setContentType(const QString &cType); 36 | const QString &getContentType() const; 37 | 38 | void setCharset(const QString &charset); 39 | const QString &getCharset() const; 40 | 41 | void setEncoding(Encoding enc); 42 | Encoding getEncoding() const; 43 | 44 | MimeContentFormatter &getContentFormatter(); 45 | 46 | virtual QString toString(); 47 | virtual void prepare(); 48 | 49 | protected: 50 | QString header; 51 | QByteArray content; 52 | 53 | QString cId; 54 | QString cName; 55 | QString cType; 56 | QString cCharset; 57 | QString cBoundary; 58 | Encoding cEncoding; 59 | 60 | QString mimeString; 61 | bool prepared; 62 | 63 | MimeContentFormatter formatter; 64 | 65 | }; 66 | 67 | #endif // MIMEPART_H 68 | -------------------------------------------------------------------------------- /qemail/mimetext.cpp: -------------------------------------------------------------------------------- 1 | #include "mimetext.h" 2 | 3 | MimeText::MimeText(const QString &txt) 4 | { 5 | this->text = txt; 6 | this->cType = "text/plain"; 7 | this->cCharset = "utf-8"; 8 | this->cEncoding = _8Bit; 9 | } 10 | 11 | MimeText::~MimeText() { } 12 | 13 | void MimeText::setText(const QString &text) 14 | { 15 | this->text = text; 16 | } 17 | 18 | const QString &MimeText::getText() const 19 | { 20 | return text; 21 | } 22 | 23 | void MimeText::prepare() 24 | { 25 | this->content.clear(); 26 | this->content.append(text); 27 | MimePart::prepare(); 28 | } 29 | -------------------------------------------------------------------------------- /qemail/mimetext.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMETEXT_H 2 | #define MIMETEXT_H 3 | 4 | #include "mimepart.h" 5 | 6 | class MimeText : public MimePart 7 | { 8 | public: 9 | 10 | MimeText(const QString &text = ""); 11 | ~MimeText(); 12 | 13 | void setText(const QString &text); 14 | const QString &getText() const; 15 | 16 | protected: 17 | QString text; 18 | void prepare(); 19 | 20 | }; 21 | 22 | #endif // MIMETEXT_H 23 | -------------------------------------------------------------------------------- /qemail/qemail.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/emailaddress.h \ 3 | $$PWD/mimeattachment.h \ 4 | $$PWD/mimecontentformatter.h \ 5 | $$PWD/mimefile.h \ 6 | $$PWD/mimehtml.h \ 7 | $$PWD/mimeinlinefile.h \ 8 | $$PWD/mimemessage.h \ 9 | $$PWD/mimemultipart.h \ 10 | $$PWD/mimepart.h \ 11 | $$PWD/mimetext.h \ 12 | $$PWD/quotedprintable.h \ 13 | $$PWD/smtpclient.h \ 14 | $$PWD/smtpmime.h 15 | 16 | SOURCES += \ 17 | $$PWD/emailaddress.cpp \ 18 | $$PWD/mimeattachment.cpp \ 19 | $$PWD/mimecontentformatter.cpp \ 20 | $$PWD/mimefile.cpp \ 21 | $$PWD/mimehtml.cpp \ 22 | $$PWD/mimeinlinefile.cpp \ 23 | $$PWD/mimemessage.cpp \ 24 | $$PWD/mimemultipart.cpp \ 25 | $$PWD/mimepart.cpp \ 26 | $$PWD/mimetext.cpp \ 27 | $$PWD/quotedprintable.cpp \ 28 | $$PWD/smtpclient.cpp 29 | -------------------------------------------------------------------------------- /qemail/quotedprintable.cpp: -------------------------------------------------------------------------------- 1 | #include "quotedprintable.h" 2 | 3 | QString &QuotedPrintable::encode(const QByteArray &input) 4 | { 5 | QString *output = new QString(); 6 | 7 | char byte; 8 | const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 9 | 10 | for (int i = 0; i < input.length() ; ++i) { 11 | byte = input.at(i); 12 | 13 | if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) { 14 | output->append(byte); 15 | } else { 16 | output->append('='); 17 | output->append(hex[((byte >> 4) & 0x0F)]); 18 | output->append(hex[(byte & 0x0F)]); 19 | } 20 | } 21 | 22 | return *output; 23 | } 24 | 25 | 26 | QByteArray &QuotedPrintable::decode(const QString &input) 27 | { 28 | // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F 29 | const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; 30 | 31 | QByteArray *output = new QByteArray(); 32 | 33 | for (int i = 0; i < input.length(); ++i) { 34 | if (input.at(i).toLatin1() == '=') { 35 | int index = ++i; 36 | output->append((hexVal[input.at(index).toLatin1() - '0'] << 4) + hexVal[input.at(++i).toLatin1() - '0']); 37 | } else { 38 | output->append(input.at(i).toLatin1()); 39 | } 40 | } 41 | 42 | return *output; 43 | } 44 | -------------------------------------------------------------------------------- /qemail/quotedprintable.h: -------------------------------------------------------------------------------- 1 | #ifndef QUOTEDPRINTABLE_H 2 | #define QUOTEDPRINTABLE_H 3 | 4 | #include 5 | #include 6 | 7 | class QuotedPrintable : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | 12 | static QString &encode(const QByteArray &input); 13 | static QByteArray &decode(const QString &input); 14 | 15 | private: 16 | QuotedPrintable(); 17 | }; 18 | 19 | #endif // QUOTEDPRINTABLE_H 20 | -------------------------------------------------------------------------------- /qemail/smtpclient.h: -------------------------------------------------------------------------------- 1 | #ifndef SMTPCLIENT_H 2 | #define SMTPCLIENT_H 3 | 4 | #include 5 | #include 6 | 7 | #include "mimemessage.h" 8 | 9 | 10 | class SmtpClient : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | 15 | enum AuthMethod { 16 | AuthPlain, 17 | AuthLogin 18 | }; 19 | 20 | enum SmtpError { 21 | ConnectionTimeoutError, 22 | ResponseTimeoutError, 23 | AuthenticationFailedError, 24 | ServerError, // 4xx smtp error 25 | ClientError // 5xx smtp error 26 | }; 27 | 28 | enum ConnectionType { 29 | TcpConnection, 30 | SslConnection, 31 | TlsConnection // STARTTLS 32 | }; 33 | 34 | SmtpClient(const QString &host = "locahost", int port = 25, ConnectionType ct = TcpConnection); 35 | 36 | ~SmtpClient(); 37 | 38 | const QString &getHost() const; 39 | void setHost(QString &host); 40 | 41 | int getPort() const; 42 | void setPort(int port); 43 | 44 | const QString &getName() const; 45 | void setName(const QString &name); 46 | 47 | ConnectionType getConnectionType() const; 48 | void setConnectionType(ConnectionType ct); 49 | 50 | const QString &getUser() const; 51 | void setUser(const QString &host); 52 | 53 | const QString &getPassword() const; 54 | void setPassword(const QString &password); 55 | 56 | SmtpClient::AuthMethod getAuthMethod() const; 57 | void setAuthMethod(AuthMethod method); 58 | 59 | const QString &getResponseText() const; 60 | int getResponseCode() const; 61 | 62 | int getConnectionTimeout() const; 63 | void setConnectionTimeout(int msec); 64 | 65 | int getResponseTimeout() const; 66 | void setResponseTimeout(int msec); 67 | 68 | QTcpSocket *getSocket(); 69 | 70 | bool connectToHost(); 71 | bool login(); 72 | bool login(const QString &user, const QString &password, AuthMethod method = AuthLogin); 73 | 74 | bool sendMail(MimeMessage &email); 75 | void quit(); 76 | 77 | protected: 78 | QTcpSocket *socket; 79 | QString host; 80 | int port; 81 | ConnectionType connectionType; 82 | QString name; 83 | 84 | QString user; 85 | QString password; 86 | AuthMethod authMethod; 87 | 88 | int connectionTimeout; 89 | int responseTimeout; 90 | 91 | QString responseText; 92 | int responseCode; 93 | 94 | 95 | class ResponseTimeoutException {}; 96 | void waitForResponse() throw (ResponseTimeoutException); 97 | void sendMessage(const QString &text); 98 | 99 | signals: 100 | void smtpError(SmtpError e); 101 | 102 | }; 103 | 104 | #endif // SMTPCLIENT_H 105 | -------------------------------------------------------------------------------- /qemail/smtpmime.h: -------------------------------------------------------------------------------- 1 | #ifndef SMTPMIME_H 2 | #define SMTPMIME_H 3 | 4 | #include "smtpclient.h" 5 | #include "mimepart.h" 6 | #include "mimehtml.h" 7 | #include "mimeattachment.h" 8 | #include "mimemessage.h" 9 | #include "mimetext.h" 10 | #include "mimeinlinefile.h" 11 | #include "mimefile.h" 12 | 13 | #endif // SMTPMIME_H 14 | -------------------------------------------------------------------------------- /qextserialport/qextserialport.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/qextserialport.h \ 3 | $$PWD/qextserialport_global.h \ 4 | $$PWD/qextserialport_p.h 5 | 6 | SOURCES += $$PWD/qextserialport.cpp 7 | 8 | win32:SOURCES += $$PWD/qextserialport_win.cpp 9 | unix:SOURCES += $$PWD/qextserialport_unix.cpp 10 | -------------------------------------------------------------------------------- /qextserialport/qextserialport_global.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (c) 2000-2003 Wayne Roth 3 | ** Copyright (c) 2004-2007 Stefan Sander 4 | ** Copyright (c) 2007 Michal Policht 5 | ** Copyright (c) 2008 Brandon Fosdick 6 | ** Copyright (c) 2009-2010 Liam Staskawicz 7 | ** Copyright (c) 2011 Debao Zhang 8 | ** All right reserved. 9 | ** Web: http://code.google.com/p/qextserialport/ 10 | ** 11 | ** Permission is hereby granted, free of charge, to any person obtaining 12 | ** a copy of this software and associated documentation files (the 13 | ** "Software"), to deal in the Software without restriction, including 14 | ** without limitation the rights to use, copy, modify, merge, publish, 15 | ** distribute, sublicense, and/or sell copies of the Software, and to 16 | ** permit persons to whom the Software is furnished to do so, subject to 17 | ** the following conditions: 18 | ** 19 | ** The above copyright notice and this permission notice shall be 20 | ** included in all copies or substantial portions of the Software. 21 | ** 22 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 | ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 | ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 | ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 | ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | ** 30 | ****************************************************************************/ 31 | 32 | #ifndef QEXTSERIALPORT_GLOBAL_H 33 | #define QEXTSERIALPORT_GLOBAL_H 34 | 35 | #include 36 | 37 | #ifdef QEXTSERIALPORT_BUILD_SHARED 38 | # define QEXTSERIALPORT_EXPORT Q_DECL_EXPORT 39 | #elif defined(QEXTSERIALPORT_USING_SHARED) 40 | # define QEXTSERIALPORT_EXPORT Q_DECL_IMPORT 41 | #else 42 | # define QEXTSERIALPORT_EXPORT 43 | #endif 44 | 45 | // ### for compatible with old version. should be removed in QESP 2.0 46 | #ifdef _TTY_NOWARN_ 47 | # define QESP_NO_WARN 48 | #endif 49 | #ifdef _TTY_NOWARN_PORT_ 50 | # define QESP_NO_PORTABILITY_WARN 51 | #endif 52 | 53 | /*if all warning messages are turned off, flag portability warnings to be turned off as well*/ 54 | #ifdef QESP_NO_WARN 55 | # define QESP_NO_PORTABILITY_WARN 56 | #endif 57 | 58 | /*macros for warning and debug messages*/ 59 | #ifdef QESP_NO_PORTABILITY_WARN 60 | # define QESP_PORTABILITY_WARNING while (false)qWarning 61 | #else 62 | # define QESP_PORTABILITY_WARNING qWarning 63 | #endif /*QESP_NOWARN_PORT*/ 64 | 65 | #ifdef QESP_NO_WARN 66 | # define QESP_WARNING while (false)qWarning 67 | #else 68 | # define QESP_WARNING qWarning 69 | #endif /*QESP_NOWARN*/ 70 | 71 | #endif // QEXTSERIALPORT_GLOBAL_H 72 | 73 | -------------------------------------------------------------------------------- /usercontrol/combobox.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "combobox.h" 6 | #include "qlistview.h" 7 | 8 | ComboBox::ComboBox(QWidget *parent) : QComboBox(parent) 9 | { 10 | this->setView(new QListView()); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /usercontrol/combobox.h: -------------------------------------------------------------------------------- 1 | #ifndef COMBOBOX_H 2 | #define COMBOBOX_H 3 | 4 | #include 5 | 6 | class ComboBox : public QComboBox 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit ComboBox(QWidget *parent = 0); 11 | 12 | signals: 13 | 14 | public slots: 15 | }; 16 | 17 | #endif // COMBOBOX_H 18 | -------------------------------------------------------------------------------- /usercontrol/defencebutton.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "defencebutton.h" 6 | #include "api/myhelper.h" 7 | #include "api/app.h" 8 | 9 | DefenceButton::DefenceButton(QWidget *parent) : QWidget(parent) 10 | { 11 | this->setCursor(QCursor(Qt::PointingHandCursor)); 12 | this->defenceID = ""; 13 | this->defenceName = ""; 14 | this->subSystem = 0; 15 | this->defenceSound = ""; 16 | this->defenceImage = ""; 17 | this->defenceX = 0; 18 | this->defenceY = 0; 19 | this->defenceStatus = Status_GuZhang; 20 | 21 | currentRG = new QRadialGradient(0, 0, 80); 22 | currentRG->setColorAt(0, QColor(50, 50, 50)); 23 | currentRG->setColorAt(0.6, QColor(30, 30, 30)); 24 | currentRG->setColorAt(1, QColor(10, 10, 10)); 25 | 26 | IsRed = false; 27 | timerAlarm = new QTimer(this); 28 | timerAlarm->setInterval(500); 29 | connect(timerAlarm, SIGNAL(timeout()), this, SLOT(BaoJingChange())); 30 | 31 | this->installEventFilter(this);//安装监听器,监听鼠标拖动 32 | } 33 | 34 | DefenceButton::DefenceButton(QWidget *parent, QString defenceID, QString defenceName, 35 | int subSystem, QString defenceSound, QString defenceImage, 36 | int defenceX, int defenceY, Status defenceStatus): 37 | QWidget(parent) 38 | { 39 | this->setCursor(QCursor(Qt::PointingHandCursor)); 40 | this->defenceID = defenceID; 41 | this->defenceName = defenceName; 42 | this->subSystem = subSystem; 43 | this->defenceSound = defenceSound; 44 | this->defenceImage = defenceImage; 45 | this->defenceX = defenceX; 46 | this->defenceY = defenceY; 47 | this->defenceStatus = defenceStatus; 48 | 49 | currentRG = new QRadialGradient(0, 0, 80); 50 | currentRG->setColorAt(0, QColor(50, 50, 50)); 51 | currentRG->setColorAt(0.6, QColor(30, 30, 30)); 52 | currentRG->setColorAt(1, QColor(10, 10, 10)); 53 | 54 | IsRed = false; 55 | timerAlarm = new QTimer(this); 56 | timerAlarm->setInterval(500); 57 | connect(timerAlarm, SIGNAL(timeout()), this, SLOT(BaoJingChange())); 58 | 59 | this->installEventFilter(this);//安装监听器,监听鼠标拖动 60 | } 61 | 62 | bool DefenceButton::eventFilter(QObject *, QEvent *evt) 63 | { 64 | if (App::IsMove) { 65 | static QPoint lastPnt; 66 | static bool isHover = false; 67 | 68 | if (evt->type() == QEvent::MouseButtonPress) { 69 | QMouseEvent *e = static_cast(evt); 70 | if (this->rect().contains(e->pos()) && (e->button() == Qt::LeftButton)) { 71 | lastPnt = e->pos(); 72 | isHover = true; 73 | } 74 | } else if (evt->type() == QEvent::MouseMove && isHover) { 75 | QMouseEvent *e = static_cast(evt); 76 | int dx = e->pos().x() - lastPnt.x(); 77 | int dy = e->pos().y() - lastPnt.y(); 78 | this->move(this->x() + dx, this->y() + dy); 79 | } else if (evt->type() == QEvent::MouseButtonRelease && isHover) { 80 | isHover = false; 81 | } 82 | } 83 | 84 | return false; 85 | } 86 | 87 | void DefenceButton::BaoJingChange() 88 | { 89 | if (IsRed) { 90 | currentRG->setColorAt(0, QColor(50, 50, 50)); 91 | currentRG->setColorAt(0.6, QColor(30, 30, 30)); 92 | currentRG->setColorAt(1, QColor(10, 10, 10)); 93 | IsRed = false; 94 | } else { 95 | currentRG->setColorAt(0, QColor(255, 0, 0)); 96 | currentRG->setColorAt(0.6, QColor(230, 0, 0)); 97 | currentRG->setColorAt(1, QColor(204, 0, 0)); 98 | IsRed = true; 99 | } 100 | update(); 101 | } 102 | 103 | void DefenceButton::paintEvent(QPaintEvent *) 104 | { 105 | QPainter painter(this); 106 | 107 | //设置坐标和缩放 108 | painter.save(); 109 | painter.setRenderHint(QPainter::Antialiasing); /* 使用反锯齿(如果可用) */ 110 | painter.translate(width() / 2, height() / 2); /* 坐标变换为窗体中心 */ 111 | int side = qMin(width(), height()); 112 | painter.scale(side / 200.0, side / 200.0); /* 比例缩放 */ 113 | painter.setPen(Qt::NoPen); 114 | 115 | //画外边框 116 | int radius = 100; 117 | QLinearGradient lg1(0, -radius, 0, radius); 118 | lg1.setColorAt(0, QColor(255, 255, 255)); 119 | lg1.setColorAt(1, QColor(166, 166, 166)); 120 | painter.setBrush(lg1); 121 | painter.drawEllipse(-radius, -radius, radius << 1, radius << 1); 122 | 123 | //画内边框 124 | radius -= 13; 125 | QLinearGradient lg2(0, -radius, 0, radius); 126 | lg2.setColorAt(0, QColor(166, 166, 166)); 127 | lg2.setColorAt(1, QColor(255, 255, 255)); 128 | painter.setBrush(lg2); 129 | painter.drawEllipse(-radius, -radius, radius << 1, radius << 1); 130 | 131 | //画内部指示颜色 132 | radius -= 4; 133 | painter.setBrush(*currentRG); 134 | painter.drawEllipse(-radius, -radius, radius << 1, radius << 1); 135 | painter.restore(); 136 | 137 | //画防区号文字 138 | painter.save(); 139 | this->setGeometry(this->geometry().left(), this->geometry().top(), 25, 25); 140 | QFont font("Arial", 8, QFont::Bold, false); 141 | painter.setFont(font); 142 | QPen pen(QColor(255, 255, 255)); 143 | painter.setPen(pen); 144 | painter.drawText(rect(), Qt::AlignCenter, this->defenceID); 145 | painter.restore(); 146 | } 147 | 148 | void DefenceButton::SetDefenceID(QString defenceID) 149 | { 150 | if (this->defenceID != defenceID) { 151 | this->defenceID = defenceID; 152 | update(); 153 | } 154 | } 155 | 156 | void DefenceButton::SetDefenceStatus(Status defenceStatus) 157 | { 158 | if (this->defenceStatus != defenceStatus) { 159 | this->defenceStatus = defenceStatus; 160 | 161 | if (defenceStatus == Status_BuFang) { 162 | timerAlarm->stop(); 163 | currentRG->setColorAt(0, QColor(68, 187, 92)); 164 | currentRG->setColorAt(0.6, QColor(59, 162, 80)); 165 | currentRG->setColorAt(1, QColor(54, 150, 74)); 166 | update(); 167 | } else if (defenceStatus == Status_CheFang) { 168 | timerAlarm->stop(); 169 | currentRG->setColorAt(0, QColor(0, 0, 245)); 170 | currentRG->setColorAt(0.6, QColor(0, 0, 210)); 171 | currentRG->setColorAt(1, QColor(0, 0, 166)); 172 | update(); 173 | } else if (defenceStatus == Status_PangLu) { 174 | timerAlarm->stop(); 175 | currentRG->setColorAt(0, QColor(180, 180, 180)); 176 | currentRG->setColorAt(0.6, QColor(140, 140, 140)); 177 | currentRG->setColorAt(1, QColor(129, 129, 129)); 178 | update(); 179 | } else if (defenceStatus == Status_DuanKai) { 180 | timerAlarm->stop(); 181 | currentRG->setColorAt(0, QColor(145, 185, 235)); 182 | currentRG->setColorAt(0.6, QColor(120, 170, 215)); 183 | currentRG->setColorAt(1, QColor(102, 153, 204)); 184 | update(); 185 | } else if (defenceStatus == Status_GuZhang) { 186 | timerAlarm->stop(); 187 | currentRG->setColorAt(0, QColor(50, 50, 50)); 188 | currentRG->setColorAt(0.6, QColor(30, 30, 30)); 189 | currentRG->setColorAt(1, QColor(10, 10, 10)); 190 | update(); 191 | } else if (defenceStatus == Status_BaoJing) { 192 | timerAlarm->start(); 193 | } 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /usercontrol/defencebutton.h: -------------------------------------------------------------------------------- 1 | #ifndef DEFENCEBUTTON_H 2 | #define DEFENCEBUTTON_H 3 | 4 | #include 5 | #include 6 | 7 | class DefenceButton: public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | 12 | //防区状态 布防、撤防、报警、旁路、断开、故障 13 | enum Status { 14 | Status_BuFang = 0, 15 | Status_CheFang = 1, 16 | Status_BaoJing = 2, 17 | Status_PangLu = 3, 18 | Status_DuanKai = 4, 19 | Status_GuZhang = 5 20 | }; 21 | 22 | explicit DefenceButton(QWidget *parent = 0); 23 | 24 | //构造函数,直接传入一个防区所需要的所有属性 25 | explicit DefenceButton(QWidget *parent, QString defenceID, QString defenceName, 26 | int subSystem, QString defenceSound, QString defenceImage, 27 | int defenceX, int defenceY, Status defenceStatus); 28 | 29 | void SetDefenceID(QString defenceID); 30 | void SetDefenceStatus(Status defenceStatus); 31 | 32 | QString DefenceID()const { 33 | return defenceID; 34 | } 35 | QString DefenceName()const { 36 | return defenceName; 37 | } 38 | int SubSystem()const { 39 | return subSystem; 40 | } 41 | QString DefenceSound()const { 42 | return defenceSound; 43 | } 44 | QString DefenceImage()const { 45 | return defenceImage; 46 | } 47 | int DefenceX()const { 48 | return defenceX; 49 | } 50 | int DefenceY()const { 51 | return defenceY; 52 | } 53 | Status DefenceStatus()const { 54 | return defenceStatus; 55 | } 56 | 57 | signals: 58 | 59 | protected: 60 | void paintEvent(QPaintEvent *event); //重写绘制函数 61 | bool eventFilter(QObject *, QEvent *); //过滤鼠标按下事件 62 | 63 | private slots: 64 | void BaoJingChange(); //执行报警改变操作 65 | 66 | private: 67 | QString defenceID; //防区号 68 | QString defenceName; //防区名 69 | int subSystem; //防区对应子系统 70 | QString defenceSound; //防区报警声音 71 | QString defenceImage; //防区地图 72 | int defenceX; //防区X坐标 73 | int defenceY; //防区Y坐标 74 | Status defenceStatus; //防区状态 75 | 76 | QRadialGradient *currentRG; //当前颜色 77 | bool IsRed; //当前报警颜色是否为红色 78 | QTimer *timerAlarm; //控制报警闪烁时钟 79 | 80 | }; 81 | 82 | #endif //DEFENCEBUTTON_H 83 | -------------------------------------------------------------------------------- /usercontrol/frminputbox.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frminputbox.h" 6 | #include "ui_frminputbox.h" 7 | #include "api/myhelper.h" 8 | 9 | frmInputBox *frmInputBox::_instance = 0; 10 | frmInputBox::frmInputBox(QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::frmInputBox) 13 | { 14 | ui->setupUi(this); 15 | this->InitStyle(); 16 | this->InitForm(); 17 | myHelper::FormInCenter(this); 18 | } 19 | 20 | frmInputBox::~frmInputBox() 21 | { 22 | delete ui; 23 | } 24 | 25 | void frmInputBox::InitStyle() 26 | { 27 | if (App::UseStyle) { 28 | this->setProperty("Form", true); 29 | this->setProperty("CanMove", true); 30 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | 31 | Qt::WindowMinMaxButtonsHint | Qt::WindowStaysOnTopHint); 32 | IconHelper::Instance()->SetIcoMain(ui->lab_Ico, App::FontSize + 2); 33 | IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close); 34 | connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close())); 35 | this->setFixedSize(280, 150); 36 | } else { 37 | this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint); 38 | this->resize(size().width(), size().height() - ui->widget_title->size().height()); 39 | ui->widget_title->setVisible(false); 40 | this->setFixedSize(280, 120); 41 | } 42 | 43 | #ifdef __arm__ 44 | this->setFixedSize(300, 160); 45 | #endif 46 | 47 | this->setWindowTitle(ui->lab_Title->text()); 48 | connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close())); 49 | } 50 | 51 | void frmInputBox::InitForm() 52 | { 53 | closeSec = 0; 54 | currentSec = 0; 55 | 56 | QTimer *timer = new QTimer(this); 57 | timer->setInterval(1000); 58 | connect(timer, SIGNAL(timeout()), this, SLOT(CheckSec())); 59 | timer->start(); 60 | } 61 | 62 | void frmInputBox::CheckSec() 63 | { 64 | if (closeSec == 0) { 65 | return; 66 | } 67 | 68 | if (currentSec < closeSec) { 69 | currentSec++; 70 | } else { 71 | this->close(); 72 | } 73 | 74 | if (App::UseStyle) { 75 | QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1); 76 | ui->labTime->setText(str); 77 | } else { 78 | QString str = QString("%1 关闭倒计时 %2 s").arg(ui->lab_Title->text()).arg(closeSec - currentSec + 1); 79 | this->setWindowTitle(str); 80 | } 81 | } 82 | 83 | void frmInputBox::SetParameter(QString title, int type, int closeSec, QString defaultValue, bool pwd) 84 | { 85 | this->closeSec = closeSec; 86 | this->currentSec = 0; 87 | ui->labTime->clear(); 88 | CheckSec(); 89 | 90 | ui->labInfo->setText(title); 91 | 92 | if (type == 0) { 93 | ui->cboxValue->setVisible(false); 94 | ui->txtValue->setPlaceholderText(defaultValue); 95 | 96 | if (pwd) { 97 | ui->txtValue->setEchoMode(QLineEdit::Password); 98 | } 99 | } else if (type == 1) { 100 | ui->txtValue->setVisible(false); 101 | ui->cboxValue->addItems(defaultValue.split("|")); 102 | } 103 | } 104 | 105 | void frmInputBox::closeEvent(QCloseEvent *) 106 | { 107 | closeSec = 0; 108 | currentSec = 0; 109 | } 110 | 111 | void frmInputBox::on_btnOk_clicked() 112 | { 113 | if (ui->txtValue->isVisible()) { 114 | value = ui->txtValue->text(); 115 | } else if (ui->cboxValue->isVisible()) { 116 | value = ui->cboxValue->currentText(); 117 | } 118 | 119 | done(1); 120 | this->close(); 121 | } 122 | -------------------------------------------------------------------------------- /usercontrol/frminputbox.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMINPUTBOX_H 2 | #define FRMINPUTBOX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui 8 | { 9 | class frmInputBox; 10 | } 11 | 12 | class frmInputBox : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit frmInputBox(QWidget *parent = 0); 18 | ~frmInputBox(); 19 | 20 | static frmInputBox *Instance() 21 | { 22 | static QMutex mutex; 23 | 24 | if (!_instance) { 25 | QMutexLocker locker(&mutex); 26 | 27 | if (!_instance) { 28 | _instance = new frmInputBox; 29 | } 30 | } 31 | 32 | return _instance; 33 | } 34 | 35 | void SetParameter(QString title, int type = 0, int closeSec = 0, QString defaultValue = QString(), bool pwd = false); 36 | 37 | QString GetValue()const 38 | { 39 | return value; 40 | } 41 | 42 | protected: 43 | void closeEvent(QCloseEvent *); 44 | 45 | private slots: 46 | void on_btnOk_clicked(); 47 | 48 | private: 49 | Ui::frmInputBox *ui; 50 | static frmInputBox *_instance; 51 | QString value; 52 | 53 | int closeSec; 54 | int currentSec; 55 | 56 | private slots: 57 | void InitStyle(); 58 | void InitForm(); 59 | void CheckSec(); 60 | 61 | }; 62 | 63 | #endif // FRMINPUTBOX_H 64 | -------------------------------------------------------------------------------- /usercontrol/frmmessagebox.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "frmmessagebox.h" 6 | #include "ui_frmmessagebox.h" 7 | #include "api/myhelper.h" 8 | 9 | frmMessageBox *frmMessageBox::_instance = 0; 10 | frmMessageBox::frmMessageBox(QWidget *parent) : 11 | QDialog(parent), 12 | ui(new Ui::frmMessageBox) 13 | { 14 | ui->setupUi(this); 15 | this->InitStyle(); 16 | this->InitForm(); 17 | myHelper::FormInCenter(this); 18 | } 19 | 20 | frmMessageBox::~frmMessageBox() 21 | { 22 | delete ui; 23 | } 24 | 25 | void frmMessageBox::InitStyle() 26 | { 27 | if (App::UseStyle) { 28 | this->setProperty("Form", true); 29 | this->setProperty("CanMove", true); 30 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | 31 | Qt::WindowMinMaxButtonsHint | Qt::WindowStaysOnTopHint); 32 | IconHelper::Instance()->SetIcoMain(ui->lab_Ico, App::FontSize + 2); 33 | IconHelper::Instance()->SetIcoClose(ui->btnMenu_Close); 34 | connect(ui->btnMenu_Close, SIGNAL(clicked()), this, SLOT(close())); 35 | } else { 36 | this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint); 37 | this->resize(size().width(), size().height() - ui->widget_title->size().height()); 38 | ui->widget_title->setVisible(false); 39 | } 40 | 41 | #ifdef __arm__ 42 | this->setFixedSize(300, 160); 43 | #endif 44 | 45 | this->setWindowTitle(ui->lab_Title->text()); 46 | connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close())); 47 | } 48 | 49 | void frmMessageBox::InitForm() 50 | { 51 | closeSec = 0; 52 | currentSec = 0; 53 | 54 | QTimer *timer = new QTimer(this); 55 | timer->setInterval(1000); 56 | connect(timer, SIGNAL(timeout()), this, SLOT(CheckSec())); 57 | timer->start(); 58 | } 59 | 60 | void frmMessageBox::CheckSec() 61 | { 62 | if (closeSec == 0) { 63 | return; 64 | } 65 | 66 | if (currentSec < closeSec) { 67 | currentSec++; 68 | } else { 69 | this->close(); 70 | } 71 | 72 | if (App::UseStyle) { 73 | QString str = QString("关闭倒计时 %1 s").arg(closeSec - currentSec + 1); 74 | ui->labTime->setText(str); 75 | } else { 76 | QString str = QString("%1 关闭倒计时 %2 s").arg(ui->lab_Title->text()).arg(closeSec - currentSec + 1); 77 | this->setWindowTitle(str); 78 | } 79 | } 80 | 81 | void frmMessageBox::SetMessage(QString msg, int type, int closeSec) 82 | { 83 | this->closeSec = closeSec; 84 | this->currentSec = 0; 85 | ui->labTime->clear(); 86 | this->setWindowTitle(ui->lab_Title->text()); 87 | 88 | CheckSec(); 89 | 90 | if (type == 0) { 91 | ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_info.png);"); 92 | ui->btnCancel->setVisible(false); 93 | ui->lab_Title->setText("提示"); 94 | } else if (type == 1) { 95 | ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_question.png);"); 96 | ui->lab_Title->setText("询问"); 97 | } else if (type == 2) { 98 | ui->labIcoMain->setStyleSheet("border-image: url(:/image/msg_error.png);"); 99 | ui->btnCancel->setVisible(false); 100 | ui->lab_Title->setText("错误"); 101 | } 102 | 103 | ui->labInfo->setText(msg); 104 | } 105 | 106 | void frmMessageBox::closeEvent(QCloseEvent *) 107 | { 108 | closeSec = 0; 109 | currentSec = 0; 110 | } 111 | 112 | void frmMessageBox::on_btnOk_clicked() 113 | { 114 | done(1); 115 | this->close(); 116 | } 117 | -------------------------------------------------------------------------------- /usercontrol/frmmessagebox.h: -------------------------------------------------------------------------------- 1 | #ifndef FRMMESSAGEBOX_H 2 | #define FRMMESSAGEBOX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui 8 | { 9 | class frmMessageBox; 10 | } 11 | 12 | class frmMessageBox : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit frmMessageBox(QWidget *parent = 0); 18 | ~frmMessageBox(); 19 | 20 | static frmMessageBox *Instance() 21 | { 22 | static QMutex mutex; 23 | 24 | if (!_instance) { 25 | QMutexLocker locker(&mutex); 26 | 27 | if (!_instance) { 28 | _instance = new frmMessageBox; 29 | } 30 | } 31 | 32 | return _instance; 33 | } 34 | 35 | void SetMessage(QString msg, int type, int closeSec = 0); 36 | 37 | protected: 38 | void closeEvent(QCloseEvent *); 39 | 40 | private slots: 41 | void on_btnOk_clicked(); 42 | 43 | private: 44 | Ui::frmMessageBox *ui; 45 | static frmMessageBox *_instance; 46 | 47 | int closeSec; 48 | int currentSec; 49 | 50 | private slots: 51 | void InitStyle(); 52 | void InitForm(); 53 | void CheckSec(); 54 | 55 | }; 56 | 57 | #endif // FRMMESSAGEBOX_H 58 | -------------------------------------------------------------------------------- /usercontrol/imageview.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEVIEW_H 2 | #define IMAGEVIEW_H 3 | 4 | #ifndef IMAGENUM_H 5 | #define IMAGENUM_H 6 | 7 | #define BOTTOM_SPACE 10 8 | #define BUTTON_SPACE 10 9 | #define ICO_SIZE QSize(30,30) 10 | #define BUTTON_SIZE QSize(35,35) 11 | 12 | #define NUM_BG_START_COLOR QColor(46,132,243) 13 | #define NUM_BG_END_COLOR QColor(39,110,203) 14 | 15 | #define VIEW_BG_START_COLOR QColor(56,56,56) 16 | #define VIEW_BG_END_COLOR QColor(52,52,52) 17 | 18 | #include 19 | 20 | class QToolButton; 21 | 22 | class ImageNum : public QWidget 23 | { 24 | Q_OBJECT 25 | public: 26 | ImageNum(QWidget *parent = 0); 27 | 28 | public slots: 29 | void setTotal(int totalNum); 30 | void setValue(int value); 31 | 32 | protected: 33 | void paintEvent(QPaintEvent *); 34 | 35 | private: 36 | void drawBg(QPainter *painter); 37 | void drawText(QPainter *painter); 38 | 39 | private: 40 | int totalNum, value; 41 | 42 | }; 43 | 44 | #endif // IMAGENUM_H 45 | 46 | class ImageView : public QWidget 47 | { 48 | Q_OBJECT 49 | public: 50 | explicit ImageView(QWidget *parent = 0); 51 | 52 | public slots: 53 | void setFill(bool fill); 54 | void setFade(bool fade); 55 | void load(const QString &strFolder); 56 | void showNext(); 57 | void showPrevious(); 58 | 59 | protected: 60 | virtual void paintEvent(QPaintEvent *); 61 | void keyPressEvent(QKeyEvent *keyEvent); 62 | virtual void showEvent(QShowEvent *); 63 | virtual void resizeEvent(QResizeEvent *); 64 | 65 | private: 66 | void drawBg(QPainter *painter); 67 | void drawImage(QPainter *painter); 68 | void init(); 69 | void calcGeo(); 70 | 71 | private: 72 | bool fill; 73 | bool fade; 74 | int totalNum; 75 | int currIndex; 76 | 77 | QToolButton *prevButton; 78 | QToolButton *nextButton; 79 | 80 | QVector imageVec; 81 | QImage *currImage; 82 | 83 | ImageNum *num; 84 | 85 | qreal imageOpacity; 86 | QTimer *timerOpacity; 87 | 88 | private slots: 89 | void DoImageFading(); 90 | 91 | signals: 92 | void sig_setValue(int value); 93 | void sig_setTotal(int total); 94 | 95 | }; 96 | 97 | #endif // IMAGEVIEW_H 98 | -------------------------------------------------------------------------------- /usercontrol/qdelegate.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "qdelegate.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | QDelegate::QDelegate(QObject *parent) : QItemDelegate(parent) 13 | { 14 | delegateType = "QLineEdit"; 15 | edit = false; 16 | delegateValue.append(""); 17 | } 18 | 19 | QWidget *QDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/) const 20 | { 21 | QWidget *editor = new QWidget(parent); 22 | 23 | if (delegateType == "QLineEdit") { 24 | QLineEdit *txt = new QLineEdit(parent); 25 | txt->setText(delegateValue.at(0)); 26 | if (pwd) { 27 | txt->setEchoMode(QLineEdit::Password); 28 | } 29 | txt->setStyleSheet("border-radius:0px;"); 30 | editor = txt; 31 | } else if (delegateType == "QComboBox") { 32 | QComboBox *cbox = new QComboBox(parent); 33 | cbox->setEditable(edit); 34 | cbox->addItems(delegateValue); 35 | cbox->setStyleSheet("border-radius:0px;"); 36 | editor = cbox; 37 | } else if (delegateType == "QDateTimeEdit") { 38 | QDateTimeEdit *dateTime = new QDateTimeEdit(parent); 39 | dateTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss"); 40 | dateTime->setCalendarPopup(true); 41 | editor = dateTime; 42 | } 43 | 44 | editor->installEventFilter(const_cast(this)); 45 | return editor; 46 | } 47 | 48 | void QDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 49 | { 50 | QString str = index.model()->data(index).toString(); 51 | 52 | if (delegateType == "QLineEdit") { 53 | QLineEdit *txt = static_cast(editor); 54 | txt->setText(str); 55 | } else if (delegateType == "QComboBox") { 56 | QComboBox *cbox = static_cast(editor); 57 | cbox->setCurrentIndex(cbox->findText(str)); 58 | } else if (delegateType == "QDateTimeEdit") { 59 | QDateTimeEdit *dateTime = static_cast(editor); 60 | dateTime->setDateTime(QDateTime::fromString(str, "yyyy-MM-dd HH:mm:ss")); 61 | } 62 | } 63 | 64 | void QDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)const 65 | { 66 | if (delegateType == "QLineEdit") { 67 | QLineEdit *txt = static_cast(editor); 68 | QString str = txt->text(); 69 | model->setData(index, str); 70 | } else if (delegateType == "QComboBox") { 71 | QComboBox *cbox = static_cast(editor); 72 | QString str = cbox->currentText(); 73 | model->setData(index, str); 74 | } else if (delegateType == "QDateTimeEdit") { 75 | QDateTimeEdit *dateTime = static_cast(editor); 76 | QString str = dateTime->dateTime().toString("yyyy-MM-dd HH:mm:ss"); 77 | model->setData(index, str); 78 | } 79 | } 80 | 81 | void QDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const 82 | { 83 | editor->setGeometry(option.rect); 84 | } 85 | -------------------------------------------------------------------------------- /usercontrol/qdelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef QDELEGATE_H 2 | #define QDELEGATE_H 3 | 4 | #include 5 | 6 | class QDelegate : public QItemDelegate 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit QDelegate(QObject *parent = 0); 11 | 12 | //设置委托类型 13 | void SetDelegateType(QString delegateType) { 14 | this->delegateType = delegateType; 15 | } 16 | 17 | //设置下拉框是否允许编辑 18 | void SetDelegateEdit(bool edit) { 19 | this->edit = edit; 20 | } 21 | 22 | //设置文本框是否密码显示 23 | void SetDelegatePwd(bool pwd) { 24 | this->pwd = pwd; 25 | } 26 | 27 | //设置委托参数 28 | void SetDelegateValue(QStringList delegateValue) { 29 | this->delegateValue = delegateValue; 30 | } 31 | 32 | protected: 33 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; 34 | void setEditorData(QWidget *editor, const QModelIndex &index)const; 35 | void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)const; 36 | void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index)const; 37 | 38 | private: 39 | QString delegateType; //委托类型 40 | bool edit; //可否编辑 41 | bool pwd; //可否密码显示 42 | QStringList delegateValue; //委托参数 43 | 44 | signals: 45 | 46 | public slots: 47 | }; 48 | 49 | #endif // QDELEGATE_H 50 | -------------------------------------------------------------------------------- /usercontrol/switchbutton.cpp: -------------------------------------------------------------------------------- 1 | #if _MSC_VER >= 1600 2 | #pragma execution_character_set("utf-8") 3 | #endif 4 | 5 | #include "switchbutton.h" 6 | 7 | SwitchButton::SwitchButton(QWidget *parent): QPushButton(parent) 8 | { 9 | setCursor(QCursor(Qt::PointingHandCursor)); 10 | isCheck = false; 11 | styleOn = "border-image:url(:/image/btn_check_on.png);"; 12 | styleOff = "border-image:url(:/image/btn_check_off.png);"; 13 | 14 | setFocusPolicy(Qt::NoFocus); 15 | setStyleSheet(styleOff); 16 | connect(this, SIGNAL(pressed()), this, SLOT(ChangeOnOff())); 17 | } 18 | 19 | void SwitchButton::ChangeOnOff() 20 | { 21 | if (isCheck) { 22 | setStyleSheet(styleOff); 23 | isCheck = false; 24 | } else { 25 | setStyleSheet(styleOn); 26 | isCheck = true; 27 | } 28 | } 29 | 30 | //设置当前选中状态 31 | void SwitchButton::SetCheck(bool isCheck) 32 | { 33 | if (this->isCheck != isCheck) { 34 | this->isCheck = !isCheck; 35 | ChangeOnOff(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /usercontrol/switchbutton.h: -------------------------------------------------------------------------------- 1 | #ifndef SWITCHBUTTON_H 2 | #define SWITCHBUTTON_H 3 | 4 | #include 5 | 6 | class SwitchButton : public QPushButton 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit SwitchButton(QWidget *parent = 0); 11 | 12 | //获取当前选中状态 13 | bool GetCheck() const { 14 | return isCheck; 15 | } 16 | 17 | //设置当前选中状态 18 | void SetCheck(bool isCheck); 19 | 20 | private: 21 | bool isCheck; 22 | QString styleOn; 23 | QString styleOff; 24 | 25 | signals: 26 | 27 | private slots: 28 | void ChangeOnOff(); 29 | 30 | }; 31 | 32 | #endif //SWITCHBUTTON_H 33 | -------------------------------------------------------------------------------- /usercontrol/usercontrol.pri: -------------------------------------------------------------------------------- 1 | FORMS += \ 2 | $$PWD/frminputbox.ui \ 3 | $$PWD/frmmessagebox.ui 4 | 5 | HEADERS += \ 6 | $$PWD/combobox.h \ 7 | $$PWD/defencebutton.h \ 8 | $$PWD/frminputbox.h \ 9 | $$PWD/frmmessagebox.h \ 10 | $$PWD/imageview.h \ 11 | $$PWD/qdelegate.h \ 12 | $$PWD/switchbutton.h 13 | 14 | SOURCES += \ 15 | $$PWD/combobox.cpp \ 16 | $$PWD/defencebutton.cpp \ 17 | $$PWD/frminputbox.cpp \ 18 | $$PWD/frmmessagebox.cpp \ 19 | $$PWD/imageview.cpp \ 20 | $$PWD/qdelegate.cpp \ 21 | $$PWD/switchbutton.cpp 22 | --------------------------------------------------------------------------------