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 00027 KStatusBarLabel::KStatusBarLabel( const QString& text, int _id, 00028 KStatusBar *parent, const char *name) : 00029 QLabel( parent, name) 00030 { 00031 id = _id; 00032 00033 setText( text ); 00034 00035 // umm... Mosfet? Can you help here? 00036 00037 // Warning: QStatusBar draws shaded rectangle around every item - which 00038 // IMHO is stupid. 00039 // So NoFrame|Plain is the best you get. the problem is that only in case of 00040 // StyledPanel|Something you get QFrame to call QStyle::drawPanel(). 00041 00042 setLineWidth (0); 00043 setFrameStyle (QFrame::NoFrame); 00044 00045 setAlignment( AlignHCenter | AlignVCenter | SingleLine ); 00046 00047 connect (this, SIGNAL(itemPressed(int)), parent, SIGNAL(pressed(int))); 00048 connect (this, SIGNAL(itemReleased(int)), parent, SIGNAL(released(int))); 00049 } 00050 00051 void KStatusBarLabel::mousePressEvent (QMouseEvent *) 00052 { 00053 emit itemPressed (id); 00054 } 00055 00056 void KStatusBarLabel::mouseReleaseEvent (QMouseEvent *) 00057 { 00058 emit itemReleased (id); 00059 } 00060 00061 class KStatusBarPrivate 00062 { 00063 public: 00064 00065 // KDE 4.0: Move into KStatusBarLabel 00066 QMap<int, bool> is_permanent_item; 00067 }; 00068 00069 KStatusBar::KStatusBar( QWidget *parent, const char *name ) 00070 : QStatusBar( parent, name ) 00071 { 00072 // make the size grip stuff configurable 00073 // ...but off by default (sven) 00074 KConfig *config = KGlobal::config(); 00075 QString group(config->group()); 00076 config->setGroup(QString::fromLatin1("StatusBar style")); 00077 bool grip_enabled = config->readBoolEntry(QString::fromLatin1("SizeGripEnabled"), false); 00078 setSizeGripEnabled(grip_enabled); 00079 config->setGroup(group); 00080 d = new KStatusBarPrivate; 00081 } 00082 00083 KStatusBar::~KStatusBar () 00084 { 00085 delete d; 00086 } 00087 00088 void KStatusBar::insertItem( const QString& text, int id, int stretch, bool permanent) 00089 { 00090 if (items[id]) 00091 kdDebug() << "KStatusBar::insertItem: item id " << id << " already exists." << endl; 00092 00093 KStatusBarLabel *l = new KStatusBarLabel (text, id, this); 00094 l->setFixedHeight(fontMetrics().height()+2); 00095 items.insert(id, l); 00096 d->is_permanent_item.insert(id, permanent); 00097 addWidget (l, stretch, permanent); 00098 l->show(); 00099 } 00100 00101 void KStatusBar::removeItem (int id) 00102 { 00103 KStatusBarLabel *l = items[id]; 00104 if (l) 00105 { 00106 removeWidget (l); 00107 items.remove(id); 00108 d->is_permanent_item.remove(id); 00109 delete l; 00110 } 00111 else 00112 kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl; 00113 } 00114 00115 bool KStatusBar::hasItem( int id ) const 00116 { 00117 KStatusBarLabel *l = items[id]; 00118 if (l) 00119 return true; 00120 else 00121 return false; 00122 } 00123 00124 void KStatusBar::changeItem( const QString& text, int id ) 00125 { 00126 KStatusBarLabel *l = items[id]; 00127 if (l) 00128 { 00129 if(!d->is_permanent_item[id]) 00130 { 00131 clear(); 00132 } 00133 l->setText(text); 00134 if(l->minimumWidth () != l->maximumWidth ()) 00135 { 00136 reformat(); 00137 } 00138 } 00139 else 00140 kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl; 00141 } 00142 00143 void KStatusBar::setItemAlignment (int id, int align) 00144 { 00145 KStatusBarLabel *l = items[id]; 00146 if (l) 00147 { 00148 l->setAlignment(align); 00149 } 00150 else 00151 kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl; 00152 } 00153 00154 void KStatusBar::setItemFixed(int id, int w) 00155 { 00156 KStatusBarLabel *l = items[id]; 00157 if (l) 00158 { 00159 if (w==-1) 00160 w=fontMetrics().boundingRect(l->text()).width()+3; 00161 00162 l->setFixedWidth(w); 00163 } 00164 else 00165 kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl; 00166 } 00167 00168 #include "kstatusbar.moc" 00169 00170 //Eh!!! 00171 //Eh what ? :) 00172
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:27:32 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003