Initial commit of BudgetPro
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
SET(VERSION_SHORT 0.1)
|
||||
project(MdiAreaWindowExample VERSION ${VERSION_SHORT})
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
# qt库加载,最低要求5.8
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} 5.8 COMPONENTS Core Gui Widgets REQUIRED)
|
||||
file(GLOB HEADER_FILES "${CMAKE_CURRENT_LIST_DIR}/*.h")
|
||||
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")
|
||||
file(GLOB UI_FILES "${CMAKE_CURRENT_LIST_DIR}/*.ui")
|
||||
file(GLOB RESOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/*.qrc")
|
||||
add_executable(MdiAreaWindowExample WIN32
|
||||
${HEADER_FILES}
|
||||
${SOURCE_FILES}
|
||||
${UI_FILES}
|
||||
${RESOURCE_FILES}
|
||||
)
|
||||
|
||||
if(NOT TARGET SARibbonBar)
|
||||
# 说明这个例子是单独加载
|
||||
message(STATUS "NOT TARGET SARibbonBar find_package(SARibbonBar REQUIRED)")
|
||||
find_package(SARibbonBar REQUIRED)
|
||||
endif()
|
||||
|
||||
target_link_libraries(MdiAreaWindowExample PUBLIC SARibbonBar::SARibbonBar)
|
||||
target_link_libraries(MdiAreaWindowExample PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
set_target_properties(MdiAreaWindowExample PROPERTIES
|
||||
AUTOMOC ON
|
||||
AUTORCC ON
|
||||
AUTOUIC ON
|
||||
CXX_EXTENSIONS OFF
|
||||
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
|
||||
VERSION ${SARIBBON_VERSION}
|
||||
EXPORT_NAME MdiAreaWindowExample
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
||||
)
|
||||
|
||||
install(TARGETS MdiAreaWindowExample
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION bin
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QMdiArea" name="mdiArea"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="windowTitle">
|
||||
<string>toolBar</string>
|
||||
</property>
|
||||
<property name="allowedAreas">
|
||||
<set>Qt::LeftToolBarArea|Qt::RightToolBarArea</set>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>LeftToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionadd_window"/>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget">
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents"/>
|
||||
</widget>
|
||||
<action name="actionadd_window">
|
||||
<property name="icon">
|
||||
<iconset resource="icon.qrc">
|
||||
<normaloff>:/mdiWindowApp/icon/add.svg</normaloff>:/mdiWindowApp/icon/add.svg</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>add window</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="icon.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,37 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-09-21T14:04:12
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
# SARibbon 1.x 版本后引入frameless库,必须要cpp17及以上
|
||||
CONFIG += c++17
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = MdiAreaWindowExample
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += main.cpp\
|
||||
mdimainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mdimainwindow.h
|
||||
|
||||
FORMS += \
|
||||
MainWindow.ui
|
||||
|
||||
RESOURCES += \
|
||||
icon.qrc
|
||||
# 下面演示了如何把SARibbon引入
|
||||
# 只需要下面2句话,只要把common.pri引入工程,就可以实现SARibbon的引入
|
||||
include($$PWD/../../common.pri)
|
||||
include($${SARIBBONBAR_PRI_FILE_PATH})
|
||||
|
||||
DESTDIR = $${SARIBBON_BIN_DIR}/bin
|
||||
|
||||
msvc {
|
||||
QMAKE_CFLAGS += /utf-8
|
||||
QMAKE_CXXFLAGS += /utf-8
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/mdiWindowApp">
|
||||
<file>icon/add.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1645972462678" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3334" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><defs><style type="text/css"></style></defs><path d="M854.42 938.77H177.51V85.28h529.76l147.15 147.16z" fill="#949BA6" p-id="3335"></path><path d="M854.42 232.44H707.27V85.28z" fill="#FFC600" p-id="3336"></path><path d="M721.98 261.87c0 8.09 6.62 14.72 14.72 14.72h117.72v-44.15H721.98v29.43z" fill="#717582" p-id="3337"></path><path d="M236.37 247.15c-8.09 0-14.72-6.62-14.72-14.72v-88.29c0-8.09 6.62-14.72 14.72-14.72 8.09 0 14.72 6.62 14.72 14.72v88.29c0 8.1-6.62 14.72-14.72 14.72zM236.37 894.63c-8.09 0-14.72-6.62-14.72-14.72V350.16c0-8.09 6.62-14.72 14.72-14.72 8.09 0 14.72 6.62 14.72 14.72v529.75c0 8.1-6.62 14.72-14.72 14.72z" fill="#DFE1E4" p-id="3338"></path><path d="M236.37 291.3m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#DFE1E4" p-id="3339"></path><path d="M913.28 423.74c-8.09 0-14.72 6.62-14.72 14.72V673.9c0 8.09 6.62 14.72 14.72 14.72 8.09 0 14.72-6.62 14.72-14.72V438.45c0-8.09-6.63-14.71-14.72-14.71z" fill="#090418" p-id="3340"></path><path d="M913.28 791.62m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3341"></path><path d="M913.28 732.76m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3342"></path><path d="M118.65 232.44m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3343"></path><path d="M118.65 291.3m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3344"></path><path d="M118.65 173.58m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3345"></path><path d="M295.24 453.17h264.88c8.09 0 14.72-6.62 14.72-14.72s-6.62-14.72-14.72-14.72H295.24c-8.09 0-14.72 6.62-14.72 14.72s6.62 14.72 14.72 14.72zM604.26 438.45c0 8.09 6.62 14.72 14.72 14.72H736.7c8.09 0 14.72-6.62 14.72-14.72s-6.62-14.72-14.72-14.72H618.97c-8.09 0.01-14.71 6.63-14.71 14.72zM736.7 482.6H295.24c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72H736.7c8.09 0 14.72-6.62 14.72-14.72-0.01-8.1-6.63-14.72-14.72-14.72zM295.24 688.61h264.88c8.09 0 14.72-6.62 14.72-14.72s-6.62-14.72-14.72-14.72H295.24c-8.09 0-14.72 6.62-14.72 14.72s6.62 14.72 14.72 14.72zM574.83 776.9H295.24c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72h279.59c8.09 0 14.72-6.62 14.72-14.72-0.01-8.09-6.63-14.72-14.72-14.72zM736.7 659.18h-58.86c-8.09 0-14.72 6.62-14.72 14.72s6.62 14.72 14.72 14.72h58.86c8.09 0 14.72-6.62 14.72-14.72s-6.63-14.72-14.72-14.72zM295.24 364.87h58.86c8.09 0 14.72-6.62 14.72-14.72 0-8.09-6.62-14.72-14.72-14.72h-9.2l9.93-29.43h57.39l9.93 29.43h-9.2c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72h58.86c8.09 0 14.72-6.62 14.72-14.72 0-8.09-6.62-14.72-14.72-14.72h-18.76L397.5 168.78c0-0.37-0.37-0.37-0.37-0.74-0.37-0.74-0.37-1.1-0.74-1.47-0.37-1.1-1.1-1.84-1.84-2.94-0.37-0.37-0.74-0.74-1.47-1.1-0.74-0.74-1.84-1.47-2.94-1.84-0.37-0.37-1.1-0.74-1.47-0.74-1.47-0.74-3.31-1.1-5.15-1.1H354.1c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72h9.2L314 335.44h-18.76c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.71 14.72 14.71z m88.29-144.94l18.76 56.65h-37.52l18.76-56.65zM471.82 276.58h22.07v22.07c0 8.09 6.62 14.72 14.72 14.72 8.09 0 14.72-6.62 14.72-14.72v-22.07h22.07c8.09 0 14.72-6.62 14.72-14.72s-6.62-14.72-14.72-14.72h-22.07v-22.07c0-8.09-6.62-14.72-14.72-14.72-8.09 0-14.72 6.62-14.72 14.72v22.07h-22.07c-8.09 0-14.72 6.62-14.72 14.72s6.63 14.72 14.72 14.72zM648.4 615.04c0-8.09-6.62-14.72-14.72-14.72H295.24c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72h338.45c8.09-0.01 14.71-6.63 14.71-14.72zM736.7 541.46H295.24c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72H736.7c8.09 0 14.72-6.62 14.72-14.72-0.01-8.1-6.63-14.72-14.72-14.72zM736.7 718.04H295.24c-8.09 0-14.72 6.62-14.72 14.72 0 8.09 6.62 14.72 14.72 14.72H736.7c8.09 0 14.72-6.62 14.72-14.72-0.01-8.1-6.63-14.72-14.72-14.72z" fill="#090418" p-id="3346"></path><path d="M864.72 222.14L717.57 74.98c-1.47-1.47-2.94-2.58-4.78-3.31s-3.68-1.1-5.52-1.1H177.51c-8.09 0-14.72 6.62-14.72 14.72v853.49c0 8.09 6.62 14.72 14.72 14.72h676.91c8.09 0 14.72-6.62 14.72-14.72V232.44c0-1.84-0.37-4.05-1.1-5.52-0.75-1.84-1.85-3.68-3.32-4.78zM721.98 120.97l96.75 96.75h-96.75v-96.75zM839.7 924.06H192.23V100h500.32v132.44c0 8.09 6.62 14.72 14.72 14.72H839.7v676.9z" fill="#090418" p-id="3347"></path><path d="M618.97 673.9m-14.72 0a14.72 14.72 0 1 0 29.44 0 14.72 14.72 0 1 0-29.44 0Z" fill="#090418" p-id="3348"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
@@ -0,0 +1,64 @@
|
||||
#include "mdimainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
#include "SARibbonBar.h"
|
||||
// 重定向qdebug的打印
|
||||
void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
||||
|
||||
/**
|
||||
* @brief 重定向qdebug的打印
|
||||
* @param type
|
||||
* @param context
|
||||
* @param msg
|
||||
*/
|
||||
void log_out_put(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||
{
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
fprintf(stdout, "%s |[Debug] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
|
||||
break;
|
||||
|
||||
case QtWarningMsg:
|
||||
fprintf(stdout, "%s |[Warning] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
|
||||
break;
|
||||
|
||||
case QtCriticalMsg:
|
||||
fprintf(stdout, "%s |[Critical] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
|
||||
break;
|
||||
|
||||
case QtFatalMsg:
|
||||
fprintf(stdout, "%s |[Fatal] (%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
|
||||
abort();
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stdout, "%s |[Debug](%s[%u],%s)\n", localMsg.constData(), context.function, context.line, context.file);
|
||||
break;
|
||||
}
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// 以下是针对高分屏的设置,有高分屏需求都需要按照下面进行设置
|
||||
SARibbonBar::initHighDpi();
|
||||
|
||||
QApplication a(argc, argv);
|
||||
qInstallMessageHandler(log_out_put);
|
||||
QFont f = a.font();
|
||||
f.setFamily(u8"微软雅黑");
|
||||
a.setFont(f);
|
||||
QElapsedTimer cost;
|
||||
|
||||
cost.start();
|
||||
MainWindow w;
|
||||
qDebug() << "window build cost:" << cost.elapsed() << " ms";
|
||||
w.show();
|
||||
|
||||
return (a.exec());
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "mdimainwindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include <QTextEdit>
|
||||
#include <QMdiSubWindow>
|
||||
#include "SARibbonBar.h"
|
||||
#include "SARibbonCategory.h"
|
||||
#include "SARibbonPannel.h"
|
||||
MainWindow::MainWindow(QWidget* parent) : SARibbonMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
// 注意,你必须在ui文件中删除菜单栏,否则会拿到空的ribbon指针
|
||||
ui->setupUi(this);
|
||||
SARibbonBar* ribbon = ribbonBar();
|
||||
SARibbonCategory* mainPage = new SARibbonCategory("Main");
|
||||
ribbon->addCategoryPage(mainPage);
|
||||
buildMainPage(mainPage);
|
||||
// 如果你用qwk,你需要安装mdi窗口的最大最小化按钮到frameless框架中,你需要绑定此槽函数
|
||||
connect(ui->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::onMdiAreaSubWindowActivated);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::buildMainPage(SARibbonCategory* mainPage)
|
||||
{
|
||||
SARibbonPannel* mainPannel = new SARibbonPannel("operate");
|
||||
mainPannel->addAction(ui->actionadd_window);
|
||||
mainPage->addPannel(mainPannel);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionadd_window_triggered()
|
||||
{
|
||||
QMdiSubWindow* sub = ui->mdiArea->addSubWindow(new QTextEdit());
|
||||
sub->setAttribute(Qt::WA_DeleteOnClose);
|
||||
sub->show();
|
||||
// 如果你用qwk,你需要安装mdi窗口的最大最小化按钮到frameless框架中,你需要绑定此槽函数
|
||||
connect(sub, &QMdiSubWindow::windowStateChanged, this, &MainWindow::onSubWindowStateChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 窗口激活后对cornerwidget的绑定
|
||||
*
|
||||
* @note mdi窗口的状态变化会导致原来的cornerwidget删除,因此,subWindowActivated和windowStateChanged这两个都要绑定,
|
||||
* 防止任意一种状态变化没有监测到,例如最大化状态关闭所有窗口,再新建一个窗口,这时候它不会触发windowStateChanged,但会触发subWindowActivated
|
||||
* @param window
|
||||
*/
|
||||
void MainWindow::onMdiAreaSubWindowActivated(QMdiSubWindow* window)
|
||||
{
|
||||
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
|
||||
if (window) {
|
||||
SARibbonBar* ribbon = ribbonBar();
|
||||
QWidget* cw = ribbon->cornerWidget(Qt::TopRightCorner);
|
||||
if (cw && cw != m_mdiCornerWidget) {
|
||||
qDebug() << "set mdi corner widget in frameless|onMdiAreaSubWindowActivated";
|
||||
setFramelessHitTestVisible(cw);
|
||||
m_mdiCornerWidget = cw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 子窗口变化对cornerwidget的绑定
|
||||
* @param oldState
|
||||
* @param newState
|
||||
*/
|
||||
void MainWindow::onSubWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState)
|
||||
{
|
||||
#if SARIBBON_USE_3RDPARTY_FRAMELESSHELPER
|
||||
if (newState.testFlag(Qt::WindowMaximized)) {
|
||||
SARibbonBar* ribbon = ribbonBar();
|
||||
QWidget* cw = ribbon->cornerWidget(Qt::TopRightCorner);
|
||||
if (cw && cw != m_mdiCornerWidget) {
|
||||
qDebug() << "set mdi corner widget in frameless|onSubWindowStateChanged";
|
||||
setFramelessHitTestVisible(cw);
|
||||
m_mdiCornerWidget = cw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "SARibbonMainWindow.h"
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
class QMdiSubWindow;
|
||||
class SARibbonCategory;
|
||||
class MainWindow : public SARibbonMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void on_actionadd_window_triggered();
|
||||
void onMdiAreaSubWindowActivated(QMdiSubWindow* window);
|
||||
void onSubWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState);
|
||||
|
||||
private:
|
||||
void buildMainPage(SARibbonCategory* mainPage);
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
QWidget* m_mdiCornerWidget { nullptr };
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
Reference in New Issue
Block a user