19#ifndef QX_RIBBON_PROP_CAN_CUSTOMIZE
20#define QX_RIBBON_PROP_CAN_CUSTOMIZE "_qx_isCanCustomize"
23QList<RibbonCustomizeData>
remove_indexs(
const QList<RibbonCustomizeData> &csd,
const QList<int> &willRemoveIndexs)
25 QList<RibbonCustomizeData> res;
27 for (
int i = 0; i < csd.size(); ++i) {
28 if (!willRemoveIndexs.contains(i)) {
39RibbonCustomizeData::RibbonCustomizeData()
42 , m_type(UnknowActionType)
52 , m_actionsManager(mgr)
182 group->removeAction(act);
192 if (-1 == currentindex) {
196 bar->
movePage(currentindex, toindex);
210 if (-1 == groupIndex) {
231 if (actindex <= -1) {
282 return m_actionsManager;
287 m_actionsManager = mgr;
291 const QString &objName)
299 qDebug() << QString(
"add page %1").arg(objName);
313 const QString &pageObjName,
const QString &objName)
321#ifdef QX_RIBBON_DEBUG
322 qDebug() << QString(
"add group %1 to page %2").arg(objName, pageObjName);
338 const QString &pageObjName,
339 const QString &groupObjName)
348 qDebug() << QString(
"add action %1 to %2/%3").arg(key, pageObjName, groupObjName);
357 if (pageObjName.isEmpty()) {
358 qDebug() << QObject::tr(
"Ribbon Warning !!! customize rename page,"
359 "but get an empty page object name,"
360 "if you want to customize Ribbon,"
361 "please make sure every element has been set object name.");
370 const QString &pageObjName,
371 const QString &groupObjName)
375 if (groupObjName.isEmpty() || pageObjName.isEmpty()) {
376 qDebug() << QObject::tr(
"Ribbon Warning !!! customize rename group,"
377 "but get an empty page/group object name,"
378 "if you want to customize Ribbon,"
379 "please make sure every element has been set object name.");
397 if (pageObjName.isEmpty()) {
398 qDebug() << QObject::tr(
"Ribbon Warning !!! customize change page order,"
399 "but get an empty page object name,"
400 "if you want to customize Ribbon,"
401 "please make sure every element has been set object name.");
404 qDebug() << QString(
"change page %1 order from %2 to %3").arg(pageObjName).arg(data.
indexValue).arg(moveIndex);
419 const QString &groupObjName,
int moveIndex)
423 if (pageObjName.isEmpty() || groupObjName.isEmpty()) {
424 qDebug() << QObject::tr(
"Ribbon Warning !!! customize change group order,"
425 "but get an empty page/group object name,"
426 "if you want to customize Ribbon,"
427 "please make sure every element has been set object name.");
430 qDebug() << QString(
"change group %1 order from %2 to %3").arg(groupObjName).arg(data.
indexValue).arg(moveIndex);
448 const QString &groupObjName,
454 if (pageObjName.isEmpty() || groupObjName.isEmpty() || key.isEmpty()) {
455 qDebug() << QObject::tr(
"Ribbon Warning !!! customize change action order,"
456 "but get an empty page/group/action object name,"
457 "if you want to customize Ribbon,"
458 "please make sure every element has been set object name.");
461 qDebug() << QString(
"change action %1 order from %2 to %3").arg(key).arg(data.
indexValue).arg(moveIndex);
474 if (pageObjName.isEmpty()) {
475 qDebug() << QObject::tr(
"Ribbon Warning !!! customize remove page,"
476 "but get an empty page object name,"
477 "if you want to customize Ribbon,"
478 "please make sure every element has been set object name.");
481 qDebug() << QString(
"remove page %1").arg(pageObjName);
488 const QString &groupObjName)
492 if (pageObjName.isEmpty() || groupObjName.isEmpty()) {
493 qDebug() << QObject::tr(
"Ribbon Warning !!! customize remove group,"
494 "but get an empty page/group object name,"
495 "if you want to customize Ribbon,"
496 "please make sure every element has been set object name.");
499 qDebug() << QString(
"remove group %1 from page %2").arg(groupObjName, pageObjName);
515 const QString &groupObjName,
const QString &key,
520 if (pageObjName.isEmpty() || groupObjName.isEmpty() || key.isEmpty()) {
521 qDebug() << QObject::tr(
"Ribbon Warning !!! customize remove action,"
522 "but get an empty page/group/action object name,"
523 "if you want to customize Ribbon,"
524 "please make sure every element has been set object name.");
527 qDebug() << QString(
"remove action %1 from %2/%3").arg(key, pageObjName, groupObjName);
545 if (pageObjName.isEmpty()) {
546 qDebug() << QObject::tr(
"Ribbon Warning !!! customize visible page,"
547 "but get an empty page object name,"
548 "if you want to customize Ribbon,"
549 "please make sure every element has been set object name.");
586 int size = csd.size();
591 QList<RibbonCustomizeData> res;
592 QList<int> willRemoveIndexs;
596 for (
int i = 0; i < size; ++i) {
598 for (
int j = i + 1; j < size; ++j) {
603 willRemoveIndexs << i << j;
608 for (
int j = i + 1; j < size; ++j) {
614 willRemoveIndexs << i << j;
619 for (
int j = i + 1; j < size; ++j) {
625 willRemoveIndexs << i << j;
632 willRemoveIndexs.clear();
637 QList<int> willNotCheckIndexs;
639 for (
int i = 0; i < size; ++i) {
642 if (willRemoveIndexs.contains(i) || willNotCheckIndexs.contains(i)) {
646 for (
int j = i + 1; j < size; ++j) {
649 willRemoveIndexs << last;
655 willNotCheckIndexs << last;
659 willNotCheckIndexs.clear();
661 willRemoveIndexs.clear();
665 QList<int> willRenameIndexs;
666 for (
int i = 0; i < size; ++i) {
670 for (
int j = i + 1; j < size; ++j) {
673 willRemoveIndexs << last;
677 willRenameIndexs << last;
681 for (
int j = i + 1; j < size; ++j) {
685 willRemoveIndexs << last;
689 willRenameIndexs << last;
693 willRemoveIndexs.clear();
696 foreach (
int i, willRenameIndexs) {
698 for (
int j = 0; j < i; ++j) {
700 res[j].keyValue = res[i].keyValue;
705 for (
int j = 0; j < i; ++j) {
708 res[j].keyValue = res[i].keyValue;
715 willRenameIndexs.clear();
719 for (
int i = 1; i < size; ++i) {
724 res[i].indexValue += res[i - 1].indexValue;
725 willRemoveIndexs << i - 1;
731 res[i].indexValue += res[i - 1].indexValue;
732 willRemoveIndexs << i - 1;
738 res[i].indexValue += res[i - 1].indexValue;
739 willRemoveIndexs << i - 1;
743 willRemoveIndexs.clear();
747 for (
int i = 0; i < size; ++i) {
751 willRemoveIndexs << i;
756 willRemoveIndexs.clear();
QAction * action(const QString &key) const
通过key获取action
RibbonBar 继承 QMenuBar, 在 RibbonWindow 中直接替换了原来的 QMenuBar
RibbonPage * insertPage(int index, const QString &title)
void movePage(int from, int to)
int pageIndex(RibbonPage *page) const
void showPage(RibbonPage *page)
显示被隐藏的page
void removePage(RibbonPage *page)
移除RibbonPage
RibbonPage * pageByObjectName(const QString &objname) const
通过ObjectName查找Page
void hidePage(RibbonPage *page)
隐藏page,并不会删除或者取走,只是隐藏
static RibbonCustomizeData makeChangeGroupOrderCustomizeData(const QString &pageObjName, const QString &groupObjName, int moveIndex)
对应ChangeGroupOrderActionType
void setActionsManager(RibbonActionsManager *mgr)
static void setCanCustomize(QObject *obj, bool canbe=true)
QString pageObjNameValue
记录pageObjName,用于定位Page
static QList< RibbonCustomizeData > simplify(const QList< RibbonCustomizeData > &csd)
对QList<RibbonCustomizeData>进行简化操作
ActionType actionType() const
获取CustomizeData的action type
static RibbonCustomizeData makeRemoveGroupCustomizeData(const QString &pageObjName, const QString &groupObjName)
static RibbonCustomizeData makeAddPageCustomizeData(const QString &title, int index, const QString &objName)
static RibbonCustomizeData makeAddGroupCustomizeData(const QString &title, int index, const QString &pageObjName, const QString &objName)
创建一个AddGroupActionType的RibbonCustomizeData
bool isValid() const
判断是否是一个正常的CustomizeData
@ RemoveGroupActionType
删除group操作
@ AddPageActionType
添加page操作
@ VisiblePageActionType
对page执行隐藏/显示操作
@ ChangePageOrderActionType
改变page顺序的操作
@ AddActionActionType
添加action操作
@ RenamePageActionType
对page更名操作
@ RenameGroupActionType
对Group更名操作
@ ChangeActionOrderActionType
改变action顺序的操作
@ RemovePageActionType
删除page操作
@ ChangeGroupOrderActionType
改变group顺序的操作
@ RemoveActionActionType
删除action操作
@ AddGroupActionType
添加group操作
static RibbonCustomizeData makeVisiblePageCustomizeData(const QString &pageObjName, bool isShow)
RibbonCustomizeData::makeVisiblePageCustomizeData
static RibbonCustomizeData makeRemovePageCustomizeData(const QString &pageObjName)
QString keyValue
记录标题、索引等参数
static RibbonCustomizeData makeRenamePageCustomizeData(const QString &newName, const QString &pageObjName)
static RibbonCustomizeData makeRenameGroupCustomizeData(const QString &newName, const QString &pageObjName, const QString &groupObjName)
static RibbonCustomizeData makeRemoveActionCustomizeData(const QString &pageObjName, const QString &groupObjName, const QString &key, RibbonActionsManager *mgr)
对应RemoveActionActionType
static RibbonCustomizeData makeChangeActionOrderCustomizeData(const QString &pageObjName, const QString &groupObjName, const QString &key, RibbonActionsManager *mgr, int moveIndex)
对应ChangeActionOrderActionType
QString groupObjNameValue
记录groupObjName,ribbon的Customize索引大部分基于objname
static RibbonCustomizeData makeChangePageOrderCustomizeData(const QString &pageObjName, int moveIndex)
对应ChangePageOrderActionType
static bool isCanCustomize(QObject *obj)
static RibbonCustomizeData makeAddActionCustomizeData(const QString &key, RibbonActionsManager *mgr, RibbonGroup::RowProportion rp, const QString &pageObjName, const QString &groupObjName)
添加action
RibbonActionsManager * actionsManager()
bool apply(RibbonBar *bar)
应用RibbonCustomizeData到RibbonBar
RibbonGroup::RowProportion actionRowProportionValue
RibbonCustomizeData()
RibbonCustomizeData
void setActionType(ActionType a)
设置CustomizeData的action type
group 用于对 ribbon 页窗口中的控件进行分组
RibbonButton * addAction(QAction *action, RibbonGroup::RowProportion rp)
添加action
void moveAction(int from, int to)
移动action
int actionIndex(QAction *act) const
action对应的布局index,此操作一般用于移动,其他意义不大
bool removeGroup(RibbonGroup *group)
移除Group,Page会直接回收RibbonGroup内存
void moveGroup(int from, int to)
移动一个Group从from index到to index
RibbonGroup * insertGroup(int index, const QString &title)
新建一个group,并插入到index位置
int groupIndex(RibbonGroup *group) const
查找group对应的索引
RibbonGroup * groupByObjectName(const QString &objname) const
通过ObjectName查找group
QList< RibbonCustomizeData > remove_indexs(const QList< RibbonCustomizeData > &csd, const QList< int > &willRemoveIndexs)
#define Q_NULLPTR
Copyleft (C) 2025 maminjie canpool@163.com SPDX-License-Identifier: MulanPSL-2.0
#define QX_RIBBON_END_NAMESPACE
#define QX_RIBBON_BEGIN_NAMESPACE
#define QX_RIBBON_PROP_CAN_CUSTOMIZE
属性,用于标记是否可以进行自定义,用于动态设置到 RibbonPage 和 RibbonGroup, 值为bool,在为true时,可以通过 RibbonCustomizeWidget 改变这个Ribb...