displaynameeditwidget.h 2.56 KB
Newer Older
1
/*
Tobias Koenig's avatar
Tobias Koenig committed
2
    This file is part of Akonadi Contact.
3 4 5

    Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>

Tobias Koenig's avatar
Tobias Koenig committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19
    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library 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 Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
20 21 22 23 24
*/

#ifndef DISPLAYNAMEEDITWIDGET_H
#define DISPLAYNAMEEDITWIDGET_H

25
#include <QWidget>
26

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
27
#include <kcontacts/addressee.h>
28

29 30
class KComboBox;

31 32 33 34 35 36 37 38
/**
 * @short A widget for editing the display name of a contact.
 *
 * The widget will either use a predefined schema for formatting
 * the name or a custom one.
 */
class DisplayNameEditWidget : public QWidget
{
Guy Maurel's avatar
Guy Maurel committed
39
    Q_OBJECT
40

Guy Maurel's avatar
Guy Maurel committed
41
public:
42 43 44
    /**
     * Describes what the display name should look like.
     */
45
    enum DisplayType {
Guy Maurel's avatar
Guy Maurel committed
46 47 48 49 50 51
        SimpleName,           ///< A name of the form: givenName familyName
        FullName,             ///< A name of the form: prefix givenName additionalName familyName suffix
        ReverseNameWithComma, ///< A name of the form: familyName, givenName
        ReverseName,          ///< A name of the form: familyName givenName
        Organization,         ///< The organization name
        CustomName            ///< Let the user input a display name
52 53
    };

Laurent Montel's avatar
Laurent Montel committed
54
    explicit DisplayNameEditWidget(QWidget *parent = nullptr);
55 56
    ~DisplayNameEditWidget();

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
57 58
    void loadContact(const KContacts::Addressee &contact);
    void storeContact(KContacts::Addressee &contact) const;
59

Guy Maurel's avatar
Guy Maurel committed
60
    void setReadOnly(bool readOnly);
61

Guy Maurel's avatar
Guy Maurel committed
62
    void setDisplayType(DisplayType type);
63 64
    DisplayType displayType() const;

Guy Maurel's avatar
Guy Maurel committed
65
public Q_SLOTS:
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
66
    void changeName(const KContacts::Addressee &contact);
Guy Maurel's avatar
Guy Maurel committed
67
    void changeOrganization(const QString &organization);
68

Guy Maurel's avatar
Guy Maurel committed
69
protected:
70
    bool eventFilter(QObject *object, QEvent *event) override;
71

Laurent Montel's avatar
Laurent Montel committed
72
private:
Guy Maurel's avatar
Guy Maurel committed
73 74
    void displayTypeChanged(int);
    void setComboBoxEditable(bool);
75 76
    void updateView();

77
    KComboBox *mView;
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
78
    KContacts::Addressee mContact;
79
    QWidget *mViewport;
Laurent Montel's avatar
Laurent Montel committed
80
    DisplayType mDisplayType;
81
    int mAdditionalPopupWidth;
82 83 84
};

#endif