QKeySequencePrivate Class Reference

#include <qkeysequence_p.h>

Collaboration diagram for QKeySequencePrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 49 of file qkeysequence_p.h.

Public Member Functions

 QKeySequencePrivate ()
 QKeySequencePrivate (const QKeySequencePrivate &copy)

Static Public Member Functions

static QString encodeString (int key, QKeySequence::SequenceFormat format)
static int decodeString (const QString &keyStr, QKeySequence::SequenceFormat format)

Public Attributes

QAtomic ref
int key [4]

Static Public Attributes

static const QKeyBinding keyBindings []
static const uint numberOfKeyBindings


Constructor & Destructor Documentation

QKeySequencePrivate::QKeySequencePrivate (  )  [inline]

Definition at line 52 of file qkeysequence_p.h.

References key.

00053     {
00054         ref = 1;
00055         key[0] = key[1] = key[2] = key[3] =  0;
00056     }

QKeySequencePrivate::QKeySequencePrivate ( const QKeySequencePrivate copy  )  [inline]

Definition at line 57 of file qkeysequence_p.h.

References TokenEngine::copy(), and key.

00058     {
00059         ref = 1;
00060         key[0] = copy.key[0];
00061         key[1] = copy.key[1];
00062         key[2] = copy.key[2];
00063         key[3] = copy.key[3];
00064     }

Here is the call graph for this function:


Member Function Documentation

QString QKeySequencePrivate::encodeString ( int  key,
QKeySequence::SequenceFormat  format 
) [static]

Definition at line 910 of file qkeysequence.cpp.

References addKey(), Qt::ALT, Qt::AltModifier, Qt::ControlModifier, Qt::CTRL, i, Qt::Key_Escape, Qt::Key_F1, Qt::Key_F35, Qt::Key_Space, keyname, Qt::META, Qt::MetaModifier, name, QKeySequence::NativeText, p, s, Qt::SHIFT, and Qt::ShiftModifier.

Referenced by QKeySequence::encodeString(), and QKeySequence::toString().

00911 {
00912     bool nativeText = (format == QKeySequence::NativeText);
00913     QString s;
00914 #if defined(Q_WS_MAC)
00915     if (nativeText) {
00916         // On MAC the order is Meta, Alt, Shift, Control.
00917         if ((key & Qt::META) == Qt::META)
00918             s += QMAC_META;
00919         if ((key & Qt::ALT) == Qt::ALT)
00920             s += QMAC_ALT;
00921         if ((key & Qt::SHIFT) == Qt::SHIFT)
00922             s += QMAC_SHIFT;
00923         if ((key & Qt::CTRL) == Qt::CTRL)
00924             s += QMAC_CTRL;
00925     } else
00926 #endif
00927     {
00928         // On other systems the order is Meta, Control, Alt, Shift
00929         if ((key & Qt::META) == Qt::META)
00930             s = nativeText ? QShortcut::tr("Meta") : QString(QLatin1String("Meta"));
00931         if ((key & Qt::CTRL) == Qt::CTRL)
00932             addKey(s, nativeText ? QShortcut::tr("Ctrl") : QString(QLatin1String("Ctrl")), format);
00933         if ((key & Qt::ALT) == Qt::ALT)
00934             addKey(s, nativeText ? QShortcut::tr("Alt") : QString(QLatin1String("Alt")), format);
00935         if ((key & Qt::SHIFT) == Qt::SHIFT)
00936             addKey(s, nativeText ? QShortcut::tr("Shift") : QString(QLatin1String("Shift")), format);
00937     }
00938 
00939 
00940     key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier);
00941     QString p;
00942 
00943     if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
00944         if (key < 0x10000) {
00945             p = QChar(key & 0xffff).toUpper();
00946         } else {
00947             p = QChar((key-0x10000)/0x400+0xd800);
00948             p += QChar((key-0x10000)%400+0xdc00);
00949         }
00950     } else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
00951             p = nativeText ? QShortcut::tr("F%1").arg(key - Qt::Key_F1 + 1)
00952                            : QString(QLatin1String("F%1")).arg(key - Qt::Key_F1 + 1);
00953     } else if (key) {
00954         int i=0;
00955         while (keyname[i].name) {
00956             if (key == keyname[i].key) {
00957                 p = nativeText ? QShortcut::tr(keyname[i].name)
00958                                : QString(QLatin1String(keyname[i].name));
00959                 break;
00960             }
00961             ++i;
00962         }
00963         // If we can't find the actual translatable keyname,
00964         // fall back on the unicode representation of it...
00965         // Or else characters like Qt::Key_aring may not get displayed
00966         // (Really depends on you locale)
00967         if (!keyname[i].name) {
00968             if (key < 0x10000) {
00969                 p = QChar(key & 0xffff).toUpper();
00970             } else {
00971                 p = QChar((key-0x10000)/0x400+0xd800);
00972                 p += QChar((key-0x10000)%400+0xdc00);
00973             }
00974         }
00975     }
00976 
00977 #ifdef Q_WS_MAC
00978     if (nativeText)
00979         s += p;
00980     else
00981 #endif
00982     addKey(s, p, format);
00983     return s;
00984 }

Here is the call graph for this function:

int QKeySequencePrivate::decodeString ( const QString keyStr,
QKeySequence::SequenceFormat  format 
) [static]

Definition at line 779 of file qkeysequence.cpp.

References Qt::ALT, QList< T >::at(), QString::contains(), Qt::CTRL, QString::fromLatin1(), i, QString::indexOf(), QList< T >::isEmpty(), j, key, Qt::Key_F1, keyname, QString::lastIndexOf(), QString::length(), Qt::META, QString::mid(), name, QKeySequence::NativeText, p, QModifKeyName::qt_key, QString::remove(), Qt::SHIFT, QList< T >::size(), QString::toInt(), QString::toLower(), and QString::unicode().

Referenced by QKeySequence::decodeString(), and QKeySequence::fromString().

00780 {
00781     int ret = 0;
00782     QString accel = str.toLower();
00783     bool nativeText = (format == QKeySequence::NativeText);
00784 
00785     QList<QModifKeyName> *gmodifs;
00786     if (nativeText) {
00787         gmodifs = globalModifs();
00788         if (gmodifs->isEmpty()) {
00789 #ifdef QMAC_CTRL
00790             *gmodifs << QModifKeyName(Qt::CTRL, QMAC_CTRL);
00791 #endif
00792 #ifdef QMAC_ALT
00793             *gmodifs << QModifKeyName(Qt::ALT, QMAC_ALT);
00794 #endif
00795 #ifdef QMAC_META
00796             *gmodifs << QModifKeyName(Qt::META, QMAC_META);
00797 #endif
00798 #ifdef QMAC_SHIFT
00799             *gmodifs << QModifKeyName(Qt::SHIFT, QMAC_SHIFT);
00800 #endif
00801             *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
00802                      << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
00803                      << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
00804                      << QModifKeyName(Qt::META, QLatin1String("meta+"));
00805         }
00806     } else {
00807         gmodifs = globalPortableModifs();
00808         if (gmodifs->isEmpty()) {
00809             *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
00810                      << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
00811                      << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
00812                      << QModifKeyName(Qt::META, QLatin1String("meta+"));
00813         }
00814     }
00815     if (!gmodifs) return ret;
00816 
00817 
00818     QList<QModifKeyName> modifs;
00819     if (nativeText) {
00820         modifs << QModifKeyName(Qt::CTRL, QShortcut::tr("Ctrl").toLower().append(QLatin1Char('+')))
00821                << QModifKeyName(Qt::SHIFT, QShortcut::tr("Shift").toLower().append(QLatin1Char('+')))
00822                << QModifKeyName(Qt::ALT, QShortcut::tr("Alt").toLower().append(QLatin1Char('+')))
00823                << QModifKeyName(Qt::META, QShortcut::tr("Meta").toLower().append(QLatin1Char('+')));
00824     }
00825     modifs += *gmodifs; // Test non-translated ones last
00826 
00827     QString sl = accel;
00828 #ifdef Q_WS_MAC
00829     for (int i = 0; i < modifs.size(); ++i) {
00830         const QModifKeyName &mkf = modifs.at(i);
00831         if (sl.contains(mkf.name)) {
00832             ret |= mkf.qt_key;
00833             accel.remove(mkf.name);
00834             sl = accel;
00835         }
00836     }
00837 #else
00838     int i = 0;
00839     int lastI = 0;
00840     while ((i = sl.indexOf('+', i + 1)) != -1) {
00841         const QString sub = sl.mid(lastI, i - lastI + 1);
00842         // Just shortcut the check here if we only have one character.
00843         // Rational: A modifier will contain the name AND +, so longer than 1, a length of 1 is just
00844         // the remaining part of the shortcut (ei. The 'C' in "Ctrl+C"), so no need to check that.
00845         if (sub.length() > 1) {
00846             for (int j = 0; j < modifs.size(); ++j) {
00847                 const QModifKeyName &mkf = modifs.at(j);
00848                 if (sub == mkf.name) {
00849                     ret |= mkf.qt_key;
00850                     break; // Shortcut, since if we find an other it would/should just be a dup
00851                 }
00852             }
00853         }
00854         lastI = i + 1;
00855     }
00856 #endif
00857 
00858     int p = accel.lastIndexOf(QLatin1Char('+'), str.length() - 2); // -2 so that Ctrl++ works
00859     if(p > 0)
00860         accel = accel.mid(p + 1);
00861 
00862     int fnum = 0;
00863     if (accel.length() == 1) {
00864         ret |= accel[0].toUpper().unicode();
00865     } else if (accel[0] == QLatin1Char('f') && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35)) {
00866         ret |= Qt::Key_F1 + fnum - 1;
00867     } else {
00868         // For NativeText, check the traslation table first,
00869         // if we don't find anything then try it out with just the untranlated stuff.
00870         // PortableText will only try the untranlated table.
00871         bool found = false;
00872         for (int tran = 0; tran < 2; ++tran) {
00873             if (!nativeText)
00874                 ++tran;
00875             for (int i = 0; keyname[i].name; ++i) {
00876                 QString keyName(tran == 0
00877                                 ? QShortcut::tr(keyname[i].name)
00878                                 : QString::fromLatin1(keyname[i].name));
00879                 if (accel == keyName.toLower()) {
00880                     ret |= keyname[i].key;
00881                     found = true;
00882                     break;
00883                 }
00884             }
00885             if (found)
00886                 break;
00887         }
00888     }
00889     return ret;
00890 }

Here is the call graph for this function:


Member Data Documentation

QAtomic QKeySequencePrivate::ref

Definition at line 65 of file qkeysequence_p.h.

Referenced by QKeySequence::isDetached(), QKeySequence::QKeySequence(), and QKeySequence::~QKeySequence().

int QKeySequencePrivate::key[4]

Definition at line 66 of file qkeysequence_p.h.

Referenced by QKeySequence::assign(), QKeySequence::count(), decodeString(), QKeySequence::isEmpty(), QKeySequence::operator int(), QKeySequence::operator<(), operator<<(), QKeySequence::operator==(), operator>>(), QKeySequence::operator[](), QKeySequence::QKeySequence(), QKeySequence::setKey(), and QKeySequence::toString().

const QKeyBinding QKeySequencePrivate::keyBindings [static]

Definition at line 70 of file qkeysequence_p.h.

Referenced by QKeySequence::keyBindings(), and QKeyEvent::matches().

const uint QKeySequencePrivate::numberOfKeyBindings [static]

Definition at line 71 of file qkeysequence_p.h.

Referenced by QKeySequence::keyBindings(), and QKeyEvent::matches().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:07:33 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1