1/* This file is part of the KDE project
2 Copyright (C) 2004 Esben Mose Hansen <kde@mosehansen.dk>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19#ifndef POPUPPROXY_H
20#define POPUPPROXY_H
21
22#include <QtCore/QObject>
23#include <QtCore/QRegExp>
24
25#include "history.h"
26
27class KMenu;
28
29class HistoryItem;
30class KlipperPopup;
31
32/**
33 * Proxy helper for the "more" menu item
34 *
35 */
36class PopupProxy : public QObject
37{
38 Q_OBJECT
39
40public:
41 /**
42 * Inserts up to itemsPerMenu into parent from parent->youngest(),
43 * and spills any remaining items into a more menu.
44 */
45 PopupProxy( KlipperPopup* parent, int menu_height, int menu_width );
46
47 KlipperPopup* parent();
48
49 /**
50 * Called when rebuilding the menu
51 * Deletes any More menus.. and start (re)inserting into the toplevel menu.
52 * @param index Items are inserted at index.
53 * @param filter If non-empty, only insert items that match filter as a regex
54 * @return number of items inserted.
55 */
56 int buildParent( int index, const QRegExp& filter = QRegExp() );
57
58public Q_SLOTS:
59 void slotAboutToShow();
60 void slotHistoryChanged();
61private:
62 /**
63 * Insert up to m_itemsPerMenu items from spill and a new
64 * more-menu if necessary.
65 * @param index Items are inserted at index
66 * @return number of items inserted.
67 */
68 int insertFromSpill( int index = 0 );
69
70 /**
71 * Insert item into proxy_for_menu at index,
72 * subtracting the items height from remainingHeight
73 */
74 void tryInsertItem( HistoryItem const * const item, int& remainingHeight, const int index );
75
76 /**
77 * Delete all "More..." menus current created.
78 */
79 void deleteMoreMenus();
80
81private:
82 KMenu* m_proxy_for_menu;
83 QByteArray m_spill_uuid;
84 QRegExp m_filter;
85 int m_menu_height;
86 int m_menu_width;
87};
88
89#endif
90