diff --git a/bt_editor/graphic_container.cpp b/bt_editor/graphic_container.cpp index 3dfce1b6..5a9872c2 100644 --- a/bt_editor/graphic_container.cpp +++ b/bt_editor/graphic_container.cpp @@ -11,6 +11,7 @@ #include #include #include +#include using namespace QtNodes; @@ -162,6 +163,18 @@ void GraphicContainer::nodeReorder() emit undoableChange(); } +void GraphicContainer::saveSvgFile(const QString path) +{ + QSvgGenerator generator; + QRectF rect = _scene->itemsBoundingRect(); + generator.setFileName(path); + generator.setSize(QSize(rect.width(), rect.height())); + generator.setViewBox(rect); + QPainter painter; + painter.begin(&generator); + _scene->render(&painter, rect, rect); +} + void GraphicContainer::zoomHomeView() { QRectF rect = _scene->itemsBoundingRect(); @@ -720,5 +733,3 @@ void GraphicContainer::loadFromJson(const QByteArray &data) clearScene(); scene()->loadFromMemory( data ); } - - diff --git a/bt_editor/graphic_container.h b/bt_editor/graphic_container.h index b725e8bf..eb3ee3c6 100644 --- a/bt_editor/graphic_container.h +++ b/bt_editor/graphic_container.h @@ -33,6 +33,8 @@ class GraphicContainer : public QObject void nodeReorder(); + void saveSvgFile(const QString path); + void zoomHomeView(); bool containsValidTree() const; diff --git a/bt_editor/mainwindow.cpp b/bt_editor/mainwindow.cpp index 21c9804c..d27af35b 100644 --- a/bt_editor/mainwindow.cpp +++ b/bt_editor/mainwindow.cpp @@ -662,13 +662,30 @@ void MainWindow::onAutoArrange() currentTabInfo()->nodeReorder(); } +void MainWindow::onSaveSvg() +{ + QSettings settings; + QString last_load_path = settings.value("MainWindow.lastLoadDirectory", + QDir::homePath() ).toString(); + QString directory_path = settings.value("MainWindow.lastSaveSvgDirectory", + last_load_path ).toString(); + + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save BehaviorTree to svg"), directory_path, + tr("SVG files (*.svg)")); + currentTabInfo()->saveSvgFile(fileName); + + directory_path = QFileInfo(fileName).absolutePath(); + settings.setValue("SidepanelEditor.lastSaveSvgDirectory", directory_path); +} + void MainWindow::onSceneChanged() { const bool valid_BT = currentTabInfo()->containsValidTree(); ui->toolButtonLayout->setEnabled(valid_BT); ui->toolButtonReorder->setEnabled(valid_BT); - ui->toolButtonReorder->setEnabled(valid_BT); + ui->toolButtonSaveSvg->setEnabled(valid_BT); ui->actionSave->setEnabled(valid_BT); QPixmap pix; @@ -1146,6 +1163,11 @@ void MainWindow::on_toolButtonReorder_pressed() onAutoArrange(); } +void MainWindow::on_toolButtonSaveSvg_pressed() +{ + onSaveSvg(); +} + void MainWindow::on_toolButtonCenterView_pressed() { currentTabInfo()->zoomHomeView(); @@ -1292,6 +1314,7 @@ void MainWindow::updateCurrentMode() ui->toolButtonSaveFile->setHidden( NOT_EDITOR ); ui->toolButtonReorder->setHidden( NOT_EDITOR ); + ui->toolButtonSaveSvg->setHidden( NOT_EDITOR ); if( _current_mode == GraphicMode::EDITOR ) { diff --git a/bt_editor/mainwindow.h b/bt_editor/mainwindow.h index 3bdb2aeb..556deda7 100644 --- a/bt_editor/mainwindow.h +++ b/bt_editor/mainwindow.h @@ -66,6 +66,8 @@ public slots: void onAutoArrange(); + void onSaveSvg(); + void onSceneChanged(); void onPushUndo(); @@ -97,6 +99,8 @@ public slots: void on_toolButtonReorder_pressed(); + void on_toolButtonSaveSvg_pressed(); + void on_toolButtonCenterView_pressed(); void onCreateAbsBehaviorTree(const AbsBehaviorTree &tree, @@ -202,7 +206,7 @@ private slots: #ifdef ZMQ_FOUND SidepanelMonitor* _monitor_widget; #endif - + MainWindow::SavedState saveCurrentState(); void clearUndoStacks(); }; diff --git a/bt_editor/mainwindow.ui b/bt_editor/mainwindow.ui index 80594ee2..8410449b 100644 --- a/bt_editor/mainwindow.ui +++ b/bt_editor/mainwindow.ui @@ -511,8 +511,7 @@ QToolButton:disabled{ true - - + false @@ -577,6 +576,71 @@ QToolButton:disabled{ + + + + false + + + + 80 + 70 + + + + + 80 + 70 + + + + + 9 + + + + Qt::NoFocus + + + QToolButton { + color:white; +} + +QToolButton:hover{ + background-color: rgb(110, 110, 110); +} + +QToolButton:pressed{ + background-color: rgb(50, 150, 0) +} + +QToolButton:disabled{ + color:gray; + background-color: rgb(50, 50, 50) +} + + + + Save svg + + + + :/icons/svg/save_white.svg:/icons/svg/save_white.svg + + + + 32 + 32 + + + + Qt::ToolButtonTextUnderIcon + + + true + + +