KWin
popupinfo.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "popupinfo.h"
00025 #include <QTextStream>
00026 #include "workspace.h"
00027 #include "client.h"
00028 #include <QPainter>
00029 #include <QLabel>
00030 #include <qdrawutil.h>
00031 #include <QStyle>
00032 #include <kglobal.h>
00033 #include <fixx11h.h>
00034 #include <kconfig.h>
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037 #include <QApplication>
00038 #include <QDesktopWidget>
00039 #include <kstringhandler.h>
00040 #include <kglobalsettings.h>
00041 #include <QX11Info>
00042 #include <QStyleOptionFrame>
00043
00044
00045
00046 namespace KWin
00047 {
00048
00049 PopupInfo::PopupInfo( Workspace* ws, const char *name )
00050 : QWidget( 0 ), workspace( ws )
00051 {
00052 setObjectName( name );
00053
00054 m_infoString = "";
00055 m_shown = false;
00056 reset();
00057 reconfigure();
00058
00059 m_delayedHideTimer.setSingleShot(true);
00060 connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
00061
00062 QFont f = font();
00063 f.setBold( true );
00064 f.setPointSize( 14 );
00065 setFont( f );
00066
00067 }
00068
00069 PopupInfo::~PopupInfo()
00070 {
00071 }
00072
00073
00077 void PopupInfo::reset()
00078 {
00079 QRect r = workspace->screenGeometry( workspace->activeScreen());
00080
00081 int w = fontMetrics().width( m_infoString ) + 30;
00082
00083 setGeometry(
00084 (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
00085 w, fontMetrics().height() + 20 );
00086 }
00087
00088
00092 void PopupInfo::paintEvent( QPaintEvent* )
00093 {
00094 QPainter p( this );
00095 QStyleOptionFrame *so = new QStyleOptionFrame;
00096 so->rect = QRect( 0, 0, width(), height() );
00097 so->palette = palette();
00098 so->palette.setCurrentColorGroup( QPalette::Active );
00099 so->state = QStyle::State_None;
00100 style()->drawPrimitive( QStyle::PE_Frame, so, &p );
00101 paintContents();
00102 }
00103
00104
00109 void PopupInfo::paintContents()
00110 {
00111 QPainter p( this );
00112 QRect r( 6, 6, width()-12, height()-12 );
00113
00114 p.fillRect( r, palette().brush( QPalette::Active, QPalette::Background ) );
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 p.drawText( r, Qt::AlignCenter, m_infoString );
00125 }
00126
00127 void PopupInfo::hide()
00128 {
00129 m_delayedHideTimer.stop();
00130 QWidget::hide();
00131 QApplication::syncX();
00132 XEvent otherEvent;
00133 while (XCheckTypedEvent (display(), EnterNotify, &otherEvent ) )
00134 ;
00135 m_shown = false;
00136 }
00137
00138 void PopupInfo::reconfigure()
00139 {
00140 KSharedConfigPtr c(KGlobal::config());
00141 const KConfigGroup cg = c->group("PopupInfo");
00142 m_show = cg.readEntry("ShowPopup", false );
00143 m_delayTime = cg.readEntry("PopupHideDelay", 350 );
00144 }
00145
00146 void PopupInfo::showInfo(const QString &infoString)
00147 {
00148 if (m_show)
00149 {
00150 m_infoString = infoString;
00151 reset();
00152 if (m_shown)
00153 {
00154 paintContents();
00155 }
00156 else
00157 {
00158 show();
00159 raise();
00160 m_shown = true;
00161 }
00162 m_delayedHideTimer.start(m_delayTime);
00163 }
00164 }
00165
00166 }
00167
00168 #include "popupinfo.moc"