Browse Source

adding dialog window

logicp 5 years ago
parent
commit
4cc0815c66
11 changed files with 373 additions and 38 deletions
  1. 14 0
      argdialog.cpp
  2. 22 0
      argdialog.h
  3. 143 0
      argdialog.ui
  4. 3 1
      client.hpp
  5. 27 0
      headers/util.hpp
  6. 3 0
      ky_gui.pro
  7. 1 1
      ky_gui.pro.user
  8. 13 0
      mainwindow.cpp
  9. 2 0
      mainwindow.h
  10. 51 36
      mainwindow.ui
  11. 94 0
      ui_argdialog.h

+ 14 - 0
argdialog.cpp

@@ -0,0 +1,14 @@
+#include "argdialog.h"
+#include "ui_argdialog.h"
+
+ArgDialog::ArgDialog(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::ArgDialog)
+{
+    ui->setupUi(this);
+}
+
+ArgDialog::~ArgDialog()
+{
+    delete ui;
+}

+ 22 - 0
argdialog.h

@@ -0,0 +1,22 @@
+#ifndef ARGDIALOG_H
+#define ARGDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+class ArgDialog;
+}
+
+class ArgDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ArgDialog(QWidget *parent = nullptr);
+    ~ArgDialog();
+
+private:
+    Ui::ArgDialog *ui;
+};
+
+#endif // ARGDIALOG_H

+ 143 - 0
argdialog.ui

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ArgDialog</class>
+ <widget class="QDialog" name="ArgDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>490</width>
+    <height>347</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QDialogButtonBox" name="argButtonBox">
+   <property name="geometry">
+    <rect>
+     <x>70</x>
+     <y>300</y>
+     <width>341</width>
+     <height>32</height>
+    </rect>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">background-color: rgb(203, 0, 239);
+color: rgb(16, 16, 16);</string>
+   </property>
+   <property name="orientation">
+    <enum>Qt::Horizontal</enum>
+   </property>
+   <property name="standardButtons">
+    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+   </property>
+  </widget>
+  <widget class="QListView" name="argList">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>60</y>
+     <width>361</width>
+     <height>151</height>
+    </rect>
+   </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>
+  </widget>
+  <widget class="QPushButton" name="addArgument">
+   <property name="geometry">
+    <rect>
+     <x>340</x>
+     <y>240</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>Add</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="argInput">
+   <property name="geometry">
+    <rect>
+     <x>80</x>
+     <y>240</y>
+     <width>231</width>
+     <height>26</height>
+    </rect>
+   </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>
+  </widget>
+  <widget class="QLabel" name="argDialogTitle">
+   <property name="geometry">
+    <rect>
+     <x>130</x>
+     <y>10</y>
+     <width>231</width>
+     <height>51</height>
+    </rect>
+   </property>
+   <property name="font">
+    <font>
+     <pointsize>22</pointsize>
+     <weight>75</weight>
+     <bold>true</bold>
+    </font>
+   </property>
+   <property name="styleSheet">
+    <string notr="true">color: rgb(170, 0, 255);</string>
+   </property>
+   <property name="text">
+    <string>Add Arguments</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>argButtonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ArgDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>argButtonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ArgDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

+ 3 - 1
client.hpp

@@ -17,7 +17,7 @@ static constexpr int MESSAGE_UPDATE_TYPE = 1;
 static constexpr int COMMANDS_UPDATE_TYPE = 2;
 
 typedef std::map<int, std::string> CommandMap;
-
+typedef std::map<int, std::vector<std::string>> CommandArgMap;
 typedef QVector<QString> StringVec;
 Q_DECLARE_METATYPE(StringVec)
 
@@ -61,5 +61,7 @@ private:
     int m_client_socket_fd;
     bool executing;
     CommandMap m_commands;
+    CommandArgMap m_command_arg_map;
     std::vector<int> selected_commands;
+
 };

+ 27 - 0
headers/util.hpp

@@ -121,6 +121,33 @@ std::string createMessage(const char* data,
     return s.GetString();
 }
 
+std::string createMessage(const char* data, std::map<int, std::vector<std::string>> map = {}) {
+    StringBuffer s;
+    Writer<StringBuffer> w(s);
+    w.StartObject();
+    w.Key("type");
+    w.String("custom");
+    w.Key("message");
+    w.String(data);
+    w.Key("args");
+    w.StartObject();
+    if (!map.empty()) {
+        for (const auto& [k, v] : map) {
+            w.Key(std::to_string(k).c_str());
+            if (!v.empty()) {
+                w.StartArray();
+                for (const auto& arg : v) {
+                    w.String(arg.c_str());
+                }
+                w.EndArray();
+            }
+        }
+    }
+    w.EndObject();
+    w.EndObject();
+    return s.GetString();
+}
+
 std::string rapidCreateMessage(const char* data,
                                std::map<int, std::string> map = {}) {
     StringBuffer s;

+ 3 - 0
ky_gui.pro

@@ -26,11 +26,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
 CONFIG += c++17
 
 SOURCES += \
+        argdialog.cpp \
         main.cpp \
         mainwindow.cpp \
         client.cpp
 
 HEADERS += \
+        argdialog.h \
         mainwindow.h \
         client.hpp \
         headers/ktextedit.hpp \
@@ -44,6 +46,7 @@ HEADERS += \
 
 
 FORMS += \
+        argdialog.ui \
         mainwindow.ui
 
 # Default rules for deployment.

+ 1 - 1
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-25T02:44:47. -->
+<!-- Written by QtCreator 4.9.2, 2019-12-27T15:00:41. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 13 - 0
mainwindow.cpp

@@ -17,6 +17,7 @@
 MainWindow::MainWindow(int argc, char** argv, QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow),
+    arg_ui(new ArgDialog),
     cli_argc(argc),
     cli_argv(argv) {
     ui->setupUi(this);
@@ -85,6 +86,18 @@ void MainWindow::connectClient() {
     QObject::connect(ui->execute, &QPushButton::clicked, this, [this, q_client]() {
         q_client->execute();
     });
+
+    QObject::connect(ui->addArgs, &QPushButton::clicked, this, [this]() {
+        auto items = ui->appList->selectedItems();
+        if (items.size() == 1) {
+            // open dialog to add arguments
+            arg_ui->show();
+        } else if (items.size() == 0) {
+            qDebug() << "You must select an App to add arguments to";
+        } else {
+            qDebug() << "Can only add arguments to one app. Please select just one app before adding arguments";
+        }
+    });
 }
 
 /**

+ 2 - 0
mainwindow.h

@@ -8,6 +8,7 @@
 #include <QListWidgetItem>
 #include <client.hpp>
 #include <headers/ktextedit.hpp>
+#include <argdialog.h>
 
 namespace Ui {
 class MainWindow;
@@ -22,6 +23,7 @@ public:
     ~MainWindow();
 private:
     Ui::MainWindow *ui;
+    ArgDialog *arg_ui;
     void connectUi();
     void runApp();
     int cli_argc;

+ 51 - 36
mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>365</width>
-    <height>487</height>
+    <width>380</width>
+    <height>485</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -25,7 +25,7 @@ background-color: rgb(10, 10, 10);</string>
    <widget class="QLabel" name="label">
     <property name="geometry">
      <rect>
-      <x>100</x>
+      <x>110</x>
       <y>10</y>
       <width>161</width>
       <height>41</height>
@@ -44,7 +44,7 @@ background-color: rgb(10, 10, 10);</string>
    <widget class="QWidget" name="gridLayoutWidget_2">
     <property name="geometry">
      <rect>
-      <x>0</x>
+      <x>10</x>
       <y>70</y>
       <width>357</width>
       <height>351</height>
@@ -115,35 +115,6 @@ font: 87 10pt &quot;Noto Sans&quot;;</string>
      </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>
-         <property name="text">
-          <string>Disconnect</string>
-         </property>
-        </widget>
-       </item>
        <item row="0" column="0">
         <widget class="QListWidget" name="appList">
          <property name="font">
@@ -166,17 +137,61 @@ selection-background-color: rgb(255, 0, 174);</string>
          </property>
         </widget>
        </item>
+       <item row="2" 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="3" column="0">
-        <widget class="QPushButton" name="execute">
+        <widget class="QPushButton" name="disconnect">
          <property name="styleSheet">
           <string notr="true">background-color: rgb(203, 0, 239);
 color: rgb(16, 16, 16);</string>
          </property>
          <property name="text">
-          <string>Execute</string>
+          <string>Disconnect</string>
          </property>
         </widget>
        </item>
+       <item row="1" column="0">
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <widget class="QPushButton" name="addArgs">
+           <property name="styleSheet">
+            <string notr="true">background-color: rgb(203, 0, 239);
+color: rgb(16, 16, 16);</string>
+           </property>
+           <property name="text">
+            <string>Args</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <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="text">
+            <string>Execute</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
       </layout>
      </item>
     </layout>
@@ -187,7 +202,7 @@ color: rgb(16, 16, 16);</string>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>365</width>
+     <width>380</width>
      <height>23</height>
     </rect>
    </property>

+ 94 - 0
ui_argdialog.h

@@ -0,0 +1,94 @@
+/********************************************************************************
+** Form generated from reading UI file 'argdialog.ui'
+**
+** Created by: Qt User Interface Compiler version 5.13.0
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_ARGDIALOG_H
+#define UI_ARGDIALOG_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QDialog>
+#include <QtWidgets/QDialogButtonBox>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QLineEdit>
+#include <QtWidgets/QListView>
+#include <QtWidgets/QPushButton>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_ArgDialog
+{
+public:
+    QDialogButtonBox *argButtonBox;
+    QListView *argList;
+    QPushButton *addArgument;
+    QLineEdit *argInput;
+    QLabel *argDialogTitle;
+
+    void setupUi(QDialog *ArgDialog)
+    {
+        if (ArgDialog->objectName().isEmpty())
+            ArgDialog->setObjectName(QString::fromUtf8("ArgDialog"));
+        ArgDialog->resize(490, 347);
+        argButtonBox = new QDialogButtonBox(ArgDialog);
+        argButtonBox->setObjectName(QString::fromUtf8("argButtonBox"));
+        argButtonBox->setGeometry(QRect(70, 300, 341, 32));
+        argButtonBox->setStyleSheet(QString::fromUtf8("background-color: rgb(203, 0, 239);\n"
+"color: rgb(16, 16, 16);"));
+        argButtonBox->setOrientation(Qt::Horizontal);
+        argButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+        argList = new QListView(ArgDialog);
+        argList->setObjectName(QString::fromUtf8("argList"));
+        argList->setGeometry(QRect(60, 60, 361, 151));
+        argList->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 255, 0);\n"
+"color: rgb(5, 5, 5);\n"
+"font: 87 10pt \"Noto Sans\";\n"
+"selection-background-color: rgb(255, 0, 174);"));
+        addArgument = new QPushButton(ArgDialog);
+        addArgument->setObjectName(QString::fromUtf8("addArgument"));
+        addArgument->setGeometry(QRect(340, 240, 80, 26));
+        addArgument->setStyleSheet(QString::fromUtf8("background-color: rgb(203, 0, 239);\n"
+"color: rgb(16, 16, 16);"));
+        argInput = new QLineEdit(ArgDialog);
+        argInput->setObjectName(QString::fromUtf8("argInput"));
+        argInput->setGeometry(QRect(80, 240, 231, 26));
+        argInput->setStyleSheet(QString::fromUtf8("background-color: rgb(0, 255, 0);\n"
+"color: rgb(5, 5, 5);\n"
+"font: 87 10pt \"Noto Sans\";"));
+        argDialogTitle = new QLabel(ArgDialog);
+        argDialogTitle->setObjectName(QString::fromUtf8("argDialogTitle"));
+        argDialogTitle->setGeometry(QRect(130, 10, 231, 51));
+        QFont font;
+        font.setPointSize(22);
+        font.setBold(true);
+        font.setWeight(75);
+        argDialogTitle->setFont(font);
+        argDialogTitle->setStyleSheet(QString::fromUtf8("color: rgb(170, 0, 255);"));
+
+        retranslateUi(ArgDialog);
+        QObject::connect(argButtonBox, SIGNAL(accepted()), ArgDialog, SLOT(accept()));
+        QObject::connect(argButtonBox, SIGNAL(rejected()), ArgDialog, SLOT(reject()));
+
+        QMetaObject::connectSlotsByName(ArgDialog);
+    } // setupUi
+
+    void retranslateUi(QDialog *ArgDialog)
+    {
+        ArgDialog->setWindowTitle(QCoreApplication::translate("ArgDialog", "Dialog", nullptr));
+        addArgument->setText(QCoreApplication::translate("ArgDialog", "Add", nullptr));
+        argDialogTitle->setText(QCoreApplication::translate("ArgDialog", "Add Arguments", nullptr));
+    } // retranslateUi
+
+};
+
+namespace Ui {
+    class ArgDialog: public Ui_ArgDialog {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_ARGDIALOG_H