subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kstatusbar.cpp
blobeb6f725df7ade25d0e66d828a50817cc576e3b13
1 /* This file is part of the KDE libraries
2 Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
3 (C) 1997,1998, 2000 Sven Radej (radej@kde.org)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include <kdebug.h>
22 #include <kstatusbar.h>
23 #include <kconfig.h>
24 #include <kglobal.h>
27 KStatusBarLabel::KStatusBarLabel( const QString& text, int _id,
28 KStatusBar *parent, const char *name) :
29 QLabel( parent, name)
31 id = _id;
33 setText( text );
35 // umm... Mosfet? Can you help here?
37 // Warning: QStatusBar draws shaded rectangle around every item - which
38 // IMHO is stupid.
39 // So NoFrame|Plain is the best you get. the problem is that only in case of
40 // StyledPanel|Something you get QFrame to call QStyle::drawPanel().
42 setLineWidth (0);
43 setFrameStyle (QFrame::NoFrame);
45 setAlignment( AlignHCenter | AlignVCenter | SingleLine );
47 connect (this, SIGNAL(itemPressed(int)), parent, SIGNAL(pressed(int)));
48 connect (this, SIGNAL(itemReleased(int)), parent, SIGNAL(released(int)));
51 void KStatusBarLabel::mousePressEvent (QMouseEvent *)
53 emit itemPressed (id);
56 void KStatusBarLabel::mouseReleaseEvent (QMouseEvent *)
58 emit itemReleased (id);
61 KStatusBar::KStatusBar( QWidget *parent, const char *name )
62 : QStatusBar( parent, name )
64 // make the size grip stuff configurable
65 // ...but off by default (sven)
66 KConfig *config = KGlobal::config();
67 QString group(config->group());
68 config->setGroup(QString::fromLatin1("StatusBar style"));
69 bool grip_enabled = config->readBoolEntry(QString::fromLatin1("SizeGripEnabled"), false);
70 setSizeGripEnabled(grip_enabled);
71 config->setGroup(group);
74 KStatusBar::~KStatusBar ()
78 void KStatusBar::insertItem( const QString& text, int id, int stretch, bool permanent)
80 if (items[id])
81 kdDebug() << "KStatusBar::insertItem: item id " << id << " already exists." << endl;
83 KStatusBarLabel *l = new KStatusBarLabel (text, id, this);
84 l->setFixedHeight(fontMetrics().height()+2);
85 items.insert(id, l);
86 addWidget (l, stretch, permanent);
87 l->show();
90 void KStatusBar::removeItem (int id)
92 KStatusBarLabel *l = items[id];
93 if (l)
95 removeWidget (l);
96 items.remove(id);
97 delete l;
99 else
100 kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl;
103 bool KStatusBar::hasItem( int id ) const
105 KStatusBarLabel *l = items[id];
106 if (l)
107 return true;
108 else
109 return false;
112 void KStatusBar::changeItem( const QString& text, int id )
114 KStatusBarLabel *l = items[id];
115 if (l)
117 l->setText(text);
118 if(l->minimumWidth () != l->maximumWidth ())
120 reformat();
123 else
124 kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl;
127 void KStatusBar::setItemAlignment (int id, int align)
129 KStatusBarLabel *l = items[id];
130 if (l)
132 l->setAlignment(align);
134 else
135 kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl;
138 void KStatusBar::setItemFixed(int id, int w)
140 KStatusBarLabel *l = items[id];
141 if (l)
143 if (w==-1)
144 w=fontMetrics().boundingRect(l->text()).width()+3;
146 l->setFixedWidth(w);
148 else
149 kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl;
152 #include "kstatusbar.moc"
154 //Eh!!!
155 //Eh what ? :)