void MainWindow::fileSaveAs() { WebTab *w = currentTab(); KUrl srcUrl = w->url(); // First, try with suggested file name... QString name = w->page()->suggestedFileName(); // Second, with KUrl fileName... if (name.isEmpty()) { name = srcUrl.fileName(); } // Last chance... if(name.isEmpty()) { name = srcUrl.host() + QString(".html"); } const QString destUrl = KFileDialog::getSaveFileName(name, QString(), this); if (destUrl.isEmpty()) return; KIO::Job *job = KIO::file_copy(srcUrl, KUrl(destUrl), -1, KIO::Overwrite); job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache. job->addMetaData("cache", "cache"); // Use entry from cache if available. job->uiDelegate()->setAutoErrorHandlingEnabled(true); }
void TabTreeView::addMenuActions(QMenu *menu, const QModelIndex &index) const { if (!m_haveTreeModel) { return; } menu->addSeparator(); QMenu *m = menu->addMenu(tr("Tab Tree")); if (index.isValid() && model()->rowCount(index) > 0) { QPersistentModelIndex pindex = index; m->addAction(tr("Close Tree"), this, [=]() { QVector<WebTab*> tabs; reverseTraverse(pindex, [&](const QModelIndex &index) { WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (tab) { tabs.append(tab); } }); for (WebTab *tab : qAsConst(tabs)) { tab->closeTab(); } }); } m->addSeparator(); m->addAction(tr("Expand All"), this, &TabTreeView::expandAll); m->addAction(tr("Collapse All"), this, &TabTreeView::collapseAll); }
void TabBar::updatePinnedTabCloseButton(int index) { if (!validIndex(index)) { return; } WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, closeButtonPosition())); bool pinned = webTab && webTab->isPinned(); if (pinned) { if (button) { button->hide(); } } else { if (button) { button->show(); } else { showCloseButton(index); } } }
void TabBar::pinTab() { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab)); if (webTab) { webTab->togglePinned(); } }
void TabBar::contextMenuEvent(QContextMenuEvent* event) { int index = tabAt(event->pos()); m_clickedTab = index; QMenu menu; menu.addAction(IconProvider::newTabIcon(), tr("&New tab"), m_window, SLOT(addTab())); menu.addSeparator(); if (index != -1) { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab)); if (!webTab) { return; } if (m_window->weView(m_clickedTab)->isLoading()) { menu.addAction(QIcon::fromTheme(QSL("process-stop")), tr("&Stop Tab"), this, SLOT(stopTab())); } else { menu.addAction(QIcon::fromTheme(QSL("view-refresh")), tr("&Reload Tab"), this, SLOT(reloadTab())); } menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab())); if (count() > 1 && !webTab->isPinned()) { menu.addAction(QIcon::fromTheme("tab-detach"), tr("D&etach Tab"), this, SLOT(detachTab())); } menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); #if QT_VERSION >= QT_VERSION_CHECK(5,7,0) menu.addAction(webTab->isMuted() ? tr("Un&mute Tab") : tr("&Mute Tab"), this, SLOT(muteTab())); #endif menu.addSeparator(); menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab())); menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs())); menu.addSeparator(); menu.addAction(m_window->action(QSL("Other/RestoreClosedTab"))); menu.addSeparator(); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab())); menu.addSeparator(); } else { menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs())); menu.addSeparator(); menu.addAction(m_window->action(QSL("Other/RestoreClosedTab"))); } m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab()); // Prevent choosing first option with double rightclick const QPoint pos = event->globalPos(); QPoint p(pos.x(), pos.y() + 1); menu.exec(p); m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true); }
bool TabbedWebView::isCurrent() { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_tabWidget->currentIndex())); if (!webTab) { return false; } return (webTab->view() == this); }
void TabBar::bookmarkTab() { TabbedWebView* view = m_window->weView(m_clickedTab); if (!view) { return; } WebTab* tab = view->webTab(); m_window->addBookmark(tab->url(), tab->title()); }
void TabBar::bookmarkTab() { TabbedWebView* view = p_QupZilla->weView(m_clickedTab); if (!view) { return; } WebTab* tab = view->webTab(); p_QupZilla->addBookmark(tab->url(), tab->title(), tab->icon()); }
void TabBar::contextMenuRequested(const QPoint &position) { int index = tabAt(position); m_clickedTab = index; QMenu menu; menu.addAction(QIcon(":/icons/menu/new-tab.png"), tr("&New tab"), p_QupZilla, SLOT(addTab())); menu.addSeparator(); if (index != -1) { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab)); if (!webTab) { return; } if (p_QupZilla->weView(m_clickedTab)->isLoading()) { menu.addAction(qIconProvider->standardIcon(QStyle::SP_BrowserStop), tr("&Stop Tab"), this, SLOT(stopTab())); } else { menu.addAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload Tab"), this, SLOT(reloadTab())); } menu.addAction(tr("&Duplicate Tab"), this, SLOT(duplicateTab())); menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); menu.addSeparator(); menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab())); menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addSeparator(); QAction* action = p_QupZilla->actionRestoreTab(); action->setEnabled(m_tabWidget->canRestoreTab()); menu.addAction(action); menu.addSeparator(); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab())); menu.addSeparator(); } else { menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addSeparator(); QAction* action = menu.addAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab())); action->setEnabled(m_tabWidget->canRestoreTab()); } // Prevent choosing first option with double rightclick const QPoint &pos = mapToGlobal(position); QPoint p(pos.x(), pos.y() + 1); menu.exec(p); p_QupZilla->actionRestoreTab()->setEnabled(true); }
void TabTreeView::initView() { // Restore expanded state expandAll(); QModelIndex index = model()->index(0, 0); while (index.isValid()) { WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (tab) { setExpanded(index, tab->sessionData().value(m_expandedSessionKey, true).toBool()); } index = indexBelow(index); } m_initializing = false; }
void TabBar::updateCloseButton(int index) { QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, QTabBar::RightSide)); if (!button) { return; } WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); if (webTab && webTab->isPinned()) { button->hide(); } else { button->show(); } }
void TabBar::showCloseButton(int index) { if (!validIndex(index)) { return; } WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, closeButtonPosition())); if (button || (webTab && webTab->isPinned())) { return; } insertCloseButton(index); }
void TabBar::showCloseButton(int index) { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); if (webTab && webTab->isPinned()) { return; } CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide); if (!button) { return; } button->show(); }
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)); }
QSize TabBar::tabSizeHint(int index) const { QSize size = QTabBar::tabSizeHint(index); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); TabBar* tabBar = const_cast <TabBar*>(this); tabBar->m_adjustingLastTab = false; if (webTab && webTab->isPinned()) { size.setWidth(PINNED_TAB_WIDTH); } else { int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width() - m_tabWidget->buttonAddTab()->width(); int normalTabsCount = count() - m_pinnedTabsCount; if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount) { tabBar->m_normalTabWidth = MAXIMUM_TAB_WIDTH; size.setWidth(m_normalTabWidth); } else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) { tabBar->m_normalTabWidth = MINIMUM_TAB_WIDTH; size.setWidth(m_normalTabWidth); } else { int maxWidthForTab = availableWidth / normalTabsCount; tabBar->m_normalTabWidth = maxWidthForTab; //Fill any empty space (we've got from rounding) with last tab if (index == count() - 1) { tabBar->m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; tabBar->m_adjustingLastTab = true; size.setWidth(m_lastTabWidth); } else { tabBar->m_lastTabWidth = maxWidthForTab; size.setWidth(m_lastTabWidth); } } } if (index == count() - 1) { int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth); if (m_adjustingLastTab) { xForAddTabButton += m_lastTabWidth - m_normalTabWidth; } emit tabBar->moveAddTabButton(xForAddTabButton); } return size; }
void TabBar::showCloseButton(int index) { if (!validIndex(index)) { return; } WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); QAbstractButton* button = qobject_cast<QAbstractButton*>(tabButton(index, QTabBar::RightSide)); if (button || (webTab && webTab->isPinned())) { return; } QAbstractButton* closeButton = new CloseButton(this); connect(closeButton, SIGNAL(clicked()), this, SLOT(closeTabFromButton())); setTabButton(index, QTabBar::RightSide, closeButton); }
WebPage *WebPage::createWindow(QWebPage::WebWindowType type) { // added to manage web modal dialogs if (type == QWebPage::WebModalDialog) kDebug() << "Modal Dialog"; WebTab *w = 0; if (ReKonfig::openTabNoWindow()) { w = rApp->mainWindow()->mainView()->newWebTab(!ReKonfig::openTabsBack()); } else { w = rApp->newMainWindow()->mainView()->currentWebTab(); } return w->page(); }
void TabBar::pinTab() { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab)); if (!webTab) { return; } webTab->pinTab(m_clickedTab); if (webTab->isPinned()) { m_pinnedTabsCount++; } else { m_pinnedTabsCount--; } // Adjust add tab button in proper position tabSizeHint(count() - 1); }
TabTreeView::TabTreeView(BrowserWindow *window, QWidget *parent) : QTreeView(parent) , m_window(window) , m_expandedSessionKey(QSL("VerticalTabs-expanded")) { setDragEnabled(true); setAcceptDrops(true); setHeaderHidden(true); setUniformRowHeights(true); setDropIndicatorShown(true); setAllColumnsShowFocus(true); setMouseTracking(true); setFocusPolicy(Qt::NoFocus); setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setIndentation(0); m_delegate = new TabTreeDelegate(this); setItemDelegate(m_delegate); // Move scrollbar to the left setLayoutDirection(isRightToLeft() ? Qt::LeftToRight : Qt::RightToLeft); // Enable hover to force redrawing close button viewport()->setAttribute(Qt::WA_Hover); auto saveExpandedState = [this](const QModelIndex &index, bool expanded) { if (m_initializing) { return; } WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (tab) { tab->setSessionData(m_expandedSessionKey, expanded); } }; connect(this, &TabTreeView::expanded, this, std::bind(saveExpandedState, std::placeholders::_1, true)); connect(this, &TabTreeView::collapsed, this, std::bind(saveExpandedState, std::placeholders::_1, false)); }
void TabBar::pinTab() { WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab)); if (!webTab) { return; } webTab->pinTab(m_clickedTab); if (webTab->isPinned()) { m_pinnedTabsCount++; } else { m_pinnedTabsCount--; } // We need to recalculate size of all tabs and repaint tabbar // Unfortunately, Qt doesn't offer refresh() function as a public API // So we are calling the lightest function that calls d->refresh() setElideMode(elideMode()); }
void TabBar::showTabPreview() { //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; int w = tabSizeHint(m_currentTabPreviewIndex).width(); int h = w * ((0.0 + currentTab->height()) / currentTab->width()); m_previewPopup = new KPassivePopup(this); m_previewPopup.data()->setFrameShape(QFrame::StyledPanel); m_previewPopup.data()->setFrameShadow(QFrame::Plain); m_previewPopup.data()->setFixedSize(w, h); QLabel *l = new QLabel(); l->setPixmap( WebSnap::renderTabPreview(*indexedTab->page(), w, h) ); m_previewPopup.data()->setView(l); m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); m_previewPopup.data()->layout()->setMargin(0); QPoint pos(tabRect(m_currentTabPreviewIndex).x() , tabRect(m_currentTabPreviewIndex).y() + tabRect(m_currentTabPreviewIndex).height()); m_previewPopup.data()->show(mapToGlobal(pos)); }
void MainWindow::notifyMessage(const QString &msg, Rekonq::Notify status) { if (this != QApplication::activeWindow()) { return; } // deleting popus if empty msgs if (msg.isEmpty()) { m_hidePopup->start(250); return; } m_hidePopup->stop(); switch (status) { case Rekonq::Url: break; case Rekonq::Info: m_hidePopup->start(500); break; case Rekonq::Success: break; case Rekonq::Error: break; case Rekonq::Download: break; default: break; } int margin = 4; // setting the popup QLabel *label = new QLabel(msg); m_popup->setView(label); QSize labelSize(label->fontMetrics().width(msg) + 2*margin, label->fontMetrics().height() + 2*margin); if (labelSize.width() > width()) labelSize.setWidth(width()); m_popup->setFixedSize(labelSize); m_popup->layout()->setAlignment(Qt::AlignTop); m_popup->layout()->setMargin(margin); // useful values WebTab *tab = m_view->currentWebTab(); // fix crash on window close if (!tab) return; // fix crash on window close if (!tab->page()) return; bool scrollbarIsVisible = tab->page()->currentFrame()->scrollBarMaximum(Qt::Horizontal); int scrollbarSize = 0; if (scrollbarIsVisible) { //TODO: detect QStyle size scrollbarSize = 17; } QPoint webViewOrigin = tab->view()->mapToGlobal(QPoint(0, 0)); int bottomLeftY = webViewOrigin.y() + tab->page()->viewportSize().height() - labelSize.height() - scrollbarSize; // setting popup in bottom-left position int x = geometry().x(); int y = bottomLeftY; QPoint mousePos = tab->mapToGlobal(tab->view()->mousePos()); if (QRect(webViewOrigin.x() , bottomLeftY , labelSize.width() , labelSize.height()).contains(mousePos)) { // setting popup above the mouse y = bottomLeftY - labelSize.height(); } m_popup->show(QPoint(x, y)); }
bool TabTreeView::viewportEvent(QEvent *event) { switch (event->type()) { case QEvent::MouseButtonPress: { QMouseEvent *me = static_cast<QMouseEvent*>(event); const QModelIndex index = indexAt(me->pos()); updateIndex(index); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (me->buttons() == Qt::MiddleButton && tab) { tab->closeTab(); } if (me->buttons() != Qt::LeftButton) { m_pressedIndex = QModelIndex(); m_pressedButton = NoButton; break; } m_pressedIndex = index; m_pressedButton = buttonAt(me->pos(), m_pressedIndex); if (m_pressedIndex.isValid()) { if (m_pressedButton == ExpandButton) { if (isExpanded(m_pressedIndex)) { collapse(m_pressedIndex); } else { expand(m_pressedIndex); } } else if (m_pressedButton == NoButton && tab) { tab->makeCurrentTab(); } } if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::MouseMove: { QMouseEvent *me = static_cast<QMouseEvent*>(event); if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::MouseButtonRelease: { QMouseEvent *me = static_cast<QMouseEvent*>(event); if (me->buttons() != Qt::NoButton) { break; } const QModelIndex index = indexAt(me->pos()); updateIndex(index); if (m_pressedIndex != index) { break; } DelegateButton button = buttonAt(me->pos(), index); if (m_pressedButton == button) { if (m_pressedButton == ExpandButton) { me->accept(); return true; } WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); if (tab) { if (m_pressedButton == CloseButton) { tab->closeTab(); } else if (m_pressedButton == AudioButton) { tab->toggleMuted(); } } } if (m_pressedButton == CloseButton) { me->accept(); return true; } break; } case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::HoverMove: { QHoverEvent *he = static_cast<QHoverEvent*>(event); updateIndex(m_hoveredIndex); m_hoveredIndex = indexAt(he->pos()); updateIndex(m_hoveredIndex); break; } case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent*>(event); const QModelIndex index = indexAt(he->pos()); DelegateButton button = buttonAt(he->pos(), index); if (button == AudioButton) { const bool muted = index.data(TabModel::AudioMutedRole).toBool(); QToolTip::showText(he->globalPos(), muted ? tr("Unmute Tab") : tr("Mute Tab"), this, visualRect(index)); he->accept(); return true; } else if (button == CloseButton) { QToolTip::showText(he->globalPos(), tr("Close Tab"), this, visualRect(index)); he->accept(); return true; } else if (button == NoButton) { QToolTip::showText(he->globalPos(), index.data().toString(), this, visualRect(index)); he->accept(); return true; } break; } case QEvent::ContextMenu: { QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event); const QModelIndex index = indexAt(ce->pos()); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); const int tabIndex = tab ? tab->tabIndex() : -1; TabContextMenu::Options options = TabContextMenu::VerticalTabs | TabContextMenu::ShowDetachTabAction; if (m_tabsInOrder) { options |= TabContextMenu::ShowCloseOtherTabsActions; } TabContextMenu menu(tabIndex, m_window, options); addMenuActions(&menu, index); menu.exec(ce->globalPos()); break; } default: break; } return QTreeView::viewportEvent(event); }
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { if (_isOnRekonqPage) { WebView *view = qobject_cast<WebView *>(parent()); WebTab *tab = qobject_cast<WebTab *>(view->parent()); _isOnRekonqPage = false; tab->setPart(0, KUrl()); // re-enable the view page } // reset webpage values _suggestedFileName.clear(); _loadingUrl = request.url(); KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager()); KIO::MetaData metaData = manager->requestMetaData(); // Get the SSL information sent, if any... if (metaData.contains(QL1S("ssl_in_use"))) { WebSslInfo info; info.restoreFrom(metaData.toVariant(), request.url()); info.setUrl(request.url()); _sslInfo = info; } if (frame) { if (_protHandler.preHandling(request, frame)) { return false; } switch (type) { case QWebPage::NavigationTypeLinkClicked: if (_sslInfo.isValid()) { setRequestMetaData("ssl_was_in_use", "TRUE"); } break; case QWebPage::NavigationTypeFormSubmitted: break; case QWebPage::NavigationTypeFormResubmitted: if (KMessageBox::warningContinueCancel(view(), i18n("Are you sure you want to send your data again?"), i18n("Resend form data") ) == KMessageBox::Cancel) { return false; } break; case QWebPage::NavigationTypeReload: case QWebPage::NavigationTypeBackOrForward: case QWebPage::NavigationTypeOther: break; default: break; } } return KWebPage::acceptNavigationRequest(frame, request, type); }
QSize TabBar::tabSizeHint(int index, bool fast) const { if (!m_window->isVisible()) { // Don't calculate it when window is not visible // It produces invalid size anyway return QSize(-1, -1); } const int pinnedTabWidth = comboTabBarPixelMetric(ComboTabBar::PinnedTabWidth); const int minTabWidth = comboTabBarPixelMetric(ComboTabBar::NormalTabMinimumWidth); QSize size = ComboTabBar::tabSizeHint(index); // The overflowed tabs have same size and we can use this fast method if (fast) { size.setWidth(index >= pinnedTabsCount() ? minTabWidth : pinnedTabWidth); return size; } WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); TabBar* tabBar = const_cast <TabBar*>(this); if (webTab && webTab->isPinned()) { size.setWidth(pinnedTabWidth); } else { int availableWidth = mainTabBarWidth() - comboTabBarPixelMetric(ExtraReservedWidth); if (availableWidth < 0) { return QSize(-1, -1); } const int normalTabsCount = ComboTabBar::normalTabsCount(); const int maxTabWidth = comboTabBarPixelMetric(ComboTabBar::NormalTabMaximumWidth); if (availableWidth >= maxTabWidth * normalTabsCount) { m_normalTabWidth = maxTabWidth; size.setWidth(m_normalTabWidth); } else if (normalTabsCount > 0) { const int minActiveTabWidth = comboTabBarPixelMetric(ComboTabBar::ActiveTabMinimumWidth); int maxWidthForTab = availableWidth / normalTabsCount; int realTabWidth = maxWidthForTab; bool adjustingActiveTab = false; if (realTabWidth < minActiveTabWidth) { maxWidthForTab = normalTabsCount > 1 ? (availableWidth - minActiveTabWidth) / (normalTabsCount - 1) : 0; realTabWidth = minActiveTabWidth; adjustingActiveTab = true; } bool tryAdjusting = availableWidth >= minTabWidth * normalTabsCount; if (m_showCloseOnInactive != 1 && tabsClosable() && availableWidth < (minTabWidth + 25) * normalTabsCount) { // Hiding close buttons to save some space tabBar->setTabsClosable(false); tabBar->showCloseButton(currentIndex()); } if (m_showCloseOnInactive == 1) { // Always showing close buttons tabBar->setTabsClosable(true); tabBar->showCloseButton(currentIndex()); } if (tryAdjusting) { m_normalTabWidth = maxWidthForTab; // Fill any empty space (we've got from rounding) with active tab if (index == mainTabBarCurrentIndex()) { if (adjustingActiveTab) { m_activeTabWidth = (availableWidth - minActiveTabWidth - maxWidthForTab * (normalTabsCount - 1)) + realTabWidth; } else { m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; } size.setWidth(m_activeTabWidth); } else { size.setWidth(m_normalTabWidth); } } } // Restore close buttons according to preferences if (m_showCloseOnInactive != 2 && !tabsClosable() && availableWidth >= (minTabWidth + 25) * normalTabsCount) { tabBar->setTabsClosable(true); // Hide close buttons on pinned tabs for (int i = 0; i < count(); ++i) { tabBar->updatePinnedTabCloseButton(i); } } } if (index == count() - 1) { WebTab* lastMainActiveTab = qobject_cast<WebTab*>(m_tabWidget->widget(mainTabBarCurrentIndex())); int xForAddTabButton = cornerWidth(Qt::TopLeftCorner) + pinTabBarWidth() + normalTabsCount() * m_normalTabWidth; if (lastMainActiveTab && m_activeTabWidth > m_normalTabWidth) { xForAddTabButton += m_activeTabWidth - m_normalTabWidth; } if (QApplication::layoutDirection() == Qt::RightToLeft) { xForAddTabButton = width() - xForAddTabButton; } emit tabBar->moveAddTabButton(xForAddTabButton); } return size; }
void TabManagerWidget::processActions() { if (!sender()) { return; } m_refreshBlocked = true; QHash<BrowserWindow*, WebTab*> selectedTabs; const QString &command = sender()->objectName(); for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) { QTreeWidgetItem* winItem = ui->treeWidget->topLevelItem(i); if (winItem->checkState(0) == Qt::Unchecked) { continue; } for (int j = 0; j < winItem->childCount(); ++j) { QTreeWidgetItem* tabItem = winItem->child(j); if (tabItem->checkState(0) == Qt::Unchecked) { continue; } BrowserWindow* mainWindow = qobject_cast<BrowserWindow*>(qvariant_cast<QWidget*>(tabItem->data(0, QupZillaPointerRole))); WebTab* webTab = qobject_cast<WebTab*>(qvariant_cast<QWidget*>(tabItem->data(0, WebTabPointerRole))); // current supported actions are not applied to pinned tabs if (webTab->isPinned()) { tabItem->setCheckState(0, Qt::Unchecked); continue; } if (command == "closeSelection") { if (webTab->url().toString() == "qupzilla:restore") { continue; } selectedTabs.insertMulti(mainWindow, webTab); } else if (command == "detachSelection" || command == "bookmarkSelection") { selectedTabs.insertMulti(mainWindow, webTab); } } winItem->setCheckState(0, Qt::Unchecked); } if (!selectedTabs.isEmpty()) { if (command == "closeSelection") { closeSelectedTabs(selectedTabs); } else if (command == "detachSelection") { detachSelectedTabs(selectedTabs); } else if (command == "bookmarkSelection") { bookmarkSelectedTabs(selectedTabs); } } m_refreshBlocked = false; delayedRefreshTree(); }
QSize TabBar::tabSizeHint(int index) const { if (!isVisible()) { // Don't calculate it when tabbar is not visible // It produces invalid size anyway return QSize(-1, -1); } static int PINNED_TAB_WIDTH = -1; static int MINIMUM_ACTIVE_TAB_WIDTH = -1; if (PINNED_TAB_WIDTH == -1) { PINNED_TAB_WIDTH = 16 + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this); MINIMUM_ACTIVE_TAB_WIDTH = PINNED_TAB_WIDTH + style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this); // just a hack: we want to be sure buttonAddTab and buttonListTabs can't cover the active tab MINIMUM_ACTIVE_TAB_WIDTH = qMax(MINIMUM_ACTIVE_TAB_WIDTH, 6 + m_tabWidget->buttonListTabs()->width() + m_tabWidget->buttonAddTab()->width()); } QSize size = QTabBar::tabSizeHint(index); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); TabBar* tabBar = const_cast <TabBar*>(this); bool adjustingActiveTab = false; if (webTab && webTab->isPinned()) { size.setWidth(PINNED_TAB_WIDTH); } else { int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width() - m_tabWidget->buttonAddTab()->width(); int normalTabsCount = count() - m_pinnedTabsCount; if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount) { m_normalTabWidth = MAXIMUM_TAB_WIDTH; size.setWidth(m_normalTabWidth); } else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) { // Tabs don't fit at all in tabbar even with MINIMUM_TAB_WIDTH // We will try to use as low width of tabs as possible // to try avoid overflowing tabs into tabbar buttons int maxWidthForTab = availableWidth / normalTabsCount; m_activeTabWidth = maxWidthForTab; if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) { maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1); m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH; adjustingActiveTab = true; } if (maxWidthForTab < PINNED_TAB_WIDTH) { // FIXME: It overflows now m_normalTabWidth = PINNED_TAB_WIDTH; if (index == currentIndex()) { size.setWidth(m_activeTabWidth); } else { size.setWidth(m_normalTabWidth); } } else { m_normalTabWidth = maxWidthForTab; // Fill any empty space (we've got from rounding) with active tab if (index == currentIndex()) { if (adjustingActiveTab) { m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH - maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth; } else { m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; } adjustingActiveTab = true; size.setWidth(m_activeTabWidth); } else { size.setWidth(m_normalTabWidth); } if (tabsClosable()) { // Hiding close buttons to save some space tabBar->setTabsClosable(false); tabBar->showCloseButton(currentIndex()); } } } else { int maxWidthForTab = availableWidth / normalTabsCount; m_activeTabWidth = maxWidthForTab; if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) { maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1); m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH; adjustingActiveTab = true; } m_normalTabWidth = maxWidthForTab; // Fill any empty space (we've got from rounding) with active tab if (index == currentIndex()) { if (adjustingActiveTab) { m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH - maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth; } else { m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; } adjustingActiveTab = true; size.setWidth(m_activeTabWidth); } else { size.setWidth(m_normalTabWidth); } // Restore close buttons according to preferences if (!tabsClosable()) { tabBar->setTabsClosable(true); // Hide close buttons on pinned tabs for (int i = 0; i < count(); ++i) { tabBar->updatePinnedTabCloseButton(i); } } } } if (index == currentIndex()) { int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth); if (adjustingActiveTab) { xForAddTabButton += m_activeTabWidth - m_normalTabWidth; } // RTL Support if (QApplication::layoutDirection() == Qt::RightToLeft) { xForAddTabButton = width() - xForAddTabButton; } emit tabBar->moveAddTabButton(xForAddTabButton); } return size; }