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.

125 lines
4.0 KiB
C

#ifndef SARIBBONGALLERY_H
#define SARIBBONGALLERY_H
#include "SARibbonGlobal.h"
#include <QFrame>
#include <QToolButton>
#include "SARibbonGalleryGroup.h"
#include <QSizeGrip>
class QLabel;
class QVBoxLayout;
class SARibbonGalleryViewport;
/**
* @brief SARibbonGallery
*/
class SA_RIBBON_EXPORT SARibbonGalleryButton : public QToolButton
{
Q_OBJECT
public:
SARibbonGalleryButton(QWidget* parent = 0);
};
/**
* @brief Gallery
*
* Gallery@sa SARibbonGalleryGroup @sa SARibbonGalleryViewport
*
* @sa SARibbonGalleryGroup @sa QListView actionsiconQListView
*
* @sa SARibbonGalleryViewport SARibbonGalleryGroup
*
*
* @code
* SARibbonGallery* gallery = pannel1->addGallery();
* QList< QAction* > galleryActions;
* ...create many actions ...
* SARibbonGalleryGroup* group1 = gallery->addCategoryActions(tr("Files"), galleryActions);
* galleryActions.clear();
* ...create many actions ...
* gallery->addCategoryActions(tr("Apps"), galleryActions);
* gallery->setCurrentViewGroup(group1);
* @endcode
*/
class SA_RIBBON_EXPORT SARibbonGallery : public QFrame
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonGallery)
public:
SARibbonGallery(QWidget* parent = 0);
virtual ~SARibbonGallery();
virtual QSize sizeHint() const Q_DECL_OVERRIDE;
// 添加一个GalleryGroup
SARibbonGalleryGroup* addGalleryGroup();
// 添加一个GalleryGroup
void addGalleryGroup(SARibbonGalleryGroup* group);
// 快速添加一组actions
SARibbonGalleryGroup* addCategoryActions(const QString& title, QList< QAction* > actions);
// 设置当前显示的SARibbonGalleryGroup
void setCurrentViewGroup(SARibbonGalleryGroup* group);
// 获取当前显示的SARibbonGalleryGroup
SARibbonGalleryGroup* currentViewGroup() const;
// 获取弹出窗口指针
SARibbonGalleryViewport* getPopupViewPort() const;
public:
// 设置最右边三个控制按钮的最大宽度默认15
static void setGalleryButtonMaximumWidth(int w);
signals:
/**
* @brief SARibbonGalleryGroup::triggered
* SARibbonGalleryactionQActionGroup,@sa getActionGroup actiongroup
* @param action
*/
void triggered(QAction* action);
/**
* @brief SARibbonGalleryGroup::hovered
* @note SARibbonGalleryGroup::setMouseTracking(true)
* @param action
*/
void hovered(QAction* action);
public slots:
// 上翻页
virtual void pageUp();
// 下翻页
virtual void pageDown();
// 显示更多触发默认弹出内部管理的SARibbonGalleryViewport用户可重载此函数实现自定义的弹出
virtual void showMoreDetail();
protected slots:
void onItemClicked(const QModelIndex& index);
virtual void onTriggered(QAction* action);
private:
SARibbonGalleryViewport* ensureGetPopupViewPort();
protected:
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
};
///
/// \brief SARibbonGallery的Viewport class
///
class SARibbonGalleryViewport : public QWidget
{
Q_OBJECT
public:
SARibbonGalleryViewport(QWidget* parent);
// 添加窗口不带标题
void addWidget(QWidget* w);
// 添加窗口,带标题
void addWidget(QWidget* w, const QString& title);
// 通过SARibbonGalleryGroup获取对应的标题用户可以通过此函数设置QLabel的属性
QLabel* titleLabel(QWidget* w);
// 移除窗口
void removeWidget(QWidget* w);
public slots:
void onTitleChanged(QWidget* w, const QString& title);
private:
QVBoxLayout* m_layout;
QMap< QWidget*, QLabel* > _widgetToTitleLable; ///< QWidget和lable的对应
};
#endif // SARIBBONGALLERY_H