mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-26 02:20:54 +00:00
Changed: #1301 Added status info and each zone tile has small text in graphics view.
This commit is contained in:
parent
beb9d7867e
commit
c7203a635c
5 changed files with 75 additions and 11 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
#include <QtGui/QStatusBar>
|
||||||
|
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
@ -88,6 +89,12 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
|
||||||
connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu()));
|
connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu()));
|
||||||
m_ui.landscapesListWidget->setContextMenuPolicy(Qt::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()
|
LandscapeEditorWindow::~LandscapeEditorWindow()
|
||||||
|
@ -318,6 +325,20 @@ void LandscapeEditorWindow::showEvent(QShowEvent *showEvent)
|
||||||
QMainWindow::showEvent(showEvent);
|
QMainWindow::showEvent(showEvent);
|
||||||
if (m_oglWidget != 0)
|
if (m_oglWidget != 0)
|
||||||
m_oglWidget->makeCurrent();
|
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()
|
void LandscapeEditorWindow::createMenus()
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtGui/QUndoStack>
|
#include <QtGui/QUndoStack>
|
||||||
#include <QtOpenGL/QGLWidget>
|
#include <QtOpenGL/QGLWidget>
|
||||||
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
namespace LandscapeEditor
|
namespace LandscapeEditor
|
||||||
{
|
{
|
||||||
|
@ -50,6 +52,7 @@ private Q_SLOTS:
|
||||||
void openProjectSettings();
|
void openProjectSettings();
|
||||||
void openSnapshotDialog();
|
void openSnapshotDialog();
|
||||||
void customContextMenu();
|
void customContextMenu();
|
||||||
|
void updateStatusBar();
|
||||||
void newLand();
|
void newLand();
|
||||||
void setActiveLand();
|
void setActiveLand();
|
||||||
void saveSelectedLand();
|
void saveSelectedLand();
|
||||||
|
@ -58,6 +61,7 @@ private Q_SLOTS:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void showEvent(QShowEvent *showEvent);
|
virtual void showEvent(QShowEvent *showEvent);
|
||||||
|
virtual void hideEvent(QHideEvent *hideEvent);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createMenus();
|
void createMenus();
|
||||||
|
@ -69,6 +73,9 @@ private:
|
||||||
void saveLandscape(int row, bool force);
|
void saveLandscape(int row, bool force);
|
||||||
int createLandscape(const QString &fileName);
|
int createLandscape(const QString &fileName);
|
||||||
|
|
||||||
|
QLabel *m_statusInfo;
|
||||||
|
QTimer *m_statusBarTimer;
|
||||||
|
|
||||||
QListWidgetItem *m_currentItem;
|
QListWidgetItem *m_currentItem;
|
||||||
LandscapeScene *m_landscapeScene;
|
LandscapeScene *m_landscapeScene;
|
||||||
ZoneBuilder *m_zoneBuilder;
|
ZoneBuilder *m_zoneBuilder;
|
||||||
|
|
|
@ -39,8 +39,6 @@ const char * const LAYER_BLACKOUT_NAME = "blackout";
|
||||||
|
|
||||||
LandscapeScene::LandscapeScene(QObject *parent)
|
LandscapeScene::LandscapeScene(QObject *parent)
|
||||||
: QGraphicsScene(parent),
|
: QGraphicsScene(parent),
|
||||||
m_mouseX(0.0),
|
|
||||||
m_mouseY(0.0),
|
|
||||||
m_mouseButton(Qt::NoButton),
|
m_mouseButton(Qt::NoButton),
|
||||||
m_zoneBuilder(0)
|
m_zoneBuilder(0)
|
||||||
{
|
{
|
||||||
|
@ -170,6 +168,9 @@ QGraphicsItem *LandscapeScene::createItemEmptyZone(const ZonePosition &zonePos)
|
||||||
if (m_zoneBuilder == 0)
|
if (m_zoneBuilder == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (checkUnderZone(zonePos.x, zonePos.y))
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Get image from pixmap database
|
// Get image from pixmap database
|
||||||
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
|
QPixmap *pixmap = m_zoneBuilder->pixmapDatabase()->pixmap(QString(STRING_UNUSED));
|
||||||
if (pixmap == 0)
|
if (pixmap == 0)
|
||||||
|
@ -276,11 +277,17 @@ void LandscapeScene::snapshot(const QString &fileName, int width, int height, co
|
||||||
scaledImage.save(fileName);
|
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)
|
void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
if (m_zoneBuilder == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qreal x = mouseEvent->scenePos().rx();
|
qreal x = mouseEvent->scenePos().rx();
|
||||||
qreal y = mouseEvent->scenePos().ry();
|
qreal y = mouseEvent->scenePos().ry();
|
||||||
if ((x < 0) || (y < 0))
|
if ((x < 0) || (y < 0))
|
||||||
|
@ -289,6 +296,9 @@ void LandscapeScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
m_posX = sint32(floor(x / m_cellSize));
|
m_posX = sint32(floor(x / m_cellSize));
|
||||||
m_posY = sint32(-floor(y / m_cellSize));
|
m_posY = sint32(-floor(y / m_cellSize));
|
||||||
|
|
||||||
|
if (m_zoneBuilder == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (mouseEvent->button() == Qt::LeftButton)
|
if (mouseEvent->button() == Qt::LeftButton)
|
||||||
m_zoneBuilder->addZone(m_posX, m_posY);
|
m_zoneBuilder->addZone(m_posX, m_posY);
|
||||||
else if (mouseEvent->button() == Qt::RightButton)
|
else if (mouseEvent->button() == Qt::RightButton)
|
||||||
|
@ -321,8 +331,11 @@ void LandscapeScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mouseX = mouseEvent->scenePos().x();
|
m_posX = posX;
|
||||||
m_mouseY = mouseEvent->scenePos().y();
|
m_posY = posY;
|
||||||
|
|
||||||
|
m_mouseX = mouseEvent->scenePos().rx();
|
||||||
|
m_mouseY = mouseEvent->scenePos().ry();
|
||||||
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
QGraphicsScene::mouseMoveEvent(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,9 +349,9 @@ bool LandscapeScene::checkUnderZone(const int posX, const int posY)
|
||||||
QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize);
|
QGraphicsItem *item = itemAt((posX * m_cellSize), abs(posY) * m_cellSize);
|
||||||
if (item != 0)
|
if (item != 0)
|
||||||
{
|
{
|
||||||
if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME))
|
//if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME))
|
||||||
return false;
|
// return false;
|
||||||
else
|
//else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
|
|
||||||
void snapshot(const QString &fileName, int width, int height, const QRectF &landRect);
|
void snapshot(const QString &fileName, int width, int height, const QRectF &landRect);
|
||||||
|
|
||||||
|
QString zoneNameFromMousePos() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
|
||||||
|
|
|
@ -137,6 +137,27 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||||
painter->drawLine(int(rect.left()), int(top), int(rect.right()), int(top));
|
painter->drawLine(int(rect.left()), int(top), int(rect.right()), int(top));
|
||||||
top += m_cellSize;
|
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 */
|
} /* namespace LandscapeEditor */
|
||||||
|
|
Loading…
Reference in a new issue