simplestringlisteditor.h 4.04 KB
Newer Older
1
2
3
4
5
6
/*  -*- c++ -*-
    simplestringlisteditor.h

    This file is part of KMail, the KDE mail client.
    Copyright (c) 2001 Marc Mutz <mutz@kde.org>

Laurent Montel's avatar
Laurent Montel committed
7
    Copyright (C) 2013-2019 Laurent Montel <montel@kde.org>
8
9

    KMail is free software; you can redistribute it and/or modify it
10
11
12
    under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

    KMail is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    In addition, as a special exception, the copyright holders give
    permission to link the code of this program with any edition of
    the Qt library by Trolltech AS, Norway (or with modified versions
    of Qt that use the same license as Qt), and distribute linked
    combinations including the two.  You must obey the GNU General
    Public License in all respects for all of the code used other than
    Qt.  If you modify this file, you may extend this exception to
    your version of the file, but you are not obligated to do so.  If
    you do not wish to do so, delete this exception statement from
    your version.
*/

35
36
#ifndef SIMPLESTRINGLISTEDITOR_H
#define SIMPLESTRINGLISTEDITOR_H
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#include <QWidget>
#include <QStringList>

#include "pimcommon_export.h"

class QListWidget;
class QListWidgetItem;

//
//
// SimpleStringListEditor (a listbox with "add..." and "remove" buttons)
//
//
Laurent Montel's avatar
Laurent Montel committed
51
namespace PimCommon {
Laurent Montel's avatar
Laurent Montel committed
52
class SimpleStringListEditorPrivate;
53
54
55
56
/**
 * @brief The SimpleStringListEditor class
 * @author Laurent Montel <montel@kde.org>
 */
57
58
59
60
61
class PIMCOMMON_EXPORT SimpleStringListEditor : public QWidget
{
    Q_OBJECT
public:
    enum ButtonCode {
Laurent Montel's avatar
Laurent Montel committed
62
63
64
65
66
67
68
        None = 0,
        Add = 1,
        Remove = 2,
        Modify = 4,
        Up = 8,
        Down = 16,
        Custom = 32,
69
70
71
72
73
        All = Add | Remove | Modify | Up | Down,
        Unsorted = Add | Remove | Modify
    };

    /** Constructor. Populates the list with @p strings. */
Laurent Montel's avatar
Laurent Montel committed
74
75
    explicit SimpleStringListEditor(QWidget *parent = nullptr, ButtonCode buttons = Unsorted, const QString &addLabel = QString(),
                                    const QString &removeLabel = QString(), const QString &modifyLabel = QString(), const QString &addDialogLabel = QString());
76

Laurent Montel's avatar
Laurent Montel committed
77
    ~SimpleStringListEditor() override;
78
79
80
81
82
83
84
    /** Sets the list of strings displayed to @p strings */
    void setStringList(const QStringList &strings);

    /** Adds @p strings to the list of displayed strings */
    void appendStringList(const QStringList &strings);

    /** Retrieves the current list of strings */
Laurent Montel's avatar
Laurent Montel committed
85
    Q_REQUIRED_RESULT QStringList stringList() const;
86
87
88
89
90

    /** Sets the text of button @p button to @p text */
    void setButtonText(ButtonCode button, const QString &text);

    void setUpDownAutoRepeat(bool b);
Laurent Montel's avatar
Laurent Montel committed
91
    Q_REQUIRED_RESULT QSize sizeHint() const override;
92
93

    virtual void addNewEntry();
Laurent Montel's avatar
Laurent Montel committed
94
95
    virtual void customEntry();

Laurent Montel's avatar
Laurent Montel committed
96
    Q_REQUIRED_RESULT virtual QString modifyEntry(const QString &text);
97
98
    void setAddDialogLabel(const QString &addDialogLabel);

99
    void setRemoveDialogLabel(const QString &removeDialogLabel);
100
101
102
103
104
Q_SIGNALS:
    /** Connected slots can alter the argument to be added or set the
      argument to QString() to suppress adding.
    */
    void aboutToAdd(QString &);
105
    void changed();
106
107
108
109
110
111
112
113
114
115

protected:
    void insertNewEntry(const QString &newEntry);

protected Q_SLOTS:
    void slotAdd();
    void slotRemove();
    void slotModify();
    void slotUp();
    void slotDown();
Laurent Montel's avatar
Laurent Montel committed
116
    void slotCustomize();
117
118
119
120

    void slotSelectionChanged();

private:
Laurent Montel's avatar
Laurent Montel committed
121
    void slotContextMenu(const QPoint &);
122
    bool containsString(const QString &str);
Laurent Montel's avatar
Laurent Montel committed
123
    SimpleStringListEditorPrivate *const d;
124
125
126
};
}

127
#endif // SIMPLESTRINGLISTEDITOR_H