2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2002 Alexander Kellett <lypanov@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
#include "popupinfo.h"
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <QTextStream>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <qdrawutil.h>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <QApplication>
|
2008-02-02 20:54:19 +00:00
|
|
|
#include <QDesktopWidget>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kstringhandler.h>
|
|
|
|
#include <kglobalsettings.h>
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <QStyleOptionFrame>
|
|
|
|
|
|
|
|
// specify externals before namespace
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-07 12:18:19 +00:00
|
|
|
PopupInfo::PopupInfo( Workspace* ws, const char *name )
|
2007-06-06 10:37:37 +00:00
|
|
|
: QWidget( 0 ), workspace( ws )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2007-05-07 12:18:19 +00:00
|
|
|
setObjectName( name );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
m_infoString = "";
|
|
|
|
m_shown = false;
|
|
|
|
reset();
|
|
|
|
reconfigure();
|
|
|
|
|
|
|
|
m_delayedHideTimer.setSingleShot(true);
|
|
|
|
connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
|
|
|
|
|
|
|
|
QFont f = font();
|
|
|
|
f.setBold( true );
|
|
|
|
f.setPointSize( 14 );
|
|
|
|
setFont( f );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupInfo::~PopupInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Resets the popup info
|
|
|
|
*/
|
|
|
|
void PopupInfo::reset()
|
|
|
|
{
|
2007-05-07 12:18:19 +00:00
|
|
|
QRect r = workspace->screenGeometry( workspace->activeScreen());
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int w = fontMetrics().width( m_infoString ) + 30;
|
|
|
|
|
|
|
|
setGeometry(
|
|
|
|
(r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
|
|
|
|
w, fontMetrics().height() + 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Paints the popup info
|
|
|
|
*/
|
|
|
|
void PopupInfo::paintEvent( QPaintEvent* )
|
|
|
|
{
|
|
|
|
QPainter p( this );
|
|
|
|
QStyleOptionFrame *so = new QStyleOptionFrame;
|
|
|
|
so->rect = QRect( 0, 0, width(), height() );
|
|
|
|
so->palette = palette();
|
2007-11-09 14:09:29 +00:00
|
|
|
so->palette.setCurrentColorGroup( QPalette::Active );
|
2007-04-29 17:35:43 +00:00
|
|
|
so->state = QStyle::State_None;
|
|
|
|
style()->drawPrimitive( QStyle::PE_Frame, so, &p );
|
|
|
|
paintContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Paints the contents of the tab popup info box.
|
|
|
|
Used in paintEvent() and whenever the contents changes.
|
|
|
|
*/
|
|
|
|
void PopupInfo::paintContents()
|
|
|
|
{
|
|
|
|
QPainter p( this );
|
|
|
|
QRect r( 6, 6, width()-12, height()-12 );
|
|
|
|
|
2007-11-09 14:09:29 +00:00
|
|
|
p.fillRect( r, palette().brush( QPalette::Active, QPalette::Background ) );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
p.setPen(Qt::white);
|
|
|
|
p.drawText( r, AlignCenter, m_infoString );
|
|
|
|
p.setPen(Qt::black);
|
2008-02-19 01:58:04 +00:00
|
|
|
r.translate( -1, -1 );
|
2007-04-29 17:35:43 +00:00
|
|
|
p.drawText( r, AlignCenter, m_infoString );
|
2008-02-19 01:58:04 +00:00
|
|
|
r.translate( -1, 0 );
|
2007-04-29 17:35:43 +00:00
|
|
|
*/
|
|
|
|
p.drawText( r, Qt::AlignCenter, m_infoString );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupInfo::hide()
|
|
|
|
{
|
|
|
|
m_delayedHideTimer.stop();
|
|
|
|
QWidget::hide();
|
|
|
|
QApplication::syncX();
|
|
|
|
XEvent otherEvent;
|
|
|
|
while (XCheckTypedEvent (display(), EnterNotify, &otherEvent ) )
|
|
|
|
;
|
|
|
|
m_shown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupInfo::reconfigure()
|
|
|
|
{
|
|
|
|
KSharedConfigPtr c(KGlobal::config());
|
|
|
|
const KConfigGroup cg = c->group("PopupInfo");
|
|
|
|
m_show = cg.readEntry("ShowPopup", false );
|
|
|
|
m_delayTime = cg.readEntry("PopupHideDelay", 350 );
|
|
|
|
}
|
|
|
|
|
2007-09-02 20:01:17 +00:00
|
|
|
void PopupInfo::showInfo(const QString &infoString)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if (m_show)
|
|
|
|
{
|
|
|
|
m_infoString = infoString;
|
|
|
|
reset();
|
|
|
|
if (m_shown)
|
|
|
|
{
|
|
|
|
paintContents();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
raise();
|
|
|
|
m_shown = true;
|
|
|
|
}
|
|
|
|
m_delayedHideTimer.start(m_delayTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "popupinfo.moc"
|