From c7203a635c38d89a398acf62bec0d7e71e133447 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 13 Jul 2011 03:34:45 +0300 Subject: [PATCH] Changed: #1301 Added status info and each zone tile has small text in graphics view. --- .../landscape_editor_window.cpp | 21 +++++++++++ .../landscape_editor_window.h | 7 ++++ .../landscape_editor/landscape_scene.cpp | 35 +++++++++++++------ .../landscape_editor/landscape_scene.h | 2 ++ .../landscape_editor/landscape_view.cpp | 21 +++++++++++ 5 files changed, 75 insertions(+), 11 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp index 3483766f9..662c1d9c9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.cpp @@ -36,6 +36,7 @@ #include #include #include +#include namespace LandscapeEditor { @@ -88,6 +89,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent) connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu())); m_ui.landscapesListWidget->setContextMenuPolicy(Qt::CustomContextMenu); + m_statusBarTimer = new QTimer(this); + connect(m_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar())); + + m_statusInfo = new QLabel(this); + m_statusInfo->hide(); + Core::ICore::instance()->mainWindow()->statusBar()->addPermanentWidget(m_statusInfo); } LandscapeEditorWindow::~LandscapeEditorWindow() @@ -318,6 +325,20 @@ void LandscapeEditorWindow::showEvent(QShowEvent *showEvent) QMainWindow::showEvent(showEvent); if (m_oglWidget != 0) m_oglWidget->makeCurrent(); + m_statusInfo->show(); + m_statusBarTimer->start(100); +} + +void LandscapeEditorWindow::hideEvent(QHideEvent *hideEvent) +{ + QMainWindow::hideEvent(hideEvent); + m_statusInfo->hide(); + m_statusBarTimer->stop(); +} + +void LandscapeEditorWindow::updateStatusBar() +{ + m_statusInfo->setText(m_landscapeScene->zoneNameFromMousePos()); } void LandscapeEditorWindow::createMenus() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h index 18ce670b7..67768e39a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_editor_window.h @@ -24,6 +24,8 @@ // Qt includes #include #include +#include +#include namespace LandscapeEditor { @@ -50,6 +52,7 @@ private Q_SLOTS: void openProjectSettings(); void openSnapshotDialog(); void customContextMenu(); + void updateStatusBar(); void newLand(); void setActiveLand(); void saveSelectedLand(); @@ -58,6 +61,7 @@ private Q_SLOTS: protected: virtual void showEvent(QShowEvent *showEvent); + virtual void hideEvent(QHideEvent *hideEvent); private: void createMenus(); @@ -69,6 +73,9 @@ private: void saveLandscape(int row, bool force); int createLandscape(const QString &fileName); + QLabel *m_statusInfo; + QTimer *m_statusBarTimer; + QListWidgetItem *m_currentItem; LandscapeScene *m_landscapeScene; ZoneBuilder *m_zoneBuilder; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp index 3b10d4fed..b2dc9dd5d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.cpp @@ -39,8 +39,6 @@ const char * const LAYER_BLACKOUT_NAME = "blackout"; LandscapeScene::LandscapeScene(QObject *parent) : QGraphicsScene(parent), - m_mouseX(0.0), - m_mouseY(0.0), m_mouseButton(Qt::NoButton), m_zoneBuilder(0) { @@ -170,6 +168,9 @@ QGraphicsItem *LandscapeScene::createItemEmptyZone(const ZonePosition &zonePos) if (m_zoneBuilder == 0) return 0; + if (checkUnderZone(zonePos.x, zonePos.y)) + return 0; + // Get image from pixmap database QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED)); if (pixmap == 0) @@ -276,11 +277,17 @@ void LandscapeScene::snapshot(const QString &fileName, int width, int height, co scaledImage.save(fileName); } +QString LandscapeScene::zoneNameFromMousePos() const +{ + if ((m_posY > 0) || (m_posY < -255) || + (m_posX < 0) || (m_posX > 255)) + return "NOT A VALID ZONE"; + + return QString("%1_%2%3").arg(-m_posY).arg(QChar('A' + (m_posX/26))).arg(QChar('A' + (m_posX%26))); +} + void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { - if (m_zoneBuilder == 0) - return; - qreal x = mouseEvent->scenePos().rx(); qreal y = mouseEvent->scenePos().ry(); if ((x < 0) || (y < 0)) @@ -289,6 +296,9 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) m_posX = sint32(floor(x / m_cellSize)); m_posY = sint32(-floor(y / m_cellSize)); + if (m_zoneBuilder == 0) + return; + if (mouseEvent->button() == Qt::LeftButton) m_zoneBuilder->addZone(m_posX, m_posY); else if (mouseEvent->button() == Qt::RightButton) @@ -321,8 +331,11 @@ void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) QApplication::processEvents(); } - m_mouseX = mouseEvent->scenePos().x(); - m_mouseY = mouseEvent->scenePos().y(); + m_posX = posX; + m_posY = posY; + + m_mouseX = mouseEvent->scenePos().rx(); + m_mouseY = mouseEvent->scenePos().ry(); QGraphicsScene::mouseMoveEvent(mouseEvent); } @@ -336,10 +349,10 @@ bool LandscapeScene::checkUnderZone(const int posX, const int posY) QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize); if (item != 0) { - if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME)) - return false; - else - return true; + //if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME)) + // return false; + //else + return true; } return false; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h index 39f81bf98..71d4c512e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_scene.h @@ -59,6 +59,8 @@ public: void snapshot(const QString &fileName, int width, int height, const QRectF &landRect); + QString zoneNameFromMousePos() const; + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp index 84bc4b47d..40074292d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/landscape_editor/landscape_view.cpp @@ -137,6 +137,27 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect) painter->drawLine(int(rect.left()), int(top), int(rect.right()), int(top)); top += m_cellSize; } + + // Render text (slow!) + if (m_numSteps > -m_maxSteps / 4) + { + painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine)); + + //painter->setFont(QFont("Helvetica [Cronyx]", 12)); + int leftSide = int(floor(rect.left() / m_cellSize)); + int rightSide = int(floor(rect.right() / m_cellSize)); + int topSide = int(floor(rect.top() / m_cellSize)); + int bottomSide = int(floor(rect.bottom() / m_cellSize)); + + for (int i = leftSide; i < rightSide + 1; ++i) + { + for (int j = topSide; j < bottomSide + 1; ++j) + { + QString text = QString("%1_%2%3").arg(j).arg(QChar('A' + (i / 26))).arg(QChar('A' + (i % 26))); + painter->drawText(i * m_cellSize + 5, j * m_cellSize + 15, text); + } + } + } } } /* namespace LandscapeEditor */