You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
koffice/kexi/widget/kexisectionheader.cpp

163 lines
4.8 KiB

/* This file is part of the KDE project
Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
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 "kexisectionheader.h"
#include "kexiviewbase.h"
#include <kexiutils/utils.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqhbox.h>
#include <tqtooltip.h>
#include <kiconloader.h>
#include <kpushbutton.h>
class KexiSectionHeader::BoxLayout : public TQBoxLayout
{
public:
BoxLayout( KexiSectionHeader* parent, Direction d, int margin = 0,
int spacing = -1, const char * name = 0 );
virtual void addItem( TQLayoutItem * item );
TQGuardedPtr<KexiViewBase> view;
};
//==========================
//! @internal
class KexiSectionHeaderPrivate
{
public:
KexiSectionHeaderPrivate()
{
}
Qt::Orientation orientation;
TQLabel *lbl;
KexiSectionHeader::BoxLayout *lyr;
TQHBox *lbl_b;
};
//==========================
KexiSectionHeader::KexiSectionHeader(const TQString &caption, Qt::Orientation o, TQWidget* parent )
: TQWidget(parent, "KexiSectionHeader")
, d( new KexiSectionHeaderPrivate() )
{
d->orientation = o;
d->lyr = new BoxLayout( this, d->orientation==Qt::Vertical ? TQBoxLayout::TopToBottom : TQBoxLayout::LeftToRight );
d->lyr->setAutoAdd(true);
d->lbl_b = new TQHBox(this);
d->lbl = new TQLabel(TQString(" ")+caption, d->lbl_b);
d->lbl->tqsetSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Preferred);
d->lbl->setFocusPolicy(TQ_StrongFocus);
d->lbl->installEventFilter(this);
installEventFilter(this);
setCaption(caption);
}
KexiSectionHeader::~KexiSectionHeader()
{
delete d;
}
void KexiSectionHeader::addButton(const TQString& icon, const TQString& toolTip,
const TQObject * receiver, const char * member)
{
KPushButton *btn = new KPushButton(d->lbl_b);
btn->setFlat(true);
btn->setFocusPolicy(TQ_NoFocus);
btn->tqsetSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred);
if (receiver && member) {
connect(btn, TQT_SIGNAL(clicked()), receiver, member);
}
if (!icon.isEmpty()) {
TQIconSet iset = SmallIconSet(icon);
btn->setIconSet( iset );
TQFontMetrics fm(d->lbl->font());
btn->setMaximumHeight( TQMAX(fm.height(), 16) );
}
if (!toolTip.isEmpty()) {
TQToolTip::add(btn, toolTip);
}
}
bool KexiSectionHeader::eventFilter( TQObject *o, TQEvent *e )
{
if (TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(d->lbl) && e->type()==TQEvent::MouseButtonRelease) {//|| e->type()==TQEvent::FocusOut) {// && o->inherits(TQWIDGET_OBJECT_NAME_STRING)) {
if (d->lyr->view)
d->lyr->view->setFocus();
// if (KexiUtils::hasParent( this, static_cast<TQWidget*>(o))) {
// d->lbl->setPaletteBackgroundColor( e->type()==TQEvent::FocusIn ? red : blue);
// }
}
return TQWidget::eventFilter(o,e);
}
void KexiSectionHeader::slotFocus(bool in)
{
in = in || tqfocusWidget()==this;
d->lbl->setPaletteBackgroundColor(
in ? tqpalette().active().color(TQColorGroup::Highlight) : tqpalette().active().color(TQColorGroup::Background) );
d->lbl->setPaletteForegroundColor(
in ? tqpalette().active().color(TQColorGroup::HighlightedText) : tqpalette().active().color(TQColorGroup::Foreground) );
}
TQSize KexiSectionHeader::tqsizeHint() const
{
if (!d->lyr->view)
return TQWidget::tqsizeHint();
TQSize s = d->lyr->view->tqsizeHint();
return TQSize(s.width(), d->lbl->tqsizeHint().height() + s.height());
}
/*void KexiSectionHeader::setFocus()
{
if (d->lyr->view)
d->lyr->view->setFocus();
else
TQWidget::setFocus();
}*/
//======================
KexiSectionHeader::BoxLayout::BoxLayout( KexiSectionHeader* parent, Direction d, int margin, int spacing, const char * name )
: TQBoxLayout(parent, d, margin, spacing, name )
{
}
void KexiSectionHeader::BoxLayout::addItem( TQLayoutItem * item )
{
TQBoxLayout::addItem( item );
if (item->widget()) {
item->widget()->installEventFilter( mainWidget() );
if (item->widget()->inherits("KexiViewBase")) {
view = static_cast<KexiViewBase*>(item->widget());
KexiSectionHeader *sh = static_cast<KexiSectionHeader*>(mainWidget());
connect(view,TQT_SIGNAL(focus(bool)),sh,TQT_SLOT(slotFocus(bool)));
sh->d->lbl->setBuddy(item->widget());
}
}
}
#include "kexisectionheader.moc"