Skip to content

Commit 1425771

Browse files
ut003640deepin-bot[bot]
authored andcommitted
tests: add test project
add debug project for dde-session-shell and dde-dock Log: add test project Influence: debug for project
1 parent fb7ad92 commit 1425771

11 files changed

Lines changed: 694 additions & 69 deletions

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project(dde-network-core
1010

1111
option(ENABLE_DEEPIN_NMQT "enable nmqt patch on deepin" ON)
1212
option(BUILD_TESTS "Build unit tests" OFF)
13+
option(BUILD_EXAMPLE "Build example programs" OFF)
1314

1415
set(DDE-Network-Core_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src-old")
1516
set(DDE-Network-Core_LIBRARIES dde-network-core)
@@ -25,7 +26,8 @@ pkg_search_module(GLIB REQUIRED glib-2.0)
2526
include_directories(${GLIB_INCLUDE_DIRS})
2627
link_directories(${GLIB_LIBRARY_DIRS})
2728

28-
if (QT_DEBUG)
29+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
30+
set(BUILD_EXAMPLE ON)
2931
message(" KF5_QT_INCLUDE_DIRS : " ${KF5_QT_INCLUDE_DIRS})
3032
message(" GLIB_INCLUDE_DIRS :" ${GLIB_INCLUDE_DIRS})
3133
message(" CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
@@ -53,8 +55,11 @@ add_subdirectory("dcc-network")
5355
if (BUILD_TESTS)
5456
add_subdirectory("tests")
5557
endif()
56-
# add_subdirectory("example")
5758
add_subdirectory("dock-network-plugin")
5859
add_subdirectory("dss-network-plugin")
59-
# add_subdirectory("dss_example")
60+
if (BUILD_EXAMPLE)
61+
# add_subdirectory("example")
62+
add_subdirectory("dss_example")
63+
add_subdirectory("dock-example")
64+
endif()
6065
add_subdirectory("network-service-plugin")

dock-example/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.7)
2+
3+
project(example-dock)
4+
5+
set(CMAKE_CXX_STANDARD 11)
6+
set(CMAKE_PREFIX_PATH $ENV{Qt6_DIR})
7+
set(CMAKE_AUTOMOC ON)
8+
set(CMAKE_AUTORCC ON)
9+
10+
find_package(Qt6 COMPONENTS Core DBus Widgets Network REQUIRED)
11+
find_package(KF6NetworkManagerQt REQUIRED)
12+
find_package(Dtk6 COMPONENTS Widget REQUIRED)
13+
find_package(PkgConfig REQUIRED)
14+
find_package(DdeDock REQUIRED)
15+
16+
# 只包含dock-example自己的源文件
17+
file(GLOB SRCS "*.cpp" "*.h")
18+
19+
add_executable(${PROJECT_NAME} ${SRCS})
20+
21+
target_include_directories(${PROJECT_NAME} PUBLIC
22+
.
23+
../src
24+
../dock-network-plugin
25+
Dtk6::Widget
26+
Qt6::DBus
27+
Qt6::Network
28+
Qt6::Widgets
29+
KF6::NetworkManagerQt
30+
${DDE-Network-Core_INCLUDE_DIRS}
31+
)
32+
33+
target_link_libraries(${PROJECT_NAME} PRIVATE
34+
Dtk6::Widget
35+
Qt6::DBus
36+
Qt6::Network
37+
Qt6::Widgets
38+
KF6::NetworkManagerQt
39+
dock-network-plugin
40+
dde-network-core6
41+
)

dock-example/dockpopupwindow.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "dockpopupwindow.h"
6+
#include <QApplication>
7+
#include <QTimer>
8+
#include <QAccessibleEvent>
9+
10+
DWIDGET_USE_NAMESPACE
11+
12+
DockPopupWindow::DockPopupWindow(QWidget *parent)
13+
: DArrowRectangle(ArrowBottom, FloatWidget, parent)
14+
, m_model(false)
15+
, m_regionInter(new DRegionMonitor(this))
16+
, m_enableMouseRelease(true)
17+
{
18+
setMargin(0);
19+
m_wmHelper = DWindowManagerHelper::instance();
20+
compositeChanged();
21+
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
22+
setShadowBlurRadius(20);
23+
setRadius(6);
24+
setShadowYOffset(2);
25+
setShadowXOffset(0);
26+
setArrowWidth(18);
27+
setArrowHeight(10);
28+
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
29+
connect(m_regionInter, &DRegionMonitor::buttonRelease, this, &DockPopupWindow::onGlobMouseRelease);
30+
}
31+
32+
DockPopupWindow::~DockPopupWindow()
33+
{
34+
QWidget *content = getContent();
35+
if (content) {
36+
content->removeEventFilter(this);
37+
content->setParent(nullptr);
38+
}
39+
}
40+
41+
bool DockPopupWindow::model() const
42+
{
43+
return isVisible() && m_model;
44+
}
45+
46+
void DockPopupWindow::setContent(QWidget *content)
47+
{
48+
QWidget *lastWidget = getContent();
49+
if (lastWidget)
50+
lastWidget->removeEventFilter(this);
51+
content->installEventFilter(this);
52+
QAccessibleEvent event(this, QAccessible::NameChanged);
53+
QAccessible::updateAccessibility(&event);
54+
if (!content->objectName().trimmed().isEmpty())
55+
setAccessibleName(content->objectName() + "-popup");
56+
DArrowRectangle::setContent(content);
57+
}
58+
59+
void DockPopupWindow::show(const QPoint &pos, const bool model)
60+
{
61+
m_model = model;
62+
m_lastPoint = pos;
63+
show(pos.x(), pos.y());
64+
if (m_regionInter->registered()) {
65+
m_regionInter->unregisterRegion();
66+
}
67+
if (m_model) {
68+
m_regionInter->registerRegion();
69+
}
70+
blockButtonRelease();
71+
}
72+
73+
void DockPopupWindow::show(const int x, const int y)
74+
{
75+
m_lastPoint = QPoint(x, y);
76+
blockButtonRelease();
77+
DArrowRectangle::show(x, y);
78+
}
79+
80+
void DockPopupWindow::blockButtonRelease()
81+
{
82+
// 短暂的不处理鼠标release事件,防止出现刚显示又被隐藏的情况
83+
m_enableMouseRelease = false;
84+
QTimer::singleShot(10, this, [this] {
85+
m_enableMouseRelease = true;
86+
});
87+
}
88+
void DockPopupWindow::hide()
89+
{
90+
if (m_regionInter->registered())
91+
m_regionInter->unregisterRegion();
92+
DArrowRectangle::hide();
93+
}
94+
95+
void DockPopupWindow::showEvent(QShowEvent *e)
96+
{
97+
DArrowRectangle::showEvent(e);
98+
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
99+
}
100+
101+
void DockPopupWindow::enterEvent(QEnterEvent *e)
102+
{
103+
DArrowRectangle::enterEvent(e);
104+
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
105+
}
106+
107+
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
108+
{
109+
if (o != getContent() || e->type() != QEvent::Resize)
110+
return false;
111+
// FIXME: ensure position move after global mouse release event
112+
if (isVisible()) {
113+
QTimer::singleShot(10, this, [=] {
114+
// NOTE(sbw): double check is necessary, in this time, the popup maybe already hided.
115+
if (isVisible())
116+
show(m_lastPoint, m_model);
117+
});
118+
}
119+
return false;
120+
}
121+
122+
void DockPopupWindow::onGlobMouseRelease(const QPoint &mousePos, const int flag)
123+
{
124+
Q_ASSERT(m_model);
125+
if (!m_enableMouseRelease)
126+
return;
127+
if ((flag != DRegionMonitor::WatchedFlags::Button_Left) && (flag != DRegionMonitor::WatchedFlags::Button_Right)) {
128+
return;
129+
}
130+
const QRect rect = QRect(pos(), size());
131+
if (rect.contains(mousePos))
132+
return;
133+
emit accept();
134+
m_regionInter->unregisterRegion();
135+
}
136+
137+
void DockPopupWindow::compositeChanged()
138+
{
139+
setBackgroundColor(QColor(235, 235, 235, 80));
140+
setBorderColor(QColor(235, 235, 235, 80));
141+
}
142+
143+
void DockPopupWindow::ensureRaised()
144+
{
145+
if (isVisible()) {
146+
QWidget *content = getContent();
147+
if (!content || !content->isVisible()) {
148+
this->setVisible(false);
149+
} else {
150+
raise();
151+
}
152+
}
153+
}

dock-example/dockpopupwindow.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#ifndef DOCKPOPUPWINDOW_H
6+
#define DOCKPOPUPWINDOW_H
7+
8+
#include <QWidget>
9+
10+
#include <DArrowRectangle>
11+
#include <DRegionMonitor>
12+
#include <DWindowManagerHelper>
13+
14+
DWIDGET_USE_NAMESPACE
15+
DGUI_USE_NAMESPACE
16+
17+
class DockPopupWindow : public Dtk::Widget::DArrowRectangle
18+
{
19+
Q_OBJECT
20+
21+
public:
22+
explicit DockPopupWindow(QWidget *parent = nullptr);
23+
~DockPopupWindow() override;
24+
bool model() const;
25+
void setContent(QWidget *content);
26+
public slots:
27+
void show(const QPoint &pos, bool model = false);
28+
void show(int x, int y) override;
29+
void hide();
30+
signals:
31+
void accept();
32+
// 在把专业版的仓库降级到debian的stable时, dock出现了一个奇怪的问题:
33+
// 在plugins/tray/system-trays/systemtrayitem.cpp中的showPopupWindow函数中
34+
// 无法连接到上面这个信号: "accept", qt给出一个运行时警告提示找不到信号
35+
// 目前的解决方案就是在下面增加了这个信号
36+
void unusedSignal();
37+
protected:
38+
void showEvent(QShowEvent *e) override;
39+
void enterEvent(QEnterEvent *e) override;
40+
bool eventFilter(QObject *o, QEvent *e) override;
41+
void blockButtonRelease();
42+
private slots:
43+
void onGlobMouseRelease(const QPoint &mousePos, int flag);
44+
void compositeChanged();
45+
void ensureRaised();
46+
private:
47+
bool m_model;
48+
QPoint m_lastPoint;
49+
DRegionMonitor *m_regionInter;
50+
DWindowManagerHelper *m_wmHelper;
51+
bool m_enableMouseRelease;
52+
};
53+
54+
#endif // DOCKPOPUPWINDOW_H

0 commit comments

Comments
 (0)