Beispiel #1
0
int ComboTabBar::insertTab(int index, const QIcon &icon, const QString &text, bool pinned)
{
    if (pinned) {
        index = m_pinnedTabBar->insertTab(index, icon, text);
    }
    else {
        index = m_mainTabBar->insertTab(index - pinnedTabsCount(), icon, text);

        if (tabsClosable()) {
            QWidget* closeButton = m_mainTabBar->tabButton(index, closeButtonPosition());
            if ((closeButton && closeButton->objectName() != QLatin1String("combotabbar_tabs_close_button")) || !closeButton) {
                // insert our close button
                insertCloseButton(index + pinnedTabsCount());
                if (closeButton) {
                    closeButton->deleteLater();
                }
            }
        }

        index += pinnedTabsCount();
    }

    updatePinnedTabBarVisibility();
    tabInserted(index);
    setMinimumWidths();

    return index;
}
int QTabBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 8)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< Shape*>(_v) = shape(); break;
        case 1: *reinterpret_cast< int*>(_v) = currentIndex(); break;
        case 2: *reinterpret_cast< int*>(_v) = count(); break;
        case 3: *reinterpret_cast< bool*>(_v) = drawBase(); break;
        case 4: *reinterpret_cast< QSize*>(_v) = iconSize(); break;
        case 5: *reinterpret_cast< Qt::TextElideMode*>(_v) = elideMode(); break;
        case 6: *reinterpret_cast< bool*>(_v) = usesScrollButtons(); break;
        case 7: *reinterpret_cast< bool*>(_v) = tabsClosable(); break;
        case 8: *reinterpret_cast< SelectionBehavior*>(_v) = selectionBehaviorOnRemove(); break;
        case 9: *reinterpret_cast< bool*>(_v) = expanding(); break;
        case 10: *reinterpret_cast< bool*>(_v) = isMovable(); break;
        case 11: *reinterpret_cast< bool*>(_v) = documentMode(); break;
        }
        _id -= 12;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setShape(*reinterpret_cast< Shape*>(_v)); break;
        case 1: setCurrentIndex(*reinterpret_cast< int*>(_v)); break;
        case 3: setDrawBase(*reinterpret_cast< bool*>(_v)); break;
        case 4: setIconSize(*reinterpret_cast< QSize*>(_v)); break;
        case 5: setElideMode(*reinterpret_cast< Qt::TextElideMode*>(_v)); break;
        case 6: setUsesScrollButtons(*reinterpret_cast< bool*>(_v)); break;
        case 7: setTabsClosable(*reinterpret_cast< bool*>(_v)); break;
        case 8: setSelectionBehaviorOnRemove(*reinterpret_cast< SelectionBehavior*>(_v)); break;
        case 9: setExpanding(*reinterpret_cast< bool*>(_v)); break;
        case 10: setMovable(*reinterpret_cast< bool*>(_v)); break;
        case 11: setDocumentMode(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 12;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 12;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
int QMdiArea::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractScrollArea::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 14)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 14;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QBrush*>(_v) = background(); break;
        case 1: *reinterpret_cast< WindowOrder*>(_v) = activationOrder(); break;
        case 2: *reinterpret_cast< ViewMode*>(_v) = viewMode(); break;
        case 3: *reinterpret_cast< bool*>(_v) = documentMode(); break;
        case 4: *reinterpret_cast< bool*>(_v) = tabsClosable(); break;
        case 5: *reinterpret_cast< bool*>(_v) = tabsMovable(); break;
        case 6: *reinterpret_cast< QTabWidget::TabShape*>(_v) = tabShape(); break;
        case 7: *reinterpret_cast< QTabWidget::TabPosition*>(_v) = tabPosition(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setBackground(*reinterpret_cast< QBrush*>(_v)); break;
        case 1: setActivationOrder(*reinterpret_cast< WindowOrder*>(_v)); break;
        case 2: setViewMode(*reinterpret_cast< ViewMode*>(_v)); break;
        case 3: setDocumentMode(*reinterpret_cast< bool*>(_v)); break;
        case 4: setTabsClosable(*reinterpret_cast< bool*>(_v)); break;
        case 5: setTabsMovable(*reinterpret_cast< bool*>(_v)); break;
        case 6: setTabShape(*reinterpret_cast< QTabWidget::TabShape*>(_v)); break;
        case 7: setTabPosition(*reinterpret_cast< QTabWidget::TabPosition*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Beispiel #4
0
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
    if(!(event->buttons() & Qt::LeftButton) || !tabsClosable())
        return PlusTabBar::mouseMoveEvent(event);

    if((event->pos() - m_startDragPos).manhattanLength() < QApplication::startDragDistance())
        return PlusTabBar::mouseMoveEvent(event);

    int idx = tabAt(event->pos());
    if(idx == -1)
        return PlusTabBar::mouseMoveEvent(event);

    event->accept();

    QDrag *drag = new QDrag(this);

    tabView()->createSplitOverlay(m_id, drag);

    QStyleOptionTabV3 tab;
    initStyleOption(&tab, idx);

    QWidget *tabWidget = ((QTabWidget*)parent())->widget(idx);
    QPixmap wMap(tabWidget->size());
    tabWidget->render(&wMap);

    if(wMap.width() > 400 || wMap.height() > 400)
        wMap = wMap.scaled(400, 400, Qt::KeepAspectRatio,
                           sConfig.get(CFG_BOOL_SMOOTH_SCALING) ? Qt::SmoothTransformation : Qt::FastTransformation);

    QSize size = tabRect(idx).size();
    size.rwidth() = std::max(wMap.width(), size.width());
    size.rheight() += wMap.height();

    QPixmap map(size);
    map.fill(Qt::transparent);

    QStylePainter p(&map, this);
    p.initFrom(this);
    p.drawItemPixmap(QRect(0, tab.rect.height()-5, wMap.width(), wMap.height()), 0, wMap);

    tab.rect.moveTopLeft(QPoint(0, 0));
    p.drawControl(QStyle::CE_TabBarTab, tab);
    p.end();

    QMimeData *mime = new QMimeData();
    mime->setData("data/tabinfo", QString("%1 %2 %3").arg(m_id).arg(idx).arg(tabView()->getWindowId()).toLatin1());

    drag->setPixmap(map);
    drag->setMimeData(mime);
    drag->exec();
    delete drag;
}
Beispiel #5
0
void TabBar::hideCloseButton(int index)
{
    if (!validIndex(index) || tabsClosable()) {
        return;
    }

    CloseButton* button = qobject_cast<CloseButton*>(tabButton(index, closeButtonPosition()));
    if (!button) {
        return;
    }

    setTabButton(index, closeButtonPosition(), 0);
    button->deleteLater();
}
Beispiel #6
0
void ComboTabBar::setTabsClosable(bool closable)
{
    if (closable == tabsClosable()) {
        return;
    }

    if (closable) {
        // insert our close button
        for (int i = 0; i < m_mainTabBar->count(); ++i) {
            QWidget* closeButton = m_mainTabBar->tabButton(i, closeButtonPosition());
            if (closeButton) {
                if (closeButton->objectName() == QLatin1String("combotabbar_tabs_close_button")) {
                    continue;
                }
            }

            insertCloseButton(i + pinnedTabsCount());
            if (closeButton) {
                closeButton->deleteLater();
            }
        }
    }
    m_mainTabBar->setTabsClosable(closable);
}
Beispiel #7
0
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;
}
Beispiel #8
0
void TabWidget::slotSettingsChanged()
{
    if (tabsClosable() != Settings::closeButtonOnTabs())
        setTabsClosable(Settings::closeButtonOnTabs());
    d->updateTabBarVisibility();
}
Beispiel #9
0
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;
}