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.

95 lines
3.7 KiB
C

#ifndef SARIBBONMAINWINDOW_H
#define SARIBBONMAINWINDOW_H
#include "SARibbonGlobal.h"
#include <QMainWindow>
#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
class SAFramelessHelper;
#endif
class QAction;
class SARibbonBar;
class SARibbonSystemButtonBar;
class QScreen;
/**
* @brief 使SARibbonBar使QMainWindow
*
* ribbonToolbar
* SARibbonBar使QMainWindowSARibbonMainWindow,
* SARibbonMainWindowQMainWindow使https://github.com/wangwenx190/framelesshelper
* useRibbon使ribbontrue
*
* @code
* SARibbonMainWindow(QWidget* parent = nullptr,bool useRibbon = true);
* @endcode
*
* ribbonuseRibbonfalse,
* isUseRibbonribbonToolbarribbon
*
* @code
* bool isUseRibbon() const;
* @endcode
*
* @ref SARibbonMainWindow ribbon@ref RibbonTheme
* @ref setRibbonTheme ribbonqss
*
*/
class SA_RIBBON_EXPORT SARibbonMainWindow : public QMainWindow
{
Q_OBJECT
SA_RIBBON_DECLARE_PRIVATE(SARibbonMainWindow)
friend class SARibbonBar;
Q_PROPERTY(SARibbonTheme ribbonTheme READ ribbonTheme WRITE setRibbonTheme)
public:
SARibbonMainWindow(QWidget* parent = nullptr, bool useRibbon = true, const Qt::WindowFlags flags = {});
~SARibbonMainWindow() Q_DECL_OVERRIDE;
// 返回SARibbonBar
SARibbonBar* ribbonBar() const;
// 设置ribbonbar
void setRibbonBar(SARibbonBar* bar);
#if !SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
// 返回SAFramelessHelper
SAFramelessHelper* framelessHelper();
#else
// 如果ribbon中有自定义的窗口在标题栏等非点击区域加入后想能点击需要调用此接口告知可点击
void setFramelessHitTestVisible(const QWidget* w, bool visible = true);
#endif
// 此函数仅用于控制最小最大化和关闭按钮的显示
void updateWindowFlag(Qt::WindowFlags flags);
// 注意主题在构造函数设置主题会不完全生效使用QTimer投放到队列最后执行即可
// QTimer::singleShot(0, this, [ this ]() { this->setRibbonTheme(SARibbonMainWindow::RibbonThemeDark); });
void setRibbonTheme(SARibbonTheme theme);
SARibbonTheme ribbonTheme() const;
// 判断当前是否使用ribbon模式
bool isUseRibbon() const;
// 把ribbonbar的事件传递到frameless
virtual bool eventFilter(QObject* obj, QEvent* e) Q_DECL_OVERRIDE;
// 获取最大化最小化关闭按钮所在的bar。可以通过此函数在最大最小化按钮旁边设置内容
SARibbonSystemButtonBar* windowButtonBar() const;
protected:
// 创建ribbonbar的工厂函数
SARibbonBar* createRibbonBar();
virtual void resizeEvent(QResizeEvent* e) Q_DECL_OVERRIDE;
virtual void changeEvent(QEvent* e) Q_DECL_OVERRIDE;
private slots:
void onPrimaryScreenChanged(QScreen* screen);
};
/**
* @brief ribbon theme
*
* SARibbonBarSARibbonMainWindow
* SARibbonMainWindowSARibbonMainWindow@sa sa_set_ribbon_theme
* 使
* @code
* @endcode
*
* @param w
* @param theme
*/
void SA_RIBBON_EXPORT sa_set_ribbon_theme(QWidget* w, SARibbonTheme theme);
#endif // SARIBBONMAINWINDOW_H