From 0662e03c68065537a6bb5084f2475c2e63a5b63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AE=E7=94=9F=E8=8B=A5=E6=A2=A6?= <1070753498@qq.com> Date: Mon, 4 Nov 2024 16:43:48 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0Qt=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=92=8C=E4=BE=9D=E8=B5=96=E7=AE=A1=E7=90=86]:=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86Qt=E7=89=88=E6=9C=AC=E5=92=8C=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E4=BA=86=E4=BE=9D=E8=B5=96=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在`action.yml`文件中,将Qt版本从`6.7.2`更新到`6.8.1`。 - 在`.github/dependabot.yml`文件中,新增了Dependabot配置,用于自动维护GitHub Actions依赖。 - 在`cmake.yml`、`qmake.yml`、`toolchain.yml`工作流文件中,将`MACOSX_DEPLOYMENT_TARGET`从`11.0`更新到`12.0`,并更新了Windows的运行器版本从`windows-2019`到`windows-latest`。 - 在`README.md`文件中,添加了关于图片加载速度问题的说明,并提出了使用缓存技术的解决方案。 - 在`qt.cmake`文件中,更新了Qt安装路径,以匹配新版本的Qt。 - 在`vcpkg.json`文件中,更新了`builtin-baseline`值,以反映vcpkg依赖的变化。 --- .../actions/install-dependencies/action.yml | 12 ++-- .github/dependabot.yml | 12 ++++ .github/workflows/cmake.yml | 2 +- .github/workflows/qmake.yml | 6 +- .github/workflows/toolchain.yml | 3 +- README.md | 4 ++ cmake/qt.cmake | 4 +- examples/graphics/CMakeLists.txt | 10 ++-- examples/graphics/imageviewer.cpp | 44 +++++++------- examples/graphics/mainwindow.cpp | 8 ++- examples/rhiviewer/CMakeLists.txt | 10 ++-- src/3rdparty/3rdparty.pri | 2 +- src/3rdparty/CMakeLists.txt | 4 +- src/3rdparty/gif/egif/CMakeLists.txt | 2 +- src/3rdparty/qtlockedfile/CMakeLists.txt | 2 +- .../qtsingleapplication/CMakeLists.txt | 18 +++--- src/dump/CMakeLists.txt | 2 +- src/gpugraphics/CMakeLists.txt | 4 +- src/gpugraphics/shader/complie_qsb.ps1 | 2 +- src/graphics/CMakeLists.txt | 2 +- src/graphics/graphics.cpp | 58 ++++++++++--------- src/graphics/graphics.h | 11 ++-- src/graphics/imageview.cpp | 9 +-- src/utils/CMakeLists.txt | 2 +- vcpkg.json | 2 +- 25 files changed, 126 insertions(+), 109 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/actions/install-dependencies/action.yml b/.github/actions/install-dependencies/action.yml index 1bfd2c3..b36ade6 100644 --- a/.github/actions/install-dependencies/action.yml +++ b/.github/actions/install-dependencies/action.yml @@ -18,7 +18,7 @@ inputs: qt_ver: description: 'qt version' required: false - default: '6.7.2' + default: '6.8.1' type: string runs: @@ -37,7 +37,7 @@ runs: rm vcpkg.json - name: Cache windows vcpkg - if: startsWith(runner.os, 'Windows') + if: runner.os == 'Windows' uses: actions/cache@v4 with: path: C:\vcpkg\installed @@ -49,7 +49,7 @@ runs: save-always: true - name: Cache macos or linux vcpkg - if: startsWith(runner.os, 'macOS') || startsWith(runner.os, 'Linux') + if: runner.os == 'macOS' || runner.os == 'Linux' uses: actions/cache@v4 with: path: /usr/local/share/vcpkg/installed @@ -61,7 +61,7 @@ runs: save-always: true - name: Install dependencies on windows - if: startsWith(runner.os, 'Windows') + if: runner.os == 'Windows' shell: bash run: | choco install ninja @@ -70,7 +70,7 @@ runs: vcpkg install ${{ inputs.vcpkg_libs }} --triplet x64-windows || (cat C:/vcpkg/installed/vcpkg/issue_body.md && exit 1) - name: Install dependencies on macos - if: startsWith(runner.os, 'macOS') + if: runner.os == 'macOS' shell: bash run: | brew install ninja python-setuptools @@ -81,7 +81,7 @@ runs: vcpkg install ${{ inputs.vcpkg_libs }} --triplet arm64-osx || (cat /usr/local/share/vcpkg/installed/vcpkg/issue_body.md && exit 1) - name: Install dependencies on linux - if: startsWith(runner.os, 'Linux') + if: runner.os == 'Linux' shell: bash run: | sudo apt-get update diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5d5094d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + \ No newline at end of file diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4dd34eb..051540d 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -17,7 +17,7 @@ on: - 'README*' env: - MACOSX_DEPLOYMENT_TARGET: 11.0 + MACOSX_DEPLOYMENT_TARGET: 12.0 jobs: build: diff --git a/.github/workflows/qmake.yml b/.github/workflows/qmake.yml index fe4ff04..bde3c99 100644 --- a/.github/workflows/qmake.yml +++ b/.github/workflows/qmake.yml @@ -17,7 +17,7 @@ on: - 'README*' env: - MACOSX_DEPLOYMENT_TARGET: 11.0 + MACOSX_DEPLOYMENT_TARGET: 12.0 jobs: build: @@ -27,7 +27,7 @@ jobs: fail-fast: false matrix: os: - - windows-2019 + - windows-latest - macos-latest - ubuntu-latest @@ -51,7 +51,7 @@ jobs: if: startsWith(matrix.os, 'windows') shell: pwsh run: | - ..\scripts\windows\setVsDev.ps1 -VersionRange "[16.0,17.0)" -Arch "x64" + ..\scripts\windows\setVsDev.ps1 & qmake ./../. & jom working-directory: build diff --git a/.github/workflows/toolchain.yml b/.github/workflows/toolchain.yml index 39dd345..9a8c81d 100644 --- a/.github/workflows/toolchain.yml +++ b/.github/workflows/toolchain.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: env: - MACOSX_DEPLOYMENT_TARGET: 11.0 + MACOSX_DEPLOYMENT_TARGET: 12.0 jobs: build: @@ -20,7 +20,6 @@ jobs: matrix: os: - windows-latest - - windows-2019 - macos-latest - ubuntu-latest diff --git a/README.md b/README.md index 507e254..16dcbd2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ 1. 跟OpenGL看图界面类似,在旋转任意角度的时候,纹理的宽高比会变化,导致显示不正常; +#### 图片加载速度问题 + +1. 使用`QPixmapCache`或者`QCache`之类的缓存技术,可以通过空间换时间,在加载已经加载过的图片时,提升加载速度。 + ## 看图界面
diff --git a/cmake/qt.cmake b/cmake/qt.cmake index 56163b4..d81b1f2 100644 --- a/cmake/qt.cmake +++ b/cmake/qt.cmake @@ -1,7 +1,7 @@ if(CMAKE_HOST_WIN32) - list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.7.2\\msvc2019_64") + list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\6.8.1\\msvc2022_64") elseif(CMAKE_HOST_APPLE) elseif(CMAKE_HOST_LINUX) - list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.7.2/gcc_64") + list(APPEND CMAKE_PREFIX_PATH "/opt/Qt/6.8.1/gcc_64") endif() diff --git a/examples/graphics/CMakeLists.txt b/examples/graphics/CMakeLists.txt index d6930cf..c233fc1 100644 --- a/examples/graphics/CMakeLists.txt +++ b/examples/graphics/CMakeLists.txt @@ -54,10 +54,10 @@ target_link_libraries( thirdparty dump utils - Qt6::Gui - Qt6::Widgets - Qt6::OpenGLWidgets - Qt6::Network - Qt6::Concurrent + Qt::Gui + Qt::Widgets + Qt::OpenGLWidgets + Qt::Network + Qt::Concurrent egif) qt_finalize_executable(Qt-Graphics) diff --git a/examples/graphics/imageviewer.cpp b/examples/graphics/imageviewer.cpp index 15a7c55..dcff651 100644 --- a/examples/graphics/imageviewer.cpp +++ b/examples/graphics/imageviewer.cpp @@ -83,12 +83,9 @@ void ImageViewer::onOpenImage() QString imageFilters(tr("Images (*.bmp *.gif *.jpg *.jpeg *.png *.svg *.tiff *.webp *.icns " "*.bitmap *.graymap *.pixmap *.tga *.xbitmap *.xpixmap)")); //qDebug() << imageFilters; - const QString path = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation) - .value(0, QDir::homePath()); - const QString filename = QFileDialog::getOpenFileName(this, - tr("Open Image"), - path, - imageFilters); + const auto path = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation) + .value(0, QDir::homePath()); + const auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), path, imageFilters); if (filename.isEmpty()) { return; } @@ -97,7 +94,7 @@ void ImageViewer::onOpenImage() void ImageViewer::onMaskImage() { - QPixmap pixmap = d_ptr->imageView->pixmap(); + auto pixmap = d_ptr->imageView->pixmap(); if (pixmap.isNull()) { return; } @@ -109,7 +106,7 @@ void ImageViewer::onMaskImage() void ImageViewer::onRoundImage() { - QPixmap pixmap = d_ptr->imageView->pixmap(); + auto pixmap = d_ptr->imageView->pixmap(); if (pixmap.isNull()) { return; } @@ -121,7 +118,7 @@ void ImageViewer::onRoundImage() void ImageViewer::onScaleFactorChanged(qreal factor) { - const QString info = QString::number(factor * 100, 'f', 2) + QLatin1Char('%'); + const auto info = QString::number(factor * 100, 'f', 2) + QLatin1Char('%'); d_ptr->scaleLabel->setText(info); } @@ -139,7 +136,7 @@ void ImageViewer::onImageChanged(const QString &url) d_ptr->urlLabel->setText(url); d_ptr->fileSizeLabel->setText(Utils::convertBytesToString(QFile(url).size())); - for (const ImageInfo &image : std::as_const(d_ptr->imageInfoList)) { + for (const auto &image : std::as_const(d_ptr->imageInfoList)) { if (image.fileInfo().absoluteFilePath() == url) { return; } @@ -171,12 +168,11 @@ void ImageViewer::onFormatChecked(bool state) void ImageViewer::onFormatChanged(const QString &) { - QImage::Format format = QImage::Format(d_ptr->formatBox->currentData().toInt()); - Qt::ImageConversionFlags flags = Qt::ImageConversionFlags( - d_ptr->colorBox->currentData().toInt()); + auto format = QImage::Format(d_ptr->formatBox->currentData().toInt()); + auto flags = Qt::ImageConversionFlags(d_ptr->colorBox->currentData().toInt()); - QImage image = d_ptr->imageView->pixmap().toImage(); - QPixmap pixmap = QPixmap::fromImage(image.convertToFormat(format, flags)); + auto image = d_ptr->imageView->pixmap().toImage(); + auto pixmap = QPixmap::fromImage(image.convertToFormat(format, flags)); if (pixmap.isNull()) { QMessageBox::warning(this, tr("WARNING"), tr("Format Conversion Failed!")); return; @@ -223,17 +219,17 @@ void ImageViewer::setupUI() QWidget *ImageViewer::toolWidget() { - QPushButton *openImageButton = new QPushButton(tr("Open Picture"), this); + auto *openImageButton = new QPushButton(tr("Open Picture"), this); connect(openImageButton, &QPushButton::clicked, this, &ImageViewer::onOpenImage); - QPushButton *maskImageButton = new QPushButton(tr("Mask Picture"), this); + auto *maskImageButton = new QPushButton(tr("Mask Picture"), this); connect(maskImageButton, &QPushButton::clicked, this, &ImageViewer::onMaskImage); - QPushButton *roundImageButton = new QPushButton(tr("Round Picture"), this); + auto *roundImageButton = new QPushButton(tr("Round Picture"), this); connect(roundImageButton, &QPushButton::clicked, this, &ImageViewer::onRoundImage); - QGroupBox *infoBox = new QGroupBox(tr("Image Information"), this); - QGridLayout *gridLayout = new QGridLayout(infoBox); + auto *infoBox = new QGroupBox(tr("Image Information"), this); + auto *gridLayout = new QGridLayout(infoBox); gridLayout->addWidget(new QLabel(tr("Url: "), this), 0, 0, 1, 1); gridLayout->addWidget(d_ptr->urlLabel, 0, 1, 1, 1); gridLayout->addWidget(new QLabel(tr("File Size: "), this), 1, 0, 1, 1); @@ -243,16 +239,16 @@ QWidget *ImageViewer::toolWidget() gridLayout->addWidget(new QLabel(tr("Scaling Ratio:"), this), 3, 0, 1, 1); gridLayout->addWidget(d_ptr->scaleLabel, 3, 1, 1, 1); - QCheckBox *formatBox = new QCheckBox(tr("Format"), this); + auto *formatBox = new QCheckBox(tr("Format"), this); connect(formatBox, &QCheckBox::clicked, this, &ImageViewer::onFormatChecked); - QHBoxLayout *formatLayout = new QHBoxLayout; + auto *formatLayout = new QHBoxLayout; formatLayout->addWidget(formatBox); formatLayout->addWidget(d_ptr->formatBox); formatLayout->addWidget(d_ptr->colorBox); - QWidget *widget = new QWidget(this); + auto *widget = new QWidget(this); widget->setMaximumWidth(300); - QVBoxLayout *rightLayout = new QVBoxLayout(widget); + auto *rightLayout = new QVBoxLayout(widget); rightLayout->addWidget(openImageButton); rightLayout->addWidget(infoBox); rightLayout->addLayout(formatLayout); diff --git a/examples/graphics/mainwindow.cpp b/examples/graphics/mainwindow.cpp index 8b1216a..aed6f26 100644 --- a/examples/graphics/mainwindow.cpp +++ b/examples/graphics/mainwindow.cpp @@ -16,8 +16,8 @@ class MainWindow::MainWindowPrivate { public: - MainWindowPrivate(QWidget *parent) - : q_ptr(parent) + explicit MainWindowPrivate(MainWindow *q) + : q_ptr(q) { drawWidget = new DrawWidget(q_ptr); imageViewer = new ImageViewer(q_ptr); @@ -35,7 +35,8 @@ class MainWindow::MainWindowPrivate } ~MainWindowPrivate() {} - QWidget *q_ptr; + MainWindow *q_ptr; + DrawWidget *drawWidget; ImageViewer *imageViewer; OpenglViewer *openglViewer; @@ -53,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) setupUI(); resize(1000, 618); Utils::windowCenter(this); + #if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) // 图片读取限制大小 qInfo() << tr("QImage memory allocation above this limit: %1MB.") diff --git a/examples/rhiviewer/CMakeLists.txt b/examples/rhiviewer/CMakeLists.txt index f8f24e0..10be077 100644 --- a/examples/rhiviewer/CMakeLists.txt +++ b/examples/rhiviewer/CMakeLists.txt @@ -16,9 +16,9 @@ target_link_libraries( thirdparty dump utils - Qt6::GuiPrivate - Qt6::Gui - Qt6::Widgets - Qt6::Network - Qt6::Concurrent) + Qt::GuiPrivate + Qt::Gui + Qt::Widgets + Qt::Network + Qt::Concurrent) qt_finalize_executable(Qt-RhiViewer) diff --git a/src/3rdparty/3rdparty.pri b/src/3rdparty/3rdparty.pri index e8b3e95..b245ffd 100644 --- a/src/3rdparty/3rdparty.pri +++ b/src/3rdparty/3rdparty.pri @@ -35,7 +35,7 @@ CONFIG(debug, debug|release) { -llibbreakpad_client -llibbreakpad } -LIBS += -lcommon -lclient -lutil -lbase +LIBS += -lvcpkg_crashpad_client_common -lvcpkg_crashpad_client -lvcpkg_crashpad_util -lvcpkg_crashpad_base LIBS += -lgif diff --git a/src/3rdparty/CMakeLists.txt b/src/3rdparty/CMakeLists.txt index aacbac9..565ef6d 100644 --- a/src/3rdparty/CMakeLists.txt +++ b/src/3rdparty/CMakeLists.txt @@ -9,8 +9,8 @@ set(PROJECT_SOURCES thirdparty_global.hpp) add_custom_library(thirdparty ${PROJECT_SOURCES}) -target_link_libraries(thirdparty PRIVATE shared_qtlockedfile utils Qt6::Network - Qt6::Widgets) +target_link_libraries(thirdparty PRIVATE shared_qtlockedfile utils Qt::Network + Qt::Widgets) if(CMAKE_HOST_WIN32) target_compile_definitions(thirdparty PRIVATE "THRIDPARTY_LIBRARY") diff --git a/src/3rdparty/gif/egif/CMakeLists.txt b/src/3rdparty/gif/egif/CMakeLists.txt index 1ef237f..deda5b4 100644 --- a/src/3rdparty/gif/egif/CMakeLists.txt +++ b/src/3rdparty/gif/egif/CMakeLists.txt @@ -1,7 +1,7 @@ set(PROJECT_SOURCES GifEncoder.cpp GifEncoder.h NeuQuant.cpp NeuQuant.h) add_custom_library(egif ${PROJECT_SOURCES}) -target_link_libraries(egif PRIVATE GIF::GIF Qt6::Widgets) +target_link_libraries(egif PRIVATE GIF::GIF Qt::Widgets) if(CMAKE_HOST_WIN32) target_compile_definitions(egif PRIVATE "THRIDPARTY_LIBRARY" _UNICODE UNICODE) diff --git a/src/3rdparty/qtlockedfile/CMakeLists.txt b/src/3rdparty/qtlockedfile/CMakeLists.txt index da604dc..b4d4af9 100644 --- a/src/3rdparty/qtlockedfile/CMakeLists.txt +++ b/src/3rdparty/qtlockedfile/CMakeLists.txt @@ -6,7 +6,7 @@ endif() add_library(shared_qtlockedfile STATIC ${OS_SOURCES} qtlockedfile.cpp qtlockedfile.h) -target_link_libraries(shared_qtlockedfile Qt6::Core) +target_link_libraries(shared_qtlockedfile Qt::Core) target_include_directories(shared_qtlockedfile PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") if(CMAKE_HOST_WIN32) diff --git a/src/3rdparty/qtsingleapplication/CMakeLists.txt b/src/3rdparty/qtsingleapplication/CMakeLists.txt index 923ab85..3a37d85 100644 --- a/src/3rdparty/qtsingleapplication/CMakeLists.txt +++ b/src/3rdparty/qtsingleapplication/CMakeLists.txt @@ -1,9 +1,11 @@ -add_library(shared_qtsingleapplication SHARED - qtsingleapplication.cpp qtsingleapplication.h - qtlocalpeer.cpp qtlocalpeer.h -) -target_link_libraries(shared_qtsingleapplication shared_qtlockedfile Qt6::Core Qt6::Network Qt6::Widgets) -target_include_directories(shared_qtsingleapplication PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") -if (WIN32) - target_compile_definitions(shared_qtsingleapplication PRIVATE "THRIDPARTY_LIBRARY" _UNICODE UNICODE) +add_library( + shared_qtsingleapplication SHARED + qtsingleapplication.cpp qtsingleapplication.h qtlocalpeer.cpp qtlocalpeer.h) +target_link_libraries(shared_qtsingleapplication shared_qtlockedfile Qt::Core + Qt::Network Qt::Widgets) +target_include_directories(shared_qtsingleapplication + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +if(WIN32) + target_compile_definitions(shared_qtsingleapplication + PRIVATE "THRIDPARTY_LIBRARY" _UNICODE UNICODE) endif() diff --git a/src/dump/CMakeLists.txt b/src/dump/CMakeLists.txt index ee32b6f..18a7b02 100644 --- a/src/dump/CMakeLists.txt +++ b/src/dump/CMakeLists.txt @@ -2,7 +2,7 @@ set(PROJECT_SOURCES breakpad.hpp breakpad.cc crashpad.hpp crashpad.cc dump_global.hpp) add_custom_library(dump ${PROJECT_SOURCES}) target_link_libraries( - dump PRIVATE utils Qt6::Widgets unofficial::breakpad::libbreakpad + dump PRIVATE utils Qt::Widgets unofficial::breakpad::libbreakpad unofficial::breakpad::libbreakpad_client crashpad::crashpad) if(CMAKE_HOST_WIN32) diff --git a/src/gpugraphics/CMakeLists.txt b/src/gpugraphics/CMakeLists.txt index 7888948..190f6c7 100644 --- a/src/gpugraphics/CMakeLists.txt +++ b/src/gpugraphics/CMakeLists.txt @@ -18,8 +18,8 @@ endif() qt_add_resources(SOURCES shader.qrc) add_custom_library(gpugraphics ${PROJECT_SOURCES} ${SOURCES}) -target_link_libraries(gpugraphics PRIVATE Qt6::GuiPrivate Qt6::Gui Qt6::Widgets - Qt6::OpenGLWidgets) +target_link_libraries(gpugraphics PRIVATE Qt::GuiPrivate Qt::Gui Qt::Widgets + Qt::OpenGLWidgets) if(CMAKE_HOST_WIN32) target_compile_definitions(gpugraphics PRIVATE "GPUGRAPHICS_LIBRARY") diff --git a/src/gpugraphics/shader/complie_qsb.ps1 b/src/gpugraphics/shader/complie_qsb.ps1 index 139c7e2..e14f6da 100644 --- a/src/gpugraphics/shader/complie_qsb.ps1 +++ b/src/gpugraphics/shader/complie_qsb.ps1 @@ -1,6 +1,6 @@ Set-Location $PSScriptRoot -$qsb = "C:\Qt\6.7.2\msvc2019_64\bin\qsb.exe" +$qsb = "C:\Qt\6.8.1\msvc2022_64\bin\qsb.exe" & $qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o vulkan.vert.qsb vulkan.vert & $qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o vulkan.frag.qsb vulkan.frag diff --git a/src/graphics/CMakeLists.txt b/src/graphics/CMakeLists.txt index fdf3df1..a11fb09 100644 --- a/src/graphics/CMakeLists.txt +++ b/src/graphics/CMakeLists.txt @@ -28,7 +28,7 @@ set(PROJECT_SOURCES imageview.h) add_custom_library(graphics ${PROJECT_SOURCES}) -target_link_libraries(graphics PRIVATE Qt6::Widgets) +target_link_libraries(graphics PRIVATE Qt::Widgets) if(CMAKE_HOST_WIN32) target_compile_definitions(graphics PRIVATE "GRAPHICS_LIBRARY") diff --git a/src/graphics/graphics.cpp b/src/graphics/graphics.cpp index 5ba39f3..0012179 100644 --- a/src/graphics/graphics.cpp +++ b/src/graphics/graphics.cpp @@ -2,50 +2,52 @@ #include -auto Graphics::calculateCircle(const QPolygonF &pts, QPointF ¢er, double &radius) -> bool +namespace Graphics { + +auto calculateCircle(const QPolygonF &pts, QPointF ¢er, double &radius) -> bool { - if(pts.size() < 3) + if (pts.size() < 3) return false; double X1(0), Y1(0), X2(0), Y2(0), X3(0), Y3(0); double X1Y1(0), X1Y2(0), X2Y1(0); - for (int i = 0; i < pts.size(); i++){ + for (int i = 0; i < pts.size(); i++) { double x = pts[i].x(); double y = pts[i].y(); - X1 = X1 + x; - Y1 = Y1 + y; - X2 = X2 + x* x; - Y2 = Y2 + y* y; - X3 = X3 + x* x* x; - Y3 = Y3 + y* y* y; - X1Y1 = X1Y1 + x* y; - X1Y2 = X1Y2 + x* y* y; - X2Y1 = X2Y1 + x* x* y; + X1 = X1 + x; + Y1 = Y1 + y; + X2 = X2 + x * x; + Y2 = Y2 + y * y; + X3 = X3 + x * x * x; + Y3 = Y3 + y * y * y; + X1Y1 = X1Y1 + x * y; + X1Y2 = X1Y2 + x * y * y; + X2Y1 = X2Y1 + x * x * y; } double C, D, E, G, H, N; double a, b, c; N = pts.size(); - C = N*X2 - X1*X1; - D = N*X1Y1 - X1*Y1; - E = N*X3 + N*X1Y2 - (X2 + Y2)*X1; - G = N*Y2 - Y1*Y1; - H = N*X2Y1 + N*Y3 - (X2 + Y2)*Y1; - a = (H*D - E*G) / (C*G - D*D); - b = (H*C - E*D) / (D*D - G*C); - c = -(a*X1 + b*Y1 + X2 + Y2) / N; + C = N * X2 - X1 * X1; + D = N * X1Y1 - X1 * Y1; + E = N * X3 + N * X1Y2 - (X2 + Y2) * X1; + G = N * Y2 - Y1 * Y1; + H = N * X2Y1 + N * Y3 - (X2 + Y2) * Y1; + a = (H * D - E * G) / (C * G - D * D); + b = (H * C - E * D) / (D * D - G * C); + c = -(a * X1 + b * Y1 + X2 + Y2) / N; double A, B; A = a / (-2); B = b / (-2); - radius = qSqrt(a*a + b*b - 4 * c) / 2; + radius = qSqrt(a * a + b * b - 4 * c) / 2; center = QPointF(A, B); return true; } -auto Graphics::curorFromAngle(double angle) -> QCursor +auto curorFromAngle(double angle) -> QCursor { if (angle >= 0 && angle < 15) { return Qt::SizeVerCursor; @@ -68,7 +70,7 @@ auto Graphics::curorFromAngle(double angle) -> QCursor } } -auto Graphics::boundingFromLine(const QLineF &line, double margin) -> QPolygonF +auto boundingFromLine(const QLineF &line, double margin) -> QPolygonF { QPolygonF ply; QPointF p1 = line.p1(); @@ -83,17 +85,19 @@ auto Graphics::boundingFromLine(const QLineF &line, double margin) -> QPolygonF return ply; } -auto Graphics::distance(QPointF pos, QPointF center) -> double +auto distance(QPointF pos, QPointF center) -> double { return QLineF(center, pos).length(); } -auto Graphics::ConvertTo360(double angle) -> double +auto ConvertTo360(double angle) -> double { - if(angle >= 0 && angle < 360) + if (angle >= 0 && angle < 360) return angle; - else if(angle < 0) + else if (angle < 0) return ConvertTo360(angle + 360); else return ConvertTo360(angle - 360); } + +} // namespace Graphics diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 82beb5a..28f725b 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -1,5 +1,4 @@ -#ifndef GRAPHICS_H -#define GRAPHICS_H +#pragma once #include #include @@ -7,12 +6,10 @@ namespace Graphics { -auto calculateCircle(const QPolygonF& pts, QPointF& center, double& radius) -> bool; +auto calculateCircle(const QPolygonF &pts, QPointF ¢er, double &radius) -> bool; auto curorFromAngle(double angle) -> QCursor; -auto boundingFromLine(const QLineF& line, double margin) -> QPolygonF; +auto boundingFromLine(const QLineF &line, double margin) -> QPolygonF; auto distance(QPointF pos, QPointF center) -> double; auto ConvertTo360(double angle) -> double; -} - -#endif // GRAPHICS_H +} // namespace Graphics diff --git a/src/graphics/imageview.cpp b/src/graphics/imageview.cpp index 621c611..4935d2d 100644 --- a/src/graphics/imageview.cpp +++ b/src/graphics/imageview.cpp @@ -8,8 +8,8 @@ namespace Graphics { class ImageView::ImageViewPrivate { public: - ImageViewPrivate(QWidget *parent) - : q_ptr(parent) + explicit ImageViewPrivate(ImageView *q) + : q_ptr(q) , menu(new QMenu) { pixmapItem = new GraphicsPixmapItem; @@ -33,7 +33,8 @@ class ImageView::ImageViewPrivate ~ImageViewPrivate() {} - QWidget *q_ptr; + ImageView *q_ptr; + GraphicsPixmapItem *pixmapItem; QGraphicsRectItem *backgroundItem; QGraphicsRectItem *outlineItem; @@ -118,7 +119,7 @@ void ImageView::setPixmap(const QPixmap &pixmap) } d_ptr->pixmapItem->setCustomPixmap(pixmap); - QRectF rectF = d_ptr->pixmapItem->boundingRect(); + auto rectF = d_ptr->pixmapItem->boundingRect(); d_ptr->backgroundItem->setRect(rectF); d_ptr->outlineItem->setRect(rectF); diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index a667e75..0d88efb 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -13,7 +13,7 @@ set(PROJECT_SOURCES validator.hpp) add_custom_library(utils ${PROJECT_SOURCES}) -target_link_libraries(utils PRIVATE Qt6::Widgets Qt6::Core5Compat) +target_link_libraries(utils PRIVATE Qt::Widgets Qt::Core5Compat) if(CMAKE_HOST_WIN32) target_compile_definitions(utils PRIVATE "UTILS_LIBRARY") diff --git a/vcpkg.json b/vcpkg.json index c21b57d..38b08b6 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,5 +8,5 @@ "crashpad", "giflib" ], - "builtin-baseline": "fe1cde61e971d53c9687cf9a46308f8f55da19fa" + "builtin-baseline": "b545373a9a536dc559dac8583467a21497a0e897" }