kexi

utils.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program 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 program 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 program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIUTILS_UTILS_H
00021 #define KEXIUTILS_UTILS_H
00022 
00023 #include "kexiutils_export.h"
00024 
00025 #include <qguardedptr.h>
00026 #include <qobjectlist.h>
00027 #include <kmimetype.h>
00028 class QColor;
00029 
00030 // General Utils
00031 
00032 namespace KexiUtils
00033 {
00035     inline bool hasParent(QObject* par, QObject* o)
00036     {
00037         if (!o || !par)
00038             return false;
00039         while (o && o!=par)
00040             o = o->parent();
00041         return o==par;
00042     }
00043 
00045     template<class type>
00046     inline type* findParent(QObject* o, const char* className)
00047     {
00048         if (!o || !className || className[0]=='\0')
00049             return 0;
00050         while ( ((o=o->parent())) && !o->inherits(className) )
00051             ;
00052         return static_cast<type*>(o);
00053     }
00054 
00057     template<class type>
00058     type* findFirstChild(QObject *o, const char* className)
00059     {
00060         if (!o || !className || className[0]=='\0')
00061             return 0;
00062         QObjectList *l = o->queryList( className );
00063         QObjectListIt it( *l );
00064         return static_cast<type*>(it.current());
00065     }
00066 
00068     inline QDateTime stringToHackedQTime(const QString& s)
00069     {
00070         if (s.isEmpty())
00071             return QDateTime();
00072     //      kdDebug() << QDateTime( QDate(0,1,2), QTime::fromString( s, Qt::ISODate ) ).toString(Qt::ISODate) << endl;;
00073         return QDateTime( QDate(0,1,2), QTime::fromString( s, Qt::ISODate ) );
00074     }
00075 
00078     KEXIUTILS_EXPORT void setWaitCursor(bool noDelay = false);
00079 
00083     KEXIUTILS_EXPORT void removeWaitCursor();
00084 
00092     class KEXIUTILS_EXPORT WaitCursor
00093     {
00094         public:
00095             WaitCursor(bool noDelay = false);
00096             ~WaitCursor();
00097     };
00098 
00104     KEXIUTILS_EXPORT QString fileDialogFilterString(const KMimeType::Ptr& mime, bool kdeFormat = true);
00105 
00107     KEXIUTILS_EXPORT QString fileDialogFilterString(const QString& mimeString, bool kdeFormat = true);
00108 
00111     KEXIUTILS_EXPORT QString fileDialogFilterStrings(const QStringList& mimeStrings, bool kdeFormat);
00112 
00115     KEXIUTILS_EXPORT QColor blendedColors(const QColor& c1, const QColor& c2, int factor1 = 1, int factor2 = 1);
00116 
00120     KEXIUTILS_EXPORT QColor contrastColor(const QColor& c);
00121 
00126     KEXIUTILS_EXPORT QColor bleachedColor(const QColor& c, int factor);
00127 
00130     KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, QByteArray& array);
00131     KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, QString& string);
00132 
00135     KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QByteArray& array);
00136 
00139     KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QString& string);
00140 
00145     KEXIUTILS_EXPORT QString stringToFileName(const QString& string);
00146 
00151     KEXIUTILS_EXPORT void simpleCrypt(QString& string);
00152 
00155     KEXIUTILS_EXPORT void simpleDecrypt(QString& string);
00156 }
00157 
00158 
00162 #define GLUE_WIDGET(what, where) \
00163     { QVBoxLayout *lyr = new QVBoxLayout(where); \
00164       lyr->addWidget(what); }
00165 
00166 
00167 #endif //KEXIUTILS_UTILS_H
KDE Home | KDE Accessibility Home | Description of Access Keys