• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWin

popupinfo.cpp

Go to the documentation of this file.
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 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; either version 2 of the License, or
00012 (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************/
00022 
00023 //#define QT_CLEAN_NAMESPACE
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 // specify externals before namespace
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     p.setPen(Qt::white);
00118     p.drawText( r, AlignCenter, m_infoString );
00119     p.setPen(Qt::black);
00120     r.translate( -1, -1 );
00121     p.drawText( r, AlignCenter, m_infoString );
00122     r.translate( -1, 0 );
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 } // namespace
00167 
00168 #include "popupinfo.moc"

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal