kdecore Library API Documentation

kaccelmanager_private.h

00001 /*  This file is part of the KDE project
00002     Copyright (C) 2002 Matthias Hölzer-Klüpfel <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., 59 Temple Place - Suite 330,
00017     Boston, MA 02111-1307, USA.
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 
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   QChar accelerator() const;
00058 
00059   int maxWeight(int &index, const QString &used);
00060 
00061   bool operator == (const KAccelString &c) const { return m_pureText == c.m_pureText && m_accel == c.m_accel && orig_accel == c.orig_accel; }
00062 
00063 
00064 private:
00065 
00066   int stripAccelerator(QString &input);
00067 
00068   void dump();
00069 
00070   QString        m_pureText;
00071   int            m_accel, orig_accel;
00072   QMemArray<int> m_weight;
00073 
00074 };
00075 
00076 
00077 typedef QValueList<KAccelString> KAccelStringList;
00078 
00079 
00088 class KAccelManagerAlgorithm
00089 {
00090 public:
00091 
00092   static const int DEFAULT_WEIGHT;
00093 
00094   static const int FIRST_CHARACTER_EXTRA_WEIGHT;
00095   static const int WORD_BEGINNING_EXTRA_WEIGHT;
00096   static const int WANTED_ACCEL_EXTRA_WEIGHT;
00097   static const int DIALOG_BUTTON_EXTRA_WEIGHT;
00098 
00099   static const int ACTION_ELEMENT_WEIGHT;
00100   static const int GROUP_BOX_WEIGHT;
00101   static const int MENU_TITLE_WEIGHT;
00102 
00103   static void findAccelerators(KAccelStringList &result, QString &used);
00104 
00105 };
00106 
00107 
00108 class QPopupMenu;
00109 
00110 
00121 class KPopupAccelManager : public QObject
00122 {
00123   Q_OBJECT
00124 
00125 public:
00126 
00127   static void manage(QPopupMenu *popup);
00128 
00129 
00130 protected:
00131 
00132   KPopupAccelManager(QPopupMenu *popup);
00133 
00134 
00135 private slots:
00136 
00137   void aboutToShow();
00138 
00139 
00140 private:
00141 
00142   void calculateAccelerators();
00143 
00144   void findMenuEntries(KAccelStringList &list);
00145   void setMenuEntries(const KAccelStringList &list);
00146 
00147   QPopupMenu       *m_popup;
00148   KAccelStringList m_entries;
00149   int              m_count;
00150 
00151 };
00152 
00153 
00154 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:14:45 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001