From fc05b2c7a20bdcd12fd64e84dbbc8911045e531e Mon Sep 17 00:00:00 2001
From: pei-jiankang <peijiankang@kylinos.cn>
Date: Mon, 28 Mar 2022 15:31:38 +0800
Subject: [PATCH] modify close ShowTaskview no replay

---
 plugin-startbar/startbar.cpp | 40 +++++++++++++++++++++++++++++++-----
 plugin-startbar/startbar.h   |  1 +
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/plugin-startbar/startbar.cpp b/plugin-startbar/startbar.cpp
index 47e1ac8..62078d7 100644
--- a/plugin-startbar/startbar.cpp
+++ b/plugin-startbar/startbar.cpp
@@ -27,13 +27,16 @@
 #include "../panel/customstyle.h"
 #define THEME_QT_SCHEMA                     "org.ukui.style"
 #define THEME_Style_Name                    "styleName"
+#define UKUI_PANEL_SETTINGS                 "org.ukui.panel.settings"
+#define SHOW_TASKVIEW                       "showtaskview"
 
 UKUIStartbarPlugin::UKUIStartbarPlugin(const IUKUIPanelPluginStartupInfo &startupInfo):
     QObject(),
     IUKUIPanelPlugin(startupInfo),
     mWidget(new UKUIStartBarWidget(this))
 {
-
+   
+    mWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
 }
 
@@ -57,11 +60,18 @@ UKUIStartBarWidget::UKUIStartBarWidget( IUKUIPanelPlugin *plugin, QWidget* paren
 {
     translator();
     mStartMenuButton=new StartMenuButton(plugin,this);
-    mTaskViewButton=new TaskViewButton(plugin,this);
     mLayout=new UKUi::GridLayout(this);
     mLayout->addWidget(mStartMenuButton);
-    mLayout->addWidget(mTaskViewButton);
+    const QByteArray id(UKUI_PANEL_SETTINGS);
+    if(QGSettings::isSchemaInstalled(id)) {
+        m_gsettings = new QGSettings(id);
+    }
+    connect(m_gsettings, &QGSettings::changed, this, [=] (const QString &key){
+        if(key==SHOW_TASKVIEW)
+            realign();
+        });
 
+    realign();
 }
 
 void UKUIStartBarWidget::translator(){
@@ -77,19 +87,39 @@ void UKUIStartBarWidget::translator(){
 
 UKUIStartBarWidget::~UKUIStartBarWidget()
 {
+    mStartMenuButton->deleteLater();
+    mTaskViewButton->deleteLater();
 }
 
 /*plugin-startmenu refresh function*/
 void UKUIStartBarWidget::realign()
 {
+    if(m_gsettings->get(SHOW_TASKVIEW).toBool()){
+        if (!this->findChild<TaskViewButton *>("TaskViewButton")) {
+	    mTaskViewButton=new TaskViewButton(mPlugin,this);
+	    mTaskViewButton->setObjectName("TaskViewButton");
+	    mLayout->addWidget(mTaskViewButton);
+	}
+    } else {
+	if (this->findChild<TaskViewButton *>("TaskViewButton")) {
+	    if (mTaskViewButton != nullptr) {
+		mLayout->removeWidget(mTaskViewButton);
+		mTaskViewButton->deleteLater();
+	    }
+	} else {
+	    mStartMenuButton->realign();
+	    return;
+	}
+    }
+
     if (mPlugin->panel()->isHorizontal()){
         mLayout->setColumnCount(mLayout->count());
         mLayout->setRowCount(0);
-        this->setFixedSize(mPlugin->panel()->panelSize()*2.3,mPlugin->panel()->panelSize());
+    //    this->setFixedSize(mPlugin->panel()->panelSize()*2.3,mPlugin->panel()->panelSize());
     }else{
         mLayout->setRowCount(mLayout->count());
         mLayout->setColumnCount(0);
-        this->setFixedSize(mPlugin->panel()->panelSize(),mPlugin->panel()->panelSize()*2.3);
+    //    this->setFixedSize(mPlugin->panel()->panelSize(),mPlugin->panel()->panelSize()*2.3);
     }
     mStartMenuButton->realign();
     mTaskViewButton->realign();
diff --git a/plugin-startbar/startbar.h b/plugin-startbar/startbar.h
index e4c4292..368ff9a 100644
--- a/plugin-startbar/startbar.h
+++ b/plugin-startbar/startbar.h
@@ -92,6 +92,7 @@ private:
     TaskViewButton *mTaskViewButton;
     UKUi::GridLayout *mLayout;
     QTranslator *m_translator;
+    QGSettings *m_gsettings;
 private:
     void translator();
 
-- 
2.33.0

