KDECore
kaccelmanager_private.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __KACCELMANAGER_PRIVATE_H__
00022 #define __KACCELMANAGER_PRIVATE_H__
00023
00024
00025 #include <qstring.h>
00026 #include <qmemarray.h>
00027 #include <qvaluelist.h>
00028 #include <qobject.h>
00029
00030 class QWidgetStack;
00031
00042 class KAccelString
00043 {
00044 public:
00045
00046 KAccelString() : m_pureText(), m_accel(-1) {}
00047 KAccelString(const QString &input, int initalWeight=-1);
00048
00049 void calculateWeights(int initialWeight);
00050
00051 const QString &pure() const { return m_pureText; }
00052 QString accelerated() const;
00053
00054 int accel() const { return m_accel; }
00055 void setAccel(int accel) { m_accel = accel; }
00056
00057 int originalAccel() const { return m_orig_accel; }
00058 QString originalText() const { return m_origText; }
00059
00060 QChar accelerator() const;
00061
00062 int maxWeight(int &index, const QString &used);
00063
00064 bool operator == (const KAccelString &c) const { return m_pureText == c.m_pureText && m_accel == c.m_accel && m_orig_accel == c.m_orig_accel; }
00065
00066
00067 private:
00068
00069 int stripAccelerator(QString &input);
00070
00071 void dump();
00072
00073 QString m_pureText, m_origText;
00074 int m_accel, m_orig_accel;
00075 QMemArray<int> m_weight;
00076
00077 };
00078
00079
00080 typedef QValueList<KAccelString> KAccelStringList;
00081
00082
00090 class KAccelManagerAlgorithm
00091 {
00092 public:
00093
00095 enum {
00097 DEFAULT_WEIGHT = 50,
00099 FIRST_CHARACTER_EXTRA_WEIGHT = 50,
00101 WORD_BEGINNING_EXTRA_WEIGHT = 50,
00103 DIALOG_BUTTON_EXTRA_WEIGHT = 300,
00105 WANTED_ACCEL_EXTRA_WEIGHT = 150,
00107 ACTION_ELEMENT_WEIGHT = 50,
00109 GROUP_BOX_WEIGHT = -2000,
00111 MENU_TITLE_WEIGHT = 250,
00113 STANDARD_ACCEL = 300
00114 };
00115
00117 static void findAccelerators(KAccelStringList &result, QString &used);
00118
00119 };
00120
00121
00122 class QPopupMenu;
00123
00124
00134 class KPopupAccelManager : public QObject
00135 {
00136 Q_OBJECT
00137
00138 public:
00139
00140 static void manage(QPopupMenu *popup);
00141
00142
00143 protected:
00144
00145 KPopupAccelManager(QPopupMenu *popup);
00146
00147
00148 private slots:
00149
00150 void aboutToShow();
00151
00152
00153 private:
00154
00155 void calculateAccelerators();
00156
00157 void findMenuEntries(KAccelStringList &list);
00158 void setMenuEntries(const KAccelStringList &list);
00159
00160 QPopupMenu *m_popup;
00161 KAccelStringList m_entries;
00162 int m_count;
00163
00164 };
00165
00166
00167 class QWidgetStackAccelManager : public QObject
00168 {
00169 Q_OBJECT
00170
00171 public:
00172
00173 static void manage(QWidgetStack *popup);
00174
00175
00176 protected:
00177
00178 QWidgetStackAccelManager(QWidgetStack *popup);
00179
00180
00181 private slots:
00182
00183 void aboutToShow(QWidget *);
00184 bool eventFilter ( QObject * watched, QEvent * e );
00185
00186 private:
00187
00188 void calculateAccelerators();
00189
00190 QWidgetStack *m_stack;
00191 KAccelStringList m_entries;
00192
00193 };
00194
00195
00196 #endif