Browse Source

added layouts to UI
added ability to execute commands
execute button
progress bar behaviour, but it is an illusion

logicp 5 years ago
parent
commit
aaf41f6b06
10 changed files with 201 additions and 130 deletions
  1. 1 0
      .gitignore
  2. 23 1
      client.cpp
  3. 4 0
      client.hpp
  4. BIN
      client.o
  5. 3 3
      ky_gui.pro.user
  6. 1 1
      main.cpp
  7. 29 2
      mainwindow.cpp
  8. 1 0
      mainwindow.h
  9. BIN
      mainwindow.o
  10. 139 123
      mainwindow.ui

+ 1 - 0
.gitignore

@@ -3,5 +3,6 @@ ky_gui
 moc*
 tags
 *.o
+**.o
 Makefile
 *.stash

+ 23 - 1
client.cpp

@@ -41,7 +41,7 @@ Client::MessageHandler Client::createMessageHandler(
  * @param count
  * @param arguments
  */
-Client::Client(QWidget *parent, int count, char** arguments) : QDialog(parent), argc(count), argv(arguments), m_client_socket_fd(-1), m_commands({}) {
+Client::Client(QWidget *parent, int count, char** arguments) : QDialog(parent), argc(count), argv(arguments), m_client_socket_fd(-1), m_commands({}), executing(false) {
     qRegisterMetaType<QVector<QString>>("QVector<QString>");
 }
 
@@ -191,3 +191,25 @@ void Client::closeConnection() {
     }
     qDebug() << "There is no active connection to close";
 }
+
+void Client::setSelectedApp(std::vector<QString> app_names) {
+    selected_commands.clear();
+    for (const auto& name : app_names) {
+        qDebug() << "Matching mask to " << name;
+        for (const auto& command : m_commands) {
+            if (command.second.c_str() == name.toUtf8()) {
+                selected_commands.push_back(command.first);
+            }
+        }
+    }
+}
+
+void Client::execute() {
+    if (!selected_commands.empty()) {
+        executing = true;
+        for (const auto& command : selected_commands) {
+            std::string execute_operation = createOperation("Execute", {std::to_string(command)});
+            sendEncoded(execute_operation);
+        }
+    }
+}

+ 4 - 0
client.hpp

@@ -43,11 +43,13 @@ public:
     ~Client();
     void start();
     void closeConnection();
+    void execute();
     MessageHandler createMessageHandler(std::function<void()> cb);
 
 public slots:
     void sendMessage(const QString& s);
     void sendEncoded(std::string message);
+    void setSelectedApp(std::vector<QString> app_names);
 
 signals:
     void messageReceived(int t, QString s,QVector<QString> args);
@@ -57,5 +59,7 @@ private:
     int argc;
     char** argv;
     int m_client_socket_fd;
+    bool executing;
     CommandMap m_commands;
+    std::vector<int> selected_commands;
 };

BIN
client.o


+ 3 - 3
ky_gui.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.9.2, 2019-12-24T12:11:11. -->
+<!-- Written by QtCreator 4.9.2, 2019-12-25T02:44:47. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -69,7 +69,7 @@
    <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
    <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
-    <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/c/build-ky_gui-Desktop_Qt_5_13_0_GCC_64bit-Debug</value>
+    <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/c/ky_gui</value>
     <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
      <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
       <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@@ -371,7 +371,7 @@
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
     <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
-    <value type="QString" key="RunConfiguration.WorkingDirectory.default">/data/c/build-ky_gui-Desktop_Qt_5_13_0_GCC_64bit-Debug</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">/data/c/ky_gui</value>
    </valuemap>
    <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 1 - 1
main.cpp

@@ -1,4 +1,4 @@
-#include "mainwindow.h"
+#include "mainwindow.h"
 #include <QApplication>
 
 int main(int argc, char **argv)

+ 29 - 2
mainwindow.cpp

@@ -20,6 +20,7 @@ MainWindow::MainWindow(int argc, char** argv, QWidget *parent) :
     cli_argc(argc),
     cli_argv(argv) {
     ui->setupUi(this);
+    this->setWindowTitle("KYGUI");
     QCommandLinkButton *button = this->findChild<QCommandLinkButton*>("connect");
     connect(button, &QCommandLinkButton::clicked, this, &MainWindow::connectClient);
 }
@@ -41,8 +42,13 @@ void MainWindow::connectClient() {
     Client* q_client = new Client(this, cli_argc, cli_argv);
     QObject::connect(q_client, &Client::messageReceived, this, &MainWindow::updateMessages);
 
+    QProgressBar* progressBar = ui->progressBar;
     q_client->start();
 
+    for (int i = 1; i < 101; i++) {
+        progressBar->setValue(i);
+    }
+
     KTextEdit* send_message_box = reinterpret_cast<KTextEdit*>(ui->inputText);
     send_message_box->show();
 
@@ -57,9 +63,28 @@ void MainWindow::connectClient() {
 //        q_client->sendMessage(send_message_box->toPlainText());
 //        send_message_box->clear();
 //    });
-
+    QListWidget* q_list_widget = ui->appList;
+    QObject::connect(q_list_widget, &QListWidget::itemSelectionChanged, this, [q_client, q_list_widget]() {
+        QList<QListWidgetItem*> items = q_list_widget->selectedItems();
+        if (!items.empty()) {
+            std::vector<QString> app_names{};
+            for (const auto& item : items) {
+                app_names.push_back(item->text());
+            }
+            q_client->setSelectedApp(app_names);
+        }
+    });
     QPushButton* disconnect_button = this->findChild<QPushButton*>("disconnect");
-    QObject::connect(disconnect_button, &QPushButton::clicked, q_client, &Client::closeConnection);
+    QObject::connect(disconnect_button, &QPushButton::clicked, this, [this, q_client, progressBar]() {
+        q_client->closeConnection();
+        progressBar->setValue(0);
+        ui->appList->clear();
+        ui->messages->clear();
+    });
+
+    QObject::connect(ui->execute, &QPushButton::clicked, this, [this, q_client]() {
+        q_client->execute();
+    });
 }
 
 /**
@@ -77,6 +102,8 @@ void MainWindow::updateMessages(int t, const QString& s, StringVec v) {
         for(const auto& s : v) {
             new QListWidgetItem(tr(s.toUtf8()), appList);
         }
+        //TODO: We do this because a CommandLinkButton turns transparent by default, except when hovered or checked
+        ui->connect->setChecked(true);
     } else {
         qDebug() << "Unknown update type. Cannot update UI";
     }

+ 1 - 0
mainwindow.h

@@ -3,6 +3,7 @@
 
 #include <QMainWindow>
 #include <QString>
+#include <QList>
 #include <QListWidget>
 #include <QListWidgetItem>
 #include <client.hpp>

BIN
mainwindow.o


+ 139 - 123
mainwindow.ui

@@ -6,13 +6,17 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>618</width>
-    <height>618</height>
+    <width>365</width>
+    <height>487</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
+  <property name="windowIcon">
+   <iconset>
+    <normaloff>favicon.ico</normaloff>favicon.ico</iconset>
+  </property>
   <property name="styleSheet">
    <string notr="true">font: 87 10pt &quot;Noto Sans&quot;;
 background-color: rgb(10, 10, 10);</string>
@@ -21,7 +25,7 @@ background-color: rgb(10, 10, 10);</string>
    <widget class="QLabel" name="label">
     <property name="geometry">
      <rect>
-      <x>200</x>
+      <x>100</x>
       <y>10</y>
       <width>161</width>
       <height>41</height>
@@ -37,133 +41,145 @@ background-color: rgb(10, 10, 10);</string>
      <bool>true</bool>
     </property>
    </widget>
-   <widget class="QCommandLinkButton" name="connect">
-    <property name="geometry">
-     <rect>
-      <x>20</x>
-      <y>280</y>
-      <width>168</width>
-      <height>41</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">color: rgb(16, 16, 16);
-background-color: rgb(255, 0, 153);</string>
-    </property>
-    <property name="text">
-     <string>Connect</string>
-    </property>
-   </widget>
-   <widget class="QProgressBar" name="progressBar">
-    <property name="geometry">
-     <rect>
-      <x>87</x>
-      <y>530</y>
-      <width>401</width>
-      <height>23</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(203, 0, 239);
-color: rgb(16, 16, 16);</string>
-    </property>
-    <property name="value">
-     <number>0</number>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="disconnect">
-    <property name="geometry">
-     <rect>
-      <x>190</x>
-      <y>290</y>
-      <width>80</width>
-      <height>26</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(203, 0, 239);
-color: rgb(16, 16, 16);</string>
-    </property>
-    <property name="text">
-     <string>Disconnect</string>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="sendMessage">
+   <widget class="QWidget" name="gridLayoutWidget_2">
     <property name="geometry">
      <rect>
-      <x>510</x>
-      <y>470</y>
-      <width>80</width>
-      <height>26</height>
+      <x>0</x>
+      <y>70</y>
+      <width>357</width>
+      <height>351</height>
      </rect>
     </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(203, 0, 239);
+    <layout class="QGridLayout" name="gridLayout_2">
+     <item row="1" column="0" colspan="2">
+      <widget class="QTextEdit" name="inputText">
+       <property name="styleSheet">
+        <string notr="true">background-color: rgb(0, 255, 0);
+color: rgb(5, 5, 5);
+font: 87 10pt &quot;Noto Sans&quot;;</string>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="0" colspan="2">
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QProgressBar" name="progressBar">
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(203, 0, 239);
 color: rgb(16, 16, 16);</string>
-    </property>
-    <property name="text">
-     <string>Send</string>
-    </property>
-   </widget>
-   <widget class="QTextEdit" name="inputText">
-    <property name="geometry">
-     <rect>
-      <x>40</x>
-      <y>360</y>
-      <width>521</width>
-      <height>81</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(0, 255, 0);
+         </property>
+         <property name="value">
+          <number>0</number>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="sendMessage">
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(203, 0, 239);
 color: rgb(16, 16, 16);</string>
-    </property>
-   </widget>
-   <widget class="QListWidget" name="appList">
-    <property name="geometry">
-     <rect>
-      <x>450</x>
-      <y>40</y>
-      <width>141</width>
-      <height>291</height>
-     </rect>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(0, 255, 0);
+         </property>
+         <property name="text">
+          <string>Send</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item row="0" column="0">
+      <widget class="QTextEdit" name="messages">
+       <property name="toolTip">
+        <string>Messages</string>
+       </property>
+       <property name="toolTipDuration">
+        <number>1</number>
+       </property>
+       <property name="autoFillBackground">
+        <bool>false</bool>
+       </property>
+       <property name="styleSheet">
+        <string notr="true">background-color: rgb(0, 255, 0);
+color: rgb(5, 5, 5);
+font: 87 10pt &quot;Noto Sans&quot;;</string>
+       </property>
+       <property name="lineWrapMode">
+        <enum>QTextEdit::WidgetWidth</enum>
+       </property>
+       <property name="readOnly">
+        <bool>true</bool>
+       </property>
+       <property name="placeholderText">
+        <string/>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <layout class="QGridLayout" name="gridLayout">
+       <item row="1" column="0">
+        <widget class="QCommandLinkButton" name="connect">
+         <property name="styleSheet">
+          <string notr="true">color: rgb(16, 16, 16);
+background-color: rgb(255, 0, 153);
+</string>
+         </property>
+         <property name="text">
+          <string>Connect</string>
+         </property>
+         <property name="checkable">
+          <bool>true</bool>
+         </property>
+         <property name="checked">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="0">
+        <widget class="QPushButton" name="disconnect">
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(203, 0, 239);
 color: rgb(16, 16, 16);</string>
-    </property>
-   </widget>
-   <widget class="QTextEdit" name="messages">
-    <property name="geometry">
-     <rect>
-      <x>40</x>
-      <y>60</y>
-      <width>391</width>
-      <height>211</height>
-     </rect>
-    </property>
-    <property name="toolTip">
-     <string>Messages</string>
-    </property>
-    <property name="toolTipDuration">
-     <number>1</number>
-    </property>
-    <property name="autoFillBackground">
-     <bool>false</bool>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background-color: rgb(0, 255, 0);
+         </property>
+         <property name="text">
+          <string>Disconnect</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="0">
+        <widget class="QListWidget" name="appList">
+         <property name="font">
+          <font>
+           <family>Noto Sans</family>
+           <pointsize>10</pointsize>
+           <weight>10</weight>
+           <italic>false</italic>
+           <bold>false</bold>
+          </font>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(0, 255, 0);
+color: rgb(5, 5, 5);
+font: 87 10pt &quot;Noto Sans&quot;;
+selection-background-color: rgb(255, 0, 174);</string>
+         </property>
+         <property name="selectionMode">
+          <enum>QAbstractItemView::MultiSelection</enum>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QPushButton" name="execute">
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(203, 0, 239);
 color: rgb(16, 16, 16);</string>
-    </property>
-    <property name="lineWrapMode">
-     <enum>QTextEdit::WidgetWidth</enum>
-    </property>
-    <property name="readOnly">
-     <bool>true</bool>
-    </property>
-    <property name="placeholderText">
-     <string/>
-    </property>
+         </property>
+         <property name="text">
+          <string>Execute</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+    </layout>
    </widget>
   </widget>
   <widget class="QMenuBar" name="menuBar">
@@ -171,7 +187,7 @@ color: rgb(16, 16, 16);</string>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>618</width>
+     <width>365</width>
      <height>23</height>
     </rect>
    </property>