KDEUI
kacceleratormanager_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 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
00095 DEFAULT_WEIGHT = 50,
00096
00097 FIRST_CHARACTER_EXTRA_WEIGHT = 50,
00098
00099 WORD_BEGINNING_EXTRA_WEIGHT = 50,
00100
00101 DIALOG_BUTTON_EXTRA_WEIGHT = 300,
00102
00103 WANTED_ACCEL_EXTRA_WEIGHT = 150,
00104
00105 ACTION_ELEMENT_WEIGHT = 50,
00106
00107 GROUP_BOX_WEIGHT = -2000,
00108
00109 MENU_TITLE_WEIGHT = 250,
00110
00111 STANDARD_ACCEL = 300
00112 };
00113
00114 static void findAccelerators(KAccelStringList &result, QString &used);
00115
00116 };
00117
00118
00128 class KPopupAccelManager : public QObject
00129 {
00130 Q_OBJECT
00131
00132 public:
00133
00134 static void manage(QMenu *popup);
00135
00136
00137 protected:
00138
00139 KPopupAccelManager(QMenu *popup);
00140
00141
00142 private Q_SLOTS:
00143
00144 void aboutToShow();
00145
00146
00147 private:
00148
00149 void calculateAccelerators();
00150
00151 void findMenuEntries(KAccelStringList &list);
00152 void setMenuEntries(const KAccelStringList &list);
00153
00154 QMenu *m_popup;
00155 KAccelStringList m_entries;
00156 int m_count;
00157
00158 };
00159
00160
00161 class QWidgetStackAccelManager : public QObject
00162 {
00163 Q_OBJECT
00164
00165 public:
00166
00167 static void manage(QStackedWidget *popup);
00168
00169
00170 protected:
00171
00172 QWidgetStackAccelManager(QStackedWidget *popup);
00173
00174
00175 private Q_SLOTS:
00176
00177 void currentChanged(int child);
00178 bool eventFilter ( QObject * watched, QEvent * e );
00179
00180 private:
00181
00182 void calculateAccelerators();
00183
00184 QStackedWidget *m_stack;
00185 KAccelStringList m_entries;
00186
00187 };
00188
00189
00190 #endif // KACCELERATORMANAGER_PRIVATE_H