Changeset View
Changeset View
Standalone View
Standalone View
klipper/popupproxy.cpp
Show All 12 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 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 | 15 | along with this program; see the file COPYING. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | #include "popupproxy.h" | 19 | #include "popupproxy.h" | ||
20 | 20 | | |||
21 | #include <QRegExp> | | |||
22 | #include <QStyle> | 21 | #include <QStyle> | ||
23 | #include <QPixmap> | 22 | #include <QPixmap> | ||
24 | #include <QStyleOption> | 23 | #include <QStyleOption> | ||
25 | 24 | | |||
26 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
27 | 26 | | |||
28 | #include "historyitem.h" | 27 | #include "historyitem.h" | ||
29 | #include "history.h" | 28 | #include "history.h" | ||
30 | #include "klipperpopup.h" | 29 | #include "klipperpopup.h" | ||
31 | 30 | | |||
32 | | ||||
33 | PopupProxy::PopupProxy( KlipperPopup* parent, int menu_height, int menu_width ) | 31 | PopupProxy::PopupProxy( KlipperPopup* parent, int menu_height, int menu_width ) | ||
34 | : QObject( parent ), | 32 | : QObject( parent ), | ||
35 | m_proxy_for_menu( parent ), | 33 | m_proxy_for_menu( parent ), | ||
36 | m_spill_uuid(), | 34 | m_spill_uuid(), | ||
37 | m_menu_height( menu_height ), | 35 | m_menu_height( menu_height ), | ||
38 | m_menu_width( menu_width ) | 36 | m_menu_width( menu_width ) | ||
39 | { | 37 | { | ||
40 | if (!parent->history()->empty()) { | 38 | if (!parent->history()->empty()) { | ||
Show All 18 Lines | 55 | while ( m_proxy_for_menu != myParent ) { | |||
59 | m_proxy_for_menu = static_cast<QMenu*>( m_proxy_for_menu->parent() ); | 57 | m_proxy_for_menu = static_cast<QMenu*>( m_proxy_for_menu->parent() ); | ||
60 | } | 58 | } | ||
61 | // We are called probably from within the menus event-handler (triggered=>slotMoveToTop=>changed=>slotHistoryChanged=>deleteMoreMenus) | 59 | // We are called probably from within the menus event-handler (triggered=>slotMoveToTop=>changed=>slotHistoryChanged=>deleteMoreMenus) | ||
62 | // what can result in a crash if we just delete the menu here (#155196 and #165154) So, delay the delete. | 60 | // what can result in a crash if we just delete the menu here (#155196 and #165154) So, delay the delete. | ||
63 | delme->deleteLater(); | 61 | delme->deleteLater(); | ||
64 | } | 62 | } | ||
65 | } | 63 | } | ||
66 | 64 | | |||
67 | int PopupProxy::buildParent( int index, const QRegExp& filter ) { | 65 | int PopupProxy::buildParent( int index, const QRegularExpression &filter ) { | ||
68 | deleteMoreMenus(); | 66 | deleteMoreMenus(); | ||
69 | // Start from top of history (again) | 67 | // Start from top of history (again) | ||
70 | m_spill_uuid = parent()->history()->empty() ? QByteArray() : parent()->history()->first()->uuid(); | 68 | m_spill_uuid = parent()->history()->empty() ? QByteArray() : parent()->history()->first()->uuid(); | ||
71 | if ( filter.isValid() ) { | 69 | if ( filter.isValid() ) { | ||
72 | m_filter = filter; | 70 | m_filter = filter; | ||
73 | } | 71 | } | ||
74 | 72 | | |||
75 | return insertFromSpill( index ); | 73 | return insertFromSpill( index ); | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 138 | int PopupProxy::insertFromSpill( int index ) { | |||
149 | // stop when the total number of items equal m_itemsPerMenu; | 147 | // stop when the total number of items equal m_itemsPerMenu; | ||
150 | int count = 0; | 148 | int count = 0; | ||
151 | int remainingHeight = m_menu_height - m_proxy_for_menu->sizeHint().height(); | 149 | int remainingHeight = m_menu_height - m_proxy_for_menu->sizeHint().height(); | ||
152 | auto item = history->find(m_spill_uuid); | 150 | auto item = history->find(m_spill_uuid); | ||
153 | if (!item) { | 151 | if (!item) { | ||
154 | return count; | 152 | return count; | ||
155 | } | 153 | } | ||
156 | do { | 154 | do { | ||
157 | if ( m_filter.indexIn( item->text() ) != -1) { | 155 | if (m_filter.match(item->text()).hasMatch()) { | ||
158 | tryInsertItem( item.data(), remainingHeight, index++ ); | 156 | tryInsertItem( item.data(), remainingHeight, index++ ); | ||
159 | count++; | 157 | count++; | ||
160 | } | 158 | } | ||
161 | item = history->find(item->next_uuid()); | 159 | item = history->find(item->next_uuid()); | ||
162 | } while ( item && history->first() != item && remainingHeight >= 0); | 160 | } while ( item && history->first() != item && remainingHeight >= 0); | ||
163 | m_spill_uuid = item->uuid(); | 161 | m_spill_uuid = item->uuid(); | ||
164 | 162 | | |||
165 | // If there is more items in the history, insert a new "More..." menu and | 163 | // If there is more items in the history, insert a new "More..." menu and | ||
Show All 14 Lines |