Browse Source

adding led indicator

logicp 5 years ago
parent
commit
82cfbd0057
8 changed files with 254 additions and 45 deletions
  1. 1 4
      client.cpp
  2. 41 0
      connection_indicator.cpp
  3. 26 0
      connection_indicator.h
  4. 4 2
      ky_gui.pro
  5. 1 1
      ky_gui.pro.user
  6. 9 0
      mainwindow.cpp
  7. 108 38
      mainwindow.ui
  8. 64 0
      ui_consoledialog.h

+ 1 - 4
client.cpp

@@ -14,13 +14,10 @@
 #include <vector>
 #include <future>
 #include <headers/kmessage_codec.hpp>
-#include <headers/json.hpp>
 #include <headers/util.hpp>
 
 using namespace KData;
 
-using json = nlohmann::json;
-
 static const int MAX_BUFFER_SIZE = 2048;
 static const int MAX_PACKET_SIZE = 4096;
 static const int HEADER_SIZE = 4;
@@ -77,7 +74,7 @@ void Client::handleMessages() {
             for (const auto& [k, v] : m_commands) {
                 s_v.push_back(v.data());
             }
-            emit Client::messageReceived(COMMANDS_UPDATE_TYPE, "", s_v);
+            emit Client::messageReceived(COMMANDS_UPDATE_TYPE, "New Session", s_v);
         } else if (serverWaitingForFile(data_string.c_str())) {
             sendFileEncoded(outgoing_file);
         } else if (isEvent(data_string.c_str())) {

+ 41 - 0
connection_indicator.cpp

@@ -0,0 +1,41 @@
+#include "connection_indicator.h"
+#include <QDebug>
+
+static const int SIZE = 20;
+static const QString greenSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.145, y1:0.16, x2:1, y2:1, stop:0 rgba(20, 252, 7, 255), stop:1 rgba(25, 134, 5, 255));").arg(SIZE/2);
+static const QString redSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.145, y1:0.16, x2:0.92, y2:0.988636, stop:0 rgba(255, 12, 12, 255), stop:0.869347 rgba(103, 0, 0, 255));").arg(SIZE/2);
+static const QString orangeSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.232, y1:0.272, x2:0.98, y2:0.959773, stop:0 rgba(255, 113, 4, 255), stop:1 rgba(91, 41, 7, 255))").arg(SIZE/2);
+static const QString blueSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.04, y1:0.0565909, x2:0.799, y2:0.795, stop:0 rgba(203, 220, 255, 255), stop:0.41206 rgba(0, 115, 255, 255), stop:1 rgba(0, 49, 109, 255));").arg(SIZE/2);
+
+
+ConnectionIndicator::ConnectionIndicator(QWidget *parent) : QLabel(parent)
+{
+    //Set to ok by default
+    setState(StateDisconnected);
+    setFixedSize(SIZE, SIZE);
+}
+
+void ConnectionIndicator::setState(State state)
+{
+    qDebug() << "setState" << state;
+    switch(state){
+    case StateConnected:
+        setStyleSheet(greenSS);
+        break;
+    case StateWarning:
+        setStyleSheet(orangeSS);
+        break;
+    case StateDisconnected:
+        setStyleSheet(redSS);
+        break;
+    case StateOkBlue:
+    default:
+        setStyleSheet(blueSS);
+        break;
+    }
+}
+
+void ConnectionIndicator::setState(bool state)
+{
+    setState(state ? StateConnected : StateDisconnected);
+}

+ 26 - 0
connection_indicator.h

@@ -0,0 +1,26 @@
+#ifndef CONNECTIONINDICATOR_H
+#define CONNECTIONINDICATOR_H
+
+#include <QLabel>
+
+class ConnectionIndicator : public QLabel
+{
+    Q_OBJECT
+public:
+    explicit ConnectionIndicator(QWidget *parent = nullptr);
+
+    enum State{
+        StateConnected,
+        StateOkBlue,
+        StateWarning,
+        StateDisconnected
+    };
+
+    void setState(bool state);
+    void setState(State state);
+
+signals:
+
+};
+
+#endif // CONNECTIONINDICATOR_H

+ 4 - 2
ky_gui.pro

@@ -30,7 +30,8 @@ SOURCES += \
         consoledialog.cpp \
         main.cpp \
         mainwindow.cpp \
-        client.cpp
+        client.cpp \
+        connection_indicator.cpp
 
 HEADERS += \
         argdialog.h \
@@ -43,7 +44,8 @@ HEADERS += \
         headers/util.hpp \
         headers/rapidjson/writer.h \
         headers/rapidjson/stringbuffer.h \
-        headers/rapidjson/document.h
+        headers/rapidjson/document.h \
+        connection_indicator.h
 
 
 

+ 1 - 1
ky_gui.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.11.0, 2020-01-10T01:04:37. -->
+<!-- Written by QtCreator 4.11.0, 2020-01-12T01:03:47. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 9 - 0
mainwindow.cpp

@@ -76,6 +76,7 @@ void MainWindow::connectClient() {
         progressBar->setValue(0);
         ui->appList->clear();
         ui->messages->clear();
+        ui->led->setState(false);
     });
 
     QObject::connect(ui->execute, &QPushButton::clicked, this, [this]() {
@@ -112,6 +113,11 @@ void MainWindow::connectClient() {
         }
     });
 
+    QObject::connect(ui->tasks, &QPushButton::clicked, this, [this]() {
+        // TODO: Change this to a complete implementation
+        q_client->sendMessage("scheduler");
+    });
+
     QObject::connect(ui->viewConsole, &QPushButton::clicked, this, [this]() {
         m_console.show();
     });
@@ -160,6 +166,9 @@ void MainWindow::updateMessages(int t, const QString& message, StringVec v) {
         ui->messages->append(simple_message);
         m_console.updateText(message);
     } else if (t == COMMANDS_UPDATE_TYPE) {
+        if (message == "New Session") {
+            ui->led->setState(true);
+        }
         qDebug() << "Updating commands";
         QComboBox* app_list = ui->appList;
         app_list->clear();

+ 108 - 38
mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>640</width>
-    <height>837</height>
+    <width>742</width>
+    <height>887</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -30,7 +30,7 @@ background-color: rgb(0, 43, 54);</string>
    <widget class="QLabel" name="label">
     <property name="geometry">
      <rect>
-      <x>230</x>
+      <x>290</x>
       <y>10</y>
       <width>161</width>
       <height>31</height>
@@ -49,13 +49,16 @@ background-color: rgb(0, 43, 54);</string>
    <widget class="QWidget" name="verticalLayoutWidget">
     <property name="geometry">
      <rect>
-      <x>50</x>
+      <x>30</x>
       <y>60</y>
-      <width>541</width>
-      <height>702</height>
+      <width>681</width>
+      <height>750</height>
      </rect>
     </property>
-    <layout class="QVBoxLayout" name="verticalLayout" stretch="6,0,0,3,0">
+    <layout class="QVBoxLayout" name="verticalLayout" stretch="6,0,0,3,0,0">
+     <property name="spacing">
+      <number>12</number>
+     </property>
      <item>
       <layout class="QGridLayout" name="gridLayout_2" rowstretch="5" columnstretch="0,0">
        <property name="sizeConstraint">
@@ -66,13 +69,17 @@ background-color: rgb(0, 43, 54);</string>
        </property>
        <item row="0" column="0">
         <layout class="QVBoxLayout" name="verticalLayout_2">
+         <property name="spacing">
+          <number>12</number>
+         </property>
          <item>
           <widget class="QPushButton" name="connect">
            <property name="styleSheet">
             <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
 color: rgb(0, 0, 0);
-background-color: rgb(94, 79, 255);
-font-weight: 700;</string>
+background-color: rgb(2, 180, 43);
+font-weight: 700;
+padding: 4px;</string>
            </property>
            <property name="text">
             <string>Connect</string>
@@ -132,10 +139,11 @@ font-weight: 700;
               </sizepolicy>
              </property>
              <property name="styleSheet">
-              <string notr="true">background-color: rgb(157, 157, 157);
+              <string notr="true">background-color: rgb(255, 85, 0);
 font: 87 11pt &quot;Noto Sans&quot;;
-color: rgb(255, 85, 0);
-font-weight: 700;</string>
+color: rgb(0, 43, 54);
+font-weight: 700;
+padding: 4px;</string>
              </property>
              <property name="text">
               <string>Args</string>
@@ -151,10 +159,11 @@ font-weight: 700;</string>
               </sizepolicy>
              </property>
              <property name="styleSheet">
-              <string notr="true">background-color: rgb(157, 157, 157);
+              <string notr="true">background-color: rgb(255, 85, 0);
 font: 87 11pt &quot;Noto Sans&quot;;
-color: rgb(255, 85, 0);
-font-weight: 700;</string>
+color: rgb(0, 43, 54);
+font-weight: 700;
+padding: 4px;</string>
              </property>
              <property name="text">
               <string>Execute</string>
@@ -267,36 +276,19 @@ font-weight: 700;
       </widget>
      </item>
      <item>
-      <layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0" columnstretch="0">
+      <layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0" columnstretch="0">
        <property name="sizeConstraint">
         <enum>QLayout::SetMinimumSize</enum>
        </property>
        <property name="spacing">
         <number>6</number>
        </property>
-       <item row="3" column="0">
-        <widget class="QPushButton" name="viewConsole">
-         <property name="styleSheet">
-          <string notr="true">background-color: rgb(157, 157, 157);
-font: 87 11pt &quot;Noto Sans&quot;;
-color: rgb(0, 0, 0);
-font-weight: 700;</string>
-         </property>
-         <property name="text">
-          <string>View Console</string>
-         </property>
-         <property name="icon">
-          <iconset resource="kres.qrc">
-           <normaloff>:/icons/log.png</normaloff>:/icons/log.png</iconset>
-         </property>
-        </widget>
-       </item>
        <item row="2" column="0">
-        <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
+        <layout class="QHBoxLayout" name="horizontalLayout" stretch="2,1">
          <item>
           <widget class="QProgressBar" name="progressBar">
            <property name="sizePolicy">
-            <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
+            <sizepolicy hsizetype="Minimum" vsizetype="Maximum">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
@@ -313,11 +305,19 @@ color: rgb(0, 0, 0);</string>
          </item>
          <item>
           <widget class="QPushButton" name="sendMessage">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
            <property name="styleSheet">
             <string notr="true">background-color: rgb(130, 255, 121);
+background-color: rgb(2, 180, 43);
 font: 87 11pt &quot;Noto Sans&quot;;
 color: rgb(0, 0, 0);
-font-weight: 700;</string>
+font-weight: 700;
+padding: 4px;</string>
            </property>
            <property name="text">
             <string>Send</string>
@@ -373,6 +373,54 @@ font-weight: 700;</string>
        </item>
       </layout>
      </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_3">
+       <item>
+        <widget class="QPushButton" name="viewConsole">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(157, 157, 157);
+font: 87 11pt &quot;Noto Sans&quot;;
+color: rgb(0, 0, 0);
+font-weight: 700;
+padding: 4px;</string>
+         </property>
+         <property name="text">
+          <string>View Console</string>
+         </property>
+         <property name="icon">
+          <iconset resource="kres.qrc">
+           <normaloff>:/icons/log.png</normaloff>:/icons/log.png</iconset>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="tasks">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="styleSheet">
+          <string notr="true">background-color: rgb(255, 85, 0);
+font: 87 11pt &quot;Noto Sans&quot;;
+color: rgb(0, 43, 54);
+font-weight: 700;
+padding: 4px;</string>
+         </property>
+         <property name="text">
+          <string>Tasks</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
      <item>
       <widget class="QPushButton" name="disconnect">
        <property name="sizePolicy">
@@ -385,7 +433,9 @@ font-weight: 700;</string>
         <string notr="true">font: 87 11pt &quot;Noto Sans&quot;;
 color: rgb(0, 0, 0);
 background-color: rgb(255, 65, 68);
-font-weight: 700;</string>
+background-color: rgb(255, 0, 4);
+font-weight: 700;
+padding: 4px;</string>
        </property>
        <property name="text">
         <string>Disconnect</string>
@@ -398,13 +448,26 @@ font-weight: 700;</string>
      </item>
     </layout>
    </widget>
+   <widget class="ConnectionIndicator" name="led">
+    <property name="geometry">
+     <rect>
+      <x>30</x>
+      <y>20</y>
+      <width>41</width>
+      <height>20</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>640</width>
+     <width>742</width>
      <height>23</height>
     </rect>
    </property>
@@ -426,6 +489,13 @@ font-weight: 700;</string>
   <widget class="QStatusBar" name="statusBar"/>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+  <customwidget>
+   <class>ConnectionIndicator</class>
+   <extends>QLabel</extends>
+   <header>connection_indicator.h</header>
+  </customwidget>
+ </customwidgets>
  <resources>
   <include location="kres.qrc"/>
  </resources>

+ 64 - 0
ui_consoledialog.h

@@ -0,0 +1,64 @@
+/********************************************************************************
+** Form generated from reading UI file 'consoledialog.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_CONSOLEDIALOG_H
+#define UI_CONSOLEDIALOG_H
+
+#include <QtCore/QVariant>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QDialog>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QTextEdit>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_ConsoleDialog
+{
+public:
+    QTextEdit *consoleText;
+    QLabel *consoleTitle;
+    QPushButton *closeConsole;
+
+    void setupUi(QDialog *ConsoleDialog)
+    {
+        if (ConsoleDialog->objectName().isEmpty())
+            ConsoleDialog->setObjectName(QString::fromUtf8("ConsoleDialog"));
+        ConsoleDialog->resize(721, 836);
+        consoleText = new QTextEdit(ConsoleDialog);
+        consoleText->setObjectName(QString::fromUtf8("consoleText"));
+        consoleText->setGeometry(QRect(30, 60, 661, 721));
+        consoleText->setReadOnly(false);
+        consoleTitle = new QLabel(ConsoleDialog);
+        consoleTitle->setObjectName(QString::fromUtf8("consoleTitle"));
+        consoleTitle->setGeometry(QRect(300, 20, 51, 18));
+        closeConsole = new QPushButton(ConsoleDialog);
+        closeConsole->setObjectName(QString::fromUtf8("closeConsole"));
+        closeConsole->setGeometry(QRect(600, 800, 80, 26));
+
+        retranslateUi(ConsoleDialog);
+
+        QMetaObject::connectSlotsByName(ConsoleDialog);
+    } // setupUi
+
+    void retranslateUi(QDialog *ConsoleDialog)
+    {
+        ConsoleDialog->setWindowTitle(QCoreApplication::translate("ConsoleDialog", "Dialog", nullptr));
+        consoleTitle->setText(QCoreApplication::translate("ConsoleDialog", "Console", nullptr));
+        closeConsole->setText(QCoreApplication::translate("ConsoleDialog", "Close", nullptr));
+    } // retranslateUi
+
+};
+
+namespace Ui {
+    class ConsoleDialog: public Ui_ConsoleDialog {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_CONSOLEDIALOG_H