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     m_shown = false;
00042     reset();
00043     reconfigure();
00044     connect(&m_delayedHideTimer, SIGNAL(timeout()), this, SLOT(hide()));
00045 
00046     QFont f = font();
00047     f.setBold( TRUE );
00048     f.setPointSize( 14 );
00049     setFont( f );
00050 
00051     }
00052 
00053 PopupInfo::~PopupInfo()
00054     {
00055     }
00056 
00057 
00061 void PopupInfo::reset()
00062     {
00063     QRect r = KGlobalSettings::desktopGeometry(QCursor::pos());
00064 
00065     int w = fontMetrics().width( m_infoString ) + 30;
00066 
00067     setGeometry( 
00068        (r.width()-w)/2 + r.x(), r.height()/2-fontMetrics().height()-10 + r.y(),
00069                  w,                       fontMetrics().height() + 20 );
00070     }
00071 
00072 
00076 void PopupInfo::paintEvent( QPaintEvent* )
00077     {
00078     QPainter p( this );
00079     style().drawPrimitive( QStyle::PE_Panel, &p, QRect( 0, 0, width(), height() ),
00080           colorGroup(), QStyle::Style_Default );
00081     paintContents();
00082     }
00083 
00084 
00089 void PopupInfo::paintContents()
00090     {
00091     QPainter p( this );
00092     QRect r( 6, 6, width()-12, height()-12 );
00093 
00094     p.fillRect( r, colorGroup().brush( QColorGroup::Background ) );
00095 
00096     /*
00097     p.setPen(Qt::white);
00098     p.drawText( r, AlignCenter, m_infoString );
00099     p.setPen(Qt::black);
00100     r.moveBy( -1, -1 );
00101     p.drawText( r, AlignCenter, m_infoString );
00102     r.moveBy( -1, 0 );
00103     */
00104     p.drawText( r, AlignCenter, m_infoString );
00105     }
00106 
00107 void PopupInfo::hide()
00108     {
00109     m_delayedHideTimer.stop();
00110     QWidget::hide();
00111     QApplication::syncX();
00112     XEvent otherEvent;
00113     while (XCheckTypedEvent (qt_xdisplay(), EnterNotify, &otherEvent ) )
00114         ;
00115     m_shown = false;
00116     }
00117 
00118 void PopupInfo::reconfigure() 
00119     {
00120     KConfig * c(KGlobal::config());
00121     c->setGroup("PopupInfo");
00122     m_show = c->readBoolEntry("ShowPopup", false );
00123     m_delayTime = c->readNumEntry("PopupHideDelay", 350 );
00124     }
00125 
00126 void PopupInfo::showInfo(QString infoString)
00127     {
00128     if (m_show) 
00129         {
00130         m_infoString = infoString;
00131         reset();
00132         if (m_shown) 
00133             {
00134             paintContents();
00135             }
00136         else 
00137             {
00138             show();
00139             raise();
00140             m_shown = true;
00141             }
00142         m_delayedHideTimer.start(m_delayTime, true);
00143         }
00144     }
00145 
00146 } // namespace
00147 
00148 #include "popupinfo.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys