2002-04-05 19:54:21 +00:00
|
|
|
/*****************************************************************
|
2003-09-16 19:28:03 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2002-04-05 19:54:21 +00:00
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
2002-04-11 01:06:33 +00:00
|
|
|
Copyright (C) 2002 Alexander Kellett <lypanov@kde.org>
|
2003-09-16 19:28:03 +00:00
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
2002-04-05 19:54:21 +00:00
|
|
|
******************************************************************/
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2002-04-05 19:54:21 +00:00
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
#include "popupinfo.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QPainter>
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QLabel>
|
2002-04-05 19:54:21 +00:00
|
|
|
#include <qdrawutil.h>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QStyle>
|
2002-04-05 19:54:21 +00:00
|
|
|
#include <kglobal.h>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <fixx11h.h>
|
2002-04-05 19:54:21 +00:00
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QApplication>
|
2002-04-05 19:54:21 +00:00
|
|
|
#include <qdesktopwidget.h>
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QCursor>
|
2002-04-05 19:54:21 +00:00
|
|
|
#include <kstringhandler.h>
|
2003-02-20 05:52:39 +00:00
|
|
|
#include <kglobalsettings.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QX11Info>
|
2006-01-22 12:44:42 +00:00
|
|
|
#include <QStyleOptionFrame>
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
// specify externals before namespace
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
PopupInfo::PopupInfo( const char *name )
|
2006-04-12 15:13:31 +00:00
|
|
|
: QWidget( 0 )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2006-04-12 15:13:31 +00:00
|
|
|
setObjectName( name );
|
|
|
|
|
2002-04-05 19:54:21 +00:00
|
|
|
m_infoString = "";
|
2006-03-31 10:33:03 +00:00
|
|
|
m_shown = false;
|
2002-04-05 19:54:21 +00:00
|
|
|
reset();
|
|
|
|
reconfigure();
|
2006-04-11 17:12:05 +00:00
|
|
|
|
|
|
|
m_delayedHideTimer.setSingleShot(true);
|
2002-04-05 19:54:21 +00:00
|
|
|
connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
|
|
|
|
|
|
|
|
QFont f = font();
|
2006-02-19 01:33:48 +00:00
|
|
|
f.setBold( true );
|
2002-04-05 19:54:21 +00:00
|
|
|
f.setPointSize( 14 );
|
|
|
|
setFont( f );
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
PopupInfo::~PopupInfo()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Resets the popup info
|
|
|
|
*/
|
|
|
|
void PopupInfo::reset()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2003-02-20 05:52:39 +00:00
|
|
|
QRect r = KGlobalSettings::desktopGeometry(QCursor::pos());
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
int w = fontMetrics().width( m_infoString ) + 30;
|
|
|
|
|
|
|
|
setGeometry(
|
|
|
|
(r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
|
2006-04-10 11:57:13 +00:00
|
|
|
w, fontMetrics().height() + 20 );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Paints the popup info
|
|
|
|
*/
|
|
|
|
void PopupInfo::paintEvent( QPaintEvent* )
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-04-05 19:54:21 +00:00
|
|
|
QPainter p( this );
|
2006-01-22 12:44:42 +00:00
|
|
|
QStyleOptionFrame *so = new QStyleOptionFrame;
|
|
|
|
so->rect = QRect( 0, 0, width(), height() );
|
|
|
|
so->palette = palette();
|
|
|
|
so->state = QStyle::State_None;
|
|
|
|
style()->drawPrimitive( QStyle::PE_Frame, so, &p );
|
2002-04-05 19:54:21 +00:00
|
|
|
paintContents();
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Paints the contents of the tab popup info box.
|
|
|
|
Used in paintEvent() and whenever the contents changes.
|
|
|
|
*/
|
|
|
|
void PopupInfo::paintContents()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-04-05 19:54:21 +00:00
|
|
|
QPainter p( this );
|
|
|
|
QRect r( 6, 6, width()-12, height()-12 );
|
|
|
|
|
2006-04-12 15:13:31 +00:00
|
|
|
p.fillRect( r, palette().brush( QPalette::Background ) );
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
p.setPen(Qt::white);
|
|
|
|
p.drawText( r, AlignCenter, m_infoString );
|
|
|
|
p.setPen(Qt::black);
|
|
|
|
r.moveBy( -1, -1 );
|
|
|
|
p.drawText( r, AlignCenter, m_infoString );
|
|
|
|
r.moveBy( -1, 0 );
|
|
|
|
*/
|
2005-07-28 14:59:42 +00:00
|
|
|
p.drawText( r, Qt::AlignCenter, m_infoString );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
void PopupInfo::hide()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-04-05 19:54:21 +00:00
|
|
|
m_delayedHideTimer.stop();
|
|
|
|
QWidget::hide();
|
|
|
|
QApplication::syncX();
|
|
|
|
XEvent otherEvent;
|
2005-07-28 14:59:42 +00:00
|
|
|
while (XCheckTypedEvent (QX11Info::display(), EnterNotify, &otherEvent ) )
|
2003-09-16 19:28:03 +00:00
|
|
|
;
|
2002-04-05 19:54:21 +00:00
|
|
|
m_shown = false;
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
void PopupInfo::reconfigure()
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
2002-04-05 19:54:21 +00:00
|
|
|
KConfig * c(KGlobal::config());
|
|
|
|
c->setGroup("PopupInfo");
|
2006-01-21 19:36:31 +00:00
|
|
|
m_show = c->readEntry("ShowPopup", false );
|
|
|
|
m_delayTime = c->readEntry("PopupHideDelay", 350 );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
void PopupInfo::showInfo(QString infoString)
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
if (m_show)
|
|
|
|
{
|
|
|
|
m_infoString = infoString;
|
|
|
|
reset();
|
|
|
|
if (m_shown)
|
|
|
|
{
|
|
|
|
paintContents();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
raise();
|
|
|
|
m_shown = true;
|
|
|
|
}
|
2006-04-11 17:12:05 +00:00
|
|
|
m_delayedHideTimer.start(m_delayTime);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2002-04-05 19:54:21 +00:00
|
|
|
}
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
} // namespace
|
2002-04-05 19:54:21 +00:00
|
|
|
|
|
|
|
#include "popupinfo.moc"
|