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.46 2003/12/16 00:44:52 kniederk 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 class KStatusBarPrivate
00063 {
00064   public:
00065 
00066     // KDE 4.0: Move into KStatusBarLabel
00067     QMap<int, bool> is_permanent_item;
00068 };
00069 
00070 KStatusBar::KStatusBar( QWidget *parent, const char *name )
00071   : QStatusBar( parent, name )
00072 {
00073   // make the size grip stuff configurable
00074   // ...but off by default (sven)
00075   KConfig *config = KGlobal::config();
00076   QString group(config->group());
00077   config->setGroup(QString::fromLatin1("StatusBar style"));
00078   bool grip_enabled = config->readBoolEntry(QString::fromLatin1("SizeGripEnabled"), false);
00079   setSizeGripEnabled(grip_enabled);
00080   config->setGroup(group);
00081   d = new KStatusBarPrivate;
00082 }
00083 
00084 KStatusBar::~KStatusBar ()
00085 {
00086   delete d;
00087 }
00088 
00089 void KStatusBar::insertItem( const QString& text, int id, int stretch, bool permanent)
00090 {
00091   if (items[id])
00092     kdDebug() << "KStatusBar::insertItem: item id " << id << " already exists." << endl;
00093 
00094   KStatusBarLabel *l = new KStatusBarLabel (text, id, this);
00095   l->setFixedHeight(fontMetrics().height()+2);
00096   items.insert(id, l);
00097   d->is_permanent_item.insert(id, permanent);
00098   addWidget (l, stretch, permanent);
00099   l->show();
00100 }
00101 
00102 void KStatusBar::removeItem (int id)
00103 {
00104   KStatusBarLabel *l = items[id];
00105   if (l)
00106   {
00107     removeWidget (l);
00108     items.remove(id);
00109     d->is_permanent_item.remove(id);
00110     delete l;
00111   }
00112   else
00113     kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl;
00114 }
00115 
00116 bool KStatusBar::hasItem( int id ) const
00117 {
00118   KStatusBarLabel *l = items[id];
00119   if (l)
00120     return true;
00121   else
00122     return false;
00123 }
00124 
00125 void KStatusBar::changeItem( const QString& text, int id )
00126 {
00127   KStatusBarLabel *l = items[id];
00128   if (l)
00129   {
00130     if(!d->is_permanent_item[id])
00131     {
00132       clear();
00133     }
00134     l->setText(text);
00135     reformat();
00136   }
00137   else
00138     kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl;
00139 }
00140 
00141 void KStatusBar::setItemAlignment (int id, int align)
00142 {
00143   KStatusBarLabel *l = items[id];
00144   if (l)
00145   {
00146     l->setAlignment(align);
00147   }
00148   else
00149     kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl;
00150 }
00151 
00152 void KStatusBar::setItemFixed(int id, int w)
00153 {
00154   KStatusBarLabel *l = items[id];
00155   if (l)
00156   {
00157     if (w==-1)
00158       w=fontMetrics().boundingRect(l->text()).width()+3;
00159 
00160     l->setFixedWidth(w);
00161   }
00162   else
00163     kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl;
00164 }
00165 
00166 #include "kstatusbar.moc"
00167 
00168 //Eh!!!
00169 //Eh what ? :)
00170 
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jan 21 09:57:29 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003