You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
7.6 KiB
C

#ifndef SARIBBONCUSTOMIZEWIDGET_H
#define SARIBBONCUSTOMIZEWIDGET_H
#include "SARibbonGlobal.h"
#include <QWidget>
#include "SARibbonActionsManager.h"
#include "SARibbonPannel.h"
#include "SARibbonCustomizeData.h"
// SARibbonCustomizeWidget 特有
class SARibbonCustomizeWidgetUi;
class SARibbonMainWindow;
class SARibbonBar;
//
class QStandardItemModel;
class QStandardItem;
class QAbstractButton;
//
class QXmlStreamWriter;
class QXmlStreamReader;
/**
* @brief
*
* @note SARibbon@ref sa_apply_customize_from_xml_file
* @ref SARibbonCustomizeWidget::fromXml
*/
class SA_RIBBON_EXPORT SARibbonCustomizeWidget : public QWidget
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonCustomizeWidget)
public:
//保留接口
SARibbonCustomizeWidget(SARibbonMainWindow* ribbonWindow, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
//对于不使用SARibbonMainWindow的情况使用此构造函数
SARibbonCustomizeWidget(SARibbonBar* ribbonbar, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~SARibbonCustomizeWidget();
/**
* @brief ribbon
*/
enum RibbonTreeShowType
{
ShowAllCategory, ///< 显示所有Category包括contextcategory
ShowMainCategory ///< 显示主要的category不包含上下文
};
/**
* @brief QStandardItemrole
*/
enum ItemRole
{
LevelRole = Qt::UserRole + 1, ///< 代表这是层级有0category 1pannel 2item
PointerRole = Qt::UserRole + 2, ///< 代表这是存放指针。根据LevelRole来进行转
CanCustomizeRole = Qt::UserRole + 3, ///< 代表个item是可以自定义的.bool
CustomizeRole = Qt::UserRole + 4, ///< 代表这个是自定义的item,bool,主要用于那些自己添加的标签和pannel有此角色必有CanCustomizeRole
CustomizeObjNameRole = Qt::UserRole + 5 ///< 记录了临时的自定义内容的obj名 QString
};
//设置action管理器
void setupActionsManager(SARibbonActionsManager* mgr);
//判断用户是否有要存储的内容对应save动作
bool isApplied() const;
//判断用户是否有改动内容对应apply动作
bool isCached() const;
//获取model
const QStandardItemModel* model() const;
//根据当前的radiobutton选项来更新model
void updateModel();
//更新model
void updateModel(RibbonTreeShowType type);
//应用所有的设定
bool applys();
//转换为xml
bool toXml(QXmlStreamWriter* xml) const;
bool toXml(const QString& xmlpath) const;
//从xml中加载QList<SARibbonCustomizeData>,对于基于配置文件的设置,对话框显示前建议调用此函数,保证叠加设置的正确记录
void fromXml(QXmlStreamReader* xml);
void fromXml(const QString& xmlpath);
//应用xml配置可以结合customize_datas_from_xml和customize_datas_apply函数
static bool fromXml(QXmlStreamReader* xml, SARibbonBar* bar, SARibbonActionsManager* mgr);
//缓存应用的动作,这些动作不会被clear清除用于本地存储
void makeActionsApplied();
//清除applied的动作cancel操作后需要清空已应用的动作
void clearApplied();
//清除缓存动作在执行applys函数后如果要继续调用应该clear否则会导致异常
void clearCache();
//清除所有动作,不包含本地读取的数据
void clear();
protected:
//把QList<SARibbonCustomizeData>进行裁剪,把一些动作合并
void simplify();
SARibbonPannelItem::RowProportion selectedRowProportion() const;
QAction* selectedAction() const;
QAction* itemToAction(QStandardItem* item) const;
QStandardItem* selectedItem() const;
//获取选中的ribbon tree 的level
int selectedRibbonLevel() const;
//根据选中的item判断
int itemLevel(QStandardItem* item) const;
//设置某个item被选中
void setSelectItem(QStandardItem* item, bool ensureVisible = true);
//判断itemn能否改动可以改动返回true
bool isItemCanCustomize(QStandardItem* item) const;
bool isSelectedItemCanCustomize() const;
//判断item是否是自定义的item
bool isCustomizeItem(QStandardItem* item) const;
bool isSelectedItemIsCustomize() const;
//删除一个item
void removeItem(QStandardItem* item);
private slots:
void onComboBoxActionIndexCurrentIndexChanged(int index);
void onRadioButtonGroupButtonClicked(QAbstractButton* b);
void onPushButtonNewCategoryClicked();
void onPushButtonNewPannelClicked();
void onPushButtonRenameClicked();
void onPushButtonAddClicked();
void onPushButtonDeleteClicked();
void onListViewSelectClicked(const QModelIndex& index);
void onTreeViewResultClicked(const QModelIndex& index);
void onToolButtonUpClicked();
void onToolButtonDownClicked();
void onItemChanged(QStandardItem* item);
void onLineEditSearchActionTextEdited(const QString& text);
void onPushButtonResetClicked();
private:
void init(SARibbonBar* ribbonbar);
void initConnection();
private:
SARibbonCustomizeWidgetUi* ui;
};
/**
* @brief xml
*
* elementdocumentdocument
* QXmlStreamWriter::writeStartDocument(),QXmlStreamWriter::writeEndDocument()
* @param xml QXmlStreamWriter
* @note QXmlStreamWriterutf-8:xml->setCodec("utf-8");
* @note QXmlStreamWriterQStringio
* QXmlStreamWriterQStringstringQByteArray
* @param cds QList<SARibbonCustomizeData>
* @return false,false
*/
bool SA_RIBBON_EXPORT sa_customize_datas_to_xml(QXmlStreamWriter* xml, const QList< SARibbonCustomizeData >& cds);
/**
* @brief xmlQList<SARibbonCustomizeData>
* @param xml
* @return QList<SARibbonCustomizeData>
*/
QList< SARibbonCustomizeData > SA_RIBBON_EXPORT sa_customize_datas_from_xml(QXmlStreamReader* xml, SARibbonActionsManager* mgr);
/**
* @brief QList<SARibbonCustomizeData>
* @param cds
* @param w SARibbonBar
* @return
*/
int SA_RIBBON_EXPORT sa_customize_datas_apply(const QList< SARibbonCustomizeData >& cds, SARibbonBar* w);
/**
* @brief
* @param cds
* @param w SARibbonBar
* @return
*/
int SA_RIBBON_EXPORT sa_customize_datas_reverse(const QList< SARibbonCustomizeData >& cds, SARibbonBar* w);
/**
* @brief xmlribbonribbon
* @param filePath xml
* @param w
* @param mgr action
* @return true
* @note
* @code
* static bool has_call = false;
* if (!has_call) {
* has_call = sa_apply_customize_from_xml_file("customize.xml", this, m_actMgr);
* }
* @endcode
*/
bool SA_RIBBON_EXPORT sa_apply_customize_from_xml_file(const QString& filePath, SARibbonBar* bar, SARibbonActionsManager* mgr);
#endif // SARIBBONCUSTOMIZEWIDGET_H