File indexing completed on 2024-11-24 04:39:31
0001 /* 0002 This file is part of Contact Editor. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QWidget> 0012 0013 #include <KContacts/Addressee> 0014 0015 class KComboBox; 0016 0017 /** 0018 * @short A widget for editing the display name of a contact. 0019 * 0020 * The widget will either use a predefined schema for formatting 0021 * the name or a custom one. 0022 */ 0023 namespace Akonadi 0024 { 0025 class DisplayNameEditWidget : public QWidget 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * Describes what the display name should look like. 0032 */ 0033 enum DisplayType { 0034 SimpleName, ///< A name of the form: givenName familyName 0035 FullName, ///< A name of the form: prefix givenName additionalName familyName suffix 0036 ReverseNameWithComma, ///< A name of the form: familyName, givenName 0037 ReverseName, ///< A name of the form: familyName givenName 0038 Organization, ///< The organization name 0039 CustomName ///< Let the user input a display name 0040 }; 0041 0042 explicit DisplayNameEditWidget(QWidget *parent = nullptr); 0043 ~DisplayNameEditWidget() override; 0044 0045 void loadContact(const KContacts::Addressee &contact); 0046 void storeContact(KContacts::Addressee &contact) const; 0047 0048 void setReadOnly(bool readOnly); 0049 0050 void setDisplayType(DisplayType type); 0051 [[nodiscard]] DisplayType displayType() const; 0052 0053 public Q_SLOTS: 0054 void changeName(const KContacts::Addressee &contact); 0055 void changeOrganization(const QString &organization); 0056 0057 protected: 0058 bool eventFilter(QObject *object, QEvent *event) override; 0059 0060 private: 0061 void displayTypeChanged(int); 0062 void setComboBoxEditable(bool); 0063 void updateView(); 0064 0065 KComboBox *mView = nullptr; 0066 KContacts::Addressee mContact; 0067 QWidget *mViewport = nullptr; 0068 DisplayType mDisplayType = DisplayType::SimpleName; 0069 int mAdditionalPopupWidth; 0070 }; 0071 }