diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 21661ec..ac5e0c0 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -7,7 +7,7 @@ TEMPLATE = lib DEFINES += LIBSEARCH_LIBRARY CONFIG += create_pc create_prl no_install_prl -PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt poppler-qt5 +PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt poppler-qt5 kysdk-qtwidgets CONFIG += c++11 link_pkgconfig no_keywords lrelease QMAKE_CXXFLAGS += -Werror=return-type -Werror=return-local-addr -Werror=uninitialized diff --git a/libsearch/plugininterface/action-label.cpp b/libsearch/plugininterface/action-label.cpp index 6af869a..90d4ae4 100644 --- a/libsearch/plugininterface/action-label.cpp +++ b/libsearch/plugininterface/action-label.cpp @@ -22,7 +22,7 @@ #define ACTION_HOVER_COLOR QColor(64, 169, 251, 255) #define ACTION_PRESS_COLOR QColor(41, 108, 217, 255) using namespace UkuiSearch; -ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *parent) : QLabel(parent) +ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *parent) : KBorderlessButton(parent) { m_action = action; m_key = key; @@ -33,32 +33,40 @@ ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *par void ActionLabel::initUi() { this->setText(m_action); - QPalette pal = palette(); - pal.setColor(QPalette::WindowText, ACTION_NORMAL_COLOR); - pal.setColor(QPalette::Light, ACTION_HOVER_COLOR); - pal.setColor(QPalette::Dark, ACTION_PRESS_COLOR); - this->setPalette(pal); - this->setForegroundRole(QPalette::WindowText); +// QPalette pal = palette(); +// pal.setColor(QPalette::WindowText, ACTION_NORMAL_COLOR); +// pal.setColor(QPalette::Light, ACTION_HOVER_COLOR); +// pal.setColor(QPalette::Dark, ACTION_PRESS_COLOR); +// this->setPalette(pal); +// this->setForegroundRole(QPalette::WindowText); this->setCursor(QCursor(Qt::PointingHandCursor)); } bool ActionLabel::eventFilter(QObject *watched, QEvent *event) { if (watched == this) { - if(event->type() == QEvent::MouseButtonPress) { - this->setForegroundRole(QPalette::Dark); - return true; - } else if(event->type() == QEvent::MouseButtonRelease) { + if (event->type() == QEvent::MouseButtonRelease) { Q_EMIT this->actionTriggered(m_action); - this->setForegroundRole(QPalette::Light); - return true; - } else if(event->type() == QEvent::Enter) { - this->setForegroundRole(QPalette::Light); - return true; - } else if(event->type() == QEvent::Leave) { - this->setForegroundRole(QPalette::WindowText); - return true; + return false; } } - return false; + + +// if (watched == this) { +// if(event->type() == QEvent::MouseButtonPress) { +// this->setForegroundRole(QPalette::Dark); +// return true; +// } else if(event->type() == QEvent::MouseButtonRelease) { +// Q_EMIT this->actionTriggered(m_action); +// this->setForegroundRole(QPalette::Light); +// return true; +// } else if(event->type() == QEvent::Enter) { +// this->setForegroundRole(QPalette::Light); +// return true; +// } else if(event->type() == QEvent::Leave) { +// this->setForegroundRole(QPalette::WindowText); +// return true; +// } +// } + return KBorderlessButton::eventFilter(watched, event); } diff --git a/libsearch/plugininterface/action-label.h b/libsearch/plugininterface/action-label.h index b1f910e..d32d1f1 100644 --- a/libsearch/plugininterface/action-label.h +++ b/libsearch/plugininterface/action-label.h @@ -23,8 +23,9 @@ #include #include #include +#include namespace UkuiSearch { -class ActionLabel : public QLabel +class ActionLabel : public kdk::KBorderlessButton { Q_OBJECT public: diff --git a/search-ukcc-plugin/search-ukcc-plugin.pro b/search-ukcc-plugin/search-ukcc-plugin.pro index 8065c6f..900c877 100644 --- a/search-ukcc-plugin/search-ukcc-plugin.pro +++ b/search-ukcc-plugin/search-ukcc-plugin.pro @@ -6,7 +6,7 @@ target.path = $$[QT_INSTALL_LIBS]/ukui-control-center/ CONFIG += plugin link_pkgconfig c++11 lrelease -PKGCONFIG += gio-2.0 gio-unix-2.0 gsettings-qt +PKGCONFIG += gio-2.0 gio-unix-2.0 gsettings-qt kysdk-qtwidgets LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt LIBS += -lukcc diff --git a/search-ukcc-plugin/search.cpp b/search-ukcc-plugin/search.cpp index 5e9153f..5b88ddd 100644 --- a/search-ukcc-plugin/search.cpp +++ b/search-ukcc-plugin/search.cpp @@ -65,7 +65,7 @@ QWidget *Search::pluginUi() m_webEngineFrame->mCombox->blockSignals(false); } }); - connect(m_searchMethodBtn, &SwitchButton::checkedChanged, this, [ = ](bool checked) { + connect(m_searchMethodBtn, &kdk::KSwitchButton::stateChanged, this, [ = ](bool checked) { if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) { m_gsettings->set(SEARCH_METHOD_KEY, checked); } @@ -147,7 +147,7 @@ void Search::initUi() m_descLabel2->setEnabled(false); m_descFrameLyt->addWidget(m_descLabel1); m_descFrameLyt->addWidget(m_descLabel2); - m_searchMethodBtn = new SwitchButton(m_searchMethodFrame); + m_searchMethodBtn = new kdk::KSwitchButton(m_searchMethodFrame); m_searchMethodLyt->addWidget(m_descFrame); m_searchMethodLyt->addStretch(); m_searchMethodLyt->addWidget(m_searchMethodBtn); diff --git a/search-ukcc-plugin/search.h b/search-ukcc-plugin/search.h index a78ed71..b86d8a1 100644 --- a/search-ukcc-plugin/search.h +++ b/search-ukcc-plugin/search.h @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -75,7 +77,7 @@ private: QFrame *m_searchMethodFrame = nullptr; QHBoxLayout *m_searchMethodLyt = nullptr; // QLabel *m_searchMethodLabel = nullptr; - SwitchButton * m_searchMethodBtn = nullptr; + kdk::KSwitchButton *m_searchMethodBtn = nullptr; //设置搜索引擎 TitleLabel * m_webEngineLabel = nullptr; ComboxFrame * m_webEngineFrame = nullptr;