Changed: #1301 Improved appearance of landscape editor.

This commit is contained in:
dnk-88 2011-07-18 14:32:54 +03:00
parent 647f3101cf
commit 58f2f006b2
5 changed files with 110 additions and 64 deletions

View file

@ -56,7 +56,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
m_ui.setupUi(this);
m_undoStack = new QUndoStack(this);
m_landscapeScene = new LandscapeScene(this);
m_landscapeScene = new LandscapeScene(160, this);
m_zoneBuilder = new ZoneBuilder(m_landscapeScene, m_ui.zoneListWidget, m_undoStack);
m_ui.zoneListWidget->setZoneBuilder(m_zoneBuilder);
@ -69,6 +69,9 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
m_ui.saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
m_ui.saveLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
m_ui.saveAsLandAction->setIcon(QIcon(Core::Constants::ICON_SAVE_AS));
m_ui.zonesDockWidget->toggleViewAction()->setIcon(QIcon(Constants::ICON_LANDSCAPE_ZONES));
m_ui.landscapesDockWidget->toggleViewAction()->setIcon(QIcon(Constants::ICON_ZONE_ITEM));
m_ui.deleteLandAction->setEnabled(false);
createMenus();
@ -85,6 +88,7 @@ LandscapeEditorWindow::LandscapeEditorWindow(QWidget *parent)
connect(m_ui.saveLandAction, SIGNAL(triggered()), this, SLOT(saveSelectedLand()));
connect(m_ui.saveAsLandAction, SIGNAL(triggered()), this, SLOT(saveAsSelectedLand()));
connect(m_ui.deleteLandAction, SIGNAL(triggered()), this, SLOT(deleteSelectedLand()));
connect(m_ui.transitionModeAction, SIGNAL(toggled(bool)), m_landscapeScene, SLOT(setTransitionMode(bool)));
connect(m_ui.landscapesListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu()));
m_ui.landscapesListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
@ -353,23 +357,27 @@ void LandscapeEditorWindow::createToolBars()
Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager();
//QAction *action = menuManager->action(Core::Constants::NEW);
//m_ui.fileToolBar->addAction(action);
QAction *action = menuManager->action(Core::Constants::OPEN);
m_ui.fileToolBar->addAction(m_ui.newLandAction);
m_ui.fileToolBar->addAction(action);
m_ui.fileToolBar->addAction(m_ui.saveAction);
action = menuManager->action(Core::Constants::UNDO);
if (action != 0)
m_ui.undoToolBar->addAction(action);
action = menuManager->action(Core::Constants::REDO);
if (action != 0)
m_ui.undoToolBar->addAction(action);
//action = menuManager->action(Core::Constants::SAVE);
//m_ui.fileToolBar->addAction(action);
//action = menuManager->action(Core::Constants::SAVE_AS);
//m_ui.fileToolBar->addAction(action);
QAction *action = menuManager->action(Core::Constants::OPEN);
m_ui.fileToolBar->addAction(m_ui.newLandAction);
m_ui.fileToolBar->addAction(action);
m_ui.fileToolBar->addAction(m_ui.saveAction);
m_ui.fileToolBar->addSeparator();
action = menuManager->action(Core::Constants::UNDO);
if (action != 0)
m_ui.fileToolBar->addAction(action);
action = menuManager->action(Core::Constants::REDO);
if (action != 0)
m_ui.fileToolBar->addAction(action);
m_ui.zoneToolBar->insertAction(m_ui.enableGridAction, m_ui.landscapesDockWidget->toggleViewAction());
m_ui.zoneToolBar->insertAction(m_ui.enableGridAction, m_ui.zonesDockWidget->toggleViewAction());
}
void LandscapeEditorWindow::readSettings()

View file

@ -31,8 +31,8 @@
<rectf>
<x>0.000000000000000</x>
<y>0.000000000000000</y>
<width>99999.000000000000000</width>
<height>99999.000000000000000</height>
<width>0.000000000000000</width>
<height>0.000000000000000</height>
</rectf>
</property>
<property name="dragMode">
@ -65,7 +65,11 @@
<bool>false</bool>
</attribute>
</widget>
<widget class="QDockWidget" name="dockWidget">
<widget class="QDockWidget" name="zonesDockWidget">
<property name="windowIcon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_nel_zones.png</normaloff>:/icons/ic_nel_zones.png</iconset>
</property>
<property name="windowTitle">
<string>Zones</string>
</property>
@ -74,18 +78,11 @@
</attribute>
<widget class="LandscapeEditor::ListZonesWidget" name="zoneListWidget"/>
</widget>
<widget class="QToolBar" name="undoToolBar">
<property name="windowTitle">
<string>toolBar_2</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QDockWidget" name="landscapesDockWidget">
<property name="windowIcon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_nel_zone.png</normaloff>:/icons/ic_nel_zone.png</iconset>
</property>
<property name="windowTitle">
<string>Landscapes</string>
</property>
@ -116,9 +113,10 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="transitionModeAction"/>
<addaction name="enableGridAction"/>
<addaction name="projectSettingsAction"/>
<addaction name="snapshotAction"/>
<addaction name="enableGridAction"/>
</widget>
<action name="projectSettingsAction">
<property name="icon">
@ -136,6 +134,10 @@
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_grid.png</normaloff>:/icons/ic_grid.png</iconset>
</property>
<property name="text">
<string>EnableGrid</string>
</property>
@ -147,6 +149,10 @@
</property>
</action>
<action name="snapshotAction">
<property name="icon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_snapshot.png</normaloff>:/icons/ic_snapshot.png</iconset>
</property>
<property name="text">
<string>snapshot</string>
</property>
@ -200,6 +206,22 @@
<string>Create new landscape</string>
</property>
</action>
<action name="transitionModeAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_nel_landscape_item.png</normaloff>
<normalon>:/icons/ic_nel_transition_land.png</normalon>:/icons/ic_nel_landscape_item.png</iconset>
</property>
<property name="text">
<string>Transition mode</string>
</property>
<property name="toolTip">
<string>Enable transition mode</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -59,9 +59,7 @@ bool LandscapeView::isVisibleGrid() const
void LandscapeView::setVisibleGrid(bool visible)
{
m_visibleGrid = visible;
// hack for repaint view
translate(0.0001, 0.0001);
scene()->update();
}
void LandscapeView::wheelEvent(QWheelEvent *event)
@ -117,45 +115,55 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
if (!m_visibleGrid)
return;
qreal scaleFactor = transform().m11();
painter->setPen(QPen(Qt::white, 0, Qt::SolidLine));
drawGrid(painter, rect);
// draw grid
qreal left = m_cellSize * floor(rect.left() / m_cellSize);
qreal top = m_cellSize * floor(rect.top() / m_cellSize);
// draw vertical lines
while (left < rect.right())
{
painter->drawLine(int(left), int(rect.bottom()), int(left), int(rect.top()));
left += m_cellSize;
}
// draw horizontal lines
while (top < rect.bottom())
{
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));
drawZoneNames(painter, rect);
}
}
for (int i = leftSide; i < rightSide + 1; ++i)
void LandscapeView::drawGrid(QPainter *painter, const QRectF &rect)
{
qreal left = m_cellSize * floor(rect.left() / m_cellSize);
qreal top = m_cellSize * floor(rect.top() / m_cellSize);
QVector<QLine> lines;
// Calculate vertical lines
while (left < rect.right())
{
lines.push_back(QLine(int(left), int(rect.bottom()), int(left), int(rect.top())));
left += m_cellSize;
}
// Calculate horizontal lines
while (top < rect.bottom())
{
lines.push_back(QLine(int(rect.left()), int(top), int(rect.right()), int(top)));
top += m_cellSize;
}
// Draw lines
painter->drawLines(lines);
}
void LandscapeView::drawZoneNames(QPainter *painter, const QRectF &rect)
{
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)
{
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);
}
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);
}
}
}

View file

@ -49,6 +49,8 @@ protected:
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void drawForeground(QPainter *painter, const QRectF &rect);
void drawGrid(QPainter *painter, const QRectF &rect);
void drawZoneNames(QPainter *painter, const QRectF &rect);
private:
bool m_visibleGrid;

View file

@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Snapshot</string>
</property>
<property name="windowIcon">
<iconset resource="landscape_editor.qrc">
<normaloff>:/icons/ic_snapshot.png</normaloff>:/icons/ic_snapshot.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -136,7 +140,9 @@
<tabstop>keepRatioCheckBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<resources>
<include location="landscape_editor.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>