kwin Library API Documentation

popupinfo.cpp

00001 /***************************************************************** 00002 KWin - the KDE window manager 00003 This file is part of the KDE project. 00004 00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org> 00006 Copyright (C) 2002 Alexander Kellett <lypanov@kde.org> 00007 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org> 00008 00009 You can Freely distribute this program under the GNU General Public 00010 License. See the file "COPYING" for the exact licensing terms. 00011 ******************************************************************/ 00012 00013 //#define QT_CLEAN_NAMESPACE 00014 #include "popupinfo.h" 00015 #include "workspace.h" 00016 #include "client.h" 00017 #include <qpainter.h> 00018 #include <qlabel.h> 00019 #include <qdrawutil.h> 00020 #include <qstyle.h> 00021 #include <kglobal.h> 00022 #include <fixx11h.h> 00023 #include <kconfig.h> 00024 #include <kdebug.h> 00025 #include <klocale.h> 00026 #include <qapplication.h> 00027 #include <qdesktopwidget.h> 00028 #include <qcursor.h> 00029 #include <kstringhandler.h> 00030 #include <kglobalsettings.h> 00031 00032 // specify externals before namespace 00033 00034 namespace KWinInternal 00035 { 00036 00037 PopupInfo::PopupInfo( const char *name ) 00038 : QWidget( 0, name ) 00039 { 00040 m_infoString = ""; 00041 reset(); 00042 reconfigure(); 00043 connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide())); 00044 00045 QFont f = font(); 00046 f.setBold( TRUE ); 00047 f.setPointSize( 14 ); 00048 setFont( f ); 00049 00050 } 00051 00052 PopupInfo::~PopupInfo() 00053 { 00054 } 00055 00056 00060 void PopupInfo::reset() 00061 { 00062 QRect r = KGlobalSettings::desktopGeometry(QCursor::pos()); 00063 00064 int w = fontMetrics().width( m_infoString ) + 30; 00065 00066 setGeometry( 00067 (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(), 00068 w, fontMetrics().height() + 20 ); 00069 } 00070 00071 00075 void PopupInfo::paintEvent( QPaintEvent* ) 00076 { 00077 QPainter p( this ); 00078 style().drawPrimitive( QStyle::PE_Panel, &p, QRect( 0, 0, width(), height() ), 00079 colorGroup(), QStyle::Style_Default ); 00080 paintContents(); 00081 } 00082 00083 00088 void PopupInfo::paintContents() 00089 { 00090 QPainter p( this ); 00091 QRect r( 6, 6, width()-12, height()-12 ); 00092 00093 p.fillRect( r, colorGroup().brush( QColorGroup::Background ) ); 00094 00095 /* 00096 p.setPen(Qt::white); 00097 p.drawText( r, AlignCenter, m_infoString ); 00098 p.setPen(Qt::black); 00099 r.moveBy( -1, -1 ); 00100 p.drawText( r, AlignCenter, m_infoString ); 00101 r.moveBy( -1, 0 ); 00102 */ 00103 p.drawText( r, AlignCenter, m_infoString ); 00104 } 00105 00106 void PopupInfo::hide() 00107 { 00108 m_delayedHideTimer.stop(); 00109 QWidget::hide(); 00110 QApplication::syncX(); 00111 XEvent otherEvent; 00112 while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) ) 00113 ; 00114 m_shown = false; 00115 } 00116 00117 void PopupInfo::reconfigure() 00118 { 00119 KConfig * c(KGlobal::config()); 00120 c->setGroup("PopupInfo"); 00121 m_show = c->readNumEntry("ShowPopup", false ); 00122 m_delayTime = c->readNumEntry("PopupHideDelay", 350 ); 00123 } 00124 00125 void PopupInfo::showInfo(QString infoString) 00126 { 00127 if (m_show) 00128 { 00129 m_infoString = infoString; 00130 reset(); 00131 if (m_shown) 00132 { 00133 paintContents(); 00134 } 00135 else 00136 { 00137 show(); 00138 raise(); 00139 m_shown = true; 00140 } 00141 m_delayedHideTimer.start(m_delayTime, true); 00142 } 00143 } 00144 00145 } // namespace 00146 00147 #include "popupinfo.moc"
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 16 15:59:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003