From baf30ba29295a8535f3af18961060e72d8ec9a09 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 3 Apr 2014 14:44:48 +0200 Subject: [PATCH] added grid tool (does not work yet) --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/scenesubview.cpp | 13 ++++ apps/opencs/view/world/scenetoolgrid.cpp | 75 ++++++++++++++++++++++++ apps/opencs/view/world/scenetoolgrid.hpp | 29 +++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/view/world/scenetoolgrid.cpp create mode 100644 apps/opencs/view/world/scenetoolgrid.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index a7a694463e..05cc93f896 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -60,7 +60,7 @@ opencs_hdrs_noqt (view/doc opencs_units (view/world table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool - scenetoolmode infocreator scriptedit dialoguesubview previewsubview + scenetoolmode infocreator scriptedit dialoguesubview previewsubview scenetoolgrid ) opencs_units (view/render diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index c075cb4d63..dedaf014b6 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -18,6 +18,7 @@ #include "creator.hpp" #include "scenetoolbar.hpp" #include "scenetoolmode.hpp" +#include "scenetoolgrid.hpp" CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) : SubView (id) @@ -36,6 +37,8 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D SceneToolbar *toolbar = new SceneToolbar (48, this); + SceneToolGrid *gridTool = 0; + if (id.getId()=="sys::default") { CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this); @@ -44,6 +47,13 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D SIGNAL (cellIndexChanged (const std::pair&, const std::pair&)), this, SLOT (cellIndexChanged (const std::pair&, const std::pair&))); + + gridTool = new SceneToolGrid (toolbar); + + connect (widget, + SIGNAL (cellIndexChanged (const std::pair&, const std::pair&)), + gridTool, + SLOT (cellIndexChanged (const std::pair&, const std::pair&))); } else mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); @@ -54,6 +64,9 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D SceneToolMode *lightingTool = mScene->makeLightingSelector (toolbar); toolbar->addTool (lightingTool); + if (gridTool) + toolbar->addTool (gridTool); + layout2->addWidget (toolbar, 0); layout2->addWidget (mScene, 1); diff --git a/apps/opencs/view/world/scenetoolgrid.cpp b/apps/opencs/view/world/scenetoolgrid.cpp new file mode 100644 index 0000000000..0769be168c --- /dev/null +++ b/apps/opencs/view/world/scenetoolgrid.cpp @@ -0,0 +1,75 @@ + +#include "scenetoolgrid.hpp" + +#include + +#include +#include +#include + +#include "scenetoolbar.hpp" + +CSVWorld::SceneToolGrid::SceneToolGrid (SceneToolbar *parent) +: SceneTool (parent), mIconSize (parent->getIconSize()) +{ +} + +void CSVWorld::SceneToolGrid::showPanel (const QPoint& position) +{ + + +} + +void CSVWorld::SceneToolGrid::cellIndexChanged (const std::pair& min, + const std::pair& max) +{ + /// \todo make font size configurable + const int fontSize = 8; + + /// \todo replace with proper icon + QPixmap image (mIconSize, mIconSize); + image.fill (QColor (0, 0, 0, 0)); + + { + QPainter painter (&image); + painter.setPen (Qt::black); + QFont font (QApplication::font().family(), fontSize); + painter.setFont (font); + + QFontMetrics metrics (font); + + if (min==max) + { + // single cell + std::ostringstream stream; + stream << min.first << ", " << min.second; + + QString text = QString::fromUtf8 (stream.str().c_str()); + + painter.drawText (QPoint ((mIconSize-metrics.width (text))/2, mIconSize/2+fontSize/2), + text); + } + else + { + // range + { + std::ostringstream stream; + stream << min.first << ", " << min.second; + painter.drawText (QPoint (0, mIconSize), + QString::fromUtf8 (stream.str().c_str())); + } + + { + std::ostringstream stream; + stream << max.first << ", " << max.second; + + QString text = QString::fromUtf8 (stream.str().c_str()); + + painter.drawText (QPoint (mIconSize-metrics.width (text), fontSize), text); + } + } + } + + QIcon icon (image); + setIcon (icon); +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenetoolgrid.hpp b/apps/opencs/view/world/scenetoolgrid.hpp new file mode 100644 index 0000000000..917df2a168 --- /dev/null +++ b/apps/opencs/view/world/scenetoolgrid.hpp @@ -0,0 +1,29 @@ +#ifndef CSV_WORLD_SCENETOOL_GRID_H +#define CSV_WORLD_SCENETOOL_GRID_H + +#include "scenetool.hpp" + +namespace CSVWorld +{ + class SceneToolbar; + + ///< \brief Cell grid selector tool + class SceneToolGrid : public SceneTool + { + Q_OBJECT + + int mIconSize; + + public: + + SceneToolGrid (SceneToolbar *parent); + + virtual void showPanel (const QPoint& position); + + public slots: + + void cellIndexChanged (const std::pair& min, const std::pair& max); + }; +} + +#endif