From 356134f0b9a1458f33c48d8249f60e56ca71e130 Mon Sep 17 00:00:00 2001 From: Skarn Date: Sun, 11 Oct 2020 15:55:35 +0300 Subject: [PATCH] fix window loosing focus on switching editing modes, add widget for holes mode --- CMakeLists.txt | 2 +- src/noggit/MapView.cpp | 11 ++++++++ src/noggit/MapView.h | 3 +++ src/noggit/ui/hole_tool.cpp | 52 +++++++++++++++++++++++++++++++++++++ src/noggit/ui/hole_tool.hpp | 38 +++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/noggit/ui/hole_tool.cpp create mode 100644 src/noggit/ui/hole_tool.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index edd52f59..272aa7c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,7 +232,7 @@ IF(WIN32) set ( os_headers include/win/StackWalker.h - ) + src/noggit/ui/hole_tool.cpp src/noggit/ui/hole_tool.hpp) ENDIF(WIN32) COLLECT_FILES(true headers_to_moc src/noggit ".h;.hpp") diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index 7f869af6..ea307cde 100644 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,8 @@ void MapView::set_editing_mode (editing_mode mode) terrainMode = mode; _toolbar->check_tool (mode); + + this->activateWindow(); } void MapView::setToolPropertyWidgetVisibility(editing_mode mode) @@ -120,6 +123,9 @@ void MapView::setToolPropertyWidgetVisibility(editing_mode mode) case editing_mode::object: _object_editor_dock->setVisible(!ui_hidden); break; + case editing_mode::holes: + _hole_tool_dock->setVisible(!ui_hidden); + break; } @@ -218,6 +224,11 @@ void MapView::createGUI() _texturing_dock->setWidget(texturingTool); _tool_properties_docks.insert(_texturing_dock); + _hole_tool_dock = new QDockWidget("Holes", this); + holeTool = new noggit::ui::hole_tool(_hole_tool_dock); + _hole_tool_dock->setWidget(holeTool); + _tool_properties_docks.insert(_hole_tool_dock); + _areaid_editor_dock = new QDockWidget("Area ID", this); ZoneIDBrowser = new noggit::ui::zone_id_browser(_areaid_editor_dock); _areaid_editor_dock->setWidget(ZoneIDBrowser); diff --git a/src/noggit/MapView.h b/src/noggit/MapView.h index 4577deb7..735fafdd 100644 --- a/src/noggit/MapView.h +++ b/src/noggit/MapView.h @@ -48,6 +48,7 @@ namespace noggit class water; class zone_id_browser; class texture_palette_small; + class hole_tool; struct main_window; struct tileset_chooser; } @@ -306,4 +307,6 @@ private: QDockWidget* _vertex_shading_dock; noggit::ui::texturing_tool* texturingTool; QDockWidget* _texturing_dock; + noggit::ui::hole_tool* holeTool; + QDockWidget* _hole_tool_dock; }; diff --git a/src/noggit/ui/hole_tool.cpp b/src/noggit/ui/hole_tool.cpp new file mode 100644 index 00000000..29a83d99 --- /dev/null +++ b/src/noggit/ui/hole_tool.cpp @@ -0,0 +1,52 @@ +// This file is part of Noggit3, licensed under GNU General Public License (version 3). +#include "hole_tool.hpp" + +#include +#include + +namespace noggit +{ + namespace ui + { + hole_tool::hole_tool(QWidget* parent) : QWidget(parent) + { + auto layout = new QFormLayout(this); + + _radius_spin = new QDoubleSpinBox (this); + _radius_spin->setRange (0.0f, 250.0f); + _radius_spin->setDecimals (2); + _radius_spin->setValue (_radius); + + layout->addRow ("Radius:", _radius_spin); + + _radius_slider = new QSlider (Qt::Orientation::Horizontal, this); + _radius_slider->setRange (0, 100); + _radius_slider->setSliderPosition (_radius); + + layout->addRow (_radius_slider); + + connect ( _radius_spin, qOverload (&QDoubleSpinBox::valueChanged) + , [&] (double v) + { + _radius = v; + QSignalBlocker const blocker(_radius_slider); + _radius_slider->setSliderPosition ((int)std::round (v)); + } + ); + + connect ( _radius_slider, &QSlider::valueChanged + , [&] (int v) + { + _radius = v; + QSignalBlocker const blocker(_radius_spin); + _radius_spin->setValue(v); + } + ); + } + + void hole_tool::changeRadius(float change) + { + _radius_spin->setValue (_radius + change); + } + } +} diff --git a/src/noggit/ui/hole_tool.hpp b/src/noggit/ui/hole_tool.hpp new file mode 100644 index 00000000..78ac7657 --- /dev/null +++ b/src/noggit/ui/hole_tool.hpp @@ -0,0 +1,38 @@ +// This file is part of Noggit3, licensed under GNU General Public License (version 3). + +#pragma once + +#include +#include +#include +#include + +#include +#include + +namespace noggit +{ + namespace ui + { + class hole_tool : public QWidget + { + Q_OBJECT + + public: + hole_tool(QWidget* parent = nullptr); + + void changeRadius(float change); + + float brushRadius() const { return _radius; } + + private: + + QSlider* _radius_slider; + QDoubleSpinBox* _radius_spin; + + float _radius = 15.0f; + + }; + } +} +