Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_delayed_save_dialog.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include "ui_kis_delayed_save_dialog.h"
9
10#include <QElapsedTimer>
11#include <QThread>
12#include <QTimer>
13#include <QtGlobal>
14
15#include "kis_debug.h"
16#include "kis_image.h"
18
19struct Q_DECL_HIDDEN KisDelayedSaveDialog::Private {
20 Private(KisImageSP _image, int _busyWait, Type _type) : image(_image), busyWait(_busyWait), type(_type) {}
21
25
27 const bool allowLocked = type != SaveDialog;
28 return image->isIdle(allowLocked);
29 }
30
32};
33
34class Q_DECL_HIDDEN WdgDelayedSaveDialog : public QWidget, public Ui::KisDelayedSaveDialog
35{
36 Q_OBJECT
37
38public:
39 WdgDelayedSaveDialog(QWidget *parent = nullptr)
40 : QWidget(parent)
41 {
42 setupUi(this);
43 }
44};
45
46KisDelayedSaveDialog::KisDelayedSaveDialog(KisImageSP image, Type type, int busyWait, QWidget *parent)
47 : KoDialog(parent)
48 , ui(new WdgDelayedSaveDialog())
49 , m_d(new Private(image, busyWait, type))
50{
52
54
55 if (type == SaveDialog) {
57 setButtonText(KoDialog::Ok, i18n("Save without waiting"));
58 setButtonText(KoDialog::Cancel, i18n("Cancel operation and save"));
59 setButtonText(KoDialog::User1, i18n("Close, do not save"));
60
62
64
65 connect(this, &KoDialog::user1Clicked, this, &KisDelayedSaveDialog::reject);
66 } else if (type == GeneralDialog) {
68 connect(this, &KoDialog::cancelClicked, &KisDelayedSaveDialog::reject);
69 } else { // type == ForcedDialog, disable closing
71 setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
72 }
73
74 connect(&m_d->updateTimer, &QTimer::timeout, this, &KisDelayedSaveDialog::slotTimerTimeout);
75
76 m_d->image->compositeProgressProxy()->addProxy(ui->progressBar);
77
78 resize(sizeHint());
79}
80
82{
83 m_d->image->compositeProgressProxy()->removeProxy(ui->progressBar);
84 delete ui;
85}
86
88{
89 if (m_d->checkImageIdle()) {
90 setResult(Accepted);
91 return;
92 }
93
94 m_d->image->requestStrokeEnd();
95
96 QElapsedTimer t;
97 t.start();
98
99 while (t.elapsed() < m_d->busyWait) {
100 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
101
102 if (m_d->checkImageIdle()) {
103 setResult(Accepted);
104 return;
105 }
106
107 QThread::yieldCurrentThread();
108 }
109
110 m_d->updateTimer.start(200);
111 exec();
112 m_d->updateTimer.stop();
113}
114
116{
117 if (m_d->checkImageIdle()) {
118 accept();
119 }
120}
121
123{
124 m_d->image->requestStrokeCancellation();
125}
126
131
132#include "kis_delayed_save_dialog.moc"
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool isIdle(bool allowLocked=false)
Definition kis_image.cc:788
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void user1Clicked()
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
void setButtonText(ButtonCode id, const QString &text)
Definition KoDialog.cpp:648
QSize sizeHint() const override
Definition KoDialog.cpp:377
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void cancelClicked()
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition KoDialog.h:127
@ User1
Show User defined button 1.
Definition KoDialog.h:136
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130
void okClicked()
WdgDelayedSaveDialog(QWidget *parent=nullptr)
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97
Private(KisImageSP _image, int _busyWait, Type _type)
KisDelayedSaveDialog(KisImageSP image, Type type, int busyWait, QWidget *parent=nullptr)
const QScopedPointer< Private > m_d
WdgDelayedSaveDialog * ui