summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-11 13:50:56 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-11 13:50:56 +0300
commitaa2f6ce77d924a0dc53325a425215a1b03e72f43 (patch)
treea6d8b8808a0f31c541aa7cb6af0cfd1f6826776f /src/ui
parentAdd solid background in TypingDisplay (diff)
downloadnheko-aa2f6ce77d924a0dc53325a425215a1b03e72f43.tar.xz
Simplify dialog creation
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/LoadingIndicator.cpp9
-rw-r--r--src/ui/LoadingIndicator.h1
-rw-r--r--src/ui/OverlayModal.cpp21
-rw-r--r--src/ui/OverlayModal.h3
4 files changed, 20 insertions, 14 deletions
diff --git a/src/ui/LoadingIndicator.cpp b/src/ui/LoadingIndicator.cpp
index 05b7fff5..c8337089 100644
--- a/src/ui/LoadingIndicator.cpp
+++ b/src/ui/LoadingIndicator.cpp
@@ -12,17 +12,10 @@ LoadingIndicator::LoadingIndicator(QWidget *parent)
         setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
         setFocusPolicy(Qt::NoFocus);
 
-        timer_ = new QTimer();
+        timer_ = new QTimer(this);
         connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout()));
 }
 
-LoadingIndicator::~LoadingIndicator()
-{
-        stop();
-
-        delete timer_;
-}
-
 void
 LoadingIndicator::paintEvent(QPaintEvent *e)
 {
diff --git a/src/ui/LoadingIndicator.h b/src/ui/LoadingIndicator.h
index bb33fe6c..e8de0aec 100644
--- a/src/ui/LoadingIndicator.h
+++ b/src/ui/LoadingIndicator.h
@@ -13,7 +13,6 @@ class LoadingIndicator : public QWidget
 
 public:
         LoadingIndicator(QWidget *parent = 0);
-        virtual ~LoadingIndicator();
 
         void paintEvent(QPaintEvent *e);
 
diff --git a/src/ui/OverlayModal.cpp b/src/ui/OverlayModal.cpp
index 30ebdf5c..abd1827a 100644
--- a/src/ui/OverlayModal.cpp
+++ b/src/ui/OverlayModal.cpp
@@ -20,18 +20,31 @@
 
 #include "OverlayModal.h"
 
-OverlayModal::OverlayModal(QWidget *parent, QWidget *content)
+OverlayModal::OverlayModal(QWidget *parent)
   : OverlayWidget(parent)
-  , content_{content}
   , color_{QColor(30, 30, 30, 170)}
 {
         layout_ = new QVBoxLayout(this);
-        layout_->addWidget(content);
         layout_->setSpacing(0);
         layout_->setContentsMargins(10, 40, 10, 20);
         setContentAlignment(Qt::AlignCenter);
+}
+
+void
+OverlayModal::setWidget(QWidget *widget)
+{
+        // Delete the previous widget
+        if (layout_->count() > 0) {
+                QLayoutItem *item;
+                while ((item = layout_->takeAt(0)) != nullptr) {
+                        delete item->widget();
+                        delete item;
+                }
+        }
 
-        content->setFocus();
+        layout_->addWidget(widget);
+        content_ = widget;
+        content_->setFocus();
 }
 
 void
diff --git a/src/ui/OverlayModal.h b/src/ui/OverlayModal.h
index acba7a7a..e1fe8ec0 100644
--- a/src/ui/OverlayModal.h
+++ b/src/ui/OverlayModal.h
@@ -27,12 +27,13 @@
 class OverlayModal : public OverlayWidget
 {
 public:
-        OverlayModal(QWidget *parent, QWidget *content);
+        OverlayModal(QWidget *parent);
 
         void setColor(QColor color) { color_ = color; }
         void setDismissible(bool state) { isDismissible_ = state; }
 
         void setContentAlignment(QFlags<Qt::AlignmentFlag> flag) { layout_->setAlignment(flag); }
+        void setWidget(QWidget *widget);
 
 protected:
         void paintEvent(QPaintEvent *event) override;