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., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, 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 TQString& text, int _id, 00028 KStatusBar *parent, const char *name) : 00029 TQLabel( parent, name) 00030 { 00031 id = _id; 00032 00033 setText( text ); 00034 00035 // umm... Mosfet? Can you help here? 00036 00037 // Warning: TQStatusBar 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 TQFrame to call TQStyle::drawPanel(). 00041 00042 setLineWidth (0); 00043 setFrameStyle (TQFrame::NoFrame); 00044 00045 setAlignment( AlignHCenter | AlignVCenter | SingleLine ); 00046 00047 connect (this, TQT_SIGNAL(itemPressed(int)), parent, TQT_SIGNAL(pressed(int))); 00048 connect (this, TQT_SIGNAL(itemReleased(int)), parent, TQT_SIGNAL(released(int))); 00049 } 00050 00051 void KStatusBarLabel::mousePressEvent (TQMouseEvent *) 00052 { 00053 emit itemPressed (id); 00054 } 00055 00056 void KStatusBarLabel::mouseReleaseEvent (TQMouseEvent *) 00057 { 00058 emit itemReleased (id); 00059 } 00060 00061 KStatusBar::KStatusBar( TQWidget *parent, const char *name ) 00062 : TQStatusBar( parent, name ) 00063 { 00064 // make the size grip stuff configurable 00065 // ...but off by default (sven) 00066 KConfig *config = KGlobal::config(); 00067 TQString group(config->group()); 00068 config->setGroup(TQString::fromLatin1("StatusBar style")); 00069 bool grip_enabled = config->readBoolEntry(TQString::fromLatin1("SizeGripEnabled"), false); 00070 setSizeGripEnabled(grip_enabled); 00071 config->setGroup(group); 00072 } 00073 00074 KStatusBar::~KStatusBar () 00075 { 00076 } 00077 00078 void KStatusBar::insertItem( const TQString& text, int id, int stretch, bool permanent) 00079 { 00080 if (items[id]) 00081 kdDebug() << "KStatusBar::insertItem: item id " << id << " already exists." << endl; 00082 00083 KStatusBarLabel *l = new KStatusBarLabel (text, id, this); 00084 l->setFixedHeight(fontMetrics().height()+2); 00085 items.insert(id, l); 00086 addWidget (l, stretch, permanent); 00087 l->show(); 00088 } 00089 00090 void KStatusBar::removeItem (int id) 00091 { 00092 KStatusBarLabel *l = items[id]; 00093 if (l) 00094 { 00095 removeWidget (l); 00096 items.remove(id); 00097 delete l; 00098 } 00099 else 00100 kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl; 00101 } 00102 00103 bool KStatusBar::hasItem( int id ) const 00104 { 00105 KStatusBarLabel *l = items[id]; 00106 if (l) 00107 return true; 00108 else 00109 return false; 00110 } 00111 00112 void KStatusBar::changeItem( const TQString& text, int id ) 00113 { 00114 KStatusBarLabel *l = items[id]; 00115 if (l) 00116 { 00117 l->setText(text); 00118 if(l->minimumWidth () != l->maximumWidth ()) 00119 { 00120 reformat(); 00121 } 00122 } 00123 else 00124 kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl; 00125 } 00126 00127 void KStatusBar::setItemAlignment (int id, int align) 00128 { 00129 KStatusBarLabel *l = items[id]; 00130 if (l) 00131 { 00132 l->setAlignment(align); 00133 } 00134 else 00135 kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl; 00136 } 00137 00138 void KStatusBar::setItemFixed(int id, int w) 00139 { 00140 KStatusBarLabel *l = items[id]; 00141 if (l) 00142 { 00143 if (w==-1) 00144 w=fontMetrics().boundingRect(l->text()).width()+3; 00145 00146 l->setFixedWidth(w); 00147 } 00148 else 00149 kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl; 00150 } 00151 00152 #include "kstatusbar.moc" 00153 00154 //Eh!!! 00155 //Eh what ? :) 00156