3333
3434namespace Cathaysia {
3535
36- PicFlowView::PicFlowView (QObject* const parent)
37- : DPluginGeneric { parent }, main_dialog_ { new QDialog }, content_ { new Z::FlowLayout } {
38- // 图片的容器的宽度与主窗口保持一致
39- main_dialog_->installEventFilter (this );
40- // 添加 QScrollArea 及其环境
41- auto mainLayout = new QHBoxLayout;
42- auto scrollWidget = new QScrollArea;
43- auto box = new QWidget;
44-
45- content_->setParent (box);
46-
47- main_dialog_->setLayout (mainLayout);
48- mainLayout->addWidget (scrollWidget);
49- box->setLayout (content_);
36+ PicFlowView::PicFlowView (QObject* const parent) : DPluginGeneric { parent } { }
5037
51- scrollWidget->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
52- scrollWidget->setWidget (box);
53- }
54-
55- PicFlowView::~PicFlowView () noexcept {
56- if (main_dialog_) delete main_dialog_;
57- if (content_) delete content_;
58- }
38+ PicFlowView::~PicFlowView () noexcept { }
5939
6040QString PicFlowView::name () const {
6141 return tr (" PicFlowPlugin" );
@@ -88,8 +68,11 @@ QList<Digikam::DPluginAuthor> PicFlowView::authors() const {
8868// clang-format on
8969
9070bool PicFlowView::eventFilter (QObject* watched, QEvent* event) {
71+ auto dialog = qobject_cast<QDialog*>(watched);
72+ if (!dialog) return false ;
9173 if (event->type () == QEvent::Resize) {
92- content_->parentWidget ()->resize (main_dialog_->width (), content_->innerHeight ());
74+ auto content = dialog->findChild <Z::FlowLayout*>(" FlowLayout" );
75+ content->parentWidget ()->resize (dialog->width (), content->innerHeight ());
9376 return true ;
9477 } else if (event->type () == QEvent::Close) {
9578 stop_ = true ;
@@ -114,29 +97,58 @@ void PicFlowView::setup(QObject* const parent) {
11497 // 添加设置
11598 connect (widthAction, &QAction::triggered, [this ]() {
11699 bool ok = false ;
117- auto result = QInputDialog::getDouble (nullptr , tr (" 输入参考宽度" ), tr (" 参考宽度" ), 300 , 10 , 9999 , 1 , &ok);
118- if (ok) this ->width_ = result;
100+ auto result = QInputDialog::getDouble (nullptr , tr (" 输入参考宽度" ), tr (" 参考宽度" ), width_, 10 , 9999 ,
101+ 1 , &ok);
102+ if (ok) {
103+ this ->width_ = result;
104+ emit widthChanged (result);
105+ };
119106 });
120107 ac->setMenu (setting);
121108 connect (ac, &DPluginAction::triggered, this , &PicFlowView::flowView);
122109 addAction (ac);
123110}
124111
112+ Cathaysia::PicFlowView::ShareData PicFlowView::getShareData () {
113+ auto mainDialog = new QDialog;
114+ auto mainLayout = new Z::FlowLayout;
115+ mainLayout->setObjectName (" FlowLayout" );
116+
117+ // 图片的容器的宽度与主窗口保持一致
118+ mainDialog->installEventFilter (this );
119+ // 添加 QScrollArea 及其环境
120+ auto dialogLayout = new QHBoxLayout;
121+ auto scrollWidget = new QScrollArea;
122+ auto box = new QWidget;
123+
124+ mainLayout->setParent (box);
125+
126+ mainDialog->setLayout (dialogLayout);
127+ dialogLayout->addWidget (scrollWidget);
128+ box->setLayout (mainLayout);
129+
130+ scrollWidget->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
131+ scrollWidget->setWidget (box);
132+ // 设置图片的参考宽度
133+ mainLayout->setWidgetWidth (width_);
134+ //
135+ connect (this , &PicFlowView::widthChanged, mainLayout, &Z::FlowLayout::setWidgetWidth);
136+ return ShareData (mainDialog, mainLayout);
137+ }
138+
125139void PicFlowView::flowView () {
126140 auto * const iface = infoIface (sender ());
127- // 设置图片的参考宽度
128- content_->setWidgetWidth (width_);
129- // 首先清空容器内的元素
130- while (content_->list ().length ()) {
131- auto item = content_->takeAt (0 );
132- // 防止第二次添加时出现重叠问题
133- item->widget ()->setParent (nullptr );
134- delete item;
135- }
141+ /* *
142+ * @todo 1. 是否让多个窗口共用一个锁(现在不是)
143+ *
144+ */
145+ auto shareData = getShareData ();
146+ auto mainDialog = shareData.first ;
147+ auto mainLayout = shareData.second ;
136148 // 先显示
137- content_ ->parentWidget ()->resize (800 , content_ ->innerHeight ());
138- main_dialog_ ->resize (800 , 600 );
139- main_dialog_ ->show ();
149+ mainLayout ->parentWidget ()->resize (800 , mainLayout ->innerHeight ());
150+ mainDialog ->resize (800 , 600 );
151+ mainDialog ->show ();
140152
141153 std::list<QPixmap> imgBuf;
142154 std::atomic_bool over = false ;
@@ -199,7 +211,7 @@ void PicFlowView::flowView() {
199211 empty.release ();
200212 // 离开临界区
201213 img->setScaledContents (true );
202- content_ ->addWidget (img);
214+ mainLayout ->addWidget (img);
203215 // 防止界面卡顿
204216 qApp->processEvents ();
205217 }
0 commit comments