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
class KStatusBarPrivate
00062 {
00063
public:
00064
00065
00066
QMap<int, bool> is_permanent_item;
00067 };
00068
00069 KStatusBar::KStatusBar(
QWidget *parent,
const char *name )
00070 :
QStatusBar( parent, name )
00071 {
00072
00073
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
00171
00172