kexi

kexiutils/utils.h
1/* This file is part of the KDE project
2 Copyright (C) 2003-2007 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KEXIUTILS_UTILS_H
21#define KEXIUTILS_UTILS_H
22
23#include "kexiutils_export.h"
24
25#include <tqguardedptr.h>
26#include <tqobjectlist.h>
27#include <kmimetype.h>
28class TQColor;
29
31namespace KexiUtils
32{
34 inline bool hasParent(TQObject* par, TQObject* o)
35 {
36 if (!o || !par)
37 return false;
38 while (o && o!=par)
39 o = o->parent();
40 return o==par;
41 }
42
44 template<class type>
45 inline type* findParent(TQObject* o, const char* className)
46 {
47 if (!o || !className || className[0]=='\0')
48 return 0;
49 while ( ((o=o->parent())) && !o->inherits(className) )
50 ;
51 return static_cast<type*>(o);
52 }
53
55 template<class type>
56 inline const type* findParentConst(const TQObject* const o, const char* className)
57 {
58 const TQObject * obj = o;
59 if (!obj || !className || className[0]=='\0')
60 return 0;
61 while ( ((obj=obj->parent())) && !obj->inherits(className) )
62 ;
63 return static_cast<const type*>(obj);
64 }
65
69 template<class type>
70 type* findFirstChild(TQObject *o, const char* className, const char* objName = 0)
71 {
72 if (!o || !className || className[0]=='\0')
73 return 0;
74 TQObjectList *l = o->queryList( className, objName );
75 TQObject *result = l->first();
76 delete l;
77 return static_cast<type*>(result);
78 }
79
81 inline TQDateTime stringToHackedTQTime(const TQString& s)
82 {
83 if (s.isEmpty())
84 return TQDateTime();
85 // kdDebug() << TQDateTime( TQDate(0,1,2), TQTime::fromString( s, TQt::ISODate ) ).toString(TQt::ISODate) << endl;;
86 return TQDateTime( TQDate(0,1,2), TQTime::fromString( s, TQt::ISODate ) );
87 }
88
91 KEXIUTILS_EXPORT void setWaitCursor(bool noDelay = false);
92
96 KEXIUTILS_EXPORT void removeWaitCursor();
97
105 class KEXIUTILS_EXPORT WaitCursor
106 {
107 public:
108 WaitCursor(bool noDelay = false);
109 ~WaitCursor();
110 };
111
120 class KEXIUTILS_EXPORT WaitCursorRemover
121 {
122 public:
123 WaitCursorRemover();
124 ~WaitCursorRemover();
125 private:
126 bool m_reactivateCursor : 1;
127 };
128
134 KEXIUTILS_EXPORT TQString fileDialogFilterString(const KMimeType::Ptr& mime, bool kdeFormat = true);
135
137 KEXIUTILS_EXPORT TQString fileDialogFilterString(const TQString& mimeString, bool kdeFormat = true);
138
141 KEXIUTILS_EXPORT TQString fileDialogFilterStrings(const TQStringList& mimeStrings, bool kdeFormat);
142
145 KEXIUTILS_EXPORT TQColor blendedColors(const TQColor& c1, const TQColor& c2, int factor1 = 1, int factor2 = 1);
146
150 KEXIUTILS_EXPORT TQColor contrastColor(const TQColor& c);
151
156 KEXIUTILS_EXPORT TQColor bleachedColor(const TQColor& c, int factor);
157
162 KEXIUTILS_EXPORT TQIconSet colorizeIconToTextColor(const TQPixmap& icon, const TQPalette& palette);
163
165 KEXIUTILS_EXPORT TQPixmap emptyIcon(TDEIcon::Group iconGroup);
166
169 KEXIUTILS_EXPORT void serializeMap(const TQMap<TQString,TQString>& map, const TQByteArray& array);
170 KEXIUTILS_EXPORT void serializeMap(const TQMap<TQString,TQString>& map, TQString& string);
171
174 KEXIUTILS_EXPORT TQMap<TQString,TQString> deserializeMap(const TQByteArray& array);
175
178 KEXIUTILS_EXPORT TQMap<TQString,TQString> deserializeMap(const TQString& string);
179
184 KEXIUTILS_EXPORT TQString stringToFileName(const TQString& string);
185
190 KEXIUTILS_EXPORT void simpleCrypt(TQString& string);
191
194 KEXIUTILS_EXPORT void simpleDecrypt(TQString& string);
195
196#ifdef KEXI_DEBUG_GUI
198 KEXIUTILS_EXPORT TQWidget *createDebugWindow(TQWidget *parent);
199
201 KEXIUTILS_EXPORT void addKexiDBDebug(const TQString& text);
202
204 KEXIUTILS_EXPORT void addAlterTableActionDebug(const TQString& text, int nestingLevel = 0);
205
208 KEXIUTILS_EXPORT void connectPushButtonActionForDebugWindow(const char* actionName,
209 const TQObject *receiver, const char* slot);
210#endif
211
214 KEXIUTILS_EXPORT void drawPixmap( TQPainter& p, int lineWidth, const TQRect& rect,
215 const TQPixmap& pixmap, int alignment, bool scaledContents, bool keepAspectRatio);
216
218 KEXIUTILS_EXPORT TQString ptrToStringInternal(void* ptr, uint size);
220 KEXIUTILS_EXPORT void* stringToPtrInternal(const TQString& str, uint size);
221
223 template<class type>
224 TQString ptrToString(type *ptr)
225 {
226 return ptrToStringInternal(ptr, sizeof(type*));
227 }
228
230 template<class type>
231 type* stringToPtr(const TQString& str)
232 {
233 return static_cast<type*>( stringToPtrInternal(str, sizeof(type*)) );
234 }
235
237 KEXIUTILS_EXPORT void setFocusWithReason(TQWidget* widget, TQFocusEvent::Reason reason);
238
240 KEXIUTILS_EXPORT void unsetFocusWithReason(TQWidget* widget, TQFocusEvent::Reason reason);
241
244 CopySuccess = 0,
245 CopyReadError = 1,
246 CopyWriteError = 2
247 };
248
254 KEXIUTILS_EXPORT CopyFileResult copyFile(const TQString& src, const TQString& dest);
255}
256
257
261#define GLUE_WIDGET(what, where) \
262 { TQVBoxLayout *lyr = new TQVBoxLayout(where); \
263 lyr->addWidget(what); }
264
265
266#endif //KEXIUTILS_UTILS_H
General Utils.
Definition identifier.h:27
KEXIUTILS_EXPORT TQString stringToFileName(const TQString &string)
KEXIUTILS_EXPORT void simpleCrypt(TQString &string)
KEXIUTILS_EXPORT void simpleDecrypt(TQString &string)
KEXIUTILS_EXPORT void unsetFocusWithReason(TQWidget *widget, TQFocusEvent::Reason reason)
Unsets focus for widget widget with reason reason.
TQDateTime stringToHackedTQTime(const TQString &s)
TQDateTime - a hack needed because TQVariant(TQTime) has broken isNull().
KEXIUTILS_EXPORT TQPixmap emptyIcon(TDEIcon::Group iconGroup)
KEXIUTILS_EXPORT TQString fileDialogFilterString(const KMimeType::Ptr &mime, bool kdeFormat=true)
KEXIUTILS_EXPORT CopyFileResult copyFile(const TQString &src, const TQString &dest)
const type * findParentConst(const TQObject *const o, const char *className)
Const version of findParent().
KEXIUTILS_EXPORT TQMap< TQString, TQString > deserializeMap(const TQByteArray &array)
KEXIUTILS_EXPORT void drawPixmap(TQPainter &p, int lineWidth, const TQRect &rect, const TQPixmap &pixmap, int alignment, bool scaledContents, bool keepAspectRatio)
type * findParent(TQObject *o, const char *className)
bool hasParent(TQObject *par, TQObject *o)
KEXIUTILS_EXPORT TQColor blendedColors(const TQColor &c1, const TQColor &c2, int factor1=1, int factor2=1)
KEXIUTILS_EXPORT void serializeMap(const TQMap< TQString, TQString > &map, const TQByteArray &array)
type * findFirstChild(TQObject *o, const char *className, const char *objName=0)
KEXIUTILS_EXPORT void setWaitCursor(bool noDelay=false)
KEXIUTILS_EXPORT TQString fileDialogFilterStrings(const TQStringList &mimeStrings, bool kdeFormat)
KEXIUTILS_EXPORT void removeWaitCursor()
CopyFileResult
Used by copyFile().
type * stringToPtr(const TQString &str)
KEXIUTILS_EXPORT TQIconSet colorizeIconToTextColor(const TQPixmap &icon, const TQPalette &palette)
KEXIUTILS_EXPORT TQColor bleachedColor(const TQColor &c, int factor)
KEXIUTILS_EXPORT void setFocusWithReason(TQWidget *widget, TQFocusEvent::Reason reason)
Sets focus for widget widget with reason reason.
KEXIUTILS_EXPORT TQColor contrastColor(const TQColor &c)
TQString ptrToString(type *ptr)