Browse Source

adding a loader window which is displayed when uploading/requesting a task

logicp 4 years ago
parent
commit
6dcc5becf5
5 changed files with 92 additions and 0 deletions
  1. 26 0
      argdialog.ui
  2. BIN
      icons/loader.gif
  3. 22 0
      include/ui/argdialog.h
  4. 1 0
      kres.qrc
  5. 43 0
      src/argdialog.cpp

+ 26 - 0
argdialog.ui

@@ -489,6 +489,32 @@ padding: 4px;</string>
     </item>
    </layout>
   </widget>
+  <widget class="QLabel" name="loaderText">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>0</width>
+     <height>0</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Sending request to Server. Please wait ...</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="loaderMovie">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>0</width>
+     <height>0</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string/>
+   </property>
+  </widget>
  </widget>
  <resources>
   <include location="kres.qrc"/>

BIN
icons/loader.gif


+ 22 - 0
include/ui/argdialog.h

@@ -15,10 +15,28 @@
 #include <string_view>
 #include <unordered_map>
 
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QMovie>
+
 using namespace Scheduler;
 
 typedef std::string Str;
 
+class KLoader : public QWidget {
+ public:
+  KLoader() {
+    QWidget* verticalLayoutWidget = new QWidget();
+    verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
+    verticalLayoutWidget->setGeometry(QRect(10, 10, 500, 500));
+    QVBoxLayout* verticalLayout = new QVBoxLayout(verticalLayoutWidget);
+    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+    verticalLayout->setContentsMargins(0, 0, 0, 0);
+    QLabel* loader_title = new QLabel{"Loading...", this};
+    verticalLayout->addWidget(loader_title);
+  }
+};
+
 namespace Ui {
 class ArgDialog;
 }
@@ -47,6 +65,7 @@ class ArgDialog : public QDialog {
   void clearPost();
   void defaultPost();
   void clearTask();
+  void displayLoader(bool visible);
   void addToArgList(QString value, QString type);
   void addOrReplaceInArgList(QString value, QString type);
   void addHashtag(QString tag);
@@ -61,6 +80,9 @@ class ArgDialog : public QDialog {
   QString       m_file_path;
   QJsonObject   m_config;
   QString       m_app_name;
+  QMovie*       m_loader;
+  QWidget      m_loader_widget;
+  QVBoxLayout  m_loader_layout;
 };
 
 #endif  // ARGDIALOG_H

+ 1 - 0
kres.qrc

@@ -19,5 +19,6 @@
         <file>icons/disconnect.png</file>
         <file>style/style.css</file>
         <file>style/messagebox.css</file>
+        <file>icons/loader.gif</file>
     </qresource>
 </RCC>

+ 43 - 0
src/argdialog.cpp

@@ -14,6 +14,13 @@ using namespace Scheduler;
 ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog), m_task(nullptr) {
   ui->setupUi(this);
 
+  m_loader = new QMovie{":/icons/loader.gif"};
+  //    m_loader_widget = new QWidget{};
+  //    m_loader_layout = new QVBoxLayout{};
+  m_loader_layout.addWidget(ui->loaderMovie);
+  m_loader_layout.addWidget(ui->loaderText);
+  m_loader_widget.setLayout(&m_loader_layout);
+
   ui->argCommandButtons->button(QDialogButtonBox::Close)
       ->setStyleSheet(QString("background:%1").arg("#2f535f"));
 
@@ -134,6 +141,7 @@ ArgDialog::ArgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ArgDialog),
                        }
                        if (m_task->isReady()) {
                          emit ArgDialog::taskRequestReady(m_task);
+                         displayLoader(true);
                        } else {
                          UI::infoMessageBox("Task is still missing arguments", "Task Verification Error");
                        }
@@ -388,6 +396,9 @@ void ArgDialog::setConfig(QJsonObject config) {
  */
 ArgDialog::~ArgDialog() {
   delete m_task;
+  delete m_loader;
+//  delete m_loader_layout;
+//  delete m_loader_widget;
   delete ui;
 }
 
@@ -402,4 +413,36 @@ void ArgDialog::setArgTypes() {
 
 void ArgDialog::notifyClientSuccess() {
   clearPost();
+  displayLoader(false);
+}
+
+void ArgDialog::displayLoader(bool visible) {
+  if (visible) {
+    auto height = 400;
+    auto width = 480;
+    this->setWindowOpacity(0.3);
+    m_loader_widget.setMaximumSize(width, height);
+    m_loader_widget.setMinimumSize(width, height);
+    m_loader_widget.show();
+    m_loader_widget.activateWindow();
+    m_loader_widget.raise();
+    ui->loaderMovie->setMovie(m_loader);
+    ui->loaderMovie->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+    ui->loaderMovie->show();
+    ui->loaderMovie->activateWindow();
+    ui->loaderMovie->raise();
+    ui->loaderMovie->setMaximumSize(width, height);
+    ui->loaderMovie->setMinimumSize(width, height / 2);
+    ui->loaderText->setMaximumSize(width, height);
+    ui->loaderText->setMinimumSize(width, height / 2);
+    m_loader->start();
+    m_loader_widget.move(this->rect().topLeft());
+  } else {
+    m_loader_widget.hide();
+    ui->loaderMovie->hide();
+    ui->loaderMovie->setVisible(false);
+    ui->loaderText->hide();
+    ui->loaderText->setVisible(false);
+    this->setWindowOpacity(1);
+  }
 }