diff --git a/CMakeLists.txt b/CMakeLists.txt index 09a0b8953..aeb170938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,37 @@ # 定义需要的cmake版本 -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16.0) -# 设置cmake参数 -set(CMAKE_CXX_STANDARD 14) +# 设置工程名字 +project(deepin-draw) + +# 设置CMake参数 +set(CMAKE_CXX_STANDARD 17) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wl,--as-needed -fPIE") +set(QT_MINIMUM_VERSION "6.0.0") +set(CMAKE_EXE_LINKER_FLAGS "-pie") -# 设置工程名字 -project(deepin-draw) +# 查找Qt库 +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core Widgets Gui DBus Xml Svg Test) +message("Using Qt version: ${QT_VERSION_MAJOR}") + +# 选择DTK版本 +if(QT_VERSION_MAJOR EQUAL "6") + set(BUILD_WITH_QT6 ON) + set(DTK_VERSION_MAJOR 6) +else() + set(DTK_VERSION_MAJOR "") +endif() +message("Using dtk version: ${DTK_VERSION_MAJOR}") + +# 查找DTK库 +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget Gui Core) + +# 包含目录 +include_directories(${DtkWidget_INCLUDE_DIRS} ${DtkGui_INCLUDE_DIRS} ${DtkCore_INCLUDE_DIRS}) # 是否开启单元测试编译 option(DEEPINDRAW_TEST "only compile and generate deepin-draw-test program." OFF) @@ -62,3 +84,22 @@ if(DEEPINDRAW_LOAD_TOOL_PLUGINS AND NOT DEEPINDRAW_LINK_DRAWBASELIB_STATIC) add_subdirectory(deepin-draw-plugins) endif() +# 设置链接库 +set(LINK_LIBS + Qt6::Core + Qt6::DBus + Qt6::Widgets + Qt6::Xml + Qt6::Svg + Qt6::Test + Qt6::SvgWidgets + Dtk${DTK_VERSION_MAJOR}::Widget + Dtk${DTK_VERSION_MAJOR}::Gui + Dtk${DTK_VERSION_MAJOR}::Core + ${DFrameworkDBus_LIBRARIES} +) + +# 安装目标 +install(TARGETS deepin-draw DESTINATION ${CMAKE_INSTALL_BINDIR}) +file(GLOB QM_FILES "${CMAKE_CURRENT_LIST_DIR}/translations/*.qm") + diff --git a/debian/control b/debian/control index 575ccdf9d..f58a667ff 100644 --- a/debian/control +++ b/debian/control @@ -5,19 +5,21 @@ Maintainer: Deepin Packages Builder Build-Depends: debhelper, cmake, - qtbase5-dev, + qt6-base-dev, pkg-config, libexif-dev, - libqt5svg5-dev, libraw-dev, libfreeimage-dev, - libqt5opengl5-dev, - libdtkgui-dev, - qttools5-dev, - qttools5-dev-tools, - libdtkwidget-dev, + libqt6opengl6, + libdtk6gui-dev, + qt6-svg-dev, + qt6-tools-dev, + qt6-tools-dev-tools, + libdtk6widget-dev, + libdtk6gui-dev, + libdtk6core-dev, libxcb-util0-dev, - libdtkcore5-bin, + libdtk6core-bin, libgtest-dev, libgmock-dev Standards-Version: 3.9.8 @@ -25,7 +27,7 @@ Homepage: http://www.deepin.org Package: deepin-draw Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, qt5-image-formats-plugins, deepin-picker-cli +Depends: ${shlibs:Depends}, ${misc:Depends}, qt6-image-formats-plugins, deepin-picker-cli Description: Draw for UOS Draw is a lightweight drawing tool for users to freely draw and simply edit images. Recommends: uos-reporter, deepin-event-log, kimageformat-plugins diff --git a/debian/rules b/debian/rules index f79188157..3f61bb38d 100755 --- a/debian/rules +++ b/debian/rules @@ -1,6 +1,6 @@ #!/usr/bin/make -f include /usr/share/dpkg/default.mk -export QT_SELECT=5 +export QT_SELECT=qt6 DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) %: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 126a123ac..e3e16b84a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,20 +1,24 @@ # 定义需要的cmake版本 -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) +# 设置基础库名称为 "deepinDrawBase",并将其存储在缓存中 SET(BASE_LIB "deepinDrawBase" CACHE STRING INTERNAL FORCE) # 设置cmake参数 -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -#set complier/link flags +set(CMAKE_CXX_STANDARD 17) # 设置C++标准为C++14 +set(CMAKE_INCLUDE_CURRENT_DIR ON) # 包含当前目录 +set(CMAKE_AUTOMOC ON) # 自动处理moc文件 +set(CMAKE_AUTORCC ON) # 自动处理rcc文件 +set(CMAKE_AUTOUIC ON) # 自动处理uic文件 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wl,--as-needed -fPIE") # 设置C++编译标志,启用调试信息和警告 +set(QT_MINIMUM_VERSION "6.0.0") # 定义Qt的最低版本为6.0.0 +set(CMAKE_EXE_LINKER_FLAGS "-pie") # 设置可执行文件的链接标志 + +# 设置编译器/链接器标志 if(DEEPINDRAW_TEST) message(DEEPINDRAW_TESTDEEPINDRAW_TESTDEEPINDRAW_TESTDEEPINDRAW_TEST) - #0.DEEPINDRAW_TEST mean that we should creat the lib that can get cover info - #mips not suport -fsanitize + # 如果定义了DEEPINDRAW_TEST,表示需要创建可以获取覆盖信息的库 + # mips不支持-fsanitize if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64") set(CMAKE_CXX_FLAGS "-g -O1 -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "-g -O1 -fprofile-arcs -ftest-coverage") @@ -26,13 +30,13 @@ if(DEEPINDRAW_TEST) set(CMAKE_L_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer -g -O1 -fprofile-arcs -ftest-coverage -lgcov") endif() else() - #1.no DEEPINDRAW_TEST mean that we just need one clearly lib(not include -ftest-coverage or -fsanitize) + # 如果没有定义DEEPINDRAW_TEST,表示只需要一个不包含-fsanitize或-ftest-coverage的清晰库 if(CMAKE_BUILD_TYPE MATCHES "Debug") - #DEBUG时不做优化方便调试 + # 在DEBUG模式下不进行优化以方便调试 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") else() - #加速编译优化参数 + # 加速编译优化参数 if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wl,-O1 -Wl,--as-needed -Wl,-E -fPIE -ffunction-sections -fdata-sections -Wl,--gc-sections -ftree-vectorize -march=loongson3a -mhard-float -mno-micromips -mno-mips16 -flax-vector-conversions -mloongson-ext2 -mloongson-mmi") @@ -44,7 +48,7 @@ else() endif() endif() - #2.sometime we also want to test deepin-draw memery info + # 有时我们也想测试deepin-draw的内存信息 if(DEEPINDRAW_SANITIZERS) set(CMAKE_CXX_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer") set(CMAKE_C_FLAGS "-fsanitize=undefined,address,leak -fno-omit-frame-pointer") @@ -52,13 +56,35 @@ else() endif() # 设置Qt模块 -set(QtModule Core Gui Widgets DBus PrintSupport Svg Concurrent LinguistTools) +set(QtModule Core Gui Widgets DBus PrintSupport Svg SvgWidgets Concurrent LinguistTools) +# 查找Qt相关的库链接 先默认qt6 +find_package(Qt6 REQUIRED COMPONENTS ${QtModule}) + +#选择DTK版本 +if(QT_VERSION_MAJOR EQUAL "6") # 如果Qt版本为6 + set(BUILD_WITH_QT6 ON) # 启用Qt6构建 + set(DTK_VERSION_MAJOR 6) # 设置DTK版本为6 +else() + set(DTK_VERSION_MAJOR "") # 否则不设置DTK版本 +endif() +message("Testing Using dtk version: ${DTK_VERSION_MAJOR}") # 输出使用的DTK版本 -# 查找Qt相关的库链接 -find_package(Qt5 REQUIRED ${QtModule}) +# 打印每个Qt模块的设置情况及其路径 +message(STATUS "Qt Module: Core, Path: ${Qt6Core_DIR}") +message(STATUS "Qt Module: Gui, Path: ${Qt6Gui_DIR}") +message(STATUS "Qt Module: Widgets, Path: ${Qt6Widgets_DIR}") +message(STATUS "Qt Module: DBus, Path: ${Qt6DBus_DIR}") +message(STATUS "Qt Module: PrintSupport, Path: ${Qt6PrintSupport_DIR}") +message(STATUS "Qt Module: Svg, Path: ${Qt6Svg_DIR}") +message(STATUS "Qt Module: Qt6SvgWidgets, Path: ${Qt6SvgWidgets_DIR}") +message(STATUS "Qt Module: Concurrent, Path: ${Qt6Concurrent_DIR}") +message(STATUS "Qt Module: LinguistTools, Path: ${Qt6LinguistTools_DIR}") + +# 配置文件,将config.h.in转换为config.h configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY) +# 定义源码目录 set(SRCDIRS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/drawshape @@ -87,51 +113,98 @@ FILE (GLOB allSource ${SRC_CPPS}) FILE (GLOB allHeaders ${SRC_HEADERS}) FILE (GLOB allQrcs ${SRC_QRCS}) +# 查找翻译文件 FILE(GLOB targetTsFiles ../translations/*.ts) -# 创建翻译文件(将源文件${allSource} ${allHeaders}关联上${targetTsFiles}的ts文件 然后生成${tragetQmFiles}的qm文件) -qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles}) -#qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles} OPTIONS -no-obsolete) +# 创建翻译文件,将源文件与ts文件关联生成qm文件 +#qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles}) +# qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles} OPTIONS -no-obsolete) + +# TODO 暂时先默认使用qt6_create_translation +qt6_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles}) + +# if(QT_MAJOR_VERSION EQUAL 6) +# qt6_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles}) +# else() +# qt5_create_translation(tragetQmFiles ${allSource} ${allHeaders} ${targetTsFiles}) +# endif() # 设置不删除生成的文件夹内容文件(设置此项是为了翻译后的文件不被删除) set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1) -qt5_add_resources(RESOURCE_ADDED ${allQrcs}) +# TODO:添加资源文件 +qt6_add_resources(RESOURCE_ADDED ${allQrcs}) + +# if(QT_MAJOR_VERSION EQUAL 6) +# qt6_add_resources(RESOURCE_ADDED ${allQrcs}) +# else() +# qt5_add_resources(RESOURCE_ADDED ${allQrcs}) +# endif() + +# 根据条件选择创建静态库或共享库 if(DEEPINDRAW_LINK_DRAWBASELIB_STATIC) add_library(${BASE_LIB} STATIC ${allSource} ${allHeaders} ${RESOURCE_ADDED} ${tragetQmFiles}) else() add_library(${BASE_LIB} SHARED ${allSource} ${allHeaders} ${RESOURCE_ADDED} ${tragetQmFiles}) endif() +# 设置目标属性 set_target_properties(${BASE_LIB} PROPERTIES VERSION 0.0 SOVERSION 0 PUBLIC_HEADER "${allHeaders}") -# Find includes in corresponding build directories +# 在相应的构建目录中查找包含文件 set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories(${PROJECT_BINARY_DIR}) include_directories(${PROJECT_SOURCE_DIR}) -#------------------------------ 添加第三方库 DTK ------------------------------- +# 添加第三方库 DTK # 使用第三方库需要用到的一个包 find_package(PkgConfig REQUIRED) # 检查第三方库(这里检查了名字为dtkwidget的库和名字为dtkgui的库),然后取名3RMODULES pkg_check_modules(3RMODULES REQUIRED - dtkwidget dtkgui dtkcore + dtk6widget dtk6gui dtk6core ) + +# 添加调试信息 +message(STATUS "DTK Widget Include Dirs: ${3RMODULES_INCLUDE_DIRS}") +message(STATUS "DTK Libraries: ${3RMODULES_LIBRARIES}") +message(STATUS "DTK Library Dirs: ${3RMODULES_LIBRARY_DIRS}") + # 添加第三方库的所有文件夹路径到工程中来(注意 *_INCLUDE_DIRS) target_include_directories(${BASE_LIB} PUBLIC ${3RMODULES_INCLUDE_DIRS}) target_link_libraries(${BASE_LIB} ${3RMODULES_LIBRARIES} ${CMAKE_DL_LIBS}) -#------------------------------添加第三方库end------------------------------------- - # 将工程与Qt模块链接起来 -qt5_use_modules(${BASE_LIB} ${QtModule}) - -# ------------------------------- install script ------------------------------- +# if(QT_MAJOR_VERSION EQUAL 6) +# foreach(module ${QtModule}) +# target_link_libraries(${BASE_LIB} Qt6::${module}) +# endforeach() +# message(STATUS "QtModule contents qt6: ${QtModule}") +# else() +# qt5_use_modules(${BASE_LIB} ${QtModule}) +# message(STATUS "QtModule contents qt5: ${QtModule}") +# endif() +# 设置链接库 +set(LINK_LIBS + Qt6::Core + Qt6::DBus + Qt6::Widgets + Qt6::PrintSupport + Qt6::Svg + Qt6::Concurrent + Dtk6::Widget + Dtk6::Gui + Dtk6::Core +) + +# 替换原来的 if-else 链接逻辑 +target_link_libraries(${BASE_LIB} ${LINK_LIBS}) + +# 安装脚本 set(DbusDir ${CMAKE_INSTALL_DATADIR}/dbus-1/services/) set(DesktopDir ${CMAKE_INSTALL_DATADIR}/applications/) set(ManIconDir ${CMAKE_INSTALL_DATADIR}/icons/deepin/apps/scalable) @@ -140,6 +213,7 @@ set(MimeFileDir ${CMAKE_INSTALL_DATADIR}/mime/packages) set(MimeTypeDir ${CMAKE_INSTALL_DATADIR}/application) set(HelpFileDir ${CMAKE_INSTALL_DATADIR}/deepin-manual/manual-assets/application) +# 如果不是静态链接库,安装库文件 if(NOT DEEPINDRAW_LINK_DRAWBASELIB_STATIC) install(TARGETS ${BASE_LIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -147,14 +221,14 @@ if(NOT DEEPINDRAW_LINK_DRAWBASELIB_STATIC) PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) endif() -# install Translation files: +# 安装翻译文件 install(FILES ${tragetQmFiles} DESTINATION ${TranslationDir}) -# install Manual icon +# 安装手册图标 install(FILES ./logo/deepin-draw.svg DESTINATION ${ManIconDir}) -# install App icon +# 安装应用图标 install(FILES ./logo/deepin-draw.svg DESTINATION ${AppIconDir}) +# 添加子目录 add_subdirectory(deepin-draw) - diff --git a/src/application.cpp b/src/application.cpp index 623edb6d4..bce8a706f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -25,13 +25,17 @@ #include #include #include -#include #include #include +#include + +#if (QT_MAJOR_VERSION == 5) #include +#elif (QT_MAJOR_VERSION == 6) +#include +#endif #include -#include #include #include @@ -40,7 +44,7 @@ #include #include -#include +#include #include "config.h" @@ -149,7 +153,7 @@ int Application::execDraw(const QStringList &paths) } // 应用已保存的主题设置 - DApplicationSettings saveTheme; + //DApplicationSettings saveTheme; showMainWindow(paths); @@ -342,11 +346,9 @@ bool Application::isWaylandPlatform() QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE")); QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY")); - if (XDG_SESSION_TYPE != QLatin1String("wayland") && - !WAYLAND_DISPLAY.contains(QLatin1String("wayland"), - Qt::CaseInsensitive)) { + if (XDG_SESSION_TYPE != QLatin1String("wayland") + && !WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) { return false; - } return true; } @@ -413,33 +415,51 @@ bool Application::isFileNameLegal(const QString &path, int *outErrorReson) return false; } - QRegExp regExp("[:\\*\\?\"<>\\|]"); + QRegularExpression regExp("[:\\*\\?\"<>\\|]"); if (path.contains(regExp)) { - if (outErrorReson != nullptr) { - *outErrorReson = 1; + *outErrorReson = 1; } return false; } - QRegExp splitExp("[/\\\\]"); - - int pos = splitExp.indexIn(path, 0); + QRegularExpression splitExp("[/\\\\]"); +//Qt5: 使用 indexIn 方法来查找匹配项。 +//Qt6: 使用 QRegularExpressionMatchIterator 来遍历所有匹配项。 +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + int pos = splitExp.indexIn(path); while (pos != -1) { QString dirStr = path.left(pos + 1); if (dirStr.count() > 1) { QDir dir(dirStr); if (!dir.exists()) { if (outErrorReson != nullptr) { - *outErrorReson = 2; + *outErrorReson = 2; } return false; } } pos = splitExp.indexIn(path, pos + 1); } +#else + QRegularExpressionMatchIterator it = splitExp.globalMatch(path); + while (it.hasNext()) { + QRegularExpressionMatch match = it.next(); + int pos = match.capturedStart(); + QString dirStr = path.left(pos + 1); + if (dirStr.count() > 1) { + QDir dir(dirStr); + if (!dir.exists()) { + if (outErrorReson != nullptr) { + *outErrorReson = 2; + } + return false; + } + } + } +#endif bool isdir = (path.endsWith('/') || path.endsWith('\\')); return !isdir; @@ -767,8 +787,16 @@ void Application::readSettings() if (!opened) { //Dtk::Widget::moveToCenter(this); //修复初次装机,画板不能还原窗口 + int w; + int h; +#if (QT_MAJOR_VERSION == 5) int w = dApp->desktop()->screenGeometry().width() / 2; - int h = dApp->desktop()->screenGeometry().height() / 2 ; + int h = dApp->desktop()->screenGeometry().height() / 2; +#elif (QT_MAJOR_VERSION == 6) + QScreen *screen = dApp->primaryScreen(); + int w = screen->geometry().width() / 2; + int h = screen->geometry().height() / 2; +#endif actWin->resize(w, h); actWin->showMaximized(); } else { diff --git a/src/deepin-draw/CMakeLists.txt b/src/deepin-draw/CMakeLists.txt index 284398963..982689fc7 100644 --- a/src/deepin-draw/CMakeLists.txt +++ b/src/deepin-draw/CMakeLists.txt @@ -17,9 +17,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${3RMODULES_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${3RMODULES_LIBRARIES} ${CMAKE_DL_LIBS} ${BASE_LIB}) -# 将工程与Qt模块链接起来 -qt5_use_modules(${PROJECT_NAME} ${QtModule}) - install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/src/deepin-draw/main.cpp b/src/deepin-draw/main.cpp index 2adb3c539..76713a800 100644 --- a/src/deepin-draw/main.cpp +++ b/src/deepin-draw/main.cpp @@ -8,8 +8,11 @@ #include "frame/ccentralwidget.h" #include -#include +#if (QT_MAJOR_VERSION == 5) +// qt6中已经自动设置了,所以不需要再设置 +#include +#endif #include #include #include diff --git a/src/drawshape/cdrawparamsigleton.cpp b/src/drawshape/cdrawparamsigleton.cpp index 7c8804713..6c8c8b704 100644 --- a/src/drawshape/cdrawparamsigleton.cpp +++ b/src/drawshape/cdrawparamsigleton.cpp @@ -7,7 +7,13 @@ #include #include #include + +#if (QT_MAJOR_VERSION == 5) #include +#elif (QT_MAJOR_VERSION == 6) +#include +#endif + #include #include "frame/cviewmanagement.h" @@ -58,11 +64,20 @@ PageContext::PageContext(const QString &file, QObject *parent): QObject(parent), //设置scene大小为屏幕分辨率 //获取屏幕分辨率 + QRect screenRect; +#if (QT_MAJOR_VERSION == 5) QDesktopWidget *desktopWidget = QApplication::desktop(); QRect screenRect = desktopWidget->screenGeometry(); //需要乘以系统缩放系数才是最终的大小 screenRect = QRect(0, 0, qRound(screenRect.width() * desktopWidget->devicePixelRatioF()), - qRound(screenRect.height() * desktopWidget->devicePixelRatioF())); + qRound(screenRect.height() * desktopWidget->devicePixelRatioF())); +#elif (QT_MAJOR_VERSION == 6) + QScreen *screen = QGuiApplication::primaryScreen(); + QRect screenRect = screen->geometry(); + //需要乘以系统缩放系数才是最终的大小 + screenRect = QRect(0, 0, qRound(screenRect.width() * screen->devicePixelRatio()), + qRound(screenRect.height() * screen->devicePixelRatio())); +#endif this->setPageRect(screenRect); } diff --git a/src/drawshape/cdrawscene.cpp b/src/drawshape/cdrawscene.cpp index 78ec42f81..2f4084079 100644 --- a/src/drawshape/cdrawscene.cpp +++ b/src/drawshape/cdrawscene.cpp @@ -41,6 +41,7 @@ #include #include #include +#include DWIDGET_USE_NAMESPACE diff --git a/src/drawshape/drawItems/bzItems/cgraphicsitem.cpp b/src/drawshape/drawItems/bzItems/cgraphicsitem.cpp index 0e33eb0da..9da2f3a09 100644 --- a/src/drawshape/drawItems/bzItems/cgraphicsitem.cpp +++ b/src/drawshape/drawItems/bzItems/cgraphicsitem.cpp @@ -1039,23 +1039,20 @@ void CGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt endCheckIns(painter); } else { - QTime *time = nullptr; + QElapsedTimer timer; // 使用QElapsedTimer替代QTime if (_autoCache) { - time = new QTime; - time->start(); + timer.start(); // 开始计时 } //绘制图元 paintItemSelf(painter, option, EPaintForNoCache); if (_autoCache) { - int elp = time->elapsed(); + int elp = timer.elapsed(); // 获取经过的时间 this->setCache(elp > _autoEplMs); - delete time; } } } - void CGraphicsItem::paintItemSelf(QPainter *painter, const QStyleOptionGraphicsItem *option, EPaintReson paintReson) { diff --git a/src/drawshape/drawItems/csizehandlerect.cpp b/src/drawshape/drawItems/csizehandlerect.cpp index ad88253f5..9b9c36217 100644 --- a/src/drawshape/drawItems/csizehandlerect.cpp +++ b/src/drawshape/drawItems/csizehandlerect.cpp @@ -20,8 +20,9 @@ #include #include +//TODO: 这一块没做qt5兼容,先备注下,后续会补充上 CSizeHandleRect::CSizeHandleRect(QGraphicsItem *parent, EDirection d) - : QGraphicsSvgItem(parent) + : QGraphicsItem(parent) // 修改为 QGraphicsItem , m_dir(d) , m_state(SelectionHandleOff) , m_bVisible(true) @@ -31,21 +32,16 @@ CSizeHandleRect::CSizeHandleRect(QGraphicsItem *parent, EDirection d) { setParentItem(parent); setCacheMode(NoCache); - setSharedRenderer(&m_lightRenderer); + // setSharedRenderer(&m_lightRenderer); // 如果不再使用 QGraphicsSvgItem,这行可以移除 //hide(); setFlag(ItemIsSelectable, false); setFlag(ItemIsMovable, false); - setCursor(getCursor()); } -CSizeHandleRect::CSizeHandleRect(QGraphicsItem *parent, CSizeHandleRect::EDirection d, const QString &filename) - : QGraphicsSvgItem(filename, parent) - , m_dir(d) - , m_state(SelectionHandleOff) - , m_bVisible(true) - , m_isRotation(true) +CSizeHandleRect::CSizeHandleRect(QGraphicsItem *parent, EDirection d, const QString &filename) + : QGraphicsItem(parent), m_dir(d), m_state(SelectionHandleOff), m_bVisible(true), m_isRotation(true) { setParentItem(parent); setCacheMode(NoCache); @@ -82,18 +78,32 @@ void CSizeHandleRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *o if (isFatherDragging()) return; + //在Qt6中,QGraphicsSvgItem的renderer()方法已经被移除。在Qt5中,renderer()方法是可用的,因此需要分别处理。 + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (!m_isRotation) { if (renderer() != &m_lightRenderer) { setSharedRenderer(&m_lightRenderer); } } + #else + // Qt6 处理逻辑 + if (!m_isRotation) { + //// 在Qt6中直接使用m_lightRenderer进行绘制 + m_lightRenderer.render(painter, this->boundingRect()); + } + #endif painter->setClipping(false); QRectF rect = this->boundingRect(); + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) this->renderer()->render(painter, rect); - painter->setClipping(true); + #else + // 在Qt6中使用QSvgRenderer直接绘制 + m_lightRenderer.render(painter, rect); + #endif + painter->setClipping(true); } bool CSizeHandleRect::isFatherDragging() @@ -147,8 +157,18 @@ QRectF CSizeHandleRect::boundingRect() const if (curView() == nullptr) return QRectF(); - qreal scale = /*curView()->getDrawParam()->getScale()*/curView()->getScale(); - QRectF rect = QGraphicsSvgItem::boundingRect(); + qreal scale = curView()->getScale(); + QRectF rect; + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // Qt5 处理逻辑 + rect = QGraphicsSvgItem::boundingRect(); +#else + // Qt6 中使用 QSvgRenderer::viewBoxF() 方法。这将返回整个SVG的视图框矩形 + // TODO: 这里以后可能需要留意下,感觉可能会出ui BUG,目前没发现问题 + rect = m_lightRenderer.viewBoxF(); +#endif + rect.setWidth(rect.width() / scale); rect.setHeight(rect.height() / scale); return rect; @@ -176,31 +196,35 @@ QCursor CSizeHandleRect::getCursor() static QPixmap m_RightTopCursor; static QPixmap m_LeftRightCursor; static QPixmap m_UpDownCursor; + + // 仅初始化一次光标图像 if (!init) { qreal radio = qApp->devicePixelRatio(); + // 不同光标类型的SVG路径列表 QStringList srcList; - srcList << ":/theme/light/images/mouse_style/rotate_mouse.svg" << ":/theme/light/images/mouse_style/icon_drag_leftup.svg" - << ":/theme/light/images/mouse_style/icon_drag_rightup.svg" << ":/theme/light/images/mouse_style/icon_drag_left.svg" + srcList << ":/theme/light/images/mouse_style/rotate_mouse.svg" + << ":/theme/light/images/mouse_style/icon_drag_leftup.svg" + << ":/theme/light/images/mouse_style/icon_drag_rightup.svg" + << ":/theme/light/images/mouse_style/icon_drag_left.svg" << ":/theme/light/images/mouse_style/icon_drag_up.svg"; - QList memberCursors; - QSvgRenderer render; + + // 加载每个SVG并渲染为QPixmap for (int i = 0; i < srcList.size(); ++i) { auto srcPath = srcList.at(i); if (render.load(srcPath)) { QPixmap pix(QSize(24, 24) * radio); - //pix.setDevicePixelRatio(radio); - pix.fill(QColor(0, 0, 0, 0)); + pix.fill(QColor(0, 0, 0, 0)); // 透明背景 QPainter painter(&pix); render.render(&painter, QRect(QPoint(0, 0), pix.size())); memberCursors << pix; } } - // 判断数据边界 + // 如果所有光标都加载成功,则分配给静态变量 if (memberCursors.size() >= 5) { m_RotateCursor = memberCursors.at(0); m_LeftTopCursor = memberCursors.at(1); @@ -213,11 +237,20 @@ QCursor CSizeHandleRect::getCursor() } QCursor cursorResult(Qt::ArrowCursor); + + // Qt5 使用 QMatrix,Qt6 使用 QTransform +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QMatrix matrix; +#else + QTransform matrix; +#endif + + // 从父项获取旋转角度 CGraphicsItem *parent = dynamic_cast(parentItem()); qreal rotaAngle = (parent == nullptr ? 0 : parent->drawRotation()); matrix.rotate(rotaAngle); + // 根据方向确定光标类型并应用变换 switch (m_dir) { case Right: case Left: @@ -237,10 +270,13 @@ QCursor CSizeHandleRect::getCursor() break; case Rotation: { - cursorResult = m_RotateCursor; - //matrix.rotate(this->rotation()); - QPixmap pixmap = cursorResult.pixmap().transformed(matrix, Qt::SmoothTransformation); - cursorResult = QCursor(pixmap); + // 变换旋转光标并设置热点 + QPixmap pixmap = m_RotateCursor.transformed(matrix, Qt::SmoothTransformation); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + cursorResult = QCursor(pixmap); // Qt5: 直接使用QPixmap +#else + cursorResult = QCursor(pixmap, pixmap.width() / 2, pixmap.height() / 2); // Qt6: 指定热点 +#endif break; } default: diff --git a/src/drawshape/drawItems/csizehandlerect.h b/src/drawshape/drawItems/csizehandlerect.h index 0853bb327..f9942e65d 100644 --- a/src/drawshape/drawItems/csizehandlerect.h +++ b/src/drawshape/drawItems/csizehandlerect.h @@ -8,7 +8,14 @@ #include #include #include +//#include + +#if (QT_MAJOR_VERSION == 5) #include +#elif (QT_MAJOR_VERSION == 6) +#include +#endif + QT_BEGIN_NAMESPACE class QFocusEvent; @@ -26,7 +33,8 @@ enum ESelectionHandleState { SelectionHandleOff, SelectionHandleInactive, Select /** * @brief The CSizeHandleRect class 外接矩形类 */ -class CSizeHandleRect : public QGraphicsSvgItem +// TODO: 后续做qt5兼容处理,目前加了有问题 +class CSizeHandleRect : public QGraphicsItem { public: enum EDirection { LeftTop, Top, RightTop, Right, RightBottom, Bottom, LeftBottom, Left, Rotation, InRect, None}; @@ -45,12 +53,10 @@ class CSizeHandleRect : public QGraphicsSvgItem QRectF boundingRect() const override; void setVisible(bool flag); - void setJustExitLogicAbility(bool b); QCursor getCursor(); - static void getTransBlockFlag(EDirection dir, bool &blockX, bool &blockY); static void getTransNegtiveFlag(EDirection dir, bool &negtiveX, bool &negtiveY); static QPointF transCenter(EDirection dir, CGraphicsItem *pItem); @@ -59,7 +65,7 @@ class CSizeHandleRect : public QGraphicsSvgItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; bool isFatherDragging(); //如果为true不会进行绘制 - //void initCursor(); + //void initCursor(); private: const EDirection m_dir; @@ -71,9 +77,104 @@ class CSizeHandleRect : public QGraphicsSvgItem bool m_onlyLogicAblity = false; private: -// void initCursor(); + // void initCursor(); }; - - +// #if (QT_MAJOR_VERSION == 5) +// class CSizeHandleRect : public QGraphicsSvgItem +// { +// public: +// enum EDirection { LeftTop, Top, RightTop, Right, RightBottom, Bottom, LeftBottom, Left, Rotation, InRect, None}; + +// CSizeHandleRect(QGraphicsItem *parent, EDirection d); +// CSizeHandleRect(QGraphicsItem *parent, EDirection d, const QString &filename); + +// EDirection dir() const +// { +// return m_dir; +// } +// PageView *curView()const; +// void setState(ESelectionHandleState st); +// bool hitTest(const QPointF &point); +// void move(qreal x, qreal y); +// QRectF boundingRect() const override; +// void setVisible(bool flag); + + +// void setJustExitLogicAbility(bool b); + +// QCursor getCursor(); + + +// static void getTransBlockFlag(EDirection dir, bool &blockX, bool &blockY); +// static void getTransNegtiveFlag(EDirection dir, bool &negtiveX, bool &negtiveY); +// static QPointF transCenter(EDirection dir, CGraphicsItem *pItem); + +// protected: +// void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; +// bool isFatherDragging(); //如果为true不会进行绘制 + +// //void initCursor(); + +// private: +// const EDirection m_dir; +// ESelectionHandleState m_state; +// bool m_bVisible; //是否显示 true 显示 false不显示 +// QSvgRenderer m_lightRenderer; +// QSvgRenderer m_darkRenderer; +// bool m_isRotation; +// bool m_onlyLogicAblity = false; + +// private: +// // void initCursor(); +// }; +// #elif (QT_MAJOR_VERSION == 6) +// class CSizeHandleRect : public QGraphicsItem +// { +// public: +// enum EDirection { LeftTop, Top, RightTop, Right, RightBottom, Bottom, LeftBottom, Left, Rotation, InRect, None}; + +// CSizeHandleRect(QGraphicsItem *parent, EDirection d); +// CSizeHandleRect(QGraphicsItem *parent, EDirection d, const QString &filename); + +// EDirection dir() const +// { +// return m_dir; +// } +// PageView *curView()const; +// void setState(ESelectionHandleState st); +// bool hitTest(const QPointF &point); +// void move(qreal x, qreal y); +// QRectF boundingRect() const override; +// void setVisible(bool flag); + + +// void setJustExitLogicAbility(bool b); + +// QCursor getCursor(); + + +// static void getTransBlockFlag(EDirection dir, bool &blockX, bool &blockY); +// static void getTransNegtiveFlag(EDirection dir, bool &negtiveX, bool &negtiveY); +// static QPointF transCenter(EDirection dir, CGraphicsItem *pItem); + +// protected: +// void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; +// bool isFatherDragging(); //如果为true不会进行绘制 + +// //void initCursor(); + +// private: +// const EDirection m_dir; +// ESelectionHandleState m_state; +// bool m_bVisible; //是否显示 true 显示 false不显示 +// QSvgRenderer m_lightRenderer; +// QSvgRenderer m_darkRenderer; +// bool m_isRotation; +// bool m_onlyLogicAblity = false; + +// private: +// // void initCursor(); +// }; +// #endif #endif // CSIZEHANDLERECT diff --git a/src/drawshape/drawTools/cmasicotool.cpp b/src/drawshape/drawTools/cmasicotool.cpp index ec128c569..1d94237c2 100644 --- a/src/drawshape/drawTools/cmasicotool.cpp +++ b/src/drawshape/drawTools/cmasicotool.cpp @@ -172,11 +172,14 @@ void IBlurTool::registerAttributionWidgets() // drawBoard()->setDrawAttribution(DrawAttribution::EBlurAttri, var, EChanged, false); // }); connect(pBlurWidget, &BlurWidget::blurEffectChanged, this, [ = ](const SBLurEffect & effect) { - - //drawBoard()->setDrawAttribution(DrawAttribution::BlurPenWidth, width, EChanged, false); - QVariant var; +#if (QT_MAJOR_VERSION == 5) + // Qt5 中使用 setValue 方法 var.setValue(effect); +#elif (QT_MAJOR_VERSION == 6) + // Qt6 中使用 fromValue 方法 + var = QVariant::fromValue(effect); +#endif drawBoard()->setDrawAttribution(DrawAttribution::EBlurAttri, var, EChanged, false); }); diff --git a/src/drawshape/drawTools/cpentool.cpp b/src/drawshape/drawTools/cpentool.cpp index 9b5fed5cf..1dd22488c 100644 --- a/src/drawshape/drawTools/cpentool.cpp +++ b/src/drawshape/drawTools/cpentool.cpp @@ -90,7 +90,11 @@ void CPenTool::registerAttributionWidgets() pStreakStartComboBox->addItem(QIcon::fromTheme("ddc_right_fill_arrow"), ""); streakBeginStyle->setComboBox(pStreakStartComboBox); - connect(pStreakStartComboBox, QOverload::of(&QComboBox::currentIndexChanged), streakBeginStyle, [ = ](int index) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + connect(pStreakStartComboBox, static_cast(&QComboBox::currentIndexChanged), streakBeginStyle, [ = ](int index) { +#else + connect(pStreakStartComboBox, &QComboBox::currentIndexChanged, streakBeginStyle, [ = ](int index) { +#endif drawBoard()->setDrawAttribution(EStreakBeginStyle, index); }); connect(drawBoard()->attributionWidget(), &CAttributeManagerWgt::updateWgt, streakBeginStyle, [ = ](QWidget * pWgt, const QVariant & var) { @@ -119,7 +123,11 @@ void CPenTool::registerAttributionWidgets() pStreakEndComboBox->addItem(QIcon::fromTheme("ddc_left_fill_arrow"), ""); streakEndStyle->setComboBox(pStreakEndComboBox); - connect(pStreakEndComboBox, QOverload::of(&QComboBox::currentIndexChanged), streakEndStyle, [ = ](int index) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + connect(pStreakEndComboBox, static_cast(&QComboBox::currentIndexChanged), streakEndStyle, [ = ](int index) { +#else + connect(pStreakEndComboBox, &QComboBox::currentIndexChanged, streakEndStyle, [ = ](int index) { +#endif drawBoard()->setDrawAttribution(EStreakEndStyle, index); }); connect(drawBoard()->attributionWidget(), &CAttributeManagerWgt::updateWgt, streakEndStyle, [ = ](QWidget * pWgt, const QVariant & var) { @@ -153,7 +161,11 @@ void CPenTool::registerAttributionWidgets() penStyleWgt->setComboBox(m_pPenStyleComboBox); - connect(m_pPenStyleComboBox, QOverload::of(&QComboBox::currentIndexChanged), penStyleWgt, [ = ](int index) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + connect(m_pPenStyleComboBox, static_cast(&QComboBox::currentIndexChanged), penStyleWgt, [ = ](int index) { +#else + connect(m_pPenStyleComboBox, &QComboBox::currentIndexChanged, penStyleWgt, [ = ](int index) { +#endif emit drawApp->attributionsWgt()->attributionChanged(EPenStyle, index + 1); }); connect(drawApp->attributionsWgt(), &CAttributeManagerWgt::updateWgt, penStyleWgt, [ = ](QWidget * pWgt, const QVariant & var) { diff --git a/src/drawshape/drawTools/cselecttool.cpp b/src/drawshape/drawTools/cselecttool.cpp index 375293a02..8a39e7a18 100644 --- a/src/drawshape/drawTools/cselecttool.cpp +++ b/src/drawshape/drawTools/cselecttool.cpp @@ -49,7 +49,11 @@ CSelectTool::CSelectTool() { connect(this, &CSelectTool::boardChanged, this, [ = ](DrawBoard * old, DrawBoard * cur) { Q_UNUSED(old) +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + connect(cur, static_cast(&DrawBoard::currentPageChanged), this, [ = ](Page * cur) { +#else connect(cur, QOverload::of(&DrawBoard::currentPageChanged), this, [ = ](Page * cur) { +#endif Q_UNUSED(cur) _hightLight = QPainterPath(); }); @@ -456,7 +460,7 @@ void CSelectTool::drawMore(QPainter *painter, const QRectF &rect, PageScene *scene) { - //注意painter是在scene的坐标系 + // 注意painter是在scene的坐标系 Q_UNUSED(rect) painter->save(); @@ -492,12 +496,12 @@ void CSelectTool::drawMore(QPainter *painter, painter->setBrush(selectBrush); painter->drawRect(QRectF(topLeft, bomRight)); } else if (info._opeTpUpdate == ERotateMove) { - //功能:将旋转角度绘制到视口上 + // 功能:将旋转角度绘制到视口上 painter->save(); painter->setClipping(false); - //重置所有变换,从而保证绘制时是视口的坐标系 + // 重置所有变换,从而保证绘制时是视口的坐标系 painter->resetTransform(); QPoint posInView = scene->drawView()->viewport()->mapFromGlobal(QCursor::pos()); @@ -509,13 +513,25 @@ void CSelectTool::drawMore(QPainter *painter, QFont f; f.setPixelSize(14); + // 创建QFontMetrics对象以计算文本宽度 QFontMetrics fontMetrics(f); - int width = fontMetrics.width(angle) + 6; + int width; +#if (QT_MAJOR_VERSION == 5) + width = fontMetrics.width(angle) + 6; +#elif (QT_MAJOR_VERSION == 6) + width = fontMetrics.horizontalAdvance(angle) + 6; +#endif + QRectF rotateRect(paintPos, paintPos + QPointF(width, fontMetrics.height())); painter->setPen(Qt::NoPen); painter->setBrush(QColor("#E5E5E5")); + +#if (QT_MAJOR_VERSION == 5) painter->drawRoundRect(rotateRect); +#elif (QT_MAJOR_VERSION == 6) + painter->drawRoundedRect(rotateRect); +#endif painter->setFont(f); painter->setPen(Qt::black); painter->drawText(rotateRect, Qt::AlignCenter, angle); diff --git a/src/drawshape/drawTools/ctexttool.cpp b/src/drawshape/drawTools/ctexttool.cpp index db352cf04..3767c3a59 100644 --- a/src/drawshape/drawTools/ctexttool.cpp +++ b/src/drawshape/drawTools/ctexttool.cpp @@ -343,13 +343,19 @@ void CTextTool::initFontFamilyWidget(QComboBox *fontHeavy) } drawBoard()->attributionWidget()->installComAttributeWgt(EFontFamily, fontFamily, sourceHumFont); - connect(fontComboBox, QOverload::of(&QComboBox::activated), this, [ = ](const QString & family) { - Q_UNUSED(family) + // 连接当前索引变化信号,兼容Qt5和Qt6 + connect(fontComboBox, &QComboBox::currentIndexChanged, this, [ = ](int index) { + // 获取当前选中的字体 + QString family = fontComboBox->itemText(index); + // 标记为活动预览 _activePackup = true; }); - connect(fontComboBox, QOverload::of(&QComboBox::highlighted), this, [ = ](const QString & family) { - //预览的不用支持撤销还原 + // 连接当前索引变化信号,处理高亮显示的字体 + connect(fontComboBox, &QComboBox::currentIndexChanged, this, [ = ](int index) { + // 获取当前高亮的字体 + QString family = fontComboBox->itemText(index); + // 预览的不用支持撤销还原 if (_fontViewShowOut) { drawBoard()->setDrawAttribution(EFontFamily, family, EChanged, false); reInitFontWeightComboxItems(family, fontHeavy); @@ -448,53 +454,77 @@ void CTextTool::reInitFontWeightComboxItems(const QString &family, QComboBox *fo void CTextTool::initFontFontSizeWidget() { + // 获取属性管理小部件 auto attriMangerWgt = drawBoard()->attributionWidget(); - //文字字体大小设置控件 + // 创建字体大小设置控件 auto fontSize = new CComBoxSettingWgt(tr("Size")); - fontSize->setAttribution(EFontSize); + fontSize->setAttribution(EFontSize); // 设置属性类型为字体大小 auto ftSizeComboBox = new QComboBox; - ftSizeComboBox->setEditable(true); - ftSizeComboBox->setMinimumWidth(105); + ftSizeComboBox->setEditable(true); // 允许编辑 + ftSizeComboBox->setMinimumWidth(105); // 设置最小宽度 fontSize->setComboBox(ftSizeComboBox); - setWgtAccesibleName(fontSize->comboBox(), "Text font size comboBox"); + setWgtAccesibleName(fontSize->comboBox(), "Text font size comboBox"); // 设置可访问名称 + + // 添加默认字体大小选项 for (int i = 0; i < _defaultFontSizeSet.count(); ++i) { auto text = QString("%1px").arg(_defaultFontSizeSet[i]); ftSizeComboBox->addItem(text); } + + // 根据Qt版本选择合适的正则表达式和验证器 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QRegularExpression regx("[0-9]*p?x?"); + QValidator *validator = new QRegularExpressionValidator(regx, ftSizeComboBox); +#else QRegExp regx("[0-9]*p?x?"); QValidator *validator = new QRegExpValidator(regx, ftSizeComboBox); - ftSizeComboBox->setValidator(validator); +#endif + ftSizeComboBox->setValidator(validator); // 设置验证器 + + // 连接信号和槽,根据Qt版本选择合适的连接方式 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) connect(ftSizeComboBox, QOverload::of(&QComboBox::currentIndexChanged), fontSize, [ = ](const QString & fontSize) { - int size = QString(fontSize).remove("px").toInt(); - onSizeChanged(size, false); +#else + connect(ftSizeComboBox, &QComboBox::currentIndexChanged, fontSize, [ = ](int index) { + QString fontSize = ftSizeComboBox->itemText(index); // 获取当前字体大小 +#endif + int size = QString(fontSize).remove("px").toInt(); // 移除"px"并转换为整数 + onSizeChanged(size, false); // 调用onSizeChanged函数 }); + + // 连接编辑完成信号 connect(ftSizeComboBox->lineEdit(), &QLineEdit::editingFinished, fontSize, [ = ]() { int size = QString(ftSizeComboBox->currentText()).remove("px").toInt(); - onSizeChanged(size); + onSizeChanged(size); // 调用onSizeChanged函数 }); + // 连接属性管理器的更新信号 connect(attriMangerWgt, &CAttributeManagerWgt::updateWgt, fontSize, [ = ](QWidget * pWgt, const QVariant & var) { if (pWgt == fontSize) { - QSignalBlocker blocker(ftSizeComboBox); + QSignalBlocker blocker(ftSizeComboBox); // 阻止信号 QString text = (!var.isValid() || var.toInt() == 0) ? QStringLiteral("— —") : QString("%1px").arg(var.toInt()); - ftSizeComboBox->setCurrentText(text); - //修复两个标签页中文本字号一起改变 - _currenFontSize = var.toInt(); + ftSizeComboBox->setCurrentText(text); // 设置当前文本 + _currenFontSize = var.toInt(); // 更新当前字体大小 } }); + + // 安装属性小部件 drawBoard()->attributionWidget()->installComAttributeWgt(EFontSize, fontSize, _currenFontSize); + // 设置lineEdit为只读模式 ftSizeComboBox->lineEdit()->setReadOnly(Application::isTabletSystemEnvir()); - m_fontSize = ftSizeComboBox; + m_fontSize = ftSizeComboBox; // 保存指针 - //combox的lineedit控件编辑文字后不用添加新的item + // 设置插入策略为不插入 m_fontSize->setInsertPolicy(QComboBox::NoInsert); + // 安装事件过滤器 m_fontSize->view()->installEventFilter(this); m_fontSize->installEventFilter(this); + // 设置自定义委托 auto delegate = new QComboxMenuDelegate(m_fontSize->view(), m_fontSize); m_fontSize->setItemDelegate(delegate); } @@ -558,7 +588,7 @@ QStyleOptionMenuItem QComboxMenuDelegate::getStyleOption(const QStyleOptionViewI qvariant_cast(index.data(Qt::BackgroundRole))); } menuOption.text = index.model()->data(index, Qt::DisplayRole).toString() - .replace(QLatin1Char('&'), QLatin1String("&&")); + .replace(QLatin1Char('&'), QLatin1String("&&")); //menuOption.reservedShortcutWidth = 0; menuOption.maxIconWidth = option.decorationSize.width() + 4; menuOption.menuRect = option.rect; diff --git a/src/drawshape/drawTools/idrawtool.cpp b/src/drawshape/drawTools/idrawtool.cpp index 055003cd0..236861a63 100644 --- a/src/drawshape/drawTools/idrawtool.cpp +++ b/src/drawshape/drawTools/idrawtool.cpp @@ -277,8 +277,11 @@ void IDrawTool::toolDoStart(CDrawToolEvent *event) info._curEvent = *event; info._startEvent = *event; info._scene = event->scene(); - info.getTimeHandle()->restart(); - +#if (QT_MAJOR_VERSION == 5) + info.getTimeHandle()->restart(); +#elif (QT_MAJOR_VERSION == 6) + info.getTimeHandle()->start(); +#endif if (getCurVaildActivedPointCount() >= allowedMaxTouchPointCount()) { event->setAccepted(true); //超过可支持的点数了 @@ -363,19 +366,28 @@ void IDrawTool::toolDoUpdate(CDrawToolEvent *event) doDecide = !rectf.contains(event->pos(CDrawToolEvent::EViewportPos)); } } - if (doDecide) { - QTime *elTi = rInfo.getTimeHandle(); - rInfo._elapsedToUpdate = (elTi == nullptr ? -1 : elTi->elapsed()); - rInfo._opeTpUpdate = decideUpdate(event, &rInfo); - if (rInfo._opeTpUpdate > 0) { - sendToolEventToItem(event, &rInfo, EChangedBegin); - } + if (doDecide) { + // TODO: 这里需要注意下 + int elapsedTime = -1; +#if (QT_MAJOR_VERSION == 5) + QTime *elTi = rInfo.getTimeHandle(); + elapsedTime = elTi ? elTi->elapsed() : -1; +#elif (QT_MAJOR_VERSION == 6) + QElapsedTimer *elTi = rInfo.getTimeHandle(); + elapsedTime = elTi ? elTi->elapsed() : -1; +#endif + rInfo._elapsedToUpdate = elapsedTime; + rInfo._opeTpUpdate = decideUpdate(event, &rInfo); - rInfo.haveDecidedOperateType = true; - } else { - event->setPosXAccepted(false); - event->setPosYAccepted(false); + if (rInfo._opeTpUpdate > 0) { + sendToolEventToItem(event, &rInfo, EChangedBegin); + } + + rInfo.haveDecidedOperateType = true; + } else { + event->setPosXAccepted(false); + event->setPosYAccepted(false); } } } @@ -954,7 +966,15 @@ bool IDrawTool::ITERecordInfo::hasMoved() const return _moved; } + +#if (QT_MAJOR_VERSION == 5) QTime *IDrawTool::ITERecordInfo::getTimeHandle() { return &_elapsedToUpdateTimeHandle; } +#elif (QT_MAJOR_VERSION == 6) +QElapsedTimer *IDrawTool::ITERecordInfo::getTimeHandle() +{ + return &_elapsedToUpdateTimeHandle; +} +#endif diff --git a/src/drawshape/drawTools/idrawtool.h b/src/drawshape/drawTools/idrawtool.h index 8781303b1..2c5094527 100644 --- a/src/drawshape/drawTools/idrawtool.h +++ b/src/drawshape/drawTools/idrawtool.h @@ -5,8 +5,8 @@ #ifndef CDRAWTOOL_H #define CDRAWTOOL_H -#include "globaldefine.h" #include "csizehandlerect.h" +#include "globaldefine.h" #include "cattributeitemwidget.h" #include "idrawtoolevent.h" #include "ccentralwidget.h" @@ -15,13 +15,14 @@ #include #include #include +#include class QGraphicsSceneMouseEvent; class PageScene; class CGraphicsItem; class DrawBoard; using namespace DrawAttribution; - +class CSizeHandleRect; class IDrawTool: public QObject { Q_OBJECT @@ -367,10 +368,19 @@ class IDrawTool: public QObject bool isVaild() const; bool hasMoved() const; int elapsedFromStartToUpdate() const { return _elapsedToUpdate; } - inline QTime *getTimeHandle(); + +#if (QT_MAJOR_VERSION == 5) + inline QTime *getTimeHandle(); +#elif (QT_MAJOR_VERSION == 6) + inline QElapsedTimer *getTimeHandle(); +#endif - private: - QTime _elapsedToUpdateTimeHandle; +private: +#if (QT_MAJOR_VERSION == 5) + QTime _elapsedToUpdateTimeHandle; +#elif (QT_MAJOR_VERSION == 6) + QElapsedTimer _elapsedToUpdateTimeHandle; +#endif }; QMap _allITERecordInfo; diff --git a/src/frame/AttributesWidgets/private/blurwidget.cpp b/src/frame/AttributesWidgets/private/blurwidget.cpp index a9e132b46..0cffb4b12 100644 --- a/src/frame/AttributesWidgets/private/blurwidget.cpp +++ b/src/frame/AttributesWidgets/private/blurwidget.cpp @@ -112,7 +112,11 @@ void BlurWidget::initUI() m_TypeButtons->addButton(m_masicBtn, MasicoEffect); m_TypeButtons->setExclusive(true); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(m_TypeButtons, &QButtonGroup::idToggled, this, [ = ](int tp, bool checked) { +#else connect(m_TypeButtons, QOverload::of(&QButtonGroup::buttonToggled), this, [ = ](int tp, bool checked) { +#endif if (checked) { emit blurEffectChanged(getEffect()); } @@ -169,8 +173,15 @@ void BlurWidget::initUI() void BlurWidget::initConnection() { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(m_spinboxForLineWidth, &CSpinBox::valueChanged, this, + [ = ](int value, EChangedPhase phase) { + setBlurWidth(value); + }); +#else connect(m_spinboxForLineWidth, QOverload::of(&CSpinBox::valueChanged), this, [ = ](int value, EChangedPhase phase) { setBlurWidth(value); }); +#endif } diff --git a/src/frame/AttributesWidgets/private/calphacontrolwidget.cpp b/src/frame/AttributesWidgets/private/calphacontrolwidget.cpp index c118750ed..95f6d64dd 100644 --- a/src/frame/AttributesWidgets/private/calphacontrolwidget.cpp +++ b/src/frame/AttributesWidgets/private/calphacontrolwidget.cpp @@ -41,7 +41,7 @@ int CAlphaControlWidget::alpha() void CAlphaControlWidget::initUI() { QHBoxLayout *layout = new QHBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); DLabel *nameLabel = new DLabel(this); diff --git a/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp b/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp index 91ac47b4b..c7bdaeec9 100644 --- a/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp +++ b/src/frame/AttributesWidgets/private/cattributeitemwidget.cpp @@ -95,9 +95,14 @@ QSize DrawAttribution::CColorSettingButton::sizeHint() const QSize DrawAttribution::CColorSettingButton::minimumSizeHint() const { QFontMetrics metrics(this->font()); - QSize textSz(metrics.width(_text), metrics.height()); + QSize textSz; +#if (QT_MAJOR_VERSION == 5) + textSz = QSize(metrics.width(_text), metrics.height()); +#elif (QT_MAJOR_VERSION == 6) + textSz = QSize(metrics.horizontalAdvance(_text), metrics.height()); +#endif const int space = 6; - return QSize(_defaultButtonSize.width() + space + textSz.width(), qMax(_defaultButtonSize.height(), textSz.width())); + return QSize(_defaultButtonSize.width() + space + textSz.width(), qMax(_defaultButtonSize.height(), textSz.height())); } void DrawAttribution::CColorSettingButton::mousePressEvent(QMouseEvent *event) @@ -131,7 +136,12 @@ void DrawAttribution::CColorSettingButton::mousePressEvent(QMouseEvent *event) void DrawAttribution::CColorSettingButton::paintFillArea(QPainter *painter) { - QSize textSize = QSize(painter->fontMetrics().width(_text), painter->fontMetrics().height()); + QSize textSize; +#if (QT_MAJOR_VERSION == 5) + textSize = QSize(painter->fontMetrics().width(_text), painter->fontMetrics().height()); +#elif (QT_MAJOR_VERSION == 6) + textSize = QSize(painter->fontMetrics().horizontalAdvance(_text), painter->fontMetrics().height()); +#endif QRect buttonRct = QRect(QPoint(0, (height() - _defaultButtonSize.height()) / 2), QSize(_defaultButtonSize.width(), _defaultButtonSize.height())); QRect textRct(QPoint(buttonRct.right() + _space, (height() - textSize.height()) / 2), textSize); @@ -204,7 +214,12 @@ void DrawAttribution::CColorSettingButton::paintFillArea(QPainter *painter) void DrawAttribution::CColorSettingButton::paintFillBorder(QPainter *painter) { - QSize textSize = QSize(painter->fontMetrics().width(_text), painter->fontMetrics().height()); + QSize textSize; +#if (QT_MAJOR_VERSION == 5) + textSize = QSize(painter->fontMetrics().width(_text), painter->fontMetrics().height()); +#elif (QT_MAJOR_VERSION == 6) + textSize = QSize(painter->fontMetrics().horizontalAdvance(_text), painter->fontMetrics().height()); +#endif QRect buttonRct = QRect(QPoint(0, (height() - _defaultButtonSize.height()) / 2), QSize(_defaultButtonSize.width(), _defaultButtonSize.height())); QRect textRct(QPoint(buttonRct.right() + _space, (height() - textSize.height()) / 2), textSize); diff --git a/src/frame/AttributesWidgets/private/cattributemanagerwgt.cpp b/src/frame/AttributesWidgets/private/cattributemanagerwgt.cpp index 5bd32e5f4..c0f86341a 100644 --- a/src/frame/AttributesWidgets/private/cattributemanagerwgt.cpp +++ b/src/frame/AttributesWidgets/private/cattributemanagerwgt.cpp @@ -184,12 +184,30 @@ SAttrisList CAttributeManagerWgt::attributions() const void CAttributeManagerWgt::setAttributions(const SAttrisList &attribution) { - if (_sAttributions != attribution) { - //qWarning() << "_sAttributions = " << _sAttributions << "attribution = " << attribution; + // 检查大小是否相同 + if (_sAttributions.size() != attribution.size()) { + _sAttributions = attribution; + _dirty = 1; + if (this->isHidden()) + this->show(); + else + update(); + return; + } + + // 逐个比较元素 + bool isDifferent = false; + for (int i = 0; i < _sAttributions.size(); ++i) { + if (_sAttributions[i].attri != attribution[i].attri || + _sAttributions[i].var != attribution[i].var) { + isDifferent = true; + break; + } + } + if (isDifferent) { _sAttributions = attribution; _dirty = 1; - //ensureAttributions(); if (this->isHidden()) this->show(); else diff --git a/src/frame/AttributesWidgets/private/ccutwidget.cpp b/src/frame/AttributesWidgets/private/ccutwidget.cpp index 731fdfa3d..43586214b 100644 --- a/src/frame/AttributesWidgets/private/ccutwidget.cpp +++ b/src/frame/AttributesWidgets/private/ccutwidget.cpp @@ -19,7 +19,12 @@ #include #include #include + +#if (QT_MAJOR_VERSION == 5) #include +#elif (QT_MAJOR_VERSION == 6) +#include +#endif #include @@ -226,8 +231,15 @@ void CCutWidget::initUI() { _allWgts.clear(); m_sizeWidget = new QWidget(this); + bool withNotVarble; +#if (QT_MAJOR_VERSION == 5) QDesktopWidget *desktopWidget = dApp->desktop(); bool withNotVarble = desktopWidget->screenGeometry().width() < 1152; +#elif (QT_MAJOR_VERSION == 6) + QScreen *screen = QGuiApplication::primaryScreen(); + bool withNotVarble = screen->geometry().width() < 1152; +#endif + DLabel *sizeLabel = new DLabel(m_sizeWidget); sizeLabel->setText(tr("Dimensions")); QFont ft; @@ -490,7 +502,11 @@ void CCutWidget::initUI() void CCutWidget::initConnection() { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(m_scaleBtnGroup, &QButtonGroup::idToggled, +#else connect(m_scaleBtnGroup, QOverload::of(&QButtonGroup::buttonToggled), +#endif this, [ = ](int tp, bool checked) { if (checked) { //修复最小化后,编辑后因焦点问题引起的,尺寸修改失败问题 diff --git a/src/frame/AttributesWidgets/private/colorpanel.cpp b/src/frame/AttributesWidgets/private/colorpanel.cpp index 9ad2596c6..e6a209896 100644 --- a/src/frame/AttributesWidgets/private/colorpanel.cpp +++ b/src/frame/AttributesWidgets/private/colorpanel.cpp @@ -11,7 +11,11 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else #include +#endif #include "utils/global.h" #include "utils/baseutils.h" @@ -163,7 +167,11 @@ void ColorPanel::initUI() m_colLineEdit->setObjectName("ColorLineEdit"); m_colLineEdit->setFixedSize(180, 36); m_colLineEdit->setClearButtonEnabled(false); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + m_colLineEdit->lineEdit()->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9A-Fa-f]{6}"), this)); +#else m_colLineEdit->lineEdit()->setValidator(new QRegExpValidator(QRegExp("[0-9A-Fa-f]{6}"), this)); +#endif m_colLineEdit->setText("ffffff"); connect(m_colLineEdit, &DLineEdit::returnPressed, this, [ = ]() { this->parentColorWidget()->hide(); @@ -186,7 +194,7 @@ void ColorPanel::initUI() m_colorfulBtn->setFocusPolicy(Qt::NoFocus); QHBoxLayout *colorLayout = new QHBoxLayout(colorValueWidget); - colorLayout->setMargin(0); + colorLayout->setContentsMargins(0, 0, 0, 0); colorLayout->setSpacing(0); colorLayout->addWidget(colLabel); colorLayout->addSpacing(14); @@ -208,7 +216,7 @@ void ColorPanel::initUI() vLayout->addWidget(colorValueWidget, 0, Qt::AlignCenter); QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addWidget(colorBtnWidget); layout->addWidget(m_pickColWidget, 0, Qt::AlignCenter); @@ -219,7 +227,11 @@ void ColorPanel::initUI() void ColorPanel::initConnection() { //1.颜色按钮组 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(m_colorsButtonGroup, &QButtonGroup::buttonToggled, +#else connect(m_colorsButtonGroup, QOverload::of(&QButtonGroup::buttonToggled), +#endif this, [ = ](QAbstractButton * pBtn, bool checked) { ColorButton *pColorBtn = qobject_cast(pBtn); if (checked) { diff --git a/src/frame/AttributesWidgets/private/pickcolorwidget.cpp b/src/frame/AttributesWidgets/private/pickcolorwidget.cpp index 63ecabbe3..4f9f39c32 100644 --- a/src/frame/AttributesWidgets/private/pickcolorwidget.cpp +++ b/src/frame/AttributesWidgets/private/pickcolorwidget.cpp @@ -62,7 +62,7 @@ PickColorWidget::PickColorWidget(DWidget *parent) m_picker->setIcon(QIcon::fromTheme("dorpper_normal")); QHBoxLayout *rgbLayout = new QHBoxLayout; - rgbLayout->setMargin(0); + rgbLayout->setContentsMargins(0, 0, 0, 0); rgbLayout->setSpacing(0); rgbLayout->addWidget(titleLabel); rgbLayout->addSpacing(22); @@ -93,7 +93,7 @@ PickColorWidget::PickColorWidget(DWidget *parent) }); QVBoxLayout *mLayout = new QVBoxLayout; - mLayout->setMargin(0); + mLayout->setContentsMargins(0, 0, 0, 0); mLayout->setSpacing(0); mLayout->addLayout(rgbLayout); mLayout->addSpacing(10); diff --git a/src/frame/ccentralwidget.cpp b/src/frame/ccentralwidget.cpp index eaf4de41d..64568ae88 100644 --- a/src/frame/ccentralwidget.cpp +++ b/src/frame/ccentralwidget.cpp @@ -42,7 +42,7 @@ #include #include #include -#include + #include #include #include diff --git a/src/frame/cgraphicsview.cpp b/src/frame/cgraphicsview.cpp index 44fa5b4c8..3eebfc26a 100644 --- a/src/frame/cgraphicsview.cpp +++ b/src/frame/cgraphicsview.cpp @@ -49,7 +49,7 @@ #include #include #include -#include + #include #include #include @@ -264,14 +264,26 @@ void PageView::wheelEvent(QWheelEvent *event) gsEvent.setScreenPos(QCursor::pos()); gsEvent.setButtons(event->buttons()); gsEvent.setModifiers(event->modifiers()); +/* +在Qt 5中,继续使用delta()和orientation()。 +在Qt 6中,使用angleDelta().y()来获取滚动量,因为angleDelta()返回一个QPoint,其中y值表示垂直滚动量。 +*/ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) gsEvent.setDelta(event->delta()); gsEvent.setOrientation(event->orientation()); +#else + gsEvent.setDelta(event->angleDelta().y()); +#endif drawScene()->sendEvent(proxyItem, &gsEvent); return; } } PageView *pCurView = this; - int delayValue = event->delta(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + int delayValue = event->delta(); +#else + int delayValue = event->angleDelta().y(); +#endif if (pCurView != nullptr) { if (event->modifiers() == Qt::NoModifier) { //滚动view的垂直scrollbar @@ -288,7 +300,11 @@ void PageView::wheelEvent(QWheelEvent *event) return; //如果按住CTRL那么就是放大缩小 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (event->delta() > 0) { +#else + if (event->angleDelta().y() > 0) { +#endif pCurView->zoomOut(PageView::EMousePos); } else { pCurView->zoomIn(PageView::EMousePos); @@ -569,7 +585,7 @@ void PageView::initContextMenuConnection() qreal space_height = (scence_BR.height() - sum_items_height) / (allitems.size() - 1); - // [6] 按照y值进行移动位置 + // [6] 按照y值��行移动位置 for (int i = 1; i < allitems.size() - 1; i++) { startPos.insert(allitems.at(i), allitems.at(i)->sceneBoundingRect().topLeft()); QPointF endPoint(allitems.at(i)->sceneBoundingRect().left() @@ -611,7 +627,7 @@ void PageView::initContextMenuConnection() auto curScene = dynamic_cast(scene()); QRectF scence_BR = curScene->selectGroup()->sceneBoundingRect(); - // [5] 用于记录保存图元的位置,便于撤销和返回 + // [5] 用于记录保存图元的位置,便于撤销��返回 QMap startPos; QMap endPos; @@ -976,7 +992,7 @@ void PageView::slotOnPaste(bool textItemInCenter) } } } else { - qDebug() << "mp->hasImage()" << mp->hasImage() << endl; + qDebug() << "mp->hasImage()" << mp->hasImage() << Qt::endl; //粘贴画板内部图元 CShapeMimeData *data = qobject_cast(mp); @@ -1399,7 +1415,7 @@ void PageView::updateSelectedItemsAlignment(Qt::AlignmentFlag align) { CHECK_CURRENTTOOL_RETURN(this) - // 获取选择的组合中全部图元 + // 获取选择��组合中全部图元 auto curScene = dynamic_cast(scene()); QList allItems = curScene->selectGroup()->items(); @@ -1576,6 +1592,16 @@ void PageView::dragMoveEvent(QDragMoveEvent *event) QAbstractScrollArea::dragMoveEvent(event); } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +void PageView::enterEvent(QEnterEvent *event) +{ +// if (page()->currentTool_p() != nullptr && drawScene() != nullptr) { +// auto e = CDrawToolEvent::fromQEvent_single(event, drawScene()); +// page()->currentTool_p()->enterEvent(&e); +// } + QGraphicsView::enterEvent(event); +} +#else void PageView::enterEvent(QEvent *event) { // if (page()->currentTool_p() != nullptr && drawScene() != nullptr) { @@ -1584,6 +1610,7 @@ void PageView::enterEvent(QEvent *event) // } QGraphicsView::enterEvent(event); } +#endif void PageView::keyPressEvent(QKeyEvent *event) { diff --git a/src/frame/cgraphicsview.h b/src/frame/cgraphicsview.h index 827052111..83cf2e33b 100644 --- a/src/frame/cgraphicsview.h +++ b/src/frame/cgraphicsview.h @@ -226,7 +226,11 @@ class PageView : public DGraphicsView * @brief enterEvent 拖拽事件 * @param event */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + void enterEvent(QEnterEvent *event) override; +#else void enterEvent(QEvent *event) override; +#endif protected: void keyPressEvent(QKeyEvent *event)override; diff --git a/src/frame/clefttoolbar.cpp b/src/frame/clefttoolbar.cpp index f93b01f43..89c9e05ee 100644 --- a/src/frame/clefttoolbar.cpp +++ b/src/frame/clefttoolbar.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include DGUI_USE_NAMESPACE @@ -184,10 +184,18 @@ void DrawToolManager::mouseMoveEvent(QMouseEvent *event) Q_UNUSED(event) } + +#if (QT_MAJOR_VERSION == 5) void DrawToolManager::enterEvent(QEvent *event) { DWidget::enterEvent(event); } +#elif (QT_MAJOR_VERSION == 6) +void DrawToolManager::enterEvent(QEnterEvent *event) +{ + DWidget::enterEvent(event); +} +#endif void DrawToolManager::paintEvent(QPaintEvent *event) { @@ -199,7 +207,12 @@ void DrawToolManager::initUI() setWgtAccesibleName(this, "LeftTool bar"); //设置颜色 DPalette pa = this->palette(); + // TODO: dtk问题,在 Qt6 中,DPalette::Background已经被移除或重命名,用DPalette::Window做代替 +#if (QT_MAJOR_VERSION == 5) pa.setColor(DPalette::Background, DPalette::Base); +#elif (QT_MAJOR_VERSION == 6) + pa.setColor(DPalette::Window, DPalette::Base); +#endif this->setPalette(pa); this->setAutoFillBackground(true); @@ -212,7 +225,7 @@ void DrawToolManager::initUI() m_layout = new QVBoxLayout; m_layout->setSpacing(BTN_SPACING); - m_layout->setMargin(0); + m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setContentsMargins(14, 24, 0, 24); mainLayout->addLayout(m_layout); mainLayout->addStretch(); @@ -252,30 +265,17 @@ void DrawToolManager::initUI() void DrawToolManager::initDrawTools() { - //_tools = CDrawToolFactory::allTools(); toolButtonGroup = new QButtonGroup(this); -// for (auto it = _tools.begin(); it != _tools.end(); ++it) { - -// auto pTool = it.value(); -// auto button = pTool->toolButton(); -// button->setCheckable(true); -// toolButtonGroup->addButton(button, it.value()->getDrawToolMode()); -// m_layout->addWidget(button); - -// pTool->setParent(this); -// pTool->setDrawBoard(drawBoard()); -// connect(button, &QAbstractButton::toggled, button, [ = ](bool checked) { -// if (checked) { -// setCurrentTool(pTool->getDrawToolMode()); -// } -// }); -// } toolButtonGroup->setExclusive(true); - //setCurrentTool(selection); - +#if (QT_MAJOR_VERSION == 5) connect(toolButtonGroup, QOverload::of(&QButtonGroup::buttonClicked), this, [ = ](int id) { setCurrentTool(id); }); +#elif (QT_MAJOR_VERSION == 6) + connect(toolButtonGroup, &QButtonGroup::idClicked, this, [ = ](int id) { + setCurrentTool(id); + }); +#endif } diff --git a/src/frame/clefttoolbar.h b/src/frame/clefttoolbar.h index 453199bce..961c6e39f 100644 --- a/src/frame/clefttoolbar.h +++ b/src/frame/clefttoolbar.h @@ -50,7 +50,13 @@ class DrawToolManager : public DFrame protected: void mouseMoveEvent(QMouseEvent *event) override; + +#if (QT_MAJOR_VERSION == 5) void enterEvent(QEvent *event) override; //进入QWidget瞬间事件 +#elif (QT_MAJOR_VERSION == 6) + void enterEvent(QEnterEvent *event) override; //进入QWidget瞬间事件 +#endif + void paintEvent(QPaintEvent *event) override; private: diff --git a/src/frame/mainwindow.cpp b/src/frame/mainwindow.cpp index 5a13f9ceb..2a64f8dcb 100644 --- a/src/frame/mainwindow.cpp +++ b/src/frame/mainwindow.cpp @@ -32,7 +32,11 @@ #include #include #include + +#if (QT_MAJOR_VERSION == 5) #include +#endif + #include #include #include diff --git a/src/frame/toptoolbar.cpp b/src/frame/toptoolbar.cpp index 052313287..12e780778 100644 --- a/src/frame/toptoolbar.cpp +++ b/src/frame/toptoolbar.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -53,7 +53,7 @@ void TopTilte::initUI() initMenu(); QHBoxLayout *hLayout = new QHBoxLayout(this); - hLayout->setMargin(0); + hLayout->setContentsMargins(0, 0, 0, 0); hLayout->setSpacing(0); hLayout->addWidget(m_zoomMenuComboBox); @@ -335,12 +335,21 @@ void TopTilte::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } +#if (QT_MAJOR_VERSION == 5) void TopTilte::enterEvent(QEvent *event) { Q_UNUSED(event) //drawApp->setApplicationCursor(Qt::ArrowCursor); DFrame::enterEvent(event); } +#elif (QT_MAJOR_VERSION == 6) +void TopTilte::enterEvent(QEnterEvent *event) +{ + Q_UNUSED(event) + //drawApp->setApplicationCursor(Qt::ArrowCursor); + DFrame::enterEvent(event); +} +#endif void TopTilte::paintEvent(QPaintEvent *event) { diff --git a/src/frame/toptoolbar.h b/src/frame/toptoolbar.h index ec542900e..cc85fd498 100644 --- a/src/frame/toptoolbar.h +++ b/src/frame/toptoolbar.h @@ -131,7 +131,12 @@ private slots: protected: void resizeEvent(QResizeEvent *event) override; - virtual void enterEvent(QEvent *event) override; //进入QWidget瞬间事件 + +#if (QT_MAJOR_VERSION == 5) + virtual void enterEvent(QEvent *event) override; //进入QWidget瞬间事件 +#elif (QT_MAJOR_VERSION == 6) + virtual void enterEvent(QEnterEvent *event) override; //进入QWidget瞬间事件 +#endif void paintEvent(QPaintEvent *event) override; diff --git a/src/service/dbusdraw_adaptor.h b/src/service/dbusdraw_adaptor.h index cd25bcf25..41b34658c 100644 --- a/src/service/dbusdraw_adaptor.h +++ b/src/service/dbusdraw_adaptor.h @@ -7,13 +7,18 @@ #include #include +#include //#include "schedulestructs.h" QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; + +#if (QT_MAJOR_VERSION == 5) class QStringList; +#endif + class QVariant; QT_END_NAMESPACE diff --git a/src/service/filehander.cpp b/src/service/filehander.cpp index 9474e3d66..dd6b88e61 100644 --- a/src/service/filehander.cpp +++ b/src/service/filehander.cpp @@ -16,7 +16,12 @@ #include #include #include + +#if (QT_MAJOR_VERSION == 5) #include +#elif (QT_MAJOR_VERSION == 6) +#include +#endif using Future = QFuture; @@ -336,11 +341,19 @@ QImage loadImage_helper(const QString &path, FileHander *hander) if (reader.canRead()) { QImage img = reader.read(); +#if (QT_MAJOR_VERSION == 5) auto desktop = QApplication::desktop(); if (Q_NULLPTR != desktop && img.logicalDpiX() != desktop->logicalDpiX()) {//图片Dpi值与屏幕会导致在图片上绘制位置错误 img.setDotsPerMeterX(qRound(desktop->logicalDpiX() * 100 / 2.54)); img.setDotsPerMeterY(qRound(desktop->logicalDpiY() * 100 / 2.54)); } +#elif (QT_MAJOR_VERSION == 6) + auto screen = QGuiApplication::primaryScreen(); + if (screen && img.logicalDpiX() != screen->logicalDotsPerInchX()) { + img.setDotsPerMeterX(qRound(screen->logicalDotsPerInchX() * 100 / 2.54)); + img.setDotsPerMeterY(qRound(screen->logicalDotsPerInchY() * 100 / 2.54)); + } +#endif //维持原大小 bool haveOptimal = shouldOptimal; @@ -542,20 +555,19 @@ bool FileHander::isLegalFile(const QString &path) // return false; // } - QRegExp splitExp("[/\\\\]"); - + QRegularExpression splitExp("[/\\\\]"); - int pos = splitExp.indexIn(path, 0); + int pos = splitExp.match(path).hasMatch() ? 0 : -1; while (pos != -1) { QString dirStr = path.left(pos + 1); - if (dirStr.count() > 1) { + if (dirStr.size() > 1) { QDir dir(dirStr); if (!dir.exists()) { return false; } } - pos = splitExp.indexIn(path, pos + 1); + pos = splitExp.match(path.mid(pos + 1)).hasMatch() ? pos + 1 : -1; } bool isdir = (path.endsWith('/') || path.endsWith('\\')); @@ -667,7 +679,7 @@ bool FileHander::saveToImage(PageContext *context, const QString &file, const QS int ww = image.width(); int wh = image.height(); writer.setResolution(96); - writer.setPageSizeMM(QSizeF(25.4 * ww / 96, 25.4 * wh / 96)); + writer.setPageSize(QPageSize(QSizeF(25.4 * ww / 96, 25.4 * wh / 96), QPageSize::Millimeter)); QPainter painter(&writer); painter.drawImage(0, 0, image); return true; diff --git a/src/utils/baseutils.cpp b/src/utils/baseutils.cpp index 411a46d82..8f85eb964 100644 --- a/src/utils/baseutils.cpp +++ b/src/utils/baseutils.cpp @@ -13,8 +13,6 @@ #include #include #include -#include - //QSize initArtboardSize(QPoint pos) //{ diff --git a/src/widgets/ciconbutton.cpp b/src/widgets/ciconbutton.cpp index a630a00c8..23ec446a8 100644 --- a/src/widgets/ciconbutton.cpp +++ b/src/widgets/ciconbutton.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include @@ -96,6 +96,8 @@ void CIconButton::mouseReleaseEvent(QMouseEvent *e) DIconButton::mouseReleaseEvent(e); } + +#if (QT_MAJOR_VERSION == 5) void CIconButton::enterEvent(QEvent *e) { m_isHover = true; @@ -104,6 +106,16 @@ void CIconButton::enterEvent(QEvent *e) updateImage(); DIconButton::enterEvent(e); } +#elif (QT_MAJOR_VERSION == 6) +void CIconButton::enterEvent(QEnterEvent *e) +{ + m_isHover = true; + m_tmpStatus = m_currentStatus; + m_currentStatus = Hover; + updateImage(); + DIconButton::enterEvent(e); +} +#endif void CIconButton::leaveEvent(QEvent *e) { diff --git a/src/widgets/ciconbutton.h b/src/widgets/ciconbutton.h index 69d5be088..1a849eee7 100644 --- a/src/widgets/ciconbutton.h +++ b/src/widgets/ciconbutton.h @@ -41,7 +41,11 @@ public slots: protected: void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; - void enterEvent(QEvent *e) override; +#if (QT_MAJOR_VERSION == 5) + void enterEvent(QEvent *e) override; +#elif (QT_MAJOR_VERSION == 6) + void enterEvent(QEnterEvent *e) override; +#endif void leaveEvent(QEvent *e) override; private: diff --git a/src/widgets/colorlabel.cpp b/src/widgets/colorlabel.cpp index d8b0cf882..9dd4ce77d 100644 --- a/src/widgets/colorlabel.cpp +++ b/src/widgets/colorlabel.cpp @@ -134,6 +134,7 @@ void ColorLabel::paintEvent(QPaintEvent *) painter.drawImage(this->rect(), backgroundImage); } +#if (QT_MAJOR_VERSION == 5) void ColorLabel::enterEvent(QEvent *e) { if (!m_workToPick) @@ -143,6 +144,17 @@ void ColorLabel::enterEvent(QEvent *e) //drawApp->setApplicationCursor(pickColorCursor()); QLabel::enterEvent(e); } +#elif (QT_MAJOR_VERSION == 6) +void ColorLabel::enterEvent(QEnterEvent *e) +{ + if (!m_workToPick) + return; + + m_lastCursor = this->cursor(); + //drawApp->setApplicationCursor(pickColorCursor()); + QLabel::enterEvent(e); +} +#endif void ColorLabel::leaveEvent(QEvent *e) { diff --git a/src/widgets/colorlabel.h b/src/widgets/colorlabel.h index 6f04f1b60..a0d2110ba 100644 --- a/src/widgets/colorlabel.h +++ b/src/widgets/colorlabel.h @@ -65,7 +65,11 @@ class ColorLabel : public DLabel * @brief enterEvent 鼠标进入事件 * @param e 事件 */ - void enterEvent(QEvent *e); +#if (QT_MAJOR_VERSION == 5) + void enterEvent(QEvent *e); +#elif (QT_MAJOR_VERSION == 6) + void enterEvent(QEnterEvent *e); +#endif /** * @brief leaveEvent 鼠标离开事件 * @param e 事件 diff --git a/src/widgets/cspinbox.cpp b/src/widgets/cspinbox.cpp index 9ee70c457..091677b17 100644 --- a/src/widgets/cspinbox.cpp +++ b/src/widgets/cspinbox.cpp @@ -30,12 +30,20 @@ CSpinBox::CSpinBox(DWidget *parent) setMaximumWidth(86); } - connect(this, QOverload::of(&DSpinBox::valueChanged), this, [ = ](int value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(this, &DSpinBox::valueChanged, this, [=](int value) { +#else + connect(this, QOverload::of(&DSpinBox::valueChanged), this, [=](int value) { +#endif setSpinPhaseValue(value, isTimerRunning() ? EChangedUpdate : EChanged); updateMaxSize(); }); - connect(this, QOverload::of(&DSpinBox::valueChanged), this, [ = ](int value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + connect(this, &DSpinBox::valueChanged, this, [=](int value) { +#else + connect(this, QOverload::of(&DSpinBox::valueChanged), this, [=](int value) { +#endif Q_UNUSED(value); //if (_keepFocus) //this->setFocus(); @@ -225,7 +233,14 @@ void CSpinBox::updateMaxSize() { if (Application::isTabletSystemEnvir()) { const int c_MinWidth = 120; - int w = lineEdit()->fontMetrics().width(lineEdit()->text()); + int w; + +#if (QT_MAJOR_VERSION == 5) + w = lineEdit()->fontMetrics().width(lineEdit()->text()); +#elif (QT_MAJOR_VERSION == 6) + w = lineEdit()->fontMetrics().horizontalAdvance(lineEdit()->text()); +#endif + setMaximumWidth(w + c_MinWidth); } } diff --git a/src/widgets/dialog/cexportimagedialog.cpp b/src/widgets/dialog/cexportimagedialog.cpp index 7c04953bc..659057f1e 100644 --- a/src/widgets/dialog/cexportimagedialog.cpp +++ b/src/widgets/dialog/cexportimagedialog.cpp @@ -152,7 +152,12 @@ void CExportImageDialog::initUI() setWgtAccesibleName(m_fileNameEdit, "Export name line editor"); m_fileNameEdit->setClearButtonEnabled(false); //编译器会对反斜杠进行转换,要想在正则表达式中包括一个\,需要输入两次,例如\\s。要想匹配反斜杠本身,需要输入4次,比如\\\\。 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + //在 Qt 6 中,QRegExpValidator 已被弃用 + m_fileNameEdit->lineEdit()->setValidator(new QRegularExpressionValidator(QRegularExpression("[^\\\\ /:*?\"<>|]+"), m_fileNameEdit->lineEdit())); +#else m_fileNameEdit->lineEdit()->setValidator(new QRegExpValidator(QRegExp("[^\\\\ /:*?\"<>|]+"), m_fileNameEdit->lineEdit())); +#endif m_savePathCombox = new QComboBox(this); setWgtAccesibleName(m_savePathCombox, "Export path comboBox"); @@ -179,7 +184,11 @@ void CExportImageDialog::initUI() connect(m_pathChosenButton, &PathActiveButton::clicked, this, [ = ]() { DFileDialog dialog(this); dialog.setViewMode(DFileDialog::Detail); - dialog.setFileMode(DFileDialog::DirectoryOnly); +#if (QT_MAJOR_VERSION == 5) + dialog.setFileMode(DFileDialog::DirectoryOnly); +#elif (QT_MAJOR_VERSION == 6) + dialog.setFileMode(DFileDialog::FileMode::Directory); +#endif dialog.setDirectory(m_pathEditor->text()); if (dialog.exec()) { auto files = dialog.selectedFiles(); @@ -211,7 +220,7 @@ void CExportImageDialog::initUI() m_qualityLabel = new DLabel(this); QHBoxLayout *qualityHLayout = new QHBoxLayout; - qualityHLayout->setMargin(0); + qualityHLayout->setContentsMargins(0, 0, 0, 0); qualityHLayout->setSpacing(0); qualityHLayout->addSpacing(3); qualityHLayout->addWidget(m_qualitySlider); @@ -225,7 +234,7 @@ void CExportImageDialog::initUI() fLayout->setFormAlignment(Qt::AlignJustify); fLayout->setHorizontalSpacing(10); fLayout->setSpacing(10); - fLayout->setMargin(0); + fLayout->setContentsMargins(0, 0, 0, 0); fLayout->addRow(tr("Name:"), m_fileNameEdit); fLayout->addRow(tr("Save to:"), lay); //fLayout->addRow(tr("Save to:"), m_savePathCombox); @@ -409,7 +418,11 @@ void CExportImageDialog::showDirChoseDialog() DFileDialog dialog(this); dialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); dialog.setViewMode(DFileDialog::Detail); +#if (QT_MAJOR_VERSION == 5) dialog.setFileMode(DFileDialog::DirectoryOnly); +#elif (QT_MAJOR_VERSION == 6) + dialog.setFileMode(DFileDialog::FileMode::Directory); +#endif if (dialog.exec()) { auto dirs = dialog.selectedFiles(); QString fileDir = dirs.isEmpty() ? "" : dirs.first(); @@ -491,12 +504,24 @@ void CExportImageDialog::CExportImageDialog_private::initSizeSettingLayoutUi(QFo QButtonGroup *group = new QButtonGroup(_q); group->addButton(_radioRadioBtn, ERadioModel); group->addButton(_radioPiexlBtn, EPixelModel); +#if (QT_MAJOR_VERSION == 5) + // 在Qt 5中,连接按钮切换信号,使用QAbstractButton*和bool作为参数 + connect(group, SIGNAL(buttonToggled(QAbstractButton*, bool)), _q, [ = ](QAbstractButton *button, bool checked) { + if (checked) { + settingModel = ESizeSettingModel(group->id(button)); // 获取按钮的ID + updateSettingModelUi(); + } + }); +#elif (QT_MAJOR_VERSION == 6) + //在Qt 6中,QButtonGroup::buttonToggled信号的签名发生了变化,因此需要调整连接的方式。 + // 在Qt 6中,连接按钮切换信号,使用int和bool作为参数 connect(group, QOverload::of(&QButtonGroup::buttonToggled), _q, [ = ](int model, bool checked) { if (checked) { settingModel = ESizeSettingModel(model); updateSettingModelUi(); } }); +#endif auto w = new QWidget(contentWidget); { //set w ui. @@ -824,7 +849,12 @@ void PathActiveButton::paintEvent(QPaintEvent *event) polygon << QPointF(xBegin + inc * i, y); } QPainter painter(this); +#if (QT_MAJOR_VERSION == 5) painter.setRenderHint(QPainter::HighQualityAntialiasing, true); +#elif (QT_MAJOR_VERSION == 6) + //在Qt6中,使用Antialiasing来设置抗锯齿,因为HighQualityAntialiasing在Qt6中已被移除 + painter.setRenderHint(QPainter::Antialiasing, true); +#endif QPen p(Qt::white); p.setCapStyle(Qt::RoundCap); p.setWidth(4); diff --git a/src/widgets/dialog/cprintmanager.cpp b/src/widgets/dialog/cprintmanager.cpp index 64c3e65bc..15359c282 100644 --- a/src/widgets/dialog/cprintmanager.cpp +++ b/src/widgets/dialog/cprintmanager.cpp @@ -33,7 +33,8 @@ CPrintManager::~CPrintManager() } -void CPrintManager::slotPaintRequest(DPrinter *_printer) +// TODO: dtk问题,DPrinter在qt6中没有pageRect这个方法,备注下,后续会处理,可能会存在样式问题 +void CPrintManager::slotPaintRequest(QPrinter *_printer) { QPainter painter(_printer); QImage img = m_image; @@ -42,13 +43,17 @@ void CPrintManager::slotPaintRequest(DPrinter *_printer) //修复打印图片会模糊 painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); - + QRect wRect; +#if (QT_MAJOR_VERSION == 5) QRect wRect = _printer->pageRect(); +#elif (QT_MAJOR_VERSION == 6) + QRect wRect = _printer->pageLayout().paintRectPixels(_printer->resolution()); +#endif + qreal ratio = wRect.width() * 1.0 / img.width(); painter.drawImage(QRectF(0, qreal(wRect.height() - img.height() * ratio) / 2, wRect.width(), img.height() * ratio), img); - } painter.end(); } @@ -75,8 +80,11 @@ void CPrintManager::showPrintDialog(const QImage &image, DWidget *widget, const #endif - //connect(&printDialog2, &DPrintPreviewDialog::paintRequested, this, &CPrintManager::slotPaintRequest); +#if (QT_MAJOR_VERSION == 5) connect(&printDialog2, QOverload::of(&DPrintPreviewDialog::paintRequested), this, &CPrintManager::slotPaintRequest); +#elif (QT_MAJOR_VERSION == 6) + connect(&printDialog2, &DPrintPreviewDialog::paintRequested, this, &CPrintManager::slotPaintRequest); +#endif //printDialog2.setFixedSize(1000, 600); printDialog2.exec(); diff --git a/src/widgets/dialog/cprintmanager.h b/src/widgets/dialog/cprintmanager.h index e80692288..310d388d6 100644 --- a/src/widgets/dialog/cprintmanager.h +++ b/src/widgets/dialog/cprintmanager.h @@ -24,7 +24,8 @@ class CPrintManager : public QObject void showPrintDialog(const QImage &image, QWidget *widget, const QString &title); private slots: - void slotPaintRequest(DPrinter *_printer); + //TODO: dtk问题,DPrinter在qt6中没有pageRect这个方法,备注下,后续会处理,可能会存在样式问题 + void slotPaintRequest(QPrinter *_printer); private: QImage m_image; }; diff --git a/src/widgets/dialog/cprogressdialog.cpp b/src/widgets/dialog/cprogressdialog.cpp index b18299241..fb6e23091 100644 --- a/src/widgets/dialog/cprogressdialog.cpp +++ b/src/widgets/dialog/cprogressdialog.cpp @@ -10,7 +10,6 @@ #include #include -#include #include ProgressDialog::ProgressDialog(const QString &text, DWidget *parent) diff --git a/src/widgets/dmenucombobox.cpp b/src/widgets/dmenucombobox.cpp index 16b9427e1..8aa95f6ec 100644 --- a/src/widgets/dmenucombobox.cpp +++ b/src/widgets/dmenucombobox.cpp @@ -204,7 +204,7 @@ void DMenuComboBox::initUI() QHBoxLayout *m_hlayout = new QHBoxLayout(this); m_hlayout->addWidget(m_btn); - m_hlayout->setMargin(0); + m_hlayout->setContentsMargins(0, 0, 0, 0); this->setLayout(m_hlayout); m_btn->setMenu(m_menu); diff --git a/src/widgets/dzoommenucombobox.cpp b/src/widgets/dzoommenucombobox.cpp index 5f1086a62..da0782a77 100644 --- a/src/widgets/dzoommenucombobox.cpp +++ b/src/widgets/dzoommenucombobox.cpp @@ -332,7 +332,7 @@ void DZoomMenuComboBox::initUI() // DTK 在 5.6.4 后提供大小模式匹配 #if DTK_VERSION_CHECK(5, 6, 4, 0) <= DTK_VERSION_CHECK(DTK_VERSION_MAJOR, DTK_VERSION_MINOR, DTK_VERSION_PATCH, DTK_VERSION_BUILD) int checkVersion = DTK_VERSION_CHECK(5, 6, 4, 0); - if (checkVersion <= dtkVersion()) { + if (checkVersion <= DApplication::runtimeDtkVersion()) { // 初始化设置 if (DGuiApplicationHelper::isCompactMode()) { setSizeMode(true); diff --git a/src/widgets/progresslayout.cpp b/src/widgets/progresslayout.cpp index 56051fe75..e08cb7fba 100644 --- a/src/widgets/progresslayout.cpp +++ b/src/widgets/progresslayout.cpp @@ -6,7 +6,7 @@ #include "frame/cviewmanagement.h" #include "application.h" #include -#include +#include #include #include DGUI_USE_NAMESPACE diff --git a/src/widgets/seperatorline.h b/src/widgets/seperatorline.h index b581a343a..88e80c008 100644 --- a/src/widgets/seperatorline.h +++ b/src/widgets/seperatorline.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include diff --git a/src/widgets/toolbutton.cpp b/src/widgets/toolbutton.cpp index 5bd6542ac..932e0f07f 100644 --- a/src/widgets/toolbutton.cpp +++ b/src/widgets/toolbutton.cpp @@ -82,8 +82,12 @@ void ToolButton::paintEvent(QPaintEvent *e) iconSz = QSize(0, 0); space = 0; } - - QSize textSz(painter.fontMetrics().width(text()), painter.fontMetrics().height()); + QSize textSz; +#if (QT_MAJOR_VERSION == 5) + QSize textSz(painter.fontMetrics().width(text()), painter.fontMetrics().height()); +#elif (QT_MAJOR_VERSION == 6) + QSize textSz(painter.fontMetrics().horizontalAdvance(text()), painter.fontMetrics().height()); +#endif int iconX = (width() - (iconSz.width() + space + textSz.width())) / 2; int iconY = (height() - iconSz.height()) / 2; @@ -99,7 +103,11 @@ void ToolButton::paintEvent(QPaintEvent *e) // 设置Hover时Icon颜色不变更 QPen pen = painter.pen(); +#if (QT_MAJOR_VERSION == 5) pen.setColor(option.palette.foreground().color()); +#elif (QT_MAJOR_VERSION == 6) + pen.setColor(option.palette.windowText().color()); +#endif painter.setPen(pen); QTransform matrix;