1 /*
2  * This file is part of KMail.
3  * SPDX-FileCopyrightText: 2012-2021 Laurent Montel <montel@kde.org>
4  * SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
5  *
6  * Parts based on KMail code by:
7  * SPDX-FileCopyrightText: 2003 Ingo Kloecker <kloecker@kde.org>
8  * SPDX-FileCopyrightText: 2007 Thomas McGuire <Thomas.McGuire@gmx.net>
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 
13 #pragma once
14 
15 #include <KConfigGroup>
16 #include <QTreeView>
17 
18 class QContextMenuEvent;
19 class QToolButton;
20 class QLabel;
21 namespace MessageComposer
22 {
23 class AttachmentModel;
24 }
25 
26 namespace KMail
27 {
28 class AttachmentView : public QTreeView
29 {
30     Q_OBJECT
31 
32 public:
33     /// can't change model afterwards.
34     explicit AttachmentView(MessageComposer::AttachmentModel *model, QWidget *parent = nullptr);
35     ~AttachmentView() override;
36 
37     QWidget *widget() const;
38     void hideIfEmpty();
39 
40 protected:
41     /** reimpl to avoid default drag cursor */
42     void startDrag(Qt::DropActions supportedActions) override;
43     void contextMenuEvent(QContextMenuEvent *event) override;
44     void keyPressEvent(QKeyEvent *event) override;
45     /** reimpl to avoid drags from ourselves */
46     void dragEnterEvent(QDragEnterEvent *event) override;
47 
48 private:
49     void slotShowHideAttchementList(bool);
50     void saveHeaderState();
51     void restoreHeaderState();
52     /// model sets these
53     void setEncryptEnabled(bool enabled);
54     void setSignEnabled(bool enabled);
55     void selectNewAttachment();
56 
57     void updateAttachmentLabel();
58 
59 Q_SIGNALS:
60     void contextMenuRequested();
61     void modified(bool);
62 
63 private:
64     MessageComposer::AttachmentModel *const mModel;
65     QToolButton *const mToolButton;
66     QLabel *const mInfoAttachment;
67     QWidget *const mWidget;
68     KConfigGroup grp;
69 };
70 } // namespace KMail
71 
72