not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / popupinfo.cpp
blobadc862a50704b11bcf9017e361320e68064f4fb5
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2002 Alexander Kellett <lypanov@kde.org>
7 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************/
23 //#define QT_CLEAN_NAMESPACE
24 #include "popupinfo.h"
25 #include <QTextStream>
26 #include "workspace.h"
27 #include "client.h"
28 #include <QPainter>
29 #include <QLabel>
30 #include <qdrawutil.h>
31 #include <QStyle>
32 #include <kglobal.h>
33 #include <fixx11h.h>
34 #include <kconfig.h>
35 #include <kdebug.h>
36 #include <klocale.h>
37 #include <QApplication>
38 #include <QDesktopWidget>
39 #include <kstringhandler.h>
40 #include <kglobalsettings.h>
41 #include <QX11Info>
42 #include <QStyleOptionFrame>
44 // specify externals before namespace
46 namespace KWin
49 PopupInfo::PopupInfo( Workspace* ws, const char *name )
50 : QWidget( 0 ), workspace( ws )
52 setObjectName( name );
54 m_infoString = "";
55 m_shown = false;
56 reset();
57 reconfigure();
59 m_delayedHideTimer.setSingleShot(true);
60 connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
62 QFont f = font();
63 f.setBold( true );
64 f.setPointSize( 14 );
65 setFont( f );
69 PopupInfo::~PopupInfo()
74 /*!
75 Resets the popup info
77 void PopupInfo::reset()
79 QRect r = workspace->screenGeometry( workspace->activeScreen());
81 int w = fontMetrics().width( m_infoString ) + 30;
83 setGeometry(
84 (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
85 w, fontMetrics().height() + 20 );
89 /*!
90 Paints the popup info
92 void PopupInfo::paintEvent( QPaintEvent* )
94 QPainter p( this );
95 QStyleOptionFrame *so = new QStyleOptionFrame;
96 so->rect = QRect( 0, 0, width(), height() );
97 so->palette = palette();
98 so->palette.setCurrentColorGroup( QPalette::Active );
99 so->state = QStyle::State_None;
100 style()->drawPrimitive( QStyle::PE_Frame, so, &p );
101 paintContents();
106 Paints the contents of the tab popup info box.
107 Used in paintEvent() and whenever the contents changes.
109 void PopupInfo::paintContents()
111 QPainter p( this );
112 QRect r( 6, 6, width()-12, height()-12 );
114 p.fillRect( r, palette().brush( QPalette::Active, QPalette::Background ) );
117 p.setPen(Qt::white);
118 p.drawText( r, AlignCenter, m_infoString );
119 p.setPen(Qt::black);
120 r.translate( -1, -1 );
121 p.drawText( r, AlignCenter, m_infoString );
122 r.translate( -1, 0 );
124 p.drawText( r, Qt::AlignCenter, m_infoString );
127 void PopupInfo::hide()
129 m_delayedHideTimer.stop();
130 QWidget::hide();
131 QApplication::syncX();
132 XEvent otherEvent;
133 while (XCheckTypedEvent (display(), EnterNotify, &otherEvent ) )
135 m_shown = false;
138 void PopupInfo::reconfigure()
140 KSharedConfigPtr c(KGlobal::config());
141 const KConfigGroup cg = c->group("PopupInfo");
142 m_show = cg.readEntry("ShowPopup", false );
143 m_delayTime = cg.readEntry("PopupHideDelay", 350 );
146 void PopupInfo::showInfo(const QString &infoString)
148 if (m_show)
150 m_infoString = infoString;
151 reset();
152 if (m_shown)
154 paintContents();
156 else
158 show();
159 raise();
160 m_shown = true;
162 m_delayedHideTimer.start(m_delayTime);
166 } // namespace
168 #include "popupinfo.moc"