kdeui Library API Documentation

kstatusbar.cpp

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
00003               (C) 1997,1998, 2000 Sven Radej (radej@kde.org)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <kdebug.h>
00022 #include <kstatusbar.h>
00023 #include <kconfig.h>
00024 #include <kglobal.h>
00025 
00026 // $Id: kstatusbar.cpp,v 1.43 2002/06/21 19:03:43 waba Exp $
00027 
00028 KStatusBarLabel::KStatusBarLabel( const QString& text, int _id,
00029                                  KStatusBar *parent, const char *name) :
00030   QLabel( parent, name)
00031 {
00032   id = _id;
00033 
00034   setText( text );
00035 
00036   // umm... Mosfet? Can you help here?
00037 
00038   // Warning: QStatusBar draws shaded rectangle around every item - which
00039   // IMHO is stupid.
00040   // So NoFrame|Plain is the best you get. the problem is that only in case of
00041   // StyledPanel|Something you get QFrame to call QStyle::drawPanel().
00042 
00043   setLineWidth  (0);
00044   setFrameStyle (QFrame::NoFrame);
00045 
00046   setAlignment( AlignHCenter | AlignVCenter );
00047 
00048   connect (this, SIGNAL(itemPressed(int)), parent, SIGNAL(pressed(int)));
00049   connect (this, SIGNAL(itemReleased(int)), parent, SIGNAL(released(int)));
00050 }
00051 
00052 void KStatusBarLabel::mousePressEvent (QMouseEvent *)
00053 {
00054   emit itemPressed (id);
00055 }
00056 
00057 void KStatusBarLabel::mouseReleaseEvent (QMouseEvent *)
00058 {
00059   emit itemReleased (id);
00060 }
00061 
00062 
00063 KStatusBar::KStatusBar( QWidget *parent, const char *name )
00064   : QStatusBar( parent, name )
00065 {
00066   // make the size grip stuff configurable
00067   // ...but off by default (sven)
00068   KConfig *config = KGlobal::config();
00069   QString group(config->group());
00070   config->setGroup(QString::fromLatin1("StatusBar style"));
00071   bool grip_enabled = config->readBoolEntry(QString::fromLatin1("SizeGripEnabled"), false);
00072   setSizeGripEnabled(grip_enabled);
00073   config->setGroup(group);
00074 }
00075 
00076 KStatusBar::~KStatusBar ()
00077 {
00078 }
00079 
00080 void KStatusBar::insertItem( const QString& text, int id, int stretch, bool permanent)
00081 {
00082   KStatusBarLabel *l = new KStatusBarLabel (text, id, this);
00083   l->setFixedHeight(fontMetrics().height()+2);
00084   items.insert(id, l);
00085   addWidget (l, stretch, permanent);
00086   l->show();
00087 }
00088 
00089 void KStatusBar::removeItem (int id)
00090 {
00091   KStatusBarLabel *l = items[id];
00092   if (l)
00093   {
00094     removeWidget (l);
00095     items.remove(id);
00096     delete l;
00097   }
00098   else
00099     kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl;
00100 }
00101 
00102 void KStatusBar::changeItem( const QString& text, int id )
00103 {
00104   KStatusBarLabel *l = items[id];
00105   if (l)
00106   {
00107     clear();
00108     l->setText(text);
00109     reformat();
00110   }
00111   else
00112     kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl;
00113 }
00114 
00115 void KStatusBar::setItemAlignment (int id, int align)
00116 {
00117   KStatusBarLabel *l = items[id];
00118   if (l)
00119   {
00120     l->setAlignment(align);
00121   }
00122   else
00123     kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl;
00124 }
00125 
00126 void KStatusBar::setItemFixed(int id, int w)
00127 {
00128   KStatusBarLabel *l = items[id];
00129   if (l)
00130   {
00131     if (w==-1)
00132       w=fontMetrics().boundingRect(l->text()).width()+3;
00133 
00134     l->setFixedSize(w, l->sizeHint().height());
00135   }
00136   else
00137     kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl;
00138 }
00139 
00140 #include "kstatusbar.moc"
00141 
00142 //Eh!!!
00143 //Eh what ? :)
00144 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:01 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001