add aci function
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Application Communication Interface - Full Version
|
||||
* Copyright (c) 2022-2032 UnknownObject
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#pragma warning(disable : 26812)
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
#include <json/json.h>
|
||||
#include <curl/curl.h>
|
||||
#include <webcc/logger.h>
|
||||
#include <webcc/server.h>
|
||||
#include <webcc/response_builder.h>
|
||||
|
||||
constexpr auto ACI_UA = "libcurl/7.68.0 (Windows NT 10.0; Win64; x64) UnknownNetworkService/2.01 (Application Communication Interface; Localhost-Only)";
|
||||
|
||||
//Common types
|
||||
using JsonValue = Json::Value;
|
||||
using JsonReader = Json::Reader;
|
||||
//Client-only types
|
||||
using ClientCallback = void(*)(JsonValue);
|
||||
using ClientDataGroup = std::vector<std::string>;
|
||||
using ClientDataPair = std::pair<std::string, std::string>;
|
||||
template<typename T> using ClassClientCallback = void(T::*)(JsonValue);
|
||||
//Server-only types
|
||||
using ServerInputCallback = void(*)(JsonValue);
|
||||
using ServerDataQueue = std::vector<std::string>;
|
||||
using ResponseFunction = std::string(*)(std::string);
|
||||
using StaticDataResponder = std::map<std::string, std::string>;
|
||||
using DynamicDataResponder = std::map<std::string, ResponseFunction>;
|
||||
|
||||
//Common classes
|
||||
class JsonUnicodeWriter
|
||||
{
|
||||
private:
|
||||
Json::StreamWriterBuilder jswb;
|
||||
public:
|
||||
JsonUnicodeWriter();
|
||||
public:
|
||||
std::string write(JsonValue root);
|
||||
};
|
||||
|
||||
//------------------------------------------Client Classes------------------------------------------
|
||||
class ClientDataEncoder
|
||||
{
|
||||
public:
|
||||
static std::string Encode(std::string item, std::string data);
|
||||
static std::string Encode(std::string item);
|
||||
static JsonValue Decode(std::string str);
|
||||
static ClientDataPair Decode(JsonValue root);
|
||||
static ClientDataGroup DecodeGroup(JsonValue root);
|
||||
};
|
||||
|
||||
class ACIClient
|
||||
{
|
||||
private:
|
||||
CURL* curl;
|
||||
int ServerPort;
|
||||
private:
|
||||
static size_t process_data(void* buffer, size_t size, size_t nmemb, void* user_p);
|
||||
public:
|
||||
ACIClient(int server_port = 10000);
|
||||
~ACIClient();
|
||||
public:
|
||||
bool SendData(std::string item, std::string data, ClientCallback cb_func = nullptr);
|
||||
template<typename T> bool SendData(std::string item, std::string data, ClassClientCallback<T> cb_func, T* class_pointer);
|
||||
bool RequestData(std::string item, std::string data, ClientCallback cb_func = nullptr);
|
||||
template<typename T> bool RequestData(std::string item, std::string data, ClassClientCallback<T> cb_func, T* class_pointer);
|
||||
bool RequestData(std::string item, ClientCallback cb_func = nullptr);
|
||||
template<typename T> bool RequestData(std::string item, ClassClientCallback<T> cb_func, T* class_pointer);
|
||||
bool RequestQuquedData(ClientCallback cb_func = nullptr);
|
||||
template<typename T> bool RequestQuquedData(ClassClientCallback<T> cb_func, T* class_pointer);
|
||||
};
|
||||
//----------------------------------------Client Classes End----------------------------------------
|
||||
|
||||
//------------------------------------------Server Classes------------------------------------------
|
||||
class ServerDataEncoder
|
||||
{
|
||||
public:
|
||||
static std::string Encode(std::string item, std::string data);
|
||||
static JsonValue Decode(std::string str);
|
||||
static std::string EncodeResponse(std::string error, ServerDataQueue data = ServerDataQueue());
|
||||
};
|
||||
|
||||
class ServerDataStorage
|
||||
{
|
||||
private:
|
||||
static ServerDataQueue DataQueue;
|
||||
static StaticDataResponder SDR_Input;
|
||||
static StaticDataResponder SDR_Output;
|
||||
static DynamicDataResponder DDR_Output;
|
||||
public:
|
||||
static void GlobalClear();
|
||||
static void DataQueueClear();
|
||||
static void SDR_InputClear();
|
||||
static void SDR_OutputClear();
|
||||
static void DDR_OutputClear();
|
||||
static void DataQueueAdd(std::string data);
|
||||
static void SDRInputAdd(std::string item, std::string resp);
|
||||
static void SDROutputAdd(std::string item, std::string resp);
|
||||
static void DDROutputAdd(std::string item, ResponseFunction resfunc);
|
||||
static ServerDataQueue GetDataQueue();
|
||||
static StaticDataResponder GetSDR_Input();
|
||||
static StaticDataResponder GetSDR_Output();
|
||||
static DynamicDataResponder GetDDR_Output();
|
||||
static bool SDRInputExist(std::string item);
|
||||
static bool SDROutputExist(std::string item);
|
||||
static bool DDROutputExist(std::string item);
|
||||
static std::string SDRInputGetValue(std::string item);
|
||||
static std::string SDROutputGetValue(std::string item);
|
||||
static ResponseFunction DDROutputGetValue(std::string item);
|
||||
};
|
||||
|
||||
class ServerInputHandler : public webcc::View
|
||||
{
|
||||
private:
|
||||
ServerInputCallback InputCallback;
|
||||
public:
|
||||
ServerInputHandler(ServerInputCallback cb_input = nullptr);
|
||||
public:
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
||||
};
|
||||
|
||||
class ServerOutputHandler : public webcc::View
|
||||
{
|
||||
public:
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
||||
};
|
||||
|
||||
class ServerSideOutputHandler : public webcc::View
|
||||
{
|
||||
public:
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
||||
};
|
||||
|
||||
class ACIServer
|
||||
{
|
||||
private:
|
||||
bool CallbackEnabled;
|
||||
webcc::Server* ccServer;
|
||||
std::thread ServerThread;
|
||||
ServerInputCallback InputCallback;
|
||||
const webcc::Strings methods = { "GET","POST","PUT","HEAD","DELETE" };
|
||||
private:
|
||||
static void ServerThreadFunction(webcc::Server* server, int worker_thread, int loop_thread);
|
||||
public:
|
||||
ACIServer(int port = 10000, bool enable_callback = false, ServerInputCallback cb_func = nullptr);
|
||||
~ACIServer();
|
||||
public:
|
||||
void Run(int worker_thread = 1, int loop_thread = 1);
|
||||
void ThreadRun(int worker_thread = 1, int loop_thread = 1);
|
||||
void Stop();
|
||||
bool EnableCallback(ServerInputCallback cb_func = nullptr);
|
||||
bool SetCallbackFunction(ServerInputCallback cb_func);
|
||||
bool DisableCallback();
|
||||
void OutputQueueAdd(std::string content);
|
||||
void OutputQueueClear();
|
||||
};
|
||||
//----------------------------------------Server Classes End----------------------------------------
|
||||
|
||||
#ifndef _DEBUG
|
||||
#pragma comment(lib, "ACIFullVersion.lib")
|
||||
#else
|
||||
#pragma comment(lib, "ACIFullVersiond.lib")
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
#include "ACIMode.h"
|
||||
|
||||
ACIMode::ACIMode(QWidget* parent) : QMainWindow(parent)
|
||||
{
|
||||
client = nullptr;
|
||||
server = nullptr;
|
||||
OperationMode = -3;
|
||||
ui.setupUi(this);
|
||||
ui.Workmode_Client->setChecked(true);
|
||||
ui.Workmode_Server->setChecked(false);
|
||||
ui.PortNumber->setPlainText("23456");
|
||||
connect(ui.BtnStart, &QCommandLinkButton::clicked, this, &ACIMode::StartACISystem);
|
||||
}
|
||||
|
||||
ACIMode::~ACIMode()
|
||||
{
|
||||
}
|
||||
|
||||
int ACIMode::ProcessRadio(bool client, bool server)
|
||||
{
|
||||
if (client && server)
|
||||
return -1;
|
||||
else if ((!client) && (!server))
|
||||
return -2;
|
||||
else if (client)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ACIMode::CleanUp()
|
||||
{
|
||||
if (client != nullptr)
|
||||
{
|
||||
delete client;
|
||||
client = nullptr;
|
||||
}
|
||||
if (server != nullptr)
|
||||
{
|
||||
server->Stop();
|
||||
delete server;
|
||||
server = nullptr;
|
||||
}
|
||||
OperationMode = -3;
|
||||
}
|
||||
|
||||
void ACIMode::StartACISystem()
|
||||
{
|
||||
CleanUp();
|
||||
OperationMode = ProcessRadio(ui.Workmode_Client->isChecked(), ui.Workmode_Server->isChecked());
|
||||
switch (OperationMode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
client = new ACIClient(ui.PortNumber->toPlainText().toInt());
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
server = new ACIServer(ui.PortNumber->toPlainText().toInt());
|
||||
ServerDataStorage::DDROutputAdd("start-timer", RequestedTimerStart);
|
||||
server->ThreadRun();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
MessageBox(NULL, L"通信参数错误", L"错误", MB_OK | MB_ICONERROR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (OperationMode == 0)
|
||||
this->hide();
|
||||
}
|
||||
|
||||
int ACIMode::GetOperationMode()
|
||||
{
|
||||
return OperationMode;
|
||||
}
|
||||
|
||||
void ACIMode::RequestRemoteTimer()
|
||||
{
|
||||
if (client != nullptr)
|
||||
client->RequestData("start-timer");
|
||||
}
|
||||
|
||||
void ACIMode::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
this->hide();
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
std::string RequestedTimerStart(std::string json)
|
||||
{
|
||||
GlobalVari::ServerRequested = true;
|
||||
return "successed";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "ACIFullVersion.h"
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include "ui_ACIMode.h"
|
||||
#include <QTimer>
|
||||
#include <QKeyEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <Windows.h>
|
||||
#include "GlobalVari.h"
|
||||
|
||||
class ACIMode : public QMainWindow
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ACIMode(QWidget* parent = nullptr);
|
||||
~ACIMode();
|
||||
|
||||
public:
|
||||
int ProcessRadio(bool client, bool server);
|
||||
void CleanUp();
|
||||
void StartACISystem();
|
||||
int GetOperationMode();
|
||||
void RequestRemoteTimer();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
private:
|
||||
int OperationMode;
|
||||
ACIClient* client;
|
||||
ACIServer* server;
|
||||
Ui::ACIModeWindow ui;
|
||||
};
|
||||
|
||||
std::string RequestedTimerStart(std::string json);
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ACIModeWindow</class>
|
||||
<widget class="QMainWindow" name="ACIModeWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>262</width>
|
||||
<height>241</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>通信模式设置</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>241</width>
|
||||
<height>171</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>通信设置</string>
|
||||
</property>
|
||||
<widget class="QPlainTextEdit" name="PortNumber">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>30</y>
|
||||
<width>161</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="centerOnScroll">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>41</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>端口号</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<width>221</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>工作模式</string>
|
||||
</property>
|
||||
<widget class="QRadioButton" name="Workmode_Client">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>19</y>
|
||||
<width>61</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>客户端</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="Workmode_Server">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>19</y>
|
||||
<width>61</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>服务端</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QCommandLinkButton" name="BtnStart">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>190</y>
|
||||
<width>141</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>启动通信系统</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+125
-83
@@ -2,21 +2,24 @@
|
||||
|
||||
ClockCounter::ClockCounter(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
PreClickCount = 0;
|
||||
PreClickPosition = QPoint(0, 0);
|
||||
ui.SpliterHourMinute->Init(UDateTimeSpliter::Type::Time);
|
||||
ui.SpliterMinuteSecond->Init(UDateTimeSpliter::Type::Time);
|
||||
ui.SpliterSecondMS->Init(UDateTimeSpliter::Type::Dots);
|
||||
connect(ui.BtnStartTimer, &QPushButton::clicked, this, &ClockCounter::StartTimer);
|
||||
connect(ui.BtnStopTimer, &QPushButton::clicked, this, &ClockCounter::StopTimer);
|
||||
connect(ui.BtnGetPreclickPos, &QPushButton::clicked, this, &ClockCounter::ShowPreClickWindow);
|
||||
connect(ui.BtnClearPreclickPos, &QPushButton::clicked, this, &ClockCounter::ClearPreClickInfo);
|
||||
connect(&CountTimer, &QTimer::timeout, this, &ClockCounter::CountCallback);
|
||||
connect(&WindowUpdater, &QTimer::timeout, this, &ClockCounter::WindowUpdateCallback);
|
||||
CountTimer.setInterval(1);
|
||||
WindowUpdater.setInterval(50);
|
||||
CountTime = 0;
|
||||
ui.setupUi(this);
|
||||
PreClickCount = 0;
|
||||
PreClickPosition = QPoint(0, 0);
|
||||
ui.SpliterHourMinute->Init(UDateTimeSpliter::Type::Time);
|
||||
ui.SpliterMinuteSecond->Init(UDateTimeSpliter::Type::Time);
|
||||
ui.SpliterSecondMS->Init(UDateTimeSpliter::Type::Dots);
|
||||
connect(ui.BtnStartTimer, &QPushButton::clicked, this, &ClockCounter::StartTimer);
|
||||
connect(ui.BtnStopTimer, &QPushButton::clicked, this, &ClockCounter::StopTimer);
|
||||
connect(ui.BtnGetPreclickPos, &QPushButton::clicked, this, &ClockCounter::ShowPreClickWindow);
|
||||
connect(ui.BtnGetPreclickPos, &UDBPushButton::rclicked, this, &ClockCounter::ShowACIModeWindow);
|
||||
connect(ui.BtnClearPreclickPos, &QPushButton::clicked, this, &ClockCounter::ClearPreClickInfo);
|
||||
connect(&CountTimer, &QTimer::timeout, this, &ClockCounter::CountCallback);
|
||||
connect(&WindowUpdater, &QTimer::timeout, this, &ClockCounter::WindowUpdateCallback);
|
||||
connect(&ServerStatusChecker, &QTimer::timeout, this, &ClockCounter::ServerStatusCallback);
|
||||
CountTimer.setInterval(1);
|
||||
WindowUpdater.setInterval(50);
|
||||
ServerStatusChecker.setInterval(1);
|
||||
CountTime = 0;
|
||||
}
|
||||
|
||||
ClockCounter::~ClockCounter()
|
||||
@@ -25,96 +28,135 @@ ClockCounter::~ClockCounter()
|
||||
|
||||
void ClockCounter::MouseClick(int cnt, QPoint point)
|
||||
{
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
this->setWindowTitle(QString::asprintf("软件执行计时器: 执行位于(%d, %d)的第%d次预点击", point.x(), point.y(), i));
|
||||
SetCursorPos(point.x(), point.y());
|
||||
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
|
||||
Sleep(500);
|
||||
}
|
||||
return;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
this->setWindowTitle(QString::asprintf("软件执行计时器: 执行位于(%d, %d)的第%d次预点击", point.x(), point.y(), i));
|
||||
SetCursorPos(point.x(), point.y());
|
||||
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
|
||||
Sleep(500);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void ClockCounter::StartTimer()
|
||||
{
|
||||
if (CountTime != 0)
|
||||
{
|
||||
ui.BtnStartTimer->setText("开始计时");
|
||||
CountTime = -1;
|
||||
CountCallback();
|
||||
if(PreClickCount!=0)
|
||||
this->setWindowTitle("软件执行计时器: 预点击指令已激活");
|
||||
else
|
||||
this->setWindowTitle("软件执行计时器");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PreClickCount > 0)
|
||||
MouseClick(PreClickCount, PreClickPosition);
|
||||
CountTimer.start();
|
||||
this->setWindowTitle("软件执行计时器: 正在计时");
|
||||
}
|
||||
if (CountTime != 0)
|
||||
{
|
||||
ui.BtnStartTimer->setText("开始计时");
|
||||
CountTime = -1;
|
||||
CountCallback();
|
||||
if (PreClickCount != 0)
|
||||
this->setWindowTitle("软件执行计时器: 预点击指令已激活");
|
||||
else
|
||||
this->setWindowTitle("软件执行计时器");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PreClickCount > 0)
|
||||
{
|
||||
MouseClick(PreClickCount, PreClickPosition);
|
||||
if (aci_mode_window.GetOperationMode() == 0)
|
||||
aci_mode_window.RequestRemoteTimer();
|
||||
else
|
||||
{
|
||||
CountTimer.start();
|
||||
this->setWindowTitle("软件执行计时器: 正在计时");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClockCounter::StopTimer()
|
||||
{
|
||||
CountTimer.stop();
|
||||
ui.BtnStartTimer->setText("重置计时器");
|
||||
this->setWindowTitle("软件执行计时器: 计时已停止");
|
||||
CountTimer.stop();
|
||||
ui.BtnStartTimer->setText("重置计时器");
|
||||
this->setWindowTitle("软件执行计时器: 计时已停止");
|
||||
}
|
||||
|
||||
void ClockCounter::ShowACIModeWindow()
|
||||
{
|
||||
if (!aci_mode_window.isActiveWindow())
|
||||
{
|
||||
aci_mode_window.show();
|
||||
aci_mode_window.activateWindow();
|
||||
aci_mode_window.setWindowState((aci_mode_window.windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
ServerStatusChecker.start();
|
||||
/*this->hide();
|
||||
WindowUpdater.start();*/
|
||||
}
|
||||
}
|
||||
|
||||
void ClockCounter::ShowPreClickWindow()
|
||||
{
|
||||
if (!pre_click_window.isActiveWindow())
|
||||
{
|
||||
pre_click_window.show();
|
||||
pre_click_window.activateWindow();
|
||||
pre_click_window.setWindowState((pre_click_window.windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
this->hide();
|
||||
WindowUpdater.start();
|
||||
}
|
||||
if (!pre_click_window.isActiveWindow())
|
||||
{
|
||||
pre_click_window.show();
|
||||
pre_click_window.activateWindow();
|
||||
pre_click_window.setWindowState((pre_click_window.windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
this->hide();
|
||||
WindowUpdater.start();
|
||||
}
|
||||
}
|
||||
|
||||
void ClockCounter::ClearPreClickInfo()
|
||||
{
|
||||
PreClickCount = 0;
|
||||
PreClickPosition = QPoint(0, 0);
|
||||
this->setWindowTitle("软件执行计时器");
|
||||
MessageBox(NULL, L"预点击坐标已清空", L"提示", MB_OK | MB_ICONINFORMATION);
|
||||
PreClickCount = 0;
|
||||
PreClickPosition = QPoint(0, 0);
|
||||
aci_mode_window.CleanUp();
|
||||
this->setWindowTitle("软件执行计时器");
|
||||
MessageBox(NULL, L"预点击坐标已清空", L"提示", MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
void ClockCounter::CountCallback()
|
||||
{
|
||||
CountTime++;
|
||||
int hour = (CountTime / 1000) / 3600;
|
||||
int minute = ((CountTime / 1000) / 60) - (hour * 60);
|
||||
int second = (CountTime / 1000) - (hour * 3600) - (minute * 60);
|
||||
int millsecond = CountTime - (hour * 3600 * 1000) - (minute * 60 * 1000) - (second * 1000);
|
||||
ui.NumHour01->setNumber(hour / 10);
|
||||
ui.NumHour02->setNumber(hour % 10);
|
||||
ui.NumMinute01->setNumber(minute / 10);
|
||||
ui.NumMinute02->setNumber(minute % 10);
|
||||
ui.NumSecond01->setNumber(second / 10);
|
||||
ui.NumSecond02->setNumber(second % 10);
|
||||
ui.NumMillSec01->setNumber(millsecond / 100);
|
||||
ui.NumMillSec02->setNumber((millsecond / 10) % 10);
|
||||
ui.NumMillSec03->setNumber((millsecond % 100) % 10);
|
||||
return;
|
||||
CountTime++;
|
||||
int hour = (CountTime / 1000) / 3600;
|
||||
int minute = ((CountTime / 1000) / 60) - (hour * 60);
|
||||
int second = (CountTime / 1000) - (hour * 3600) - (minute * 60);
|
||||
int millsecond = CountTime - (hour * 3600 * 1000) - (minute * 60 * 1000) - (second * 1000);
|
||||
ui.NumHour01->setNumber(hour / 10);
|
||||
ui.NumHour02->setNumber(hour % 10);
|
||||
ui.NumMinute01->setNumber(minute / 10);
|
||||
ui.NumMinute02->setNumber(minute % 10);
|
||||
ui.NumSecond01->setNumber(second / 10);
|
||||
ui.NumSecond02->setNumber(second % 10);
|
||||
ui.NumMillSec01->setNumber(millsecond / 100);
|
||||
ui.NumMillSec02->setNumber((millsecond / 10) % 10);
|
||||
ui.NumMillSec03->setNumber((millsecond % 100) % 10);
|
||||
return;
|
||||
}
|
||||
|
||||
void ClockCounter::WindowUpdateCallback()
|
||||
{
|
||||
if (!pre_click_window.isVisible())
|
||||
{
|
||||
WindowUpdater.stop();
|
||||
this->show();
|
||||
this->activateWindow();
|
||||
this->setWindowState((this->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
if (pre_click_window.GetWindowStatus())
|
||||
{
|
||||
PreClickCount = pre_click_window.GetClickCount();
|
||||
PreClickPosition = pre_click_window.GetCursorPosition();
|
||||
this->setWindowTitle("软件执行计时器: 预点击指令已激活");
|
||||
}
|
||||
}
|
||||
if (!pre_click_window.isVisible())
|
||||
{
|
||||
WindowUpdater.stop();
|
||||
this->show();
|
||||
this->activateWindow();
|
||||
this->setWindowState((this->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||
if (pre_click_window.GetWindowStatus())
|
||||
{
|
||||
PreClickCount = pre_click_window.GetClickCount();
|
||||
PreClickPosition = pre_click_window.GetCursorPosition();
|
||||
this->setWindowTitle("软件执行计时器: 预点击指令已激活");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClockCounter::ServerStatusCallback()
|
||||
{
|
||||
if (aci_mode_window.GetOperationMode() == 0)
|
||||
{
|
||||
ServerStatusChecker.stop();
|
||||
this->hide();
|
||||
}
|
||||
else if (aci_mode_window.GetOperationMode() == 1)
|
||||
{
|
||||
if (GlobalVari::ServerRequested)
|
||||
{
|
||||
CountTimer.start();
|
||||
ServerStatusChecker.stop();
|
||||
this->setWindowTitle("软件执行计时器: 正在计时");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "ACIMode.h"
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include "ui_ClockCounter.h"
|
||||
#include "PreClick.h"
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include "GlobalVari.h"
|
||||
|
||||
class ClockCounter : public QMainWindow
|
||||
{
|
||||
@@ -20,10 +22,12 @@ public:
|
||||
public slots:
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
void ShowACIModeWindow();
|
||||
void ShowPreClickWindow();
|
||||
void ClearPreClickInfo();
|
||||
void CountCallback();
|
||||
void WindowUpdateCallback();
|
||||
void ServerStatusCallback();
|
||||
|
||||
private:
|
||||
time_t CountTime;
|
||||
@@ -31,6 +35,8 @@ private:
|
||||
QTimer CountTimer;
|
||||
QTimer WindowUpdater;
|
||||
QPoint PreClickPosition;
|
||||
ACIMode aci_mode_window;
|
||||
Ui::ClockCounterClass ui;
|
||||
PreClick pre_click_window;
|
||||
QTimer ServerStatusChecker;
|
||||
};
|
||||
|
||||
@@ -166,7 +166,7 @@
|
||||
<string>停止计时</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="BtnGetPreclickPos">
|
||||
<widget class="UDBPushButton" name="BtnGetPreclickPos">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
@@ -207,6 +207,11 @@
|
||||
<header>udatetimespliter.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>UDBPushButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>udbpushbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="ClockCounter.qrc"/>
|
||||
|
||||
@@ -92,9 +92,13 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ACIMode.cpp" />
|
||||
<ClCompile Include="GlobalVari.cpp" />
|
||||
<ClCompile Include="PreClick.cpp" />
|
||||
<ClCompile Include="UDateTimeSpliter.cpp" />
|
||||
<ClCompile Include="UDBPushButton.cpp" />
|
||||
<QtRcc Include="ClockCounter.qrc" />
|
||||
<QtUic Include="ACIMode.ui" />
|
||||
<QtUic Include="ClockCounter.ui" />
|
||||
<QtMoc Include="ClockCounter.h" />
|
||||
<ClCompile Include="ClockCounter.cpp" />
|
||||
@@ -107,6 +111,12 @@
|
||||
<ItemGroup>
|
||||
<QtMoc Include="UDateTimeSpliter.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ACIFullVersion.h" />
|
||||
<ClInclude Include="GlobalVari.h" />
|
||||
<QtMoc Include="UDBPushButton.h" />
|
||||
<QtMoc Include="ACIMode.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||
<Import Project="$(QtMsBuild)\qt.targets" />
|
||||
|
||||
@@ -46,11 +46,23 @@
|
||||
<ClCompile Include="UDateTimeSpliter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ACIMode.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UDBPushButton.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GlobalVari.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="PreClick.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="ACIMode.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="PreClick.h">
|
||||
@@ -59,5 +71,19 @@
|
||||
<QtMoc Include="UDateTimeSpliter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="ACIMode.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="UDBPushButton.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="GlobalVari.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ACIFullVersion.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "GlobalVari.h"
|
||||
|
||||
bool GlobalVari::ServerRequested = false;
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace GlobalVari
|
||||
{
|
||||
extern bool ServerRequested;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "UDBPushButton.h"
|
||||
|
||||
UDBPushButton::UDBPushButton(QWidget* parent) : QPushButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
UDBPushButton::~UDBPushButton()
|
||||
{
|
||||
}
|
||||
|
||||
void UDBPushButton::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
emit db_clicked();
|
||||
}
|
||||
|
||||
void UDBPushButton::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
emit clicked();
|
||||
else if (event->button() == Qt::RightButton)
|
||||
emit rclicked();
|
||||
else if (event->button() == Qt::MiddleButton)
|
||||
emit center_clicked();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class UDBPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
UDBPushButton(QWidget* parent);
|
||||
~UDBPushButton();
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
signals:
|
||||
void db_clicked();
|
||||
void rclicked();
|
||||
void center_clicked();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user