summaryrefslogtreecommitdiffstats
path: root/lib/kofficeui/KoTabBar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kofficeui/KoTabBar.cpp')
-rw-r--r--lib/kofficeui/KoTabBar.cpp248
1 files changed, 124 insertions, 124 deletions
diff --git a/lib/kofficeui/KoTabBar.cpp b/lib/kofficeui/KoTabBar.cpp
index d73025b4..002f3ebe 100644
--- a/lib/kofficeui/KoTabBar.cpp
+++ b/lib/kofficeui/KoTabBar.cpp
@@ -24,23 +24,23 @@
#include "KoTabBar.h"
-#include <qdrawutil.h>
-#include <qpainter.h>
-#include <qstring.h>
-#include <qstringlist.h>
-#include <qstyle.h>
-#include <qtimer.h>
-#include <qtoolbutton.h>
-#include <qvaluevector.h>
-#include <qwidget.h>
+#include <tqdrawutil.h>
+#include <tqpainter.h>
+#include <tqstring.h>
+#include <tqstringlist.h>
+#include <tqstyle.h>
+#include <tqtimer.h>
+#include <tqtoolbutton.h>
+#include <tqvaluevector.h>
+#include <tqwidget.h>
// TODO
// improvement possibilities
// - use offscreen buffer to reduce flicker even more
-// - keep track of tabs, only (re)layout when necessary
+// - keep track of tabs, only (re)tqlayout when necessary
// - paint all tabs to buffer, show only by shifting
// - customizable button pixmaps
-// - use QStyle to paint the tabs & buttons (is it good/possible?)
+// - use TQStyle to paint the tabs & buttons (is it good/possible?)
class KoTabBarPrivate
@@ -49,22 +49,22 @@ public:
KoTabBar* tabbar;
// scroll buttons
- QToolButton* scrollFirstButton;
- QToolButton* scrollLastButton;
- QToolButton* scrollBackButton;
- QToolButton* scrollForwardButton;
+ TQToolButton* scrollFirstButton;
+ TQToolButton* scrollLastButton;
+ TQToolButton* scrollBackButton;
+ TQToolButton* scrollForwardButton;
// read-only: no mouse drag, double-click, right-click
bool readOnly;
- // if true, layout is from right to left
+ // if true, tqlayout is from right to left
bool reverseLayout;
// list of all tabs, in order of appearance
- QStringList tabs;
+ TQStringList tabs;
- // array of QRect for each visible tabs
- QValueVector<QRect> tabRects;
+ // array of TQRect for each visible tabs
+ TQValueVector<TQRect> tabRects;
// leftmost tab (or rightmost if reverseLayout)
int firstTab;
@@ -91,20 +91,20 @@ public:
bool autoScroll;
// calculate the bounding rectangle for each visible tab
- void layoutTabs();
+ void tqlayoutTabs();
// reposition scroll buttons
- void layoutButtons();
+ void tqlayoutButtons();
// find a tab whose bounding rectangle contains the pos
// return -1 if no such tab is found
- int tabAt( const QPoint& pos );
+ int tabAt( const TQPoint& pos );
// draw a single tab
- void drawTab( QPainter& painter, QRect& rect, const QString& text, bool active );
+ void drawTab( TQPainter& painter, TQRect& rect, const TQString& text, bool active );
// draw a marker to indicate tab moving
- void drawMoveMarker( QPainter& painter, int x, int y );
+ void drawMoveMarker( TQPainter& painter, int x, int y );
// update the enable/disable status of scroll buttons
void updateButtons();
@@ -176,16 +176,16 @@ static const char * arrow_right_xpm[] = {
" "};
-void KoTabBarPrivate::layoutTabs()
+void KoTabBarPrivate::tqlayoutTabs()
{
tabRects.clear();
- QPainter painter( tabbar );
+ TQPainter painter( tabbar );
- QFont f = painter.font();
+ TQFont f = painter.font();
f.setBold( true );
painter.setFont( f );
- QFontMetrics fm = painter.fontMetrics();
+ TQFontMetrics fm = painter.fontMetrics();
if( !reverseLayout )
{
@@ -193,12 +193,12 @@ void KoTabBarPrivate::layoutTabs()
int x = 0;
for( unsigned c = 0; c < tabs.count(); c++ )
{
- QRect rect;
+ TQRect rect;
if( (int)c >= firstTab-1 )
{
- QString text = tabs[ c ];
+ TQString text = tabs[ c ];
int tw = fm.width( text ) + 4;
- rect = QRect( x, 0, tw + 20, tabbar->height() );
+ rect = TQRect( x, 0, tw + 20, tabbar->height() );
x = x + tw + 20;
}
tabRects.append( rect );
@@ -218,12 +218,12 @@ void KoTabBarPrivate::layoutTabs()
int x = tabbar->width() - offset;
for( unsigned c = 0; c < tabs.count(); c++ )
{
- QRect rect;
+ TQRect rect;
if( (int)c >= firstTab-1 )
{
- QString text = tabs[ c ];
+ TQString text = tabs[ c ];
int tw = fm.width( text ) + 4;
- rect = QRect( x - tw - 20, 0, tw + 20, tabbar->height() );
+ rect = TQRect( x - tw - 20, 0, tw + 20, tabbar->height() );
x = x - tw - 20;
}
tabRects.append( rect );
@@ -239,21 +239,21 @@ void KoTabBarPrivate::layoutTabs()
}
}
-int KoTabBarPrivate::tabAt( const QPoint& pos )
+int KoTabBarPrivate::tabAt( const TQPoint& pos )
{
for( unsigned i = 0; i < tabRects.count(); i++ )
{
- QRect rect = tabRects[ i ];
+ TQRect rect = tabRects[ i ];
if( rect.isNull() ) continue;
- if( rect.contains( pos ) ) return i;
+ if( rect.tqcontains( pos ) ) return i;
}
return -1; // not found
}
-void KoTabBarPrivate::drawTab( QPainter& painter, QRect& rect, const QString& text, bool active )
+void KoTabBarPrivate::drawTab( TQPainter& painter, TQRect& rect, const TQString& text, bool active )
{
- QPointArray polygon;
+ TQPointArray polygon;
if( !reverseLayout )
polygon.setPoints( 6, rect.x(), rect.y(),
@@ -273,24 +273,24 @@ void KoTabBarPrivate::drawTab( QPainter& painter, QRect& rect, const QString& te
painter.save();
// fill it first
- QBrush bg = tabbar->colorGroup().background();
- if( active ) bg = tabbar->colorGroup().base();
+ TQBrush bg = tabbar->tqcolorGroup().background();
+ if( active ) bg = TQBrush(tabbar->tqcolorGroup().base());
painter.setBrush( bg );
- painter.setPen( QPen( Qt::NoPen ) );
+ painter.setPen( TQPen( TQt::NoPen ) );
painter.drawPolygon( polygon );
// draw the lines
- painter.setPen( tabbar->colorGroup().dark() );
+ painter.setPen( tabbar->tqcolorGroup().dark() );
if( !active )
painter.drawLine( rect.x()-25, rect.y(), rect.right()+25, rect.top() );
- // Qt4: painter.setRenderHint( QPainter::Antialiasing );
+ // TQt4: painter.setRenderHint( TQPainter::Antialiasing );
painter.drawPolyline( polygon );
- painter.setPen( tabbar->colorGroup().buttonText() );
- QFont f = painter.font();
+ painter.setPen( tabbar->tqcolorGroup().buttonText() );
+ TQFont f = painter.font();
if( active ) f.setBold( true );
painter.setFont( f );
- QFontMetrics fm = painter.fontMetrics();
+ TQFontMetrics fm = painter.fontMetrics();
int tx = rect.x() + ( rect.width() - fm.width( text ) ) / 2;
int ty = rect.y() + ( rect.height() - fm.height() ) / 2 + fm.ascent();
painter.drawText( tx, ty, text );
@@ -298,17 +298,17 @@ void KoTabBarPrivate::drawTab( QPainter& painter, QRect& rect, const QString& te
painter.restore();
}
-void KoTabBarPrivate::drawMoveMarker( QPainter& painter, int x, int y )
+void KoTabBarPrivate::drawMoveMarker( TQPainter& painter, int x, int y )
{
- QPointArray movmark;
+ TQPointArray movmark;
movmark.setPoints( 3, x, y, x + 7, y, x + 4, y + 6);
- QBrush oldBrush = painter.brush();
- painter.setBrush( Qt::black );
+ TQBrush oldBrush = painter.brush();
+ painter.setBrush( TQt::black );
painter.drawPolygon(movmark);
painter.setBrush( oldBrush );
}
-void KoTabBarPrivate::layoutButtons()
+void KoTabBarPrivate::tqlayoutButtons()
{
int bw = tabbar->height();
int w = tabbar->width();
@@ -347,8 +347,8 @@ void KoTabBarPrivate::updateButtons()
}
// creates a new tabbar
-KoTabBar::KoTabBar( QWidget* parent, const char* name )
- : QWidget( parent, name, Qt::WResizeNoErase | Qt::WRepaintNoErase )
+KoTabBar::KoTabBar( TQWidget* tqparent, const char* name )
+ : TQWidget( tqparent, name, TQt::WResizeNoErase | TQt::WRepaintNoErase )
{
d = new KoTabBarPrivate;
d->tabbar = this;
@@ -363,19 +363,19 @@ KoTabBar::KoTabBar( QWidget* parent, const char* name )
d->offset = 64;
// initialize the scroll buttons
- d->scrollFirstButton = new QToolButton( this );
- connect( d->scrollFirstButton, SIGNAL( clicked() ),
- this, SLOT( scrollFirst() ) );
- d->scrollLastButton = new QToolButton( this );
- connect( d->scrollLastButton, SIGNAL( clicked() ),
- this, SLOT( scrollLast() ) );
- d->scrollBackButton = new QToolButton( this );
- connect( d->scrollBackButton, SIGNAL( clicked() ),
- this, SLOT( scrollBack() ) );
- d->scrollForwardButton = new QToolButton( this );
- connect( d->scrollForwardButton, SIGNAL( clicked() ),
- this, SLOT( scrollForward() ) );
- d->layoutButtons();
+ d->scrollFirstButton = new TQToolButton( this );
+ connect( d->scrollFirstButton, TQT_SIGNAL( clicked() ),
+ this, TQT_SLOT( scrollFirst() ) );
+ d->scrollLastButton = new TQToolButton( this );
+ connect( d->scrollLastButton, TQT_SIGNAL( clicked() ),
+ this, TQT_SLOT( scrollLast() ) );
+ d->scrollBackButton = new TQToolButton( this );
+ connect( d->scrollBackButton, TQT_SIGNAL( clicked() ),
+ this, TQT_SLOT( scrollBack() ) );
+ d->scrollForwardButton = new TQToolButton( this );
+ connect( d->scrollForwardButton, TQT_SIGNAL( clicked() ),
+ this, TQT_SLOT( scrollForward() ) );
+ d->tqlayoutButtons();
d->updateButtons();
}
@@ -386,7 +386,7 @@ KoTabBar::~KoTabBar()
}
// adds a new visible tab
-void KoTabBar::addTab( const QString& text )
+void KoTabBar::addTab( const TQString& text )
{
d->tabs.append( text );
@@ -394,9 +394,9 @@ void KoTabBar::addTab( const QString& text )
}
// removes a tab
-void KoTabBar::removeTab( const QString& text )
+void KoTabBar::removeTab( const TQString& text )
{
- int i = d->tabs.findIndex( text );
+ int i = d->tabs.tqfindIndex( text );
if ( i == -1 ) return;
if ( d->activeTab == i + 1 )
@@ -437,16 +437,16 @@ void KoTabBar::setReverseLayout( bool reverse )
if( reverse != d->reverseLayout )
{
d->reverseLayout = reverse;
- d->layoutTabs();
- d->layoutButtons();
+ d->tqlayoutTabs();
+ d->tqlayoutButtons();
d->updateButtons();
update();
}
}
-void KoTabBar::setTabs( const QStringList& list )
+void KoTabBar::setTabs( const TQStringList& list )
{
- QString left, active;
+ TQString left, active;
if( d->activeTab > 0 )
active = d->tabs[ d->activeTab-1 ];
@@ -457,7 +457,7 @@ void KoTabBar::setTabs( const QStringList& list )
if( !left.isNull() )
{
- d->firstTab = d->tabs.findIndex( left ) + 1;
+ d->firstTab = d->tabs.tqfindIndex( left ) + 1;
if( d->firstTab > (int)d->tabs.count() )
d->firstTab = 1;
if( d->firstTab <= 0 )
@@ -471,7 +471,7 @@ void KoTabBar::setTabs( const QStringList& list )
update();
}
-QStringList KoTabBar::tabs() const
+TQStringList KoTabBar::tabs() const
{
return d->tabs;
}
@@ -505,7 +505,7 @@ void KoTabBar::scrollBack()
d->firstTab--;
if( d->firstTab < 1 ) d->firstTab = 1;
- d->layoutTabs();
+ d->tqlayoutTabs();
d->updateButtons();
update();
}
@@ -519,7 +519,7 @@ void KoTabBar::scrollForward()
if( d->firstTab > (int)d->tabs.count() )
d->firstTab = d->tabs.count();
- d->layoutTabs();
+ d->tqlayoutTabs();
d->updateButtons();
update();
}
@@ -530,7 +530,7 @@ void KoTabBar::scrollFirst()
return;
d->firstTab = 1;
- d->layoutTabs();
+ d->tqlayoutTabs();
d->updateButtons();
update();
}
@@ -540,7 +540,7 @@ void KoTabBar::scrollLast()
if ( !canScrollForward() )
return;
- d->layoutTabs();
+ d->tqlayoutTabs();
if( !d->reverseLayout )
{
@@ -561,18 +561,18 @@ void KoTabBar::scrollLast()
int x = d->tabRects[ d->tabRects.count()-1 ].x();
if( x > 0 ) break;
d->firstTab++;
- d->layoutTabs();
+ d->tqlayoutTabs();
}
}
- d->layoutTabs();
+ d->tqlayoutTabs();
d->updateButtons();
update();
}
-void KoTabBar::ensureVisible( const QString& tab )
+void KoTabBar::ensureVisible( const TQString& tab )
{
- int i = d->tabs.findIndex( tab );
+ int i = d->tabs.tqfindIndex( tab );
if ( i == -1 )
return;
i++;
@@ -592,8 +592,8 @@ void KoTabBar::ensureVisible( const QString& tab )
void KoTabBar::moveTab( unsigned tab, unsigned target )
{
- QString tabName = d->tabs[ tab ];
- QStringList::Iterator it;
+ TQString tabName = d->tabs[ tab ];
+ TQStringList::Iterator it;
it = d->tabs.at( tab );
d->tabs.remove( it );
@@ -610,9 +610,9 @@ void KoTabBar::moveTab( unsigned tab, unsigned target )
update();
}
-void KoTabBar::setActiveTab( const QString& text )
+void KoTabBar::setActiveTab( const TQString& text )
{
- int i = d->tabs.findIndex( text );
+ int i = d->tabs.tqfindIndex( text );
if ( i == -1 )
return;
@@ -635,7 +635,7 @@ void KoTabBar::autoScrollBack()
if( !canScrollBack() )
d->autoScroll = false;
else
- QTimer::singleShot( 400, this, SLOT( autoScrollBack() ) );
+ TQTimer::singleShot( 400, this, TQT_SLOT( autoScrollBack() ) );
}
void KoTabBar::autoScrollForward()
@@ -647,10 +647,10 @@ void KoTabBar::autoScrollForward()
if( !canScrollForward() )
d->autoScroll = false;
else
- QTimer::singleShot( 400, this, SLOT( autoScrollForward() ) );
+ TQTimer::singleShot( 400, this, TQT_SLOT( autoScrollForward() ) );
}
-void KoTabBar::paintEvent( QPaintEvent* )
+void KoTabBar::paintEvent( TQPaintEvent* )
{
if ( d->tabs.count() == 0 )
{
@@ -658,36 +658,36 @@ void KoTabBar::paintEvent( QPaintEvent* )
return;
}
- QPainter painter;
- QPixmap pm( size() );
- pm.fill( colorGroup().background() );
- painter.begin( &pm, this );
+ TQPainter painter;
+ TQPixmap pm( size() );
+ pm.fill( tqcolorGroup().background() );
+ painter.tqbegin( TQT_TQPAINTDEVICE(&pm), this );
- painter.setPen( colorGroup().dark() );
+ painter.setPen( tqcolorGroup().dark() );
painter.drawLine( 0, 0, width(), 0 );
if( !d->reverseLayout )
painter.translate( 5, 0 );
- d->layoutTabs();
+ d->tqlayoutTabs();
d->updateButtons();
// draw first all non-active, visible tabs
for( int c = d->tabRects.count()-1; c>=0; c-- )
{
- QRect rect = d->tabRects[ c ];
+ TQRect rect = d->tabRects[ c ];
if( rect.isNull() ) continue;
- QString text = d->tabs[ c ];
+ TQString text = d->tabs[ c ];
d->drawTab( painter, rect, text, false );
}
// draw the active tab
if( d->activeTab > 0 )
{
- QRect rect = d->tabRects[ d->activeTab-1 ];
+ TQRect rect = d->tabRects[ d->activeTab-1 ];
if( !rect.isNull() )
{
- QString text = d->tabs[ d->activeTab-1 ];
+ TQString text = d->tabs[ d->activeTab-1 ];
d->drawTab( painter, rect, text, true );
}
}
@@ -695,8 +695,8 @@ void KoTabBar::paintEvent( QPaintEvent* )
// draw the move marker
if( d->targetTab > 0 )
{
- int p = QMIN( d->targetTab, (int)d->tabRects.count() );
- QRect rect = d->tabRects[ p-1 ];
+ int p = TQMIN( d->targetTab, (int)d->tabRects.count() );
+ TQRect rect = d->tabRects[ p-1 ];
if( !rect.isNull() )
{
int x = !d->reverseLayout ? rect.x() : rect.right()-7;
@@ -715,35 +715,35 @@ void KoTabBar::paintEvent( QPaintEvent* )
}
-void KoTabBar::resizeEvent( QResizeEvent* )
+void KoTabBar::resizeEvent( TQResizeEvent* )
{
- d->layoutButtons();
+ d->tqlayoutButtons();
d->updateButtons();
update();
}
-QSize KoTabBar::sizeHint() const
+TQSize KoTabBar::tqsizeHint() const
{
- return QSize( 40, style().pixelMetric( QStyle::PM_ScrollBarExtent, this ) );
+ return TQSize( 40, tqstyle().tqpixelMetric( TQStyle::PM_ScrollBarExtent, this ) );
}
-void KoTabBar::renameTab( const QString& old_name, const QString& new_name )
+void KoTabBar::renameTab( const TQString& old_name, const TQString& new_name )
{
- QStringList::Iterator it = d->tabs.find( old_name );
+ TQStringList::Iterator it = d->tabs.tqfind( old_name );
(*it) = new_name;
update();
}
-QString KoTabBar::activeTab() const
+TQString KoTabBar::activeTab() const
{
if( d->activeTab == 0 )
- return QString::null;
+ return TQString();
else
return d->tabs[ d->activeTab ];
}
-void KoTabBar::mousePressEvent( QMouseEvent* ev )
+void KoTabBar::mousePressEvent( TQMouseEvent* ev )
{
if ( d->tabs.count() == 0 )
{
@@ -751,10 +751,10 @@ void KoTabBar::mousePressEvent( QMouseEvent* ev )
return;
}
- d->layoutTabs();
+ d->tqlayoutTabs();
- QPoint pos = ev->pos();
- if( !d->reverseLayout ) pos = pos - QPoint( d->offset,0 );
+ TQPoint pos = ev->pos();
+ if( !d->reverseLayout ) pos = pos - TQPoint( d->offset,0 );
int tab = d->tabAt( pos ) + 1;
if( ( tab > 0 ) && ( tab != d->activeTab ) )
@@ -769,30 +769,30 @@ void KoTabBar::mousePressEvent( QMouseEvent* ev )
scrollForward();
}
- if( ev->button() == RightButton )
+ if( ev->button() == Qt::RightButton )
if( !d->readOnly )
emit contextMenu( ev->globalPos() );
}
-void KoTabBar::mouseReleaseEvent( QMouseEvent* ev )
+void KoTabBar::mouseReleaseEvent( TQMouseEvent* ev )
{
if ( d->readOnly ) return;
d->autoScroll = false;
- if ( ev->button() == LeftButton && d->targetTab != 0 )
+ if ( ev->button() == Qt::LeftButton && d->targetTab != 0 )
{
emit tabMoved( d->activeTab-1, d->targetTab-1 );
d->targetTab = 0;
}
}
-void KoTabBar::mouseMoveEvent( QMouseEvent* ev )
+void KoTabBar::mouseMoveEvent( TQMouseEvent* ev )
{
if ( d->readOnly ) return;
- QPoint pos = ev->pos();
- if( !d->reverseLayout) pos = pos - QPoint( d->offset,0 );
+ TQPoint pos = ev->pos();
+ if( !d->reverseLayout) pos = pos - TQPoint( d->offset,0 );
// check if user drags a tab to move it
int i = d->tabAt( pos ) + 1;
@@ -811,7 +811,7 @@ void KoTabBar::mouseMoveEvent( QMouseEvent* ev )
// drag past the very latest visible tab
// e.g move a tab to the last ordering position
- QRect r = d->tabRects[ d->tabRects.count()-1 ];
+ TQRect r = d->tabRects[ d->tabRects.count()-1 ];
bool moveToLast = false;
if( r.isValid() )
{
@@ -848,7 +848,7 @@ void KoTabBar::mouseMoveEvent( QMouseEvent* ev )
}
}
-void KoTabBar::mouseDoubleClickEvent( QMouseEvent* ev )
+void KoTabBar::mouseDoubleClickEvent( TQMouseEvent* ev )
{
int offset = d->reverseLayout ? 0 : d->offset;
if( ev->pos().x() > offset )
@@ -856,7 +856,7 @@ void KoTabBar::mouseDoubleClickEvent( QMouseEvent* ev )
emit doubleClicked();
}
-void KoTabBar::wheelEvent( QWheelEvent * e )
+void KoTabBar::wheelEvent( TQWheelEvent * e )
{
if ( d->tabs.count() == 0 )
{