1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org>
4 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
5 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org>
6 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org>
7 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org>
8 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org>
9 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org>
10 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org>
11 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org>
12 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org>
13 SPDX-FileCopyrightText: 2006 Albert Astals Cid <aacid@kde.org>
14 SPDX-FileCopyrightText: 2006 Clarence Dang <dang@kde.org>
15 SPDX-FileCopyrightText: 2006 Michel Hermier <michel.hermier@gmail.com>
16 SPDX-FileCopyrightText: 2007 Nick Shaforostoff <shafff@ukr.net>
17
18 SPDX-License-Identifier: LGPL-2.0-only
19*/
20
21#ifndef KSELECTACTION_P_H
22#define KSELECTACTION_P_H
23
24#include <QActionGroup>
25#include <QComboBox>
26
27class KSelectActionPrivate
28{
29 Q_DECLARE_PUBLIC(KSelectAction)
30
31public:
32 KSelectActionPrivate(KSelectAction *qq)
33 : q_ptr(qq)
34 {
35 m_edit = false;
36 m_menuAccelsEnabled = true;
37 m_comboWidth = -1;
38 m_maxComboViewCount = -1;
39
40 m_toolBarMode = KSelectAction::ComboBoxMode;
41 m_toolButtonPopupMode = QToolButton::InstantPopup; // InstantPopup by default because there is no default action
42
43 m_actionGroup = new QActionGroup(nullptr);
44 }
45
46 // virtual so the derived private class for e.g. KRecentFilesAction can be deleted correctly
47 // and not leaked
48 virtual ~KSelectActionPrivate()
49 {
50 // unhook the event filter, as the deletion of the actiongroup
51 // will trigger it
52 for (QComboBox *box : std::as_const(t&: m_comboBoxes)) {
53 box->removeEventFilter(obj: q_ptr);
54 QObject::disconnect(sender: box, signal: nullptr, receiver: q_ptr, member: nullptr); // To prevent a crash in comboBoxDeleted()
55 }
56
57 for (QToolButton *button : std::as_const(t&: m_buttons)) {
58 button->removeEventFilter(obj: q_ptr);
59 }
60 delete m_actionGroup;
61 }
62
63 void comboBoxDeleted(QComboBox *combo);
64 void comboBoxCurrentIndexChanged(int value);
65
66 void init();
67
68 bool m_edit : 1;
69 bool m_menuAccelsEnabled : 1;
70 int m_comboWidth;
71 int m_maxComboViewCount;
72
73 KSelectAction::ToolBarMode m_toolBarMode;
74 QToolButton::ToolButtonPopupMode m_toolButtonPopupMode;
75
76 QActionGroup *m_actionGroup;
77
78 QList<QToolButton *> m_buttons;
79 QList<QComboBox *> m_comboBoxes;
80
81 QString makeMenuText(const QString &_text)
82 {
83 if (m_menuAccelsEnabled) {
84 return _text;
85 }
86 QString text = _text;
87 int i = 0;
88 while (i < text.length()) {
89 if (text[i] == QLatin1Char('&')) {
90 text.insert(i, c: QLatin1Char('&'));
91 i += 2;
92 } else {
93 ++i;
94 }
95 }
96 return text;
97 }
98
99 KSelectAction *const q_ptr;
100};
101
102#endif // KSELECTACTION_P_H
103

source code of kwidgetsaddons/src/kselectaction_p.h