geometrytip.cpp

00001 /*****************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (c) 2003, Karol Szwed <kszwed@kde.org>
00006 
00007 You can Freely distribute this program under the GNU General Public
00008 License. See the file "COPYING" for the exact licensing terms.
00009 ******************************************************************/
00010 
00011 #include "geometrytip.h"
00012 
00013 namespace KWinInternal
00014 {
00015 
00016 GeometryTip::GeometryTip( const XSizeHints* xSizeHints, bool save_under ):
00017     QLabel(NULL, "kwingeometry" )
00018     {
00019     setMargin(1);
00020     setIndent(0);
00021     setLineWidth(1);
00022     setFrameStyle( QFrame::Raised | QFrame::StyledPanel );
00023     setAlignment( AlignCenter | AlignTop );
00024     sizeHints = xSizeHints;
00025     if( save_under )
00026         {
00027         XSetWindowAttributes attr;
00028         attr.save_under = True; // use saveunder if possible to avoid weird effects in transparent mode
00029         XChangeWindowAttributes( qt_xdisplay(), winId(), CWSaveUnder, &attr );
00030         }
00031     }
00032 
00033 GeometryTip::~GeometryTip()
00034     {
00035     }
00036 
00037 void GeometryTip::setGeometry( const QRect& geom )
00038     {
00039     int w = geom.width();
00040     int h = geom.height();
00041 
00042     if (sizeHints) 
00043         {
00044         if (sizeHints->flags & PResizeInc) 
00045             {
00046             w = ( w - sizeHints->base_width ) / sizeHints->width_inc;
00047             h = ( h - sizeHints->base_height ) / sizeHints->height_inc; 
00048             }
00049         }
00050 
00051     h = QMAX( h, 0 ); // in case of isShade() and PBaseSize
00052     QString pos;
00053     pos.sprintf( "%+d,%+d<br>(<b>%d&nbsp;x&nbsp;%d</b>)",
00054                      geom.x(), geom.y(), w, h );
00055     setText( pos );
00056     adjustSize();
00057     move( geom.x() + ((geom.width()  - width())  / 2),
00058           geom.y() + ((geom.height() - height()) / 2) );
00059     }
00060 
00061 } // namespace
00062 
00063 #include "geometrytip.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys