File indexing completed on 2024-04-28 16:54:25

0001 /*
0002     SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk>
0003     SPDX-FileCopyrightText: Andrew Stanley-Jones
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QList>
0009 
0010 #include <QMenu>
0011 
0012 class QAction;
0013 class QWidgetAction;
0014 class QKeyEvent;
0015 
0016 class KLineEdit;
0017 
0018 class PopupProxy;
0019 class History;
0020 
0021 /**
0022  * Default view of clipboard history.
0023  *
0024  */
0025 class KlipperPopup : public QMenu
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit KlipperPopup(History *history);
0031     ~KlipperPopup() override = default;
0032 
0033     /**
0034      * Normally, the popupmenu is only rebuilt just before showing.
0035      * If you need the pixel-size or similar of the this menu, call
0036      * this beforehand.
0037      */
0038     void ensureClean();
0039 
0040     History *history()
0041     {
0042         return m_history;
0043     }
0044     const History *history() const
0045     {
0046         return m_history;
0047     }
0048 
0049 public Q_SLOTS:
0050     void slotHistoryChanged()
0051     {
0052         m_dirty = true;
0053     }
0054     void slotTopIsUserSelectedSet();
0055     void slotAboutToShow();
0056     /**
0057      * set the top history item active, to easy kb navigation
0058      */
0059     void slotSetTopActive();
0060 
0061 private:
0062     void rebuild(const QString &filter = QString());
0063     void buildFromScratch();
0064     void showStatus(const QString &errorText);
0065 
0066 protected:
0067     void keyPressEvent(QKeyEvent *e) override;
0068     void showEvent(QShowEvent *e) override;
0069 
0070 private:
0071     bool m_dirty : 1; // true if menu contents needs to be rebuild.
0072 
0073     /**
0074      * The "document" (clipboard history)
0075      */
0076     History *m_history;
0077 
0078     /**
0079      * Proxy helper object used to track history items
0080      */
0081     PopupProxy *m_popupProxy;
0082 
0083     /**
0084      * search filter widget
0085      */
0086     KLineEdit *m_filterWidget;
0087 
0088     /**
0089      * Action of search widget
0090      */
0091     QWidgetAction *m_filterWidgetAction;
0092 
0093     /**
0094      * The last event which was received. Used to avoid an infinite event loop
0095      */
0096     QKeyEvent *m_lastEvent;
0097 };