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.

138 lines
5.1 KiB
C

#ifndef SARIBBONGALLERYGROUP_H
#define SARIBBONGALLERYGROUP_H
#include "SARibbonGlobal.h"
#include <QList>
#include <QListView>
#include <QStyledItemDelegate>
#include "SARibbonGalleryItem.h"
///
/// \brief SARibbonGalleryGroup对应的显示代理
///
class SA_RIBBON_EXPORT SARibbonGalleryGroupItemDelegate : public QStyledItemDelegate
{
public:
SARibbonGalleryGroupItemDelegate(SARibbonGalleryGroup* group, QObject* parent = Q_NULLPTR);
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const Q_DECL_OVERRIDE;
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const Q_DECL_OVERRIDE;
virtual void paintIconOnly(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paintIconWithText(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paintIconWithTextWordWrap(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
SARibbonGalleryGroup* m_group;
};
///
/// \brief SARibbonGalleryGroup对应的model
///
class SA_RIBBON_EXPORT SARibbonGalleryGroupModel : public QAbstractListModel
{
Q_OBJECT
public:
SARibbonGalleryGroupModel(QObject* parent = Q_NULLPTR);
~SARibbonGalleryGroupModel();
virtual int rowCount(const QModelIndex& parent) const Q_DECL_OVERRIDE;
virtual Qt::ItemFlags flags(const QModelIndex& index) const Q_DECL_OVERRIDE;
virtual QVariant data(const QModelIndex& index, int role) const Q_DECL_OVERRIDE;
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const Q_DECL_OVERRIDE;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role) Q_DECL_OVERRIDE;
void clear();
SARibbonGalleryItem* at(int row) const;
void insert(int row, SARibbonGalleryItem* item);
SARibbonGalleryItem* take(int row);
void append(SARibbonGalleryItem* item);
private:
QList< SARibbonGalleryItem* > m_items;
};
/**
* @brief Gallery
*
* Gallery Item
*/
class SA_RIBBON_EXPORT SARibbonGalleryGroup : public QListView
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonGalleryGroup)
public:
/**
* @brief GalleryGroup
*/
enum GalleryGroupStyle
{
IconWithText, ///< 图标带文字
IconWithWordWrapText, ///< 图标带文字,文字会换行显示此模式只会对DisplayOneRow生效如果不是DisplayOneRow等同IconWithText
IconOnly ///< 只有图标
};
/**
* @brief Gallerypannel
*/
enum DisplayRow
{
DisplayOneRow = 1, ///< 显示1行默认
DisplayTwoRow = 2,
DisplayThreeRow = 3
};
SARibbonGalleryGroup(QWidget* w = 0);
virtual ~SARibbonGalleryGroup();
// 重新计算grid尺寸
void setRecalcGridSizeBlock(bool on = true);
bool isRecalcGridSizeBlock() const;
void recalcGridSize();
void recalcGridSize(int galleryHeight);
// 设置显示的样式
void setGalleryGroupStyle(GalleryGroupStyle style);
GalleryGroupStyle galleryGroupStyle() const;
// 添加一个item
void addItem(const QString& text, const QIcon& icon);
void addItem(SARibbonGalleryItem* item);
// 以一个aciton作为item添加
void addActionItem(QAction* act);
void addActionItemList(const QList< QAction* >& acts);
// 构建一个model这个model的父类是SARibbonGalleryGroup如果要共享model需要手动处理model的父类
void setupGroupModel();
SARibbonGalleryGroupModel* groupModel();
// 标题
void setGroupTitle(const QString& title);
QString groupTitle() const;
void selectByIndex(int i);
// 设置显示的行数
void setDisplayRow(DisplayRow r);
DisplayRow displayRow() const;
// 设置grid最小的宽度默认为0不限制可以限定grid的宽度
void setGridMinimumWidth(int w);
int gridMinimumWidth() const;
// 设置grid最大的宽度默认为0不限制可以限定grid的宽度
void setGridMaximumWidth(int w);
int gridMaximumWidth() const;
// 获取SARibbonGalleryGroup管理的actiongroup
QActionGroup* actionGroup() const;
private slots:
void onItemClicked(const QModelIndex& index);
void onItemEntered(const QModelIndex& index);
signals:
void groupTitleChanged(const QString& title);
/**
* @brief QActionGrouptriggered
* SARibbonGalleryGroupactionQActionGroup,@sa getActionGroup actiongroup
* @param action
*/
void triggered(QAction* action);
/**
* @brief QActionGrouptriggered
* SARibbonGalleryGroupactionQActionGroup,@sa getActionGroup actiongroup
* @note QAbstractItemView::entered(const QModelIndex &index)setMouseTracking(true)
* @param action
*/
void hovered(QAction* action);
};
#endif // SARIBBONGALLERYGROUP_H