From d5199b1d910404dcfb0cc22154fdb1baa7ffe0c6 Mon Sep 17 00:00:00 2001 From: gangphon Date: Tue, 30 Aug 2022 23:07:13 +0800 Subject: [PATCH] =?UTF-8?q?ledset=E6=9B=B4=E6=96=B0=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=B1=8F=E8=BF=9E=E6=8E=A5=20ledok=E5=A2=9E=E5=8A=A0taxihub?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LedOK/globaldefine.cpp | 24 ++- LedOK/gqt.h | 15 ++ LedOK/wDevicesManager/ctrladvancedpanel.cpp | 92 ++++++--- ledset/expertscreenconnwin.cpp | 202 ++++++++++++++++---- ledset/expertscreenconnwin.h | 15 +- ledset/expertsmartpointsetwin.cpp | 5 +- ledset/expertwin.cpp | 5 +- ledset/expertwin.h | 14 -- ledset/gqt.cpp | 3 - ledset/gqt.h | 137 +++++++++++-- ledset/imgs/conn5.png | Bin 5534 -> 972 bytes ledset/imgs/conn6.png | Bin 5534 -> 983 bytes ledset/imgs/conn7.png | Bin 5534 -> 940 bytes ledset/imgs/conn8.png | Bin 5534 -> 942 bytes ledset/main.cpp | 3 +- ledset/mainwin.cpp | 5 +- 16 files changed, 398 insertions(+), 122 deletions(-) diff --git a/LedOK/globaldefine.cpp b/LedOK/globaldefine.cpp index 3302a8f..c87e4db 100644 --- a/LedOK/globaldefine.cpp +++ b/LedOK/globaldefine.cpp @@ -20,11 +20,13 @@ QString parseReplyJson(QNetworkReply *reply, QJsonDocument *outJson) { auto error = reply->error(); if(error != QNetworkReply::NoError) { auto errStr = reply->errorString(); - if(error==QNetworkReply::OperationCanceledError) { - error = QNetworkReply::TimeoutError; - errStr = QCoreApplication::translate("Def","Connection Timeout"); + if(error!=QNetworkReply::InternalServerError || ! errStr.endsWith("replied: Unknown")) { + if(error==QNetworkReply::OperationCanceledError) { + error = QNetworkReply::TimeoutError; + errStr = QCoreApplication::translate("Def","Connection Timeout"); + } + return QString(QMetaEnum::fromType().valueToKey(error))+" ("+QString::number(error)+")\n"+errStr+"\n"+reply->readAll(); } - return QString::number(error)+" "+QMetaEnum::fromType().valueToKey(error)+" "+errStr+"\n"+reply->readAll(); } auto status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(status != 200) return QString::number(status)+" "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()+"\n"+reply->readAll(); @@ -42,18 +44,20 @@ QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *doc) { auto data = reply->readAll(); if(error != QNetworkReply::NoError) { auto errStr = reply->errorString(); - if(error==QNetworkReply::OperationCanceledError) { - error = QNetworkReply::TimeoutError; - errStr = QCoreApplication::translate("Def","Connection Timeout"); + if(error!=QNetworkReply::InternalServerError || ! errStr.endsWith("replied: Unknown")) { + if(error==QNetworkReply::OperationCanceledError) { + error = QNetworkReply::TimeoutError; + errStr = QCoreApplication::translate("Def","Connection Timeout"); + } + return QString(QMetaEnum::fromType().valueToKey(error))+" ("+QString::number(error)+")\n"+errStr+"\n"+data; } - return QString::number(error)+" - "+QMetaEnum::fromType().valueToKey(error)+": "+errStr+"\n"+data; } auto status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if(status != 200) return QString::number(status)+" "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()+"\n"+data; + if(status != 200) return QString::number(status)+" - "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString()+"\n"+data; QJsonParseError jsonErr; QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr); if(jsonErr.error != QJsonParseError::NoError) return "JsonError "+jsonErr.errorString()+"\n"+data; - if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail"); + if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+"\n"+data; if(doc) doc->swap(json); return ""; } diff --git a/LedOK/gqt.h b/LedOK/gqt.h index 8f2cd58..11bc6c8 100644 --- a/LedOK/gqt.h +++ b/LedOK/gqt.h @@ -90,6 +90,21 @@ public: } }; +class VBox : public QBoxLayout { +public: + inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {} + inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) { + parent->addLayout(this); + }; +}; +class HBox : public QBoxLayout { +public: + inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {} + inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) { + parent->addLayout(this); + }; +}; + template inline QThread *ThreadStart(Func &&f) { QThread* thread = QThread::create(f); diff --git a/LedOK/wDevicesManager/ctrladvancedpanel.cpp b/LedOK/wDevicesManager/ctrladvancedpanel.cpp index eb9fab9..9d64dd5 100644 --- a/LedOK/wDevicesManager/ctrladvancedpanel.cpp +++ b/LedOK/wDevicesManager/ctrladvancedpanel.cpp @@ -507,37 +507,83 @@ CtrlAdvancedPanel::CtrlAdvancedPanel(QWidget *parent,QList *list) : Q btnBindTaxiIc = new QPushButton; btnBindTaxiIc->setProperty("ssType", "progManageTool"); connect(btnBindTaxiIc, &QPushButton::clicked, this, [this] { - if(m_pLedlist==nullptr) return; - CHECK_CARD_SELECTED - m_strStartUrl = "http://"+m_pLedCard->m_strCardIp+":3000"; + if(gSelCards->isEmpty()) { + QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController")); + return; + } QString icFile = QFileDialog::getOpenFileName(this, "open file dialog", "", tr("indentity voucher (*.ic)")); if(icFile.isEmpty()) return; QFile file(icFile); - file.open(QIODevice::ReadOnly); - QJsonDocument icJson = QJsonDocument::fromJson(file.readAll()); + if(! file.open(QIODevice::ReadOnly)) { + QMessageBox::information(gMainWin, tr("Tip"), tr("Open file Failed")); + return; + } + auto data = file.readAll(); file.close(); + QJsonParseError jsonErr; + QJsonDocument icJson = QJsonDocument::fromJson(data, &jsonErr); + if(jsonErr.error != QJsonParseError::NoError) { + QMessageBox::information(gMainWin, tr("Tip"), "JsonError "+jsonErr.errorString()+"\n"+data); + return; + } + QJsonObject jsonCommand; + jsonCommand.insert("action", "BindAccount"); + jsonCommand.insert("accountIdToken", icJson["account_id_token"]); + jsonCommand.insert("server", icJson["taxiServerURL"]); + jsonCommand.insert("tlsServer", icJson["taxiServerTLSURL"]); QJsonObject json; json.insert("action", "InvokeTaxiAppFunction"); - - QJsonObject subJson; - subJson.insert("action", "BindAccount"); - subJson.insert("accountIdToken", icJson["account_id_token"].toString()); - subJson.insert("server", icJson["taxiServerURL"].toString()); - subJson.insert("tlsServer", icJson["taxiServerTLSURL"].toString()); - json.insert("jsonCommand", subJson); - if(m_pLedlist->count()==1) { - if(m_pLedCard!=nullptr) { - HttpPostByTypeJsonObject(pHpptClient,m_strStartUrl,json); - if(m_PostingDlg==nullptr) { - m_PostingDlg = new LoEmptyDialog(this); - connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg())); - connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock())); - m_PostingDlg->lock(tr("InvokeTaxiAppFunction"),tr("Success"),tr("failed")); - m_pGetAskTimer->start(5000); - m_PostingDlg->exec(); + json.insert("jsonCommand", jsonCommand); + if(gSelCards->count() == 1) { + auto waitingDlg = new WaitingDlg(this, tr("InvokeTaxiAppFunction")); + waitingDlg->show(); + auto reply = Tools::netManager().post(reqForJson("http://"+gSelCards->at(0)->m_strCardIp+":3000"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); + connect(reply, &QNetworkReply::finished, this, [reply, waitingDlg] { + QString err = parseReplyJson(reply); + if(! err.isEmpty()) { + waitingDlg->close(); + QMessageBox::critical(gMainWin, tr("Error"), err); + return; } + auto data = reply->readAll(); + QJsonParseError jsonErr; + QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr); + if(jsonErr.error != QJsonParseError::NoError) { + waitingDlg->close(); + QMessageBox::critical(gMainWin, tr("Error"), "JsonError "+jsonErr.errorString()+"\n"+data); + return; + } + if(json["result"].toString() != "true") { + waitingDlg->close(); + QMessageBox::critical(gMainWin, tr("Error"), data); + return; + } + waitingDlg->success(); + }); + } else { + foreach(auto card, *gSelCards) { + auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":3000"), QJsonDocument{json}.toJson(QJsonDocument::Compact)); + connect(reply, &QNetworkReply::finished, this, [reply, card] { + QString err = parseReplyJson(reply); + if(! err.isEmpty()) { + gFdResInfo->append(card->m_strCardId+" "+tr("InvokeTaxiAppFunction")+" "+tr("Error")+" "+err); + return; + } + auto data = reply->readAll(); + QJsonParseError jsonErr; + QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr); + if(jsonErr.error != QJsonParseError::NoError) { + gFdResInfo->append(card->m_strCardId+" "+tr("InvokeTaxiAppFunction")+" "+tr("Error")+" JsonError "+jsonErr.errorString()+"\n"+data); + return; + } + if(json["result"].toString() != "true") { + gFdResInfo->append(card->m_strCardId+" "+tr("InvokeTaxiAppFunction")+" "+tr("Error")+" "+data); + return; + } + gFdResInfo->append(card->m_strCardId+" "+tr("InvokeTaxiAppFunction")+" "+QCoreApplication::translate("Def","Success")); + }); } - } else emit sigSend(json,tr("InvokeTaxiAppFunction")); + } }); hBox->addWidget(btnBindTaxiIc); hBox->addStretch(); diff --git a/ledset/expertscreenconnwin.cpp b/ledset/expertscreenconnwin.cpp index f893800..86edc99 100644 --- a/ledset/expertscreenconnwin.cpp +++ b/ledset/expertscreenconnwin.cpp @@ -1,57 +1,119 @@ #include "expertscreenconnwin.h" -#include +#include "gqt.h" #include #include #include #include #include +#include +#include +#include +#include + +QColor cardColors[] {QColor(0xff2222), QColor(0xffaa00), QColor(0x00bb00), QColor(0x00bbcc), QColor(0x0044ff), QColor(0xffffff), QColor(0xffff00)}; ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QWidget{parent} { - auto vBox = new QVBoxLayout(this); - vBox->setContentsMargins(4, 4, 4, 4); + auto vv = new QVBoxLayout(this); + vv->setContentsMargins(4, 4, 4, 4); auto hh = new QHBoxLayout; - vBox->addLayout(hh); + vv->addLayout(hh); - auto vvv = new QVBoxLayout; - hh->addLayout(vvv); + auto leftWgt = new QWidget; + auto poli = leftWgt->sizePolicy(); + poli.setHorizontalPolicy(QSizePolicy::Maximum); + leftWgt->setSizePolicy(poli); + hh->addWidget(leftWgt); - auto gBox = new QGroupBox("接收卡设置"); + auto vvv = new QVBoxLayout(leftWgt); + vvv->setContentsMargins(0,0,0,0); + + auto gBox = new QGroupBox("起始位置"); vvv->addWidget(gBox); - auto hhh = new QHBoxLayout(gBox); - auto lb = new QLabel("卡宽度: "); - hhh->addWidget(lb); + auto fdX = new QSpinBox; + auto fdY = new QSpinBox; + { + auto hhh = new QHBoxLayout(gBox); - auto fdReCardWidth = new QSpinBox; - fdReCardWidth->setRange(0, 9999); - fdReCardWidth->setValue(128); - hhh->addWidget(fdReCardWidth); + auto lb = new QLabel("X坐标: "); + hhh->addWidget(lb); - lb = new QLabel("卡高度: "); - hhh->addWidget(lb); + fdX->setRange(0, 99999); + fdX->setValue(0); + hhh->addWidget(fdX); - auto fdReCardHeight = new QSpinBox; - fdReCardHeight->setRange(0, 9999); - fdReCardHeight->setValue(64); - hhh->addWidget(fdReCardHeight); + lb = new QLabel("Y坐标: "); + hhh->addWidget(lb); + + fdY->setRange(0, 99999); + fdY->setValue(0); + hhh->addWidget(fdY); + } + + gBox = new QGroupBox("接收卡设置"); + vvv->addWidget(gBox); + + auto fdCardColNum = new QSpinBox; + auto fdCardRowNum = new QSpinBox; + auto fdCardWidth = new QSpinBox; + auto fdCardHeight = new QSpinBox; + { + auto vBox = new QVBoxLayout(gBox); + auto hhh = new QHBoxLayout; + vBox->addLayout(hhh); + + auto lb = new QLabel("卡列数: "); + hhh->addWidget(lb); + + fdCardColNum->setRange(0, 9999); + fdCardColNum->setValue(2); +// connect(fdCardColNum, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) { +// table->setColumnCount(value); +// }); + hhh->addWidget(fdCardColNum); + + lb = new QLabel("卡行数: "); + hhh->addWidget(lb); + + fdCardRowNum->setRange(0, 9999); + fdCardRowNum->setValue(2); + + hhh->addWidget(fdCardRowNum); + + vBox->addLayout(hhh = new QHBoxLayout); + + lb = new QLabel("卡宽度: "); + hhh->addWidget(lb); + + fdCardWidth->setRange(0, 9999); + fdCardWidth->setValue(128); + hhh->addWidget(fdCardWidth); + + lb = new QLabel("卡高度: "); + hhh->addWidget(lb); + + fdCardHeight->setRange(0, 9999); + fdCardHeight->setValue(128); + hhh->addWidget(fdCardHeight); + } gBox = new QGroupBox("网口选择"); vvv->addWidget(gBox); - hhh = new QHBoxLayout(gBox); - - auto bnNet1 = new QPushButton("1"); - hhh->addWidget(bnNet1); - - auto bnNet2 = new QPushButton("2"); - hhh->addWidget(bnNet2); - - auto bnNet3 = new QPushButton("3"); - hhh->addWidget(bnNet3); - - auto bnNet4 = new QPushButton("4"); - hhh->addWidget(bnNet4); + auto hhh = new QHBoxLayout(gBox); + auto pal = palette(); + auto fdNet = new QButtonGroup(gBox); + for(int i=0; isetCheckable(true); + if(i==0) bn->setChecked(true); + bn->setMinimumHeight(30); + pal.setColor(QPalette::ButtonText, cardColors[i%(sizeof(cardColors)/sizeof(cardColors[0]))]); + bn->setPalette(pal); + hhh->addWidget(bn); + fdNet->addButton(bn, i); + } gBox = new QGroupBox("快速串线:"); gBox->setStyleSheet("QToolButton {border: none; }"); @@ -104,16 +166,76 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QWidget{parent} { bnConn8->setIcon(QIcon(":/imgs/conn8.png")); hhh->addWidget(bnConn8); } - vvv->addStretch(); - vvv = new QVBoxLayout; - hh->addLayout(vvv); + vvv->addLayout(hhh = new QHBoxLayout); - hhh = new QHBoxLayout; - vvv->addLayout(hhh); - - auto bnRefresh = new QToolButton; + auto bnRefresh = new QPushButton("重新开始"); + connect(bnRefresh, &QPushButton::clicked, this, [this] { + table->clearContents(); + for(int i=0; iaddWidget(bnRefresh); + auto bnBack = new QPushButton("后退"); + connect(bnBack, &QPushButton::clicked, this, [this, fdNet] { + auto netIdx = fdNet->checkedId(); + if(netss[netIdx].isEmpty()) return; + auto sels = table->selectedItems(); + if(! sels.isEmpty()) sels[0]->setSelected(false); + auto point = netss[netIdx].takeLast(); + table->setItem(point.y(), point.x(), 0); + table->update(); + }); + hhh->addWidget(bnBack); + hhh->addStretch(); + + vvv->addStretch(); + + table = new CardTable(fdCardRowNum->value(), fdCardColNum->value()); + table->win = this; + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter); + table->horizontalHeader()->setDefaultSectionSize(90); + table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter); + table->verticalHeader()->setDefaultSectionSize(90); + table->verticalHeader()->setMinimumWidth(30); + table->setSelectionMode(QTableWidget::SingleSelection); + connect(table, &QTableWidget::currentCellChanged, this, [this, fdNet, fdCardWidth, fdCardHeight](int row, int column) { + auto item = table->item(row, column); + if(item) { + auto netIdx = item->data(Qt::UserRole).toInt(); + table->setStyleSheet("QTableView{selection-color:"+cardColors[netIdx % (sizeof(cardColors)/sizeof(cardColors[0]))].name()+";}"); + //fdNet->button(netIdx)->setChecked(true); + return; + } + auto netIdx = fdNet->checkedId(); + netss[netIdx].append(QPoint(column, row)); + item = new QTableWidgetItem("网口: "+QString::number(netIdx+1)+"\n接收卡: "+QString::number(netss[netIdx].size())+"\n宽度: "+QString::number(fdCardWidth->value())+"\n高度: "+QString::number(fdCardHeight->value())); + auto color = cardColors[netIdx % (sizeof(cardColors)/sizeof(cardColors[0]))]; + item->setForeground(color); + table->setStyleSheet("QTableView{selection-color:"+color.name()+";}"); + item->setData(Qt::UserRole, netIdx); + table->setItem(row, column, item); + table->update(); + }); + connect(fdCardColNum, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, table, &QTableWidget::setColumnCount); + connect(fdCardRowNum, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, table, &QTableWidget::setRowCount); + hh->addWidget(table); +} + +void CardTable::paintEvent(QPaintEvent *event) { + QTableWidget::paintEvent(event); + QPainter painter(viewport()); + for(int i=0; inetss.size(); i++) { + auto size = win->netss[i].size(); + if(size < 2) continue; + painter.setPen(QPen(cardColors[i % (sizeof(cardColors)/sizeof(cardColors[0]))], 2)); + int off = 45 + (i+1)/2 * (i%2 ? -4 : 4); + for(int j=1; jnetss[i][j-1]; + auto point2 = win->netss[i][j]; + painter.drawLine(point1.x()*90+off, point1.y()*90+off, point2.x()*90+off, point2.y()*90+off); + } + } } diff --git a/ledset/expertscreenconnwin.h b/ledset/expertscreenconnwin.h index 681367f..2c15238 100644 --- a/ledset/expertscreenconnwin.h +++ b/ledset/expertscreenconnwin.h @@ -1,15 +1,24 @@ #ifndef EXPERTSCREENCONNWIN_H #define EXPERTSCREENCONNWIN_H -#include +#include +class CardTable; class ExpertScreenConnWin : public QWidget { Q_OBJECT public: explicit ExpertScreenConnWin(QWidget *parent = nullptr); + CardTable *table; + QList> netss{QList{}, QList{}, QList{}, QList{}}; +}; -signals: - +class CardTable : public QTableWidget { +public: + explicit CardTable(QWidget *parent = nullptr) : QTableWidget{parent} {} + CardTable(int rows, int columns, QWidget *parent = nullptr) : QTableWidget{rows, columns, parent} {} + ExpertScreenConnWin *win; +protected: + void paintEvent(QPaintEvent *event); }; #endif // EXPERTSCREENCONNWIN_H diff --git a/ledset/expertsmartpointsetwin.cpp b/ledset/expertsmartpointsetwin.cpp index 89b70a7..1aca82a 100644 --- a/ledset/expertsmartpointsetwin.cpp +++ b/ledset/expertsmartpointsetwin.cpp @@ -315,10 +315,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(QWidget *parent) : BaseWin{parent auto bnReset = new QPushButton("重新走点"); bnReset->setMinimumSize(90, 30); connect(bnReset, &QPushButton::clicked, this, [this] { - table->setColumnCount(0); - table->setRowCount(0); - table->setColumnCount(moduleWidth); - table->setRowCount(moduleHeight); + table->clearContents(); curPoint = 0; }); diff --git a/ledset/expertwin.cpp b/ledset/expertwin.cpp index e624906..1b7ff4d 100644 --- a/ledset/expertwin.cpp +++ b/ledset/expertwin.cpp @@ -1,4 +1,5 @@ #include "expertwin.h" +#include "gqt.h" #include "table.h" #include "screenunit.h" #include "expertsmartpointsetwin.h" @@ -86,14 +87,14 @@ QTabBar::tab:selected {margin-top: 0; border-bottom: none; color: #acf; backgrou vLeft->addWidget(table); table->setRowCount(4); - auto canvas = new Canvas; + auto canvas = new ResizeEmitedWgt; auto screen = new QWidget(canvas); screen->setGeometry(0, 0, screenWidth, screenHeight); screen->setAutoFillBackground(true); auto pal = palette(); pal.setColor(QPalette::Window, QColor(0, 0, 0)); screen->setPalette(pal); - connect(canvas, &Canvas::resized, this, [this, canvas, screen] { + connect(canvas, &ResizeEmitedWgt::resized, this, [this, canvas, screen] { rate = qMin(canvas->width()/(double)screenWidth, canvas->height()/(double)screenHeight); if(rate==0) return; screen->resize(qRound(screenWidth*rate), qRound(screenHeight*rate)); diff --git a/ledset/expertwin.h b/ledset/expertwin.h index c2b229f..b6873ec 100644 --- a/ledset/expertwin.h +++ b/ledset/expertwin.h @@ -10,20 +10,6 @@ public: int screenWidth{1280}, screenHeight{720}; double rate{1}; -signals: - }; -class Canvas : public QWidget { - Q_OBJECT -public: - explicit Canvas(QWidget *parent = nullptr) : QWidget{parent} {} -protected: - void resizeEvent(QResizeEvent *) override { - emit resized(); - }; - -signals: - void resized(); -}; #endif // EXPERTWIN_H diff --git a/ledset/gqt.cpp b/ledset/gqt.cpp index ed8369c..04b68fe 100644 --- a/ledset/gqt.cpp +++ b/ledset/gqt.cpp @@ -1,4 +1 @@ #include "gqt.h" - -Label::Label(QWidget *parent, Qt::WindowFlags f) : QLabel(parent, f), Wgt(this){} -Label::Label(const QString &text, QWidget *parent, Qt::WindowFlags f) : QLabel(text, parent, f), Wgt(this){} diff --git a/ledset/gqt.h b/ledset/gqt.h index a488d29..d341b50 100644 --- a/ledset/gqt.h +++ b/ledset/gqt.h @@ -1,33 +1,132 @@ -#ifndef GLABEL_H -#define GLABEL_H -#include -#include +#ifndef GQT_H +#define GQT_H +#include +#include +#include + +inline long long steady_milli() { + return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); +} +inline long long system_milli() { + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); +} +inline long long steady_micro() { + return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); +} +inline long long system_micro() { + return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); +} template -class Wgt{ +class Wrp { public: - T *wgt; - Wgt(T *wgt = nullptr){ - this->wgt = wgt; + T *obj; + Wrp(T *obj = nullptr){ + this->obj = obj; }; - inline Wgt* margin(int a){ - wgt->setMargin(a); - return this; + inline Wrp& operator()(T *obj){ + this->obj = obj; + return *this; + } + inline Wrp& operator()(T *obj, QLayout *layout){ + this->obj = obj; + layout->addWidget(obj); + return *this; + } + inline Wrp& addTo(QLayout *layout){ + layout->addWidget(obj); + return *this; + } + inline Wrp& margin(int a){ + obj->setMargin(a); + return *this; + } + inline Wrp& font(const QFont &font){ + obj->setFont(font); + return *this; + } + inline Wrp& font(int size){ + QFont font = obj->font(); + font.setPointSize(size); + obj->setFont(font); + return *this; + } + + inline Wrp& width(int w){ + obj->setFixedWidth(w); + return *this; + } + inline Wrp& height(int h){ + obj->setFixedHeight(h); + return *this; + } + inline Wrp& padding(int wAdd, int hAdd, int minW = 32, int minH = 16){ + wAdd+=8; + hAdd+=8; + QSize size = obj->fontMetrics().size(Qt::TextShowMnemonic, obj->text()); + int &rwidth = size.rwidth(); + rwidth += wAdd; + if(rwidth < minW) rwidth = minW; + int &rheight = size.rheight(); + rheight += hAdd; + if(rheight < minH) rheight = minH; + obj->setFixedSize(size); + return *this; + } + + inline Wrp& alignC(){ + obj->setAlignment(Qt::AlignCenter); + return *this; + } + inline Wrp& alignR(){ + obj->setAlignment(Qt::AlignRight); + return *this; + } + + inline Wrp& connStart(){ + QObject::connect(obj, &QThread::finished, obj, &QThread::deleteLater); + obj->start(); + return *this; } }; -class VBox : public QVBoxLayout{ +class VBox : public QBoxLayout { public: - inline VBox(QWidget *parent=nullptr) : QVBoxLayout(parent){} - inline VBox(QBoxLayout *boxLayout){ - boxLayout->addLayout(this); + inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {} + inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) { + parent->addLayout(this); + }; +}; +class HBox : public QBoxLayout { +public: + inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {} + inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) { + parent->addLayout(this); }; }; -class Label : public QLabel, public Wgt