diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index f79dc912c..89a7a6e8e 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -654,6 +654,11 @@ void AppItem::showPreview() connect(m_appPreviewTips, &PreviewContainer::requestCancelPreviewWindow, this, &AppItem::onResetPreview); connect(m_appPreviewTips, &PreviewContainer::requestHidePopup, this, &AppItem::onResetPreview); + // 预览标题显示方式的配置 + if (m_activeAppSettings->keys().contains("previewTitle")) { + m_appPreviewTips->setTitleDisplayMode(m_activeAppSettings->get("previewTitle").toInt()); + } + showPopupWindow(m_appPreviewTips, true); } diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index e0dbde934..237b1b416 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -60,6 +60,7 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) , m_closeAble(false) , m_isWidowHidden(false) , m_title(new TipsWidget(this)) + , m_3DtitleBtn(nullptr) , m_waitLeaveTimer(new QTimer(this)) , m_closeBtn2D(new DIconButton(this)) , m_wmHelper(DWindowManagerHelper::instance()) @@ -95,6 +96,50 @@ void AppSnapshot::setWindowState() } } +// 每次更新窗口信息时更新标题 +void AppSnapshot::updateTitle() +{ + // 2D不显示 + if (!m_wmHelper->hasComposite()) + return; + + if (!m_3DtitleBtn) { + m_3DtitleBtn = new DPushButton(this); + m_3DtitleBtn->setAccessibleName("AppPreviewTitle"); + m_3DtitleBtn->setBackgroundRole(QPalette::Base); + m_3DtitleBtn->setForegroundRole(QPalette::Text); + m_3DtitleBtn->setFocusPolicy(Qt::NoFocus); + m_3DtitleBtn->setAttribute(Qt::WA_TransparentForMouseEvents); + m_3DtitleBtn->setFixedHeight(36); + m_3DtitleBtn->setVisible(false); + } + + QFontMetrics fm(m_3DtitleBtn->font()); + int textWidth = fm.width(title()) + 10 + BTN_TITLE_MARGIN; + int titleWidth = SNAP_WIDTH - (TITLE_MARGIN * 2 + BORDER_MARGIN); + + if (textWidth < titleWidth) { + m_3DtitleBtn->setFixedWidth(textWidth); + m_3DtitleBtn->setText(title()); + } else { + QString str = title(); + /*某些特殊字符只显示一半 如"Q"," W",所以加一个空格保证字符显示完整,*/ + str.insert(0, " "); + QString strTtile = m_3DtitleBtn->fontMetrics().elidedText(str, Qt::ElideRight, titleWidth - BTN_TITLE_MARGIN); + m_3DtitleBtn->setText(strTtile); + m_3DtitleBtn->setFixedWidth(titleWidth + BTN_TITLE_MARGIN); + } + + // 移动到预览图中下 + m_3DtitleBtn->move(QPoint(SNAP_WIDTH / 2, SNAP_HEIGHT - m_3DtitleBtn->height() / 2 - TITLE_MARGIN) - m_3DtitleBtn->rect().center()); +} + +void AppSnapshot::setTitleVisible(bool bVisible) +{ + if (m_3DtitleBtn) + m_3DtitleBtn->setVisible(bVisible && m_wmHelper->hasComposite()); +} + void AppSnapshot::closeWindow() const { const auto display = QX11Info::display(); @@ -135,6 +180,7 @@ void AppSnapshot::setWindowInfo(const WindowInfo &info) QString strTtile = m_title->fontMetrics().elidedText(m_windowInfo.title, Qt::ElideRight, width() - m_closeBtn2D->width()); m_title->setText(strTtile); getWindowState(); + updateTitle(); } void AppSnapshot::dragEnterEvent(QDragEnterEvent *e) diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index a8dd7a847..b39c69a5c 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -40,6 +41,14 @@ DGUI_USE_NAMESPACE #define SNAP_CLOSE_BTN_WIDTH (24) #define SNAP_CLOSE_BTN_MARGIN (5) +// 标题到左右两边的距离 +#define TITLE_MARGIN (20) + +// 标题的文本到标题背景两边的距离 +#define BTN_TITLE_MARGIN (6) + +// 高亮框边距 +#define BORDER_MARGIN (8) struct SHMInfo; struct _XImage; @@ -66,6 +75,8 @@ public: inline const QRectF snapshotGeometry() const { return m_snapshotSrcRect; } inline const QString title() const { return m_windowInfo.title; } void setWindowState(); + void setTitleVisible(bool bVisible); + QString appTitle() { return m_3DtitleBtn ? m_3DtitleBtn->text() : QString(); } signals: void entered(const WId wid) const; @@ -91,6 +102,7 @@ private: XImage *getImageXlib(); QRect rectRemovedShadow(const QImage &qimage, unsigned char *prop_to_return_gtk); void getWindowState(); + void updateTitle(); private: const WId m_wid; @@ -102,6 +114,8 @@ private: QRectF m_snapshotSrcRect; Dock::TipsWidget *m_title; + DPushButton *m_3DtitleBtn; + QTimer *m_waitLeaveTimer; DIconButton *m_closeBtn2D; DWindowManagerHelper *m_wmHelper; diff --git a/frame/item/components/floatingpreview.cpp b/frame/item/components/floatingpreview.cpp index 7892dfe12..be9960d0c 100644 --- a/frame/item/components/floatingpreview.cpp +++ b/frame/item/components/floatingpreview.cpp @@ -29,10 +29,6 @@ #include #include -#define BORDER_MARGIN 8 -#define TITLE_MARGIN 20 -#define BTN_TITLE_MARGIN 6 - FloatingPreview::FloatingPreview(QWidget *parent) : QWidget(parent) , m_closeBtn3D(new DIconButton(this)) @@ -77,6 +73,11 @@ AppSnapshot *FloatingPreview::trackedWindow() return m_tracked; } +void FloatingPreview::setFloatingTitleVisible(bool bVisible) +{ + m_titleBtn->setVisible(bVisible); +} + void FloatingPreview::trackWindow(AppSnapshot *const snap) { if (!snap) @@ -90,21 +91,9 @@ void FloatingPreview::trackWindow(AppSnapshot *const snap) m_closeBtn3D->setVisible(m_tracked->closeAble()); - QFontMetrics fm(m_titleBtn->font()); - int textWidth = fm.width(m_tracked->title()) + 10 + BTN_TITLE_MARGIN; - int titleWidth = width() - (TITLE_MARGIN * 2 + BORDER_MARGIN); - - if (textWidth < titleWidth) { - m_titleBtn->setFixedWidth(textWidth); - m_titleBtn->setText(m_tracked->title()); - } else { - QString str = m_tracked->title(); - /*某些特殊字符只显示一半 如"Q"," W",所以加一个空格保证字符显示完整,*/ - str.insert(0, " "); - QString strTtile = m_titleBtn->fontMetrics().elidedText(str, Qt::ElideRight, titleWidth - BTN_TITLE_MARGIN); - m_titleBtn->setText(strTtile); - m_titleBtn->setFixedWidth(titleWidth + BTN_TITLE_MARGIN); - } + // 显示此标题的前提条件:配置了标题跟随鼠标显示 + // 此对象是共用的,鼠标移动到哪个预览图,title就移动到哪里显示,所以他的text统一snap获取,不再重复计算显示长度 + m_titleBtn->setText(snap->appTitle()); QTimer::singleShot(0, this, [ = ] { // 此处获取的snap->geometry()有可能是错误的,所以做个判断并且在resizeEvent中也做处理 diff --git a/frame/item/components/floatingpreview.h b/frame/item/components/floatingpreview.h index f3d5f3c83..f6aff6203 100644 --- a/frame/item/components/floatingpreview.h +++ b/frame/item/components/floatingpreview.h @@ -40,6 +40,7 @@ public: WId trackedWid() const; AppSnapshot *trackedWindow(); + void setFloatingTitleVisible(bool bVisible); public slots: void trackWindow(AppSnapshot *const snap); diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 3f40d96c3..e0a748156 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -37,6 +37,7 @@ PreviewContainer::PreviewContainer(QWidget *parent) , m_floatingPreview(new FloatingPreview(this)) , m_mouseLeaveTimer(new QTimer(this)) , m_wmHelper(DWindowManagerHelper::instance()) + , m_titleMode(HoverShow) { m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight, this); m_windowListLayout->setSpacing(SPACING); @@ -96,6 +97,20 @@ void PreviewContainer::updateSnapshots() snap->fetchSnapshot(); } +void PreviewContainer::setTitleDisplayMode(int mode) +{ + m_titleMode = static_cast(mode); + + if (!m_wmHelper->hasComposite()) + return; + + m_floatingPreview->setFloatingTitleVisible(m_titleMode == HoverShow); + + for (AppSnapshot *snap : m_snapshots) { + snap->setTitleVisible(m_titleMode == AlwaysShow); + } +} + void PreviewContainer::updateLayoutDirection(const Dock::Position dockPos) { if (m_wmHelper->hasComposite() && (dockPos == Dock::Top || dockPos == Dock::Bottom)) diff --git a/frame/item/components/previewcontainer.h b/frame/item/components/previewcontainer.h index 90ef1b7ad..1ecd50c60 100644 --- a/frame/item/components/previewcontainer.h +++ b/frame/item/components/previewcontainer.h @@ -43,6 +43,12 @@ class PreviewContainer : public QWidget public: explicit PreviewContainer(QWidget *parent = 0); + enum TitleDisplayMode { + HoverShow = 0, + AlwaysShow = 1, + AlwaysHide = 2, + }; + signals: void requestActivateWindow(const WId wid) const; void requestPreviewWindow(const WId wid) const; @@ -53,6 +59,7 @@ signals: public: void setWindowInfos(const WindowInfoMap &infos, const WindowList &allowClose); void updateSnapshots(); + void setTitleDisplayMode(int mode); public slots: void updateLayoutDirection(const Dock::Position dockPos); @@ -85,6 +92,7 @@ private: DWindowManagerHelper *m_wmHelper; QTimer *m_waitForShowPreviewTimer; WId m_currentWId; + TitleDisplayMode m_titleMode; }; #endif // PREVIEWCONTAINER_H diff --git a/gschema/com.deepin.dde.dock.module.gschema.xml b/gschema/com.deepin.dde.dock.module.gschema.xml index af24b19f6..d0447371c 100644 --- a/gschema/com.deepin.dde.dock.module.gschema.xml +++ b/gschema/com.deepin.dde.dock.module.gschema.xml @@ -62,6 +62,13 @@ Control Module Enable + + 0 + 0 Mouse over show;1 Always show; 2 Always hide + + The display mode of the application preview + +