diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-11-18 14:56:32 +0100 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-11-18 14:56:32 +0100 |
commit | 42120e2ea5db0cdb9920ff1c5efef33e0f496d48 (patch) | |
tree | 20ba1ae0a53f757cb8814b6cd6a466fe5acf1308 /Tools/QtBiomeVisualiser/MainWindow.cpp | |
parent | Fixed compile errors. (diff) | |
parent | Merge pull request #1598 from mc-server/SignEditor (diff) | |
download | cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.gz cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.bz2 cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.lz cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.xz cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.zst cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.zip |
Diffstat (limited to 'Tools/QtBiomeVisualiser/MainWindow.cpp')
-rw-r--r-- | Tools/QtBiomeVisualiser/MainWindow.cpp | 138 |
1 files changed, 134 insertions, 4 deletions
diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index eb45690c1..c6ea8656e 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -7,12 +7,23 @@ #include <QFileDialog> #include <QSettings> #include <QDirIterator> -#include "inifile/iniFile.h" +#include <QStatusBar> #include "ChunkSource.h" +#include "src/IniFile.h" #include "src/Generating/BioGen.h" #include "src/StringCompression.h" #include "src/WorldStorage/FastNBT.h" #include "GeneratorSetup.h" +#include "RegionLoader.h" + + + + + +const double MainWindow::m_ViewZooms[] = +{ + 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 24, +}; @@ -21,11 +32,27 @@ MainWindow::MainWindow(QWidget * parent) : QMainWindow(parent), m_GeneratorSetup(nullptr), - m_LineSeparator(nullptr) + m_LineSeparator(nullptr), + m_CurrentZoomLevel(2) { initMinecraftPath(); m_BiomeView = new BiomeView(); + connect(m_BiomeView, SIGNAL(increaseZoom()), this, SLOT(increaseZoom())); + connect(m_BiomeView, SIGNAL(decreaseZoom()), this, SLOT(decreaseZoom())); + connect(m_BiomeView, SIGNAL(wheelUp()), this, SLOT(increaseZoom())); + connect(m_BiomeView, SIGNAL(wheelDown()), this, SLOT(decreaseZoom())); + m_BiomeView->setZoomLevel(m_ViewZooms[m_CurrentZoomLevel]); + + m_StatusBar = new QStatusBar(); + this->setStatusBar(m_StatusBar); + m_StatusBlockX = new QLabel(tr("X")); + m_StatusBlockZ = new QLabel(tr("Z")); + m_StatusBiome = new QLabel(tr("B")); + m_StatusBar->addPermanentWidget(m_StatusBlockX); + m_StatusBar->addPermanentWidget(m_StatusBlockZ); + m_StatusBar->addPermanentWidget(m_StatusBiome); + m_MainLayout = new QHBoxLayout(); m_MainLayout->addWidget(m_BiomeView, 1); m_MainLayout->setMenuBar(menuBar()); @@ -36,6 +63,8 @@ MainWindow::MainWindow(QWidget * parent) : createActions(); createMenus(); + + connect(m_BiomeView, SIGNAL(hoverChanged(int, int, int)), this, SLOT(hoverChanged(int, int, int))); } @@ -44,7 +73,7 @@ MainWindow::MainWindow(QWidget * parent) : MainWindow::~MainWindow() { - + RegionLoader::shutdown(); } @@ -129,6 +158,80 @@ void MainWindow::openVanillaWorld() +void MainWindow::centerView() +{ + m_BiomeView->setPosition(0, 0); +} + + + + + +void MainWindow::setViewZoom() +{ + // The zoom level is stored in the sender action's data, retrieve it: + QAction * action = qobject_cast<QAction *>(sender()); + if (action == nullptr) + { + return; + } + m_CurrentZoomLevel = action->data().toInt(); + double newZoom = m_ViewZooms[m_CurrentZoomLevel]; + m_BiomeView->setZoomLevel(newZoom); + action->setChecked(true); +} + + + + + +void MainWindow::increaseZoom() +{ + // If already at max zoom, bail out: + if (m_CurrentZoomLevel >= ARRAYCOUNT(m_ViewZooms) - 1) + { + return; + } + + // Increase the zoom level: + m_CurrentZoomLevel += 1; + m_actViewZoom[m_CurrentZoomLevel]->setChecked(true); + m_BiomeView->setZoomLevel(m_ViewZooms[m_CurrentZoomLevel]); +} + + + + + +void MainWindow::decreaseZoom() +{ + // If already at min zoom, bail out: + if (m_CurrentZoomLevel == 0) + { + return; + } + + // Decrease the zoom level: + m_CurrentZoomLevel -= 1; + m_actViewZoom[m_CurrentZoomLevel]->setChecked(true); + m_BiomeView->setZoomLevel(m_ViewZooms[m_CurrentZoomLevel]); +} + + + + + +void MainWindow::hoverChanged(int a_BlockX, int a_BlockZ, int a_Biome) +{ + m_StatusBlockX->setText(tr("X: %1").arg(a_BlockX)); + m_StatusBlockZ->setText(tr("Z: %1").arg(a_BlockZ)); + m_StatusBiome->setText (tr("B: %1 (%2)").arg(BiomeToString(a_Biome).c_str()).arg(a_Biome)); +} + + + + + void MainWindow::initMinecraftPath() { #ifdef Q_OS_MAC @@ -147,6 +250,7 @@ void MainWindow::initMinecraftPath() void MainWindow::createActions() { + // Map menu: createWorldActions(); m_actNewGen = new QAction(tr("&New generator"), this); @@ -173,6 +277,22 @@ void MainWindow::createActions() m_actExit->setShortcut(tr("Alt+X")); m_actExit->setStatusTip(tr("Exit %1").arg(QApplication::instance()->applicationName())); connect(m_actExit, SIGNAL(triggered()), this, SLOT(close())); + + // View menu: + m_actViewCenter = new QAction(tr("&Reset to center"), this); + m_actViewCenter->setStatusTip(tr("Scrolls the view back to the map center")); + connect(m_actViewCenter, SIGNAL(triggered()), this, SLOT(centerView())); + + QActionGroup * zoomGroup = new QActionGroup(this); + for (int i = 0; i < ARRAYCOUNT(m_ViewZooms); i++) + { + m_actViewZoom[i] = new QAction(tr("&Zoom %1%").arg(std::floor(m_ViewZooms[i] * 100)), this); + m_actViewZoom[i]->setCheckable(true); + m_actViewZoom[i]->setData(QVariant(i)); + zoomGroup->addAction(m_actViewZoom[i]); + connect(m_actViewZoom[i], SIGNAL(triggered()), this, SLOT(setViewZoom())); + } + m_actViewZoom[m_CurrentZoomLevel]->setChecked(true); } @@ -220,11 +340,12 @@ void MainWindow::createWorldActions() void MainWindow::createMenus() { + // Map menu: QMenu * file = menuBar()->addMenu(tr("&Map")); file->addAction(m_actNewGen); file->addAction(m_actOpenGen); file->addSeparator(); - QMenu * worlds = file->addMenu(tr("Open existing")); + QMenu * worlds = file->addMenu(tr("Open &existing")); worlds->addActions(m_WorldActions); if (m_WorldActions.empty()) { @@ -235,6 +356,15 @@ void MainWindow::createMenus() file->addAction(m_actReload); file->addSeparator(); file->addAction(m_actExit); + + // View menu: + QMenu * view = menuBar()->addMenu(tr("&View")); + view->addAction(m_actViewCenter); + view->addSeparator(); + for (size_t i = 0; i < ARRAYCOUNT(m_actViewZoom); i++) + { + view->addAction(m_actViewZoom[i]); + } } |