From 16791d58c11ce6251d84fb638cb00037022852a0 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 3 Aug 2014 19:04:34 +0200 Subject: [PATCH] Rotation can now be set. --- .../tile_editor/tile_editor_main_window.cpp | 24 +++++++++++++++++++ .../tile_editor/tile_editor_main_window.h | 3 +++ .../tile_editor/tile_editor_main_window.ui | 12 ++++++++++ .../src/plugins/tile_editor/tile_item.cpp | 9 ++++++- .../src/plugins/tile_editor/tile_item.h | 2 ++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp index 7c9ec8f52..aee2002ce 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -58,6 +58,23 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) rotateActions.push_back(m_ui->actionRotateTile270); m_rotationMenu->addActions(rotateActions); m_ui->toolBar->addAction(m_rotationMenu->menuAction()); + m_rotateSM = new QSignalMapper(); + m_rotateAG = new QActionGroup(this); + m_rotateAG->addAction(m_ui->actionRotateTile0); + m_rotateAG->addAction(m_ui->actionRotateTile90); + m_rotateAG->addAction(m_ui->actionRotateTile180); + m_rotateAG->addAction(m_ui->actionRotateTile270); + m_ui->actionRotateTile0->setChecked( true ); + + connect( m_ui->actionRotateTile0, SIGNAL( triggered() ), m_rotateSM, SLOT( map() ) ); + connect( m_ui->actionRotateTile90, SIGNAL( triggered() ), m_rotateSM, SLOT( map() ) ); + connect( m_ui->actionRotateTile180, SIGNAL( triggered() ), m_rotateSM, SLOT( map() ) ); + connect( m_ui->actionRotateTile270, SIGNAL( triggered() ), m_rotateSM, SLOT( map() ) ); + m_rotateSM->setMapping( m_ui->actionRotateTile0, 0 ); + m_rotateSM->setMapping( m_ui->actionRotateTile90, 1 ); + m_rotateSM->setMapping( m_ui->actionRotateTile180, 2 ); + m_rotateSM->setMapping( m_ui->actionRotateTile270, 3 ); + connect( m_rotateSM, SIGNAL( mapped( int ) ), this, SLOT( onRotate( int ) ) ); // Create the tile zoom menu. m_zoomMenu = new QMenu(tr("Zoom"), m_ui->toolBar); @@ -186,6 +203,8 @@ TileEditorMainWindow::~TileEditorMainWindow() delete m_ui; delete m_undoStack; delete m_rotationMenu; + delete m_rotateSM; + delete m_rotateAG; delete m_tileDisplayMenu; delete m_tileEditorMenu; @@ -315,6 +334,11 @@ void TileEditorMainWindow::onZoomFactor(int level) m_ui->listViewTransition->repaint(); } +void TileEditorMainWindow::onRotate( int id ) +{ + TileItemNode::setAlphaRot( id * 90 ); +} + void TileEditorMainWindow::onActionAddTile(bool triggered) { onActionAddTile(m_ui->tileViewTabWidget->currentIndex()); diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h index d98ec9651..44b2c9869 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h @@ -81,6 +81,7 @@ private Q_SLOTS: void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex); void onZoomFactor(int level); + void onRotate(int id); private: void onActionAddTile(int tabId); @@ -107,6 +108,8 @@ private: QMenu *m_zoomMenu; QActionGroup *m_zoomActionGroup; QSignalMapper *m_zoomSignalMapper; + QActionGroup *m_rotateAG; + QSignalMapper *m_rotateSM; TileItemDelegate *m_tileItemDelegate; diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui index f45951aba..8974570a1 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui @@ -581,6 +581,9 @@ + + true + :/tileRotation/images/rotation0.png:/tileRotation/images/rotation0.png @@ -617,6 +620,9 @@ + + true + :/tileRotation/images/rotation90.png:/tileRotation/images/rotation90.png @@ -629,6 +635,9 @@ + + true + :/tileRotation/images/rotation180.png:/tileRotation/images/rotation180.png @@ -641,6 +650,9 @@ + + true + :/tileRotation/images/rotation270.png:/tileRotation/images/rotation270.png diff --git a/code/studio/src/plugins/tile_editor/tile_item.cpp b/code/studio/src/plugins/tile_editor/tile_item.cpp index fe1df0ebf..1daa3c297 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.cpp +++ b/code/studio/src/plugins/tile_editor/tile_item.cpp @@ -290,6 +290,7 @@ public: m_borderFirst[ i ] = false; m_id = -1; + m_alphaRot = 0; } bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels ) @@ -511,6 +512,9 @@ public: const NL3D::CTileBorder &border( TileModel::TTileChannel channel ){ return m_border[ channel ]; } + int alphaRot() const{ return m_alphaRot; } + void setAlphaRot( int rot ){ m_alphaRot = rot; } + private: QPixmap pixmaps[ TileModel::TileChannelCount ]; TileModel::TNodeTileType m_type; @@ -518,9 +522,11 @@ private: int m_id; QString m_lastError; bool m_borderFirst[ TileModel::TileChannelCount ]; + int m_alphaRot; }; TileModel::TTileChannel TileItemNode::s_displayChannel = TileModel::TileDiffuse; +int TileItemNode::s_alphaRot = 0; TileItemNode::TileItemNode( TileModel::TNodeTileType type, int tileId, TileModel::TTileChannel channel, QString filename, Node *parent) { @@ -555,6 +561,7 @@ bool TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString file empty = true; } + pvt->setAlphaRot( s_alphaRot ); bool b = pvt->loadImage( channel, fn, empty ); m_hasError = !b; if( !b ) @@ -601,7 +608,7 @@ const NL3D::CTileBorder& TileItemNode::border( TileModel::TTileChannel channel ) int TileItemNode::alphaRot() const { - return 0; + return pvt->alphaRot(); } QVariant TileItemNode::data(int column, int role) const diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index 2e374061d..14bc66fe4 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -129,6 +129,7 @@ public: static void setDisplayChannel( TileModel::TTileChannel channel ){ s_displayChannel = channel; } static TileModel::TTileChannel displayChannel(){ return s_displayChannel; } + static void setAlphaRot( int rot ){ s_alphaRot = rot; } bool hasError() const{ return m_hasError; } @@ -137,6 +138,7 @@ private: QMap m_tileWidget; static TileModel::TTileChannel s_displayChannel; + static int s_alphaRot; TileItemNodePvt *pvt;