kexi

utils.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2006 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 
00056     template<class type>
00057     inline type* findParentConst(const QObject* const o, const char* className)
00058     {
00059         const QObject * obj = o;
00060         if (!obj || !className || className[0]=='\0')
00061             return 0;
00062         while ( ((obj=obj->parent())) && !obj->inherits(className) )
00063             ;
00064         return static_cast<type*>(obj);
00065     }
00066 
00071 
00072 
00073 
00074     template<class type>
00075     type* findFirstChild(QObject *o, const char* className, const char* objName = 0)
00076     {
00077         if (!o || !className || className[0]=='\0')
00078             return 0;
00079         QObjectList *l = o->queryList( className, objName );
00080         QObjectListIt it( *l );
00081         return static_cast<type*>(it.current());
00082     }
00083 
00085     inline QDateTime stringToHackedQTime(const QString& s)
00086     {
00087         if (s.isEmpty())
00088             return QDateTime();
00089     //      kdDebug() << QDateTime( QDate(0,1,2), QTime::fromString( s, Qt::ISODate ) ).toString(Qt::ISODate) << endl;;
00090         return QDateTime( QDate(0,1,2), QTime::fromString( s, Qt::ISODate ) );
00091     }
00092 
00095     KEXIUTILS_EXPORT void setWaitCursor(bool noDelay = false);
00096 
00100     KEXIUTILS_EXPORT void removeWaitCursor();
00101 
00109     class KEXIUTILS_EXPORT WaitCursor
00110     {
00111         public:
00112             WaitCursor(bool noDelay = false);
00113             ~WaitCursor();
00114     };
00115 
00124     class KEXIUTILS_EXPORT WaitCursorRemover
00125     {
00126         public:
00127             WaitCursorRemover();
00128             ~WaitCursorRemover();
00129         private:
00130             bool m_reactivateCursor : 1;
00131     };
00132 
00138     KEXIUTILS_EXPORT QString fileDialogFilterString(const KMimeType::Ptr& mime, bool kdeFormat = true);
00139 
00141     KEXIUTILS_EXPORT QString fileDialogFilterString(const QString& mimeString, bool kdeFormat = true);
00142 
00145     KEXIUTILS_EXPORT QString fileDialogFilterStrings(const QStringList& mimeStrings, bool kdeFormat);
00146 
00149     KEXIUTILS_EXPORT QColor blendedColors(const QColor& c1, const QColor& c2, int factor1 = 1, int factor2 = 1);
00150 
00154     KEXIUTILS_EXPORT QColor contrastColor(const QColor& c);
00155 
00160     KEXIUTILS_EXPORT QColor bleachedColor(const QColor& c, int factor);
00161 
00166     KEXIUTILS_EXPORT QIconSet colorizeIconToTextColor(const QPixmap& icon, const QPalette& palette);
00167 
00170     KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, const QByteArray& array);
00171     KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, QString& string);
00172 
00175     KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QByteArray& array);
00176 
00179     KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QString& string);
00180 
00185     KEXIUTILS_EXPORT QString stringToFileName(const QString& string);
00186 
00191     KEXIUTILS_EXPORT void simpleCrypt(QString& string);
00192 
00195     KEXIUTILS_EXPORT void simpleDecrypt(QString& string);
00196 
00197 #ifdef KEXI_DEBUG_GUI
00199     KEXIUTILS_EXPORT QWidget *createDebugWindow(QWidget *parent);
00200 
00202     KEXIUTILS_EXPORT void addKexiDBDebug(const QString& text);
00203 
00205     KEXIUTILS_EXPORT void addAlterTableActionDebug(const QString& text, int nestingLevel = 0);
00206 
00209     KEXIUTILS_EXPORT void connectPushButtonActionForDebugWindow(const char* actionName, 
00210         const QObject *receiver, const char* slot);
00211 #endif
00212 
00215     KEXIUTILS_EXPORT void drawPixmap( QPainter& p, int lineWidth, const QRect& rect,
00216         const QPixmap& pixmap, int alignment, bool scaledContents, bool keepAspectRatio);
00217 
00219     KEXIUTILS_EXPORT QString ptrToStringInternal(void* ptr, uint size);
00221     KEXIUTILS_EXPORT void* stringToPtrInternal(const QString& str, uint size);
00222 
00224     template<class type>
00225     QString ptrToString(type *ptr)
00226     {
00227         return ptrToStringInternal(ptr, sizeof(type*));
00228     }
00229     
00231     template<class type>
00232     type* stringToPtr(const QString& str)
00233     {
00234         return static_cast<type*>( stringToPtrInternal(str, sizeof(type*)) );
00235     }
00236 }
00237 
00241 #define GLUE_WIDGET(what, where) \
00242     { QVBoxLayout *lyr = new QVBoxLayout(where); \
00243       lyr->addWidget(what); }
00244 
00245 
00246 #endif //KEXIUTILS_UTILS_H
KDE Home | KDE Accessibility Home | Description of Access Keys