40#include <QApplication>
41#include <QDragMoveEvent>
43#include <QTextDocument>
44#include <QtGuiVersion>
81 QSize size(
m_parent->tabBar()->sizeHint() );
82 if ( (
m_parent->tabPosition() == QTabWidget::North && point.y() < size.height() ) ||
83 (
m_parent->tabPosition() == QTabWidget::South && point.y() > (
m_parent->height() - size.height() ) ) ) {
85 QWidget *rightcorner =
m_parent->cornerWidget( Qt::TopRightCorner );
87 if ( point.x() >=
m_parent->width()-rightcorner->width() )
91 QWidget *leftcorner =
m_parent->cornerWidget( Qt::TopLeftCorner );
93 if ( point.x() <= leftcorner->width() )
97 for (
int i = 0; i <
m_parent->count(); ++i )
98 if (
m_parent->tabBar()->tabRect( i ).contains(
m_parent->tabBar()->mapFromParent( point ) ) )
113 int lcw = 0, rcw = 0;
115 int tabBarHeight =
m_parent->tabBar()->sizeHint().height();
116 if (
m_parent->cornerWidget( Qt::TopLeftCorner ) &&
m_parent->cornerWidget( Qt::TopLeftCorner )->isVisible() )
117 lcw = qMax(
m_parent->cornerWidget( Qt::TopLeftCorner )->width(), tabBarHeight );
119 if (
m_parent->cornerWidget( Qt::TopRightCorner ) &&
m_parent->cornerWidget( Qt::TopRightCorner )->isVisible() )
120 rcw = qMax(
m_parent->cornerWidget( Qt::TopRightCorner )->width(), tabBarHeight );
122 int maxTabBarWidth =
m_parent->width() - lcw - rcw;
124 for ( ; newMaxLength >
m_minLength; newMaxLength-- ) {
125 if (
m_parent->tabBarWidthForMaxChars( newMaxLength ) < maxTabBarWidth )
134 for (
int i = 0; i <
m_parent->count(); ++i )
136 }
else if ( changeTabIndex != -1 )
146 if ( Qt::mightBeRichText( title ) )
148 m_parent->setTabToolTip(
index, QString(title).toHtmlEscaped() );
155 title.replace(
'&',
"&&" );
163 : QTabWidget( parent ),
166 setWindowFlags( flags );
168 setObjectName(
"tabbar" );
169 setAcceptDrops(
true );
175 connect(tabBar(), SIGNAL(
testCanDecode(
const QDragMoveEvent *,
bool & )), SIGNAL(
testCanDecode(
const QDragMoveEvent *,
bool & )));
179#ifndef QT_NO_WHEELEVENT
216 QWidget *rightcorner = cornerWidget( Qt::TopRightCorner );
217 QWidget *leftcorner = cornerWidget( Qt::TopLeftCorner );
220 if ( leftcorner ) leftcorner->hide();
221 if ( rightcorner ) rightcorner->hide();
225 if ( leftcorner ) leftcorner->show();
226 if ( rightcorner ) rightcorner->show();
232 return !( tabBar()->isVisible() );
242 return tabBar()->tabTextColor(
index );
268 hframe = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabHSpace, 0L, tabBar() );
271 QFontMetrics fm = tabBar()->fontMetrics();
273 for (
int i = 0; i <
count(); ++i ) {
274 QString newTitle =
m_d->m_tabNames[ i ];
278 int lw = fm.horizontalAdvance( newTitle );
280 if ( !tabBar()->tabIcon( i ).isNull() ){
281 iw = tabBar()->tabIcon( i ).pixmap( style()->pixelMetric( QStyle::PM_SmallIconSize ), QIcon::Normal ).width() + 4;
283 x += ( tabBar()->style()->sizeFromContents( QStyle::CT_TabBarTab, 0L,
284 QSize( qMax( lw + hframe + iw, QApplication::globalStrut().
width() ), 0 ),
293 if (
m_d->m_automaticResizeTabs ) {
300 return QTabWidget::tabText(
index );
305 QTabWidget::setTabText(
index, text );
306 if (
m_d->m_automaticResizeTabs ) {
317 event->setAccepted(
true );
318 QTabWidget::dragEnterEvent( event );
323 if (
m_d->isEmptyTabbarSpace( event->pos() ) ) {
329 event->setAccepted( accept );
333 event->setAccepted(
false );
334 QTabWidget::dragMoveEvent( event );
339 if (
m_d->isEmptyTabbarSpace( event->pos() ) ) {
344 QTabWidget::dropEvent( event );
347#ifndef QT_NO_WHEELEVENT
350#if QTGUI_VERSION >= 0x050E00
351 if (
m_d->isEmptyTabbarSpace( event->position().toPoint() ) )
353 if (
m_d->isEmptyTabbarSpace( event->pos() ) )
365 int page = currentIndex();
367 page = (page + 1) %
count();
373 setCurrentIndex( page );
379 if ( event->button() != Qt::LeftButton )
382 if (
m_d->isEmptyTabbarSpace( event->pos() ) ) {
387 QTabWidget::mouseDoubleClickEvent( event );
392 if ( event->button() == Qt::RightButton ) {
393 if (
m_d->isEmptyTabbarSpace( event->pos() ) ) {
394 emit(
contextMenu( mapToGlobal( event->pos() ) ) );
397 }
else if ( event->button() == Qt::MiddleButton ) {
398 if (
m_d->isEmptyTabbarSpace( event->pos() ) ) {
404 QTabWidget::mousePressEvent( event );
434 QString tablabel =
tabText( from );
435 QWidget *w = widget( from );
437 QIcon tabiconset = tabIcon( from );
438 QString tabtooltip = tabToolTip( from );
439 bool current = ( from == currentIndex() );
440 bool enabled = isTabEnabled( from );
442 bool blocked = blockSignals(
true );
446 insertTab( to, w, tablabel );
447 if (
m_d->m_automaticResizeTabs ) {
448 if ( to < 0 || to >=
count() )
449 m_d->m_tabNames.append( QString() );
451 m_d->m_tabNames.insert( to, QString() );
454 setTabIcon( to, tabiconset );
456 setTabToolTip( to, tabtooltip );
459 setCurrentIndex( to );
460 setTabEnabled( to, enabled );
461 blockSignals( blocked );
468 QTabWidget::removeTab( indexOf( widget ) );
469 if (
m_d->m_automaticResizeTabs )
475 QTabWidget::removeTab(
index );
476 if (
m_d->m_automaticResizeTabs )
482 if (
m_d->m_automaticResizeTabs == enabled )
485 m_d->m_automaticResizeTabs = enabled;
487 m_d->m_tabNames.clear();
488 for (
int i = 0; i <
count(); ++i )
489 m_d->m_tabNames.append( tabBar()->
tabText( i ) );
491 for (
int i = 0; i <
count(); ++i )
492 tabBar()->setTabText( i,
m_d->m_tabNames[ i ] );
499 return m_d->m_automaticResizeTabs;
509 QTabWidget::resizeEvent( event );
515 m_d->m_tabNames.insert( idx, tabBar()->
tabText( idx ) );
520 m_d->m_tabNames.removeAt( idx );
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string