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
00031 namespace KexiUtils
00032 {
00034 inline bool hasParent(QObject* par, QObject* o)
00035 {
00036 if (!o || !par)
00037 return false;
00038 while (o && o!=par)
00039 o = o->parent();
00040 return o==par;
00041 }
00042
00044 template<class type>
00045 inline type* findParent(QObject* o, const char* className)
00046 {
00047 if (!o || !className || className[0]=='\0')
00048 return 0;
00049 while ( ((o=o->parent())) && !o->inherits(className) )
00050 ;
00051 return static_cast<type*>(o);
00052 }
00053
00055 template<class type>
00056 inline const type* findParentConst(const QObject* const o, const char* className)
00057 {
00058 const QObject * obj = o;
00059 if (!obj || !className || className[0]=='\0')
00060 return 0;
00061 while ( ((obj=obj->parent())) && !obj->inherits(className) )
00062 ;
00063 return static_cast<const type*>(obj);
00064 }
00065
00069 template<class type>
00070 type* findFirstChild(QObject *o, const char* className, const char* objName = 0)
00071 {
00072 if (!o || !className || className[0]=='\0')
00073 return 0;
00074 QObjectList *l = o->queryList( className, objName );
00075 QObject *result = l->first();
00076 delete l;
00077 return static_cast<type*>(result);
00078 }
00079
00081 inline QDateTime stringToHackedQTime(const QString& s)
00082 {
00083 if (s.isEmpty())
00084 return QDateTime();
00085
00086 return QDateTime( QDate(0,1,2), QTime::fromString( s, Qt::ISODate ) );
00087 }
00088
00091 KEXIUTILS_EXPORT void setWaitCursor(bool noDelay = false);
00092
00096 KEXIUTILS_EXPORT void removeWaitCursor();
00097
00105 class KEXIUTILS_EXPORT WaitCursor
00106 {
00107 public:
00108 WaitCursor(bool noDelay = false);
00109 ~WaitCursor();
00110 };
00111
00120 class KEXIUTILS_EXPORT WaitCursorRemover
00121 {
00122 public:
00123 WaitCursorRemover();
00124 ~WaitCursorRemover();
00125 private:
00126 bool m_reactivateCursor : 1;
00127 };
00128
00134 KEXIUTILS_EXPORT QString fileDialogFilterString(const KMimeType::Ptr& mime, bool kdeFormat = true);
00135
00137 KEXIUTILS_EXPORT QString fileDialogFilterString(const QString& mimeString, bool kdeFormat = true);
00138
00141 KEXIUTILS_EXPORT QString fileDialogFilterStrings(const QStringList& mimeStrings, bool kdeFormat);
00142
00145 KEXIUTILS_EXPORT QColor blendedColors(const QColor& c1, const QColor& c2, int factor1 = 1, int factor2 = 1);
00146
00150 KEXIUTILS_EXPORT QColor contrastColor(const QColor& c);
00151
00156 KEXIUTILS_EXPORT QColor bleachedColor(const QColor& c, int factor);
00157
00162 KEXIUTILS_EXPORT QIconSet colorizeIconToTextColor(const QPixmap& icon, const QPalette& palette);
00163
00165 KEXIUTILS_EXPORT QPixmap emptyIcon(KIcon::Group iconGroup);
00166
00169 KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, const QByteArray& array);
00170 KEXIUTILS_EXPORT void serializeMap(const QMap<QString,QString>& map, QString& string);
00171
00174 KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QByteArray& array);
00175
00178 KEXIUTILS_EXPORT QMap<QString,QString> deserializeMap(const QString& string);
00179
00184 KEXIUTILS_EXPORT QString stringToFileName(const QString& string);
00185
00190 KEXIUTILS_EXPORT void simpleCrypt(QString& string);
00191
00194 KEXIUTILS_EXPORT void simpleDecrypt(QString& string);
00195
00196 #ifdef KEXI_DEBUG_GUI
00198 KEXIUTILS_EXPORT QWidget *createDebugWindow(QWidget *parent);
00199
00201 KEXIUTILS_EXPORT void addKexiDBDebug(const QString& text);
00202
00204 KEXIUTILS_EXPORT void addAlterTableActionDebug(const QString& text, int nestingLevel = 0);
00205
00208 KEXIUTILS_EXPORT void connectPushButtonActionForDebugWindow(const char* actionName,
00209 const QObject *receiver, const char* slot);
00210 #endif
00211
00214 KEXIUTILS_EXPORT void drawPixmap( QPainter& p, int lineWidth, const QRect& rect,
00215 const QPixmap& pixmap, int alignment, bool scaledContents, bool keepAspectRatio);
00216
00218 KEXIUTILS_EXPORT QString ptrToStringInternal(void* ptr, uint size);
00220 KEXIUTILS_EXPORT void* stringToPtrInternal(const QString& str, uint size);
00221
00223 template<class type>
00224 QString ptrToString(type *ptr)
00225 {
00226 return ptrToStringInternal(ptr, sizeof(type*));
00227 }
00228
00230 template<class type>
00231 type* stringToPtr(const QString& str)
00232 {
00233 return static_cast<type*>( stringToPtrInternal(str, sizeof(type*)) );
00234 }
00235
00237 KEXIUTILS_EXPORT void setFocusWithReason(QWidget* widget, QFocusEvent::Reason reason);
00238
00240 KEXIUTILS_EXPORT void unsetFocusWithReason(QWidget* widget, QFocusEvent::Reason reason);
00241
00243 enum CopyFileResult {
00244 CopySuccess = 0,
00245 CopyReadError = 1,
00246 CopyWriteError = 2
00247 };
00248
00255 KEXIUTILS_EXPORT CopyFileResult copyFile(const QString& src, const QString& dest);
00256 }
00257
00258
00262 #define GLUE_WIDGET(what, where) \
00263 { QVBoxLayout *lyr = new QVBoxLayout(where); \
00264 lyr->addWidget(what); }
00265
00266
00267 #endif //KEXIUTILS_UTILS_H