You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
3.9 KiB
179 lines
3.9 KiB
15 years ago
|
/*
|
||
|
* copyright : (C) 2001-2002 by Richard Moore
|
||
|
* License : This file is released under the terms of the LGPL, version 2.
|
||
|
* email : rich@kde.org
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqobjectlist.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqtimer.h>
|
||
|
#include <tqtooltip.h>
|
||
15 years ago
|
#include <ksystemtray.h>
|
||
13 years ago
|
#include <twin.h>
|
||
15 years ago
|
|
||
13 years ago
|
#include "twindowinfo.h"
|
||
|
#include "twindowinfo.moc"
|
||
15 years ago
|
|
||
|
static const int UNSPECIFIED_TIMEOUT = -1;
|
||
|
static const int DEFAULT_MESSAGE_TIMEOUT = 3000;
|
||
|
|
||
15 years ago
|
KWindowInfo::KWindowInfo( TQWidget *parent, const char *name )
|
||
|
: TQObject( parent, name ), win( parent ), autoDel( false )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
KWindowInfo::~KWindowInfo()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::showMessage( TQWidget *window, const TQString &text, int timeout )
|
||
15 years ago
|
{
|
||
|
KWindowInfo *info = new KWindowInfo( window );
|
||
|
info->autoDel = true;
|
||
|
info->message( text, timeout );
|
||
|
if ( timeout == 0 )
|
||
|
delete info;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::showMessage( TQWidget *window, const TQString &text, const TQPixmap &pix, int timeout )
|
||
15 years ago
|
{
|
||
|
KWindowInfo *info = new KWindowInfo( window );
|
||
|
info->autoDel = true;
|
||
|
info->message( text, pix, timeout );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::message( const TQString &text )
|
||
15 years ago
|
{
|
||
15 years ago
|
message( text, TQPixmap(), UNSPECIFIED_TIMEOUT );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::message( const TQString &text, const TQPixmap &pix )
|
||
15 years ago
|
{
|
||
|
message( text, pix, UNSPECIFIED_TIMEOUT );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::message( const TQString &text, int timeout )
|
||
15 years ago
|
{
|
||
15 years ago
|
message( text, TQPixmap(), timeout );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::message( const TQString &text, const TQPixmap &pix, int timeout )
|
||
15 years ago
|
{
|
||
|
if ( timeout != 0 )
|
||
|
save();
|
||
|
|
||
|
display( text, pix );
|
||
|
|
||
|
if ( timeout < 0 )
|
||
|
timeout = DEFAULT_MESSAGE_TIMEOUT;
|
||
|
if ( timeout != 0 )
|
||
15 years ago
|
TQTimer::singleShot( timeout, this, TQT_SLOT( restore() ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::permanent( const TQString &text )
|
||
15 years ago
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
|
||
|
oldIcon = KWin::icon( win->winId(), 34, 34, false );
|
||
|
if ( oldIcon.isNull() )
|
||
|
oldIcon = KWin::icon( win->winId(), 32, 32, true );
|
||
|
#endif
|
||
|
|
||
|
permanent( text, oldIcon );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::permanent( const TQString &text, const TQPixmap &pix )
|
||
15 years ago
|
{
|
||
|
if ( !oldText.isNull() ) {
|
||
14 years ago
|
TQObjectList *l = queryList( TQTIMER_OBJECT_NAME_STRING );
|
||
15 years ago
|
TQObjectListIt it( *l );
|
||
|
TQObject *obj;
|
||
15 years ago
|
|
||
|
while ( (obj = it.current()) != 0 ) {
|
||
|
++it;
|
||
|
delete obj;
|
||
|
}
|
||
|
delete l;
|
||
|
}
|
||
|
|
||
15 years ago
|
oldText = TQString::null;
|
||
15 years ago
|
display( text, pix );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KWindowInfo::display( const TQString &text, const TQPixmap &pix )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPixmap icon;
|
||
15 years ago
|
if ( pix.isNull() )
|
||
|
icon.load( "bell.png" );
|
||
|
else
|
||
|
icon = pix;
|
||
|
|
||
|
if ( win->inherits( "KSystemTray" ) ) {
|
||
|
KSystemTray *tray = static_cast<KSystemTray *>( win );
|
||
|
tray->setPixmap( icon );
|
||
15 years ago
|
TQToolTip::add( tray, text );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
win->setCaption( text );
|
||
|
win->setIcon( icon );
|
||
|
#ifdef Q_WS_X11
|
||
|
KWin::setIcons( win->winId(), icon, icon );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void KWindowInfo::save()
|
||
|
{
|
||
|
if ( !oldText.isNull() )
|
||
|
return;
|
||
|
|
||
|
if ( win->inherits( "KSystemTray" ) ) {
|
||
|
KSystemTray *tray = static_cast<KSystemTray *>( win );
|
||
|
oldIcon = *(tray->pixmap());
|
||
15 years ago
|
oldText = TQToolTip::textFor( tray );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
oldText = win->caption();
|
||
|
#ifdef Q_WS_X11
|
||
|
oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
|
||
|
oldIcon = KWin::icon( win->winId(), 34, 34, false );
|
||
|
if ( oldIcon.isNull() )
|
||
|
oldIcon = KWin::icon( win->winId(), 32, 32, true );
|
||
|
#endif
|
||
|
|
||
|
if ( oldIcon.isNull() ) {
|
||
15 years ago
|
const TQPixmap *px = win->icon();
|
||
15 years ago
|
if ( px )
|
||
|
oldIcon = *px;
|
||
|
else
|
||
|
oldIcon.resize( 0, 0 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KWindowInfo::restore()
|
||
|
{
|
||
|
if ( win->inherits( "KSystemTray" ) ) {
|
||
|
KSystemTray *tray = static_cast<KSystemTray *>( win );
|
||
|
tray->setPixmap( oldIcon );
|
||
15 years ago
|
TQToolTip::add( tray, oldText );
|
||
|
oldText = TQString::null;
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
win->setIcon( oldIcon );
|
||
|
#ifdef Q_WS_X11
|
||
|
KWin::setIcons( win->winId(), oldIcon, oldMiniIcon );
|
||
|
#endif
|
||
|
win->setCaption( oldText );
|
||
15 years ago
|
oldText = TQString::null;
|
||
15 years ago
|
|
||
|
if ( autoDel )
|
||
|
delete this;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|