Qt 4.8
qtabbar.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qlayoutengine_p.h"
43 #include "qabstractitemdelegate.h"
44 #include "qapplication.h"
45 #include "qbitmap.h"
46 #include "qcursor.h"
47 #include "qevent.h"
48 #include "qpainter.h"
49 #include "qstyle.h"
50 #include "qstyleoption.h"
51 #include "qstylepainter.h"
52 #include "qtabwidget.h"
53 #include "qtooltip.h"
54 #include "qwhatsthis.h"
55 #include "private/qtextengine_p.h"
56 #ifndef QT_NO_ACCESSIBILITY
57 #include "qaccessible.h"
58 #endif
59 
60 #include "qdebug.h"
61 #include "private/qtabbar_p.h"
62 
63 #ifndef QT_NO_TABBAR
64 
65 #ifdef Q_WS_MAC
66 #include <private/qt_mac_p.h>
67 #include <private/qt_cocoa_helpers_mac_p.h>
68 #endif
69 
70 #ifndef QT_NO_STYLE_S60
71 #include "qs60style.h"
72 #endif
73 
75 
76 
77 inline static bool verticalTabs(QTabBar::Shape shape)
78 {
79  return shape == QTabBar::RoundedWest
80  || shape == QTabBar::RoundedEast
81  || shape == QTabBar::TriangularWest
82  || shape == QTabBar::TriangularEast;
83 }
84 
86 {
87 #if (defined Q_WS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
89  Q_Q(QTabBar);
90  ::HIContentBorderMetrics metrics;
91 
92  // TODO: get metrics to preserve the bottom value
93  // TODO: test tab bar position
94 
96 
97  // push base line separator down to the client are so we can paint over it (Carbon)
98  metrics.top = (documentMode && q->isVisible()) ? 1 : 0;
99  metrics.bottom = 0;
100  metrics.left = 0;
101  metrics.right = 0;
102  qt_mac_updateContentBorderMetricts(window, metrics);
103 #if QT_MAC_USE_COCOA
104  // In Cocoa we need to keep track of the drawRect method.
105  // If documentMode is enabled we need to change it, unless
106  // a toolbar is present.
107  // Notice that all the information is kept in the window,
108  // that's why we get the private widget for it instead of
109  // the private widget for this widget.
110  QWidgetPrivate *privateWidget = qt_widget_private(q->window());
111  if(privateWidget)
112  privateWidget->changeMethods = documentMode;
113  // Since in Cocoa there is no simple way to remove the baseline, so we just ask the
114  // top level to do the magic for us.
115  privateWidget->syncUnifiedMode();
116 #endif // QT_MAC_USE_COCOA
117  }
118 #endif
119 }
120 
130 void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const
131 {
132  Q_D(const QTabBar);
133  int totalTabs = d->tabList.size();
134 
135  if (!option || (tabIndex < 0 || tabIndex >= totalTabs))
136  return;
137 
138  const QTabBarPrivate::Tab &tab = d->tabList.at(tabIndex);
139  option->initFrom(this);
141  option->rect = tabRect(tabIndex);
142  bool isCurrent = tabIndex == d->currentIndex;
143  option->row = 0;
144  if (tabIndex == d->pressedIndex)
145  option->state |= QStyle::State_Sunken;
146  if (isCurrent)
147  option->state |= QStyle::State_Selected;
148  if (isCurrent && hasFocus())
149  option->state |= QStyle::State_HasFocus;
150  if (!tab.enabled)
151  option->state &= ~QStyle::State_Enabled;
152  if (isActiveWindow())
153  option->state |= QStyle::State_Active;
154  if (!d->dragInProgress && option->rect == d->hoverRect)
155  option->state |= QStyle::State_MouseOver;
156  option->shape = d->shape;
157  option->text = tab.text;
158 
159  if (tab.textColor.isValid())
160  option->palette.setColor(foregroundRole(), tab.textColor);
161 
162  option->icon = tab.icon;
163  if (QStyleOptionTabV2 *optionV2 = qstyleoption_cast<QStyleOptionTabV2 *>(option))
164  optionV2->iconSize = iconSize(); // Will get the default value then.
165 
166  if (QStyleOptionTabV3 *optionV3 = qstyleoption_cast<QStyleOptionTabV3 *>(option)) {
167  optionV3->leftButtonSize = tab.leftWidget ? tab.leftWidget->size() : QSize();
168  optionV3->rightButtonSize = tab.rightWidget ? tab.rightWidget->size() : QSize();
169  optionV3->documentMode = d->documentMode;
170  }
171 
172  if (tabIndex > 0 && tabIndex - 1 == d->currentIndex)
174  else if (tabIndex + 1 < totalTabs && tabIndex + 1 == d->currentIndex)
176  else
178 
179  bool paintBeginning = (tabIndex == 0) || (d->dragInProgress && tabIndex == d->pressedIndex + 1);
180  bool paintEnd = (tabIndex == totalTabs - 1) || (d->dragInProgress && tabIndex == d->pressedIndex - 1);
181  if (paintBeginning) {
182  if (paintEnd)
184  else
186  } else if (paintEnd) {
187  option->position = QStyleOptionTab::End;
188  } else {
190  }
191 
192 #ifndef QT_NO_TABWIDGET
193  if (const QTabWidget *tw = qobject_cast<const QTabWidget *>(parentWidget())) {
194  if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner))
196  if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))
198  }
199 #endif
200 
201  QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this);
202  option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(),
204 }
205 
355 {
356  Q_Q(const QTabBar);
357  return 2 * qMax(q->style()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, 0, q),
359 }
360 
362 {
363  Q_Q(QTabBar);
364  leftB = new QToolButton(q);
365  leftB->setAutoRepeat(true);
366  QObject::connect(leftB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs()));
367  leftB->hide();
368  rightB = new QToolButton(q);
369  rightB->setAutoRepeat(true);
370  QObject::connect(rightB, SIGNAL(clicked()), q, SLOT(_q_scrollTabs()));
371  rightB->hide();
372 #ifdef QT_KEYPAD_NAVIGATION
373  if (QApplication::keypadNavigationEnabled()) {
376  q->setFocusPolicy(Qt::NoFocus);
377  } else
378 #endif
379  q->setFocusPolicy(Qt::TabFocus);
380  q->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
381  elideMode = Qt::TextElideMode(q->style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, q));
382  useScrollButtons = !q->style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, q);
383 }
384 
386 {
387  return validIndex(index)?&tabList[index]:0;
388 }
389 
391 {
392  return validIndex(index)?&tabList[index]:0;
393 }
394 
396 {
397  Q_Q(const QTabBar);
398  if (q->tabRect(currentIndex).contains(p))
399  return currentIndex;
400  for (int i = 0; i < tabList.count(); ++i)
401  if (tabList.at(i).enabled && q->tabRect(i).contains(p))
402  return i;
403  return -1;
404 }
405 
407 {
408  Q_Q(QTabBar);
409  scrollOffset = 0;
410  layoutDirty = false;
411  QSize size = q->size();
412  int last, available;
413  int maxExtent;
414  int i;
415  bool vertTabs = verticalTabs(shape);
416  int tabChainIndex = 0;
417 
418  Qt::Alignment tabAlignment = Qt::Alignment(q->style()->styleHint(QStyle::SH_TabBar_Alignment, 0, q));
419  QVector<QLayoutStruct> tabChain(tabList.count() + 2);
420 
421  // We put an empty item at the front and back and set its expansive attribute
422  // depending on tabAlignment.
423  tabChain[tabChainIndex].init();
424  tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignLeft)
425  && (tabAlignment != Qt::AlignJustify);
426  tabChain[tabChainIndex].empty = true;
427  ++tabChainIndex;
428 
429  // We now go through our list of tabs and set the minimum size and the size hint
430  // This will allow us to elide text if necessary. Since we don't set
431  // a maximum size, tabs will EXPAND to fill up the empty space.
432  // Since tab widget is rather *ahem* strict about keeping the geometry of the
433  // tab bar to its absolute minimum, this won't bleed through, but will show up
434  // if you use tab bar on its own (a.k.a. not a bug, but a feature).
435  // Update: if expanding is false, we DO set a maximum size to prevent the tabs
436  // being wider than necessary.
437  if (!vertTabs) {
438  int minx = 0;
439  int x = 0;
440  int maxHeight = 0;
441  for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {
442  QSize sz = q->tabSizeHint(i);
443  tabList[i].maxRect = QRect(x, 0, sz.width(), sz.height());
444  x += sz.width();
445  maxHeight = qMax(maxHeight, sz.height());
446  sz = minimumTabSizeHint(i);
447  tabList[i].minRect = QRect(minx, 0, sz.width(), sz.height());
448  minx += sz.width();
449  tabChain[tabChainIndex].init();
450  tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.width();
451  tabChain[tabChainIndex].minimumSize = sz.width();
452  tabChain[tabChainIndex].empty = false;
453  tabChain[tabChainIndex].expansive = true;
454 
455  if (!expanding)
456  tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint;
457  }
458 
459  last = minx;
460  available = size.width();
461  maxExtent = maxHeight;
462  } else {
463  int miny = 0;
464  int y = 0;
465  int maxWidth = 0;
466  for (i = 0; i < tabList.count(); ++i, ++tabChainIndex) {
467  QSize sz = q->tabSizeHint(i);
468  tabList[i].maxRect = QRect(0, y, sz.width(), sz.height());
469  y += sz.height();
470  maxWidth = qMax(maxWidth, sz.width());
471  sz = minimumTabSizeHint(i);
472  tabList[i].minRect = QRect(0, miny, sz.width(), sz.height());
473  miny += sz.height();
474  tabChain[tabChainIndex].init();
475  tabChain[tabChainIndex].sizeHint = tabList.at(i).maxRect.height();
476  tabChain[tabChainIndex].minimumSize = sz.height();
477  tabChain[tabChainIndex].empty = false;
478  tabChain[tabChainIndex].expansive = true;
479 
480  if (!expanding)
481  tabChain[tabChainIndex].maximumSize = tabChain[tabChainIndex].sizeHint;
482  }
483 
484  last = miny;
485  available = size.height();
486  maxExtent = maxWidth;
487  }
488 
489  Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure.
490  // Mirror our front item.
491  tabChain[tabChainIndex].init();
492  tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight)
493  && (tabAlignment != Qt::AlignJustify);
494  tabChain[tabChainIndex].empty = true;
495 
496  // Do the calculation
497  qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0);
498 
499  // Use the results
500  for (i = 0; i < tabList.count(); ++i) {
501  const QLayoutStruct &lstruct = tabChain.at(i + 1);
502  if (!vertTabs)
503  tabList[i].rect.setRect(lstruct.pos, 0, lstruct.size, maxExtent);
504  else
505  tabList[i].rect.setRect(0, lstruct.pos, maxExtent, lstruct.size);
506  }
507 
508  if (useScrollButtons && tabList.count() && last > available) {
509  int extra = extraWidth();
510 #ifndef QT_NO_STYLE_S60
511  QS60Style *s60Style = qobject_cast<QS60Style*>(QApplication::style());
512 #endif
513  if (!vertTabs) {
514  Qt::LayoutDirection ld = q->layoutDirection();
515  QRect arrows = QStyle::visualRect(ld, q->rect(),
516  QRect(available - extra, 0, extra, size.height()));
517  int buttonOverlap = q->style()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap, 0, q);
518 
519  if (ld == Qt::LeftToRight) {
520 // In S60style, tab scroll buttons are layoutted separately, on the sides of the tabbar.
521 #ifndef QT_NO_STYLE_S60
522  if (s60Style) {
523  rightB->setGeometry(arrows.left() + extra / 2, arrows.top(), extra / 2, arrows.height());
524  leftB->setGeometry(0, arrows.top(), extra / 2, arrows.height());
525  } else {
526 #endif
527  leftB->setGeometry(arrows.left(), arrows.top(), extra/2, arrows.height());
528  rightB->setGeometry(arrows.right() - extra/2 + buttonOverlap, arrows.top(),
529  extra/2, arrows.height());
530 #ifndef QT_NO_STYLE_S60
531  }
532 #endif
535  } else {
536 #ifndef QT_NO_STYLE_S60
537  if (s60Style) {
538  rightB->setGeometry(arrows.left() + extra / 2, arrows.top(), extra / 2, arrows.height());
539  leftB->setGeometry(0, arrows.top(), extra / 2, arrows.height());
540  } else {
541 #endif
542  rightB->setGeometry(arrows.left(), arrows.top(), extra/2, arrows.height());
543  leftB->setGeometry(arrows.right() - extra/2 + buttonOverlap, arrows.top(),
544  extra/2, arrows.height());
545 #ifndef QT_NO_STYLE_S60
546  }
547 #endif
550  }
551  } else {
552 #ifndef QT_NO_STYLE_S60
553  if (s60Style) {
554  QRect arrows = QRect(0, 0, size.width(), available );
555  leftB->setGeometry(arrows.left(), arrows.top(), arrows.width(), extra / 2);
557  rightB->setGeometry(arrows.left(), arrows.bottom() - extra / 2 + 1,
558  arrows.width(), extra / 2);
560  } else {
561 #endif
562  QRect arrows = QRect(0, available - extra, size.width(), extra );
563  leftB->setGeometry(arrows.left(), arrows.top(), arrows.width(), extra/2);
565  rightB->setGeometry(arrows.left(), arrows.bottom() - extra/2 + 1,
566  arrows.width(), extra/2);
568 #ifndef QT_NO_STYLE_S60
569  }
570 #endif
571  }
573  rightB->setEnabled(last - scrollOffset >= available - extra);
574  leftB->show();
575  rightB->show();
576  } else {
577  rightB->hide();
578  leftB->hide();
579  }
580 
581  layoutWidgets();
582  q->tabLayoutChange();
583 }
584 
586 {
587  Q_Q(QTabBar);
588  if (!validIndex(index) || leftB->isHidden())
589  return;
590 
591  const QRect tabRect = tabList.at(index).rect;
592  const int oldScrollOffset = scrollOffset;
593  const bool horiz = !verticalTabs(shape);
594  const int available = (horiz ? q->width() : q->height()) - extraWidth();
595  const int start = horiz ? tabRect.left() : tabRect.top();
596  const int end = horiz ? tabRect.right() : tabRect.bottom();
597  if (start < scrollOffset) // too far left
598  scrollOffset = start - (index ? 8 : 0);
599  else if (end > scrollOffset + available) // too far right
600  scrollOffset = end - available + 1;
601 
603  const int last = horiz ? tabList.last().rect.right() : tabList.last().rect.bottom();
604  rightB->setEnabled(last - scrollOffset >= available);
605  if (oldScrollOffset != scrollOffset) {
606  q->update();
607  layoutWidgets();
608  }
609 }
610 
612 {
613  Q_Q(QTabBar);
614  Q_ASSERT(index >= 0);
615 
616  Tab &tab = tabList[index];
617  bool vertical = verticalTabs(shape);
618  if (!(tab.leftWidget || tab.rightWidget))
619  return;
620 
621  QStyleOptionTabV3 opt;
622  q->initStyleOption(&opt, index);
623  if (tab.leftWidget) {
624  QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabLeftButton, &opt, q);
625  QPoint p = rect.topLeft();
626  if ((index == pressedIndex) || paintWithOffsets) {
627  if (vertical)
628  p.setY(p.y() + tabList[index].dragOffset);
629  else
630  p.setX(p.x() + tabList[index].dragOffset);
631  }
632  tab.leftWidget->move(p);
633  }
634  if (tab.rightWidget) {
635  QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabRightButton, &opt, q);
636  QPoint p = rect.topLeft();
637  if ((index == pressedIndex) || paintWithOffsets) {
638  if (vertical)
639  p.setY(p.y() + tab.dragOffset);
640  else
641  p.setX(p.x() + tab.dragOffset);
642  }
643  tab.rightWidget->move(p);
644  }
645 }
646 
648 {
649  Q_Q(QTabBar);
650  for (int i = start; i < q->count(); ++i) {
651  layoutTab(i);
652  }
653 }
654 
656 {
657  Q_Q(QTabBar);
658  QObject *object = q->sender();
659  int tabToClose = -1;
661  for (int i = 0; i < tabList.count(); ++i) {
662  if (closeSide == QTabBar::LeftSide) {
663  if (tabList.at(i).leftWidget == object) {
664  tabToClose = i;
665  break;
666  }
667  } else {
668  if (tabList.at(i).rightWidget == object) {
669  tabToClose = i;
670  break;
671  }
672  }
673  }
674  if (tabToClose != -1)
675  emit q->tabCloseRequested(tabToClose);
676 }
677 
679 {
680  Q_Q(QTabBar);
681  const QObject *sender = q->sender();
682  int i = -1;
683  if (!verticalTabs(shape)) {
684  if (sender == leftB) {
685  for (i = tabList.count() - 1; i >= 0; --i) {
686  if (tabList.at(i).rect.left() - scrollOffset < 0) {
687  makeVisible(i);
688  return;
689  }
690  }
691  } else if (sender == rightB) {
692  int availableWidth = q->width() - extraWidth();
693  for (i = 0; i < tabList.count(); ++i) {
694  if (tabList.at(i).rect.right() - scrollOffset > availableWidth) {
695  makeVisible(i);
696  return;
697  }
698  }
699  }
700  } else { // vertical
701  if (sender == leftB) {
702  for (i = tabList.count() - 1; i >= 0; --i) {
703  if (tabList.at(i).rect.top() - scrollOffset < 0) {
704  makeVisible(i);
705  return;
706  }
707  }
708  } else if (sender == rightB) {
709  int available = q->height() - extraWidth();
710  for (i = 0; i < tabList.count(); ++i) {
711  if (tabList.at(i).rect.bottom() - scrollOffset > available) {
712  makeVisible(i);
713  return;
714  }
715  }
716  }
717  }
718 }
719 
721 {
722  Q_Q(QTabBar);
723 
724  // be safe in case a subclass is also handling move with the tabs
725  if (pressedIndex != -1
726  && movable
729  if (!validIndex(pressedIndex))
730  pressedIndex = -1;
731  }
732 
733  if (!q->isVisible()) {
734  layoutDirty = true;
735  } else {
736  layoutTabs();
738  q->update();
739  q->updateGeometry();
740  }
741 }
742 
747  :QWidget(*new QTabBarPrivate, parent, 0)
748 {
749  Q_D(QTabBar);
750  d->init();
751 }
752 
753 
758 {
759 }
760 
773 {
774  Q_D(const QTabBar);
775  return d->shape;
776 }
777 
779 {
780  Q_D(QTabBar);
781  if (d->shape == shape)
782  return;
783  d->shape = shape;
784  d->refresh();
785 }
786 
801 {
802  Q_D(QTabBar);
803  if (d->drawBase == drawBase)
804  return;
805  d->drawBase = drawBase;
806  update();
807 }
808 
809 bool QTabBar::drawBase() const
810 {
811  Q_D(const QTabBar);
812  return d->drawBase;
813 }
814 
820 {
821  return insertTab(-1, text);
822 }
823 
833 int QTabBar::addTab(const QIcon& icon, const QString &text)
834 {
835  return insertTab(-1, icon, text);
836 }
837 
844 {
845  return insertTab(index, QIcon(), text);
846 }
847 
860 int QTabBar::insertTab(int index, const QIcon& icon, const QString &text)
861 {
862  Q_D(QTabBar);
863  if (!d->validIndex(index)) {
864  index = d->tabList.count();
865  d->tabList.append(QTabBarPrivate::Tab(icon, text));
866  } else {
867  d->tabList.insert(index, QTabBarPrivate::Tab(icon, text));
868  }
869 #ifndef QT_NO_SHORTCUT
870  d->tabList[index].shortcutId = grabShortcut(QKeySequence::mnemonic(text));
871 #endif
872  d->refresh();
873  if (d->tabList.count() == 1)
874  setCurrentIndex(index);
875  else if (index <= d->currentIndex)
876  ++d->currentIndex;
877 
878  if (d->closeButtonOnTabs) {
879  QStyleOptionTabV3 opt;
880  initStyleOption(&opt, index);
882  QAbstractButton *closeButton = new CloseButton(this);
883  connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab()));
884  setTabButton(index, closeSide, closeButton);
885  }
886 
887  for (int i = 0; i < d->tabList.count(); ++i) {
888  if (d->tabList[i].lastTab >= index)
889  ++d->tabList[i].lastTab;
890  }
891 
892  tabInserted(index);
893  return index;
894 }
895 
896 
903 {
904  Q_D(QTabBar);
905  if (d->validIndex(index)) {
906 #ifndef QT_NO_SHORTCUT
907  releaseShortcut(d->tabList.at(index).shortcutId);
908 #endif
909  if (d->tabList[index].leftWidget) {
910  d->tabList[index].leftWidget->hide();
911  d->tabList[index].leftWidget->deleteLater();
912  d->tabList[index].leftWidget = 0;
913  }
914  if (d->tabList[index].rightWidget) {
915  d->tabList[index].rightWidget->hide();
916  d->tabList[index].rightWidget->deleteLater();
917  d->tabList[index].rightWidget = 0;
918  }
919 
920  int newIndex = d->tabList[index].lastTab;
921  d->tabList.removeAt(index);
922  for (int i = 0; i < d->tabList.count(); ++i) {
923  if (d->tabList[i].lastTab == index)
924  d->tabList[i].lastTab = -1;
925  if (d->tabList[i].lastTab > index)
926  --d->tabList[i].lastTab;
927  }
928  if (index == d->currentIndex) {
929  // The current tab is going away, in order to make sure
930  // we emit that "current has changed", we need to reset this
931  // around.
932  d->currentIndex = -1;
933  if (d->tabList.size() > 0) {
934  switch(d->selectionBehaviorOnRemove) {
935  case SelectPreviousTab:
936  if (newIndex > index)
937  newIndex--;
938  if (d->validIndex(newIndex))
939  break;
940  // else fallthrough
941  case SelectRightTab:
942  newIndex = index;
943  if (newIndex >= d->tabList.size())
944  newIndex = d->tabList.size() - 1;
945  break;
946  case SelectLeftTab:
947  newIndex = index - 1;
948  if (newIndex < 0)
949  newIndex = 0;
950  break;
951  default:
952  break;
953  }
954 
955  if (d->validIndex(newIndex)) {
956  // don't loose newIndex's old through setCurrentIndex
957  int bump = d->tabList[newIndex].lastTab;
958  setCurrentIndex(newIndex);
959  d->tabList[newIndex].lastTab = bump;
960  }
961  } else {
962  emit currentChanged(-1);
963  }
964  } else if (index < d->currentIndex) {
965  setCurrentIndex(d->currentIndex - 1);
966  }
967  d->refresh();
968  tabRemoved(index);
969  }
970 }
971 
972 
978 {
979  Q_D(const QTabBar);
980  if (const QTabBarPrivate::Tab *tab = d->at(index))
981  return tab->enabled;
982  return false;
983 }
984 
990 {
991  Q_D(QTabBar);
992  if (QTabBarPrivate::Tab *tab = d->at(index)) {
993  tab->enabled = enabled;
994 #ifndef QT_NO_SHORTCUT
995  setShortcutEnabled(tab->shortcutId, enabled);
996 #endif
997  update();
998  if (!enabled && index == d->currentIndex)
999  setCurrentIndex(d->validIndex(index+1)?index+1:0);
1000  else if (enabled && !d->validIndex(d->currentIndex))
1001  setCurrentIndex(index);
1002  }
1003 }
1004 
1005 
1011 {
1012  Q_D(const QTabBar);
1013  if (const QTabBarPrivate::Tab *tab = d->at(index))
1014  return tab->text;
1015  return QString();
1016 }
1017 
1022 {
1023  Q_D(QTabBar);
1024  if (QTabBarPrivate::Tab *tab = d->at(index)) {
1025  tab->text = text;
1026 #ifndef QT_NO_SHORTCUT
1027  releaseShortcut(tab->shortcutId);
1028  tab->shortcutId = grabShortcut(QKeySequence::mnemonic(text));
1029  setShortcutEnabled(tab->shortcutId, tab->enabled);
1030 #endif
1031  d->refresh();
1032  }
1033 }
1034 
1042 {
1043  Q_D(const QTabBar);
1044  if (const QTabBarPrivate::Tab *tab = d->at(index))
1045  return tab->textColor;
1046  return QColor();
1047 }
1048 
1056 void QTabBar::setTabTextColor(int index, const QColor &color)
1057 {
1058  Q_D(QTabBar);
1059  if (QTabBarPrivate::Tab *tab = d->at(index)) {
1060  tab->textColor = color;
1061  update(tabRect(index));
1062  }
1063 }
1064 
1070 {
1071  Q_D(const QTabBar);
1072  if (const QTabBarPrivate::Tab *tab = d->at(index))
1073  return tab->icon;
1074  return QIcon();
1075 }
1076 
1080 void QTabBar::setTabIcon(int index, const QIcon & icon)
1081 {
1082  Q_D(QTabBar);
1083  if (QTabBarPrivate::Tab *tab = d->at(index)) {
1084  bool simpleIconChange = (!icon.isNull() && !tab->icon.isNull());
1085  tab->icon = icon;
1086  if (simpleIconChange)
1087  update(tabRect(index));
1088  else
1089  d->refresh();
1090  }
1091 }
1092 
1093 #ifndef QT_NO_TOOLTIP
1094 
1097 void QTabBar::setTabToolTip(int index, const QString & tip)
1098 {
1099  Q_D(QTabBar);
1100  if (QTabBarPrivate::Tab *tab = d->at(index))
1101  tab->toolTip = tip;
1102 }
1103 
1109 {
1110  Q_D(const QTabBar);
1111  if (const QTabBarPrivate::Tab *tab = d->at(index))
1112  return tab->toolTip;
1113  return QString();
1114 }
1115 #endif // QT_NO_TOOLTIP
1116 
1117 #ifndef QT_NO_WHATSTHIS
1118 
1128 {
1129  Q_D(QTabBar);
1130  if (QTabBarPrivate::Tab *tab = d->at(index))
1131  tab->whatsThis = text;
1132 }
1133 
1144 {
1145  Q_D(const QTabBar);
1146  if (const QTabBarPrivate::Tab *tab = d->at(index))
1147  return tab->whatsThis;
1148  return QString();
1149 }
1150 
1151 #endif // QT_NO_WHATSTHIS
1152 
1157 {
1158  Q_D(QTabBar);
1159  if (QTabBarPrivate::Tab *tab = d->at(index))
1160  tab->data = data;
1161 }
1162 
1168 {
1169  Q_D(const QTabBar);
1170  if (const QTabBarPrivate::Tab *tab = d->at(index))
1171  return tab->data;
1172  return QVariant();
1173 }
1174 
1180 {
1181  Q_D(const QTabBar);
1182  if (const QTabBarPrivate::Tab *tab = d->at(index)) {
1183  if (d->layoutDirty)
1184  const_cast<QTabBarPrivate*>(d)->layoutTabs();
1185  QRect r = tab->rect;
1186  if (verticalTabs(d->shape))
1187  r.translate(0, -d->scrollOffset);
1188  else
1189  r.translate(-d->scrollOffset, 0);
1190  if (!verticalTabs(d->shape))
1192  return r;
1193  }
1194  return QRect();
1195 }
1196 
1203 int QTabBar::tabAt(const QPoint &position) const
1204 {
1205  Q_D(const QTabBar);
1206  if (d->validIndex(d->currentIndex)
1207  && tabRect(d->currentIndex).contains(position)) {
1208  return d->currentIndex;
1209  }
1210  const int max = d->tabList.size();
1211  for (int i = 0; i < max; ++i) {
1212  if (tabRect(i).contains(position)) {
1213  return i;
1214  }
1215  }
1216  return -1;
1217 }
1218 
1229 int QTabBar::currentIndex() const
1230 {
1231  Q_D(const QTabBar);
1232  if (d->validIndex(d->currentIndex))
1233  return d->currentIndex;
1234  return -1;
1235 }
1236 
1237 
1239 {
1240  Q_D(QTabBar);
1241  if (d->dragInProgress && d->pressedIndex != -1)
1242  return;
1243 
1244  int oldIndex = d->currentIndex;
1245  if (d->validIndex(index) && d->currentIndex != index) {
1246  d->currentIndex = index;
1247  update();
1248  d->makeVisible(index);
1249  d->tabList[index].lastTab = oldIndex;
1250  if (oldIndex >= 0 && oldIndex < count())
1251  d->layoutTab(oldIndex);
1252  d->layoutTab(index);
1253 #ifndef QT_NO_ACCESSIBILITY
1254  if (QAccessible::isActive()) {
1256 
1259  }
1260 #endif
1261 #ifdef QT3_SUPPORT
1262  emit selected(index);
1263 #endif
1264  emit currentChanged(index);
1265  }
1266 }
1267 
1281 QSize QTabBar::iconSize() const
1282 {
1283  Q_D(const QTabBar);
1284  if (d->iconSize.isValid())
1285  return d->iconSize;
1286  int iconExtent = style()->pixelMetric(QStyle::PM_TabBarIconSize, 0, this);
1287  return QSize(iconExtent, iconExtent);
1288 
1289 }
1290 
1292 {
1293  Q_D(QTabBar);
1294  d->iconSize = size;
1295  d->layoutDirty = true;
1296  update();
1297  updateGeometry();
1298 }
1299 
1308 int QTabBar::count() const
1309 {
1310  Q_D(const QTabBar);
1311  return d->tabList.count();
1312 }
1313 
1314 
1318 {
1319  Q_D(const QTabBar);
1320  if (d->layoutDirty)
1321  const_cast<QTabBarPrivate*>(d)->layoutTabs();
1322  QRect r;
1323  for (int i = 0; i < d->tabList.count(); ++i)
1324  r = r.united(d->tabList.at(i).maxRect);
1326  return r.size().expandedTo(sz);
1327 }
1328 
1332 {
1333  Q_D(const QTabBar);
1334  if (d->layoutDirty)
1335  const_cast<QTabBarPrivate*>(d)->layoutTabs();
1336  if (!d->useScrollButtons) {
1337  QRect r;
1338  for (int i = 0; i < d->tabList.count(); ++i)
1339  r = r.united(d->tabList.at(i).minRect);
1341  }
1342  if (verticalTabs(d->shape))
1343  return QSize(sizeHint().width(), d->rightB->sizeHint().height() * 2 + 75);
1344  else
1345  return QSize(d->rightB->sizeHint().width() * 2 + 75, sizeHint().height());
1346 }
1347 
1348 // Compute the most-elided possible text, for minimumSizeHint
1350 {
1351  if (text.length() <= 3)
1352  return text;
1353 
1354  static const QLatin1String Ellipses("...");
1355  QString ret;
1356  switch (mode) {
1357  case Qt::ElideRight:
1358  ret = text.left(2) + Ellipses;
1359  break;
1360  case Qt::ElideMiddle:
1361  ret = text.left(1) + Ellipses + text.right(1);
1362  break;
1363  case Qt::ElideLeft:
1364  ret = Ellipses + text.right(2);
1365  break;
1366  case Qt::ElideNone:
1367  ret = text;
1368  break;
1369  }
1370  return ret;
1371 }
1372 
1374 {
1375  Q_Q(QTabBar);
1376  // ### Qt 5: make this a protected virtual function in QTabBar
1377  Tab &tab = tabList[index];
1378  QString oldText = tab.text;
1379  tab.text = computeElidedText(elideMode, oldText);
1380  QSize size = q->tabSizeHint(index);
1381  tab.text = oldText;
1382  return size;
1383 }
1384 
1389 {
1390  //Note: this must match with the computations in QCommonStylePrivate::tabLayout
1391  Q_D(const QTabBar);
1392  if (const QTabBarPrivate::Tab *tab = d->at(index)) {
1393  QStyleOptionTabV3 opt;
1394  initStyleOption(&opt, index);
1395  opt.text = d->tabList.at(index).text;
1396  QSize iconSize = tab->icon.isNull() ? QSize(0, 0) : opt.iconSize;
1397  int hframe = style()->pixelMetric(QStyle::PM_TabBarTabHSpace, &opt, this);
1398  int vframe = style()->pixelMetric(QStyle::PM_TabBarTabVSpace, &opt, this);
1399  const QFontMetrics fm = fontMetrics();
1400 
1401  int maxWidgetHeight = qMax(opt.leftButtonSize.height(), opt.rightButtonSize.height());
1402  int maxWidgetWidth = qMax(opt.leftButtonSize.width(), opt.rightButtonSize.width());
1403 
1404  int widgetWidth = 0;
1405  int widgetHeight = 0;
1406  int padding = 0;
1407  if (!opt.leftButtonSize.isEmpty()) {
1408  padding += 4;
1409  widgetWidth += opt.leftButtonSize.width();
1410  widgetHeight += opt.leftButtonSize.height();
1411  }
1412  if (!opt.rightButtonSize.isEmpty()) {
1413  padding += 4;
1414  widgetWidth += opt.rightButtonSize.width();
1415  widgetHeight += opt.rightButtonSize.height();
1416  }
1417  if (!opt.icon.isNull())
1418  padding += 4;
1419 
1420  QSize csz;
1421  if (verticalTabs(d->shape)) {
1422  csz = QSize( qMax(maxWidgetWidth, qMax(fm.height(), iconSize.height())) + vframe,
1423  fm.size(Qt::TextShowMnemonic, tab->text).width() + iconSize.width() + hframe + widgetHeight + padding);
1424  } else {
1425  csz = QSize(fm.size(Qt::TextShowMnemonic, tab->text).width() + iconSize.width() + hframe
1426  + widgetWidth + padding,
1427  qMax(maxWidgetHeight, qMax(fm.height(), iconSize.height())) + vframe);
1428  }
1429 
1430  QSize retSize = style()->sizeFromContents(QStyle::CT_TabBarTab, &opt, csz, this);
1431  return retSize;
1432  }
1433  return QSize();
1434 }
1435 
1443 {
1444  Q_UNUSED(index)
1445 }
1446 
1454 {
1455  Q_UNUSED(index)
1456 }
1457 
1464 {
1465 }
1466 
1467 
1471 {
1472  Q_D(QTabBar);
1473  if (d->layoutDirty)
1474  d->refresh();
1475  if (!d->validIndex(d->currentIndex))
1476  setCurrentIndex(0);
1477  d->updateMacBorderMetrics();
1478 }
1479 
1483 {
1484  Q_D(QTabBar);
1485  d->updateMacBorderMetrics();
1486 }
1487 
1491 {
1492  Q_D(QTabBar);
1493  if (event->type() == QEvent::HoverMove
1494  || event->type() == QEvent::HoverEnter) {
1495  QHoverEvent *he = static_cast<QHoverEvent *>(event);
1496  if (!d->hoverRect.contains(he->pos())) {
1497  QRect oldHoverRect = d->hoverRect;
1498  for (int i = 0; i < d->tabList.count(); ++i) {
1499  QRect area = tabRect(i);
1500  if (area.contains(he->pos())) {
1501  d->hoverRect = area;
1502  break;
1503  }
1504  }
1505  if (he->oldPos() != QPoint(-1, -1))
1506  update(oldHoverRect);
1507  update(d->hoverRect);
1508  }
1509  return true;
1510  } else if (event->type() == QEvent::HoverLeave ) {
1511  QRect oldHoverRect = d->hoverRect;
1512  d->hoverRect = QRect();
1513  update(oldHoverRect);
1514  return true;
1515 #ifndef QT_NO_TOOLTIP
1516  } else if (event->type() == QEvent::ToolTip) {
1517  if (const QTabBarPrivate::Tab *tab = d->at(tabAt(static_cast<QHelpEvent*>(event)->pos()))) {
1518  if (!tab->toolTip.isEmpty()) {
1519  QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tab->toolTip, this);
1520  return true;
1521  }
1522  }
1523 #endif // QT_NO_TOOLTIP
1524 #ifndef QT_NO_WHATSTHIS
1525  } else if (event->type() == QEvent::QueryWhatsThis) {
1526  const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos()));
1527  if (!tab || tab->whatsThis.isEmpty())
1528  event->ignore();
1529  return true;
1530  } else if (event->type() == QEvent::WhatsThis) {
1531  if (const QTabBarPrivate::Tab *tab = d->at(d->indexAtPos(static_cast<QHelpEvent*>(event)->pos()))) {
1532  if (!tab->whatsThis.isEmpty()) {
1533  QWhatsThis::showText(static_cast<QHelpEvent*>(event)->globalPos(),
1534  tab->whatsThis, this);
1535  return true;
1536  }
1537  }
1538 #endif // QT_NO_WHATSTHIS
1539 #ifndef QT_NO_SHORTCUT
1540  } else if (event->type() == QEvent::Shortcut) {
1541  QShortcutEvent *se = static_cast<QShortcutEvent *>(event);
1542  for (int i = 0; i < d->tabList.count(); ++i) {
1543  const QTabBarPrivate::Tab *tab = &d->tabList.at(i);
1544  if (tab->shortcutId == se->shortcutId()) {
1545  setCurrentIndex(i);
1546  return true;
1547  }
1548  }
1549 #endif
1550  }
1551  return QWidget::event(event);
1552 }
1553 
1557 {
1558  Q_D(QTabBar);
1559  if (d->layoutDirty)
1560  updateGeometry();
1561  d->layoutTabs();
1562 
1563  d->makeVisible(d->currentIndex);
1564 }
1565 
1569 {
1570  Q_D(QTabBar);
1571 
1572  QStyleOptionTabBarBaseV2 optTabBase;
1573  QTabBarPrivate::initStyleBaseOption(&optTabBase, this, size());
1574 
1575  QStylePainter p(this);
1576  int selected = -1;
1577  int cut = -1;
1578  bool rtl = optTabBase.direction == Qt::RightToLeft;
1579  bool vertical = verticalTabs(d->shape);
1580  QStyleOptionTab cutTab;
1581  selected = d->currentIndex;
1582  if (d->dragInProgress)
1583  selected = d->pressedIndex;
1584 
1585  for (int i = 0; i < d->tabList.count(); ++i)
1586  optTabBase.tabBarRect |= tabRect(i);
1587 
1588  optTabBase.selectedTabRect = tabRect(selected);
1589 
1590  if (d->drawBase)
1592 
1593  for (int i = 0; i < d->tabList.count(); ++i) {
1594  QStyleOptionTabV3 tab;
1595  initStyleOption(&tab, i);
1596  if (d->paintWithOffsets && d->tabList[i].dragOffset != 0) {
1597  if (vertical) {
1598  tab.rect.moveTop(tab.rect.y() + d->tabList[i].dragOffset);
1599  } else {
1600  tab.rect.moveLeft(tab.rect.x() + d->tabList[i].dragOffset);
1601  }
1602  }
1603  if (!(tab.state & QStyle::State_Enabled)) {
1605  }
1606  // If this tab is partially obscured, make a note of it so that we can pass the information
1607  // along when we draw the tear.
1608  if (((!vertical && (!rtl && tab.rect.left() < 0)) || (rtl && tab.rect.right() > width()))
1609  || (vertical && tab.rect.top() < 0)) {
1610  cut = i;
1611  cutTab = tab;
1612  }
1613  // Don't bother drawing a tab if the entire tab is outside of the visible tab bar.
1614  if ((!vertical && (tab.rect.right() < 0 || tab.rect.left() > width()))
1615  || (vertical && (tab.rect.bottom() < 0 || tab.rect.top() > height())))
1616  continue;
1617 
1618  optTabBase.tabBarRect |= tab.rect;
1619  if (i == selected)
1620  continue;
1621 
1623  }
1624 
1625  // Draw the selected tab last to get it "on top"
1626  if (selected >= 0) {
1627  QStyleOptionTabV3 tab;
1628  initStyleOption(&tab, selected);
1629  if (d->paintWithOffsets && d->tabList[selected].dragOffset != 0) {
1630  if (vertical)
1631  tab.rect.moveTop(tab.rect.y() + d->tabList[selected].dragOffset);
1632  else
1633  tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset);
1634  }
1635  if (!d->dragInProgress)
1637  else {
1638  int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0, this);
1639  d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0));
1640  }
1641  }
1642 
1643  // Only draw the tear indicator if necessary. Most of the time we don't need too.
1644  if (d->leftB->isVisible() && cut >= 0) {
1645  cutTab.rect = rect();
1646  cutTab.rect = style()->subElementRect(QStyle::SE_TabBarTearIndicator, &cutTab, this);
1648  }
1649 }
1650 
1651 /*
1652  Given that index at position from moved to position to where return where index goes.
1653  */
1654 int QTabBarPrivate::calculateNewPosition(int from, int to, int index) const
1655 {
1656  if (index == from)
1657  return to;
1658 
1659  int start = qMin(from, to);
1660  int end = qMax(from, to);
1661  if (index >= start && index <= end)
1662  index += (from < to) ? -1 : 1;
1663  return index;
1664 }
1665 
1672 void QTabBar::moveTab(int from, int to)
1673 {
1674  Q_D(QTabBar);
1675  if (from == to
1676  || !d->validIndex(from)
1677  || !d->validIndex(to))
1678  return;
1679 
1680  bool vertical = verticalTabs(d->shape);
1681  int oldPressedPosition = 0;
1682  if (d->pressedIndex != -1) {
1683  // Record the position of the pressed tab before reordering the tabs.
1684  oldPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.y()
1685  : d->tabList[d->pressedIndex].rect.x();
1686  }
1687 
1688  // Update the locations of the tabs first
1689  int start = qMin(from, to);
1690  int end = qMax(from, to);
1691  int width = vertical ? d->tabList[from].rect.height() : d->tabList[from].rect.width();
1692  if (from < to)
1693  width *= -1;
1694  bool rtl = isRightToLeft();
1695  for (int i = start; i <= end; ++i) {
1696  if (i == from)
1697  continue;
1698  if (vertical)
1699  d->tabList[i].rect.moveTop(d->tabList[i].rect.y() + width);
1700  else
1701  d->tabList[i].rect.moveLeft(d->tabList[i].rect.x() + width);
1702  int direction = -1;
1703  if (rtl && !vertical)
1704  direction *= -1;
1705  if (d->tabList[i].dragOffset != 0)
1706  d->tabList[i].dragOffset += (direction * width);
1707  }
1708 
1709  if (vertical) {
1710  if (from < to)
1711  d->tabList[from].rect.moveTop(d->tabList[to].rect.bottom() + 1);
1712  else
1713  d->tabList[from].rect.moveTop(d->tabList[to].rect.top() - width);
1714  } else {
1715  if (from < to)
1716  d->tabList[from].rect.moveLeft(d->tabList[to].rect.right() + 1);
1717  else
1718  d->tabList[from].rect.moveLeft(d->tabList[to].rect.left() - width);
1719  }
1720 
1721  // Move the actual data structures
1722  d->tabList.move(from, to);
1723 
1724  // update lastTab locations
1725  for (int i = 0; i < d->tabList.count(); ++i)
1726  d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab);
1727 
1728  // update external variables
1729  d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);
1730 
1731  // If we are in the middle of a drag update the dragStartPosition
1732  if (d->pressedIndex != -1) {
1733  d->pressedIndex = d->calculateNewPosition(from, to, d->pressedIndex);
1734  int newPressedPosition = vertical ? d->tabList[d->pressedIndex].rect.top() : d->tabList[d->pressedIndex].rect.left();
1735  int diff = oldPressedPosition - newPressedPosition;
1736  if (isRightToLeft() && !vertical)
1737  diff *= -1;
1738  if (vertical)
1739  d->dragStartPosition.setY(d->dragStartPosition.y() - diff);
1740  else
1741  d->dragStartPosition.setX(d->dragStartPosition.x() - diff);
1742  }
1743 
1744  d->layoutWidgets(start);
1745  update();
1746  emit tabMoved(from, to);
1748 }
1749 
1750 void QTabBarPrivate::slide(int from, int to)
1751 {
1752  Q_Q(QTabBar);
1753  if (from == to
1754  || !validIndex(from)
1755  || !validIndex(to))
1756  return;
1757  bool vertical = verticalTabs(shape);
1758  int preLocation = vertical ? q->tabRect(from).y() : q->tabRect(from).x();
1759  q->setUpdatesEnabled(false);
1760  q->moveTab(from, to);
1761  q->setUpdatesEnabled(true);
1762  int postLocation = vertical ? q->tabRect(to).y() : q->tabRect(to).x();
1763  int length = postLocation - preLocation;
1764  tabList[to].dragOffset -= length;
1765  tabList[to].startAnimation(this, ANIMATION_DURATION);
1766 }
1767 
1768 void QTabBarPrivate::moveTab(int index, int offset)
1769 {
1770  if (!validIndex(index))
1771  return;
1772  tabList[index].dragOffset = offset;
1773  layoutTab(index); // Make buttons follow tab
1774  q_func()->update();
1775 }
1776 
1780 {
1781  Q_D(QTabBar);
1782  if (event->button() != Qt::LeftButton) {
1783  event->ignore();
1784  return;
1785  }
1786  // Be safe!
1787  if (d->pressedIndex != -1 && d->movable)
1788  d->moveTabFinished(d->pressedIndex);
1789 
1790  d->pressedIndex = d->indexAtPos(event->pos());
1791 #ifdef Q_WS_MAC
1792  d->previousPressedIndex = d->pressedIndex;
1793 #endif
1794  if (d->validIndex(d->pressedIndex)) {
1795  QStyleOptionTabBarBaseV2 optTabBase;
1796  optTabBase.init(this);
1797  optTabBase.documentMode = d->documentMode;
1798  if (event->type() == style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this))
1799  setCurrentIndex(d->pressedIndex);
1800  else
1801  repaint(tabRect(d->pressedIndex));
1802  if (d->movable) {
1803  d->dragStartPosition = event->pos();
1804  }
1805  }
1806 }
1807 
1811 {
1812  Q_D(QTabBar);
1813  if (d->movable) {
1814  // Be safe!
1815  if (d->pressedIndex != -1
1816  && event->buttons() == Qt::NoButton)
1817  d->moveTabFinished(d->pressedIndex);
1818 
1819  // Start drag
1820  if (!d->dragInProgress && d->pressedIndex != -1) {
1821  if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {
1822  d->dragInProgress = true;
1823  d->setupMovableTab();
1824  }
1825  }
1826 
1827  int offset = (event->pos() - d->dragStartPosition).manhattanLength();
1828  if (event->buttons() == Qt::LeftButton
1829  && offset > QApplication::startDragDistance()
1830  && d->validIndex(d->pressedIndex)) {
1831  bool vertical = verticalTabs(d->shape);
1832  int dragDistance;
1833  if (vertical) {
1834  dragDistance = (event->pos().y() - d->dragStartPosition.y());
1835  } else {
1836  dragDistance = (event->pos().x() - d->dragStartPosition.x());
1837  }
1838  d->tabList[d->pressedIndex].dragOffset = dragDistance;
1839 
1840  QRect startingRect = tabRect(d->pressedIndex);
1841  if (vertical)
1842  startingRect.moveTop(startingRect.y() + dragDistance);
1843  else
1844  startingRect.moveLeft(startingRect.x() + dragDistance);
1845 
1846  int overIndex;
1847  if (dragDistance < 0)
1848  overIndex = tabAt(startingRect.topLeft());
1849  else
1850  overIndex = tabAt(startingRect.topRight());
1851 
1852  if (overIndex != d->pressedIndex && overIndex != -1) {
1853  int offset = 1;
1854  if (isRightToLeft() && !vertical)
1855  offset *= -1;
1856  if (dragDistance < 0) {
1857  dragDistance *= -1;
1858  offset *= -1;
1859  }
1860  for (int i = d->pressedIndex;
1861  offset > 0 ? i < overIndex : i > overIndex;
1862  i += offset) {
1863  QRect overIndexRect = tabRect(overIndex);
1864  int needsToBeOver = (vertical ? overIndexRect.height() : overIndexRect.width()) / 2;
1865  if (dragDistance > needsToBeOver)
1866  d->slide(i + offset, d->pressedIndex);
1867  }
1868  }
1869  // Buttons needs to follow the dragged tab
1870  d->layoutTab(d->pressedIndex);
1871 
1872  update();
1873  }
1874 #ifdef Q_WS_MAC
1875  } else if (!d->documentMode && event->buttons() == Qt::LeftButton && d->previousPressedIndex != -1) {
1876  int newPressedIndex = d->indexAtPos(event->pos());
1877  if (d->pressedIndex == -1 && d->previousPressedIndex == newPressedIndex) {
1878  d->pressedIndex = d->previousPressedIndex;
1879  update(tabRect(d->pressedIndex));
1880  } else if(d->pressedIndex != newPressedIndex) {
1881  d->pressedIndex = -1;
1882  update(tabRect(d->previousPressedIndex));
1883  }
1884 #endif
1885  }
1886 
1887  if (event->buttons() != Qt::LeftButton) {
1888  event->ignore();
1889  return;
1890  }
1891  QStyleOptionTabBarBaseV2 optTabBase;
1892  optTabBase.init(this);
1893  optTabBase.documentMode = d->documentMode;
1894 }
1895 
1897 {
1898  Q_Q(QTabBar);
1899  if (!movingTab)
1900  movingTab = new QWidget(q);
1901 
1902  int taboverlap = q->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0 ,q);
1903  QRect grabRect = q->tabRect(pressedIndex);
1904  grabRect.adjust(-taboverlap, 0, taboverlap, 0);
1905 
1906  QPixmap grabImage(grabRect.size());
1907  grabImage.fill(Qt::transparent);
1908  QStylePainter p(&grabImage, q);
1909  p.initFrom(q);
1910 
1911  QStyleOptionTabV3 tab;
1912  q->initStyleOption(&tab, pressedIndex);
1913  tab.rect.moveTopLeft(QPoint(taboverlap, 0));
1915  p.end();
1916 
1917  QPalette pal;
1918  pal.setBrush(QPalette::All, QPalette::Window, grabImage);
1919  movingTab->setPalette(pal);
1920  movingTab->setGeometry(grabRect);
1921  movingTab->setAutoFillBackground(true);
1922  movingTab->raise();
1923 
1924  // Re-arrange widget order to avoid overlaps
1925  if (tabList[pressedIndex].leftWidget)
1926  tabList[pressedIndex].leftWidget->raise();
1927  if (tabList[pressedIndex].rightWidget)
1928  tabList[pressedIndex].rightWidget->raise();
1929  if (leftB)
1930  leftB->raise();
1931  if (rightB)
1932  rightB->raise();
1933  movingTab->setVisible(true);
1934 }
1935 
1937 {
1938  Q_Q(QTabBar);
1939  bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index);
1940  bool allAnimationsFinished = true;
1941 #ifndef QT_NO_ANIMATION
1942  for(int i = 0; allAnimationsFinished && i < tabList.count(); ++i) {
1943  const Tab &t = tabList.at(i);
1945  allAnimationsFinished = false;
1946  }
1947 #endif //QT_NO_ANIMATION
1948  if (allAnimationsFinished && cleanup) {
1949  if(movingTab)
1950  movingTab->setVisible(false); // We might not get a mouse release
1951  for (int i = 0; i < tabList.count(); ++i) {
1952  tabList[i].dragOffset = 0;
1953  }
1954  if (pressedIndex != -1 && movable) {
1955  pressedIndex = -1;
1956  dragInProgress = false;
1957  dragStartPosition = QPoint();
1958  }
1959  layoutWidgets();
1960  } else {
1961  if (!validIndex(index))
1962  return;
1963  tabList[index].dragOffset = 0;
1964  }
1965  q->update();
1966 }
1967 
1971 {
1972  Q_D(QTabBar);
1973  if (event->button() != Qt::LeftButton) {
1974  event->ignore();
1975  return;
1976  }
1977 #ifdef Q_WS_MAC
1978  d->previousPressedIndex = -1;
1979 #endif
1980  if (d->movable && d->dragInProgress && d->validIndex(d->pressedIndex)) {
1981  int length = d->tabList[d->pressedIndex].dragOffset;
1982  int width = verticalTabs(d->shape)
1983  ? tabRect(d->pressedIndex).height()
1984  : tabRect(d->pressedIndex).width();
1985  int duration = qMin(ANIMATION_DURATION,
1986  (qAbs(length) * ANIMATION_DURATION) / width);
1987  d->tabList[d->pressedIndex].startAnimation(d, duration);
1988  d->dragInProgress = false;
1989  d->movingTab->setVisible(false);
1990  d->dragStartPosition = QPoint();
1991  }
1992 
1993  int i = d->indexAtPos(event->pos()) == d->pressedIndex ? d->pressedIndex : -1;
1994  d->pressedIndex = -1;
1995  QStyleOptionTabBarBaseV2 optTabBase;
1996  optTabBase.initFrom(this);
1997  optTabBase.documentMode = d->documentMode;
1999  setCurrentIndex(i);
2000 }
2001 
2005 {
2006  Q_D(QTabBar);
2007  if (event->key() != Qt::Key_Left && event->key() != Qt::Key_Right) {
2008  event->ignore();
2009  return;
2010  }
2011  int offset = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
2012  d->setCurrentNextEnabledIndex(offset);
2013 }
2014 
2017 #ifndef QT_NO_WHEELEVENT
2019 {
2020  Q_D(QTabBar);
2021  int offset = event->delta() > 0 ? -1 : 1;
2022  d->setCurrentNextEnabledIndex(offset);
2023  QWidget::wheelEvent(event);
2024 }
2025 #endif //QT_NO_WHEELEVENT
2026 
2028 {
2029  Q_Q(QTabBar);
2030  for (int index = currentIndex + offset; validIndex(index); index += offset) {
2031  if (tabList.at(index).enabled) {
2032  q->setCurrentIndex(index);
2033  break;
2034  }
2035  }
2036 }
2037 
2041 {
2042  Q_D(QTabBar);
2043  if (event->type() == QEvent::StyleChange) {
2044  if (!d->elideModeSetByUser)
2045  d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this));
2046  if (!d->useScrollButtonsSetByUser)
2047  d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this);
2048  d->refresh();
2049  } else if (event->type() == QEvent::FontChange) {
2050  d->refresh();
2051  }
2052  QWidget::changeEvent(event);
2053 }
2054 
2072 {
2073  Q_D(const QTabBar);
2074  return d->elideMode;
2075 }
2076 
2078 {
2079  Q_D(QTabBar);
2080  d->elideMode = mode;
2081  d->elideModeSetByUser = true;
2082  d->refresh();
2083 }
2084 
2101 bool QTabBar::usesScrollButtons() const
2102 {
2103  return d_func()->useScrollButtons;
2104 }
2105 
2106 void QTabBar::setUsesScrollButtons(bool useButtons)
2107 {
2108  Q_D(QTabBar);
2109  d->useScrollButtonsSetByUser = true;
2110  if (d->useScrollButtons == useButtons)
2111  return;
2112  d->useScrollButtons = useButtons;
2113  d->refresh();
2114 }
2115 
2152 bool QTabBar::tabsClosable() const
2153 {
2154  Q_D(const QTabBar);
2155  return d->closeButtonOnTabs;
2156 }
2157 
2158 void QTabBar::setTabsClosable(bool closable)
2159 {
2160  Q_D(QTabBar);
2161  if (d->closeButtonOnTabs == closable)
2162  return;
2163  d->closeButtonOnTabs = closable;
2165  if (!closable) {
2166  for (int i = 0; i < d->tabList.count(); ++i) {
2167  if (closeSide == LeftSide && d->tabList[i].leftWidget) {
2168  d->tabList[i].leftWidget->deleteLater();
2169  d->tabList[i].leftWidget = 0;
2170  }
2171  if (closeSide == RightSide && d->tabList[i].rightWidget) {
2172  d->tabList[i].rightWidget->deleteLater();
2173  d->tabList[i].rightWidget = 0;
2174  }
2175  }
2176  } else {
2177  bool newButtons = false;
2178  for (int i = 0; i < d->tabList.count(); ++i) {
2179  if (tabButton(i, closeSide))
2180  continue;
2181  newButtons = true;
2182  QAbstractButton *closeButton = new CloseButton(this);
2183  connect(closeButton, SIGNAL(clicked()), this, SLOT(_q_closeTab()));
2184  setTabButton(i, closeSide, closeButton);
2185  }
2186  if (newButtons)
2187  d->layoutTabs();
2188  }
2189  update();
2190 }
2191 
2241 {
2242  Q_D(const QTabBar);
2243  return d->selectionBehaviorOnRemove;
2244 }
2245 
2247 {
2248  Q_D(QTabBar);
2249  d->selectionBehaviorOnRemove = behavior;
2250 }
2251 
2265 bool QTabBar::expanding() const
2266 {
2267  Q_D(const QTabBar);
2268  return d->expanding;
2269 }
2270 
2272 {
2273  Q_D(QTabBar);
2274  if (d->expanding == enabled)
2275  return;
2276  d->expanding = enabled;
2277  d->layoutTabs();
2278 }
2279 
2294 {
2295  Q_D(const QTabBar);
2296  return d->movable;
2297 }
2298 
2300 {
2301  Q_D(QTabBar);
2302  d->movable = movable;
2303 }
2304 
2305 
2320 bool QTabBar::documentMode() const
2321 {
2322  return d_func()->documentMode;
2323 }
2324 
2326 {
2327  Q_D(QTabBar);
2328 
2329  d->documentMode = enabled;
2330  d->updateMacBorderMetrics();
2331 }
2332 
2347 {
2348  Q_D(QTabBar);
2349  if (index < 0 || index >= d->tabList.count())
2350  return;
2351  if (widget) {
2352  widget->setParent(this);
2353  // make sure our left and right widgets stay on top
2354  widget->lower();
2355  widget->show();
2356  }
2357  if (position == LeftSide) {
2358  if (d->tabList[index].leftWidget)
2359  d->tabList[index].leftWidget->hide();
2360  d->tabList[index].leftWidget = widget;
2361  } else {
2362  if (d->tabList[index].rightWidget)
2363  d->tabList[index].rightWidget->hide();
2364  d->tabList[index].rightWidget = widget;
2365  }
2366  d->layoutTabs();
2367  d->refresh();
2368  update();
2369 }
2370 
2376 {
2377  Q_D(const QTabBar);
2378  if (index < 0 || index >= d->tabList.count())
2379  return 0;
2380  if (position == LeftSide)
2381  return d->tabList.at(index).leftWidget;
2382  else
2383  return d->tabList.at(index).rightWidget;
2384 }
2385 
2387  : QAbstractButton(parent)
2388 {
2390 #ifndef QT_NO_CURSOR
2392 #endif
2393 #ifndef QT_NO_TOOLTIP
2394  setToolTip(tr("Close Tab"));
2395 #endif
2396  resize(sizeHint());
2397 }
2398 
2400 {
2401  ensurePolished();
2404  return QSize(width, height);
2405 }
2406 
2408 {
2409  if (isEnabled())
2410  update();
2412 }
2413 
2415 {
2416  if (isEnabled())
2417  update();
2419 }
2420 
2422 {
2423  QPainter p(this);
2424  QStyleOption opt;
2425  opt.init(this);
2427  if (isEnabled() && underMouse() && !isChecked() && !isDown())
2428  opt.state |= QStyle::State_Raised;
2429  if (isChecked())
2430  opt.state |= QStyle::State_On;
2431  if (isDown())
2432  opt.state |= QStyle::State_Sunken;
2433 
2434  if (const QTabBar *tb = qobject_cast<const QTabBar *>(parent())) {
2435  int index = tb->currentIndex();
2437  if (tb->tabButton(index, position) == this)
2439  }
2440 
2441  style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
2442 }
2443 
2445 
2446 #include "moc_qtabbar.cpp"
2447 
2448 #endif // QT_NO_TABBAR
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setDrawBase(bool drawTheBase)
Definition: qtabbar.cpp:800
void moveTab(int from, int to)
Moves the item at index position from to index position to.
Definition: qtabbar.cpp:1672
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QPoint pos() const
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void moveTab(int index, int offset)
em>Reimplemented Function
Definition: qtabbar.cpp:1768
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void showEvent(QShowEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1470
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void setupMovableTab()
Definition: qtabbar.cpp:1896
SelectionBehavior selectionBehaviorOnRemove() const
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
virtual void tabRemoved(int index)
This virtual handler is called after a tab was removed from position index.
Definition: qtabbar.cpp:1453
bool isChecked() const
bool validIndex(int index) const
Definition: qtabbar_p.h:165
bool event(QEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1490
void updateMacBorderMetrics()
Definition: qtabbar.cpp:85
void currentChanged(int index)
This signal is emitted when the tab bar&#39;s current tab changes.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
void _q_closeTab()
Definition: qtabbar.cpp:655
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void moveTabFinished(int index)
em>Reimplemented Function
Definition: qtabbar.cpp:1936
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
QSize size() const
QPointer< QWidget > widget
void drawControl(QStyle::ControlElement ce, const QStyleOption &opt)
Use the widget&#39;s style to draw a control element ce specified by QStyleOption option.
Definition: qstylepainter.h:87
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
The QStyleOptionTabV2 class is used to describe the parameters necessary for drawing a tabs in Qt 4...
Definition: qstyleoption.h:333
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QColor tabTextColor(int index) const
Returns the text color of the tab with the given index, or a invalid color if index is out of range...
Definition: qtabbar.cpp:1041
QToolButton * rightB
Definition: qtabbar_p.h:170
void mouseReleaseEvent(QMouseEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1970
QWidget * rightWidget
Definition: qtabbar_p.h:119
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
static QSize globalStrut()
QVariant tabData(int index) const
Returns the data of the tab at position index, or a null variant if index is out of range...
Definition: qtabbar.cpp:1167
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
bool isTabEnabled(int index) const
Returns true if the tab at position index is enabled; otherwise returns false.
Definition: qtabbar.cpp:977
QRect united(const QRect &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Definition: qrect.h:491
static QKeySequence mnemonic(const QString &text)
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics ...
State state() const
QSize minimumSizeHint() const
Definition: qtabbar.cpp:1331
The QHoverEvent class contains parameters that describe a mouse event.
Definition: qevent.h:125
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
ButtonPosition
This enum type lists the location of the widget on a tab.
Definition: qtabbar.h:89
#define SLOT(a)
Definition: qobjectdefs.h:226
TextElideMode
Definition: qnamespace.h:263
virtual void leaveEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qwidget.cpp:9491
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QTabBar(QWidget *parent=0)
Creates a new tab bar with the given parent.
Definition: qtabbar.cpp:746
bool isDown() const
void hideEvent(QHideEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1482
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
Definition: qevent.h:675
void setCurrentNextEnabledIndex(int offset)
em>Reimplemented Function
Definition: qtabbar.cpp:2027
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
void tabMoved(int from, int to)
This signal is emitted when the tab has moved the tab at index position from to index position to...
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void setCurrentIndex(int index)
Definition: qtabbar.cpp:1238
void init(const QWidget *w)
Use initFrom(widget) instead.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
TabPosition position
the position of the tab in the tab bar
Definition: qstyleoption.h:320
int indexAtPos(const QPoint &p) const
Definition: qtabbar.cpp:395
static QStyle * style()
Returns the application&#39;s style object.
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition: qwidget.h:996
bool tabsClosable() const
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
bool expanding() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
void mousePressEvent(QMouseEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1779
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
QSize sizeHint() const
em>Reimplemented Function
Definition: qtabbar.cpp:1317
void removeTab(int index)
Removes the tab at position index.
Definition: qtabbar.cpp:902
QWidget * tabButton(int index, ButtonPosition position) const
Returns the widget set a tab index and position or 0 if one is not set.
Definition: qtabbar.cpp:2375
#define Q_D(Class)
Definition: qglobal.h:2482
QSize sizeHint() const
Definition: qtabbar.cpp:2399
int height() const
int extraWidth() const
Definition: qtabbar.cpp:354
QTabBar::Shape shape
the tab shape used to draw the tab; by default QTabBar::RoundedNorth
Definition: qstyleoption.h:316
virtual void tabLayoutChange()
This virtual handler is called whenever the tab layout changes.
Definition: qtabbar.cpp:1463
QToolButton * leftB
Definition: qtabbar_p.h:171
void setTabText(int index, const QString &text)
Sets the text of the tab at position index to text.
Definition: qtabbar.cpp:1021
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt&#39;s shortcut system.
Definition: qwidget.cpp:11771
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setTabButton(int index, ButtonPosition position, QWidget *widget)
Sets widget on the tab index.
Definition: qtabbar.cpp:2346
bool drawBase() const
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
#define Q_Q(Class)
Definition: qglobal.h:2483
void setAutoRepeat(bool)
virtual void tabInserted(int index)
This virtual handler is called after a new tab was added or inserted at position index.
Definition: qtabbar.cpp:1442
QRect tabBarRect
the rectangle containing all the tabs
Definition: qstyleoption.h:225
void paintEvent(QPaintEvent *event)
Reimplemented Function
Definition: qtabbar.cpp:2421
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
bool useScrollButtons
Definition: qtabbar_p.h:190
const QPoint & oldPos() const
Returns the previous position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:132
bool layoutDirty
Definition: qtabbar_p.h:89
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool event(QEvent *e)
Reimplemented Function
QTabBar::Shape shape
Definition: qtabbar_p.h:88
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
bool paintWithOffsets
Definition: qtabbar_p.h:198
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void leaveEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qtabbar.cpp:2414
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition: qtabbar.h:81
void lower()
Lowers the widget to the bottom of the parent widget&#39;s stack.
Definition: qwidget.cpp:11939
bool documentMode
whether the tabbar is in document mode.
Definition: qstyleoption.h:239
void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
Use the widget&#39;s style to draw a primitive element pe specified by QStyleOption option.
Definition: qstylepainter.h:82
void setTabToolTip(int index, const QString &tip)
Sets the tool tip of the tab at position index to tip.
Definition: qtabbar.cpp:1097
void setTabsClosable(bool closable)
Definition: qtabbar.cpp:2158
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
WindowRef OSWindowRef
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of text.
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define ANIMATION_DURATION
Definition: qtabbar_p.h:66
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
void setExpanding(bool enabled)
Definition: qtabbar.cpp:2271
int width() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
bool isMovable() const
Definition: qtabbar.cpp:2293
int insertTab(int index, const QString &text)
Inserts a new tab with text text at position index.
Definition: qtabbar.cpp:843
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setDocumentMode(bool set)
Definition: qtabbar.cpp:2325
LayoutDirection
Definition: qnamespace.h:1580
void setShape(Shape shape)
Definition: qtabbar.cpp:778
QWidgetData * data
Definition: qwidget.h:815
void setElideMode(Qt::TextElideMode)
Definition: qtabbar.cpp:2077
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
const char * styleHint(const QFontDef &request)
QTabBarPrivate::Tab::TabBarAnimation * animation
static Bigint * diff(Bigint *a, Bigint *b)
void setTabTextColor(int index, const QColor &color)
Sets the color of the text in the tab with the given index to the specified color.
Definition: qtabbar.cpp:1056
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QList< Tab > tabList
Definition: qtabbar_p.h:153
void slide(int from, int to)
Definition: qtabbar.cpp:1750
void wheelEvent(QWheelEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive wheel events for t...
Definition: qtabbar.cpp:2018
int row
which row the tab is currently in
Definition: qstyleoption.h:319
int calculateNewPosition(int from, int to, int index) const
Definition: qtabbar.cpp:1654
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
void setShortcutEnabled(int id, bool enable=true)
If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled...
Definition: qwidget.cpp:11790
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
void setTabWhatsThis(int index, const QString &text)
Sets the What&#39;s This help text of the tab at position index to text.
Definition: qtabbar.cpp:1127
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
static int startDragDistance()
QSize minimumTabSizeHint(int index)
Definition: qtabbar.cpp:1373
bool documentMode() const
void show()
Shows the widget and its child widgets.
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void setTabEnabled(int index, bool)
If enabled is true then the tab at position index is enabled; otherwise the item at position index is...
Definition: qtabbar.cpp:989
CornerWidgets cornerWidgets
an OR combination of CornerWidget values indicating the corner widgets of the tab bar ...
Definition: qstyleoption.h:322
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
QRect rect() const
void setEnabled(bool)
Definition: qwidget.cpp:3447
void refresh()
Definition: qtabbar.cpp:720
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
void layoutTabs()
Definition: qtabbar.cpp:406
void setMovable(bool movable)
Definition: qtabbar.cpp:2299
bool isEnabled() const
Definition: qwidget.h:948
void hide()
Hides the widget.
Definition: qwidget.h:501
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
QSize rightButtonSize
the size for the right widget on the tab.
Definition: qstyleoption.h:353
static QWidget * parentWidget(const QWidget *w)
void setArrowType(Qt::ArrowType type)
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
void setToolTip(const QString &)
Definition: qwidget.cpp:11600
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
SelectionBehavior
This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also ...
Definition: qtabbar.h:94
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
Definition: qwidget.cpp:10761
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
Adds a shortcut to Qt&#39;s shortcut system that watches for the given key sequence in the given context...
Definition: qwidget.cpp:11747
The QStyleOptionTabBarBaseV2 class is used to describe the base of a tab bar, i.e.
Definition: qstyleoption.h:235
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qtabbar.cpp:1810
int pressedIndex
Definition: qtabbar_p.h:87
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
void setTabData(int index, const QVariant &data)
Sets the data of the tab at position index to data.
Definition: qtabbar.cpp:1156
QString text
the text of the tab
Definition: qstyleoption.h:317
int shortcutId()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qevent.h:683
SelectedPosition selectedPosition
the position of the selected tab in relation to this tab
Definition: qstyleoption.h:321
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:131
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
virtual void wheelEvent(QWheelEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive wheel events for t...
Definition: qwidget.cpp:9326
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
Qt::LayoutDirection layoutDirection() const
QString tabText(int index) const
Returns the text of the tab at position index, or an empty string if index is out of range...
Definition: qtabbar.cpp:1010
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qtabbar.cpp:1568
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qtabbar.cpp:2040
QSize iconSize() const
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
Tab * at(int index)
Definition: qtabbar.cpp:385
void enterEvent(QEvent *event)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qtabbar.cpp:2407
QString tabToolTip(int index) const
Returns the tool tip of the tab at position index, or an empty string if index is out of range...
Definition: qtabbar.cpp:1108
void keyPressEvent(QKeyEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:2004
static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
Definition: qtabbar_p.h:208
bool documentMode
Definition: qtabbar_p.h:201
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QRect selectedTabRect
the rectangle containing the selected tab
Definition: qstyleoption.h:226
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool movable
This property holds whether the user can move the tabs within the tabbar area.
Definition: qtabbar.h:74
void initStyleOption(QStyleOptionTab *option, int tabIndex) const
Initialize option with the values from the tab at tabIndex.
Definition: qtabbar.cpp:130
static QString computeElidedText(Qt::TextElideMode mode, const QString &text)
Definition: qtabbar.cpp:1349
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
int count() const
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
QSize iconSize
the size for the icons
Definition: qstyleoption.h:337
The QStyleOptionTabV3 class is used to describe the parameters necessary for drawing a tabs in Qt 4...
Definition: qstyleoption.h:347
int height() const
Returns the height.
Definition: qsize.h:129
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
static void cleanup()
Definition: qpicture.cpp:1508
void setSelectionBehaviorOnRemove(SelectionBehavior behavior)
Definition: qtabbar.cpp:2246
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int currentIndex
Definition: qtabbar_p.h:86
void layoutWidgets(int start=0)
Definition: qtabbar.cpp:647
QWExtra * extra
Definition: qwidget_p.h:700
Qt::TextElideMode elideMode
Definition: qtabbar_p.h:188
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
QRect tabRect(int index) const
Returns the visual rectangle of the tab at position index, or a null rectangle if index is out of ran...
Definition: qtabbar.cpp:1179
quint16 index
void initFrom(const QWidget *widget)
Initializes the painters pen, background and font to the same as the given widget.
Definition: qpainter.cpp:1558
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
The QStyleOptionTab class is used to describe the parameters for drawing a tab bar.
Definition: qstyleoption.h:304
QIcon icon
the icon for the tab
Definition: qstyleoption.h:318
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
QSize iconSize
Definition: qtabbar_p.h:187
void _q_scrollTabs()
Definition: qtabbar.cpp:678
virtual QSize tabSizeHint(int index) const
Returns the size hint for the tab at position index.
Definition: qtabbar.cpp:1388
int tabAt(const QPoint &pos) const
Definition: qtabbar.cpp:1203
void layoutTab(int index)
Definition: qtabbar.cpp:611
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setTabIcon(int index, const QIcon &icon)
Sets the icon of the tab at position index to icon.
Definition: qtabbar.cpp:1080
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
void setUsesScrollButtons(bool useButtons)
Definition: qtabbar.cpp:2106
bool isRightToLeft() const
Definition: qwidget.h:428
The QTabWidget class provides a stack of tabbed widgets.
Definition: qtabwidget.h:60
Shape shape() const
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
Qt::TextElideMode elideMode() const
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
QSize leftButtonSize
the size for the left widget on the tab.
Definition: qstyleoption.h:352
int height() const
Returns the height of the font.
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
QWidget * leftWidget
Definition: qtabbar_p.h:118
int currentIndex() const
void setIconSize(const QSize &size)
Definition: qtabbar.cpp:1291
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
void resizeEvent(QResizeEvent *)
em>Reimplemented Function
Definition: qtabbar.cpp:1556
int addTab(const QString &text)
Adds a new tab with text text.
Definition: qtabbar.cpp:819
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
~QTabBar()
Destroys the tab bar.
Definition: qtabbar.cpp:757
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
bool usesScrollButtons() const
virtual void enterEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qwidget.cpp:9475
int scrollOffset
Definition: qtabbar_p.h:91
bool end()
Ends painting.
Definition: qpainter.cpp:1929
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
#define text
Definition: qobjectdefs.h:80
static bool verticalTabs(QTabBar::Shape shape)
Definition: qtabbar.cpp:77
QString tabWhatsThis(int index) const
Returns the What&#39;s This help text of the tab at position index, or an empty string if index is out of...
Definition: qtabbar.cpp:1143
CloseButton(QWidget *parent=0)
Definition: qtabbar.cpp:2386
void makeVisible(int index)
Definition: qtabbar.cpp:585
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
void qt_mac_updateContentBorderMetricts(void *window, const ::HIContentBorderMetrics &metrics)
static int area(const QSize &s)
Definition: qicon.cpp:155
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
Qt::LayoutDirection direction
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
QIcon tabIcon(int index) const
Returns the icon of the tab at position index, or a null icon if index is out of range.
Definition: qtabbar.cpp:1069
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60