Initial commit of BudgetPro
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
#if _MSC_VER >= 1600
|
||||
#pragma execution_character_set("utf-8")
|
||||
#endif
|
||||
#include <QMenuBar>
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <QPixmap>
|
||||
#include <QBitmap>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QDockWidget>
|
||||
#include <QTreeWidget>
|
||||
#include <QStatusBar>
|
||||
|
||||
//#include "SgfPlatformCore.h"
|
||||
//#include "SgfSingleCoreObjectImpl.h"
|
||||
//#include "SgfCoreManager.h"
|
||||
|
||||
#include "QsfMainWindow.h"
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
QsfWorkWindow::QsfWorkWindow(QWidget *parent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
|
||||
#else
|
||||
QsfWorkWindow::QsfWorkWindow(QWidget *parent /* = 0 */, Qt::WFlags flags /* = 0 */)
|
||||
#endif
|
||||
|
||||
:QMainWindow(parent,flags)
|
||||
{
|
||||
setObjectName("QsfWorkWindow");
|
||||
|
||||
//允许嵌套dock
|
||||
setDockNestingEnabled(true);
|
||||
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
|
||||
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
|
||||
|
||||
m_workspace = new QTabWidget;
|
||||
setCentralWidget(m_workspace);
|
||||
m_workspace->setTabsClosable(false);
|
||||
|
||||
/*状态条*/
|
||||
QStatusBar* statusBar = new QStatusBar();
|
||||
statusBar->setObjectName("QsfStatuBar");
|
||||
this->setStatusBar(statusBar);
|
||||
|
||||
this->setStatusTip("自定义程序框架 V1.0 作者: 梁振 liang1057@163.com");
|
||||
}
|
||||
|
||||
QsfWorkWindow::~QsfWorkWindow()
|
||||
{
|
||||
delete m_workspace;
|
||||
}
|
||||
|
||||
|
||||
QWidget* QsfWorkWindow::getCurrentTabWidget()
|
||||
{
|
||||
if (m_workspace != NULL)
|
||||
{
|
||||
return m_workspace->currentWidget();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
QWidget * QsfWorkWindow::currentTabWidget()
|
||||
{
|
||||
return getCurrentTabWidget();
|
||||
}
|
||||
|
||||
QTabWidget* QsfWorkWindow::workSpace()
|
||||
{
|
||||
return m_workspace;
|
||||
}
|
||||
|
||||
void QsfMainWindow::createMainWindow()
|
||||
{
|
||||
//将参数管理器注册到核心中
|
||||
//REGIST_OBJECT(QsfMainWindow);
|
||||
}
|
||||
|
||||
QsfMainWindow::QsfMainWindow()
|
||||
{
|
||||
resize(800,600);
|
||||
int alpha = 255;
|
||||
this->setWindowOpacity(alpha);
|
||||
setObjectName("SYS_QsfMainWindow");
|
||||
|
||||
Qt::WindowFlags myWinFlags = Qt::WindowFlags();
|
||||
myWinFlags |= Qt::FramelessWindowHint; // 不可调整大小
|
||||
myWinFlags |= Qt::CustomizeWindowHint;
|
||||
setWindowFlags(myWinFlags);
|
||||
//setAttribute(Qt::WA_TranslucentBackground); //背景透明
|
||||
|
||||
QVBoxLayout* tMainVB = new QVBoxLayout;
|
||||
tMainVB->setSpacing(0);
|
||||
tMainVB->setContentsMargins(0,0,0,0);
|
||||
this->setLayout(tMainVB);
|
||||
|
||||
m_titleBar = new QsfTitleBar;
|
||||
tMainVB->addWidget(m_titleBar);
|
||||
|
||||
m_tableMenu = new QTabWidget;
|
||||
m_tableMenu->setMaximumHeight(150);
|
||||
tMainVB->addWidget(m_tableMenu);
|
||||
|
||||
m_workWindow = new QsfWorkWindow;
|
||||
tMainVB->addWidget(m_workWindow);
|
||||
}
|
||||
|
||||
QsfMainWindow::~QsfMainWindow()
|
||||
{
|
||||
delete m_titleBar;
|
||||
delete m_workWindow;
|
||||
|
||||
//清理参数管理器
|
||||
}
|
||||
|
||||
QDockWidget* QsfMainWindow::createDockWidget( QString title, QString name, Qt::DockWidgetArea area )
|
||||
{
|
||||
QDockWidget* tDock = new QDockWidget(title);
|
||||
|
||||
SgfParamManager::GetInstance()->addParam(name.toStdString(), tDock);
|
||||
m_workWindow->addDockWidget(area, tDock);
|
||||
QWidget* docWid1 = new QWidget;
|
||||
tDock->setWidget(docWid1);
|
||||
return tDock;
|
||||
}
|
||||
|
||||
void QsfMainWindow::addDockWidget( QDockWidget* tDock, QString title, Qt::DockWidgetArea area )
|
||||
{
|
||||
m_workWindow->addDockWidget(area, tDock);
|
||||
QWidget* docWid1 = new QWidget;
|
||||
tDock->setWidget(docWid1);
|
||||
}
|
||||
|
||||
|
||||
QWidget* QsfMainWindow::createWorkWidget( QString title, QString name )
|
||||
{
|
||||
QWidget* tWidget = new QWidget();
|
||||
tWidget->setWindowTitle(title);
|
||||
SgfParamManager::GetInstance()->addParam(name.toStdString(), tWidget);
|
||||
m_workWindow->workSpace()->addTab(tWidget, title);
|
||||
return tWidget;
|
||||
|
||||
}
|
||||
|
||||
/** @brief 添加工作页Widget. */
|
||||
void QsfMainWindow::addWorkWidget( QWidget* workTab, QString title )
|
||||
{
|
||||
m_workWindow->workSpace()->addTab(workTab, title);
|
||||
}
|
||||
|
||||
void QsfMainWindow::mousePressEvent( QMouseEvent *event )
|
||||
{
|
||||
if (m_titleRect.contains(oldMousePos))
|
||||
{
|
||||
oldMousePos = event->globalPos() - this->pos();
|
||||
m_titleRect = m_titleBar->rect();
|
||||
}
|
||||
}
|
||||
|
||||
void QsfMainWindow::mouseDoubleClickEvent( QMouseEvent * event )
|
||||
{
|
||||
if (m_titleRect.contains(oldMousePos))
|
||||
{
|
||||
if (isMaximized())
|
||||
{
|
||||
showNormal();
|
||||
}
|
||||
else
|
||||
{
|
||||
showMaximized();
|
||||
}
|
||||
m_titleRect = m_titleBar->rect();
|
||||
}
|
||||
QWidget::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void QsfMainWindow::mouseMoveEvent( QMouseEvent *event )
|
||||
{
|
||||
if( isMaximized() )
|
||||
return;
|
||||
|
||||
if (m_titleRect.contains(oldMousePos))
|
||||
move(event->globalPos()-oldMousePos);
|
||||
|
||||
oldMousePos = event->globalPos() - this->pos();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/************************************************************************
|
||||
* 版权所有 (C) 梁振 Email: liang1057@163.com.cn
|
||||
*
|
||||
* 文件名称: QsMainWindow.h
|
||||
* 内容摘要:
|
||||
* 其它说明: 无
|
||||
* 当前版本: 0.1
|
||||
* 作 者: Leon
|
||||
* 完成日期: [2020/06/16]
|
||||
*
|
||||
* 修改记录1:暂无
|
||||
* 修改日期:
|
||||
* 版 本 号:
|
||||
* 修 改 人:
|
||||
* 修改内容:
|
||||
* 修改记录2:…
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QSMAINWINDOW_H
|
||||
#define QSMAINWINDOW_H
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QMainWindow>
|
||||
#include <QDragMoveEvent>
|
||||
|
||||
#include "SgfParamManager.h"
|
||||
#include "QsfTitleBar.h"
|
||||
|
||||
|
||||
/************************************************************************
|
||||
类声明: 工作窗口
|
||||
************************************************************************/
|
||||
/** @brief 工作窗口.
|
||||
*
|
||||
* @details 工作窗口的主体是Tab窗口.
|
||||
*/
|
||||
class QsfWorkWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/** @brief 构造函数.
|
||||
*
|
||||
* @details 构造函数.
|
||||
* @param parent 父指针.
|
||||
* @param flags flags.
|
||||
*/
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
QsfWorkWindow(QWidget *parent = 0, Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
#else
|
||||
QsfWorkWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
#endif
|
||||
/** @brief 析构函数.
|
||||
*
|
||||
* @details 析构函数,为了防止资源泄漏所以为virtual函数.
|
||||
*/
|
||||
virtual ~QsfWorkWindow();
|
||||
|
||||
public:
|
||||
/** @brief 获取当前tab页Widget函数.
|
||||
*
|
||||
* @details 获取当前tab页Widget函数.
|
||||
* @return 当前Widget指针.
|
||||
*/
|
||||
QWidget* getCurrentTabWidget();
|
||||
|
||||
/** @brief 获取当前tab页SgfWidget函数.
|
||||
*
|
||||
* @details 获取当前tab页SgfWidget函数.
|
||||
* @return 当前SgfWidget指针.
|
||||
*/
|
||||
QWidget * currentTabWidget();
|
||||
|
||||
/** @brief 获取tabWidget函数.
|
||||
*
|
||||
* @details 获取tabWidget函数.
|
||||
* @return SgfTabWidget指针.
|
||||
*/
|
||||
QTabWidget* workSpace();
|
||||
|
||||
private:
|
||||
QTabWidget* m_workspace;
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
类声明:
|
||||
************************************************************************/
|
||||
|
||||
/** @brief
|
||||
*
|
||||
* @details
|
||||
*/
|
||||
/** 默认 布局文件名称 */
|
||||
const QString MAINWINDOWLAYOUTFILE = "sw_mainframe.layout";
|
||||
/** @brief 应用程序主窗口对象
|
||||
*
|
||||
* @details 定义一个应用程序主窗口的宏对象,可在插件中访问主窗口资源.这是一个指针
|
||||
*/
|
||||
#define QSF_MainWindow ((QsfMainWindow*)(COREOBJECT(QsfMainWindow)))
|
||||
|
||||
#define QSF_MainWindow_GetParam(type, name) static_cast<type*>(GET_COREOBJECT(SgfParamManager)->getParamValue( string(name)))
|
||||
#define QSF_MainWindow_GetParam(type, name) ((type*)(GET_COREOBJECT(SgfParamManager)->getParamValue( string(name))))
|
||||
|
||||
/**************************************************************************
|
||||
* 类声明 *
|
||||
**************************************************************************/
|
||||
|
||||
/** @brief 应用程序主窗口类.
|
||||
*
|
||||
* @details 平台应用程序框架服务-应用程序主窗口类
|
||||
*/
|
||||
class QsfMainWindow : public QWidget //, public SgfParamManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsfMainWindow();
|
||||
~QsfMainWindow();
|
||||
static void createMainWindow();
|
||||
|
||||
QsfTitleBar* titleBar(){
|
||||
return m_titleBar;
|
||||
}
|
||||
QsfWorkWindow* workWindow(){
|
||||
return m_workWindow;
|
||||
}
|
||||
QTabWidget* tabMenuWidget(){
|
||||
return m_tableMenu;
|
||||
}
|
||||
|
||||
/** @brief 创建DockWidget. */
|
||||
QDockWidget* createDockWidget(QString title, QString name, Qt::DockWidgetArea area);
|
||||
/** @brief 添加DockWidget. */
|
||||
void addDockWidget(QDockWidget* tDock, QString title, Qt::DockWidgetArea area);
|
||||
|
||||
/** @brief 创建工作页Widget. */
|
||||
QWidget* createWorkWidget(QString title, QString name);
|
||||
/** @brief 添加工作页Widget. */
|
||||
void addWorkWidget(QWidget* workTab, QString title);
|
||||
|
||||
private:
|
||||
QsfWorkWindow* m_workWindow;
|
||||
QsfTitleBar* m_titleBar;
|
||||
QTabWidget* m_tableMenu;
|
||||
|
||||
|
||||
protected:
|
||||
/** @brief 标题范围. */
|
||||
QRect m_titleRect;
|
||||
/** @brief 鼠标上一次的位置. */
|
||||
QPoint oldMousePos;
|
||||
/** @brief 鼠标单击. */
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
/** @brief 鼠标双击. */
|
||||
void mouseDoubleClickEvent ( QMouseEvent * event);
|
||||
/** @brief 鼠标拖动. */
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
};
|
||||
|
||||
|
||||
#endif // QsfMainWindow_H
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <QPixmap>
|
||||
#include "QsfTitleBar.h"
|
||||
|
||||
QsfTitleBar::QsfTitleBar( QWidget *parent /*= NULL*/ )
|
||||
:QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
QWidget* backWidget = new QWidget;
|
||||
QHBoxLayout* backLayout = new QHBoxLayout;
|
||||
this->setLayout(backLayout);
|
||||
backLayout->addWidget(backWidget);
|
||||
//backLayout->setMargin(0);
|
||||
backLayout->setSpacing(0);
|
||||
backWidget->setObjectName("TITLE_BACK_WIDGET");
|
||||
|
||||
m_layout = new QHBoxLayout;
|
||||
m_layout->setContentsMargins(0, 0, 0, 0); //设置按钮组离边界的距离为5px
|
||||
layLeft = new QHBoxLayout;
|
||||
layLeft->setContentsMargins(0, 0, 0, 0); //设置按钮组离边界的距离为5px
|
||||
|
||||
layRight = new QHBoxLayout;
|
||||
layRight->setContentsMargins(0, 0, 0, 0); //设置按钮组离边界的距离为5px
|
||||
layRight->setSpacing(0);
|
||||
|
||||
m_titleLab = new QLabel;
|
||||
m_titleLab->setMouseTracking(false);
|
||||
backWidget->setLayout(m_layout);
|
||||
m_layout->addLayout(layLeft);
|
||||
m_layout->addStretch();
|
||||
m_layout->addWidget(m_titleLab);
|
||||
m_layout->addStretch();
|
||||
m_layout->addLayout(layRight);
|
||||
|
||||
setObjectName("QsfTitleBar");
|
||||
}
|
||||
|
||||
QsfTitleBar::~QsfTitleBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QsfTitleBar::setWindowTitle( QString title, Qt::Alignment tAlignment /*= Qt::AlignCenter*/ )
|
||||
{
|
||||
m_titleLab->setText(title);
|
||||
m_titleLab->setAlignment(tAlignment);
|
||||
}
|
||||
void QsfTitleBar::addLeftAction( QPushButton* tAct )
|
||||
{
|
||||
m_leftActions.append(tAct);
|
||||
layLeft->addWidget(tAct);
|
||||
}
|
||||
|
||||
void QsfTitleBar::addRightAction( QPushButton* tAct )
|
||||
{
|
||||
m_rightActions.append(tAct);
|
||||
layRight->addWidget(tAct);
|
||||
}
|
||||
|
||||
QString QsfTitleBar::windowTitle()
|
||||
{
|
||||
return m_titleLab->text();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/************************************************************************
|
||||
* 版权所有 (C) 梁振 Email: liang1057@163.com.cn
|
||||
*
|
||||
* 文件名称: QsfTitleBar.h
|
||||
* 内容摘要: 自定义界面标题栏类
|
||||
* 其它说明: 自定义界面的标题栏,按照Office Ribbon的扁平化策略实现了一个左侧按钮+中间标题+用户文本+右侧按钮 的布局
|
||||
* 当前版本: 0.1
|
||||
* 作 者: Leon
|
||||
* 完成日期: [3/20/2013]
|
||||
*
|
||||
* 修改记录1:暂无
|
||||
* 修改日期:
|
||||
* 版 本 号:
|
||||
* 修 改 人:
|
||||
* 修改内容:
|
||||
* 修改记录2:…
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QSF_TITLEBAR_H
|
||||
#define QSF_TITLEBAR_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QButtonGroup>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include "QsfToolButton.h"
|
||||
|
||||
#include "QsfToolButton.h"
|
||||
|
||||
class QsfTitleBar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QsfTitleBar(QWidget *parent = NULL);
|
||||
~QsfTitleBar();
|
||||
|
||||
/** @brief 设置窗口标题.
|
||||
*
|
||||
* @details 设置窗口标题.
|
||||
* @param title 窗口的标题.
|
||||
* @return .
|
||||
*/
|
||||
void setWindowTitle(QString title, Qt::Alignment tAlignment = Qt::AlignCenter);
|
||||
QString windowTitle();
|
||||
|
||||
void addLeftAction(QPushButton* tAct);
|
||||
void addRightAction(QPushButton* tAct);
|
||||
|
||||
private:
|
||||
QLabel* m_titleLab;
|
||||
QIcon* m_icon;
|
||||
|
||||
QList<QPushButton*> m_leftActions;
|
||||
QList<QPushButton*> m_rightActions;
|
||||
|
||||
QHBoxLayout* m_layout, *layLeft, *layRight;
|
||||
|
||||
};
|
||||
|
||||
#endif //QSF_TITLEBAR_H
|
||||
@@ -0,0 +1,96 @@
|
||||
/************************************************************************
|
||||
* 版权所有 (C) 梁振 Email: liang1057@163.com.cn
|
||||
*
|
||||
* 文件名称: QsfToolButton.cpp
|
||||
* 内容摘要:
|
||||
* 其它说明: 无
|
||||
* 当前版本: 0.1
|
||||
* 作 者: Leon
|
||||
* 完成日期: [3/20/2013]
|
||||
*
|
||||
* 修改记录1:暂无
|
||||
* 修改日期:
|
||||
* 版 本 号:
|
||||
* 修 改 人:
|
||||
* 修改内容:
|
||||
* 修改记录2:…
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#include "QsfToolButton.h"
|
||||
|
||||
|
||||
QsfToolButton::QsfToolButton( QWidget * parent /*= 0 */ )
|
||||
:QPushButton(parent)
|
||||
{
|
||||
resize(16,16);
|
||||
setObjectName("RibbonToolButton");
|
||||
}
|
||||
QsfToolButton::~QsfToolButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QsfToolButton::enterEvent( QEnterEvent *event )
|
||||
{
|
||||
QPushButton::setIcon(m_icon_hover);
|
||||
QPushButton::enterEvent(event);
|
||||
}
|
||||
|
||||
void QsfToolButton::leaveEvent( QEvent * event)
|
||||
{
|
||||
QPushButton::setIcon(m_icon);
|
||||
QPushButton::leaveEvent(event);
|
||||
}
|
||||
|
||||
// void QsfToolButton::setIcon(QIcon icon)
|
||||
// {
|
||||
// setIcon(icon, icon);
|
||||
// }
|
||||
//
|
||||
// void QsfToolButton::setIcon( QIcon icon1, QIcon icon2 )
|
||||
// {
|
||||
// m_iconIn = icon1;
|
||||
// m_iconOut = icon2;
|
||||
// QPushButton::setIcon(m_iconOut);
|
||||
// }
|
||||
//
|
||||
// void QsfToolButton::setIcon( QPixmap iconIn, QPixmap iconOut )
|
||||
// {
|
||||
// setIcon(QIcon(iconIn), QIcon(iconOut));
|
||||
// setIconSize(iconIn.size());
|
||||
// setFixedSize(iconIn.size());
|
||||
// }
|
||||
//
|
||||
// void QsfToolButton::setIcon( QString fileIn, QString fileOut )
|
||||
// {
|
||||
// setIcon(QPixmap(fileIn), QPixmap(fileOut));
|
||||
// }
|
||||
|
||||
void QsfToolButton::setIcon( QString icon, QString icon_hover, QString icon_pressed )
|
||||
{
|
||||
m_icon = QIcon(icon);
|
||||
m_icon_hover = QIcon(icon_hover);
|
||||
m_icon_pressed = QIcon(icon_pressed);
|
||||
QPushButton::setIcon(m_icon);
|
||||
}
|
||||
// void QsfToolButton::setButtonIcon( QPushButton* tBtn, QString filename, bool asIconSize/*=true*/ )
|
||||
// {
|
||||
// QPixmap pm(filename);
|
||||
// tBtn->setIcon(QIcon(pm));
|
||||
// tBtn->setIconSize(pm.size());
|
||||
// if(asIconSize)
|
||||
// tBtn->setFixedSize(pm.size());
|
||||
// }
|
||||
|
||||
void QsfToolButton::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
QPushButton::setIcon(m_icon_pressed);
|
||||
QPushButton::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void QsfToolButton::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
QPushButton::setIcon(m_icon);
|
||||
QPushButton::mouseReleaseEvent(e);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/************************************************************************
|
||||
* 版权所有 (C) 梁振 Email: liang1057@163.com.cn
|
||||
*
|
||||
* 文件名称: QsfToolButton.h
|
||||
* 内容摘要: 自定义界面按钮
|
||||
* 其它说明: 如自定义界面中的最大、最小、关闭、换肤按钮等
|
||||
* 当前版本: 0.1
|
||||
* 作 者: Leon
|
||||
* 完成日期: [3/20/2013]
|
||||
*
|
||||
* 修改记录1:暂无
|
||||
* 修改日期:
|
||||
* 版 本 号:
|
||||
* 修 改 人:
|
||||
* 修改内容:
|
||||
* 修改记录2:…
|
||||
************************************************************************/
|
||||
|
||||
#ifndef QSFTOOLBUTTON_H
|
||||
#define QSFTOOLBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
/************************************************************************
|
||||
类声明:
|
||||
************************************************************************/
|
||||
|
||||
/** @brief 自定义界面的按钮
|
||||
*
|
||||
* @details 自定义界面的按钮类
|
||||
*/
|
||||
class QsfToolButton: public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ButtonMouseState
|
||||
{
|
||||
ButtonMouseDefault = 0,
|
||||
ButtonMouseEnter,
|
||||
ButtonMousePress,
|
||||
ButtonMouseNone
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
QsfToolButton( QWidget * parent = 0 );
|
||||
~QsfToolButton();
|
||||
|
||||
void setIcon(QString icon, QString icon_hover, QString icon_pressed);
|
||||
private:
|
||||
QIcon m_icon, m_icon_hover, m_icon_pressed;
|
||||
|
||||
protected:
|
||||
void enterEvent(QEnterEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
};
|
||||
#endif // QSFTOOLBUTTON_H
|
||||
@@ -0,0 +1,928 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QDockWidget>
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
#include "QsfMainWindow.h"
|
||||
#include "QsrRibbonCore.h"
|
||||
#include "SgfParamManager.h"
|
||||
|
||||
#define RIBBON_STYLE_QSS "../userData/RibbonStyle.qss"
|
||||
|
||||
RobbonWidget::RobbonWidget(QWidget *parent /* = Q_NULLPTR */, Qt::WindowFlags f /* = Qt::WindowFlags() */)
|
||||
:QWidget(parent,f)
|
||||
{
|
||||
setObjectName("RobbonWidget");
|
||||
}
|
||||
|
||||
RobbonWidget::~RobbonWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void RobbonWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QStyleOption opt;
|
||||
opt.init(this);
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
}
|
||||
|
||||
QsrRibbonTitleBar::QsrRibbonTitleBar()
|
||||
{
|
||||
setObjectName("RibbonTitleBar");
|
||||
QHBoxLayout* titleLayout = new QHBoxLayout();
|
||||
titleLayout->setMargin(0);
|
||||
titleLayout->setSpacing(0);
|
||||
this->setLayout(titleLayout);
|
||||
|
||||
titleLayout->addSpacing(10); // 10pix
|
||||
m_quickAccessToolBar = new QsrRibbonQuickAccessToolBar();
|
||||
titleLayout->addWidget(m_quickAccessToolBar);
|
||||
titleLayout->addStretch();
|
||||
|
||||
m_titleLable1 = new QLabel();
|
||||
m_titleLable1->setStyleSheet("color:white;");
|
||||
m_titleLable1->setObjectName("RibbonTitleBarLabel1");
|
||||
titleLayout->addWidget(m_titleLable1);
|
||||
titleLayout->addStretch();
|
||||
|
||||
|
||||
m_userInfoLabel = new QLabel(QByteArray::fromHex("6c69616e6731303537403136332e636f6d").data());//("liang1057@163.com");
|
||||
m_userInfoLabel->setStyleSheet("color:white;");
|
||||
titleLayout->addWidget(m_userInfoLabel);
|
||||
|
||||
m_systemButton = new QsrRibbonQuickAccessToolBar();
|
||||
titleLayout->addWidget(m_systemButton);
|
||||
}
|
||||
|
||||
QsrRibbonTitleBar::~QsrRibbonTitleBar()
|
||||
{
|
||||
delete m_quickAccessToolBar;
|
||||
m_quickAccessToolBar = NULL;
|
||||
}
|
||||
|
||||
/** @brief 设置窗口标题.
|
||||
*
|
||||
* @details 设置窗口标题.
|
||||
* @param title 窗口的标题.
|
||||
* @return .
|
||||
*/
|
||||
void QsrRibbonTitleBar::setTitle(QString title)
|
||||
{
|
||||
QWidget::setWindowTitle(title);
|
||||
m_titleLable1->setText(title);
|
||||
m_titleLable1->setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
QString QsrRibbonTitleBar::getTitle()
|
||||
{
|
||||
return this->windowTitle();
|
||||
}
|
||||
|
||||
/** @brief 设置工具条的文字. */
|
||||
void QsrRibbonTitleBar::setToolsText(QString txt)
|
||||
{
|
||||
m_ToolsLabel.setText(txt);
|
||||
}
|
||||
|
||||
void QsrRibbonTitleBar::addQuickAction(QAction *action)
|
||||
{
|
||||
m_quickAccessToolBar->addAction(action);
|
||||
}
|
||||
|
||||
void QsrRibbonTitleBar::addSysAction(QAction* action)
|
||||
{
|
||||
QList<QAction*> tList = m_systemButton->actions();
|
||||
if (tList.count() == 0)
|
||||
m_systemButton->addAction(action);
|
||||
else
|
||||
{
|
||||
m_systemButton->insertAction(tList[0], action);
|
||||
}
|
||||
}
|
||||
|
||||
void QsrRibbonTitleBar::setUserInfo(QString txt)
|
||||
{
|
||||
m_userInfoLabel->setText(txt);
|
||||
}
|
||||
|
||||
// QList<QT_NAMESPACE::QAction>* QsrRibbonTitleBar::getActionList(bool isLeft/*=true*/)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
// /** @brief 获取快捷工具栏 . */
|
||||
// QsrRibbonQuickAccessToolBar* QsrRibbonTitleBar::quickAccessToolBar()
|
||||
// {
|
||||
// return m_quickAccessToolBar;
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
QtbMenuBar::QtbMenuBar()
|
||||
{
|
||||
setObjectName("RibbonMenuBar");
|
||||
QVBoxLayout* tVB = new QVBoxLayout();
|
||||
tVB->setSpacing(0);
|
||||
tVB->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(tVB);
|
||||
|
||||
m_layout = new QHBoxLayout();
|
||||
m_layout->setSpacing(0);
|
||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
||||
tVB->addLayout(m_layout);
|
||||
|
||||
m_toolBarStackedWid = new QStackedWidget();
|
||||
m_toolBarStackedWid->setObjectName("RibbonMenuStackeWidget");
|
||||
m_menuTabBar = new QTabBar;
|
||||
m_menuTabBar->setMinimumHeight(32);
|
||||
m_menuTabBar->setObjectName("RibbonMenuTabBar");
|
||||
m_layout->addWidget(m_menuTabBar);
|
||||
|
||||
/* 暂时不提供扩展型的可变菜单
|
||||
m_ExtentedMenuTabBar = new QTabBar;
|
||||
m_ExtentedMenuTabBar->setObjectName("RibbonExtentedMenuTabBar");
|
||||
m_ExtentedMenuTabBar->addTab("");
|
||||
m_ExtentedMenuTabBar->setTabEnabled(0, false);
|
||||
m_layout->addWidget(m_ExtentedMenuTabBar);
|
||||
// m_extentedWidget = new QWidget();
|
||||
// m_layout->addWidget(m_extentedWidget);
|
||||
// m_layoutExtented = new QHBoxLayout();
|
||||
// m_layoutExtented->setContentsMargins(0, 0, 0, 0);
|
||||
// m_layoutExtented->setSpacing(0);
|
||||
// m_extentedWidget->setLayout(m_layoutExtented);
|
||||
*/
|
||||
m_layout->addStretch();
|
||||
|
||||
m_extentBtn = new RibbonToolButton();
|
||||
m_layout->addWidget(m_extentBtn);
|
||||
m_toolBarVisible = true;
|
||||
QObject::connect(m_extentBtn, SIGNAL(clicked()), this, SLOT(onExtentToggled()));
|
||||
|
||||
|
||||
tVB->addWidget(m_toolBarStackedWid);
|
||||
|
||||
m_toolBarStackedWid->setMaximumHeight(96);
|
||||
m_toolBarStackedWid->setMinimumHeight(96);
|
||||
m_toolBarStackedWid->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
|
||||
|
||||
connect(m_menuTabBar, SIGNAL(currentChanged(int)), this, SLOT(onCurrentTabChenged(int)));
|
||||
return;
|
||||
}
|
||||
|
||||
QtbMenuBar::~QtbMenuBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtbMenuBar::addAction(ribbonAction* tAction,int tIndex)
|
||||
{
|
||||
m_layout->insertWidget(tIndex, tAction);
|
||||
}
|
||||
|
||||
/** @brief 增加菜单. */
|
||||
void QtbMenuBar::addMenu(QString menuName)
|
||||
{
|
||||
// 添加一个tab标签
|
||||
int tabIndex = m_menuTabBar->addTab(menuName);
|
||||
|
||||
// 下方Ribbon工具条上添加相应的显示widget作为Group的载体
|
||||
RobbonWidget* tempWid = new RobbonWidget();
|
||||
m_toolBarStackedWid->addWidget(tempWid);
|
||||
m_StaWidMap.insert(menuName, tempWid);
|
||||
|
||||
// 这是显示widget用的横向布局
|
||||
QHBoxLayout* tempHB = new QHBoxLayout();
|
||||
tempHB->setSpacing(0);
|
||||
tempHB->setContentsMargins(0, 0, 0, 0);
|
||||
tempWid->setLayout(tempHB);
|
||||
|
||||
RobbonWidget* lastWid = new RobbonWidget();
|
||||
QHBoxLayout* lastHB = new QHBoxLayout();
|
||||
lastWid->setLayout(lastHB);
|
||||
lastHB->addStretch();
|
||||
|
||||
tempHB->addWidget(lastWid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @brief 增加扩展型菜单. */
|
||||
/* 暂时不提供扩展型的可变菜单
|
||||
void QtbMenuBar::addExtendedMenu(QString menuName, QString showName)
|
||||
{
|
||||
// 添加一个tab标签
|
||||
// int tabIndex = m_ExtentedMenuTabBar->addTab(menuName);
|
||||
|
||||
// 下方Ribbon工具条上添加相应的显示widget作为Group的载体
|
||||
RobbonWidget* tempWid = new RobbonWidget();
|
||||
m_toolBarStackedWid->addWidget(tempWid);
|
||||
m_StaWidMap.insert(menuName, tempWid);
|
||||
tempWid->setWindowTitle(showName);
|
||||
|
||||
QHBoxLayout* tempHB = new QHBoxLayout();
|
||||
tempHB->setSpacing(0);
|
||||
tempHB->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
tempHB->addStretch();
|
||||
tempWid->setLayout(tempHB);
|
||||
|
||||
// QPushButton* tBtn = new QPushButton(m_extentedWidget);
|
||||
// tBtn->setText(showName);
|
||||
// m_layoutExtented->addWidget(tBtn);
|
||||
// tBtn->setVisible(true);
|
||||
// tBtn->setCheckable(true);
|
||||
// tBtn->setObjectName("RibbonExtentedMenu");
|
||||
// m_extentedBtnMap.insert(menuName, tBtn);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
void QtbMenuBar::setMenuVisible(QString menuName, bool tIsVisible)
|
||||
{
|
||||
QString tabTitle = "";
|
||||
if (m_StaWidMap.contains(menuName))
|
||||
{
|
||||
m_StaWidMap[menuName]->setVisible(tIsVisible);
|
||||
tabTitle = m_StaWidMap[menuName]->windowTitle();
|
||||
}
|
||||
|
||||
if (tIsVisible == true)
|
||||
{
|
||||
for (int i = m_menuTabBar->count() - 1; i >= 0; i--)
|
||||
{
|
||||
if (menuName == m_menuTabBar->tabText(i))
|
||||
return;
|
||||
}
|
||||
m_menuTabBar->addTab(menuName);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = m_menuTabBar->count() - 1; i >= 0; i--)
|
||||
{
|
||||
if (menuName == m_menuTabBar->tabText(i))
|
||||
m_menuTabBar->removeTab(i);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (tabTitle.isEmpty())
|
||||
return;
|
||||
// m_extentedBtnMap[menuName]->setVisible(tIsVisible);
|
||||
if (tIsVisible == true)
|
||||
{
|
||||
int tabIndex = m_ExtentedMenuTabBar->addTab(tabTitle);
|
||||
//m_layoutExtented->addWidget();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for (int i = m_ExtentedMenuTabBar->count() - 1; i >= 0; i--)
|
||||
{
|
||||
if (tabTitle == m_ExtentedMenuTabBar->tabText(i))
|
||||
m_ExtentedMenuTabBar->removeTab(i);
|
||||
}
|
||||
}
|
||||
m_ExtentedMenuTabBar->setCurrentIndex(0);
|
||||
*/
|
||||
}
|
||||
|
||||
bool QtbMenuBar::isMenuVisible(QString menuName)
|
||||
{
|
||||
if (m_StaWidMap.contains(menuName))
|
||||
{
|
||||
return m_StaWidMap[menuName]->isVisible();
|
||||
}
|
||||
}
|
||||
|
||||
QtbGroupWidget* QtbMenuBar::addGroup(QString menuName, QString txtGroupTitle)
|
||||
{
|
||||
if (m_StaWidMap.contains(menuName))
|
||||
{
|
||||
RobbonWidget* tempWid = m_StaWidMap[menuName]; //先找到menu的承载页
|
||||
QtbGroupWidget* newGW = new QtbGroupWidget();
|
||||
newGW->setTitle(txtGroupTitle);
|
||||
QHBoxLayout* tempHB = (QHBoxLayout*)(tempWid->layout());
|
||||
tempHB->insertWidget(tempHB->count()-1,newGW);
|
||||
return newGW;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void QtbMenuBar::menuReady(QString menuName)
|
||||
{
|
||||
// if (m_StaWidMap.contains(menuName))
|
||||
// {
|
||||
// RobbonWidget* tempWid = m_StaWidMap[menuName]; //先找到menu的承载页
|
||||
// RobbonWidget* lastWid = new QtbGroupWidget();
|
||||
// QHBoxLayout* tempHB = (QHBoxLayout*)(tempWid->layout());
|
||||
// tempHB->insertWidget(tempHB->count() - 1, newGW);
|
||||
// return newGW;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return NULL;
|
||||
// }
|
||||
}
|
||||
|
||||
void QtbMenuBar::setExtentBtnIcon(QIcon icoExtent, QIcon icoHide)
|
||||
{
|
||||
m_icoExtent = icoExtent;
|
||||
m_icoHide = icoHide;
|
||||
if (m_toolBarVisible)
|
||||
m_extentBtn->setIcon(m_icoHide);
|
||||
else
|
||||
m_extentBtn->setIcon(m_icoExtent);
|
||||
}
|
||||
|
||||
void QtbMenuBar::setToolBarVisible(bool tVal)
|
||||
{
|
||||
m_toolBarVisible = tVal;
|
||||
m_toolBarStackedWid->setVisible(m_toolBarVisible);
|
||||
}
|
||||
|
||||
void QtbMenuBar::onExtentToggled()
|
||||
{
|
||||
setToolBarVisible(!m_toolBarVisible);
|
||||
if (m_toolBarVisible)
|
||||
m_extentBtn->setIcon(m_icoHide);
|
||||
else
|
||||
m_extentBtn->setIcon(m_icoExtent);
|
||||
}
|
||||
|
||||
void QtbMenuBar::onCurrentTabChenged(int index)
|
||||
{
|
||||
m_toolBarStackedWid->setCurrentIndex(index);
|
||||
m_toolBarStackedWid->show();
|
||||
|
||||
/* 暂时不提供扩展型的可变菜单
|
||||
for each (QPushButton* var in m_extentedBtnMap)
|
||||
{
|
||||
var->setChecked(false);
|
||||
}
|
||||
m_ExtentedMenuTabBar->setCurrentIndex(0);
|
||||
*/
|
||||
}
|
||||
|
||||
/* 暂时不提供扩展型的可变菜单
|
||||
void QtbMenuBar::onExtentedTabChenged()
|
||||
{
|
||||
for each (QPushButton* var in m_extentedBtnMap)
|
||||
{
|
||||
var->setChecked(false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void QtbMenuBar::enterEvent(QEvent *event)
|
||||
{
|
||||
QWidget::enterEvent(event);
|
||||
if (m_toolBarVisible == false)
|
||||
m_toolBarStackedWid->show();
|
||||
}
|
||||
|
||||
void QtbMenuBar::leaveEvent(QEvent *event)
|
||||
{
|
||||
QWidget::leaveEvent(event);
|
||||
//m_toolBarStackedWid->setVisible(m_toolBarVisible);
|
||||
if (m_toolBarVisible == false)
|
||||
m_toolBarStackedWid->setVisible(false);
|
||||
}
|
||||
|
||||
bool QtbMenuBar::isToolBarVisible()
|
||||
{
|
||||
return m_toolBarVisible;
|
||||
}
|
||||
|
||||
/** @brief Ribbon工具栏.
|
||||
* @details Ribbon工具栏.
|
||||
*/
|
||||
QtbToolBar::QtbToolBar(/*QTabBar* tabBar*/)
|
||||
{
|
||||
//this->setTabBar(tabBar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QtbToolBar::~QtbToolBar()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QtbToolBar::addMenu(QString txt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** @brief 主窗口.
|
||||
* @details
|
||||
*/
|
||||
QtbMainWindow::QtbMainWindow(QWidget *parent /* = Q_NULLPTR */, Qt::WindowFlags f /* = Qt::WindowFlags() */)
|
||||
:RobbonWidget(parent/*, Qt::FramelessWindowHint*/)
|
||||
{
|
||||
setObjectName("RibbonMainWindow");
|
||||
resize(800, 600);
|
||||
QFile qssFile(RIBBON_STYLE_QSS);
|
||||
if (qssFile.exists())
|
||||
{
|
||||
if (qssFile.open(QFile::ReadOnly))
|
||||
{
|
||||
QString qssStr = QString(qssFile.readAll());
|
||||
setStyleSheet(qssStr);
|
||||
}
|
||||
}
|
||||
|
||||
Qt::WindowFlags myWinFlags = 0;
|
||||
myWinFlags |= Qt::Window;
|
||||
myWinFlags |= Qt::FramelessWindowHint;
|
||||
//myWinFlags |= Qt::CustomizeWindowHint;
|
||||
|
||||
setWindowFlags(myWinFlags);
|
||||
|
||||
// #ifdef Q_OS_WIN
|
||||
// HWND hwnd = reinterpret_cast<HWND>(this->winId());
|
||||
//
|
||||
// //const long style = (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN);
|
||||
// const long style = WS_POPUP; //( | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN);
|
||||
// SetWindowLongPtr(hwnd, GWL_STYLE, style);
|
||||
//
|
||||
// const MARGINS shadow = { 1, 1, 1, 1 };
|
||||
// DwmExtendFrameIntoClientArea(hwnd, &shadow);
|
||||
//
|
||||
// SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
|
||||
// #endif
|
||||
|
||||
|
||||
|
||||
QVBoxLayout* tMainVB = new QVBoxLayout;
|
||||
tMainVB->setSpacing(0);
|
||||
tMainVB->setContentsMargins(1,1,1,1);
|
||||
this->setLayout(tMainVB);
|
||||
|
||||
m_titleBar = new QsrRibbonTitleBar();
|
||||
tMainVB->addWidget(m_titleBar);
|
||||
|
||||
m_menuBar = new QtbMenuBar();
|
||||
tMainVB->addWidget(m_menuBar);
|
||||
tMainVB->addSpacing(1);
|
||||
m_workWindow = new QsfWorkWindow;
|
||||
tMainVB->addWidget(m_workWindow);
|
||||
}
|
||||
|
||||
QtbMainWindow::~QtbMainWindow()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
QsrRibbonTitleBar* QtbMainWindow::titleBar()
|
||||
{
|
||||
return m_titleBar;
|
||||
}
|
||||
|
||||
QtbMenuBar* QtbMainWindow::menuBar()
|
||||
{
|
||||
return m_menuBar;
|
||||
}
|
||||
|
||||
/** @brief 创建DockWidget. */
|
||||
QDockWidget * QtbMainWindow::createDockWidget(QString title, QString name, Qt::DockWidgetArea area)
|
||||
{
|
||||
QDockWidget* tDock = new QDockWidget(title);
|
||||
SgfParamManager::GetInstance()->addParam(name.toStdString(), tDock);
|
||||
m_workWindow->addDockWidget(area, tDock);
|
||||
// QWidget* docWid1 = new QWidget;
|
||||
// tDock->setWidget(docWid1);
|
||||
return tDock;
|
||||
}
|
||||
|
||||
QWidget* QtbMainWindow::createWorkWidget(QString title, QString name)
|
||||
{
|
||||
QWidget* tWidget = static_cast<QWidget*>(SgfParamManager::GetInstance()->getParamValue(name.toStdString()));
|
||||
if(tWidget==NULL)
|
||||
{
|
||||
tWidget = new QWidget();
|
||||
tWidget->setWindowTitle(title);
|
||||
SgfParamManager::GetInstance()->addParam(name.toStdString(), tWidget);
|
||||
m_workWindow->workSpace()->addTab(tWidget, title);
|
||||
}
|
||||
return tWidget;
|
||||
}
|
||||
void QtbMainWindow::addWorkWidget(QWidget* tWidget)
|
||||
{
|
||||
m_workWindow->workSpace()->addTab(tWidget, tWidget->windowTitle());
|
||||
}
|
||||
|
||||
void QtbMainWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
// m_titleRect = m_titleBar->rect();
|
||||
// if (m_titleRect.contains(event->pos()))
|
||||
// oldMousePos = event->globalPos() - this->pos();
|
||||
// else
|
||||
// oldMousePos = QPoint(-1, -1);
|
||||
|
||||
QWidget::mousePressEvent(event);
|
||||
m_titleRect = m_titleBar->rect();
|
||||
if (m_titleRect.contains(event->pos()))
|
||||
{
|
||||
if (!event->isAccepted()) {
|
||||
#ifdef Q_OS_WIN
|
||||
ReleaseCapture();
|
||||
SendMessage(reinterpret_cast<HWND>(winId()), WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
|
||||
}
|
||||
#else
|
||||
if (m_titleRect.contains(event->pos()))
|
||||
oldMousePos = event->globalPos() - this->pos();
|
||||
else
|
||||
oldMousePos = QPoint(-1, -1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void QtbMainWindow::mouseDoubleClickEvent(QMouseEvent * event)
|
||||
{
|
||||
m_titleRect = m_titleBar->rect();
|
||||
if (m_titleRect.contains(event->pos()))
|
||||
{
|
||||
if (isMaximized())
|
||||
{
|
||||
showNormal();
|
||||
}
|
||||
else
|
||||
{
|
||||
showMaximized();
|
||||
}
|
||||
m_titleRect = m_titleBar->rect();
|
||||
}
|
||||
RobbonWidget::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void QtbMainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// if (isMaximized())
|
||||
// return;
|
||||
//
|
||||
// if (m_titleRect.contains(oldMousePos))
|
||||
// move(event->globalPos() - oldMousePos);
|
||||
//
|
||||
// oldMousePos = event->globalPos() - this->pos();
|
||||
}
|
||||
|
||||
void QtbMainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
update();
|
||||
}
|
||||
|
||||
void QtbMainWindow::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter p(this);
|
||||
if (this->isActiveWindow())
|
||||
p.setPen(QColor(60, 136, 193));
|
||||
else
|
||||
p.setPen(Qt::darkGray);
|
||||
|
||||
|
||||
|
||||
p.drawRect(QRect(0,0,width()-1, height()-1));
|
||||
|
||||
}
|
||||
|
||||
void QtbMainWindow::onSkin()
|
||||
{
|
||||
//QFile qssFile(RIBBON_STYLE_QSS);
|
||||
QString fileneame = QFileDialog::getOpenFileName(this, "换肤", "../bin/userdata");
|
||||
if (fileneame.isEmpty())
|
||||
return;
|
||||
QFile qssFile(fileneame);
|
||||
if (qssFile.exists())
|
||||
{
|
||||
if (qssFile.open(QFile::ReadOnly))
|
||||
{
|
||||
QString qssStr = QString(qssFile.readAll());
|
||||
setStyleSheet(qssStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** @brief Ribbon操作.
|
||||
* @details 一个操作对应一个图标,或者控件
|
||||
*/
|
||||
// ribbonAction::ribbonAction()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
/** @brief Ribbon 操作组.
|
||||
* @details Ribbon 操作组
|
||||
*/
|
||||
QtbGroupWidget::QtbGroupWidget()
|
||||
{
|
||||
m_actionGroup = new QActionGroup(this);
|
||||
//this->setStyleSheet("background-color : rgba(33, 140, 240, 255);");
|
||||
this->setObjectName("RibbonGroupWidget");
|
||||
//setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
QVBoxLayout* groupLayout = new QVBoxLayout;
|
||||
groupLayout->setSpacing(0);
|
||||
groupLayout->setContentsMargins(5, 5, 5, 0);
|
||||
this->setLayout(groupLayout);
|
||||
m_gridLayout = new QGridLayout();
|
||||
m_gridLayout->setSpacing(5);
|
||||
m_gridLayout->setContentsMargins(0, 0, 0, 0);
|
||||
groupLayout->addLayout(m_gridLayout);
|
||||
groupLayout->addStretch();
|
||||
QHBoxLayout* titleLayout = new QHBoxLayout;
|
||||
titleLayout->setSpacing(0);
|
||||
titleLayout->setContentsMargins(5, 0, 5, 0);
|
||||
groupLayout->addLayout(titleLayout);
|
||||
//titleLayout->addStretch();
|
||||
m_groupTitleLabel = new QLabel();
|
||||
titleLayout->addWidget(m_groupTitleLabel);
|
||||
m_groupTitleLabel->setMaximumHeight(24);
|
||||
m_groupTitleLabel->setMinimumHeight(24);
|
||||
//m_groupTitleLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
|
||||
|
||||
|
||||
// 右下角的按钮5
|
||||
QsfToolButton* popBtn = new QsfToolButton(); popBtn->setText(">");
|
||||
popBtn->setMaximumSize(QSize(24, 24));
|
||||
popBtn->setMinimumSize(QSize(24, 24));
|
||||
//m_groupTitleLabel->setLayout(titleLayout);
|
||||
//titleLayout->addStretch();
|
||||
titleLayout->addWidget(popBtn);
|
||||
}
|
||||
|
||||
QtbGroupWidget::~QtbGroupWidget()
|
||||
{
|
||||
delete m_actionGroup;
|
||||
}
|
||||
void QtbGroupWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
RobbonWidget::paintEvent(event);
|
||||
|
||||
// 绘制每个Group上的分隔线
|
||||
QPainter p(this);
|
||||
p.setPen(Qt::darkGray);
|
||||
p.drawLine(width() - 2, 5, width() - 2, height()-5);
|
||||
}
|
||||
|
||||
void QtbGroupWidget::setTitle(QString tTitle)
|
||||
{
|
||||
m_groupTitleLabel->setText(tTitle);
|
||||
m_groupTitleLabel->setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void QtbGroupWidget::addAction(ribbonAction* rAct, int row, int col, int rowSpan /*= 1*/, int columnSpan /*= 1*/, Qt::Alignment alignment /*= Qt::Alignment()*/)
|
||||
{
|
||||
m_gridLayout->addWidget(rAct, row, col, rowSpan, columnSpan, alignment);
|
||||
}
|
||||
void QtbGroupWidget::addAction(RibbonToolButton* rAct, int row, int col, int rowSpan /*= 1*/, int columnSpan /*= 1*/, Qt::Alignment alignment /*= Qt::Alignment()*/)
|
||||
{
|
||||
m_gridLayout->addWidget(rAct->window(), row, col, rowSpan, columnSpan, alignment);
|
||||
}
|
||||
|
||||
QActionGroup* QtbGroupWidget::getActionGroup() const
|
||||
{
|
||||
return m_actionGroup;
|
||||
}
|
||||
|
||||
|
||||
QsrRibbonQuickAccessToolBar::QsrRibbonQuickAccessToolBar()
|
||||
{
|
||||
setObjectName("RibbonQuickAccessToolBar");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @brief RibbonControlBase 控件基类.
|
||||
* @details
|
||||
*/RibbonControlBase::RibbonControlBase()
|
||||
{
|
||||
}
|
||||
|
||||
RibbonControlBase::~RibbonControlBase()
|
||||
{
|
||||
}
|
||||
|
||||
void RibbonControlBase::setGroupPos(QPoint tPos, int index /*= -1*/)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case -1:
|
||||
m_pos0 = tPos;
|
||||
m_pos1 = tPos;
|
||||
break;
|
||||
case 0:
|
||||
m_pos0 = tPos;
|
||||
break;
|
||||
case 1:
|
||||
m_pos1 = tPos;
|
||||
break;
|
||||
default:
|
||||
m_pos0 = tPos;
|
||||
m_pos1 = tPos;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QPoint RibbonControlBase::groupPos(int index)
|
||||
{
|
||||
if (index == 1)
|
||||
return m_pos1;
|
||||
else
|
||||
return m_pos0;
|
||||
}
|
||||
|
||||
|
||||
/** @brief RibbonPushButton Ribbon按钮类.
|
||||
* @details
|
||||
*/
|
||||
RibbonToolButton::RibbonToolButton(QWidget *parent /*= Q_NULLPTR*/)
|
||||
: QPushButton(parent)
|
||||
{
|
||||
setObjectName("RibbonToolButton");
|
||||
m_action = NULL;
|
||||
m_txtVisible = true;
|
||||
setMinimumHeight(24);
|
||||
setMinimumWidth(24);
|
||||
setStyleSheet("text-align : left;");
|
||||
m_action = new QAction();
|
||||
connect(this, SIGNAL(clicked(bool)), m_action, SIGNAL(triggered(bool)));
|
||||
}
|
||||
|
||||
RibbonToolButton::RibbonToolButton(const QIcon &icon, const QString &text, QWidget *parent /*= Q_NULLPTR*/)
|
||||
:QPushButton(icon, text, parent)
|
||||
{
|
||||
setObjectName("RibbonToolButton");
|
||||
m_text = text;
|
||||
m_txtVisible = true;
|
||||
setMinimumHeight(24);
|
||||
setStyleSheet("text-align : left;");
|
||||
m_action = new QAction(icon, text);
|
||||
connect(this, SIGNAL(clicked(bool)), m_action, SIGNAL(triggered(bool)));
|
||||
}
|
||||
|
||||
RibbonToolButton::RibbonToolButton(const QString &text, QWidget *parent /*= Q_NULLPTR*/)
|
||||
:QPushButton(text, parent)
|
||||
{
|
||||
setObjectName("RibbonToolButton");
|
||||
m_action = NULL;
|
||||
m_text = text;
|
||||
m_txtVisible = true;
|
||||
setMinimumHeight(24);
|
||||
setMaximumWidth(75);
|
||||
setStyleSheet("text-align : left;");
|
||||
m_action = new QAction(text);
|
||||
connect(this, SIGNAL(clicked(bool)), m_action, SIGNAL(triggered(bool)));
|
||||
}
|
||||
|
||||
RibbonToolButton::~RibbonToolButton()
|
||||
{
|
||||
// 没有释放action的操作
|
||||
}
|
||||
|
||||
void RibbonToolButton::setTxtVisible(bool tVal)
|
||||
{
|
||||
m_txtVisible = tVal;
|
||||
if (m_txtVisible)
|
||||
QPushButton::setText(m_text);
|
||||
else
|
||||
QPushButton::setText("");
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
bool RibbonToolButton::txtVisible()
|
||||
{
|
||||
return m_txtVisible;
|
||||
}
|
||||
|
||||
void RibbonToolButton::setAlignment(Qt::Alignment flag)
|
||||
{
|
||||
QString str = "";
|
||||
switch (flag)
|
||||
{
|
||||
case Qt::AlignCenter:
|
||||
str = "center";
|
||||
break;
|
||||
case Qt::AlignLeft:
|
||||
str = "left";
|
||||
break;
|
||||
case Qt::AlignRight:
|
||||
str = "right";
|
||||
break;
|
||||
case Qt::AlignBottom:
|
||||
str = "bottom";
|
||||
break;
|
||||
case Qt::AlignTop:
|
||||
str = "top";
|
||||
break;
|
||||
default:
|
||||
str = "center";
|
||||
break;
|
||||
}
|
||||
setStyleSheet(QString("text-align : %1;").arg(str));
|
||||
}
|
||||
|
||||
/** @brief 设置Action. */
|
||||
// void RibbonToolButton::setAction(QAction* tAction)
|
||||
// {
|
||||
// m_action = tAction;
|
||||
// this->setText(tAction->text());
|
||||
// this->setIcon(tAction->icon());
|
||||
// connect(this, SIGNAL(triggered(bool)), m_action, SIGNAL(triggered(bool)));
|
||||
// }
|
||||
|
||||
/** @brief 获取Action. */
|
||||
QAction* RibbonToolButton::getAction()
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
void RibbonToolButton::setText(QString &text)
|
||||
{
|
||||
m_action->setText(text);
|
||||
QPushButton::setText(text);
|
||||
}
|
||||
|
||||
void RibbonToolButton::setIcon(const QIcon &icon)
|
||||
{
|
||||
m_action->setIcon(icon);
|
||||
QPushButton::setIcon(icon);
|
||||
}
|
||||
|
||||
void RibbonToolButton::setEnabled(bool &tEnabled)
|
||||
{
|
||||
m_action->setEnabled(tEnabled);
|
||||
QPushButton::setEnabled(tEnabled);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RibbonToolButtonBig::RibbonToolButtonBig(const QIcon &icon, const QString &text, QWidget *parent)
|
||||
{
|
||||
setObjectName("RibbonToolButton");
|
||||
// this->resize(64, 54);
|
||||
// this->setMaximumSize(QSize(64, 54));
|
||||
// this->setMinimumSize(QSize(64, 54));
|
||||
|
||||
QVBoxLayout* tVB = new QVBoxLayout;
|
||||
setLayout(tVB);
|
||||
tVB->setSpacing(0);
|
||||
tVB->setContentsMargins(0, 0, 0, 0);
|
||||
m_pushButton = new QPushButton();
|
||||
m_pushButton->setIcon(icon);
|
||||
m_pushButton->setIconSize(QSize(32, 32));
|
||||
tVB->addWidget(m_pushButton);
|
||||
m_label = new QLabel();
|
||||
m_label->setText(text);
|
||||
m_label->setMaximumHeight(18);
|
||||
m_label->setAlignment(Qt::AlignCenter);
|
||||
tVB->addWidget(m_label);
|
||||
|
||||
m_label_extent = new QLabel;
|
||||
m_label_extent->setMaximumHeight(12);
|
||||
m_label_extent->setText("V");
|
||||
m_label_extent->setAlignment(Qt::AlignCenter);
|
||||
tVB->addWidget(m_label_extent);
|
||||
m_label_extent->setVisible(false);
|
||||
|
||||
m_pushButton->setObjectName("RibbonToolButton");
|
||||
connect(m_pushButton, SIGNAL(clicked(bool)), this, SIGNAL(triggered(bool)));
|
||||
}
|
||||
|
||||
RibbonToolButtonBig::~RibbonToolButtonBig()
|
||||
{
|
||||
delete m_pushButton;
|
||||
delete m_label;
|
||||
}
|
||||
|
||||
QPushButton* RibbonToolButtonBig::pushButton() const
|
||||
{
|
||||
return m_pushButton;
|
||||
}
|
||||
|
||||
QLabel* RibbonToolButtonBig::label() const
|
||||
{
|
||||
return m_label;
|
||||
}
|
||||
|
||||
void RibbonToolButtonBig::setExtentIconVisible(bool tVal)
|
||||
{
|
||||
m_label_extent->setVisible(tVal);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,535 @@
|
||||
#ifndef QSR_RIBBON_CORE_H
|
||||
#define QSR_RIBBON_CORE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QToolBar>
|
||||
#include <QList>
|
||||
#include <QLabel>
|
||||
#include <QAction>
|
||||
#include <QPainter>
|
||||
#include <QStyleOption>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 当前的程序主要是运行在windows系统下, 如果运行在Linux下还需要进行优化,比如主界面的外框等
|
||||
*/
|
||||
|
||||
// 从大于0的开始, RIBBON开始的是控件,三级的归属于二级
|
||||
//(暂时还没有使用)
|
||||
enum RIBBON_OBJECT_TYPE // RIBBON 对象
|
||||
{
|
||||
RIBBON_OBJECTITEM = 0,
|
||||
RIBBON_TITLEBAR_QuickAccessBar, // 标题栏上左侧的 快捷图标
|
||||
RIBBON_TITLEBAR_Title, // 标题栏的 标题
|
||||
RIBBON_TITLEBAR_UserInfo, // 标题栏上的 用户信息
|
||||
RIBBON_TITLEBAR_StanderdButton, // 标题栏上的 右侧按钮
|
||||
RIBBON_TITLEBAR, // 以上是标题栏的内容
|
||||
RIBBON_MENUBAR_WidgetActionLeft, // 比如word中的“文件”按钮
|
||||
RIBBON_MENUBAR_WidgetActionRight, // 右侧的按钮
|
||||
RIBBON_MENUBAR, // 以上是菜单栏的内容
|
||||
RIBBON_TOOLBAR_GroupWidget, // 工具栏的控件容器(如 word中的“段落”为一组)
|
||||
RIBBON_TOOLBAR_IconWidget, // 大图标缩略图
|
||||
RIBBON_TOOLBAR_Saperator, // 工具栏控件容器中的分隔线
|
||||
RIBBON_TOOLBAR,// 以上是工具栏的内容
|
||||
RIBBON_CONTRAL_Control // 具体的控件
|
||||
};
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
/** @brief Ribbon操作.
|
||||
* @details 一个操作对应一个图标,或者控件
|
||||
*/
|
||||
typedef QWidget ribbonAction;
|
||||
|
||||
|
||||
/** @brief Ribbon Widget 的基类.
|
||||
* @details 为了实现Qss对QWidget的重绘
|
||||
*/
|
||||
class RobbonWidget :public QWidget
|
||||
{
|
||||
public:
|
||||
RobbonWidget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~RobbonWidget();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 需要自定义一套按钮,用来显示/隐藏 图标、文字, 参考之前实现的那个按钮的代码
|
||||
/** @brief RibbonControlBase 控件基类.
|
||||
* @details
|
||||
*/
|
||||
class RibbonControlBase
|
||||
{
|
||||
public:
|
||||
RibbonControlBase();
|
||||
~RibbonControlBase();
|
||||
|
||||
/** @brief 设置控件在GroupWidget中的位置,有两套位置可以设置.
|
||||
* @details 如果只有一种布局则不需要设置index参数.
|
||||
*/
|
||||
void setGroupPos(QPoint tPos, int index = -1);
|
||||
QPoint groupPos(int index);
|
||||
|
||||
virtual void setText(QString &text) {};
|
||||
virtual void setIcon(const QIcon &icon) {};
|
||||
virtual void setEnabled(bool &tEnabled) {};
|
||||
|
||||
|
||||
private:
|
||||
QPoint m_pos0, m_pos1;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** @brief RibbonPushButton 普通Ribbon按钮类.
|
||||
* @details
|
||||
*/
|
||||
class RibbonToolButton : public QPushButton, public RibbonControlBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RibbonToolButton(QWidget *parent = Q_NULLPTR);
|
||||
RibbonToolButton(const QString &text, QWidget *parent = Q_NULLPTR);
|
||||
RibbonToolButton(const QIcon &icon, const QString &text, QWidget *parent = Q_NULLPTR);
|
||||
~RibbonToolButton();
|
||||
|
||||
void setTxtVisible(bool tVal);
|
||||
bool txtVisible();
|
||||
|
||||
/** @brief 对齐方式. */
|
||||
void setAlignment(Qt::Alignment flag);
|
||||
|
||||
/** @brief 设置Action. //放弃使用: 不再接受从外部赋值 */
|
||||
//void setAction(QAction* tAction);
|
||||
/** @brief 获取Action. 用于从Ribbon风格切换到传统样式的菜单工具栏等 */
|
||||
QAction* getAction();
|
||||
|
||||
virtual void setText(QString &text);
|
||||
virtual void setIcon(const QIcon &icon);
|
||||
virtual void setEnabled(bool &tEnabled);
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
bool m_txtVisible;
|
||||
|
||||
/** @brief Action指针,从外部指定. */
|
||||
QAction* m_action;
|
||||
|
||||
// private:
|
||||
// RIBBON_OBJECT_TYPE m_objType;
|
||||
};
|
||||
|
||||
/** @brief RibbonPushButton 大的Ribbon按钮类.
|
||||
* @details
|
||||
*/
|
||||
class RibbonToolButtonBig : public RobbonWidget, public RibbonControlBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RibbonToolButtonBig(const QIcon &icon, const QString &text, QWidget *parent = Q_NULLPTR);
|
||||
~RibbonToolButtonBig();
|
||||
|
||||
QPushButton* pushButton() const;
|
||||
QLabel* label() const;
|
||||
void setExtentIconVisible(bool tVal);
|
||||
|
||||
virtual void setText(QString &text) {};
|
||||
virtual void setIcon(const QIcon &icon){};
|
||||
virtual void setEnabled(bool &tEnabled){};
|
||||
|
||||
|
||||
signals:
|
||||
void triggered(bool checked = false);
|
||||
|
||||
private:
|
||||
QPushButton* m_pushButton;
|
||||
QLabel* m_label, *m_label_extent;
|
||||
};
|
||||
|
||||
|
||||
// class ribbonAction: public QWidget
|
||||
// {
|
||||
// Q_OBJECT
|
||||
// public:
|
||||
// ribbonAction();
|
||||
// ~ribbonAction() {};
|
||||
//
|
||||
// private:
|
||||
//
|
||||
//
|
||||
// };
|
||||
|
||||
//基类
|
||||
// class QsrRibbonObject
|
||||
// {
|
||||
// public:
|
||||
// QsrRibbonObject() {};
|
||||
// ~QsrRibbonObject() {};
|
||||
// };
|
||||
|
||||
class QsrRibbonQuickAccessToolBar : /*public QsrRibbonObject,*/ public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsrRibbonQuickAccessToolBar() ;
|
||||
~QsrRibbonQuickAccessToolBar() {};
|
||||
};
|
||||
|
||||
/** @brief 标题栏.
|
||||
* @details 标题栏的组成(从左到右): 快捷工具栏,标题控件,用户信息控件,系统按钮(放置系统按钮:设置、最小化、最大化、关闭)
|
||||
*/
|
||||
class QsrRibbonTitleBar : /*public QsrRibbonObject ,*/ public RobbonWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QsrRibbonTitleBar();
|
||||
~QsrRibbonTitleBar();
|
||||
|
||||
/** @brief 设置窗口标题.
|
||||
*
|
||||
* @details 设置窗口标题.
|
||||
* @param title 窗口的标题.
|
||||
* @return .
|
||||
*/
|
||||
void setTitle(QString title);
|
||||
QString getTitle();
|
||||
|
||||
/** @brief 设置工具条的文字. */
|
||||
void setToolsText(QString txt);
|
||||
|
||||
void addQuickAction(QAction *action);
|
||||
void addSysAction(QAction* action);
|
||||
|
||||
void setUserInfo(QString txt);
|
||||
|
||||
private:
|
||||
QLabel* m_titleLable1, m_ToolsLabel, m_titleLable2;
|
||||
QLabel* m_userInfoLabel;
|
||||
QsrRibbonQuickAccessToolBar* m_quickAccessToolBar, *m_systemButton;
|
||||
};
|
||||
|
||||
|
||||
/** @brief Ribbon 操作组.
|
||||
* @details Ribbon 操作组
|
||||
*/
|
||||
#include <QGridLayout>
|
||||
#include <QActionGroup>
|
||||
class QtbGroupWidget : public RobbonWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtbGroupWidget();
|
||||
~QtbGroupWidget();
|
||||
|
||||
void setTitle(QString tTitle);
|
||||
void addAction(ribbonAction* rAct, int row, int col, int rowSpan = 1, int columnSpan = 1, Qt::Alignment alignment = Qt::Alignment());
|
||||
void addAction(RibbonToolButton* rAct, int row, int col, int rowSpan /*= 1*/, int columnSpan /*= 1*/, Qt::Alignment alignment /*= Qt::Alignment()*/);
|
||||
|
||||
QActionGroup* getActionGroup() const;
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
private:
|
||||
QGridLayout* m_gridLayout;
|
||||
QLabel* m_groupTitleLabel;
|
||||
|
||||
QActionGroup* m_actionGroup;
|
||||
};
|
||||
|
||||
/** @brief Ribbon菜单栏.
|
||||
* @details Ribbon菜单栏
|
||||
*/
|
||||
#include <QMap>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QStackedWidget>
|
||||
class QtbMenuBar : /*public QsrRibbonObject ,*/ public RobbonWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtbMenuBar();
|
||||
~QtbMenuBar();
|
||||
|
||||
/** @brief 增加操作按钮. */
|
||||
void addAction(ribbonAction* tAction,int tIndex);
|
||||
/** @brief 增加菜单. menuName是唯一的,也是显示的 */
|
||||
void addMenu(QString menuName);
|
||||
|
||||
/** @brief 增加扩展型菜单. menuName是全局唯一的,showName是显示的可以重复 */
|
||||
// void addExtendedMenu(QString menuName, QString showName);
|
||||
void setMenuVisible(QString menuName, bool tIsVisible);
|
||||
bool isMenuVisible(QString menuName);
|
||||
|
||||
QtbGroupWidget* addGroup(QString menuName, QString txtGroupTitle);
|
||||
void menuReady(QString menuName);
|
||||
|
||||
void setExtentBtnIcon(QIcon icoExtent, QIcon icoHide);
|
||||
|
||||
bool isToolBarVisible();
|
||||
public slots:
|
||||
void setToolBarVisible(bool tVal);
|
||||
|
||||
private slots:
|
||||
/** @brief Ribbon工具栏折叠/展开按钮的操作. */
|
||||
void onExtentToggled();
|
||||
void onCurrentTabChenged(int index);
|
||||
|
||||
protected:
|
||||
virtual void enterEvent(QEvent *event);
|
||||
virtual void leaveEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
/** @brief 菜单栏的TabBar. */
|
||||
QTabBar* m_menuTabBar;
|
||||
QTabBar* m_ExtentedMenuTabBar;
|
||||
/** @brief Ribbon菜单的主layout. */
|
||||
QHBoxLayout* m_layout;
|
||||
/** @brief Ribbon菜单的主layout. */
|
||||
QMap<QString, RobbonWidget*> m_StaWidMap;
|
||||
|
||||
/* 暂时不提供扩展型的可变菜单*/
|
||||
// QHBoxLayout* m_layoutExtented;
|
||||
// /** @brief Ribbon扩展菜单的按钮. */
|
||||
// QMap<QString, QPushButton*> m_extentedBtnMap;
|
||||
// QWidget* m_extentedWidget;
|
||||
|
||||
QStackedWidget* m_toolBarStackedWid;
|
||||
|
||||
/** @brief 折叠按钮. */
|
||||
RibbonToolButton* m_extentBtn;
|
||||
|
||||
bool m_toolBarVisible;
|
||||
|
||||
QIcon m_icoExtent, m_icoHide;
|
||||
|
||||
};
|
||||
|
||||
/** @brief Ribbon工具栏.
|
||||
* @details Ribbon工具栏.
|
||||
*/
|
||||
class QtbToolBar : /*public QsrRibbonObject ,*/ public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtbToolBar();
|
||||
~QtbToolBar();
|
||||
|
||||
void addMenu(QString txt);
|
||||
private:
|
||||
// QTabBar m_menuTabBar;
|
||||
// QHBoxLayout m_layout;
|
||||
// QMap<QString, RobbonWidget*> m_menuLabelMap;
|
||||
// QTabWidget* m_toolTabWidget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** @brief 主窗口.
|
||||
* @details
|
||||
*/
|
||||
#include <QDragMoveEvent>
|
||||
class QsfWorkWindow;
|
||||
class QDockWidget;
|
||||
//#include "SgfParamManager.h"
|
||||
class QtbMainWindow : public RobbonWidget //, public SgfParamManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtbMainWindow(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~QtbMainWindow();
|
||||
|
||||
QsrRibbonTitleBar* titleBar();
|
||||
QtbMenuBar* menuBar();
|
||||
|
||||
/** @brief 创建DockWidget. */
|
||||
QDockWidget* createDockWidget(QString title, QString name, Qt::DockWidgetArea area);
|
||||
|
||||
/** @brief 创建工作页Widget. */
|
||||
QWidget* createWorkWidget(QString title, QString name);
|
||||
/** @brief 添加已有的widget作为工作页Widget. */
|
||||
void addWorkWidget(QWidget* tWidget);
|
||||
|
||||
|
||||
private:
|
||||
QsrRibbonTitleBar* m_titleBar;
|
||||
QtbMenuBar* m_menuBar;
|
||||
|
||||
protected:
|
||||
|
||||
/** @brief 标题范围. */
|
||||
QRect m_titleRect;
|
||||
|
||||
/** @brief 工作窗口. */
|
||||
QsfWorkWindow* m_workWindow;
|
||||
|
||||
|
||||
/** @brief 鼠标上一次的位置. */
|
||||
QPoint oldMousePos;
|
||||
/** @brief 鼠标单击. */
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
/** @brief 鼠标上双击. */
|
||||
void mouseDoubleClickEvent(QMouseEvent * event);
|
||||
/** @brief 鼠标拖动. */
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
|
||||
|
||||
public slots:
|
||||
void onSkin();
|
||||
};
|
||||
|
||||
/** @brief 主窗口借助dwmapi实现在windows下的拖动
|
||||
* @details Linux下的暂时没有做实现。次出应当用宏来统一windows和linux
|
||||
*/
|
||||
#include <windowsx.h>
|
||||
#include <dwmapi.h>
|
||||
class NativeEventFilter : public QAbstractNativeEventFilter
|
||||
{
|
||||
public:
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) Q_DECL_OVERRIDE
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
if (eventType != "windows_generic_MSG")
|
||||
return false;
|
||||
|
||||
MSG* msg = static_cast<MSG*>(message);
|
||||
QWidget* widget0 = QWidget::find(reinterpret_cast<WId>(msg->hwnd));
|
||||
if (widget0 == NULL)
|
||||
return false;
|
||||
|
||||
QtbMainWindow* widget = static_cast<QtbMainWindow*>(widget0);
|
||||
if (!widget)
|
||||
return false;
|
||||
|
||||
if (widget->isMaximized())
|
||||
return false;
|
||||
|
||||
switch (msg->message)
|
||||
{
|
||||
// case WM_NCCALCSIZE: { // 如果处理该消息,dock窗口或子窗口会有问题
|
||||
// *result = 0;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
case WM_NCHITTEST: {
|
||||
const LONG borderWidth = 9;
|
||||
RECT winrect;
|
||||
GetWindowRect(msg->hwnd, &winrect);
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
|
||||
// bottom left
|
||||
if (x >= winrect.left && x < winrect.left + borderWidth &&
|
||||
y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
||||
{
|
||||
*result = HTBOTTOMLEFT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// bottom right
|
||||
if (x < winrect.right && x >= winrect.right - borderWidth &&
|
||||
y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
||||
{
|
||||
*result = HTBOTTOMRIGHT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// top left
|
||||
if (x >= winrect.left && x < winrect.left + borderWidth &&
|
||||
y >= winrect.top && y < winrect.top + borderWidth)
|
||||
{
|
||||
*result = HTTOPLEFT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// top right
|
||||
if (x < winrect.right && x >= winrect.right - borderWidth &&
|
||||
y >= winrect.top && y < winrect.top + borderWidth)
|
||||
{
|
||||
*result = HTTOPRIGHT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// left
|
||||
if (x >= winrect.left && x < winrect.left + borderWidth)
|
||||
{
|
||||
*result = HTLEFT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// right
|
||||
if (x < winrect.right && x >= winrect.right - borderWidth)
|
||||
{
|
||||
*result = HTRIGHT;
|
||||
return true;
|
||||
}
|
||||
|
||||
// bottom
|
||||
if (y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
||||
{
|
||||
*result = HTBOTTOM;
|
||||
return true;
|
||||
}
|
||||
|
||||
// top
|
||||
if (y >= winrect.top && y < winrect.top + borderWidth)
|
||||
{
|
||||
*result = HTTOP;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //QSF_TITLEBAR_H
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "SgfParamManager.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
/** @brief ²ÎÊýÈÝÆ÷±äÁ¿*/
|
||||
map<std::string, void *> m_mapParaManager;
|
||||
static SgfParamManager* m_SgfParamManager_pInstance = NULL;
|
||||
|
||||
SgfParamManager* SgfParamManager::GetInstance()
|
||||
{
|
||||
if (m_SgfParamManager_pInstance == NULL)
|
||||
m_SgfParamManager_pInstance = new SgfParamManager();
|
||||
|
||||
return m_SgfParamManager_pInstance;
|
||||
}
|
||||
|
||||
void SgfParamManager::addParam(const string &tKey, void *paramValue)
|
||||
{
|
||||
// Reemplaza la línea problemática
|
||||
string tKeyLow = tKey; // Copia el contenido de tKey
|
||||
std::transform(tKeyLow.begin(), tKeyLow.end(), tKeyLow.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
|
||||
//string tKeyLow = strlwr((char*)(tKey.data()));
|
||||
map<string, void *>::iterator it = m_mapParaManager.find(tKey);
|
||||
if (it == m_mapParaManager.end())
|
||||
{
|
||||
m_mapParaManager.insert(std::pair<string, void*>(tKey, paramValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second = paramValue;
|
||||
}
|
||||
}
|
||||
|
||||
void* SgfParamManager::getParamValue(const string &tKey)
|
||||
{
|
||||
string tKeyLow = tKey; // Copia el contenido de tKey
|
||||
std::transform(tKeyLow.begin(), tKeyLow.end(), tKeyLow.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
|
||||
//string tKeyLow = strlwr((char*)(tKey.data()));
|
||||
map<string, void *>::iterator it = m_mapParaManager.find(tKey);
|
||||
if (it == m_mapParaManager.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/************************************************************************
|
||||
* 版权所有 (C) 梁振 Email: liang1057@163.com.cn
|
||||
*
|
||||
* 文件名称: SgfParamManager.h
|
||||
* 内容摘要: 平台内核-参数管理类头文件
|
||||
* 其它说明: 无
|
||||
* 当前版本: 0.1
|
||||
* 作 者: leon
|
||||
* 完成日期: 2016-11-22
|
||||
*
|
||||
* 修改记录1:
|
||||
* 修改日期:
|
||||
* 版 本 号:
|
||||
* 修 改 人:
|
||||
* 修改内容:
|
||||
* 修改记录2:…
|
||||
************************************************************************/
|
||||
#ifndef SWFPARAMMANAGER_H
|
||||
#define SWFPARAMMANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class SgfParamManager
|
||||
{
|
||||
public:
|
||||
/** brief 单例模式. */
|
||||
static SgfParamManager* GetInstance();
|
||||
|
||||
/** @brief 添加参数函数.
|
||||
*
|
||||
* @details 添加参数函数.
|
||||
* @param tKey 参数名称.
|
||||
* @param paramValue 参数值指针.
|
||||
* @return void.
|
||||
*/
|
||||
void addParam(const string &tKey, void *paramValue);
|
||||
|
||||
|
||||
/** @brief 获取参数值指针函数.
|
||||
*
|
||||
* @details 获取参数值指针函数.
|
||||
* @param tKey 参数名称.
|
||||
* @return void * 参数值指针.
|
||||
*/
|
||||
void* getParamValue(const string &tKey);
|
||||
};
|
||||
|
||||
|
||||
#endif // SWFPARAMMANAGER_H
|
||||
Reference in New Issue
Block a user