Skip to content

Commit 800ea18

Browse files
committed
[图形工具更新]: 新增多页面跳转功能并优化图像查看体验
- **新增多页面跳转功能**: 在图像查看器中添加"跳转到多页"按钮,支持从单张图像查看快速跳转到多图像文件查看器 - **统一应用信息管理**: 移除独立的appinfo.hpp文件,将版本信息等统一整合到utils/appdata.hpp中 - **增强图像格式支持**: 扩展支持的文件格式,新增对ICO格式的支持 - **优化拖拽体验**: 为OpenGL和RHI视图添加拖拽打开图像文件的功能 - **改进缩放计算**: 修正缩放因子计算逻辑,考虑设备像素比确保显示精度 - **修复图像加载**: 优化空路径处理和图像缓存机制,提升稳定性 - **代码结构优化**: 调整界面布局和信号槽连接,提高代码可维护性 - **多视图协同**: 实现图像查看器、OpenGL查看器和Vulkan查看器之间的页面跳转联动
1 parent 4551ee3 commit 800ea18

26 files changed

Lines changed: 253 additions & 83 deletions

examples/appinfo.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/common/viewer.cc

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ bool Viewer::setThumbnail(const Thumbnail &thumbnail, const qint64 taskCount)
2929
return true;
3030
}
3131

32+
void Viewer::setEnableJumpToMultiPage(bool enable)
33+
{
34+
m_enableJumpToMultiPage = enable;
35+
if (!enable) {
36+
m_jumpToMultiPageButton->setVisible(false);
37+
}
38+
}
39+
3240
void Viewer::onScaleFactorChanged(qreal factor)
3341
{
3442
const auto text = QString::number(factor * 100, 'f', 2) + QLatin1Char('%');
@@ -52,6 +60,18 @@ void Viewer::onImageChanged(const QString &url)
5260
m_urlLabel->setToolTip(url);
5361
m_fileSizeLabel->setText(Utils::formatBytes(QFile(url).size()));
5462

63+
m_jumpToMultiPageButton->setVisible(m_enableJumpToMultiPage
64+
&& Utils::asynchronous<bool>([url]() {
65+
if (url.isEmpty()) {
66+
return false;
67+
}
68+
QImageReader reader(url);
69+
if (!reader.canRead()) {
70+
return false;
71+
}
72+
return reader.imageCount() > 1;
73+
}));
74+
5575
for (const auto &data : std::as_const(m_thumbnailList)) {
5676
if (data.fileInfo().absoluteFilePath() == url) {
5777
return;
@@ -61,11 +81,16 @@ void Viewer::onImageChanged(const QString &url)
6181
startImageLoadThread(url);
6282
}
6383

84+
void Viewer::onJumpToMultiPage()
85+
{
86+
emit jumpToMultiPage(m_urlLabel->text());
87+
}
88+
6489
QString Viewer::openImage()
6590
{
6691
const QString imageFilters(
67-
tr("Images (*.bmp *.gif *.jpg *.jpeg *.png *.svg *.tiff *.webp *.icns "
68-
"*.bitmap *.graymap *.pixmap *.tga *.xbitmap *.xpixmap)"));
92+
tr("Images (*.bmp *.gif *.jpg *.jpeg *.png *.svg *.tiff *.webp *.ico *.icns *.bitmap "
93+
"*.graymap *.pixmap *.tga *.xbitmap *.xpixmap)"));
6994
const auto path = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation)
7095
.value(0, QDir::homePath());
7196
return QFileDialog::getOpenFileName(this, tr("Open Image"), path, imageFilters);
@@ -120,6 +145,14 @@ void Viewer::setupUI()
120145
gridLayout->addWidget(m_sizeLabel, 2, 1, 1, 1);
121146
gridLayout->addWidget(new QLabel(tr("Scaling Ratio:"), this), 3, 0, 1, 1);
122147
gridLayout->addWidget(m_scaleLabel, 3, 1, 1, 1);
148+
149+
m_jumpToMultiPageButton = new QToolButton(this);
150+
sizePolicy = m_jumpToMultiPageButton->sizePolicy();
151+
sizePolicy.setHorizontalPolicy(QSizePolicy::Preferred);
152+
m_jumpToMultiPageButton->setSizePolicy(sizePolicy);
153+
m_jumpToMultiPageButton->setText(tr("Jump To Multi Page"));
154+
m_jumpToMultiPageButton->hide();
155+
connect(m_jumpToMultiPageButton, &QToolButton::clicked, this, &Viewer::onJumpToMultiPage);
123156
}
124157

125158
class ImageLoadRunnable::ImageLoadRunnablePrivate

examples/common/viewer.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ class Viewer : public QWidget
1717

1818
virtual auto setThumbnail(const Thumbnail &thumbnail, const qint64 taskCount) -> bool;
1919

20+
void setEnableJumpToMultiPage(bool enable);
21+
2022
signals:
2123
void imageReady(const QImage &image);
24+
void jumpToMultiPage(const QString &imageUrl);
2225

2326
protected slots:
2427
void onScaleFactorChanged(qreal factor);
2528
void onImageSizeChanged(const QSize &size);
2629
void onImageChanged(const QString &url);
2730

31+
private slots:
32+
void onJumpToMultiPage();
33+
2834
protected:
2935
QString openImage();
3036
virtual void startImageLoadThread(const QString &url);
@@ -38,13 +44,18 @@ protected slots:
3844
QLabel *m_fileSizeLabel;
3945
QLabel *m_sizeLabel;
4046
QLabel *m_scaleLabel;
47+
48+
QToolButton *m_jumpToMultiPageButton;
49+
4150
ThumbnailList m_thumbnailList;
4251
ImageListView *m_imageListView;
4352

4453
std::atomic_llong m_taskCount = 1;
4554

4655
private:
4756
void setupUI();
57+
58+
bool m_enableJumpToMultiPage = false;
4859
};
4960

5061
class ImageLoadRunnable : public QRunnable

examples/graphics/imageviewer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class ImageViewer::ImageViewerPrivate
2424
for (int i = 0; i < imageFormat.keyCount(); i++) {
2525
formatBox->addItem(imageFormat.key(i), imageFormat.value(i));
2626
}
27-
const auto Conversionflags = QMetaEnum::fromType<Qt::ImageConversionFlags>();
28-
for (int i = 0; i < Conversionflags.keyCount(); i++) {
29-
colorBox->addItem(Conversionflags.key(i), Conversionflags.value(i));
27+
const auto conversionflags = QMetaEnum::fromType<Qt::ImageConversionFlags>();
28+
for (int i = 0; i < conversionflags.keyCount(); i++) {
29+
colorBox->addItem(conversionflags.key(i), conversionflags.value(i));
3030
}
3131
}
3232

@@ -45,6 +45,7 @@ ImageViewer::ImageViewer(QWidget *parent)
4545
{
4646
setupUI();
4747
buildConnect();
48+
setEnableJumpToMultiPage(true);
4849
}
4950

5051
ImageViewer::~ImageViewer() {}
@@ -90,8 +91,8 @@ void ImageViewer::onChangedImage(int index)
9091
void ImageViewer::onFormatChecked(bool state)
9192
{
9293
d_ptr->formatBox->setVisible(state);
93-
d_ptr->imageViewFormat->setVisible(state);
9494
d_ptr->colorBox->setVisible(state);
95+
d_ptr->imageViewFormat->setVisible(state);
9596
}
9697

9798
void ImageViewer::onFormatChanged(const QString &)
@@ -125,8 +126,8 @@ void ImageViewer::setupUI()
125126
layout->addWidget(m_imageListView);
126127

127128
d_ptr->formatBox->hide();
128-
d_ptr->imageViewFormat->hide();
129129
d_ptr->colorBox->hide();
130+
d_ptr->imageViewFormat->hide();
130131
}
131132

132133
QWidget *ImageViewer::toolWidget()
@@ -152,6 +153,7 @@ QWidget *ImageViewer::toolWidget()
152153
rightLayout->addLayout(formatLayout);
153154
rightLayout->addWidget(maskImageButton);
154155
rightLayout->addWidget(roundImageButton);
156+
rightLayout->addWidget(m_jumpToMultiPageButton);
155157
rightLayout->addStretch();
156158

157159
return widget;

examples/graphics/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <3rdparty/qtsingleapplication/qtsingleapplication.h>
44
#include <dump/crashpad.hpp>
5-
#include <examples/appinfo.hpp>
5+
#include <utils/appdata.hpp>
66
#include <utils/hostosinfo.h>
77
#include <utils/logasync.h>
88
#include <utils/utils.hpp>
@@ -16,12 +16,12 @@
1616

1717
void setAppInfo()
1818
{
19-
qApp->setApplicationVersion(AppInfo::version);
19+
qApp->setApplicationVersion(Utils::version);
2020
qApp->setApplicationDisplayName(AppName);
2121
qApp->setApplicationName(AppName);
2222
qApp->setDesktopFileName(AppName);
23-
qApp->setOrganizationDomain(AppInfo::organizationDomain);
24-
qApp->setOrganizationName(AppInfo::organzationName);
23+
qApp->setOrganizationDomain(Utils::organizationDomain);
24+
qApp->setOrganizationName(Utils::organzationName);
2525
qApp->setWindowIcon(qApp->style()->standardIcon(QStyle::SP_MediaPlay));
2626
}
2727

examples/graphics/mainwindow.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ class MainWindow::MainWindowPrivate
5656
SubtitlSplicingWidget *subtitlSplicingWidget;
5757
DrawWidget *drawWidget;
5858
QStackedWidget *stackedWidget;
59+
60+
QAction *multiImageFileViewerAction = nullptr;
5961
};
6062

6163
MainWindow::MainWindow(QWidget *parent)
6264
: QMainWindow(parent)
6365
, d_ptr(new MainWindowPrivate(this))
6466
{
6567
setupUI();
68+
buildConnect();
6669
resize(1000, 618);
6770
Utils::windowCenter(this);
6871

@@ -84,6 +87,16 @@ MainWindow::MainWindow(QWidget *parent)
8487

8588
MainWindow::~MainWindow() {}
8689

90+
void MainWindow::onJumpToMultiImageFileViewer(const QString &url)
91+
{
92+
if (url.isEmpty()) {
93+
return;
94+
}
95+
96+
d_ptr->multiImageFileViewerAction->trigger();
97+
d_ptr->multiImageFileViewer->setImageUrl(url);
98+
}
99+
87100
void MainWindow::setupUI()
88101
{
89102
initMenuBar();
@@ -116,9 +129,10 @@ void MainWindow::initMenuBar()
116129
}));
117130
}
118131
#endif
119-
setCheckable(menu->addAction(tr("Multi Image File Viewer"), this, [this] {
132+
d_ptr->multiImageFileViewerAction = menu->addAction(tr("Multi Image File Viewer"), this, [this] {
120133
d_ptr->stackedWidget->setCurrentWidget(d_ptr->multiImageFileViewer);
121-
}));
134+
});
135+
setCheckable(d_ptr->multiImageFileViewerAction);
122136
setCheckable(menu->addAction(tr("ICO Converter"), this, [this] {
123137
d_ptr->stackedWidget->setCurrentWidget(d_ptr->icoConverterWidget);
124138
}));
@@ -139,4 +153,22 @@ void MainWindow::initMenuBar()
139153
auto recordWidget = new RecordWidget;
140154
recordWidget->show();
141155
});
142-
}
156+
}
157+
158+
void MainWindow::buildConnect()
159+
{
160+
connect(d_ptr->imageViewer,
161+
&ImageViewer::jumpToMultiPage,
162+
this,
163+
&MainWindow::onJumpToMultiImageFileViewer);
164+
connect(d_ptr->openglViewer,
165+
&OpenglViewer::jumpToMultiPage,
166+
this,
167+
&MainWindow::onJumpToMultiImageFileViewer);
168+
#ifdef BUILD_VULKAN
169+
connect(d_ptr->vulkanViewer,
170+
&VulkanViewer::jumpToMultiPage,
171+
this,
172+
&MainWindow::onJumpToMultiImageFileViewer);
173+
#endif
174+
}

examples/graphics/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ class MainWindow : public QMainWindow
99
explicit MainWindow(QWidget *parent = nullptr);
1010
~MainWindow() override;
1111

12+
private slots:
13+
void onJumpToMultiImageFileViewer(const QString &url);
14+
1215
private:
1316
void setupUI();
1417
void initMenuBar();
18+
void buildConnect();
1519

1620
class MainWindowPrivate;
1721
QScopedPointer<MainWindowPrivate> d_ptr;

examples/graphics/multiimagefileviewer.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ MultiImageFileViewer::MultiImageFileViewer(QWidget *parent)
3030

3131
MultiImageFileViewer::~MultiImageFileViewer() {}
3232

33+
void MultiImageFileViewer::setImageUrl(const QString &url)
34+
{
35+
if (url.isEmpty()) {
36+
return;
37+
}
38+
d_ptr->imageView->createScene(url);
39+
}
40+
3341
void MultiImageFileViewer::onOpenImage()
3442
{
3543
const QString imageFilters(tr("Images (*.ico *.gif)"));

examples/graphics/multiimagefileviewer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class MultiImageFileViewer : public Viewer
99
explicit MultiImageFileViewer(QWidget *parent = nullptr);
1010
~MultiImageFileViewer() override;
1111

12+
void setImageUrl(const QString &url);
13+
1214
private slots:
1315
void onOpenImage();
1416
void onChangedImage(int index);

examples/graphics/openglviewer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OpenglViewer::OpenglViewer(QWidget *parent)
2727
{
2828
setupUI();
2929
buildConnect();
30+
setEnableJumpToMultiPage(true);
3031
}
3132

3233
OpenglViewer::~OpenglViewer() {}
@@ -71,6 +72,7 @@ QWidget *OpenglViewer::toolWidget()
7172
auto *rightLayout = new QVBoxLayout(widget);
7273
rightLayout->addWidget(m_openButton);
7374
rightLayout->addWidget(m_infoBox);
75+
rightLayout->addWidget(m_jumpToMultiPageButton);
7476
rightLayout->addStretch();
7577

7678
return widget;

0 commit comments

Comments
 (0)