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
class KStatusBarPrivate
00063 {
00064
public:
00065
00066
00067
QMap<int, bool> is_permanent_item;
00068 };
00069
00070 KStatusBar::KStatusBar(
QWidget *parent,
const char *name )
00071 :
QStatusBar( parent, name )
00072 {
00073
00074
00075
KConfig *config =
KGlobal::config();
00076
QString group(config->
group());
00077 config->
setGroup(QString::fromLatin1(
"StatusBar style"));
00078
bool grip_enabled = config->
readBoolEntry(QString::fromLatin1(
"SizeGripEnabled"),
false);
00079 setSizeGripEnabled(grip_enabled);
00080 config->
setGroup(group);
00081 d =
new KStatusBarPrivate;
00082 }
00083
00084 KStatusBar::~KStatusBar ()
00085 {
00086
delete d;
00087 }
00088
00089 void KStatusBar::insertItem(
const QString& text,
int id,
int stretch,
bool permanent)
00090 {
00091
if (items[
id])
00092
kdDebug() <<
"KStatusBar::insertItem: item id " <<
id <<
" already exists." <<
endl;
00093
00094
KStatusBarLabel *l =
new KStatusBarLabel (text,
id,
this);
00095 l->setFixedHeight(fontMetrics().height()+2);
00096 items.
insert(
id, l);
00097 d->is_permanent_item.insert(
id, permanent);
00098 addWidget (l, stretch, permanent);
00099 l->show();
00100 }
00101
00102 void KStatusBar::removeItem (
int id)
00103 {
00104
KStatusBarLabel *l = items[
id];
00105
if (l)
00106 {
00107 removeWidget (l);
00108 items.remove(
id);
00109 d->is_permanent_item.remove(
id);
00110
delete l;
00111 }
00112
else
00113
kdDebug() <<
"KStatusBar::removeItem: bad item id: " <<
id <<
endl;
00114 }
00115
00116 bool KStatusBar::hasItem(
int id )
const
00117
{
00118
KStatusBarLabel *l = items[
id];
00119
if (l)
00120
return true;
00121
else
00122
return false;
00123 }
00124
00125 void KStatusBar::changeItem(
const QString& text,
int id )
00126 {
00127
KStatusBarLabel *l = items[
id];
00128
if (l)
00129 {
00130
if(!d->is_permanent_item[
id])
00131 {
00132
clear();
00133 }
00134 l->
setText(text);
00135
reformat();
00136 }
00137
else
00138
kdDebug() <<
"KStatusBar::changeItem: bad item id: " <<
id <<
endl;
00139 }
00140
00141 void KStatusBar::setItemAlignment (
int id,
int align)
00142 {
00143
KStatusBarLabel *l = items[
id];
00144
if (l)
00145 {
00146 l->
setAlignment(align);
00147 }
00148
else
00149
kdDebug() <<
"KStatusBar::setItemAlignment: bad item id: " <<
id <<
endl;
00150 }
00151
00152 void KStatusBar::setItemFixed(
int id,
int w)
00153 {
00154
KStatusBarLabel *l = items[
id];
00155
if (l)
00156 {
00157
if (w==-1)
00158 w=fontMetrics().boundingRect(l->
text()).width()+3;
00159
00160 l->setFixedWidth(w);
00161 }
00162
else
00163
kdDebug() <<
"KStatusBar::setItemFixed: bad item id: " <<
id <<
endl;
00164 }
00165
00166
#include "kstatusbar.moc"
00167
00168
00169
00170