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 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
00036
00037
00038
00039
00040
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 KStatusBar::KStatusBar(
QWidget *parent,
const char *name )
00062 :
QStatusBar( parent, name )
00063 {
00064
00065
00066
KConfig *config =
KGlobal::config();
00067
QString group(config->
group());
00068 config->
setGroup(QString::fromLatin1(
"StatusBar style"));
00069
bool grip_enabled = config->
readBoolEntry(QString::fromLatin1(
"SizeGripEnabled"),
false);
00070 setSizeGripEnabled(grip_enabled);
00071 config->
setGroup(group);
00072 }
00073
00074 KStatusBar::~KStatusBar ()
00075 {
00076 }
00077
00078 void KStatusBar::insertItem(
const QString& 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 QString& 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
00155
00156