From f65c7dde444f8a8523dc69cb6502124bc9df2b35 Mon Sep 17 00:00:00 2001
From: "alexandr.mruchok" <alexandrmruchok@demlabs.net>
Date: Mon, 2 Mar 2020 17:11:07 +0200
Subject: [PATCH] [*] Disable shadow changing in disabled ComboBox [+]
 CustomComboBoxPopup::setModel(QAbstractItemModel*)
 CustomComboBoxPopup::itemSelected(int) signal [+] Properties::VISIBLE, VALID;

---
 auxiliary/defines.h              |  2 ++
 controls/CustomComboBox.cpp      |  4 +++
 controls/CustomComboBoxPopup.cpp | 53 ++++++++++++++++++++++++--------
 controls/CustomComboBoxPopup.h   | 14 ++++++---
 4 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/auxiliary/defines.h b/auxiliary/defines.h
index f97d405..fd2ffea 100644
--- a/auxiliary/defines.h
+++ b/auxiliary/defines.h
@@ -10,6 +10,8 @@ namespace Properties
     static const QString ENABLED = "enabled";
     static const QString HOVER   = "hover"  ;
     static const QString CHECKED = "checked";
+    static const QString VISIBLE = "visible";
+    static const QString VALID = "valid";
 }
 
 
diff --git a/controls/CustomComboBox.cpp b/controls/CustomComboBox.cpp
index e2d2747..7914360 100644
--- a/controls/CustomComboBox.cpp
+++ b/controls/CustomComboBox.cpp
@@ -30,6 +30,10 @@ void CustomComboBox::showPopup()
 void CustomComboBox:: enterEvent(QEvent *event)
 {
     Q_UNUSED(event);
+
+    if (!this->isEnabled())
+        return;
+
     m_styledshadow->updateStyle(HOVER_SHADOW);
     setGraphicsEffect(m_styledshadow);
 
diff --git a/controls/CustomComboBoxPopup.cpp b/controls/CustomComboBoxPopup.cpp
index 2387dfe..00bd5f8 100644
--- a/controls/CustomComboBoxPopup.cpp
+++ b/controls/CustomComboBoxPopup.cpp
@@ -6,11 +6,10 @@ CustomComboBoxPopup::CustomComboBoxPopup(QWidget *parent)
       m_layout(new QVBoxLayout(this)),
       m_layoutScroll(new QVBoxLayout(this)),
       m_lblCaption(new QLabel(this)),
-      m_scaList(new QScrollArea(this)),
-      m_listButton(new QList<CustomPlacementButton_New*>())
+      m_scaList(new QScrollArea(this))
 {
     setFixedSize(parent->width(),parent->height());
-    setObjectName("wgtComboBoxPopup");
+    this->setObjectName("wgtComboBoxPopup");
     m_scaList->setObjectName("scaList");
 
     m_scaList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -41,14 +40,14 @@ void CustomComboBoxPopup::setModel(QList<DataModel> *model)
     for(int i=0; i<model->size();i++)
     {
        // CustomPlacementButton_New tmp;
-        m_listButton->append(new CustomPlacementButton_New());
-        m_listButton->last()->setIcon(model->at(i).iconPath);
-        m_listButton->last()->setText(model->at(i).text);
-        m_listButton->last()->setObjectName("btnServer");
-        m_listButton->last()->addSubcontrol("arrow");
-
-        m_layoutScroll->addWidget(m_listButton->last());
-        m_layoutScroll->setAlignment(m_listButton->last(),Qt::AlignHCenter);
+        m_listButton.append(new CustomPlacementButton_New());
+        m_listButton.last()->setIcon(model->at(i).iconPath);
+        m_listButton.last()->setText(model->at(i).text);
+        m_listButton.last()->setObjectName("btnServer");
+        m_listButton.last()->addSubcontrol("arrow");
+
+        m_layoutScroll->addWidget(m_listButton.last());
+        m_layoutScroll->setAlignment(m_listButton.last(),Qt::AlignHCenter);
         QWidget *tmpWidget = new QWidget();
         if(i<model->size()-1)
         {
@@ -60,8 +59,38 @@ void CustomComboBoxPopup::setModel(QList<DataModel> *model)
     }
 }
 
+void CustomComboBoxPopup::setModel(QAbstractItemModel *a_model)
+{
+    for(int i=0; i<a_model->rowCount(); i++)
+    {
+       // CustomPlacementButton_New tmp;
+        CustomPlacementButton_New *newButton = new CustomPlacementButton_New;
+        m_listButton.append(newButton);
+//        newButton->setIcon(a_model->at(i).iconPath);
+        newButton->setText(a_model->data(a_model->index(i, 0)).toString());
+        newButton->setObjectName("btnServer");
+        newButton->addSubcontrol("arrow");
+
+        m_layoutScroll->addWidget(newButton);
+        m_layoutScroll->setAlignment(newButton, Qt::AlignHCenter);
+        QWidget *tmpWidget = new QWidget();
+        if(i < a_model->rowCount() - 1)
+        {
+            tmpWidget->setProperty("state", "sizeFixed"); //This setting is for fixing gaps between widgets other than the last.
+        }
+
+        m_layoutScroll->addWidget(tmpWidget);
+
+        connect(newButton, &QPushButton::clicked, [this, i]{
+            emit this->itemSelected(i);
+            this->hide();
+        });
+
+    }
+}
+
 
-void CustomComboBoxPopup::setTextCapture(const QString &text)
+void CustomComboBoxPopup::setCaption(const QString &text)
 {
     m_lblCaption->setText(text);
 }
diff --git a/controls/CustomComboBoxPopup.h b/controls/CustomComboBoxPopup.h
index 68a4fad..f931593 100644
--- a/controls/CustomComboBoxPopup.h
+++ b/controls/CustomComboBoxPopup.h
@@ -18,22 +18,28 @@ struct DataModel
 
 class CustomComboBoxPopup: public QWidget
 {
+    Q_OBJECT
 public:
     CustomComboBoxPopup( QWidget *parent = nullptr);
     /// Set model.
     /// @param model Model date for button.
     void setModel(QList<DataModel> *model);
-    /// Set capture name.
+
+    void setModel(QAbstractItemModel *a_model);
+    /// Set caption.
     /// @param text Name.
-    void setTextCapture(const QString &text);
-private:
+    void setCaption(const QString &text);
 
+signals:
+    void itemSelected(int index);
+
+private:
 
     QVBoxLayout *m_layout;
     QVBoxLayout *m_layoutScroll;
     QLabel *m_lblCaption;
     QScrollArea *m_scaList;
-    QList<CustomPlacementButton_New*> *m_listButton;
+    QList<CustomPlacementButton_New*> m_listButton;
 };
 
 #endif // CUSTOMCOMBOBOXPOPUP_H
-- 
GitLab