KDELibs4Support

ktabwidget.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Stephan Binner <[email protected]>
3  Copyright (C) 2003 Zack Rusin <[email protected]>
4  Copyright (C) 2009 Urs Wolfer <uwolfer @ kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "ktabwidget.h"
23 
24 #include <QApplication>
25 #include <QDragMoveEvent>
26 #include <QDropEvent>
27 #include <QMouseEvent>
28 #include <QStyle>
29 #include <QStyleOption>
30 #include <QTextDocument>
31 #include <QWheelEvent>
32 #include <QList>
33 
34 #include <ksharedconfig.h>
35 #include <kiconloader.h>
36 #include <kstringhandler.h>
37 #include <kdebug.h>
38 
39 #include <ktabbar.h>
40 
41 #include <kconfiggroup.h>
42 
43 class Q_DECL_HIDDEN KTabWidget::Private
44 {
45 public:
46  enum {
47  ResizeEnabled = 0,
48  ResizeDisabled,
49  ResizeLater
50  } m_resizeSuspend;
51 
52  Private(KTabWidget *parent)
53  : m_resizeSuspend(ResizeEnabled),
54  m_parent(parent),
55  m_automaticResizeTabs(false),
56  m_tabBarHidden(false)
57  {
58 
59  KConfigGroup cg(KSharedConfig::openConfig(), "General");
60  m_maxLength = cg.readEntry("MaximumTabLength", 30);
61  m_minLength = cg.readEntry("MinimumTabLength", 3);
62  Q_ASSERT(m_maxLength >= m_minLength);
63  m_currentTabLength = m_minLength;
64  }
65 
66  KTabWidget *m_parent;
67  bool m_automaticResizeTabs;
68  bool m_tabBarHidden;
69  int m_maxLength;
70  int m_minLength;
71  int m_currentTabLength;
72 
73  //holds the full names of the tab, otherwise all we
74  //know about is the shortened name
75  QStringList m_tabNames;
76 
77  bool isEmptyTabbarSpace(const QPoint &) const;
78  void resizeTabs(int changedTabIndex = -1);
79  void updateTab(int index);
80  void removeTab(int index);
81 
82  void slotTabMoved(int from, int to);
83 };
84 
85 bool KTabWidget::Private::isEmptyTabbarSpace(const QPoint &point) const
86 {
87  if (m_parent->count() == 0) {
88  return true;
89  }
90  if (m_parent->tabBar()->isHidden()) {
91  return false;
92  }
93  QSize size(m_parent->tabBar()->sizeHint());
94  if ((m_parent->tabPosition() == QTabWidget::North && point.y() < size.height()) ||
95  (m_parent->tabPosition() == QTabWidget::South && point.y() > (m_parent->height() - size.height()))) {
96 
97  QWidget *rightcorner = m_parent->cornerWidget(Qt::TopRightCorner);
98  if (rightcorner && rightcorner->isVisible()) {
99  if (point.x() >= m_parent->width() - rightcorner->width()) {
100  return false;
101  }
102  }
103 
104  QWidget *leftcorner = m_parent->cornerWidget(Qt::TopLeftCorner);
105  if (leftcorner && leftcorner->isVisible()) {
106  if (point.x() <= leftcorner->width()) {
107  return false;
108  }
109  }
110 
111  for (int i = 0; i < m_parent->count(); ++i)
112  if (m_parent->tabBar()->tabRect(i).contains(m_parent->tabBar()->mapFromParent(point))) {
113  return false;
114  }
115 
116  return true;
117  }
118 
119  return false;
120 }
121 
122 void KTabWidget::Private::removeTab(int index)
123 {
124  // prevent cascading resize slowness, not to mention crashes due to tab count()
125  // and m_tabNames.count() being out of sync!
126  m_resizeSuspend = ResizeDisabled;
127 
128  // Need to do this here, rather than in tabRemoved(). Calling
129  // QTabWidget::removeTab() below may cause a relayout of the tab bar, which
130  // will call resizeTabs() immediately. If m_automaticResizeTabs is true,
131  // that will use the m_tabNames[] list before it has been updated to reflect
132  // the new tab arrangement. See bug 190528.
133  m_tabNames.removeAt(index);
134 
135  m_parent->QTabWidget::removeTab(index);
136 
137  const bool doResize = (m_resizeSuspend == ResizeLater) || m_automaticResizeTabs;
138  m_resizeSuspend = ResizeEnabled;
139  if (doResize) {
140  resizeTabs();
141  }
142 
143 }
144 
145 void KTabWidget::Private::resizeTabs(int changeTabIndex)
146 {
147  if (m_resizeSuspend != ResizeEnabled) {
148  m_resizeSuspend = ResizeLater;
149  return;
150  }
151 
152  int newTabLength = m_maxLength;
153 
154  if (m_automaticResizeTabs) {
155  // Calculate new max length
156  int lcw = 0, rcw = 0;
157 
158  const int tabBarHeight = m_parent->tabBar()->sizeHint().height();
159  if (m_parent->cornerWidget(Qt::TopLeftCorner) &&
160  m_parent->cornerWidget(Qt::TopLeftCorner)->isVisible()) {
161  lcw = qMax(m_parent->cornerWidget(Qt::TopLeftCorner)->width(), tabBarHeight);
162  }
163  if (m_parent->cornerWidget(Qt::TopRightCorner) &&
164  m_parent->cornerWidget(Qt::TopRightCorner)->isVisible()) {
165  rcw = qMax(m_parent->cornerWidget(Qt::TopRightCorner)->width(), tabBarHeight);
166  }
167 
168  const int maxTabBarWidth = m_parent->width() - lcw - rcw;
169 
170  // binary search for the best fitting tab title length; some wiggling was
171  // required to make this behave in the face of rounding.
172  int newTabLengthHi = m_maxLength + 1;
173  int newTabLengthLo = m_minLength;
174  int prevTabLengthMid = -1;
175  while (true) {
176  int newTabLengthMid = (newTabLengthHi + newTabLengthLo) / 2;
177  if (prevTabLengthMid == newTabLengthMid) {
178  // no change, we're stuck due to rounding.
179  break;
180  }
181  prevTabLengthMid = newTabLengthMid;
182 
183  if (m_parent->tabBarWidthForMaxChars(newTabLengthMid) > maxTabBarWidth) {
184  newTabLengthHi = newTabLengthMid;
185  } else {
186  newTabLengthLo = newTabLengthMid;
187  }
188  }
189  newTabLength = qMin(newTabLengthLo, m_maxLength);
190  }
191 
192  // Update hinted or all tabs
193  if (m_currentTabLength != newTabLength) {
194  m_currentTabLength = newTabLength;
195  for (int i = 0; i < m_parent->count(); i++) {
196  updateTab(i);
197  }
198  } else if (changeTabIndex != -1) {
199  updateTab(changeTabIndex);
200  }
201 }
202 
203 void KTabWidget::Private::updateTab(int index)
204 {
205  QString title = m_automaticResizeTabs ? m_tabNames[ index ] : m_parent->QTabWidget::tabText(index);
206  m_parent->setTabToolTip(index, QString());
207 
208  if (title.length() > m_currentTabLength) {
209  QString toolTipText = title;
210  // Remove '&'s, which are indicators for keyboard shortcuts in tab titles. "&&" is replaced by '&'.
211  for (int i = toolTipText.indexOf('&'); i >= 0 && i < toolTipText.length(); i = toolTipText.indexOf('&', i + 1)) {
212  toolTipText.remove(i, 1);
213  }
214 
215  if (Qt::mightBeRichText(toolTipText)) {
216  m_parent->setTabToolTip(index, toolTipText.toHtmlEscaped());
217  } else {
218  m_parent->setTabToolTip(index, toolTipText);
219  }
220  }
221 
222  title = KStringHandler::rsqueeze(title, m_currentTabLength).leftJustified(m_minLength, ' ');
223 
224  if (m_parent->QTabWidget::tabText(index) != title) {
225  m_parent->QTabWidget::setTabText(index, title);
226  }
227 }
228 
229 void KTabWidget::Private::slotTabMoved(int from, int to)
230 {
231  /* called from Qt slot when Qt has moved the tab, so we only
232  need to adjust the m_tabNames list */
233  if (m_automaticResizeTabs) {
234  QString movedName = m_tabNames.takeAt(from);
235  m_tabNames.insert(to, movedName);
236  }
237 }
238 
240  : QTabWidget(parent),
241  d(new Private(this))
242 {
243  setWindowFlags(flags);
244  setTabBar(new KTabBar(this));
245  setObjectName("tabbar");
246  setAcceptDrops(true);
247 
248  connect(tabBar(), SIGNAL(contextMenu(int,QPoint)), SLOT(contextMenu(int,QPoint)));
249  connect(tabBar(), SIGNAL(tabDoubleClicked(int)), SLOT(mouseDoubleClick(int)));
250  connect(tabBar(), SIGNAL(newTabRequest()), this, SIGNAL(mouseDoubleClick())); // #185487
251  connect(tabBar(), SIGNAL(mouseMiddleClick(int)), SLOT(mouseMiddleClick(int)));
252  connect(tabBar(), SIGNAL(initiateDrag(int)), SLOT(initiateDrag(int)));
253  connect(tabBar(), SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)), SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)));
255  connect(tabBar(), SIGNAL(moveTab(int,int)), SLOT(moveTab(int,int)));
256  connect(tabBar(), SIGNAL(tabMoved(int,int)), SLOT(slotTabMoved(int,int)));
257  connect(tabBar(), SIGNAL(tabCloseRequested(int)), SLOT(closeRequest(int)));
258 }
259 
261 {
262  delete d;
263 }
264 
265 /*void KTabWidget::insertTab( QWidget *child, const QString &label, int index )
266 {
267  QTabWidget::insertTab( child, label, index );
268 }
269 
270 void KTabWidget::insertTab( QWidget *child, const QIcon& iconset, const QString &label, int index )
271 {
272  QTabWidget::insertTab( child, iconset, label, index );
273 }
274 
275 void KTabWidget::insertTab( QWidget *child, QTab *tab, int index )
276 {
277  QTabWidget::insertTab( child, tab, index);
278  if ( d->m_automaticResizeTabs ) {
279  if ( index < 0 || index >= count() ) {
280  d->m_tabNames.append( tab->text() );
281  d->resizeTabs( d->m_tabNames.count()-1 );
282  }
283  else {
284  d->m_tabNames.insert( d->m_tabNames.at( index ), tab->text() );
285  d->resizeTabs( index );
286  }
287  }
288 }*/
289 
291 {
292  if (hide == isTabBarHidden()) {
293  return;
294  }
295 
296  QWidget *rightcorner = cornerWidget(Qt::TopRightCorner);
297  QWidget *leftcorner = cornerWidget(Qt::TopLeftCorner);
298 
299  d->m_tabBarHidden = hide;
300  if (hide) {
301  if (leftcorner) {
302  leftcorner->hide();
303  }
304  if (rightcorner) {
305  rightcorner->hide();
306  }
307  tabBar()->hide();
308  } else {
309  tabBar()->show();
310  if (leftcorner) {
311  leftcorner->show();
312  }
313  if (rightcorner) {
314  rightcorner->show();
315  }
316  }
317 }
318 
320 {
321  return d->m_tabBarHidden;
322 }
323 
324 void KTabWidget::setTabTextColor(int index, const QColor &color)
325 {
326  tabBar()->setTabTextColor(index, color);
327 }
328 
330 {
331  return tabBar()->tabTextColor(index);
332 }
333 
334 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
336 {
337  static_cast<KTabBar *>(tabBar())->setTabReorderingEnabled(on);
338 }
339 #endif
340 
341 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
343 {
344  return static_cast<KTabBar *>(tabBar())->isTabReorderingEnabled();
345 }
346 #endif
347 
348 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
350 {
351  static_cast<KTabBar *>(tabBar())->setTabCloseActivatePrevious(previous);
352 }
353 #endif
354 
355 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
357 {
358  return static_cast<KTabBar *>(tabBar())->tabCloseActivatePrevious();
359 }
360 #endif
361 
362 int KTabWidget::tabBarWidthForMaxChars(int maxLength)
363 {
364  const int hframe = tabBar()->style()->pixelMetric(QStyle::PM_TabBarTabHSpace, nullptr, tabBar());
365 
366  const QFontMetrics fm = tabBar()->fontMetrics();
367  int x = 0;
368  for (int i = 0; i < count(); ++i) {
369  QString newTitle = d->m_tabNames.value(i);
370  newTitle = KStringHandler::rsqueeze(newTitle, maxLength).leftJustified(d->m_minLength, ' ');
371 
372  int lw = fm.width(newTitle);
373  int iw = 0;
374  if (!tabBar()->tabIcon(i).isNull()) {
375  iw = tabBar()->tabIcon(i).pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize), QIcon::Normal).width() + 4;
376  }
377 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
378  if (isCloseButtonEnabled()) {
379  // FIXME: how to get the size of the close button directly from the tabBar()?
380  iw += KIconLoader::SizeSmall * 3 / 2;
381  }
382 #endif
383  x += (tabBar()->style()->sizeFromContents(QStyle::CT_TabBarTab, nullptr,
384  QSize(qMax(lw + hframe + iw, QApplication::globalStrut().width()), 0),
385  this)).width();
386  }
387 
388  return x;
389 }
390 
391 QString KTabWidget::tabText(int index) const
392 {
393  if (d->m_automaticResizeTabs) {
394  if (index >= 0 && index < count()) {
395  if (index >= d->m_tabNames.count()) {
396  // Ooops, the tab exists, but tabInserted wasn't called yet.
397  // This can happen when inserting the first tab,
398  // and calling tabText from slotCurrentChanged,
399  // see KTabWidget_UnitTest.
400  const_cast<KTabWidget *>(this)->tabInserted(index);
401  }
402  return d->m_tabNames[ index ];
403  } else {
404  return QString();
405  }
406  } else {
407  return QTabWidget::tabText(index);
408  }
409 }
410 
411 void KTabWidget::setTabText(int index, const QString &text)
412 {
413  if (text == tabText(index)) {
414  return;
415  }
416 
417  if (d->m_automaticResizeTabs) {
418 
419  tabBar()->setUpdatesEnabled(false); //no flicker
420 
421  QTabWidget::setTabText(index, text);
422 
423  if (index != -1) {
424  if (index >= d->m_tabNames.count()) {
425  kWarning(240) << "setTabText(" << index << ") called but d->m_tabNames has only" << d->m_tabNames.count() << "entries";
426  while (index >= d->m_tabNames.count()) {
427  d->m_tabNames.append(QString());
428  }
429  }
430  d->m_tabNames[ index ] = text;
431  d->resizeTabs(index);
432  }
433 
434  tabBar()->setUpdatesEnabled(true);
435 
436  } else {
437  QTabWidget::setTabText(index, text);
438  }
439 }
440 
441 void KTabWidget::dragEnterEvent(QDragEnterEvent *event)
442 {
443  if (d->isEmptyTabbarSpace(event->pos())) {
444  bool accept = false;
445  // The receivers of the testCanDecode() signal has to adjust
446  // 'accept' accordingly.
447  emit testCanDecode(event, accept);
448 
449  event->setAccepted(accept);
450  return;
451  }
452 
454 }
455 
456 void KTabWidget::dragMoveEvent(QDragMoveEvent *event)
457 {
458  if (d->isEmptyTabbarSpace(event->pos())) {
459  bool accept = false;
460  // The receivers of the testCanDecode() signal has to adjust
461  // 'accept' accordingly.
462  emit testCanDecode(event, accept);
463 
464  event->setAccepted(accept);
465  return;
466  }
467 
469 }
470 
471 void KTabWidget::dropEvent(QDropEvent *event)
472 {
473  if (d->isEmptyTabbarSpace(event->pos())) {
474  emit(receivedDropEvent(event));
475  return;
476  }
477 
478  QTabWidget::dropEvent(event);
479 }
480 
481 #ifndef QT_NO_WHEELEVENT
482 void KTabWidget::wheelEvent(QWheelEvent *event)
483 {
484  if (d->isEmptyTabbarSpace(event->pos())) {
486  } else {
487  QTabWidget::wheelEvent(event);
488  }
489 }
490 
491 void KTabWidget::wheelDelta(int delta)
492 {
493  if (count() < 2) {
494  return;
495  }
496 
497  int page = currentIndex();
498  if (delta < 0) {
499  page = (page + 1) % count();
500  } else {
501  page--;
502  if (page < 0) {
503  page = count() - 1;
504  }
505  }
506  setCurrentIndex(page);
507 }
508 #endif
509 
510 void KTabWidget::mouseDoubleClickEvent(QMouseEvent *event)
511 {
512  if (event->button() != Qt::LeftButton) {
513  return;
514  }
515 
516  if (d->isEmptyTabbarSpace(event->pos())) {
517  emit(mouseDoubleClick());
518  return;
519  }
520 
522 }
523 
524 void KTabWidget::mousePressEvent(QMouseEvent *event)
525 {
526  if (event->button() == Qt::RightButton) {
527  if (d->isEmptyTabbarSpace(event->pos())) {
528  emit(contextMenu(mapToGlobal(event->pos())));
529  return;
530  }
531  }
532 
534 }
535 
536 void KTabWidget::mouseReleaseEvent(QMouseEvent *event)
537 {
538  if (event->button() == Qt::MidButton) {
539  if (d->isEmptyTabbarSpace(event->pos())) {
540  emit(mouseMiddleClick());
541  return;
542  }
543  }
544 
546 }
547 
548 void KTabWidget::receivedDropEvent(int index, QDropEvent *event)
549 {
550  emit(receivedDropEvent(widget(index), event));
551 }
552 
553 void KTabWidget::initiateDrag(int index)
554 {
555  emit(initiateDrag(widget(index)));
556 }
557 
558 void KTabWidget::contextMenu(int index, const QPoint &point)
559 {
560  emit(contextMenu(widget(index), point));
561 }
562 
563 void KTabWidget::mouseDoubleClick(int index)
564 {
565  emit(mouseDoubleClick(widget(index)));
566 }
567 
568 void KTabWidget::mouseMiddleClick(int index)
569 {
570  emit(mouseMiddleClick(widget(index)));
571 }
572 
573 void KTabWidget::moveTab(int from, int to)
574 {
575  setUpdatesEnabled(false);
576 
577  const QString tablabel = tabText(from);
578  QWidget *w = widget(from);
579  const QColor color = tabTextColor(from);
580  const QIcon tabiconset = tabIcon(from);
581  const QString tabtooltip = tabToolTip(from);
582  const bool current = (from == currentIndex());
583  const bool enabled = isTabEnabled(from);
584 
585  const bool blocked = blockSignals(true);
586 
588 
589  removeTab(from);
590  insertTab(to, w, tablabel);
591 
592  // Don't lose focus due to moving the tab (#159295)
593  // (removeTab hides the widget, which gives focus to the "next in chain", could be anything)
594  if (w->isAncestorOf(fw)) {
595  fw->setFocus();
596  }
597 
598  setTabIcon(to, tabiconset);
599  setTabText(to, tablabel);
600  setTabToolTip(to, tabtooltip);
601  setTabTextColor(to, color);
602  if (current) {
603  setCurrentIndex(to);
604  }
605  setTabEnabled(to, enabled);
606  if (d->m_automaticResizeTabs) {
607  d->resizeTabs(to);
608  }
609  blockSignals(blocked);
610 
611  setUpdatesEnabled(true);
612 
613 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
614  emit(movedTab(from, to));
615 #endif
616 }
617 
619 {
620  // not just calling removeTab() because that one is also virtual.
621  const int index = indexOf(widget);
622  if (d->m_automaticResizeTabs) {
623  setUpdatesEnabled(false);
624  d->removeTab(index);
625  setUpdatesEnabled(true);
626  } else {
627  d->removeTab(index);
628  }
629 }
630 
631 void KTabWidget::removeTab(int index)
632 {
633  if (d->m_automaticResizeTabs) {
634  const bool wasUpdatesEnabled = updatesEnabled();
635  setUpdatesEnabled(false);
636  d->removeTab(index);
637  setUpdatesEnabled(wasUpdatesEnabled);
638  } else {
639  d->removeTab(index);
640  }
641 }
642 
643 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
645 {
646  // deprecated
647  setTabsClosable(button);
648 }
649 #endif
650 
651 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
652 bool KTabWidget::hoverCloseButton() const
653 {
654  // deprecated
655  return false;
656 }
657 #endif
658 
659 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
661 {
662  // deprecated
663  Q_UNUSED(delayed);
664 }
665 #endif
666 
667 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
669 {
670  // deprecated
671  return tabsClosable();
672 }
673 #endif
674 
675 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
677 {
678  static_cast<KTabBar *>(tabBar())->setTabsClosable(enable);
679 }
680 #endif
681 
682 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
684 {
685  return static_cast<KTabBar *>(tabBar())->tabsClosable();
686 }
687 #endif
688 
690 {
691  if (d->m_automaticResizeTabs == enabled) {
692  return;
693  }
694 
695  setUpdatesEnabled(false);
696 
697  d->m_automaticResizeTabs = enabled;
698  if (enabled) {
699  d->m_tabNames.clear();
700  for (int i = 0; i < count(); ++i) {
701  d->m_tabNames.append(tabBar()->tabText(i));
702  }
703  } else
704  for (int i = 0; i < count(); ++i) {
705  tabBar()->setTabText(i, d->m_tabNames[ i ]);
706  }
707 
708  d->resizeTabs();
709 
710  setUpdatesEnabled(true);
711 }
712 
714 {
715  return d->m_automaticResizeTabs;
716 }
717 
718 void KTabWidget::closeRequest(int index)
719 {
720  emit(closeRequest(widget(index)));
721 }
722 
723 void KTabWidget::resizeEvent(QResizeEvent *event)
724 {
726  d->resizeTabs();
727 }
728 
729 void KTabWidget::tabInserted(int idx)
730 {
731  d->m_tabNames.insert(idx, tabBar()->tabText(idx));
732 }
733 
734 void KTabWidget::tabRemoved(int idx)
735 {
736  Q_UNUSED(idx)
737 // d->m_tabNames is now updated in KTabWidget::Private::removeTab()
738 }
739 
740 /* This function is kept only for BC reasons, it is not useful anymore */
741 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
743 {
744 }
745 #endif
746 
747 #include "moc_ktabwidget.cpp"
void mouseDoubleClick()
A double left mouse button click was performed over empty space besides tabbar.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
virtual void dropEvent(QDropEvent *event)
QString tabText(int) const
Reimplemented for internal reasons.
Definition: ktabwidget.cpp:391
int width() const const
KCOREADDONS_EXPORT QString rsqueeze(const QString &str, int maxlen=40)
QString tabText(int index) const const
void tabCloseRequested(int index)
KTabWidget(QWidget *parent=nullptr, Qt::WindowFlags flags={})
Creates a new tab widget.
Definition: ktabwidget.cpp:239
void setTabText(int index, const QString &text)
bool hoverCloseButtonDelayed() const
Returns true if the close button is shown on tabs after a delay.
QSize globalStrut()
QStyle * style() const const
virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const =0
virtual void dragEnterEvent(QDragEnterEvent *event)
QPoint pos() const const
QIcon tabIcon(int index) const const
bool isVisible() const const
QPoint mapToGlobal(const QPoint &pos) const const
LeftButton
QPoint pos() const const
TopRightCorner
bool isAncestorOf(const QWidget *child) const const
bool isTabReorderingEnabled() const
Returns true if tab ordering with the middle mouse button has been enabled.
Definition: ktabwidget.cpp:342
bool isTabBarHidden() const
Returns true if the tabbar was hidden by a call to setTabBarHidden( true ).
Definition: ktabwidget.cpp:319
QT_MOC_COMPAT void setTabCloseActivatePrevious(bool previous)
If previous is true, closing the current tab activates the previous active tab instead of the one to ...
Definition: ktabwidget.cpp:349
virtual void dragMoveEvent(QDragMoveEvent *event)
QString & remove(int position, int n)
int indexOf(QWidget *w) const const
void setTabsClosable(bool closeable)
void setTabEnabled(int index, bool enable)
virtual void mouseReleaseEvent(QMouseEvent *event)
int count() const const
void mouseMiddleClick()
A middle mouse button click was performed over empty space besides tabbar.
bool mightBeRichText(const QString &text)
int x() const const
int y() const const
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) const const
void setTabText(int index, const QString &label)
int currentIndex() const const
void setTabTextColor(int index, const QColor &color)
void contextMenu(const QPoint &)
The right mouse button was pressed over empty space besides tabbar.
QString & insert(int position, QChar ch)
virtual void mousePressEvent(QMouseEvent *event)
int x() const const
bool hoverCloseButton() const
Returns true if the close button is shown on tabs when mouse is hovering over them.
virtual ~KTabWidget()
Destroys the tab widget.
Definition: ktabwidget.cpp:260
void setUpdatesEnabled(bool enable)
void setFocus()
Qt::MouseButton button() const const
void setObjectName(const QString &name)
QWidget * focusWidget()
QT_MOC_COMPAT void setTabReorderingEnabled(bool enable)
If enable is true, tab reordering with middle button will be enabled.
Definition: ktabwidget.cpp:335
bool sendEvent(QObject *receiver, QEvent *event)
void setTabTextColor(int index, const QColor &color)
Set the tab of the given widget to color.
Definition: ktabwidget.cpp:324
void setTabBarHidden(bool hide)
If hide is true, the tabbar is hidden along with any corner widgets.
Definition: ktabwidget.cpp:290
void currentChanged(int)
Definition: ktabwidget.cpp:742
QIcon tabIcon(int index) const const
void testCanDecode(const QDragMoveEvent *e, bool &accept)
Connect to this and set accept to true if you can and want to decode the event.
int insertTab(int index, QWidget *page, const QString &label)
A QTabBar with extended features.
Definition: ktabbar.h:34
void setTabToolTip(int index, const QString &tip)
void hide()
QWidget * widget(int index) const const
void setAcceptDrops(bool on)
QT_MOC_COMPAT void setHoverCloseButton(bool enable)
If enable is true, a close button will be shown on mouse hover over tab icons which will emit signal ...
Definition: ktabwidget.cpp:644
bool tabCloseActivatePrevious() const
Returns true if closing the current tab activates the previous actice tab instead of the one to the r...
bool blockSignals(bool block)
QString toHtmlEscaped() const const
void initiateDrag(QWidget *)
Request to start a drag operation on the given tab.
virtual void wheelEvent(QWheelEvent *event)
virtual void moveTab(int, int)
Move a widget&#39;s tab from first to second specified index and emit signal movedTab( int...
Definition: ktabwidget.cpp:573
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
bool isCloseButtonEnabled() const
Returns true if the close button is shown on tabs.
Definition: ktabwidget.cpp:683
virtual void mouseDoubleClickEvent(QMouseEvent *event)
void setWindowFlags(Qt::WindowFlags type)
QWidget * cornerWidget(Qt::Corner corner) const const
PM_TabBarTabHSpace
QFontMetrics fontMetrics() const const
QT_MOC_COMPAT void setHoverCloseButtonDelayed(bool delayed)
If delayed is true, a close button will be shown on mouse hover over tab icons after mouse double cli...
Definition: ktabwidget.cpp:660
virtual void resizeEvent(QResizeEvent *e) override
void closeRequest(QWidget *)
The close button of a widget&#39;s tab was clicked.
int length() const const
QString leftJustified(int width, QChar fill, bool truncate) const const
void setAutomaticResizeTabs(bool enable)
If enable is true, tabs will be resized to the width of the tab bar.
Definition: ktabwidget.cpp:689
QColor tabTextColor(int index) const
Returns the tab color for the given widget.
Definition: ktabwidget.cpp:329
virtual void removeTab(int index)
Removes the widget, reimplemented for internal reasons (keeping labels in sync).
Definition: ktabwidget.cpp:631
QT_MOC_COMPAT void setCloseButtonEnabled(bool)
If enabled, a close button is available for each tab.
Definition: ktabwidget.cpp:676
void receivedDropEvent(QDropEvent *)
Received an event in the empty space beside tabbar.
virtual QT_MOC_COMPAT void removePage(QWidget *w)
Removes the widget, reimplemented for internal reasons (keeping labels in sync).
Definition: ktabwidget.cpp:618
void show()
QPoint pos() const const
int width(const QString &text, int len) const const
void movedTab(int, int)
A tab was moved from first to second index.
QTabBar * tabBar() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setTabText(int, const QString &)
Reimplemented for internal reasons.
Definition: ktabwidget.cpp:411
QColor tabTextColor(int index) const const
bool automaticResizeTabs() const
Returns true if calling setTitle() will resize tabs to the width of the tab bar.
typedef WindowFlags
virtual bool event(QEvent *ev) override
virtual QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const const =0
QString tabToolTip(int index) const const
bool isTabEnabled(int index) const const
void setTabBar(QTabBar *tb)
void setTabIcon(int index, const QIcon &icon)
A widget containing multiple tabs.
Definition: ktabwidget.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 22:56:48 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.