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

0001 /*
0002     SPDX-FileCopyrightText: 2004 Esben Mose Hansen <kde@mosehansen.dk>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QObject>
0009 #include <QRegularExpression>
0010 
0011 #include "history.h"
0012 
0013 class QMenu;
0014 
0015 class HistoryItem;
0016 class KlipperPopup;
0017 
0018 /**
0019  * Proxy helper for the "more" menu item
0020  *
0021  */
0022 class PopupProxy : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     /**
0028      * Inserts up to itemsPerMenu into parent from parent->youngest(),
0029      * and spills any remaining items into a more menu.
0030      */
0031     PopupProxy(KlipperPopup *parent, int menu_height, int menu_width);
0032 
0033     KlipperPopup *parent();
0034 
0035     /**
0036      * Called when rebuilding the menu
0037      * Deletes any More menus.. and start (re)inserting into the toplevel menu.
0038      * @param index Items are inserted at index.
0039      * @param filter If non-empty, only insert items that match filter as a regex
0040      * @return number of items inserted.
0041      */
0042     int buildParent(int index, const QRegularExpression &filter = QRegularExpression());
0043 
0044 public Q_SLOTS:
0045     void slotAboutToShow();
0046     void slotHistoryChanged();
0047 
0048 private:
0049     /**
0050      * Insert up to m_itemsPerMenu items from spill and a new
0051      * more-menu if necessary.
0052      * @param index Items are inserted at index
0053      * @return number of items inserted.
0054      */
0055     int insertFromSpill(int index = 0);
0056 
0057     /**
0058      * Insert item into proxy_for_menu at index,
0059      * subtracting the items height from remainingHeight
0060      */
0061     void tryInsertItem(HistoryItem const *const item, int &remainingHeight, const int index);
0062 
0063     /**
0064      * Delete all "More..." menus current created.
0065      */
0066     void deleteMoreMenus();
0067 
0068 private:
0069     QMenu *m_proxy_for_menu;
0070     QByteArray m_spill_uuid;
0071     QRegularExpression m_filter;
0072     int m_menu_height;
0073     int m_menu_width;
0074 };