parent
defd6f44a9
commit
8d8d9ea4a3
2 changed files with 181 additions and 0 deletions
@ -0,0 +1,139 @@ |
|||||||
|
// animated busy pointer
|
||||||
|
|
||||||
|
#include "kbusyptr.h" |
||||||
|
#include <kapp.h> |
||||||
|
#include <qcursor.h> |
||||||
|
#include <qtimer.h> |
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
KBusyPtr :: KBusyPtr (KApplication* aApp) |
||||||
|
{ |
||||||
|
app = aApp; |
||||||
|
if (!app) printf ("KBusyPtr error: KApplication required\n"); |
||||||
|
|
||||||
|
busyLevel = 0; |
||||||
|
numCursors = 0; |
||||||
|
frameDelay = 500; |
||||||
|
cursorList = NULL; |
||||||
|
bitmapList = NULL; |
||||||
|
|
||||||
|
loadCursor("./pics/stopwatch.xbm","./pics/stopwatchMask.xbm"); |
||||||
|
|
||||||
|
//connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
KBusyPtr :: ~KBusyPtr() |
||||||
|
{ |
||||||
|
if (cursorList) delete cursorList; |
||||||
|
if (bitmapList) delete bitmapList; |
||||||
|
cursorList = NULL; |
||||||
|
bitmapList = NULL; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void KBusyPtr :: busy (void) |
||||||
|
{ |
||||||
|
KAlarmTimer* kat; |
||||||
|
|
||||||
|
if (busyLevel <= 0) |
||||||
|
{ |
||||||
|
currentCursor = 0; |
||||||
|
if (!cursorList) |
||||||
|
{ |
||||||
|
app->setOverrideCursor(waitCursor); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
app->setOverrideCursor(cursorList[currentCursor]); |
||||||
|
start(500); |
||||||
|
} |
||||||
|
} |
||||||
|
busyLevel++; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void KBusyPtr :: idle (void) |
||||||
|
{ |
||||||
|
busyLevel--; |
||||||
|
if (busyLevel < 0) busyLevel = 0; |
||||||
|
|
||||||
|
if (busyLevel <= 0) |
||||||
|
{ |
||||||
|
stop(); |
||||||
|
app->restoreOverrideCursor(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void KBusyPtr :: timerEvent (void) |
||||||
|
{ |
||||||
|
if (busyLevel <= 0) return; |
||||||
|
|
||||||
|
if (++currentCursor >= numCursors) currentCursor = 0; |
||||||
|
|
||||||
|
if (cursorList) |
||||||
|
app->setOverrideCursor(cursorList[currentCursor], TRUE); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
bool KBusyPtr :: loadBitmap (QBitmap& bm, const QString& filename) |
||||||
|
{ |
||||||
|
QString f; |
||||||
|
bool rc; |
||||||
|
|
||||||
|
if (filename[0]=='/' || filename[0]=='.') |
||||||
|
{ |
||||||
|
f = filename; |
||||||
|
} |
||||||
|
else
|
||||||
|
{ |
||||||
|
f = kapp->kdedir(); |
||||||
|
f.detach(); |
||||||
|
f += "/lib/pics/"; |
||||||
|
f += filename; |
||||||
|
} |
||||||
|
rc = bm.load(f); |
||||||
|
if (!rc) printf ("ERROR: cannot load bitmap %s\n", f.data()); |
||||||
|
return rc; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void KBusyPtr :: loadCursor (const char* cursorName,const char* maskName) |
||||||
|
{ |
||||||
|
int i, ix, iy, numX, numY, x, y; |
||||||
|
QBitmap map, mask; |
||||||
|
QBitmap cmap(16,16), cmask(16,16); |
||||||
|
|
||||||
|
numCursors = 0; |
||||||
|
|
||||||
|
if (!loadBitmap(map,cursorName)) return; |
||||||
|
if (!loadBitmap(mask,maskName)) return; |
||||||
|
|
||||||
|
numX = map.width() >> 4; |
||||||
|
numY = map.height() >> 4; |
||||||
|
numCursors = numX * numY; |
||||||
|
|
||||||
|
if (bitmapList) delete[] bitmapList; |
||||||
|
bitmapList = new QBitmap[numCursors](16,16); |
||||||
|
if (cursorList) delete[] cursorList; |
||||||
|
cursorList = new QCursor[numCursors]; |
||||||
|
|
||||||
|
for (i=0,iy=0,y=0; iy<numY; iy++, y+=16) |
||||||
|
{ |
||||||
|
for (ix=0,x=0; ix<numX; ix++, x+=16, i++) |
||||||
|
{ |
||||||
|
bitBlt(&cmap, 0, 0, &map, x, y, 16, 16); |
||||||
|
bitBlt(&cmask, 0, 0, &mask, x, y, 16, 16); |
||||||
|
cursorList[i] = QCursor(cmap, cmask, 8, 8); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#include "kbusyptr.moc" |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
/* animated busy pointer handling
|
||||||
|
*/ |
||||||
|
#ifndef kbusyptr_h_ |
||||||
|
#define kbusyptr_h_ |
||||||
|
|
||||||
|
#include "kalarmtimer.h" |
||||||
|
|
||||||
|
class KApplication; |
||||||
|
class QCursor; |
||||||
|
|
||||||
|
class KBusyPtr: public KAlarmTimer |
||||||
|
{ |
||||||
|
Q_OBJECT; |
||||||
|
|
||||||
|
public: |
||||||
|
KBusyPtr(KApplication*); |
||||||
|
virtual ~KBusyPtr(); |
||||||
|
|
||||||
|
virtual void busy(void); |
||||||
|
virtual void idle(void); |
||||||
|
|
||||||
|
virtual void loadCursor(const char* cursorName, const char* maskName); |
||||||
|
// Load cursor from given bitmap files. When the filename
|
||||||
|
// is relative the $KDEDIR/lib/pics directory is searched
|
||||||
|
|
||||||
|
protected: |
||||||
|
virtual void timerEvent(void); |
||||||
|
|
||||||
|
private: |
||||||
|
bool loadBitmap(QBitmap& bitmap, const QString& fileName); |
||||||
|
|
||||||
|
protected: |
||||||
|
KApplication* app; |
||||||
|
int busyLevel; |
||||||
|
int numCursors; |
||||||
|
int frameDelay; |
||||||
|
int currentCursor; |
||||||
|
QCursor* cursorList; |
||||||
|
QBitmap* bitmapList; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif /*kbusyptr_h_*/ |
||||||
Loading…
Reference in new issue