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 #include "popupinfo.h" 00014 #include "workspace.h" 00015 #include "client.h" 00016 #include <tqpainter.h> 00017 #include <tqlabel.h> 00018 #include <tqdrawutil.h> 00019 #include <tqstyle.h> 00020 #include <tdeglobal.h> 00021 #include <fixx11h.h> 00022 #include <tdeconfig.h> 00023 #include <kdebug.h> 00024 #include <tdelocale.h> 00025 #include <tqapplication.h> 00026 #include <tqdesktopwidget.h> 00027 #include <kstringhandler.h> 00028 #include <tdeglobalsettings.h> 00029 00030 // specify externals before namespace 00031 00032 namespace KWinInternal 00033 { 00034 00035 PopupInfo::PopupInfo( Workspace* ws, const char *name ) 00036 : TQWidget( 0, name ), workspace( ws ) 00037 { 00038 m_infoString = ""; 00039 m_shown = false; 00040 reset(); 00041 reconfigure(); 00042 connect(&m_delayedHideTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(hide())); 00043 00044 TQFont f = font(); 00045 f.setBold( TRUE ); 00046 f.setPointSize( 14 ); 00047 setFont( f ); 00048 00049 } 00050 00051 PopupInfo::~PopupInfo() 00052 { 00053 } 00054 00055 00059 void PopupInfo::reset() 00060 { 00061 TQRect r = workspace->screenGeometry( workspace->activeScreen()); 00062 00063 int w = fontMetrics().width( m_infoString ) + 30; 00064 00065 setGeometry( 00066 (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(), 00067 w, fontMetrics().height() + 20 ); 00068 } 00069 00070 00074 void PopupInfo::paintEvent( TQPaintEvent* ) 00075 { 00076 TQPainter p( this ); 00077 style().tqdrawPrimitive( TQStyle::PE_Panel, &p, TQRect( 0, 0, width(), height() ), 00078 colorGroup(), TQStyle::Style_Default ); 00079 paintContents(); 00080 } 00081 00082 00087 void PopupInfo::paintContents() 00088 { 00089 TQPainter p( this ); 00090 TQRect r( 6, 6, width()-12, height()-12 ); 00091 00092 p.fillRect( r, colorGroup().brush( TQColorGroup::Background ) ); 00093 00094 /* 00095 p.setPen(Qt::white); 00096 p.drawText( r, AlignCenter, m_infoString ); 00097 p.setPen(Qt::black); 00098 r.moveBy( -1, -1 ); 00099 p.drawText( r, AlignCenter, m_infoString ); 00100 r.moveBy( -1, 0 ); 00101 */ 00102 p.drawText( r, AlignCenter, m_infoString ); 00103 } 00104 00105 void PopupInfo::hide() 00106 { 00107 m_delayedHideTimer.stop(); 00108 TQWidget::hide(); 00109 TQApplication::syncX(); 00110 XEvent otherEvent; 00111 while (XCheckTypedEvent (tqt_xdisplay(), EnterNotify, &otherEvent ) ) 00112 ; 00113 m_shown = false; 00114 } 00115 00116 void PopupInfo::reconfigure() 00117 { 00118 TDEConfig * c(TDEGlobal::config()); 00119 c->setGroup("PopupInfo"); 00120 m_show = c->readBoolEntry("ShowPopup", false ); 00121 m_delayTime = c->readNumEntry("PopupHideDelay", 350 ); 00122 } 00123 00124 void PopupInfo::showInfo(TQString infoString) 00125 { 00126 if (m_show) 00127 { 00128 m_infoString = infoString; 00129 reset(); 00130 if (m_shown) 00131 { 00132 paintContents(); 00133 } 00134 else 00135 { 00136 show(); 00137 raise(); 00138 m_shown = true; 00139 } 00140 m_delayedHideTimer.start(m_delayTime, true); 00141 } 00142 } 00143 00144 } // namespace 00145 00146 #include "popupinfo.moc"
Trinity API Reference