KDECore
kuitformats.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2007 Chusslove Illich <caslav.ilic@gmx.net> 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 #include <kuitformats_p.h> 00021 00022 #include <config.h> 00023 #include <klocale.h> 00024 00025 #include <QStringList> 00026 #include <QRegExp> 00027 00028 00029 QString KuitFormats::toKeyCombo (const QString &shstr, const QString &delim, 00030 const QHash<QString, QString> &keydict) 00031 { 00032 static QRegExp delRx(QLatin1String("[+-]")); 00033 00034 int p = delRx.indexIn(shstr); // find delimiter 00035 00036 QStringList keys; 00037 if (p < 0) { // single-key shortcut, no delimiter found 00038 keys.append(shstr); 00039 } 00040 else { // multi-key shortcut 00041 QChar oldDelim = shstr[p]; 00042 keys = shstr.split(oldDelim, QString::SkipEmptyParts); 00043 } 00044 00045 for (int i = 0; i < keys.size(); ++i) { 00046 // Normalize key, trim and all lower-case. 00047 QString nkey = keys[i].trimmed().toLower(); 00048 bool isFunctionKey = nkey.length() > 1 && nkey[1].isDigit(); 00049 if (!isFunctionKey) { 00050 keys[i] = keydict.contains(nkey) ? keydict[nkey] : keys[i].trimmed(); 00051 } 00052 else { 00053 keys[i] = keydict[QLatin1String("f%1")].arg(nkey.mid(1)); 00054 } 00055 } 00056 return keys.join(delim); 00057 } 00058 00059 QString KuitFormats::toInterfacePath (const QString &inpstr, 00060 const QString &delim) 00061 { 00062 static QRegExp delRx(QLatin1String("\\||->")); 00063 00064 int p = delRx.indexIn(inpstr); // find delimiter 00065 if (p < 0) { // single-element path, no delimiter found 00066 return inpstr; 00067 } 00068 else { // multi-element path 00069 QString oldDelim = delRx.capturedTexts().at(0); 00070 QStringList guiels = inpstr.split(oldDelim, QString::SkipEmptyParts); 00071 return guiels.join(delim); 00072 } 00073 } 00074
KDE 4.6 API Reference