File indexing completed on 2024-04-28 15:39:43

0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team
0002 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef ANNOTATIONDIALOG_COMPLETABLELINEEDIT_H
0007 #define ANNOTATIONDIALOG_COMPLETABLELINEEDIT_H
0008 
0009 #include <kpabase/enums.h>
0010 
0011 #include <KLineEdit>
0012 class QKeyEvent;
0013 class QTreeWidget;
0014 class QTreeWidgetItem;
0015 
0016 namespace AnnotationDialog
0017 {
0018 class ListSelect;
0019 class ResizableFrame;
0020 
0021 class CompletableLineEdit : public KLineEdit
0022 {
0023 
0024 public:
0025     /**
0026      * @brief This is just a convenience constructor for the common use-case when the lineEdit is inside a ListSelect.
0027      * @param parent
0028      */
0029     explicit CompletableLineEdit(ListSelect *parent);
0030     explicit CompletableLineEdit(ListSelect *ls, QWidget *parent);
0031     void setListView(QTreeWidget *);
0032     /**
0033      * @brief If the mode is SearchMode, only items that exist in the ListSelect can be entered.
0034      * @param mode
0035      */
0036     void setMode(UsageMode mode);
0037     void keyPressEvent(QKeyEvent *ev) override;
0038 
0039 protected:
0040     QTreeWidgetItem *findItemInListView(const QString &startWith);
0041     bool isSpecialKey(QKeyEvent *);
0042     void handleSpecialKeysInSearch(QKeyEvent *);
0043     bool itemMatchesText(QTreeWidgetItem *item, const QString &text);
0044     void selectPrevNextMatch(bool next);
0045     void selectItemAndUpdateLineEdit(QTreeWidgetItem *item, int itemStart, const QString &inputText);
0046     void mergePreviousImageSelection();
0047 
0048 private:
0049     QTreeWidget *m_listView = nullptr;
0050     UsageMode m_mode = UsageMode::InputSingleImageConfigMode;
0051     ListSelect *m_listSelect = nullptr;
0052 };
0053 }
0054 
0055 #endif /* ANNOTATIONDIALOG_COMPLETABLELINEEDIT_H */
0056 
0057 // vi:expandtab:tabstop=4 shiftwidth=4: