QSize TabBar::tabSizeHint(int index) const { MainView *view = qobject_cast<MainView *>(parent()); int buttonSize = view->addTabButton()->size().width(); int tabBarWidth = view->size().width() - buttonSize; int baseWidth = view->sizeHint().width() / BASE_WIDTH_DIVISOR; int minWidth = view->sizeHint().width() / MIN_WIDTH_DIVISOR; int w; if (baseWidth*count() < tabBarWidth) { w = baseWidth; } else { if (count() > 0 && tabBarWidth / count() > minWidth) { w = tabBarWidth / count(); } else { w = minWidth; } } int h = KTabBar::tabSizeHint(index).height(); QSize ts = QSize(w, h); return ts; }
void TabBar::showTabPreview() { if (m_isFirstTimeOnTab) m_isFirstTimeOnTab = false; //delete previous tab preview delete m_previewPopup.data(); m_previewPopup.clear(); MainView *mv = qobject_cast<MainView *>(parent()); WebTab *indexedTab = mv->webTab(m_currentTabPreviewIndex); WebTab *currentTab = mv->webTab(currentIndex()); // check if view && currentView exist before using them :) if (!currentTab || !indexedTab) return; // no previews during load if (indexedTab->isPageLoading()) return; // Make sure the hovered webtab match the current size // Only the active one is updated by window resize events indexedTab->resize(currentTab->size()); m_previewPopup = new TabPreviewPopup(indexedTab , this); int tabWidth = tabSizeHint(m_currentTabPreviewIndex).width(); int tabBarWidth = mv->size().width(); int leftIndex = tabRect(m_currentTabPreviewIndex).x() + (tabRect(m_currentTabPreviewIndex).width() - tabWidth) / 2; int popupWidth = m_previewPopup.data()->thumbnailSize().width(); // Center the popup if the tab width is bigger or smaller leftIndex += (tabWidth - popupWidth) / 2; if (leftIndex < 0) { leftIndex = 0; } else if (leftIndex + tabWidth > tabBarWidth) { leftIndex = tabBarWidth - tabWidth; } QPoint pos(leftIndex, tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height()); m_previewPopup.data()->show(mapToGlobal(pos)); }