File indexing completed on 2025-02-02 14:20:10
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> 0004 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0005 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> 0006 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0007 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> 0008 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> 0009 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> 0010 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org> 0011 SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> 0012 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> 0013 SPDX-FileCopyrightText: 2006 Albert Astals Cid <aacid@kde.org> 0014 SPDX-FileCopyrightText: 2006 Clarence Dang <dang@kde.org> 0015 SPDX-FileCopyrightText: 2006 Michel Hermier <michel.hermier@gmail.com> 0016 SPDX-FileCopyrightText: 2007 Nick Shaforostoff <shafff@ukr.net> 0017 0018 SPDX-License-Identifier: LGPL-2.0-only 0019 */ 0020 0021 #ifndef KSELECTACTION_P_H 0022 #define KSELECTACTION_P_H 0023 0024 #include <QActionGroup> 0025 #include <QComboBox> 0026 0027 class KSelectActionPrivate 0028 { 0029 Q_DECLARE_PUBLIC(KSelectAction) 0030 0031 public: 0032 KSelectActionPrivate(KSelectAction *qq) 0033 : q_ptr(qq) 0034 { 0035 m_edit = false; 0036 m_menuAccelsEnabled = true; 0037 m_comboWidth = -1; 0038 m_maxComboViewCount = -1; 0039 0040 m_toolBarMode = KSelectAction::ComboBoxMode; 0041 m_toolButtonPopupMode = QToolButton::InstantPopup; // InstantPopup by default because there is no default action 0042 0043 m_actionGroup = new QActionGroup(nullptr); 0044 } 0045 0046 // virtual so the derived private class for e.g. KRecentFilesAction can be deleted correctly 0047 // and not leaked 0048 virtual ~KSelectActionPrivate() 0049 { 0050 // unhook the event filter, as the deletion of the actiongroup 0051 // will trigger it 0052 for (QComboBox *box : std::as_const(m_comboBoxes)) { 0053 box->removeEventFilter(q_ptr); 0054 QObject::disconnect(box, nullptr, q_ptr, nullptr); // To prevent a crash in comboBoxDeleted() 0055 } 0056 0057 for (QToolButton *button : std::as_const(m_buttons)) { 0058 button->removeEventFilter(q_ptr); 0059 } 0060 delete m_actionGroup; 0061 } 0062 0063 void comboBoxDeleted(QComboBox *combo); 0064 void comboBoxCurrentIndexChanged(int value); 0065 0066 void init(); 0067 0068 bool m_edit : 1; 0069 bool m_menuAccelsEnabled : 1; 0070 int m_comboWidth; 0071 int m_maxComboViewCount; 0072 0073 KSelectAction::ToolBarMode m_toolBarMode; 0074 QToolButton::ToolButtonPopupMode m_toolButtonPopupMode; 0075 0076 QActionGroup *m_actionGroup; 0077 0078 QList<QToolButton *> m_buttons; 0079 QList<QComboBox *> m_comboBoxes; 0080 0081 QString makeMenuText(const QString &_text) 0082 { 0083 if (m_menuAccelsEnabled) { 0084 return _text; 0085 } 0086 QString text = _text; 0087 int i = 0; 0088 while (i < text.length()) { 0089 if (text[i] == QLatin1Char('&')) { 0090 text.insert(i, QLatin1Char('&')); 0091 i += 2; 0092 } else { 0093 ++i; 0094 } 0095 } 0096 return text; 0097 } 0098 0099 KSelectAction *const q_ptr; 0100 }; 0101 0102 #endif // KSELECTACTION_P_H