소스 검색

editable config

logicp 5 년 전
부모
커밋
50cee8acbc
3개의 변경된 파일152개의 추가작업 그리고 78개의 파일을 삭제
  1. 1 0
      include/mainwindow.h
  2. 119 71
      mainwindow.ui
  3. 32 7
      src/mainwindow.cpp

+ 1 - 0
include/mainwindow.h

@@ -56,6 +56,7 @@ private:
     char** cli_argv;
     /** UI & Messages */
     void connectUi();
+    void setConnectScreen(bool visible = true);
     QString parseMessage(const QString& s, StringVec v);
     void updateProcessResult(QString request_id, QString result);
     /** UI Members */

+ 119 - 71
mainwindow.ui

@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>1366</width>
-    <height>810</height>
+    <height>825</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -339,71 +339,6 @@ color: rgb(0, 0, 0);</string>
      <string/>
     </property>
    </widget>
-   <widget class="QPushButton" name="connect">
-    <property name="geometry">
-     <rect>
-      <x>0</x>
-      <y>0</y>
-      <width>79</width>
-      <height>79</height>
-     </rect>
-    </property>
-    <property name="minimumSize">
-     <size>
-      <width>79</width>
-      <height>79</height>
-     </size>
-    </property>
-    <property name="maximumSize">
-     <size>
-      <width>0</width>
-      <height>0</height>
-     </size>
-    </property>
-    <property name="font">
-     <font>
-      <family>Noto Sans</family>
-      <pointsize>36</pointsize>
-      <weight>87</weight>
-      <italic>false</italic>
-      <bold>true</bold>
-     </font>
-    </property>
-    <property name="autoFillBackground">
-     <bool>false</bool>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">font: 87 36pt &quot;Noto Sans&quot;;
-color: rgb(0, 0, 0);
-background-color: rgb(2, 180, 43);
-font-weight: 700;
-padding: 4px;
-border-style: outset;
-border-width: 2px;
-border-radius: 6px;
-border-color: #00000f;
-min-width: 1em;
-min-height: 1em;
-padding: 4px;
-opacity: 0.3;</string>
-    </property>
-    <property name="text">
-     <string>Connect</string>
-    </property>
-    <property name="icon">
-     <iconset resource="kres.qrc">
-      <normaloff>:/icons/icons/start.png</normaloff>:/icons/icons/start.png</iconset>
-    </property>
-    <property name="iconSize">
-     <size>
-      <width>64</width>
-      <height>64</height>
-     </size>
-    </property>
-    <property name="flat">
-     <bool>false</bool>
-    </property>
-   </widget>
    <widget class="QWidget" name="verticalLayoutWidget_2">
     <property name="geometry">
      <rect>
@@ -693,11 +628,124 @@ font-weight: 700;</string>
      </item>
     </layout>
    </widget>
-   <zorder>label</zorder>
-   <zorder>verticalLayoutWidget</zorder>
-   <zorder>led</zorder>
-   <zorder>verticalLayoutWidget_2</zorder>
-   <zorder>connect</zorder>
+   <widget class="QWidget" name="startScreen" native="true">
+    <property name="enabled">
+     <bool>true</bool>
+    </property>
+    <property name="geometry">
+     <rect>
+      <x>0</x>
+      <y>-40</y>
+      <width>0</width>
+      <height>0</height>
+     </rect>
+    </property>
+    <property name="minimumSize">
+     <size>
+      <width>0</width>
+      <height>0</height>
+     </size>
+    </property>
+    <layout class="QVBoxLayout" name="connectScreen" stretch="0">
+     <property name="spacing">
+      <number>4</number>
+     </property>
+     <item>
+      <layout class="QVBoxLayout" name="connectLayout" stretch="0,0">
+       <property name="spacing">
+        <number>4</number>
+       </property>
+       <item>
+        <widget class="QPushButton" name="connect">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="font">
+          <font>
+           <family>Noto Sans</family>
+           <pointsize>36</pointsize>
+           <weight>87</weight>
+           <italic>false</italic>
+           <bold>true</bold>
+          </font>
+         </property>
+         <property name="autoFillBackground">
+          <bool>false</bool>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">font: 87 36pt &quot;Noto Sans&quot;;
+color: rgb(0, 0, 0);
+background-color: rgb(2, 180, 43);
+font-weight: 700;
+padding: 4px;
+border-style: outset;
+border-width: 2px;
+border-radius: 6px;
+border-color: #00000f;
+min-width: 1em;
+min-height: 1em;
+padding: 4px;
+opacity: 0.3;</string>
+         </property>
+         <property name="text">
+          <string>Connect</string>
+         </property>
+         <property name="icon">
+          <iconset resource="kres.qrc">
+           <normaloff>:/icons/icons/start.png</normaloff>:/icons/icons/start.png</iconset>
+         </property>
+         <property name="iconSize">
+          <size>
+           <width>64</width>
+           <height>64</height>
+          </size>
+         </property>
+         <property name="flat">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QTextEdit" name="kyConfig">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">

+ 32 - 7
src/mainwindow.cpp

@@ -39,11 +39,8 @@ MainWindow::MainWindow(int argc, char** argv, QWidget *parent) :
     q_client = new Client(this, cli_argc, cli_argv);
     ui->setupUi(this);
     this->setWindowTitle("KYGUI");
-
-    QPushButton *button = this->findChild<QPushButton*>("connect");
-    button->setMaximumSize(1366, 768);
-    button->setMinimumSize(1366, 768);
-    connect(button, &QPushButton::clicked, this, &MainWindow::connectClient);
+    setConnectScreen();
+    connect(ui->connect, &QPushButton::clicked, this, &MainWindow::connectClient);
     ui->processList->setModel(m_process_model);
     ui->eventList->setModel(m_event_model);
 }
@@ -57,13 +54,33 @@ MainWindow::~MainWindow()
     delete ui;
 }
 
+void MainWindow::setConnectScreen(bool visible) {
+    if (visible) {
+        ui->startScreen->setMaximumSize(1366, 825);
+        ui->startScreen->setMinimumSize(1366, 825);
+        ui->connect->setMaximumSize(1366, 725);
+        ui->connect->setMinimumSize(1366, 725);
+        ui->kyConfig->setMaximumSize(1366, 75);
+        ui->kyConfig->setMinimumSize(1366, 75);
+        QFile file(QCoreApplication::applicationDirPath() + "/config/config.json");
+        file.open(QIODevice::ReadOnly | QFile::ReadOnly);
+        QString config_json = QString::fromUtf8(file.readAll());
+        ui->kyConfig->setText(config_json);
+        qDebug() << "Set config json: \n" << ui->kyConfig->toPlainText();
+        file.close();
+    } else {
+        ui->connect->hide();
+        ui->kyConfig->hide();
+        ui->startScreen->setVisible(false);
+    }
+}
+
 /**
  * @brief MainWindow::buttonClicked
  */
 void MainWindow::connectClient() {
-    ui->connect->hide();
+    setConnectScreen(false);
     qDebug() << "Connecting to KServer";
-
     QObject::connect(q_client, &Client::messageReceived, this, &MainWindow::updateMessages);
 
     QProgressBar* progressBar = ui->progressBar;
@@ -201,8 +218,16 @@ void MainWindow::updateMessages(int t, const QString& message, StringVec v) {
         qDebug() << "Updating commands";
         QComboBox* app_list = ui->appList;
         app_list->clear();
+        ConfigJson config = getConfigObject(ui->kyConfig->toPlainText());
+        QString default_app = config.at("defaultApp");
+        int app_index = 0;
         for (const auto& s : v) {
             app_list->addItem(s);
+            if (s.toLower() == default_app.toLower()) {
+                q_client->setSelectedApp(std::vector<QString>{{default_app}});
+                ui->appList->setCurrentIndex(app_index);
+            }
+            app_index++;
         }
     } else if (t == PROCESS_REQUEST_TYPE) {
         qDebug() << "Updating process list";