kstatusbar.cpp
/* This file is part of the KDE libraries
Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
(C) 1997,1998, 2000 Sven Radej (radej@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <kdebug.h>
#include <kstatusbar.h>
#include <kconfig.h>
#include <kglobal.h>
KStatusBarLabel::KStatusBarLabel( const QString& text, int _id,
KStatusBar *parent, const char *name) :
QLabel( parent, name)
{
id = _id;
setText( text );
// umm... Mosfet? Can you help here?
// Warning: QStatusBar draws shaded rectangle around every item - which
// IMHO is stupid.
// So NoFrame|Plain is the best you get. the problem is that only in case of
// StyledPanel|Something you get QFrame to call QStyle::drawPanel().
setLineWidth (0);
setFrameStyle (QFrame::NoFrame);
setAlignment( AlignHCenter | AlignVCenter | SingleLine );
connect (this, SIGNAL(itemPressed(int)), parent, SIGNAL(pressed(int)));
connect (this, SIGNAL(itemReleased(int)), parent, SIGNAL(released(int)));
}
void KStatusBarLabel::mousePressEvent (QMouseEvent *)
{
emit itemPressed (id);
}
void KStatusBarLabel::mouseReleaseEvent (QMouseEvent *)
{
emit itemReleased (id);
}
KStatusBar::KStatusBar( QWidget *parent, const char *name )
: QStatusBar( parent, name )
{
// make the size grip stuff configurable
// ...but off by default (sven)
KConfig *config = KGlobal::config();
QString group(config->group());
config->setGroup(QString::fromLatin1("StatusBar style"));
bool grip_enabled = config->readBoolEntry(QString::fromLatin1("SizeGripEnabled"), false);
setSizeGripEnabled(grip_enabled);
config->setGroup(group);
}
KStatusBar::~KStatusBar ()
{
}
void KStatusBar::insertItem( const QString& text, int id, int stretch, bool permanent)
{
if (items[id])
kdDebug() << "KStatusBar::insertItem: item id " << id << " already exists." << endl;
KStatusBarLabel *l = new KStatusBarLabel (text, id, this);
l->setFixedHeight(fontMetrics().height()+2);
items.insert(id, l);
addWidget (l, stretch, permanent);
l->show();
}
void KStatusBar::removeItem (int id)
{
KStatusBarLabel *l = items[id];
if (l)
{
removeWidget (l);
items.remove(id);
delete l;
}
else
kdDebug() << "KStatusBar::removeItem: bad item id: " << id << endl;
}
bool KStatusBar::hasItem( int id ) const
{
KStatusBarLabel *l = items[id];
if (l)
return true;
else
return false;
}
void KStatusBar::changeItem( const QString& text, int id )
{
KStatusBarLabel *l = items[id];
if (l)
{
l->setText(text);
if(l->minimumWidth () != l->maximumWidth ())
{
reformat();
}
}
else
kdDebug() << "KStatusBar::changeItem: bad item id: " << id << endl;
}
void KStatusBar::setItemAlignment (int id, int align)
{
KStatusBarLabel *l = items[id];
if (l)
{
l->setAlignment(align);
}
else
kdDebug() << "KStatusBar::setItemAlignment: bad item id: " << id << endl;
}
void KStatusBar::setItemFixed(int id, int w)
{
KStatusBarLabel *l = items[id];
if (l)
{
if (w==-1)
w=fontMetrics().boundingRect(l->text()).width()+3;
l->setFixedWidth(w);
}
else
kdDebug() << "KStatusBar::setItemFixed: bad item id: " << id << endl;
}
#include "kstatusbar.moc"
//Eh!!!
//Eh what ? :)
KStatusBar::setItemFixed
void setItemFixed(int id, int width=-1)
Sets item id to have fixed width.
Definition: kstatusbar.cpp:138
KStatusBarLabel
Internal label class for use in KStatusBar.
Definition: kstatusbar.h:35
KStatusBar::removeItem
void removeItem(int id)
Removes an item.
Definition: kstatusbar.cpp:90
KStatusBar::changeItem
void changeItem(const QString &text, int id)
Changes the text in a status bar field.
Definition: kstatusbar.cpp:112
KStatusBar::insertItem
void insertItem(const QString &text, int id, int stretch=0, bool permanent=false)
Inserts a text label into the status bar.
Definition: kstatusbar.cpp:78
kdDebug
kdbgstream kdDebug(int area=0)
KStatusBar::~KStatusBar
~KStatusBar()
Destructor.
Definition: kstatusbar.cpp:74
KStatusBar
KDE statusbar widget
Definition: kstatusbar.h:87
KStatusBar::KStatusBar
KStatusBar(QWidget *parent=0L, const char *name=0L)
Constructs a status bar.
Definition: kstatusbar.cpp:61
KConfig
KConfig::readBoolEntry
bool readBoolEntry(const QString &pKey, bool bDefault=false) const
KStatusBar::setItemAlignment
void setItemAlignment(int id, int align)
Sets the alignment of item id.
Definition: kstatusbar.cpp:127
endl
kndbgstream & endl(kndbgstream &s)
KSqueezedTextLabel::setAlignment
virtual void setAlignment(int)
Overridden for internal reasons; the API remains unaffected.
Definition: ksqueezedtextlabel.cpp:76
KConfig::setGroup
void setGroup(const QString &group)
KGlobal::config
static KConfig * config()
KConfig::group
QString group() const
KStatusBar::hasItem
bool hasItem(int id) const
Definition: kstatusbar.cpp:103

KDE Home | KDE Accessibility Home | Description of Access Keys