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++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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
*
* 由于ribbon的风格和传统的Toolbar风格差异较大
* SARibbonBar使用需要把原有的QMainWindow替换为SARibbonMainWindow,
* SARibbonMainWindow是个无边框窗体继承自QMainWindow目前使用第三方的无边框方案https://github.com/wangwenx190/framelesshelper
* 其构造函数的参数useRibbon用于指定是否使用ribbon风格默认为true
*
* @code
* SARibbonMainWindow(QWidget* parent = nullptr,bool useRibbon = true);
* @endcode
*
* 如果想换回非ribbon风格只需要把useRibbon设置为false即可,
* 成员函数isUseRibbon用于判断当前是否为ribbon模式这个函数在兼容传统Toolbar风格和ribbon风格时非常有用。
*
* @code
* bool isUseRibbon() const;
* @endcode
*
* @ref SARibbonMainWindow 提供了几种常用的ribbon样式样式可见@ref RibbonTheme
* 通过@ref setRibbonTheme 可改变ribbon的样式用户也可通过qss自己定义自己的样式
*
*/
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函数
*
* 之所以提供此函数是因为在某些情况下SARibbonBar不用在SARibbonMainWindow情况下的时候也需要设置主题
* 但主题设置是在SARibbonMainWindow下的为了能在非SARibbonMainWindow下也能设置主题这里提供@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