40 #include <QApplication>
41 #include <QDragMoveEvent>
43 #include <QTextDocument>
44 #include <QtGuiVersion>
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() )
98 if (
m_parent->tabBar()->tabRect(
i ).contains(
m_parent->tabBar()->mapFromParent( point ) ) )
110 if ( m_automaticResizeTabs ) {
112 newMaxLength = m_maxLength;
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 )
132 if ( m_currentMaxLength != newMaxLength ) {
133 m_currentMaxLength = newMaxLength;
134 for (
int i = 0;
i < m_parent->count(); ++
i )
136 }
else if ( changeTabIndex != -1 )
137 updateTab( changeTabIndex );
142 QString
title = m_automaticResizeTabs ? m_tabNames[
index ] : m_parent->QTabWidget::tabText(
index );
143 m_parent->setTabToolTip(
index, QString() );
145 if (
title.length() > m_currentMaxLength ) {
146 if ( Qt::mightBeRichText(
title ) )
148 m_parent->setTabToolTip(
index, QString(
title).toHtmlEscaped() );
155 title.replace(
'&',
"&&" );
157 if ( m_parent->QTabWidget::tabText(
index ) !=
title )
158 m_parent->QTabWidget::setTabText(
index,
title );
166 setWindowFlags(
flags );
168 setObjectName(
"tabbar" );
169 setAcceptDrops(
true );
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 ) {
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 ),
300 return QTabWidget::tabText(
index );
317 event->setAccepted(
true );
318 QTabWidget::dragEnterEvent(
event );
329 event->setAccepted(
accept );
333 event->setAccepted(
false );
334 QTabWidget::dragMoveEvent(
event );
344 QTabWidget::dropEvent(
event );
347 #ifndef QT_NO_WHEELEVENT
350 #if QTGUI_VERSION >= 0x050E00
365 int page = currentIndex();
373 setCurrentIndex(
page );
379 if (
event->button() != Qt::LeftButton )
387 QTabWidget::mouseDoubleClickEvent(
event );
392 if (
event->button() == Qt::RightButton ) {
397 }
else if (
event->button() == Qt::MiddleButton ) {
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 );
448 if ( to < 0 || to >=
count() )
454 setTabIcon(
to, tabiconset );
456 setTabToolTip(
to, tabtooltip );
459 setCurrentIndex(
to );
460 setTabEnabled(
to, enabled );
461 blockSignals( blocked );
468 QTabWidget::removeTab( indexOf( widget ) );
475 QTabWidget::removeTab(
index );
509 QTabWidget::resizeEvent(
event );