File indexing completed on 2024-05-19 05:06:53
0001 /* 0002 * SPDX-FileCopyrightText: 2024 Thomas Baumgart <tbaumgart@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef TAGCREATOR_H 0007 #define TAGCREATOR_H 0008 0009 #include "kmm_base_dialogs_export.h" 0010 0011 // ---------------------------------------------------------------------------- 0012 // QT Includes 0013 0014 #include <QObject> 0015 class QAbstractButton; 0016 class KTagContainer; 0017 0018 // ---------------------------------------------------------------------------- 0019 // KDE Headers 0020 0021 // ---------------------------------------------------------------------------- 0022 // Project Includes 0023 0024 /** 0025 * This class implements the creation of a new tag 0026 * based on the data provided through a KTagContainer. 0027 * It can be called within a focusOut event handler to check 0028 * if the text contained in the combobox of the KTagContainer 0029 * refers to an existing item or needs to create a new one. 0030 * 0031 * If the tag is created, it will be added to the KTagContainer 0032 * and the focus is moved to the next widget. 0033 * If it is not created, the text will be removed in the 0034 * lineedit of the combobox and the focus remains in the 0035 * combobox. 0036 * 0037 * Since any editor buttons (enter, cancel, etc.) also issue 0038 * a focusOut event on the combobox, they need to be added 0039 * to this object using the @c addButton() method so that the 0040 * creation does not trigger when one of the buttons is 0041 * pressed. 0042 * 0043 * Use @c setComboBox() to identify the combobox to be used. 0044 * 0045 * Calling @c createTag() will start the creation process 0046 * delayed by at least 150ms and returns immediately. This period 0047 * is extended in case one of the buttons added using @c addButton() 0048 * is still pressed. In case the object is destroyed before the 0049 * waiting period elapses, the creation will not be triggered. 0050 * Once the creation is processed, the object destroys itself. 0051 */ 0052 class KMM_BASE_DIALOGS_EXPORT TagCreator : public QObject 0053 { 0054 Q_OBJECT 0055 public: 0056 explicit TagCreator(QObject* parent); 0057 0058 void addButton(QAbstractButton* button); 0059 void setTagContainer(KTagContainer* tagContainer); 0060 0061 public Q_SLOTS: 0062 void createTag(); 0063 0064 private: 0065 QList<QAbstractButton*> m_buttons; 0066 KTagContainer* m_tagContainer; 0067 QString m_name; 0068 }; 0069 0070 #endif // TAGCREATOR_H