Changed: #1301 Added status info and each zone tile has small text in graphics view.
--HG-- branch : gsoc2011-worldeditorqt
This commit is contained in:
parent
018fcac076
commit
a5749c75f5
5 changed files with 75 additions and 11 deletions
|
@ -36,6 +36,7 @@
|
|||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QStatusBar>
|
||||
|
||||
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()
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
// Qt includes
|
||||
#include <QtGui/QUndoStack>
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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,9 +349,9 @@ 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
|
||||
//if (item->data(ZONE_NAME) == QString(LAYER_BLACKOUT_NAME))
|
||||
// return false;
|
||||
//else
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue