Skip to content

Commit

Permalink
tabbed_plot_widget增加部分事件处理
Browse files Browse the repository at this point in the history
  • Loading branch information
ComerLater committed May 24, 2024
1 parent ba6bf3f commit 178ec30
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/common/common.pri
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
QT += xml

HEADERS += $$PWD/data_source_base.hpp
HEADERS += $$PWD/data_source_base.hpp \
$$PWD/load_svg.hpp

INCLUDEPATH += $$PWD

Expand Down
72 changes: 72 additions & 0 deletions src/common/load_svg.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*****************************************************************
* _ __ __ ____ _ __ __
* / | / /___ _ __ / /_ / __ \ (_)/ /____ / /_
* / |/ // _ \ | |/_// __// /_/ // // // __ \ / __/
* / /| // __/_> < / /_ / ____// // // /_/ // /_
* /_/ |_/ \___//_/|_| \__//_/ /_//_/ \____/ \__/
*
* Copyright All Reserved © 2015-2024 NextPilot Development Team
******************************************************************/

#ifndef __LOAD_SVG_H__
#define __LOAD_SVG_H__


/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/


#ifdef QT_NO_SVGRENDERER
# error "QT_NO_SVGRENDERER defined"
#endif

#include <QtSvg>
#include <QFile>
#include <QIcon>
#include <QTextStream>
#include <QByteArray>
#include <QPainter>
#include <QPixmap>
#include <QDebug>

// Useful function to change the color of SVG icons programmatically.
// Useful to switch between dark view and light view.
// To work, the SVG file must use the color #ffffff and #000000 only.
inline const QPixmap &LoadSvg(QString filename, QString style_name = "light") {
static std::map<QString, QPixmap> light_images;
static std::map<QString, QPixmap> dark_images;
bool light_theme = style_name.contains("light");

auto *stored_images = light_theme ? &light_images : &dark_images;

auto it = stored_images->find(filename);
if (it == stored_images->end()) {
QFile file(filename);
file.open(QFile::ReadOnly | QFile::Text);
auto svg_data = file.readAll();
file.close();

if (light_theme) {
svg_data.replace("#000000", "#111111");
svg_data.replace("#ffffff", "#dddddd");
} else {
svg_data.replace("#000000", "#dddddd");
svg_data.replace("#ffffff", "#111111");
}
QByteArray content(svg_data);

QSvgRenderer rr(content);
QImage image(64, 64, QImage::Format_ARGB32);
QPainter painter(&image);
image.fill(Qt::transparent);
rr.render(&painter);

it = stored_images->insert({filename, QPixmap::fromImage(image)}).first;
}
return it->second;
}

#endif // __LOAD_SVG_H__
13 changes: 8 additions & 5 deletions src/main/main.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += core gui widgets xml
QT += core gui widgets xml svg

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Expand All @@ -15,15 +15,15 @@ TEMPLATE = app
SOURCES += \
main.cpp \
mainwindow.cpp \
plot/plot_axes.cpp \
plot/plot_figure.cpp \
plot/docked_axes.cpp \
plot/docked_figure.cpp \
plot/tabbed_plot_widget.cpp \
project_explorer.cpp

HEADERS += \
mainwindow.h \
plot/plot_axes.hpp \
plot/plot_figure.hpp \
plot/docked_axes.hpp \
plot/docked_figure.hpp \
plot/tabbed_plot_widget.hpp \
project_explorer.hpp

Expand All @@ -48,6 +48,9 @@ include($$PWD/../3rdparty/qwt/importQwtLib.pri)
# add SARibbon lib
include($$PWD/../3rdparty/SARibbon/importSARibbonBarLib.pri)

# add commm lib
include($$PWD/../common/common.pri)

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
Expand Down
15 changes: 6 additions & 9 deletions src/main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ MainWindow::MainWindow(QWidget *parent) :
// 创建ui界面
ui->setupUi(this);


// 创建ribbon菜单
createRibbon();

// dock管理器
createDockManager();

// 项目浏览器窗口
createPrjectExplorer();

// 绘图窗口(中心窗口)
createTabbedPlot();


// 属性窗口
}

Expand All @@ -66,8 +61,8 @@ void MainWindow::createRibbon() {
SARibbonCategory *main = _ribbon_bar->addCategoryPage(tr("IMPORT"));
SARibbonPannel *pannel = main->addPannel(tr("actions"));
pannel->addAction(tr("action1"), QIcon(":/core/resources/svg/grid.svg"), QToolButton::InstantPopup);
pannel->addAction(tr("action2"), QIcon(":/app/icon/customize0.svg"), QToolButton::InstantPopup);
pannel->addAction(tr("action3"), QIcon(":/app/icon/save.svg"), QToolButton::InstantPopup);
// pannel->addAction(tr("action2"), QIcon(":/app/icon/customize0.svg"), QToolButton::InstantPopup);
// pannel->addAction(tr("action3"), QIcon(":/app/icon/save.svg"), QToolButton::InstantPopup);
pannel->addAction(tr("action4"), QIcon(":/core/resources/svg/grid.svg"), QToolButton::InstantPopup, SARibbonPannelItem::Small);
pannel->addAction(tr("action5"), QIcon(":/core/resources/svg/grid.svg"), QToolButton::InstantPopup, SARibbonPannelItem::Small);
pannel->addAction(tr("action6"), QIcon(":/core/resources/svg/grid.svg"), QToolButton::InstantPopup, SARibbonPannelItem::Small);
Expand All @@ -92,7 +87,7 @@ void MainWindow::createDockManager() {
// 配置docker
ads::CDockManager::setConfigFlag(ads::CDockManager::DockAreaHasTabsMenuButton, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::DockAreaHasUndockButton, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::AlwaysShowTabs, false);
// ads::CDockManager::setConfigFlag(ads::CDockManager::AlwaysShowTabs, false);
ads::CDockManager::setConfigFlag(ads::CDockManager::OpaqueSplitterResize, true);
ads::CDockManager::setConfigFlag(ads::CDockManager::XmlCompressionEnabled, false);
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
Expand All @@ -111,6 +106,7 @@ void MainWindow::createDockManager() {
}

void MainWindow::createPrjectExplorer() {
createDockManager();
_project_explorer = new ProjectExplorer(this);
ads::CDockWidget *dock = new ads::CDockWidget("Project Explore");
dock->setWidget(_project_explorer);
Expand All @@ -123,11 +119,12 @@ void MainWindow::createPrjectExplorer() {
}

void MainWindow::createTabbedPlot() {
createDockManager();
_main_tabbed_plot = new TabbedPlotWidget(this);
ads::CDockWidget *dock = new ads::CDockWidget("Tabbed Plot");
dock->setWidget(_main_tabbed_plot);
_dock_manager->addDockWidget(ads::RightDockWidgetArea, dock);
// _dock_manager->setCentralWidget(dock);
//_dock_manager->setCentralWidget(dock);

// auto* wdg = new QPushButton(this);
// dock->setWidget(wdg);
Expand Down
8 changes: 4 additions & 4 deletions src/main/plot/plot_axes.cpp → src/main/plot/docked_axes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* Copyright All Reserved © 2015-2024 NextPilot Development Team
******************************************************************/

#include "plot_axes.hpp"
#include "docked_axes.hpp"

PlotAxes::PlotAxes(QWidget *parent) :
PlotAxes("plot", parent) {
DockedAxes::DockedAxes(QWidget *parent) :
DockedAxes("plot", parent) {
}

PlotAxes::PlotAxes(const QString &title, QWidget *parent) :
DockedAxes::DockedAxes(const QString &title, QWidget *parent) :
ads::CDockWidget(title, parent) {
setFrameShape(QFrame::NoFrame);
setFeature(ads::CDockWidget::DockWidgetFloatable, false);
Expand Down
6 changes: 3 additions & 3 deletions src/main/plot/plot_axes.hpp → src/main/plot/docked_axes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
#include "qwt_symbol.h"
#include "qwt_text.h"

class PlotAxes : public ads::CDockWidget {
class DockedAxes : public ads::CDockWidget {
Q_OBJECT

public:
PlotAxes(QWidget *parent = nullptr);
PlotAxes(const QString &title, QWidget *parent = nullptr);
DockedAxes(QWidget *parent = nullptr);
DockedAxes(const QString &title, QWidget *parent = nullptr);


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright All Reserved © 2015-2024 NextPilot Development Team
******************************************************************/

#include "plot_figure.hpp"
#include "docked_figure.hpp"
#include "DockComponentsFactory.h"
#include "DockAreaTitleBar.h"
#include "DockAreaWidget.h"
Expand All @@ -22,7 +22,7 @@ class SplittableComponentsFactory : public ads::CDockComponentsFactory {
}
};

PlotFigure::PlotFigure(QWidget *parent) :
DockedFigure::DockedFigure(QWidget *parent) :
ads::CDockManager(parent) {
ads::CDockComponentsFactory::setFactory(new SplittableComponentsFactory());

Expand All @@ -31,12 +31,12 @@ PlotFigure::PlotFigure(QWidget *parent) :
addAxes("axes 2");
}

PlotFigure::~PlotFigure() {
DockedFigure::~DockedFigure() {
}

PlotAxes *PlotFigure::addAxes(QString title) {
PlotAxes *axes = new PlotAxes(title, this);
auto *area = addDockWidget(ads::TopDockWidgetArea, axes);
DockedAxes *DockedFigure::addAxes(QString title) {
DockedAxes *axes = new DockedAxes(title, this);
auto *area = addDockWidget(ads::TopDockWidgetArea, axes);
area->setAllowedAreas(ads::OuterDockAreas);

return axes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
#include <QDomElement>
#include <QXmlStreamReader>
#include "DockManager.h"
#include "plot_axes.hpp"
#include "docked_axes.hpp"

class PlotFigure : public ads::CDockManager {
class DockedFigure : public ads::CDockManager {
Q_OBJECT

public:
PlotFigure(QWidget *parent);
~PlotFigure() override;
DockedFigure(QWidget *parent);
~DockedFigure() override;

PlotAxes *addAxes(QString name);
PlotAxes *addSubplot();
DockedAxes *addAxes(QString name);
DockedAxes *addSubplot();
};
#endif // __PLOT_FIGURE_H__
Loading

0 comments on commit 178ec30

Please sign in to comment.