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 KexiSectionHeader::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 KexiSectionHeader::BoxLayout *lyr;
00054 QHBox *lbl_b;
00055 };
00056
00057
00058
00059 KexiSectionHeader::KexiSectionHeader(const QString &caption, Orientation o, QWidget* parent )
00060 : QWidget(parent, "KexiSectionHeader")
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->setFocusPolicy(StrongFocus);
00070 d->lbl->installEventFilter(this);
00071 installEventFilter(this);
00072 setCaption(caption);
00073 }
00074
00075 KexiSectionHeader::~KexiSectionHeader()
00076 {
00077 delete d;
00078 }
00079
00080 void KexiSectionHeader::addButton(const QString& icon, const QString& toolTip,
00081 const QObject * receiver, const char * member)
00082 {
00083 KPushButton *btn = new KPushButton(d->lbl_b);
00084 btn->setFlat(true);
00085 btn->setFocusPolicy(NoFocus);
00086 btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
00087 if (receiver && member) {
00088 connect(btn, SIGNAL(clicked()), receiver, member);
00089 }
00090
00091 if (!icon.isEmpty()) {
00092 QIconSet iset = SmallIconSet(icon);
00093 btn->setIconSet( iset );
00094 QFontMetrics fm(d->lbl->font());
00095 btn->setMaximumHeight( QMAX(fm.height(), 16) );
00096 }
00097 if (!toolTip.isEmpty()) {
00098 QToolTip::add(btn, toolTip);
00099 }
00100 }
00101
00102 bool KexiSectionHeader::eventFilter( QObject *o, QEvent *e )
00103 {
00104 if (o == d->lbl && e->type()==QEvent::MouseButtonRelease) {
00105 if (d->lyr->view)
00106 d->lyr->view->setFocus();
00107
00108
00109
00110 }
00111 return QWidget::eventFilter(o,e);
00112 }
00113
00114 void KexiSectionHeader::slotFocus(bool in)
00115 {
00116 in = in || focusWidget()==this;
00117 d->lbl->setPaletteBackgroundColor(
00118 in ? palette().active().color(QColorGroup::Highlight) : palette().active().color(QColorGroup::Background) );
00119 d->lbl->setPaletteForegroundColor(
00120 in ? palette().active().color(QColorGroup::HighlightedText) : palette().active().color(QColorGroup::Foreground) );
00121 }
00122
00123 QSize KexiSectionHeader::sizeHint() const
00124 {
00125 if (!d->lyr->view)
00126 return QWidget::sizeHint();
00127 QSize s = d->lyr->view->sizeHint();
00128 return QSize(s.width(), d->lbl->sizeHint().height() + s.height());
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 KexiSectionHeader::BoxLayout::BoxLayout( KexiSectionHeader* parent, Direction d, int margin, int spacing, const char * name )
00142 : QBoxLayout(parent, d, margin, spacing, name )
00143 {
00144 }
00145
00146 void KexiSectionHeader::BoxLayout::addItem( QLayoutItem * item )
00147 {
00148 QBoxLayout::addItem( item );
00149 if (item->widget()) {
00150 item->widget()->installEventFilter( mainWidget() );
00151 if (item->widget()->inherits("KexiViewBase")) {
00152 view = static_cast<KexiViewBase*>(item->widget());
00153 KexiSectionHeader *sh = static_cast<KexiSectionHeader*>(mainWidget());
00154 connect(view,SIGNAL(focus(bool)),sh,SLOT(slotFocus(bool)));
00155 sh->d->lbl->setBuddy(item->widget());
00156 }
00157 }
00158 }
00159
00160
00161 #include "kexisectionheader.moc"
00162
|