progressdialog.h 4.21 KB
Newer Older
1
2
3
/* -*- c++ -*-
 * progressdialog.h
 *
4
 *  SPDX-FileCopyrightText: 2004 Till Adam <adam@kde.org>
5
 *  based on imapprogressdialog.cpp ,which is
6
 *  SPDX-FileCopyrightText: 2002-2003 Klarälvdalens Datakonsult AB
7
 *
8
 *  SPDX-License-Identifier: GPL-2.0-or-later
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 */

#ifndef KDEPIM_PROGRESSDIALOG_H
#define KDEPIM_PROGRESSDIALOG_H

#include "kdepim_export.h"

#include "progressmanager.h"

#include <QScrollArea>
#include <QMap>

class QProgressBar;
class QFrame;
class QLabel;
class QPushButton;

Laurent Montel's avatar
Laurent Montel committed
26
namespace KPIM {
27
28
29
class TransactionItem;
class SSLLabel;

30
31
32
33
34
35
36
/**
 * This is a widget that can align itself with another one, without using a layout,
 * so that it can actually be on top of other widgets.
 * Currently the only supported type of alignment is "right aligned, on top of the other widget".
 *
 */
class OverlayWidgetPrivate;
Daniel Vrátil's avatar
Daniel Vrátil committed
37
class KDEPIM_EXPORT OverlayWidget : public QFrame
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
    Q_OBJECT

public:
    OverlayWidget(QWidget *alignWidget, QWidget *parent);
    ~OverlayWidget() override;

    Q_REQUIRED_RESULT QWidget *alignWidget() const;
    void setAlignWidget(QWidget *alignWidget);

protected:
    void resizeEvent(QResizeEvent *ev) override;
    bool eventFilter(QObject *o, QEvent *e) override;

private:
    void reposition();

private:
    OverlayWidgetPrivate *const d;
};

59
60
61
62
class TransactionItemView : public QScrollArea
{
    Q_OBJECT
public:
Laurent Montel's avatar
Laurent Montel committed
63
    explicit TransactionItemView(QWidget *parent = nullptr, const QString &name = QString());
64

Laurent Montel's avatar
Laurent Montel committed
65
    ~TransactionItemView() override
Laurent Montel's avatar
Laurent Montel committed
66
67
68
    {
    }

69
70
    TransactionItem *addTransactionItem(ProgressItem *item, bool first);

71
72
    QSize sizeHint() const override;
    QSize minimumSizeHint() const override;
73
74
75
76
77

public Q_SLOTS:
    void slotLayoutFirstItem();

protected:
78
    void resizeEvent(QResizeEvent *event) override;
79
80

private:
Laurent Montel's avatar
Laurent Montel committed
81
    QWidget *mBigBox = nullptr;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
};

class TransactionItem : public QWidget
{
    Q_OBJECT
public:
    TransactionItem(QWidget *parent, ProgressItem *item, bool first);

    ~TransactionItem();

    void hideHLine();

    void setProgress(int progress);
    void setLabel(const QString &);

    // the given text is interpreted as RichText, so you might need to
    // .toHtmlEscaped() it before passing
    void setStatus(const QString &);

    void setCryptoStatus(KPIM::ProgressItem::CryptoStatus);
    void setTotalSteps(int totalSteps);

    ProgressItem *item() const
    {
        return mItem;
    }

    void addSubTransaction(ProgressItem *item);

    // The progressitem is deleted immediately, we take 5s to go out,
    // so better not use mItem during this time.
    void setItemComplete()
    {
Laurent Montel's avatar
Laurent Montel committed
115
        mItem = nullptr;
116
117
118
119
120
121
    }

public Q_SLOTS:
    void slotItemCanceled();

protected:
Laurent Montel's avatar
Laurent Montel committed
122
123
124
125
126
127
128
    QProgressBar *mProgress = nullptr;
    QPushButton *mCancelButton = nullptr;
    QLabel *mItemLabel = nullptr;
    QLabel *mItemStatus = nullptr;
    QFrame *mFrame = nullptr;
    SSLLabel *mSSLLabel = nullptr;
    ProgressItem *mItem = nullptr;
129
130
131
132
133
134
135
};

class KDEPIM_EXPORT ProgressDialog : public OverlayWidget
{
    Q_OBJECT
public:
    ProgressDialog(QWidget *alignWidget, QWidget *parent);
Laurent Montel's avatar
Laurent Montel committed
136
    ~ProgressDialog() override;
137
    void setVisible(bool b) override;
138
139
140

    void setShowTypeProgressItem(unsigned int type);

Laurent Montel's avatar
Laurent Montel committed
141
142
    bool wasLastShown() const;

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
public Q_SLOTS:
    void slotToggleVisibility();

protected Q_SLOTS:
    void slotTransactionAdded(KPIM::ProgressItem *item);
    void slotTransactionCompleted(KPIM::ProgressItem *item);
    void slotTransactionCanceled(KPIM::ProgressItem *item);
    void slotTransactionProgress(KPIM::ProgressItem *item, unsigned int progress);
    void slotTransactionStatus(KPIM::ProgressItem *item, const QString &);
    void slotTransactionLabel(KPIM::ProgressItem *item, const QString &);
    void slotTransactionCryptoStatus(KPIM::ProgressItem *item, KPIM::ProgressItem::CryptoStatus);
    void slotTransactionUsesBusyIndicator(KPIM::ProgressItem *, bool);

    void slotClose();
    void slotShow();
    void slotHide();

Q_SIGNALS:
    void visibilityChanged(bool);

protected:
164
    void closeEvent(QCloseEvent *) override;
165

Laurent Montel's avatar
Laurent Montel committed
166
    TransactionItemView *mScrollView = nullptr;
167
    QMap<const ProgressItem *, TransactionItem *> mTransactionsToListviewItems;
Laurent Montel's avatar
Laurent Montel committed
168
169
    unsigned int mShowTypeProgressItem = 0;
    bool mWasLastShown = false;
170
171
172
173
};
} // namespace KPIM

#endif // __KPIM_PROGRESSDIALOG_H__