当前位置: 首页>>代码示例>>C++>>正文


C++ TabBar::updatePinnedTabCloseButton方法代码示例

本文整理汇总了C++中TabBar::updatePinnedTabCloseButton方法的典型用法代码示例。如果您正苦于以下问题:C++ TabBar::updatePinnedTabCloseButton方法的具体用法?C++ TabBar::updatePinnedTabCloseButton怎么用?C++ TabBar::updatePinnedTabCloseButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TabBar的用法示例。


在下文中一共展示了TabBar::updatePinnedTabCloseButton方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tabSizeHint

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;

//.........这里部分代码省略.........
开发者ID:solodyagin,项目名称:qupzilla,代码行数:101,代码来源:tabbar.cpp

示例2: tabSizeHint


//.........这里部分代码省略.........

            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;
}
开发者ID:ff2000,项目名称:qupzilla,代码行数:101,代码来源:tabbar.cpp


注:本文中的TabBar::updatePinnedTabCloseButton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。