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"
30 #include <qdrawutil.h>
37 #include <QApplication>
38 #include <QDesktopWidget>
39 #include <kstringhandler.h>
40 #include <kglobalsettings.h>
42 #include <QStyleOptionFrame>
44 // specify externals before namespace
49 PopupInfo::PopupInfo( Workspace
* ws
, const char *name
)
50 : QWidget( 0 ), workspace( ws
)
52 setObjectName( name
);
59 m_delayedHideTimer
.setSingleShot(true);
60 connect(&m_delayedHideTimer
, SIGNAL(timeout()), this, SLOT(hide()));
69 PopupInfo::~PopupInfo()
77 void PopupInfo::reset()
79 QRect r
= workspace
->screenGeometry( workspace
->activeScreen());
81 int w
= fontMetrics().width( m_infoString
) + 30;
84 (r
.width()-w
)/2 + r
.x(), r
.height()/2-fontMetrics().height()-10 + r
.y(),
85 w
, fontMetrics().height() + 20 );
92 void PopupInfo::paintEvent( QPaintEvent
* )
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
);
106 Paints the contents of the tab popup info box.
107 Used in paintEvent() and whenever the contents changes.
109 void PopupInfo::paintContents()
112 QRect
r( 6, 6, width()-12, height()-12 );
114 p
.fillRect( r
, palette().brush( QPalette::Active
, QPalette::Background
) );
118 p.drawText( r, AlignCenter, m_infoString );
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();
131 QApplication::syncX();
133 while (XCheckTypedEvent (display(), EnterNotify
, &otherEvent
) )
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
)
150 m_infoString
= infoString
;
162 m_delayedHideTimer
.start(m_delayTime
);
168 #include "popupinfo.moc"