00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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
00169 KEXIUTILS_EXPORT QPixmap emptyIcon(KIcon::Group iconGroup);
00170
00173 KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, const QByteArray& array);
00174 KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, QString& string);
00175
00178 KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QByteArray& array);
00179
00182 KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QString& string);
00183
00188 KEXIUTILS_EXPORT QString stringToFileName(const QString& string);
00189
00194 KEXIUTILS_EXPORT void simpleCrypt(QString& string);
00195
00198 KEXIUTILS_EXPORT void simpleDecrypt(QString& string);
00199
00200 #ifdef KEXI_DEBUG_GUI
00202 KEXIUTILS_EXPORT QWidget *createDebugWindow(QWidget *parent);
00203
00205 KEXIUTILS_EXPORT void addKexiDBDebug(const QString& text);
00206
00208 KEXIUTILS_EXPORT void addAlterTableActionDebug(const QString& text, int nestingLevel = 0);
00209
00212 KEXIUTILS_EXPORT void connectPushButtonActionForDebugWindow(const char* actionName,
00213 const QObject *receiver, const char* slot);
00214 #endif
00215
00218 KEXIUTILS_EXPORT void drawPixmap( QPainter& p, int lineWidth, const QRect& rect,
00219 const QPixmap& pixmap, int alignment, bool scaledContents, bool keepAspectRatio);
00220
00222 KEXIUTILS_EXPORT QString ptrToStringInternal(void* ptr, uint size);
00224 KEXIUTILS_EXPORT void* stringToPtrInternal(const QString& str, uint size);
00225
00227 template<class type>
00228 QString ptrToString(type *ptr)
00229 {
00230 return ptrToStringInternal(ptr, sizeof(type*));
00231 }
00232
00234 template<class type>
00235 type* stringToPtr(const QString& str)
00236 {
00237 return static_cast<type*>( stringToPtrInternal(str, sizeof(type*)) );
00238 }
00239 }
00240
00244 #define GLUE_WIDGET(what, where) \
00245 { QVBoxLayout *lyr = new QVBoxLayout(where); \
00246 lyr->addWidget(what); }
00247
00248
00249 #endif //KEXIUTILS_UTILS_H