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 <tqpainter.h> 00018 #include <tqlabel.h> 00019 #include <tqdrawutil.h> 00020 #include <tqstyle.h> 00021 #include <tdeglobal.h> 00022 #include <fixx11h.h> 00023 #include <tdeconfig.h> 00024 #include <kdebug.h> 00025 #include <tdelocale.h> 00026 #include <tqapplication.h> 00027 #include <tqdesktopwidget.h> 00028 #include <kstringhandler.h> 00029 #include <tdeglobalsettings.h> 00030 00031 // specify externals before namespace 00032 00033 namespace KWinInternal 00034 { 00035 00036 PopupInfo::PopupInfo( Workspace* ws, const char *name ) 00037 : TQWidget( 0, name ), workspace( ws ) 00038 { 00039 m_infoString = ""; 00040 m_shown = false; 00041 reset(); 00042 reconfigure(); 00043 connect(&m_delayedHideTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(hide())); 00044 00045 TQFont 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 TQRect r = workspace->screenGeometry( workspace->activeScreen()); 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( TQPaintEvent* ) 00076 { 00077 TQPainter p( this ); 00078 style().tqdrawPrimitive( TQStyle::PE_Panel, &p, TQRect( 0, 0, width(), height() ), 00079 colorGroup(), TQStyle::Style_Default ); 00080 paintContents(); 00081 } 00082 00083 00088 void PopupInfo::paintContents() 00089 { 00090 TQPainter p( this ); 00091 TQRect r( 6, 6, width()-12, height()-12 ); 00092 00093 p.fillRect( r, colorGroup().brush( TQColorGroup::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 TQWidget::hide(); 00110 TQApplication::syncX(); 00111 XEvent otherEvent; 00112 while (XCheckTypedEvent (tqt_xdisplay(), EnterNotify, &otherEvent ) ) 00113 ; 00114 m_shown = false; 00115 } 00116 00117 void PopupInfo::reconfigure() 00118 { 00119 TDEConfig * c(TDEGlobal::config()); 00120 c->setGroup("PopupInfo"); 00121 m_show = c->readBoolEntry("ShowPopup", false ); 00122 m_delayTime = c->readNumEntry("PopupHideDelay", 350 ); 00123 } 00124 00125 void PopupInfo::showInfo(TQString 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"