From 294cd9316f50ec8b0f31ef4bbcac97f7023b6cda Mon Sep 17 00:00:00 2001 From: likehomedream Date: Thu, 21 Dec 2023 15:28:56 +0800 Subject: [PATCH 1/3] fix history button UI --- src/module/historywidget.cpp | 47 ++++++++++++++++++++++++++++-------- src/module/historywidget.h | 6 +++++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/module/historywidget.cpp b/src/module/historywidget.cpp index 9468046..0a174b3 100644 --- a/src/module/historywidget.cpp +++ b/src/module/historywidget.cpp @@ -165,6 +165,7 @@ HistoryButton::HistoryButton(QWidget* parent): QPushButton(parent) // this->setBackgroundRole(QPalette::Base); this->setFixedSize(240, 280); m_menu = new QMenu(this); + this->installEventFilter(this); } void HistoryButton::setHistoryTime(const QString &text) @@ -196,6 +197,7 @@ void HistoryButton::setThemeType(const QString &themeType) */ void HistoryButton::initUI() { + this->setProperty("useButtonPalette", true); QVBoxLayout* layout = new QVBoxLayout(this); QLabel* imageLabel = new QLabel; @@ -231,7 +233,6 @@ void HistoryButton::initUI() QHBoxLayout * btnwidgetlayout = new QHBoxLayout(btnwidget); btnwidgetlayout->setContentsMargins(0,0,0,0); - QPushButton* button; QString buttonText; if (m_themetype == "globalTheme") { buttonText = tr("globalTheme"); @@ -244,13 +245,18 @@ void HistoryButton::initUI() } else { buttonText = tr("grubTheme"); } - button = new QPushButton(buttonText, this); + m_typebutton = new QPushButton(buttonText, this); + m_typebutton->setProperty("useButtonPalette", true); - QPushButton* btn_menu = new QPushButton("···"); - btn_menu->setFixedWidth(50); - btnwidgetlayout->addWidget(button); + m_menubutton = new QToolButton(this); + m_menubutton->setProperty("useButtonPalette", true); + m_menubutton->setFixedWidth(50); + m_menubutton->setText("···"); + m_menubutton->setPopupMode(QToolButton::InstantPopup); + + btnwidgetlayout->addWidget(m_typebutton); btnwidgetlayout->addStretch(1); - btnwidgetlayout->addWidget(btn_menu); + btnwidgetlayout->addWidget(m_menubutton); btnwidget->setLayout(btnwidgetlayout); layout->addWidget(btnwidget); @@ -258,10 +264,10 @@ void HistoryButton::initUI() // 创建并添加菜单选项 QAction* action1 = m_menu->addAction("删除"); QAction* action2 = m_menu->addAction("导出"); - - connect(btn_menu, &QPushButton::clicked, this, [=]() { - m_menu->exec(btn_menu->mapToGlobal(btn_menu->rect().bottomLeft())); - }); + m_menubutton->setMenu(m_menu); +// connect(btn_menu, &QPushButton::clicked, this, [=]() { +// m_menu->exec(btn_menu->mapToGlobal(btn_menu->rect().bottomLeft())); +// }); // connect(action2,&QAction::triggered,this,[=](){ // emit startBuild(m_historytime); // }); @@ -297,7 +303,28 @@ void HistoryButton::initUI() FileProcess::g_createThemeType = nullptr; }); }); + //FIX ME:现在是三个button,当historybutton hover的时候,button和btn_menu没有悬浮,导致有色差,用qss的话一样会出现这个问题。暂时没有好的解决方式 +// connect(this, &HistoryButton::hoverStateChanged, this, [&](bool ishover) { +// if(ishover){ +// button->setStyleSheet("background-color: #DADADA;"); +// btn_menu->setStyleSheet("background-color: #DADADA;"); +// }else{ +// button->setStyleSheet(""); +// btn_menu->setStyleSheet(""); +// } +// }); +} +bool HistoryButton::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == this) { + if (event->type() == QEvent::Enter) { + emit hoverStateChanged(true); + } else if (event->type() == QEvent::Leave) { + emit hoverStateChanged(false); + } + } + return QPushButton::eventFilter(obj, event); } diff --git a/src/module/historywidget.h b/src/module/historywidget.h index 55c55e3..57130f4 100644 --- a/src/module/historywidget.h +++ b/src/module/historywidget.h @@ -17,6 +17,7 @@ #include #include #include +#include class HistoryButton : public QPushButton { @@ -28,16 +29,21 @@ public: void setThemeName(const QString &themeName); void setThemeType(const QString &themeType); void initUI(); +protected: + bool eventFilter(QObject* obj, QEvent* event); signals: void updateHistoryRequested(); void startBuild(QString &historytime); + void hoverStateChanged(bool isHovered); private: QString m_historytime = nullptr; QString m_showhistorytime = nullptr; QString m_coverpath = nullptr; QString m_themename = nullptr; QString m_themetype = nullptr; + QPushButton* m_typebutton; + QToolButton* m_menubutton; QMenu *m_menu; }; From 3d8797bff57d8c400b78920f86663ce1437e5f55 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Thu, 21 Dec 2023 16:52:21 +0800 Subject: [PATCH 2/3] fix some error and add shortcut --- src/build/buildresultwidget.cpp | 3 +++ src/mainwindow.cpp | 6 ++++++ src/module/globalthemewidget.cpp | 4 ++-- src/module/infocreatewidget.cpp | 3 ++- src/module/infocreatewidget.h | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/build/buildresultwidget.cpp b/src/build/buildresultwidget.cpp index c8c83e6..b71abaa 100644 --- a/src/build/buildresultwidget.cpp +++ b/src/build/buildresultwidget.cpp @@ -7,6 +7,9 @@ buildResultWidget::buildResultWidget(QWidget *parent) this->setWindowModality(Qt::ApplicationModal); this->setWindowFlags(Qt::FramelessWindowHint); + this->setBackgroundRole(QPalette::Base); + this->setAutoFillBackground(true); + m_buildResultLayout = new QVBoxLayout; m_buildResult = new QLabel; m_buildResult->setText("主题制作完成!"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b747d1e..959dda4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -201,6 +201,12 @@ void MainWindow::initUI() buttonGroup->addButton(m_plymouthbtn); buttonGroup->addButton(m_grubbtn); + m_globalbtn->setProperty("useButtonPalette", true); + m_iconbtn->setProperty("useButtonPalette", true); + m_cursorbtn->setProperty("useButtonPalette", true); + m_plymouthbtn->setProperty("useButtonPalette", true); + m_grubbtn->setProperty("useButtonPalette", true); + connect(m_historywidget,&HistoryWidget::startSecondEdit,[=](HistoryInfo InfoData){ m_titlebar->setGoHomeBtn(true); m_maininterface->isHistory(true); diff --git a/src/module/globalthemewidget.cpp b/src/module/globalthemewidget.cpp index 1510ddf..fce1509 100644 --- a/src/module/globalthemewidget.cpp +++ b/src/module/globalthemewidget.cpp @@ -151,8 +151,8 @@ void GlobalThemeWidget::initPreviewWidget() void GlobalThemeWidget::initRightWidget() { m_rightwidget = new QWidget(this); - m_rightwidget->setMinimumSize(400,620); - m_rightwidget->setMaximumWidth(400); + m_rightwidget->setMinimumSize(410,620); + m_rightwidget->setMaximumWidth(410); m_rightwidget->setBackgroundRole(QPalette::Base); m_rightwidget->setContentsMargins(0,0,0,0); diff --git a/src/module/infocreatewidget.cpp b/src/module/infocreatewidget.cpp index d76e23c..c4e8cab 100644 --- a/src/module/infocreatewidget.cpp +++ b/src/module/infocreatewidget.cpp @@ -87,7 +87,8 @@ void InfoCreateWidget::InitInfoBtn(const QString &m_state){ m_exitBtn->setText(tr("Back")); m_recogniseBtn->setText(tr("OK")); m_createDebBtn->setText(tr("Create")); - + QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Return), m_recogniseBtn); + QObject::connect(shortcut, &QShortcut::activated, m_recogniseBtn, &QPushButton::click); m_infoBtnLayout->addWidget(m_exitBtn); m_infoBtnLayout->addWidget(m_recogniseBtn); m_infoBtnLayout->addWidget(m_createDebBtn); diff --git a/src/module/infocreatewidget.h b/src/module/infocreatewidget.h index a372bf8..676a14f 100644 --- a/src/module/infocreatewidget.h +++ b/src/module/infocreatewidget.h @@ -21,6 +21,7 @@ #include #include #include +#include class InfoCreateWidget : public QWidget { From 86a8cf53010f15f698584d5b29a18b400d8d74c7 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Fri, 22 Dec 2023 17:46:34 +0800 Subject: [PATCH 3/3] fix some error --- src/mainwindow.cpp | 2 +- src/module/cursorthemewidget.cpp | 10 ++++++++-- src/module/historywidget.cpp | 24 +++++++++++++++--------- src/module/iconthemewidget.cpp | 7 ++++++- src/module/infocreatewidget.cpp | 2 ++ src/titlebar.cpp | 6 ++++++ 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 959dda4..9e9f15f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -99,7 +99,7 @@ MainWindow::MainWindow(QWidget *parent) FileProcess::g_debPath = path; m_bridge->savePathConfigChanged(path); }); - this->setContentsMargins(0,2,0,0); + this->setContentsMargins(5,5,5,0); } MainWindow::~MainWindow() diff --git a/src/module/cursorthemewidget.cpp b/src/module/cursorthemewidget.cpp index ba519bc..aac3c46 100644 --- a/src/module/cursorthemewidget.cpp +++ b/src/module/cursorthemewidget.cpp @@ -40,8 +40,14 @@ void CursorThemeWidget::eidtInitWidget(const HistoryInfo &InfoData) m_preview2->updateIconMap(m_historytimeiconpathmap); updateCustomPathMap(m_historyiconpathmap,"cursor"); updateCustomPathMap(m_historytimeiconpathmap,"timecursor"); - m_preview->updateImage(m_info.wallpaperpath); - m_preview2->updateImage(m_info.wallpaperpath); + if(m_info.wallpaperpath != nullptr){ + m_preview->updateImage(m_info.wallpaperpath); + m_preview2->updateImage(m_info.wallpaperpath); + }else{ + m_preview->updateImage(":/resource/background/1-openkylin.jpg"); + m_preview2->updateImage(":/resource/background/1-openkylin.jpg"); + } + } /** diff --git a/src/module/historywidget.cpp b/src/module/historywidget.cpp index 0a174b3..d4f5cde 100644 --- a/src/module/historywidget.cpp +++ b/src/module/historywidget.cpp @@ -247,6 +247,7 @@ void HistoryButton::initUI() } m_typebutton = new QPushButton(buttonText, this); m_typebutton->setProperty("useButtonPalette", true); + m_typebutton->setProperty("setRadius", 18); m_menubutton = new QToolButton(this); m_menubutton->setProperty("useButtonPalette", true); @@ -265,6 +266,11 @@ void HistoryButton::initUI() QAction* action1 = m_menu->addAction("删除"); QAction* action2 = m_menu->addAction("导出"); m_menubutton->setMenu(m_menu); + if(m_themename != nullptr){ + action2->setDisabled(false); + }else{ + action2->setDisabled(true); + } // connect(btn_menu, &QPushButton::clicked, this, [=]() { // m_menu->exec(btn_menu->mapToGlobal(btn_menu->rect().bottomLeft())); // }); @@ -304,15 +310,15 @@ void HistoryButton::initUI() }); }); //FIX ME:现在是三个button,当historybutton hover的时候,button和btn_menu没有悬浮,导致有色差,用qss的话一样会出现这个问题。暂时没有好的解决方式 -// connect(this, &HistoryButton::hoverStateChanged, this, [&](bool ishover) { -// if(ishover){ -// button->setStyleSheet("background-color: #DADADA;"); -// btn_menu->setStyleSheet("background-color: #DADADA;"); -// }else{ -// button->setStyleSheet(""); -// btn_menu->setStyleSheet(""); -// } -// }); + connect(this, &HistoryButton::hoverStateChanged, this, [&](bool ishover) { + if(ishover){ + m_typebutton->setAttribute(Qt::WA_UnderMouse, true); + m_menubutton->setAttribute(Qt::WA_UnderMouse, true); + }else{ + m_typebutton->setAttribute(Qt::WA_UnderMouse, false); + m_menubutton->setAttribute(Qt::WA_UnderMouse, false); + } + }); } bool HistoryButton::eventFilter(QObject *obj, QEvent *event) diff --git a/src/module/iconthemewidget.cpp b/src/module/iconthemewidget.cpp index e0c656a..d0ec37e 100644 --- a/src/module/iconthemewidget.cpp +++ b/src/module/iconthemewidget.cpp @@ -547,7 +547,12 @@ void IconThemeWidget::eidtInitWidget(const HistoryInfo &InfoData) m_systempreview->updateIconMap(m_historysystemiconmap); updateCustomIconPathMap(m_historyiconmap); updateCustomSyetemIconPathMap(m_historysystemiconmap); - m_preview->updateImage(m_info.wallpaperpath); + if(m_info.wallpaperpath != nullptr){ + m_preview->updateImage(m_info.wallpaperpath); + }else{ + m_preview->updateImage(":/resource/background/1-openkylin.jpg"); + } + } /** diff --git a/src/module/infocreatewidget.cpp b/src/module/infocreatewidget.cpp index c4e8cab..2f7a371 100644 --- a/src/module/infocreatewidget.cpp +++ b/src/module/infocreatewidget.cpp @@ -89,6 +89,8 @@ void InfoCreateWidget::InitInfoBtn(const QString &m_state){ m_createDebBtn->setText(tr("Create")); QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Return), m_recogniseBtn); QObject::connect(shortcut, &QShortcut::activated, m_recogniseBtn, &QPushButton::click); + QShortcut *shortcut1 = new QShortcut(QKeySequence(Qt::Key_Return), m_createDebBtn); + QObject::connect(shortcut1, &QShortcut::activated, m_createDebBtn, &QPushButton::click); m_infoBtnLayout->addWidget(m_exitBtn); m_infoBtnLayout->addWidget(m_recogniseBtn); m_infoBtnLayout->addWidget(m_createDebBtn); diff --git a/src/titlebar.cpp b/src/titlebar.cpp index fb0f858..f48405f 100644 --- a/src/titlebar.cpp +++ b/src/titlebar.cpp @@ -31,24 +31,29 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent) m_gohomebtn->setIcon(QIcon::fromTheme("go-home-symbolic")); m_gohomebtn->setToolTip(tr("Return")); m_gohomebtn->setFlat(true); + m_gohomebtn->setProperty("isWindowButton", 0x01); m_minimumbtn = new QPushButton(); m_minimumbtn->setFixedSize(30,30); m_minimumbtn->setIcon(QIcon::fromTheme("window-minimize-symbolic")); m_minimumbtn->setToolTip(tr("Minimize")); m_minimumbtn->setFlat(true); + m_minimumbtn->setProperty("isWindowButton", 0x01); m_maximumbtn = new QPushButton(); m_maximumbtn->setFixedSize(30,30); m_maximumbtn->setIcon(QIcon::fromTheme("window-maximize-symbolic")); m_maximumbtn->setToolTip(tr("Maximize")); m_maximumbtn->setFlat(true); + m_maximumbtn->setProperty("isWindowButton", 0x01); + m_closebtn = new QPushButton(); m_closebtn->setFixedSize(30, 30); m_closebtn->setIcon(QIcon::fromTheme("window-close-symbolic")); m_closebtn->setToolTip(tr("Close")); m_closebtn->setFlat(true); + m_closebtn->setProperty("isWindowButton", 0x02); connect(m_gohomebtn, &QPushButton::clicked, this,[=](){ emit gohomesignal(); @@ -63,6 +68,7 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent) m_optionbtn->setFixedSize(30,30); m_optionbtn->setIcon(QIcon::fromTheme("application-menu")); m_optionbtn->setAutoRaise(true); + m_optionbtn->setProperty("isWindowButton", 0x01); QMenu* menu = new QMenu(m_optionbtn);