From 4b0166f59b272acaa9c9592781810f73a5dd57c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=9C=8B=E7=A8=8B?= Date: Fri, 31 Dec 2021 15:09:12 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B8=85=E9=99=A4=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清除编译警告和cppcheck检查出的警告信息 Log: Influence: 无 Task: https://pms.uniontech.com/zentao/task-view-96546.html Change-Id: I8b32b02c9d3a284029a39826516ab7b41132f236 --- frame/item/components/appsnapshot.cpp | 2 + frame/item/components/previewcontainer.cpp | 27 +--- frame/item/components/previewcontainer.h | 1 - frame/main.cpp | 2 +- frame/util/dockpopupwindow.cpp | 31 +---- frame/util/dockpopupwindow.h | 1 - frame/util/utils.h | 24 ++++ frame/window/components/desktop_widget.cpp | 2 + frame/window/mainpanelcontrol.cpp | 119 +----------------- frame/window/mainpanelcontrol.h | 2 - frame/window/mainwindow.h | 2 +- plugins/dcc-dock-plugin/CMakeLists.txt | 4 +- plugins/onboard/onboardplugin.cpp | 2 + plugins/shutdown/shutdownplugin.cpp | 2 + .../containers/attentioncontainer.cpp | 2 + .../fashiontray/fashiontraycontrolwidget.cpp | 2 + plugins/tray/fashiontray/fashiontrayitem.cpp | 1 + plugins/tray/trayplugin.cpp | 2 + 18 files changed, 57 insertions(+), 171 deletions(-) diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index a61322a3d..9587b6803 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -309,6 +309,8 @@ void AppSnapshot::leaveEvent(QEvent *e) void AppSnapshot::paintEvent(QPaintEvent *e) { + Q_UNUSED(e); + QPainter painter(this); if (!m_wmHelper->hasComposite()) { diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 21089643c..2c070faf0 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -215,31 +215,12 @@ void PreviewContainer::appendSnapWidget(const WId wid) snap->fetchSnapshot(); } -void PreviewContainer::updatePreviewCursor() -{ - static QCursor *lastArrowCursor = nullptr; - static QString lastCursorTheme; - int lastCursorSize = 0; - QString theme = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-name", "bloom").toString(); - int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); - if (theme != lastCursorTheme || cursorSize != lastCursorSize) { - QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); - if (!cursor) - return; - lastCursorTheme = theme; - lastCursorSize = cursorSize; - setCursor(*cursor); - if (lastArrowCursor) - delete lastArrowCursor; - - lastArrowCursor = cursor; - } -} - void PreviewContainer::enterEvent(QEvent *e) { - if (Utils::IS_WAYLAND_DISPLAY) - updatePreviewCursor(); + if (Utils::IS_WAYLAND_DISPLAY) { + Utils::updateCursor(this); + } + QWidget::enterEvent(e); m_needActivate = false; diff --git a/frame/item/components/previewcontainer.h b/frame/item/components/previewcontainer.h index 634593a71..1ecd50c60 100644 --- a/frame/item/components/previewcontainer.h +++ b/frame/item/components/previewcontainer.h @@ -69,7 +69,6 @@ public slots: private: void adjustSize(const bool composite); void appendSnapWidget(const WId wid); - void updatePreviewCursor(); void enterEvent(QEvent *e); void leaveEvent(QEvent *e); diff --git a/frame/main.cpp b/frame/main.cpp index e89600b82..6863f19ca 100644 --- a/frame/main.cpp +++ b/frame/main.cpp @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) setenv("D_DXCB_FORCE_NO_TITLEBAR", "1", 1); } - DGuiApplicationHelper::setUseInactiveColorGroup(false); + DGuiApplicationHelper::setAttribute(DGuiApplicationHelper::UseInactiveColorGroup, false); DockApplication app(argc, argv); auto configs = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation); diff --git a/frame/util/dockpopupwindow.cpp b/frame/util/dockpopupwindow.cpp index 60500fb89..36d187b02 100644 --- a/frame/util/dockpopupwindow.cpp +++ b/frame/util/dockpopupwindow.cpp @@ -114,8 +114,9 @@ void DockPopupWindow::hide() void DockPopupWindow::showEvent(QShowEvent *e) { DArrowRectangle::showEvent(e); - if (Utils::IS_WAYLAND_DISPLAY) - updatePopupWindowCursor(); + if (Utils::IS_WAYLAND_DISPLAY) { + Utils::updateCursor(this); + } QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised); } @@ -123,33 +124,13 @@ void DockPopupWindow::showEvent(QShowEvent *e) void DockPopupWindow::enterEvent(QEvent *e) { DArrowRectangle::enterEvent(e); - if (Utils::IS_WAYLAND_DISPLAY) - updatePopupWindowCursor(); + if (Utils::IS_WAYLAND_DISPLAY) { + Utils::updateCursor(this); + } QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised); } -void DockPopupWindow::updatePopupWindowCursor() -{ - static QCursor *lastArrowCursor = nullptr; - static QString lastCursorTheme; - int lastCursorSize = 0; - QString theme = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-name", "bloom").toString(); - int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); - if (theme != lastCursorTheme || cursorSize != lastCursorSize) { - QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); - if (!cursor) - return; - lastCursorTheme = theme; - lastCursorSize = cursorSize; - setCursor(*cursor); - if (lastArrowCursor) - delete lastArrowCursor; - - lastArrowCursor = cursor; - } -} - bool DockPopupWindow::eventFilter(QObject *o, QEvent *e) { if (o != getContent() || e->type() != QEvent::Resize) diff --git a/frame/util/dockpopupwindow.h b/frame/util/dockpopupwindow.h index d58b15a0c..81465abea 100644 --- a/frame/util/dockpopupwindow.h +++ b/frame/util/dockpopupwindow.h @@ -63,7 +63,6 @@ private slots: void onGlobMouseRelease(const QPoint &mousePos, const int flag); void compositeChanged(); void ensureRaised(); - void updatePopupWindowCursor(); private: bool m_model; diff --git a/frame/util/utils.h b/frame/util/utils.h index 0fb40c76f..fd4cfdd33 100644 --- a/frame/util/utils.h +++ b/frame/util/utils.h @@ -27,6 +27,8 @@ #include #include +#include "imageutil.h" + namespace Utils { #define ICBC_CONF_FILE "/etc/deepin/icbc.conf" @@ -215,6 +217,28 @@ inline int comparePluginApi(const QString &pluginApi1, const QString &pluginApi2 return -1; } } + +inline void updateCursor(QWidget *w) +{ + static QString lastCursorTheme; + static int lastCursorSize = 0; + QString theme = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-name", "bloom").toString(); + int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); + if (theme != lastCursorTheme || cursorSize != lastCursorSize) { + QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); + if (!cursor) + return; + lastCursorTheme = theme; + lastCursorSize = cursorSize; + w->setCursor(*cursor); + static QCursor *lastArrowCursor = nullptr; + if (lastArrowCursor) + delete lastArrowCursor; + + lastArrowCursor = cursor; + } +} + } #endif // UTILS diff --git a/frame/window/components/desktop_widget.cpp b/frame/window/components/desktop_widget.cpp index f703b73ff..f21911490 100644 --- a/frame/window/components/desktop_widget.cpp +++ b/frame/window/components/desktop_widget.cpp @@ -15,6 +15,8 @@ DesktopWidget::DesktopWidget(QWidget *parent) void DesktopWidget::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); //描绘桌面区域的颜色 painter.setOpacity(1); diff --git a/frame/window/mainpanelcontrol.cpp b/frame/window/mainpanelcontrol.cpp index eff17926a..e7ab3bba7 100755 --- a/frame/window/mainpanelcontrol.cpp +++ b/frame/window/mainpanelcontrol.cpp @@ -711,8 +711,9 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) void MainPanelControl::enterEvent(QEvent *event) { - if (Utils::IS_WAYLAND_DISPLAY) - updatePanelCursor(); + if (Utils::IS_WAYLAND_DISPLAY) { + Utils::updateCursor(this); + } QWidget::enterEvent(event); } @@ -802,98 +803,6 @@ void MainPanelControl::startDrag(DockItem *dockItem) } } -void MainPanelControl::startDragWayland(DockItem *item) -{ - QPixmap pixmap; - if (item->itemType() == DockItem::App) { - pixmap = qobject_cast(item)->appIcon(); - } else { - pixmap = item->grab(); - } - /*TODO: pixmap半透明处理 - QPixmap pixmap1; - { - QPixmap temp(pixmap.size()); - temp.fill(Qt::transparent); - - QPainter p1(&temp); - p1.setCompositionMode(QPainter::CompositionMode_Source); - p1.drawPixmap(0, 0, pixmap); - p1.setCompositionMode(QPainter::CompositionMode_DestinationIn); - - //根据QColor中第四个参数设置透明度,0~255 - p1.fillRect(temp.rect(), QColor(0, 0, 0, 125)); - p1.end(); - - pixmap1 = temp; - }*/ - - item->setDraging(true); - item->update(); - - QDrag *drag = new QDrag(item); - drag->setPixmap(pixmap); - - drag->setHotSpot(pixmap.rect().center() / pixmap.devicePixelRatioF()); - drag->setMimeData(new QMimeData); - - /*TODO: 开启线程,在移动中设置图片是否为半透明, 当前接口调用QShapedPixmapWindow找不到动态库的实现 - bool isRun = true; - QtConcurrent::run([&isRun, &pixmap, &pixmap1, this]{ - while (isRun) { - QPlatformDrag *platformDrag = QGuiApplicationPrivate::platformIntegration()->drag(); - QShapedPixmapWindow *dragIconWindow = nullptr; - if (platformDrag) - dragIconWindow = static_cast(platformDrag)->shapedPixmapWindow(); - - if (!dragIconWindow) - continue; - - if (AppDragWidget::isRemoveable(m_position, QRect(mapToGlobal(pos()), size()))) { - // dragIconWindow->setPixmap(pixmap1); - } else { - // dragIconWindow->setPixmap(pixmap); - } - - } - });*/ - - drag->exec(Qt::MoveAction); - - //isRun = false; - - if (drag->target() == this) { - item->setDraging(false); - item->update(); - return; - } - - //开启动画效果 - auto appDragWidget = new AppDragWidget(); - appDragWidget->setAppPixmap(pixmap); - appDragWidget->setItem(item); - appDragWidget->setDockInfo(m_position, QRect(mapToGlobal(pos()), size())); - appDragWidget->setOriginPos(m_appAreaSonWidget->mapToGlobal(item->pos())); - appDragWidget->setPixmapOpacity(0.5); - appDragWidget->show(); - QGuiApplication::platformNativeInterface()->setWindowProperty(appDragWidget->windowHandle()->handle(), - "_d_dwayland_window-type" , "menu"); - - QTimer::singleShot(10, [item, appDragWidget]{ - if (appDragWidget->isRemoveAble(QCursor::pos())) { - appDragWidget->showRemoveAnimation(); - AppItem *appItem = static_cast(item); - appItem->undock(); - item->setDraging(false); - item->update(); - } else { - appDragWidget->showGoBackAnimation(); - item->setDraging(false); - item->update(); - } - }); -} - DockItem *MainPanelControl::dropTargetItem(DockItem *sourceItem, QPoint point) { QWidget *parentWidget = m_appAreaSonWidget; @@ -1303,25 +1212,3 @@ bool MainPanelControl::appIsOnDock(const QString &appDesktop) { return DockItemManager::instance()->appIsOnDock(appDesktop); } - -// TODO: 多处使用类似方法,可尝试提取公共函数 -void MainPanelControl::updatePanelCursor() -{ - static QCursor *lastArrowCursor = nullptr; - static QString lastCursorTheme; - int lastCursorSize = 0; - QString theme = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-name", "bloom").toString(); - int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); - if (theme != lastCursorTheme || cursorSize != lastCursorSize) { - QCursor *cursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), "left_ptr", cursorSize); - if (!cursor) - return; - lastCursorTheme = theme; - lastCursorSize = cursorSize; - setCursor(*cursor); - if (lastArrowCursor) - delete lastArrowCursor; - - lastArrowCursor = cursor; - } -} diff --git a/frame/window/mainpanelcontrol.h b/frame/window/mainpanelcontrol.h index 8024d85fa..50cd1eb5e 100755 --- a/frame/window/mainpanelcontrol.h +++ b/frame/window/mainpanelcontrol.h @@ -77,7 +77,6 @@ private: // 拖拽相关 void startDrag(DockItem *); - void startDragWayland(DockItem *item); DockItem *dropTargetItem(DockItem *sourceItem, QPoint point); void moveItem(DockItem *sourceItem, DockItem *targetItem); void handleDragMove(QDragMoveEvent *e, bool isFilter); @@ -96,7 +95,6 @@ protected: void mousePressEvent(QMouseEvent *e) override; void resizeEvent(QResizeEvent *event) override; void paintEvent(QPaintEvent *event) override; - void updatePanelCursor(); private: QBoxLayout *m_mainPanelLayout; diff --git a/frame/window/mainwindow.h b/frame/window/mainwindow.h index e4427cf4a..dc0f08f2e 100644 --- a/frame/window/mainwindow.h +++ b/frame/window/mainwindow.h @@ -133,7 +133,6 @@ private: int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt(); Position position = static_cast(qApp->property("position").toInt()); - static QCursor *lastCursor = nullptr; static QString lastTheme; static int lastPosition = -1; static int lastCursorSize = -1; @@ -147,6 +146,7 @@ private: return; setCursor(*newCursor); + static QCursor *lastCursor = nullptr; if (lastCursor) delete lastCursor; diff --git a/plugins/dcc-dock-plugin/CMakeLists.txt b/plugins/dcc-dock-plugin/CMakeLists.txt index b6b5982be..0c5144277 100644 --- a/plugins/dcc-dock-plugin/CMakeLists.txt +++ b/plugins/dcc-dock-plugin/CMakeLists.txt @@ -10,7 +10,7 @@ file(GLOB_RECURSE SRCS "*.h" "*.cpp") -find_package(Qt5 COMPONENTS Core Widgets DBus LinguistTools REQUIRED) +find_package(Qt5 COMPONENTS Core Widgets DBus Svg LinguistTools REQUIRED) find_package(DdeControlCenter REQUIRED) find_package(PkgConfig REQUIRED) find_package(DtkWidget REQUIRED) @@ -24,6 +24,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ../src ../../frame/util ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5Svg_INCLUDE_DIRS} ${DtkWidget_INCLUDE_DIRS} ${DdeControlCenter_INCLUDE_DIR} ${DFrameworkDBus_INCLUDE_DIRS} @@ -32,6 +33,7 @@ target_include_directories(${PLUGIN_NAME} PUBLIC ) target_link_libraries(${PLUGIN_NAME} PRIVATE ${Qt5Widgets_LIBRARIES} + ${Qt5Svg_LIBRARIES} ${DtkWidget_LIBRARIES} ${DdeControlCenter_LIBRARIES} ${DFrameworkDBus_LIBRARIES} diff --git a/plugins/onboard/onboardplugin.cpp b/plugins/onboard/onboardplugin.cpp index 72d890ca5..f5838690f 100644 --- a/plugins/onboard/onboardplugin.cpp +++ b/plugins/onboard/onboardplugin.cpp @@ -94,6 +94,8 @@ const QString OnboardPlugin::itemCommand(const QString &itemKey) const QString OnboardPlugin::itemContextMenu(const QString &itemKey) { + Q_UNUSED(itemKey); + QList items; QMap onboardSettings; diff --git a/plugins/shutdown/shutdownplugin.cpp b/plugins/shutdown/shutdownplugin.cpp index 606ec1b9b..113344ded 100644 --- a/plugins/shutdown/shutdownplugin.cpp +++ b/plugins/shutdown/shutdownplugin.cpp @@ -116,6 +116,8 @@ const QString ShutdownPlugin::itemCommand(const QString &itemKey) const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) { + Q_UNUSED(itemKey); + QList items; items.reserve(6); diff --git a/plugins/tray/fashiontray/containers/attentioncontainer.cpp b/plugins/tray/fashiontray/containers/attentioncontainer.cpp index 756a4f92c..392c84406 100644 --- a/plugins/tray/fashiontray/containers/attentioncontainer.cpp +++ b/plugins/tray/fashiontray/containers/attentioncontainer.cpp @@ -17,6 +17,8 @@ FashionTrayWidgetWrapper *AttentionContainer::takeAttentionWrapper() bool AttentionContainer::acceptWrapper(FashionTrayWidgetWrapper *wrapper) { + Q_UNUSED(wrapper); + return true; } diff --git a/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp b/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp index 2238f559c..8f7ca282b 100644 --- a/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp +++ b/plugins/tray/fashiontray/fashiontraycontrolwidget.cpp @@ -81,6 +81,8 @@ void FashionTrayControlWidget::setExpanded(const bool &expanded) void FashionTrayControlWidget::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); diff --git a/plugins/tray/fashiontray/fashiontrayitem.cpp b/plugins/tray/fashiontray/fashiontrayitem.cpp index 10d0d25df..00f6379dc 100644 --- a/plugins/tray/fashiontray/fashiontrayitem.cpp +++ b/plugins/tray/fashiontray/fashiontrayitem.cpp @@ -183,6 +183,7 @@ void FashionTrayItem::onExpandChanged(const bool expand) void FashionTrayItem::setRightSplitVisible(const bool visible) { + Q_UNUSED(visible); } void FashionTrayItem::onPluginSettingsChanged() diff --git a/plugins/tray/trayplugin.cpp b/plugins/tray/trayplugin.cpp index 59b38a5ab..7915ba4f9 100644 --- a/plugins/tray/trayplugin.cpp +++ b/plugins/tray/trayplugin.cpp @@ -134,6 +134,8 @@ bool TrayPlugin::pluginIsDisable() void TrayPlugin::displayModeChanged(const Dock::DisplayMode mode) { + Q_UNUSED(mode); + if (pluginIsDisable()) { return; }