20#include "kexitableviewheader.h"
22#include <tqapplication.h>
26#include <kexiutils/utils.h>
27#include <kexiutils/styleproxy.h>
34 KexiTableViewHeaderStyle(TQStyle *parentStyle, TQWidget *widget)
37 setBackgroundColor( widget->palette().active().background() );
39 ~KexiTableViewHeaderStyle() {}
41 virtual void drawPrimitive( PrimitiveElement pe,
42 TQPainter *p,
const TQRect &r,
const TQColorGroup &cg, SFlags flags = Style_Default,
43 const TQStyleOption& option = TQStyleOption::Default )
const
45 if (pe==TQStyle::PE_HeaderSection) {
46 TQColorGroup
newCg(cg);
47 newCg.setColor(TQColorGroup::Button, m_backgroundColor);
48 newCg.setColor(TQColorGroup::Background, m_backgroundColor);
49 m_style->drawPrimitive( pe, p, r, newCg, flags, option );
52 m_style->drawPrimitive( pe, p, r, cg, flags, option );
55 void setBackgroundColor(
const TQColor& color ) { m_backgroundColor = color; }
58 TQColor m_backgroundColor;
61KexiTableViewHeader::KexiTableViewHeader(TQWidget * parent,
const char * name)
62 : TQHeader(parent, name)
63 , m_lastToolTipSection(-1)
64 , m_selectionBackgroundColor(tqApp->palette().active().highlight())
65 , m_selectedSection(-1)
66 , m_styleChangeEnabled(true)
68 styleChange( style() );
69 installEventFilter(
this);
70 connect(
this, TQ_SIGNAL(sizeChange(
int,
int,
int)),
71 this, TQ_SLOT(slotSizeChange(
int,
int,
int)));
74KexiTableViewHeader::~KexiTableViewHeader()
78void KexiTableViewHeader::styleChange( TQStyle& oldStyle )
80 TQHeader::styleChange( oldStyle );
81 if (!m_styleChangeEnabled)
83 m_styleChangeEnabled =
false;
84 setStyle(
new KexiTableViewHeaderStyle(&tqApp->style(),
this) );
85 m_styleChangeEnabled =
true;
88int KexiTableViewHeader::addLabel (
const TQString & s,
int size )
91 slotSizeChange(0,0,0);
92 return TQHeader::addLabel(s, size);
95int KexiTableViewHeader::addLabel (
const TQIconSet & iconset,
const TQString & s,
int size )
98 slotSizeChange(0,0,0);
99 return TQHeader::addLabel(iconset, s, size);
102void KexiTableViewHeader::removeLabel(
int section )
104 if (section < 0 || section >= count())
106 TQStringList::Iterator it = m_toolTips.begin();
108 m_toolTips.remove(it);
109 slotSizeChange(0,0,0);
110 TQHeader::removeLabel(section);
115 if (section < 0 || section >= (
int)m_toolTips.count())
117 m_toolTips[ section ] = toolTip;
120bool KexiTableViewHeader::eventFilter(TQObject * watched, TQEvent * e)
122 if (e->type()==TQEvent::MouseMove) {
123 const int section = sectionAt(
static_cast<TQMouseEvent*
>(e)->x() );
124 if (section != m_lastToolTipSection && section >= 0 && section < (
int)m_toolTips.count()) {
125 TQToolTip::remove(
this, m_toolTipRect);
126 TQString tip = m_toolTips[ section ];
128 TQFontMetrics fm(font());
129 int minWidth = fm.width( label( section ) ) + style().pixelMetric( TQStyle::PM_HeaderMargin );
130 TQIconSet *iset = iconSet( section );
132 minWidth += (2+iset->pixmap( TQIconSet::Small, TQIconSet::Normal ).width());
133 if (minWidth > sectionSize( section ))
134 tip = label( section );
137 m_lastToolTipSection = -1;
140 TQToolTip::add(
this, m_toolTipRect = sectionRect(section), tip);
141 m_lastToolTipSection = section;
148 return TQHeader::eventFilter(watched, e);
151void KexiTableViewHeader::slotSizeChange(
int ,
int ,
int )
153 if (m_lastToolTipSection>0)
154 TQToolTip::remove(
this, m_toolTipRect);
155 m_lastToolTipSection = -1;
158void KexiTableViewHeader::setSelectionBackgroundColor(
const TQColor &color)
160 m_selectionBackgroundColor = color;
163TQColor KexiTableViewHeader::selectionBackgroundColor()
const
165 return m_selectionBackgroundColor;
168void KexiTableViewHeader::setSelectedSection(
int section)
170 if (m_selectedSection==section || (section!=-1 && section>=count()))
172 const int oldSection = m_selectedSection;
173 m_selectedSection = section;
175 update(sRect(oldSection));
176 if (m_selectedSection!=-1)
177 update(sRect(m_selectedSection));
180int KexiTableViewHeader::selectedSection()
const
182 return m_selectedSection;
185void KexiTableViewHeader::paintSection( TQPainter * p,
int index,
const TQRect & fr )
187 const bool paintSelection = index==m_selectedSection && index != -1;
188 if (paintSelection) {
189 static_cast<KexiTableViewHeaderStyle&
>(style()).setBackgroundColor(
191 palette().active().background(), m_selectionBackgroundColor, 2, 1) );
194 TQHeader::paintSection( p, index, fr );
196 if (paintSelection) {
197 static_cast<KexiTableViewHeaderStyle&
>(style()).setBackgroundColor(
198 palette().active().background());
202#include "kexitableviewheader.moc"
a TQStyle proxy allowing to customizing the currently used style
StyleProxy(TQStyle *parentStyle)
type * findParent(TQObject *o, const char *className)
KEXIUTILS_EXPORT TQColor blendedColors(const TQColor &c1, const TQColor &c2, int factor1=1, int factor2=1)