Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加category或左侧快捷按钮及右侧按钮群没有排序功能 #60

Open
xinchangli opened this issue Nov 16, 2022 · 0 comments

Comments

@xinchangli
Copy link
Contributor

不知是不是我没找到对应的接口,我只看到有insert接口,

SARibbonCategory* insertCategoryPage(const QString& title, int index);
void insertCategoryPage(SARibbonCategory* category, int index);

void SARibbonBar::insertCategoryPage(SARibbonCategory* category, int index)
{
    if (nullptr == category) {
        return;
    }
    category->setRibbonPannelLayoutMode(isTwoRowStyle() ? SARibbonPannel::TwoRowMode : SARibbonPannel::ThreeRowMode);
    int i = m_d->_ribbonTabBar->insertTab(index, category->windowTitle());

    _SARibbonTabData tabdata;

    tabdata.category = category;
    tabdata.index    = i;
    m_d->_ribbonTabBar->setTabData(i, QVariant::fromValue(tabdata));
    m_d->_stackedContainerWidget->insertWidget(index, category);

    connect(category, &QWidget::windowTitleChanged, this, &SARibbonBar::onCategoryWindowTitleChanged);
    QApplication::postEvent(this, new QResizeEvent(size(), size()));
}

但是这个接口的方式利用的是tabbar和stack widget的插入功能,单单只通过index索引是无法有效控制插入顺序的,例如,定义category1的索引为20,category2的索引为21,但在无法确定category1和category2的插入谁先进行时,还是无法保证这两个category谁在前,因为如果他们都超过的容器的size那将都添加到最后,这种情况在独立插件或模块中使用时比较明显,介于此我在本地代码中加入了排序功能,我的思路是给category添加了ID属性,用ID的大小来计算索引,

...

    //通过ID判断插入顺序
    int index;
    auto listCategoryPages = CategoryPages();
    if(listCategoryPages.isEmpty())
    {
        index = d->ribbonTabBar->insertTab(0, category->windowTitle());
    }
    else
    {
        bool bFind = false;
        for(auto c : listCategoryPages)
        {
            if(c->CategoryID() > category->CategoryID())
            {
                index = listCategoryPages.indexOf(c);
                bFind = true;
                break;
            }
        }

        //没找到说明最大,插入到最后
        if(!bFind)
        {
            index = d->ribbonTabBar->insertTab(listCategoryPages.size(), category->windowTitle());
        }
        else
        {
            index = d->ribbonTabBar->insertTab(index, category->windowTitle());
        }
    }

    category->SetRibbonPannelLayoutMode(IsTwoRowStyle() ? RibbonPannel::TwoRowMode : RibbonPannel::ThreeRowMode);

...

这样一来ID也不必连续,也方便新添加的category定义ID,通常每个ID之间都会有10或100的间距,给后续的category以空间。
希望可以改善此功能,快捷区那里是一样的道理,

void SARibbonButtonGroupWidget::actionEvent(QActionEvent* e)

这里我就简单在添加时给QAction::setData()了;目的都是添加一个ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant