20#include "kexisectionheader.h"
21#include "kexiviewbase.h"
22#include <kexiutils/utils.h>
29#include <kiconloader.h>
30#include <kpushbutton.h>
32class KexiSectionHeader::BoxLayout :
public TQBoxLayout
35 BoxLayout( KexiSectionHeader* parent, Direction d,
int margin = 0,
36 int spacing = -1,
const char * name = 0 );
37 virtual void addItem( TQLayoutItem * item );
38 TQGuardedPtr<KexiViewBase> view;
44class KexiSectionHeaderPrivate
47 KexiSectionHeaderPrivate()
51 TQt::Orientation orientation;
53 KexiSectionHeader::BoxLayout *lyr;
59KexiSectionHeader::KexiSectionHeader(
const TQString &caption, TQt::Orientation o, TQWidget* parent )
60 : TQWidget(parent,
"KexiSectionHeader")
61 , d( new KexiSectionHeaderPrivate() )
64 d->lyr =
new BoxLayout(
this, d->orientation==TQt::Vertical ? TQBoxLayout::TopToBottom : TQBoxLayout::LeftToRight );
65 d->lyr->setAutoAdd(
true);
66 d->lbl_b =
new TQHBox(
this);
67 d->lbl =
new TQLabel(TQString(
" ")+caption, d->lbl_b);
68 d->lbl->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Preferred);
69 d->lbl->setFocusPolicy(TQWidget::StrongFocus);
70 d->lbl->installEventFilter(
this);
71 installEventFilter(
this);
75KexiSectionHeader::~KexiSectionHeader()
80void KexiSectionHeader::addButton(
const TQString& icon,
const TQString& toolTip,
81 const TQObject * receiver,
const char * member)
83 KPushButton *btn =
new KPushButton(d->lbl_b);
85 btn->setFocusPolicy(TQWidget::NoFocus);
86 btn->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Preferred);
87 if (receiver && member) {
88 connect(btn, TQ_SIGNAL(clicked()), receiver, member);
91 if (!icon.isEmpty()) {
92 TQIconSet iset = SmallIconSet(icon);
93 btn->setIconSet( iset );
94 TQFontMetrics fm(d->lbl->font());
95 btn->setMaximumHeight( TQMAX(fm.height(), 16) );
97 if (!toolTip.isEmpty()) {
98 TQToolTip::add(btn, toolTip);
102bool KexiSectionHeader::eventFilter( TQObject *o, TQEvent *e )
104 if (o == d->lbl && e->type()==TQEvent::MouseButtonRelease) {
106 d->lyr->view->setFocus();
111 return TQWidget::eventFilter(o,e);
114void KexiSectionHeader::slotFocus(
bool in)
116 in = in || focusWidget()==
this;
117 d->lbl->setPaletteBackgroundColor(
118 in ? palette().active().color(TQColorGroup::Highlight) : palette().active().color(TQColorGroup::Background) );
119 d->lbl->setPaletteForegroundColor(
120 in ? palette().active().color(TQColorGroup::HighlightedText) : palette().active().color(TQColorGroup::Foreground) );
123TQSize KexiSectionHeader::sizeHint()
const
126 return TQWidget::sizeHint();
127 TQSize s = d->lyr->view->sizeHint();
128 return TQSize(s.width(), d->lbl->sizeHint().height() + s.height());
141KexiSectionHeader::BoxLayout::BoxLayout( KexiSectionHeader* parent, Direction d,
int margin,
int spacing,
const char * name )
142 : TQBoxLayout(parent, d, margin, spacing, name )
146void KexiSectionHeader::BoxLayout::addItem( TQLayoutItem * item )
148 TQBoxLayout::addItem( item );
149 if (item->widget()) {
150 item->widget()->installEventFilter( mainWidget() );
151 if (item->widget()->inherits(
"KexiViewBase")) {
152 view =
static_cast<KexiViewBase*
>(item->widget());
153 KexiSectionHeader *sh =
static_cast<KexiSectionHeader*
>(mainWidget());
154 connect(view,TQ_SIGNAL(focus(
bool)),sh,TQ_SLOT(slotFocus(
bool)));
155 sh->d->lbl->setBuddy(item->widget());
161#include "kexisectionheader.moc"