diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 388f5027f..aaefd6b48 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -56,15 +56,17 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) , m_wid(wid) , m_title(new TipsWidget) , m_waitLeaveTimer(new QTimer(this)) - , m_closeBtn2D(new DImageButton) + , m_closeBtn2D(new DIconButton(this)) , m_wmHelper(DWindowManagerHelper::instance()) { m_closeBtn2D->setFixedSize(24, 24); + m_closeBtn2D->setIconSize(QSize(24, 24)); m_closeBtn2D->setObjectName("closebutton-2d"); - m_closeBtn2D->setNormalPic(":/icons/resources/close_round_normal.svg"); - m_closeBtn2D->setHoverPic(":/icons/resources/close_round_hover.svg"); - m_closeBtn2D->setPressPic(":/icons/resources/close_round_press.svg"); + m_closeBtn2D->setIcon(QIcon(":/icons/resources/close_round_normal.svg")); m_closeBtn2D->setVisible(false); + m_closeBtn2D->setFlat(true); + m_closeBtn2D->installEventFilter(this); + m_title->setObjectName("AppSnapshotTitle"); QHBoxLayout *centralLayout = new QHBoxLayout; @@ -79,7 +81,7 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) setAcceptDrops(true); resize(SNAP_WIDTH, SNAP_HEIGHT); - connect(m_closeBtn2D, &DImageButton::clicked, this, &AppSnapshot::closeWindow, Qt::QueuedConnection); + connect(m_closeBtn2D, &DIconButton::clicked, this, &AppSnapshot::closeWindow, Qt::QueuedConnection); connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &AppSnapshot::compositeChanged, Qt::QueuedConnection); QTimer::singleShot(1, this, &AppSnapshot::compositeChanged); } @@ -270,6 +272,23 @@ void AppSnapshot::mousePressEvent(QMouseEvent *e) emit clicked(m_wid); } +bool AppSnapshot::eventFilter(QObject *watched, QEvent *e) +{ + if(watched == m_closeBtn2D) { + if(watched == m_closeBtn2D && (e->type() == QEvent::HoverEnter || e->type() == QEvent::HoverMove)) { + m_closeBtn2D->setIcon(QIcon(":/icons/resources/close_round_hover.svg")); + } + else if (watched == m_closeBtn2D && e->type() == QEvent::HoverLeave) { + m_closeBtn2D->setIcon(QIcon(":/icons/resources/close_round_normal.svg")); + } + else if (watched == m_closeBtn2D && e->type() == QEvent::MouseButtonPress) { + m_closeBtn2D->setIcon(QIcon(":/icons/resources/close_round_press.svg")); + } + } + + return false; +} + SHMInfo *AppSnapshot::getImageDSHM() { const auto display = QX11Info::display(); diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 7d2e5fa35..1ea687247 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -27,7 +27,7 @@ #include #include "../widgets/tipswidget.h" -#include +#include #include #include @@ -69,14 +69,15 @@ public slots: void setWindowInfo(const WindowInfo &info); private: - void dragEnterEvent(QDragEnterEvent *e); - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mousePressEvent(QMouseEvent *e); + void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE; + void enterEvent(QEvent *e) Q_DECL_OVERRIDE; + void leaveEvent(QEvent *e) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; + void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; + bool eventFilter(QObject *watched, QEvent *e) Q_DECL_OVERRIDE; SHMInfo *getImageDSHM(); - XImage * getImageXlib(); + XImage *getImageXlib(); QRect rectRemovedShadow(const QImage &qimage, unsigned char *prop_to_return_gtk); private: @@ -90,7 +91,7 @@ private: TipsWidget *m_title; QTimer *m_waitLeaveTimer; - DImageButton *m_closeBtn2D; + DIconButton *m_closeBtn2D; DWindowManagerHelper *m_wmHelper; }; diff --git a/frame/item/components/floatingpreview.cpp b/frame/item/components/floatingpreview.cpp index f042938dc..81fff56a5 100644 --- a/frame/item/components/floatingpreview.cpp +++ b/frame/item/components/floatingpreview.cpp @@ -35,14 +35,15 @@ FloatingPreview::FloatingPreview(QWidget *parent) : QWidget(parent) - , m_closeBtn3D(new DImageButton) + , m_closeBtn3D(new DIconButton(this)) , m_titleBtn(new DPushButton) { m_closeBtn3D->setObjectName("closebutton-3d"); m_closeBtn3D->setFixedSize(24, 24); - m_closeBtn3D->setNormalPic(":/icons/resources/close_round_normal.svg"); - m_closeBtn3D->setHoverPic(":/icons/resources/close_round_hover.svg"); - m_closeBtn3D->setPressPic(":/icons/resources/close_round_press.svg"); + m_closeBtn3D->setIconSize(QSize(24, 24)); + m_closeBtn3D->setIcon(QIcon(":/icons/resources/close_round_normal.svg")); + m_closeBtn3D->setFlat(true); + m_closeBtn3D->installEventFilter(this); m_titleBtn->setBackgroundRole(QPalette::Base); m_titleBtn->setForegroundRole(QPalette::Text); @@ -61,7 +62,7 @@ FloatingPreview::FloatingPreview(QWidget *parent) setLayout(centralLayout); setFixedSize(SNAP_WIDTH, SNAP_HEIGHT); - connect(m_closeBtn3D, &DImageButton::clicked, this, &FloatingPreview::onCloseBtnClicked); + connect(m_closeBtn3D, &DIconButton::clicked, this, &FloatingPreview::onCloseBtnClicked); } WId FloatingPreview::trackedWid() const @@ -163,6 +164,18 @@ void FloatingPreview::mouseReleaseEvent(QMouseEvent *e) bool FloatingPreview::eventFilter(QObject *watched, QEvent *event) { + if(watched == m_closeBtn3D) { + if(watched == m_closeBtn3D && (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverMove)) { + m_closeBtn3D->setIcon(QIcon(":/icons/resources/close_round_hover.svg")); + } + else if (watched == m_closeBtn3D && event->type() == QEvent::HoverLeave) { + m_closeBtn3D->setIcon(QIcon(":/icons/resources/close_round_normal.svg")); + } + else if (watched == m_closeBtn3D && event->type() == QEvent::MouseButtonPress) { + m_closeBtn3D->setIcon(QIcon(":/icons/resources/close_round_press.svg")); + } + } + if (watched == m_tracked && event->type() == QEvent::Destroy) hide(); diff --git a/frame/item/components/floatingpreview.h b/frame/item/components/floatingpreview.h index 54dada978..f3d5f3c83 100644 --- a/frame/item/components/floatingpreview.h +++ b/frame/item/components/floatingpreview.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include DWIDGET_USE_NAMESPACE @@ -56,7 +56,7 @@ private slots: private: QPointer m_tracked; - DImageButton *m_closeBtn3D; + DIconButton *m_closeBtn3D; DPushButton *m_titleBtn; }; diff --git a/frame/window/accessible.h b/frame/window/accessible.h index e4736c461..1c7367fa8 100644 --- a/frame/window/accessible.h +++ b/frame/window/accessible.h @@ -45,7 +45,7 @@ #include "../plugins/multitasking/multitaskingwidget.h" #include "../plugins/overlay-warning/overlaywarningwidget.h" -#include +#include #include #include @@ -91,7 +91,7 @@ SET_FORM_ACCESSIBLE(ShowDesktopWidget, "plugin-showdesktop") SET_FORM_ACCESSIBLE(OverlayWarningWidget, "plugin-overlaywarningwidget") SET_FORM_ACCESSIBLE(QWidget, m_w->objectName().isEmpty() ? "widget" : m_w->objectName()) SET_LABEL_ACCESSIBLE(QLabel, m_w->text().isEmpty() ? m_w->objectName().isEmpty() ? "text" : m_w->objectName() : m_w->text()) -SET_BUTTON_ACCESSIBLE(DImageButton, m_w->objectName().isEmpty() ? "imagebutton" : m_w->objectName()) +SET_BUTTON_ACCESSIBLE(DIconButton, m_w->objectName().isEmpty() ? "imagebutton" : m_w->objectName()) SET_BUTTON_ACCESSIBLE(DSwitchButton, m_w->text().isEmpty() ? "switchbutton" : m_w->text()) SET_BUTTON_ACCESSIBLE(DesktopWidget, "desktopWidget"); QAccessibleInterface *accessibleFactory(const QString &classname, QObject *object) @@ -141,8 +141,8 @@ QAccessibleInterface *accessibleFactory(const QString &classname, QObject *objec USE_ACCESSIBLE_BY_OBJECTNAME(classname, QLabel, "spliter_app"); USE_ACCESSIBLE_BY_OBJECTNAME(classname, QLabel, "spliter_tray"); USE_ACCESSIBLE(classname, QLabel); - USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DImageButton, "closebutton-2d"); - USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DImageButton, "closebutton-3d"); + USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DIconButton, "closebutton-2d"); + USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DIconButton, "closebutton-3d"); USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DSwitchButton, ""); return interface; diff --git a/plugins/network/item/applet/accesspointwidget.h b/plugins/network/item/applet/accesspointwidget.h index cb6b71c43..a57472f97 100644 --- a/plugins/network/item/applet/accesspointwidget.h +++ b/plugins/network/item/applet/accesspointwidget.h @@ -24,8 +24,6 @@ #include "accesspoint.h" -#include - #include #include diff --git a/plugins/sound/sinkinputwidget.cpp b/plugins/sound/sinkinputwidget.cpp index 216a29408..d9f3da84a 100644 --- a/plugins/sound/sinkinputwidget.cpp +++ b/plugins/sound/sinkinputwidget.cpp @@ -25,6 +25,7 @@ #include #include #include + #include #include #include @@ -33,7 +34,6 @@ #define ICON_SIZE 24 #define APP_TITLE_SIZE 110 -DWIDGET_USE_NAMESPACE DGUI_USE_NAMESPACE const QPixmap getIconFromTheme(const QString &name, const QSize &size, const qreal ratio) @@ -47,15 +47,17 @@ const QPixmap getIconFromTheme(const QString &name, const QSize &size, const qre SinkInputWidget::SinkInputWidget(const QString &inputPath, QWidget *parent) : QWidget(parent) , m_inputInter(new DBusSinkInput(inputPath, this)) - , m_appBtn(new DImageButton(this)) - , m_volumeBtnMin(new DImageButton(this)) + , m_appBtn(new DIconButton(this)) + , m_volumeBtnMin(new DIconButton(this)) , m_volumeIconMax(new QLabel(this)) , m_volumeSlider(new VolumeSlider(this)) , m_volumeLabel(new TipsWidget(this)) { const QString iconName = m_inputInter->icon(); m_appBtn->setAccessibleName("app-" + iconName + "-icon"); - m_appBtn->setPixmap(getIconFromTheme(iconName, QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF())); + m_appBtn->setIcon(getIconFromTheme(iconName, QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF())); + m_appBtn->setIconSize(QSize(ICON_SIZE, ICON_SIZE)); + m_appBtn->setFlat(true); DLabel *titleLabel = new DLabel; titleLabel->setForegroundRole(DPalette::TextTitle); @@ -63,7 +65,9 @@ SinkInputWidget::SinkInputWidget(const QString &inputPath, QWidget *parent) m_volumeBtnMin->setAccessibleName("volume-button"); m_volumeBtnMin->setFixedSize(ICON_SIZE, ICON_SIZE); - m_volumeBtnMin->setPixmap(DHiDPIHelper::loadNxPixmap("://audio-volume-low-symbolic.svg")); + m_volumeBtnMin->setIconSize(QSize(ICON_SIZE, ICON_SIZE)); + m_volumeBtnMin->setIcon(DHiDPIHelper::loadNxPixmap("://audio-volume-low-symbolic.svg")); + m_volumeBtnMin->setFlat(true); m_volumeIconMax->setFixedSize(ICON_SIZE, ICON_SIZE); @@ -82,7 +86,6 @@ SinkInputWidget::SinkInputWidget(const QString &inputPath, QWidget *parent) appLayout->setSpacing(0); appLayout->setMargin(0); - // 音量图标+slider QHBoxLayout *volumeCtrlLayout = new QHBoxLayout; volumeCtrlLayout->addSpacing(2); @@ -104,7 +107,7 @@ SinkInputWidget::SinkInputWidget(const QString &inputPath, QWidget *parent) connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::setVolume); connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SinkInputWidget::onVolumeChanged); // connect(m_volumeSlider, &VolumeSlider::requestPlaySoundEffect, this, &SinkInputWidget::onPlaySoundEffect); - connect(m_volumeBtnMin, &DImageButton::clicked, this, &SinkInputWidget::setMute); + connect(m_volumeBtnMin, &DIconButton::clicked, this, &SinkInputWidget::setMute); connect(m_inputInter, &DBusSinkInput::MuteChanged, this, &SinkInputWidget::setMuteIcon); connect(m_inputInter, &DBusSinkInput::VolumeChanged, this, [ = ] { m_volumeSlider->setValue(m_inputInter->volume() * 1000); @@ -163,9 +166,9 @@ void SinkInputWidget::setMuteIcon() p.drawPixmap(0, 0, muteIcon); appIconSource.setDevicePixelRatio(ratio); - m_volumeBtnMin->setPixmap(appIconSource); + m_volumeBtnMin->setIcon(appIconSource); } else { - m_volumeBtnMin->setPixmap(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF())); + m_volumeBtnMin->setIcon(getIconFromTheme(m_inputInter->icon(), QSize(ICON_SIZE, ICON_SIZE), devicePixelRatioF())); } refreshIcon(); @@ -195,7 +198,7 @@ void SinkInputWidget::refreshIcon() m_volumeIconMax->setPixmap(ret); ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio); - m_volumeBtnMin->setPixmap(ret); + m_volumeBtnMin->setIcon(ret); } void SinkInputWidget:: onVolumeChanged() diff --git a/plugins/sound/sinkinputwidget.h b/plugins/sound/sinkinputwidget.h index 34bfd7246..6ead6c92a 100644 --- a/plugins/sound/sinkinputwidget.h +++ b/plugins/sound/sinkinputwidget.h @@ -27,10 +27,13 @@ #include "../widgets/tipswidget.h" #include - -#include #include +#include + +DWIDGET_USE_NAMESPACE + +class QLabel; class SinkInputWidget : public QWidget { Q_OBJECT @@ -51,8 +54,8 @@ private: private: DBusSinkInput *m_inputInter; - Dtk::Widget::DImageButton *m_appBtn; - Dtk::Widget::DImageButton *m_volumeBtnMin; + DIconButton *m_appBtn; + DIconButton *m_volumeBtnMin; QLabel *m_volumeIconMax; VolumeSlider *m_volumeSlider; TipsWidget *m_volumeLabel; diff --git a/plugins/sound/soundapplet.cpp b/plugins/sound/soundapplet.cpp index 157bafebb..d1cc09785 100644 --- a/plugins/sound/soundapplet.cpp +++ b/plugins/sound/soundapplet.cpp @@ -43,14 +43,13 @@ SoundApplet::SoundApplet(QWidget *parent) : QScrollArea(parent) , m_centralWidget(new QWidget) , m_applicationTitle(new QWidget) - , m_volumeBtn(new DImageButton) + , m_volumeBtn(new DIconButton(this)) , m_volumeIconMax(new QLabel) , m_volumeSlider(new VolumeSlider) , m_soundShow(new TipsWidget) , m_audioInter(new DBusAudio(this)) , m_defSinkInter(nullptr) { - // QIcon::setThemeName("deepin"); m_centralWidget->setAccessibleName("volumn-centralwidget"); m_volumeBtn->setAccessibleName("volume-button"); m_volumeIconMax->setAccessibleName("volume-iconmax"); @@ -66,10 +65,10 @@ SoundApplet::SoundApplet(QWidget *parent) TipsWidget *deviceLabel = new TipsWidget; deviceLabel->setText(tr("Device")); - QHBoxLayout *deviceLayout =new QHBoxLayout; + QHBoxLayout *deviceLayout = new QHBoxLayout; deviceLayout->addSpacing(2); - deviceLayout->addWidget(deviceLabel,0, Qt::AlignLeft); - deviceLayout->addWidget(m_soundShow,0,Qt::AlignRight); + deviceLayout->addWidget(deviceLabel, 0, Qt::AlignLeft); + deviceLayout->addWidget(m_soundShow, 0, Qt::AlignRight); deviceLayout->setSpacing(0); deviceLayout->setMargin(0); @@ -110,6 +109,8 @@ SoundApplet::SoundApplet(QWidget *parent) m_applicationTitle->setAccessibleName("applicationtitle"); m_volumeBtn->setFixedSize(ICON_SIZE, ICON_SIZE); + m_volumeBtn->setIconSize(QSize(ICON_SIZE, ICON_SIZE)); + m_volumeBtn->setFlat(true); m_volumeSlider->setMinimum(0); m_volumeSlider->setMaximum(m_audioInter->maxUIVolume() * 100.0f); @@ -131,7 +132,7 @@ SoundApplet::SoundApplet(QWidget *parent) m_centralWidget->setAutoFillBackground(false); viewport()->setAutoFillBackground(false); - connect(m_volumeBtn, &DImageButton::clicked, this, &SoundApplet::toggleMute); + connect(m_volumeBtn, &DIconButton::clicked, this, &SoundApplet::toggleMute); connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged); connect(m_volumeSlider, &VolumeSlider::requestPlaySoundEffect, this, &SoundApplet::onPlaySoundEffect); connect(m_audioInter, &DBusAudio::SinkInputsChanged, this, &SoundApplet::sinkInputsChanged); @@ -259,5 +260,5 @@ void SoundApplet::refreshIcon() m_volumeIconMax->setPixmap(ret); ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio); - m_volumeBtn->setPixmap(ret); + m_volumeBtn->setIcon(ret); } diff --git a/plugins/sound/soundapplet.h b/plugins/sound/soundapplet.h index 9aca0fba7..d9471a085 100644 --- a/plugins/sound/soundapplet.h +++ b/plugins/sound/soundapplet.h @@ -30,7 +30,10 @@ #include #include #include -#include + +#include + +DWIDGET_USE_NAMESPACE class TipsWidget; class SoundApplet : public QScrollArea @@ -62,7 +65,7 @@ private: private: QWidget *m_centralWidget; QWidget *m_applicationTitle; - Dtk::Widget::DImageButton *m_volumeBtn; + DIconButton *m_volumeBtn; QLabel *m_volumeIconMax; VolumeSlider *m_volumeSlider; TipsWidget *m_soundShow;