33#include <tdeapplication.h>
35#include <kiconeffect.h>
36#include <kpixmapeffect.h>
37#include <kiconloader.h>
40# include <win32_utils.h>
45DelayedCursorHandler::DelayedCursorHandler()
46 : startedOrActive(false)
48 connect(&timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(show()));
50void DelayedCursorHandler::start( bool noDelay) {
51 startedOrActive = true;
52 timer.start(noDelay ? 0 : 1000, true);
54void DelayedCursorHandler::stop() {
55 startedOrActive = false;
57 TQApplication::restoreOverrideCursor();
59void DelayedCursorHandler::show() {
60 TQApplication::setOverrideCursor( KCursor::waitCursor(), true );
63DelayedCursorHandler _delayedCursorHandler;
66 if (kapp->guiEnabled())
67 _delayedCursorHandler.start(noDelay);
70 if (kapp->guiEnabled())
71 _delayedCursorHandler.stop();
74WaitCursor::WaitCursor( bool noDelay)
79WaitCursor::~WaitCursor()
84WaitCursorRemover::WaitCursorRemover()
86 m_reactivateCursor = _delayedCursorHandler.startedOrActive;
87 _delayedCursorHandler.stop();
90WaitCursorRemover::~WaitCursorRemover()
92 if (m_reactivateCursor)
93 _delayedCursorHandler.start( true);
105 if (mime->patterns().isEmpty())
108 str = mime->patterns().join( " ");
111 str += mime->comment();
112 if (!mime->patterns().isEmpty() || !kdeFormat) {
114 if (mime->patterns().isEmpty())
117 str += mime->patterns().join( "; ");
129 KMimeType::Ptr ptr = KMimeType::mimeType(mimeString);
136 TQStringList::ConstIterator endIt = mimeStrings.constEnd();
137 for(TQStringList::ConstIterator it = mimeStrings.constBegin(); it != endIt; ++it)
145 int( (c1.red()*factor1+c2.red()*factor2)/(factor1+factor2) ),
146 int( (c1.green()*factor1+c2.green()*factor2)/(factor1+factor2) ),
147 int( (c1.blue()*factor1+c2.blue()*factor2)/(factor1+factor2) ) );
152 int g = tqGray( c.rgb() );
165 c.getHsv( &h, &s, &v );
169 if (s>=250 && v>=250)
170 s = TQMAX(0, s - factor - 50);
171 else if (s<=5 && s<=5)
173 c2.setHsv(h, s, TQMIN(255,v + factor-100));
180 TDEIconEffect().apply( icon, TDEIconEffect::Colorize, 1.0f, palette.active().buttonText(), false ) );
184 KPixmapEffect::fade( kpm, 0.33, palette.active().button() ) );
189 TQPixmap noIcon( IconSize( iconGroup ), IconSize( iconGroup ) );
190 TQBitmap bmpNoIcon(noIcon.size());
191 bmpNoIcon.fill(TQt::color0);
192 noIcon.setMask(bmpNoIcon);
198 TQDataStream ds(array, IO_WriteOnly);
205 TQDataStream ds(array, IO_WriteOnly);
207 kdDebug() << array[3] << " " << array[4] << " " << array[5] << endl;
208 const uint size = array.size();
210 string.reserve(size);
211 for (uint i=0; i<size; i++) {
212 string[i]=TQChar(ushort(array[i]+1));
218 TQMap<TQString,TQString> map;
219 TQDataStream ds(array, IO_ReadOnly);
226 const uint size = string.length();
227 TQCString cstr( string.latin1());
228 TQByteArray array( size );
229 for (uint i=0; i<size; i++) {
230 array[i] = char( string[i].unicode()-1);
232 TQMap<TQString,TQString> map;
233 TQDataStream ds(array, IO_ReadOnly);
240 TQString _string( string);
241 _string.replace(TQRegExp( "[\\\\/:\\*?\"<>|]"), " ");
242 return _string.simplifyWhiteSpace();
247 for (uint i=0; i< string.length(); i++)
248 string[i] = TQChar( string[i].unicode() + 47 + i );
253 for (uint i=0; i< string.length(); i++)
254 string[i] = TQChar( string[i].unicode() - 47 - i );
258 const TQPixmap& pixmap, int alignment, bool scaledContents, bool keepAspectRatio)
263 const bool fast = pixmap.width()>1000 && pixmap.height()>800;
264 const int w = rect.width()-lineWidth-lineWidth;
265 const int h = rect.height()-lineWidth-lineWidth;
268 TQPixmap pixmapBuffer;
283 if (scaledContents) {
284 if (keepAspectRatio) {
285 TQImage img(pixmap.convertToImage());
286 img = img.smoothScale(w, h, TQImage::ScaleMin);
287 pos = rect.topLeft();
288 if (img.width() < w) {
289 int hAlign = TQApplication::horizontalAlignment( alignment );
290 if ( hAlign & TQt::AlignRight )
291 pos.setX(pos.x() + w-img.width());
292 else if ( hAlign & TQt::AlignHCenter )
293 pos.setX(pos.x() + w/2-img.width()/2);
295 else if (img.height() < h) {
296 if ( alignment & TQt::AlignBottom )
297 pos.setY(pos.y() + h-img.height());
298 else if ( alignment & TQt::AlignVCenter )
299 pos.setY(pos.y() + h/2-img.height()/2);
301 pixmapBuffer.convertFromImage(img);
303 p2.begin(&pixmapBuffer, p.device());
306 target->drawPixmap(pos, pixmapBuffer);
310 pixmapBuffer.resize(rect.size()-TQSize(lineWidth, lineWidth));
311 p2.begin(&pixmapBuffer, p.device());
312 p2.drawPixmap(TQRect(rect.x(), rect.y(), w, h), pixmap);
315 target->drawPixmap(TQRect(rect.x() + lineWidth, rect.y() + lineWidth, w, h), pixmap);
319 int hAlign = TQApplication::horizontalAlignment( alignment );
320 if ( hAlign & TQt::AlignRight )
321 pos.setX(pos.x() + w-pixmap.width());
322 else if ( hAlign & TQt::AlignHCenter )
323 pos.setX(pos.x() + w/2-pixmap.width()/2);
327 if ( alignment & TQt::AlignBottom )
328 pos.setY(pos.y() + h-pixmap.height());
329 else if ( alignment & TQt::AlignVCenter )
330 pos.setY(pos.y() + h/2-pixmap.height()/2);
336 p.drawPixmap(lineWidth+pos.x(), lineWidth+pos.y(), pixmap);
338 if (scaledContents && !fast && p.isActive()) {
343 ( int)p.worldMatrix().dx() + rect.x() + lineWidth + pos.x(),
344 ( int)p.worldMatrix().dy() + rect.y() + lineWidth + pos.y(),
349TQString KexiUtils::ptrToStringInternal( void* ptr, uint size)
352 unsigned char* cstr_ptr = ( unsigned char*)&ptr;
353 for (uint i=0; i<size; i++) {
355 s.sprintf( "%2.2x", cstr_ptr[i]);
361void* KexiUtils::stringToPtrInternal( const TQString& str, uint size)
363 TQByteArray array(size);
364 if ((str.length()/2)<size)
367 for (uint i=0; i<size; i++) {
368 array[i]=( unsigned char)(str.mid(i*2, 2).toUInt(&ok, 16));
372 return *( void**)(array.data());
377 TQEvent fe( TQEvent::FocusIn );
378 static_cast<TQFocusEvent* >(&fe)->setReason(reason);
379 TQApplication::sendEvent( widget, &fe );
380 static_cast<TQFocusEvent* >(&fe)->resetReason();
385 TQEvent fe( TQEvent::FocusOut );
386 static_cast<TQFocusEvent* >(&fe)->setReason(reason);
387 TQApplication::sendEvent( widget, &fe );
388 static_cast<TQFocusEvent* >(&fe)->resetReason();
394 int res = fcopy( TQFile::encodeName( src ), TQFile::encodeName( dest ) );
395 if (res == fcopy_src_err)
396 return CopyReadError;
397 else if (res == fcopy_dest_err)
398 return CopyWriteError;
402# define _fcopy_BUFLEN 1024*32
403 char _fcopy_buf[_fcopy_BUFLEN];
408 in=fopen(TQFile::encodeName( src ), "rb");
410 return CopyReadError;
411 out=fopen(TQFile::encodeName( dest ), "wb");
413 return CopyWriteError;
414 while (!feof(in) && !ferror(in) && !ferror(out)) {
415 c_in=fread(_fcopy_buf, 1, _fcopy_BUFLEN, in);
416 if (ferror(in) || c_in==0)
418 c_out=fwrite(_fcopy_buf, 1, c_in, out);
419 if (ferror(out) || c_in!=c_out)
425 else if (ferror(out))
427 else if (c_in!=c_out)
435#include "utils_p.moc"
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.
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)
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)
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)
KEXIUTILS_EXPORT void setWaitCursor(bool noDelay=false)
KEXIUTILS_EXPORT TQString fileDialogFilterStrings(const TQStringList &mimeStrings, bool kdeFormat)
KEXIUTILS_EXPORT void removeWaitCursor()
CopyFileResult Used by copyFile().
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)
|