diff --git a/src/application.cpp b/src/application.cpp index 16fc27c0..586d5628 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -247,3 +247,13 @@ void Application::showSplashScreenMessage(const QString &msg) splashScreen->showMessage(msg, Qt::AlignBottom | Qt::AlignLeft, Qt::white); QApplication::processEvents(); } + +QString Application::left2rightTips() const +{ + return tr("Transfer rx bytes with right page"); +} + +QString Application::right2leftTips() const +{ + return tr("Transfer rx bytes with left page"); +} \ No newline at end of file diff --git a/src/application.h b/src/application.h index 8dc4f7bd..032b2693 100644 --- a/src/application.h +++ b/src/application.h @@ -45,4 +45,7 @@ public: QSplashScreen *splashScreen(); void showSplashScreenMessage(const QString &msg); + + QString left2rightTips() const; + QString right2leftTips() const; }; diff --git a/src/main.cpp b/src/main.cpp index fae8d33e..ad640534 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,9 +24,10 @@ int main(int argc, char *argv[]) MainWindow window; QSplashScreen *splash = app.splashScreen(); splash->finish(&window); - window.resize(1366, 768); + window.resize(620 * 1.732, 620); window.show(); window.load(); + window.moveToCenter(); int ret = app.exec(); Application::uninstallLog(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f13273b1..6e677372 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,19 @@ void MainWindow::updateGrid(WindowGrid grid) xApp->settings()->setValue(m_settingsKey.windowGrid, static_cast(grid)); } +void MainWindow::moveToCenter() +{ + QRect screenRect = QApplication::primaryScreen()->geometry(); + bool tooWidth = (width() > screenRect.width()); + bool tooHeight = (height() > screenRect.height()); + if (tooWidth || tooHeight) { + showMaximized(); + qInfo() << "The screen is too small."; + } else { + move((screenRect.width() - width()) / 2, (screenRect.height() - height()) / 2); + } +} + void MainWindow::closeEvent(QCloseEvent* event) { save(); diff --git a/src/mainwindow.h b/src/mainwindow.h index a0e7ad71..341a466f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -26,6 +26,7 @@ public: void load(const QString& fileName = QString()) const; void save(const QString& fileName = QString()) const; void updateGrid(WindowGrid grid); + void moveToCenter(); protected: void closeEvent(QCloseEvent* event) override; diff --git a/src/page/page.cpp b/src/page/page.cpp index a586892b..206e3c33 100644 --- a/src/page/page.cpp +++ b/src/page/page.cpp @@ -266,7 +266,7 @@ QToolButton *Page::presetToolButton() void Page::inputBytes(const QByteArray &bytes) { - if (m_deviceController->device() && m_deviceController->device()->isRunning()) { + if (m_deviceController->device()) { m_deviceController->device()->writeBytes(bytes); } } @@ -296,6 +296,17 @@ void Page::hideTransferWidgets() ui->tabTransfers->hide(); } +void Page::removeTestDevices() +{ + for (int i = 0; i < ui->comboBoxDeviceTypes->count(); i++) { + int type = ui->comboBoxDeviceTypes->itemData(i).toInt(); + if (type == static_cast(DeviceType::ChartsTest)) { + ui->comboBoxDeviceTypes->removeItem(i); + break; + } + } +} + void Page::initUi() { #if 0 diff --git a/src/page/page.h b/src/page/page.h index 8c01c127..1c6bb8a7 100644 --- a/src/page/page.h +++ b/src/page/page.h @@ -54,6 +54,7 @@ public: void appendOutputControl(QWidget *widget); void hideChartsWidgets(); void hideTransferWidgets(); + void removeTestDevices(); signals: void bytesWritten(const QByteArray &bytes, const QString &to); diff --git a/xapps/xassistant/res/icons/left_blue.svg b/xapps/xassistant/res/icons/left_blue.svg new file mode 100644 index 00000000..d79ae042 --- /dev/null +++ b/xapps/xassistant/res/icons/left_blue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xapps/xassistant/res/icons/left_gray.svg b/xapps/xassistant/res/icons/left_gray.svg new file mode 100644 index 00000000..95c2b471 --- /dev/null +++ b/xapps/xassistant/res/icons/left_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xapps/xassistant/res/icons/right_blue.svg b/xapps/xassistant/res/icons/right_blue.svg new file mode 100644 index 00000000..e902c0ee --- /dev/null +++ b/xapps/xassistant/res/icons/right_blue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xapps/xassistant/res/icons/right_gray.svg b/xapps/xassistant/res/icons/right_gray.svg new file mode 100644 index 00000000..8fd0f96a --- /dev/null +++ b/xapps/xassistant/res/icons/right_gray.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/xapps/xassistant/src/main.cpp b/xapps/xassistant/src/main.cpp index f92e5266..6eaa73ce 100644 --- a/xapps/xassistant/src/main.cpp +++ b/xapps/xassistant/src/main.cpp @@ -24,10 +24,11 @@ int main(int argc, char *argv[]) xAssistant window; QSplashScreen *splash = app.splashScreen(); splash->finish(&window); - window.resize(620 * 1.732, 620); + window.resize(1280, 620); window.show(); window.load(); window.updateGrid(MainWindow::WindowGrid::Grid1x2); + window.moveToCenter(); int ret = app.exec(); Application::uninstallLog(); diff --git a/xapps/xassistant/src/pipe.cpp b/xapps/xassistant/src/pipe.cpp index ee5a6003..28c03de2 100644 --- a/xapps/xassistant/src/pipe.cpp +++ b/xapps/xassistant/src/pipe.cpp @@ -1,5 +1,5 @@ /*************************************************************************************************** - * Copyright 2024 x-tools-author(x-tools@outlook.com). All rights reserved. + * Copyright 2024-2025 x-tools-author(x-tools@outlook.com). All rights reserved. * * The file is encoded using "utf8 with bom", it is a part of eTools project. * @@ -8,71 +8,78 @@ **************************************************************************************************/ #include "pipe.h" +#include + +#include "application.h" #include "device/device.h" #include "page/page.h" -Pipeline::Pipeline(Page *leftPage, Page *rightPage, QObject *parent) +Pipe::Pipe(Page *leftPage, Page *rightPage, QObject *parent) : QObject(parent) , m_leftPage(leftPage) , m_rightPage(rightPage) { - // QToolButton *leftPageLeftButton = m_leftPage->outputPanel()->leftButton(); - // m_left2rightButton = m_leftPage->outputPanel()->rightButton(); - // m_right2leftButton = m_rightPage->outputPanel()->leftButton(); - // QToolButton *rightPageRightButton = m_rightPage->outputPanel()->rightButton(); - // leftPageLeftButton->setVisible(false); - // rightPageRightButton->setVisible(false); - // m_left2rightButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - // m_right2leftButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - // m_left2rightButton->setCheckable(true); - // m_right2leftButton->setCheckable(true); - // m_left2rightButton->setIcon(QIcon(":/Resource/Icons/RightGray.svg")); - // m_right2leftButton->setIcon(QIcon(":/Resource/Icons/LeftGray.svg")); - // m_left2rightButton->setToolTip(tr("Transmit the data received by the right page")); - // m_right2leftButton->setToolTip(tr("Transmit the data received by the left page")); - // connect(m_left2rightButton, &QToolButton::clicked, this, &Pipeline::onLeft2RightButtonClicked); - // connect(m_right2leftButton, &QToolButton::clicked, this, &Pipeline::onRight2LeftButtonClicked); + m_leftButton = new QToolButton(); + m_rightButton = new QToolButton(); + m_leftButton->setCheckable(true); + m_rightButton->setCheckable(true); + m_leftButton->setToolTip(xApp->left2rightTips()); + m_rightButton->setToolTip(xApp->right2leftTips()); + leftPage->appendOutputControl(m_leftButton); + rightPage->prependOutputControl(m_rightButton); - // connect(m_leftPage, &Page::bytesRead, this, &Pipeline::onLeftPageBytesRead); - // connect(m_rightPage, &Page::bytesRead, this, &Pipeline::onRightPageBytesRead); + connect(m_leftButton, &QToolButton::clicked, this, &Pipe::onLeftButtonClicked); + connect(m_rightButton, &QToolButton::clicked, this, &Pipe::onRightButtonClicked); + + connect(leftPage, &Page::bytesRead, this, &Pipe::onLeftPageBytesRead); + connect(rightPage, &Page::bytesRead, this, &Pipe::onRightPageBytesRead); + + QSettings *settings = xApp->settings(); + bool left2right = settings->value(m_keys.left2right, false).toBool(); + bool right2left = settings->value(m_keys.right2left, false).toBool(); + m_leftButton->setChecked(left2right); + m_rightButton->setChecked(right2left); + + onLeftButtonClicked(); + onRightButtonClicked(); } -Pipeline::~Pipeline() {} +Pipe::~Pipe() {} -void Pipeline::onLeft2RightButtonClicked() +void Pipe::onLeftButtonClicked() { - if (m_left2rightButton->isChecked()) { - m_left2rightButton->setIcon(QIcon(":/Resource/Icons/RightGreen.svg")); + if (m_leftButton->isChecked()) { + m_leftButton->setIcon(QIcon(":/res/icons/right_gray.svg")); } else { - m_left2rightButton->setIcon(QIcon(":/Resource/Icons/RightGray.svg")); + m_leftButton->setIcon(QIcon(":/res/icons/right_blue.svg")); + } + + xApp->settings()->setValue(m_keys.left2right, m_leftButton->isChecked()); +} + +void Pipe::onRightButtonClicked() +{ + if (m_rightButton->isChecked()) { + m_rightButton->setIcon(QIcon(":/res/icons/left_gray.svg")); + } else { + m_rightButton->setIcon(QIcon(":/res/icons/left_blue.svg")); + } + + xApp->settings()->setValue(m_keys.right2left, m_rightButton->isChecked()); +} + +void Pipe::onLeftPageBytesRead(const QByteArray &bytes, const QString &from) +{ + Q_UNUSED(from); + if (m_leftButton->isChecked()) { + m_rightPage->inputBytes(bytes); } } -void Pipeline::onRight2LeftButtonClicked() +void Pipe::onRightPageBytesRead(const QByteArray &bytes, const QString &from) { - if (m_right2leftButton->isChecked()) { - m_right2leftButton->setIcon(QIcon(":/Resource/Icons/LeftGreen.svg")); - } else { - m_right2leftButton->setIcon(QIcon(":/Resource/Icons/LeftGray.svg")); + Q_UNUSED(from); + if (m_rightButton->isChecked()) { + m_leftPage->inputBytes(bytes); } } - -void Pipeline::onLeftPageBytesRead(const QByteArray &bytes) -{ - // if (m_left2rightButton->isChecked()) { - // Device *device = m_leftPage->device(); - // if (device) { - // device->writeBytes(bytes); - // } - // } -} - -void Pipeline::onRightPageBytesRead(const QByteArray &bytes) -{ - // if (m_right2leftButton->isChecked()) { - // Device *device = m_rightPage->device(); - // if (device) { - // device->writeBytes(bytes); - // } - // } -} diff --git a/xapps/xassistant/src/pipe.h b/xapps/xassistant/src/pipe.h index a80d40a9..9a161916 100644 --- a/xapps/xassistant/src/pipe.h +++ b/xapps/xassistant/src/pipe.h @@ -12,23 +12,30 @@ #include class Page; -class Pipeline : public QObject +class Pipe : public QObject { Q_OBJECT public: - Pipeline(Page *leftPage, Page *rightPage, QObject *parent = nullptr); - ~Pipeline(); + Pipe(Page *leftPage, Page *rightPage, QObject *parent = nullptr); + ~Pipe(); private: Page *m_leftPage; Page *m_rightPage; - QToolButton *m_left2rightButton; - QToolButton *m_right2leftButton; + QToolButton *m_leftButton; + QToolButton *m_rightButton; private: - void onLeft2RightButtonClicked(); - void onRight2LeftButtonClicked(); + struct + { + const QString left2right{"MainWindow/left2right"}; + const QString right2left{"MainWindow/right2left"}; + } m_keys; - void onLeftPageBytesRead(const QByteArray &bytes); - void onRightPageBytesRead(const QByteArray &bytes); +private: + void onLeftButtonClicked(); + void onRightButtonClicked(); + + void onLeftPageBytesRead(const QByteArray &bytes, const QString &from); + void onRightPageBytesRead(const QByteArray &bytes, const QString &from); }; diff --git a/xapps/xassistant/src/xassistant.cpp b/xapps/xassistant/src/xassistant.cpp index 2ee3ae31..e0f1e615 100644 --- a/xapps/xassistant/src/xassistant.cpp +++ b/xapps/xassistant/src/xassistant.cpp @@ -1,5 +1,5 @@ /*************************************************************************************************** - * Copyright 2018-2025 x-tools-author(x-tools@outlook.com). All rights reserved. + * Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved. * * The file is encoded using "utf8 with bom", it is a part of xTools project. * @@ -11,6 +11,7 @@ #include #include "page/page.h" +#include "pipe.h" xAssistant::xAssistant(QWidget* parent) : MainWindow(parent) @@ -42,6 +43,14 @@ xAssistant::xAssistant(QWidget* parent) m_iopage01->hideChartsWidgets(); m_iopage10->hideChartsWidgets(); m_iopage11->hideChartsWidgets(); + + m_iopage00->removeTestDevices(); + m_iopage01->removeTestDevices(); + m_iopage10->removeTestDevices(); + m_iopage11->removeTestDevices(); + + Pipe* pipe = new Pipe(m_iopage00, m_iopage01, this); + Q_UNUSED(pipe); } xAssistant::~xAssistant() {} diff --git a/xapps/xassistant/src/xassistant.h b/xapps/xassistant/src/xassistant.h index 8320ac4d..980ab46a 100644 --- a/xapps/xassistant/src/xassistant.h +++ b/xapps/xassistant/src/xassistant.h @@ -1,5 +1,5 @@ /*************************************************************************************************** - * Copyright 2018-2025 x-tools-author(x-tools@outlook.com). All rights reserved. + * Copyright 2025-2025 x-tools-author(x-tools@outlook.com). All rights reserved. * * The file is encoded using "utf8 with bom", it is a part of xTools project. * @@ -10,7 +10,6 @@ #include "mainwindow.h" -class Page; class xAssistant : public MainWindow { Q_OBJECT diff --git a/xapps/xassistant/xAssistant.cmake b/xapps/xassistant/xAssistant.cmake index 55df9c41..a7505d86 100644 --- a/xapps/xassistant/xAssistant.cmake +++ b/xapps/xassistant/xAssistant.cmake @@ -5,6 +5,7 @@ endif() file(GLOB_RECURSE X_ASSISTANT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.*) list(APPEND X_ASSISTANT_SOURCES ${X_APPS_SOURCES}) list(APPEND X_ASSISTANT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/xAssistant.rc) +list(APPEND X_ASSISTANT_SOURCES ${CMAKE_CURRENT_LIST_DIR}/xAssistant.qrc) include_directories(${CMAKE_CURRENT_LIST_DIR}/src) set(bin ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE}/xAssistant) diff --git a/xapps/xassistant/xAssistant.qrc b/xapps/xassistant/xAssistant.qrc new file mode 100644 index 00000000..9c084de8 --- /dev/null +++ b/xapps/xassistant/xAssistant.qrc @@ -0,0 +1,8 @@ + + + res/icons/left_blue.svg + res/icons/left_gray.svg + res/icons/right_blue.svg + res/icons/right_gray.svg + +