From 53acfee79564616192609c73a07e1d336d66dd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=BE=D0=B2=D0=B0=D1=80=D0=B8=D1=89=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=81=D1=82?= <2962928213@qq.com> Date: Thu, 18 May 2023 00:49:14 +0800 Subject: [PATCH] feat: make buttons blue when clickable and gray when not clickable --- .gitignore | 3 +++ minikube.pro | 2 ++ src/advancedview.cpp | 20 ++++++++++---------- src/advancedview.h | 21 +++++++++++---------- src/basicview.cpp | 35 +++++++++++++++++------------------ src/basicview.h | 33 +++++++++++++++++---------------- src/minikubebutton.cpp | 24 ++++++++++++++++++++++++ src/minikubebutton.h | 20 ++++++++++++++++++++ 8 files changed, 104 insertions(+), 54 deletions(-) create mode 100644 src/minikubebutton.cpp create mode 100644 src/minikubebutton.h diff --git a/.gitignore b/.gitignore index 982efb0..3213d68 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ compile_commands.json *creator.user* .DS_Store + +# Vscode configurations +.vscode \ No newline at end of file diff --git a/minikube.pro b/minikube.pro index 5e437f4..d4e75c6 100644 --- a/minikube.pro +++ b/minikube.pro @@ -10,6 +10,7 @@ HEADERS = src/window.h \ src/fonts.h \ src/hyperkit.h \ src/logger.h \ + src/minikubebutton.h \ src/mount.h \ src/operator.h \ src/paths.h \ @@ -31,6 +32,7 @@ SOURCES = src/main.cpp \ src/fonts.cpp \ src/hyperkit.cpp \ src/logger.cpp \ + src/minikubebutton.cpp \ src/operator.cpp \ src/paths.cpp \ src/progresswindow.cpp \ diff --git a/src/advancedview.cpp b/src/advancedview.cpp index dbbdc71..abaef33 100644 --- a/src/advancedview.cpp +++ b/src/advancedview.cpp @@ -46,16 +46,16 @@ AdvancedView::AdvancedView(QIcon icon) clusterListView->horizontalHeader()->setSectionResizeMode(6, QHeaderView::ResizeToContents); setSelectedClusterName("default"); - startButton = new QPushButton(tr("Start")); - stopButton = new QPushButton(tr("Stop")); - pauseButton = new QPushButton(tr("Pause")); - deleteButton = new QPushButton(tr("Delete")); - refreshButton = new QPushButton(tr("Refresh")); - createButton = new QPushButton(tr("Create")); - dockerEnvButton = new QPushButton("docker-env"); - sshButton = new QPushButton("SSH"); - dashboardButton = new QPushButton(tr("Dashboard")); - basicButton = new QPushButton(tr("Basic View")); + startButton = new MinikubeButton(tr("Start")); + stopButton = new MinikubeButton(tr("Stop")); + pauseButton = new MinikubeButton(tr("Pause")); + deleteButton = new MinikubeButton(tr("Delete")); + refreshButton = new MinikubeButton(tr("Refresh")); + createButton = new MinikubeButton(tr("Create")); + dockerEnvButton = new MinikubeButton("docker-env"); + sshButton = new MinikubeButton("SSH"); + dashboardButton = new MinikubeButton(tr("Dashboard")); + basicButton = new MinikubeButton(tr("Basic View")); disableButtons(); diff --git a/src/advancedview.h b/src/advancedview.h index ee5e2e8..cdcec65 100644 --- a/src/advancedview.h +++ b/src/advancedview.h @@ -18,6 +18,7 @@ limitations under the License. #define ADVANCEDVIEW_H #include "cluster.h" +#include "minikubebutton.h" #include #include @@ -58,16 +59,16 @@ public slots: void askName(); void askCustom(); - QPushButton *startButton; - QPushButton *stopButton; - QPushButton *pauseButton; - QPushButton *deleteButton; - QPushButton *refreshButton; - QPushButton *dockerEnvButton; - QPushButton *sshButton; - QPushButton *dashboardButton; - QPushButton *basicButton; - QPushButton *createButton; + MinikubeButton *startButton; + MinikubeButton *stopButton; + MinikubeButton *pauseButton; + MinikubeButton *deleteButton; + MinikubeButton *refreshButton; + MinikubeButton *dockerEnvButton; + MinikubeButton *sshButton; + MinikubeButton *dashboardButton; + MinikubeButton *basicButton; + MinikubeButton *createButton; QLabel *loading; ClusterModel *m_clusterModel; diff --git a/src/basicview.cpp b/src/basicview.cpp index 88cf76c..deeecc8 100644 --- a/src/basicview.cpp +++ b/src/basicview.cpp @@ -38,24 +38,23 @@ BasicView::BasicView(QIcon icon) QVBoxLayout *topBar = new QVBoxLayout; topBar->addWidget(topStatusButton); - startButton = new QPushButton(Constants::startIcon); - stopButton = new QPushButton(Constants::stopIcon); - pauseButton = new QPushButton(Constants::pauseIcon); - deleteButton = new QPushButton(Constants::deleteIcon); - - dockerEnvButton = new QPushButton("docker-env"); - serviceButton = new QPushButton("service"); - mountButton = new QPushButton(tr("mount")); - tunnelButton = new QPushButton(tr("tunnel")); - sshButton = new QPushButton("SSH"); - dashboardButton = new QPushButton(tr("dashboard")); - addonsButton = new QPushButton(tr("addons")); - advancedButton = new QPushButton(tr("cluster list")); - - refreshButton = new QPushButton(Constants::refreshIcon); - settingsButton = new QPushButton(Constants::settingsIcon); - aboutButton = new QPushButton(Constants::aboutIcon); - exitButton = new QPushButton(Constants::exitIcon); + startButton = new MinikubeButton(Constants::startIcon); + stopButton = new MinikubeButton(Constants::stopIcon); + pauseButton = new MinikubeButton(Constants::pauseIcon); + deleteButton = new MinikubeButton(Constants::deleteIcon); + + dockerEnvButton = new MinikubeButton("docker-env"); + serviceButton = new MinikubeButton("service"); + mountButton = new MinikubeButton(tr("mount")); + tunnelButton = new MinikubeButton(tr("tunnel")); + sshButton = new MinikubeButton("SSH"); + dashboardButton = new MinikubeButton(tr("dashboard")); + addonsButton = new MinikubeButton(tr("addons")); + advancedButton = new MinikubeButton(tr("cluster list")); + refreshButton = new MinikubeButton(Constants::refreshIcon); + settingsButton = new MinikubeButton(Constants::settingsIcon); + aboutButton = new MinikubeButton(Constants::aboutIcon); + exitButton = new MinikubeButton(Constants::exitIcon); // all the buttons that have icon needs to be set here Fonts::setFontAwesome(startButton); diff --git a/src/basicview.h b/src/basicview.h index 89fad03..53478cc 100644 --- a/src/basicview.h +++ b/src/basicview.h @@ -20,6 +20,7 @@ limitations under the License. #include "cluster.h" #include "mount.h" #include "setting.h" +#include "minikubebutton.h" #include #include @@ -57,22 +58,22 @@ class BasicView : public QObject private: QPushButton *topStatusButton; - QPushButton *startButton; - QPushButton *stopButton; - QPushButton *pauseButton; - QPushButton *deleteButton; - QPushButton *refreshButton; - QPushButton *dockerEnvButton; - QPushButton *serviceButton; - QPushButton *mountButton; - QPushButton *tunnelButton; - QPushButton *sshButton; - QPushButton *dashboardButton; - QPushButton *addonsButton; - QPushButton *advancedButton; - QPushButton *settingsButton; - QPushButton *aboutButton; - QPushButton *exitButton; + MinikubeButton *startButton; + MinikubeButton *stopButton; + MinikubeButton *pauseButton; + MinikubeButton *deleteButton; + MinikubeButton *refreshButton; + MinikubeButton *dockerEnvButton; + MinikubeButton *serviceButton; + MinikubeButton *mountButton; + MinikubeButton *tunnelButton; + MinikubeButton *sshButton; + MinikubeButton *dashboardButton; + MinikubeButton *addonsButton; + MinikubeButton *advancedButton; + MinikubeButton *settingsButton; + MinikubeButton *aboutButton; + MinikubeButton *exitButton; QIcon m_icon; MountList m_mountList; Setting m_setting; diff --git a/src/minikubebutton.cpp b/src/minikubebutton.cpp new file mode 100644 index 0000000..9d71790 --- /dev/null +++ b/src/minikubebutton.cpp @@ -0,0 +1,24 @@ +#include "minikubebutton.h" + +MinikubeButton::MinikubeButton(QWidget *parent) : QPushButton(parent) +{ + // By default a button is enabled when instantiated + setStyleSheet(enabledStyleSheet); +} + +MinikubeButton::MinikubeButton(const QString &text, QWidget *parent) : QPushButton(text, parent) +{ + setStyleSheet(enabledStyleSheet); +} + +MinikubeButton::MinikubeButton(const QIcon &icon, const QString &text, QWidget *parent) + : QPushButton(icon, text, parent) +{ + setStyleSheet(enabledStyleSheet); +} + +void MinikubeButton::setEnabled(bool enabled) +{ + QPushButton::setEnabled(enabled); + setStyleSheet(enabled ? enabledStyleSheet : diabledStyleSheet); +} \ No newline at end of file diff --git a/src/minikubebutton.h b/src/minikubebutton.h new file mode 100644 index 0000000..c516b7e --- /dev/null +++ b/src/minikubebutton.h @@ -0,0 +1,20 @@ +#ifndef MINIKUBEBUTTON_H +#define MINIKUBEBUTTON_H +#include + +class MinikubeButton : public QPushButton +{ +public: + explicit MinikubeButton(QWidget *parent = nullptr); + explicit MinikubeButton(const QString &text, QWidget *parent = nullptr); + MinikubeButton(const QIcon &icon, const QString &text, QWidget *parent = nullptr); + + void setEnabled(bool enabled); + +private: + const QString enabledStyleSheet = "QPushButton:hover{background-color:rgb(105,192,255,50);}"; + const QString diabledStyleSheet = + "QPushButton{background-color:rgb(191,191,191,50);color:rgb(140,140,140);}"; +}; + +#endif // MINIKUBEBUTTON_H