kexi
kexisectionheader.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexisectionheader.h"
00021 #include "kexiviewbase.h"
00022 #include <kexiutils/utils.h>
00023
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qhbox.h>
00027 #include <qtooltip.h>
00028
00029 #include <kiconloader.h>
00030 #include <kpushbutton.h>
00031
00032 class BoxLayout : public QBoxLayout
00033 {
00034 public:
00035 BoxLayout( KexiSectionHeader* parent, Direction d, int margin = 0,
00036 int spacing = -1, const char * name = 0 );
00037 virtual void addItem( QLayoutItem * item );
00038 QGuardedPtr<KexiViewBase> view;
00039 };
00040
00041
00042
00044 class KexiSectionHeaderPrivate
00045 {
00046 public:
00047 KexiSectionHeaderPrivate()
00048 {
00049 }
00050
00051 Qt::Orientation orientation;
00052 QLabel *lbl;
00053 BoxLayout *lyr;
00054 QHBox *lbl_b;
00055 };
00056
00057
00058
00059 KexiSectionHeader::KexiSectionHeader(const QString &caption, Orientation o, QWidget* parent, const char * name )
00060 : QWidget(parent, name)
00061 , d( new KexiSectionHeaderPrivate() )
00062 {
00063 d->orientation = o;
00064 d->lyr = new BoxLayout( this, d->orientation==Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight );
00065 d->lyr->setAutoAdd(true);
00066 d->lbl_b = new QHBox(this);
00067 d->lbl = new QLabel(QString(" ")+caption, d->lbl_b);
00068 d->lbl->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
00069 d->lbl->installEventFilter(this);
00070 installEventFilter(this);
00071 setCaption(caption);
00072 }
00073
00074 KexiSectionHeader::~KexiSectionHeader()
00075 {
00076 delete d;
00077 }
00078
00079 void KexiSectionHeader::addButton(const QString& icon, const QString& toolTip,
00080 const QObject * receiver, const char * member)
00081 {
00082 KPushButton *btn = new KPushButton(d->lbl_b);
00083 btn->setFlat(true);
00084 btn->setFocusPolicy(NoFocus);
00085 btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
00086 if (receiver && member) {
00087 connect(btn, SIGNAL(clicked()), receiver, member);
00088 }
00089
00090 if (!icon.isEmpty()) {
00091 QIconSet iset = SmallIconSet(icon);
00092 btn->setIconSet( iset );
00093 QFontMetrics fm(d->lbl->font());
00094 btn->setMaximumHeight( QMAX(fm.height(), 16) );
00095 }
00096 if (!toolTip.isEmpty()) {
00097 QToolTip::add(btn, toolTip);
00098 }
00099 }
00100
00101 bool KexiSectionHeader::eventFilter( QObject *o, QEvent *e )
00102 {
00103 if (o == d->lbl && e->type()==QEvent::MouseButtonRelease) {
00104 if (d->lyr->view)
00105 d->lyr->view->setFocus();
00106
00107
00108
00109 }
00110 return QWidget::eventFilter(o,e);
00111 }
00112
00113
00114 void KexiSectionHeader::slotFocus(bool in) {
00115 in = in || focusWidget()==this;
00116 d->lbl->setPaletteBackgroundColor(
00117 in ? palette().active().color(QColorGroup::Highlight) : palette().active().color(QColorGroup::Background) );
00118 d->lbl->setPaletteForegroundColor(
00119 in ? palette().active().color(QColorGroup::HighlightedText) : palette().active().color(QColorGroup::Foreground) );
00120 }
00121
00122 QSize KexiSectionHeader::sizeHint() const
00123 {
00124 if (!d->lyr->view)
00125 return QWidget::sizeHint();
00126 QSize s = d->lyr->view->sizeHint();
00127 return QSize(s.width(), d->lbl->sizeHint().height() + s.height());
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 BoxLayout::BoxLayout( KexiSectionHeader* parent, Direction d, int margin, int spacing, const char * name )
00141 : QBoxLayout(parent, d, margin, spacing, name )
00142 {
00143 }
00144
00145 void BoxLayout::addItem( QLayoutItem * item )
00146 {
00147 QBoxLayout::addItem( item );
00148 if (item->widget()) {
00149 item->widget()->installEventFilter( mainWidget() );
00150 if (item->widget()->inherits("KexiViewBase")) {
00151 view = static_cast<KexiViewBase*>(item->widget());
00152 KexiSectionHeader *sh = static_cast<KexiSectionHeader*>(mainWidget());
00153 connect(view,SIGNAL(focus(bool)),sh,SLOT(slotFocus(bool)));
00154 }
00155 }
00156 }
00157
00158
00159 #include "kexisectionheader.moc"
00160
|