summaryrefslogtreecommitdiffstats
path: root/src/widgets/qtabbar.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-16 15:40:54 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-16 15:40:54 -0500
commit0e044c1a92745f8508f5813efc9709a280583d11 (patch)
tree67963c1b752b6fa680f9123b73fca2c703b7c61b /src/widgets/qtabbar.cpp
parentff2caed1b8e1bea513172d48d07b13f53b73a9de (diff)
downloadtqt3-0e044c1a92745f8508f5813efc9709a280583d11.tar.gz
tqt3-0e044c1a92745f8508f5813efc9709a280583d11.zip
Automated update from Qt3
Diffstat (limited to 'src/widgets/qtabbar.cpp')
-rw-r--r--src/widgets/qtabbar.cpp237
1 files changed, 143 insertions, 94 deletions
diff --git a/src/widgets/qtabbar.cpp b/src/widgets/qtabbar.cpp
index caa8e7d1..db08012c 100644
--- a/src/widgets/qtabbar.cpp
+++ b/src/widgets/qtabbar.cpp
@@ -335,7 +335,7 @@ private:
*/
TQTabBar::TQTabBar( TQWidget * parent, const char *name )
- : TQWidget( parent, name, WNoAutoErase | WNoMousePropagation ), l(NULL)
+ : TQWidget( parent, name, WNoAutoErase | WNoMousePropagation ), l(NULL), hoverTab( 0 )
{
d = new TQTabPrivate;
d->pressed = 0;
@@ -581,45 +581,49 @@ TQSize TQTabBar::minimumSizeHint() const
void TQTabBar::paint( TQPainter * p, TQTab * t, bool selected ) const
{
- TQStyle::SFlags flags = TQStyle::Style_Default;
-
- if (isEnabled() && t->isEnabled())
- flags |= TQStyle::Style_Enabled;
- if (topLevelWidget() == tqApp->activeWindow())
- flags |= TQStyle::Style_Active;
- if ( selected )
- flags |= TQStyle::Style_Selected;
- else if(t == d->pressed)
- flags |= TQStyle::Style_Sunken;
- //selection flags
- if(t->rect().contains(mapFromGlobal(TQCursor::pos())))
- flags |= TQStyle::Style_MouseOver;
- style().drawControl( TQStyle::CE_TabBarTab, p, this, t->rect(),
- colorGroup(), flags, TQStyleOption(t) );
-
- TQRect r( t->r );
- p->setFont( font() );
-
- int iw = 0;
- int ih = 0;
- if ( t->iconset != 0 ) {
- iw = t->iconset->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4;
- ih = t->iconset->pixmap( TQIconSet::Small, TQIconSet::Normal ).height();
- }
- TQFontMetrics fm = p->fontMetrics();
- int fw = fm.width( t->label );
- fw -= t->label.contains('&') * fm.width('&');
- fw += t->label.contains("&&") * fm.width('&');
- int w = iw + fw + 4;
- int h = TQMAX(fm.height() + 4, ih );
- int offset = 3;
+ TQStyle::SFlags flags = TQStyle::Style_Default;
+
+ if (isEnabled() && t->isEnabled()) {
+ flags |= TQStyle::Style_Enabled;
+ }
+ if (topLevelWidget() == tqApp->activeWindow()) {
+ flags |= TQStyle::Style_Active;
+ }
+ if ( selected ) {
+ flags |= TQStyle::Style_Selected;
+ }
+ else if (t == d->pressed) {
+ flags |= TQStyle::Style_Sunken;
+ }
+
+ //selection flags
+ if (t->rect().contains(mapFromGlobal(TQCursor::pos()))) {
+ flags |= TQStyle::Style_MouseOver;
+ }
+ style().drawControl( TQStyle::CE_TabBarTab, p, this, t->rect(), colorGroup(), flags, TQStyleOption(t, hoverTab) );
+
+ TQRect r( t->r );
+ p->setFont( font() );
+
+ int iw = 0;
+ int ih = 0;
+ if ( t->iconset != 0 ) {
+ iw = t->iconset->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4;
+ ih = t->iconset->pixmap( TQIconSet::Small, TQIconSet::Normal ).height();
+ }
+ TQFontMetrics fm = p->fontMetrics();
+ int fw = fm.width( t->label );
+ fw -= t->label.contains('&') * fm.width('&');
+ fw += t->label.contains("&&") * fm.width('&');
+ int w = iw + fw + 4;
+ int h = TQMAX(fm.height() + 4, ih );
+ int offset = 3;
#ifdef Q_WS_MAC
- if (::tqt_cast<TQMacStyle *>(&style()))
- offset = 0;
+ if (::tqt_cast<TQMacStyle *>(&style())) {
+ offset = 0;
+ }
#endif
- paintLabel( p, TQRect( r.left() + (r.width()-w)/2 - offset,
- r.top() + (r.height()-h)/2,
- w, h ), t, t->id == keyboardFocusTab() );
+ paintLabel( p, TQRect( r.left() + (r.width()-w)/2 - offset, r.top() + (r.height()-h)/2, w, h ), t, t->id == keyboardFocusTab() );
}
/*!
@@ -630,43 +634,48 @@ void TQTabBar::paint( TQPainter * p, TQTab * t, bool selected ) const
void TQTabBar::paintLabel( TQPainter* p, const TQRect& br,
TQTab* t, bool has_focus ) const
{
- TQRect r = br;
- bool selected = currentTab() == t->id;
- if ( t->iconset) {
- // the tab has an iconset, draw it in the right mode
- TQIconSet::Mode mode = (t->enabled && isEnabled())
- ? TQIconSet::Normal : TQIconSet::Disabled;
- if ( mode == TQIconSet::Normal && has_focus )
- mode = TQIconSet::Active;
- TQPixmap pixmap = t->iconset->pixmap( TQIconSet::Small, mode );
- int pixw = pixmap.width();
- int pixh = pixmap.height();
- r.setLeft( r.left() + pixw + 4 );
- r.setRight( r.right() + 2 );
-
- int xoff = 0, yoff = 0;
- if(!selected) {
- xoff = style().pixelMetric(TQStyle::PM_TabBarTabShiftHorizontal, this);
- yoff = style().pixelMetric(TQStyle::PM_TabBarTabShiftVertical, this);
+ TQRect r = br;
+ bool selected = currentTab() == t->id;
+ if ( t->iconset) {
+ // the tab has an iconset, draw it in the right mode
+ TQIconSet::Mode mode = (t->enabled && isEnabled())
+ ? TQIconSet::Normal : TQIconSet::Disabled;
+ if ( mode == TQIconSet::Normal && has_focus )
+ mode = TQIconSet::Active;
+ TQPixmap pixmap = t->iconset->pixmap( TQIconSet::Small, mode );
+ int pixw = pixmap.width();
+ int pixh = pixmap.height();
+ r.setLeft( r.left() + pixw + 4 );
+ r.setRight( r.right() + 2 );
+
+ int xoff = 0, yoff = 0;
+ if(!selected) {
+ xoff = style().pixelMetric(TQStyle::PM_TabBarTabShiftHorizontal, this);
+ yoff = style().pixelMetric(TQStyle::PM_TabBarTabShiftVertical, this);
+ }
+ p->drawPixmap( br.left() + 2 + xoff, br.center().y()-pixh/2 + yoff, pixmap );
}
- p->drawPixmap( br.left() + 2 + xoff, br.center().y()-pixh/2 + yoff, pixmap );
- }
- TQStyle::SFlags flags = TQStyle::Style_Default;
-
- if (isEnabled() && t->isEnabled())
- flags |= TQStyle::Style_Enabled;
- if (has_focus)
- flags |= TQStyle::Style_HasFocus;
- if ( selected )
- flags |= TQStyle::Style_Selected;
- else if(t == d->pressed)
- flags |= TQStyle::Style_Sunken;
- if(t->rect().contains(mapFromGlobal(TQCursor::pos())))
- flags |= TQStyle::Style_MouseOver;
- style().drawControl( TQStyle::CE_TabBarLabel, p, this, r,
- t->isEnabled() ? colorGroup(): palette().disabled(),
- flags, TQStyleOption(t) );
+ TQStyle::SFlags flags = TQStyle::Style_Default;
+
+ if (isEnabled() && t->isEnabled()) {
+ flags |= TQStyle::Style_Enabled;
+ }
+ if (has_focus) {
+ flags |= TQStyle::Style_HasFocus;
+ }
+ if ( selected ) {
+ flags |= TQStyle::Style_Selected;
+ }
+ else if(t == d->pressed) {
+ flags |= TQStyle::Style_Sunken;
+ }
+ if(t->rect().contains(mapFromGlobal(TQCursor::pos()))) {
+ flags |= TQStyle::Style_MouseOver;
+ }
+ style().drawControl( TQStyle::CE_TabBarLabel, p, this, r,
+ t->isEnabled() ? colorGroup(): palette().disabled(),
+ flags, TQStyleOption(t, hoverTab) );
}
@@ -689,8 +698,9 @@ void TQTabBar::paintEvent( TQPaintEvent * e )
t = l->first();
do {
TQTab * n = l->next();
- if ( t && t->r.intersects( e->rect() ) )
+ if ( t && t->r.intersects( e->rect() ) ) {
paint( buffer.painter(), t, n == 0 );
+ }
t = n;
} while ( t != 0 );
@@ -776,19 +786,38 @@ void TQTabBar::mousePressEvent( TQMouseEvent * e )
void TQTabBar::mouseMoveEvent ( TQMouseEvent *e )
{
- if ( e->state() != LeftButton ) {
- e->ignore();
- return;
- }
- if(style().styleHint( TQStyle::SH_TabBar_SelectMouseType, this ) == TQEvent::MouseButtonRelease) {
TQTab *t = selectTab( e->pos() );
- if(t != d->pressed) {
- if(d->pressed)
- repaint(d->pressed->rect(), FALSE);
- if((d->pressed = t))
- repaint(t->rect(), FALSE);
+
+ // Repaint hover indicator(s)
+ // Also, avoid unnecessary repaints which otherwise would occour on every MouseMove event causing high cpu load
+ bool forceRepaint = true;
+ if (hoverTab == t) {
+ forceRepaint = false;
+ }
+ hoverTab = t;
+ if (forceRepaint) {
+ repaint(false);
+ }
+
+ if ( e->state() != LeftButton ) {
+ e->ignore();
+ return;
+ }
+
+ if(style().styleHint( TQStyle::SH_TabBar_SelectMouseType, this ) == TQEvent::MouseButtonRelease) {
+ if(t != d->pressed) {
+ if (d->pressed) {
+ if (!forceRepaint) {
+ repaint(d->pressed->rect(), FALSE);
+ }
+ }
+ if ((d->pressed = t)) {
+ if (!forceRepaint) {
+ repaint(t->rect(), FALSE);
+ }
+ }
+ }
}
- }
}
/*!
@@ -797,16 +826,28 @@ void TQTabBar::mouseMoveEvent ( TQMouseEvent *e )
void TQTabBar::mouseReleaseEvent( TQMouseEvent *e )
{
- if ( e->button() != LeftButton )
- e->ignore();
- if(d->pressed) {
- TQTab *t = selectTab( e->pos() ) == d->pressed ? d->pressed : 0;
- d->pressed = 0;
- if(t && t->enabled && e->type() == style().styleHint( TQStyle::SH_TabBar_SelectMouseType, this ))
- setCurrentTab( t );
- }
+ if (e->button() != LeftButton) {
+ e->ignore();
+ }
+
+ if (d->pressed) {
+ TQTab *t = selectTab( e->pos() ) == d->pressed ? d->pressed : 0;
+ d->pressed = 0;
+ if(t && t->enabled && e->type() == style().styleHint( TQStyle::SH_TabBar_SelectMouseType, this )) {
+ setCurrentTab( t );
+ }
+ }
}
+void TQTabBar::enterEvent( TQEvent * )
+{
+ hoverTab = 0;
+}
+
+void TQTabBar::leaveEvent( TQEvent * )
+{
+ hoverTab = 0;
+}
/*!
\reimp
@@ -1119,7 +1160,7 @@ void TQTabBar::layoutTabs()
h += vframe;
t->r = TQRect(TQPoint(x, 0), style().sizeFromContents(TQStyle::CT_TabBarTab, this,
TQSize( TQMAX( lw + hframe + iw, TQApplication::globalStrut().width() ), h ),
- TQStyleOption(t) ));
+ TQStyleOption(t, hoverTab) ));
x += t->r.width() - overlap;
r = r.unite( t->r );
if ( reverse )
@@ -1375,4 +1416,12 @@ void TQTabBar::fontChange( const TQFont & oldFont )
TQWidget::fontChange( oldFont );
}
+/*!
+ Returns the tab currently under the mouse pointer, or NULL if no tab is under the cursor
+*/
+TQTab *TQTabBar::mouseHoverTab() const
+{
+ return hoverTab;
+}
+
#endif