kstatusbar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <kdebug.h>
00022 #include <kstatusbar.h>
00023 #include <kconfig.h>
00024 #include <kglobal.h>
00025
00026
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
00037
00038
00039
00040
00041
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
00067
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->setFixedWidth(w);
00135 }
00136 else
00137 kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl;
00138 }
00139
00140 #include "kstatusbar.moc"
00141
00142
00143
00144
This file is part of the documentation for kdelibs Version 3.1.4.