Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit dc41731

Browse files
committed
更新清空布局的算法,添加更改图片参考宽度的设置
1 parent 63b66a6 commit dc41731

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/PicFlowView.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <QApplication>
44
#include <QDialog>
55
#include <QDir>
6+
#include <QDoubleSpinBox>
67
#include <QHBoxLayout>
8+
#include <QInputDialog>
79
#include <QLabel>
810
#include <QList>
911
#include <QMenu>
@@ -36,8 +38,6 @@ PicFlowView::PicFlowView(QObject* const parent)
3638

3739
scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
3840
scrollWidget->setWidget(box);
39-
// 设置图片的理想宽度
40-
content_->setWidgetWidth(300);
4141
}
4242

4343
PicFlowView::~PicFlowView() noexcept {
@@ -89,21 +89,29 @@ void PicFlowView::setup(QObject* const parent) {
8989
ac->setObjectName(QLatin1String("PiclLowView"));
9090
ac->setActionCategory(DPluginAction::ActionCategory::GenericView);
9191
ac->setText("PicFlowView");
92+
// 添加菜单项
93+
auto setting = new QMenu;
94+
auto widthAction = setting->addAction(tr("设置参考宽度"));
95+
widthAction->setWhatsThis(tr("设置图片的参考宽度,图片的宽度会在更<b>倾向于</b>选择此宽度"));
96+
// 添加设置
97+
connect(widthAction, &QAction::triggered, [this]() {
98+
bool ok = false;
99+
auto result = QInputDialog::getDouble(nullptr, tr("输入参考宽度"), tr("参考宽度"), 300, 10, 9999, 1, &ok);
100+
if(ok) this->width_ = result;
101+
});
102+
ac->setMenu(setting);
92103
connect(ac, &DPluginAction::triggered, this, &PicFlowView::flowView);
93104
addAction(ac);
94-
95105
}
96106

97107
void PicFlowView::flowView() {
98108
auto* const iface = infoIface(sender());
99-
// 首先清空容器内
100-
if(content_){
101-
auto parent = content_->parentWidget();
102-
parent->setLayout(nullptr);
103-
delete content_;
104-
content_ = new Z::FlowLayout;
105-
content_->setWidgetWidth(300);
106-
parent->setLayout(content_);
109+
// 设置图片的参考宽度
110+
content_->setWidgetWidth(width_);
111+
// 首先清空容器内的元素
112+
while(content_->list().length()) {
113+
// 若容器内的元素不为零
114+
content_->takeAt(0);
107115
}
108116
for(auto& item: iface->currentAlbumItems()) {
109117
QString imgPath = item.toString().replace("file://", "");

src/PicFlowView.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#ifndef DIGIKAMFLOWPLUGIN_DIGIKAMFLOWPLUGIN
22
#define DIGIKAMFLOWPLUGIN_DIGIKAMFLOWPLUGIN
33

4-
#include <digikam/dplugingeneric.h>
54
#include <digikam/coredbaccess.h>
6-
5+
#include <digikam/dplugingeneric.h>
76

87
#include <flowlayout.h>
98

@@ -37,6 +36,11 @@ class PicFlowView : public DPluginGeneric {
3736
bool eventFilter(QObject* watched, QEvent* event) override;
3837

3938
private:
39+
/**
40+
* @brief 图片的参考宽度
41+
*
42+
*/
43+
qreal width_ = 300;
4044
QDialog* main_dialog_;
4145
Z::FlowLayout* content_;
4246
};

0 commit comments

Comments
 (0)