KDEUI
kacceleratormanager_private.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2002 Matthias H�zer-Klpfel <mhk@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 00021 #ifndef KACCELERATORMANAGER_PRIVATE_H 00022 #define KACCELERATORMANAGER_PRIVATE_H 00023 00024 00025 #include <QtCore/QString> 00026 00027 #include <QtCore/QObject> 00028 00029 class QStackedWidget; 00030 00041 class KAccelString 00042 { 00043 public: 00044 00045 KAccelString() : m_pureText(), m_accel(-1) {} 00046 explicit KAccelString(const QString &input, int initalWeight=-1); 00047 00048 void calculateWeights(int initialWeight); 00049 00050 const QString &pure() const { return m_pureText; } 00051 QString accelerated() const; 00052 00053 int accel() const { return m_accel; } 00054 void setAccel(int accel) { m_accel = accel; } 00055 00056 int originalAccel() const { return m_orig_accel; } 00057 QString originalText() const { return m_origText; } 00058 00059 QChar accelerator() const; 00060 00061 int maxWeight(int &index, const QString &used) const; 00062 00063 bool operator == (const KAccelString &c) const { return m_pureText == c.m_pureText && m_accel == c.m_accel && m_orig_accel == c.m_orig_accel; } 00064 00065 00066 private: 00067 00068 int stripAccelerator(QString &input); 00069 00070 void dump(); 00071 00072 QString m_pureText, m_origText; 00073 int m_accel, m_orig_accel; 00074 QVector<int> m_weight; 00075 00076 }; 00077 00078 00079 typedef QList<KAccelString> KAccelStringList; 00080 00081 00089 class KAccelManagerAlgorithm 00090 { 00091 public: 00092 00093 enum { 00094 // Default control weight 00095 DEFAULT_WEIGHT = 50, 00096 // Additional weight for first character in string 00097 FIRST_CHARACTER_EXTRA_WEIGHT = 50, 00098 // Additional weight for the beginning of a word 00099 WORD_BEGINNING_EXTRA_WEIGHT = 50, 00100 // Additional weight for the dialog buttons (large, we basically never want these reassigned) 00101 DIALOG_BUTTON_EXTRA_WEIGHT = 300, 00102 // Additional weight for a 'wanted' accelerator 00103 WANTED_ACCEL_EXTRA_WEIGHT = 150, 00104 // Default weight for an 'action' widget (ie, pushbuttons) 00105 ACTION_ELEMENT_WEIGHT = 50, 00106 // Default weight for group boxes (lowest priority) 00107 GROUP_BOX_WEIGHT = -2000, 00108 // Default weight for checkable group boxes (low priority) 00109 CHECKABLE_GROUP_BOX_WEIGHT = 20, 00110 // Default weight for menu titles 00111 MENU_TITLE_WEIGHT = 250, 00112 // Additional weight for KDE standard accelerators 00113 STANDARD_ACCEL = 300 00114 }; 00115 00116 static void findAccelerators(KAccelStringList &result, QString &used); 00117 00118 }; 00119 00120 00130 class KPopupAccelManager : public QObject 00131 { 00132 Q_OBJECT 00133 00134 public: 00135 00136 static void manage(QMenu *popup); 00137 00138 00139 protected: 00140 00141 KPopupAccelManager(QMenu *popup); 00142 00143 00144 private Q_SLOTS: 00145 00146 void aboutToShow(); 00147 00148 00149 private: 00150 00151 void calculateAccelerators(); 00152 00153 void findMenuEntries(KAccelStringList &list); 00154 void setMenuEntries(const KAccelStringList &list); 00155 00156 QMenu *m_popup; 00157 KAccelStringList m_entries; 00158 int m_count; 00159 00160 }; 00161 00162 00163 class QWidgetStackAccelManager : public QObject 00164 { 00165 Q_OBJECT 00166 00167 public: 00168 00169 static void manage(QStackedWidget *popup); 00170 00171 00172 protected: 00173 00174 QWidgetStackAccelManager(QStackedWidget *popup); 00175 00176 00177 private Q_SLOTS: 00178 00179 void currentChanged(int child); 00180 bool eventFilter ( QObject * watched, QEvent * e ); 00181 00182 private: 00183 00184 void calculateAccelerators(); 00185 00186 QStackedWidget *m_stack; 00187 KAccelStringList m_entries; 00188 00189 }; 00190 00191 00192 #endif // KACCELERATORMANAGER_PRIVATE_H
KDE 4.6 API Reference