From 31892d736e582f9ad74c884375206622dfdb6088 Mon Sep 17 00:00:00 2001 From: sfb Date: Fri, 30 Dec 2011 14:36:51 -0600 Subject: [PATCH] Changed: #1409 Added TileItemDelegate for rendering the icons at the correct size, adding tile set auto selects newest tile set, converted model items to accept role in their data for special handling, fixed column count bug, moved important enums centrally to TileModel. --- .../tile_editor/tile_editor_main_window.cpp | 43 ++++-- .../tile_editor/tile_editor_main_window.h | 2 + .../tile_editor/tile_editor_main_window.ui | 72 ++++++++++ .../src/plugins/tile_editor/tile_item.cpp | 124 +++++++++++++----- .../src/plugins/tile_editor/tile_item.h | 46 +++---- .../tile_editor/tile_item_delegate.cpp | 98 ++++++++++++++ .../plugins/tile_editor/tile_item_delegate.h | 53 ++++++++ .../src/plugins/tile_editor/tile_model.cpp | 66 +++++++--- .../src/plugins/tile_editor/tile_model.h | 26 ++++ 9 files changed, 443 insertions(+), 87 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp index 427fda7a9..301f3564a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -30,6 +30,7 @@ #include "tile_model.h" #include "tile_item.h" +#include "tile_item_delegate.h" TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) : QMainWindow(parent), @@ -72,6 +73,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) QStringList headers; headers << "Tile Set"; m_model = new TileModel(headers, this); + m_tileItemDelegate = new TileItemDelegate(); // Set up the tile set list view. m_ui->tileSetLV->setModel(m_model); @@ -82,6 +84,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &))); // 128x128 List View + m_ui->listView128->setItemDelegate(m_tileItemDelegate); m_ui->listView128->setModel(m_model); m_ui->listView128->addAction(m_ui->actionAddTile); m_ui->listView128->addAction(m_ui->actionDeleteTile); @@ -89,6 +92,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) m_ui->listView128->addAction(m_ui->actionDeleteImage); // 256x256 List View + m_ui->listView256->setItemDelegate(m_tileItemDelegate); m_ui->listView256->setModel(m_model); m_ui->listView256->addAction(m_ui->actionAddTile); m_ui->listView256->addAction(m_ui->actionDeleteTile); @@ -96,14 +100,17 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) m_ui->listView256->addAction(m_ui->actionDeleteImage); // Transition List View + m_ui->listViewTransition->setItemDelegate(m_tileItemDelegate); m_ui->listViewTransition->setModel(m_model); m_ui->listViewTransition->addAction(m_ui->actionReplaceImage); m_ui->listViewTransition->addAction(m_ui->actionDeleteImage); // Displacement List View + m_ui->listViewDisplacement->setItemDelegate(m_tileItemDelegate); m_ui->listViewDisplacement->setModel(m_model); m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage); m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage); + // Connect context menu actions up. connect(m_ui->actionAddTile, SIGNAL(triggered(bool)), this, SLOT(onActionAddTile(bool))); @@ -168,11 +175,15 @@ void TileEditorMainWindow::onTileSetAdd() //} //else //{ - - + + + // Create and append the new tile set to the model. TileSetNode *tileSet = model->createTileSetNode(text); - + + // Retrieve how many rows there currently are and set the current index using that. m_ui->tileSetLV->reset(); + uint32 rows = model->rowCount(); + m_ui->tileSetLV->setCurrentIndex(model->index(rows-1, 0)); } } @@ -180,23 +191,31 @@ void TileEditorMainWindow::onActionAddTile(int tabId) { QFileDialog::Options options; QString selectedFilter; - QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Tile Texture", "." , "PNG Bitmap(*.png);;All Files (*.*);;", &selectedFilter, options); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Tile Texture", "." , "Images (*.png);;All Files (*.*)", &selectedFilter, options); } void TileEditorMainWindow::changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex) { - const QModelIndex &tile128Idx = newIndex.child(0,0); - const QModelIndex &tile256Idx = newIndex.child(1,0); - const QModelIndex &tileTransIdx = newIndex.child(2,0); - const QModelIndex &tileDispIdx = newIndex.child(3,0); + TileModel *model = static_cast(m_ui->tileSetLV->model()); + + QModelIndex tile128Idx = model->index(0, 0, newIndex); + QModelIndex tile256Idx = model->index(1, 0, newIndex); + QModelIndex tileTransIdx = model->index(2, 0, newIndex); + QModelIndex tileDispIdx = model->index(3, 0, newIndex); m_ui->listView128->setRootIndex(tile128Idx); + m_ui->listView128->setCurrentIndex(m_ui->listView128->model()->index(0, 0, m_ui->listView128->rootIndex())); m_ui->listView256->setRootIndex(tile256Idx); + m_ui->listView256->setCurrentIndex(m_ui->listView256->model()->index(0, 0, m_ui->listView256->rootIndex())); m_ui->listViewTransition->setRootIndex(tileTransIdx); + m_ui->listViewTransition->setCurrentIndex(m_ui->listViewTransition->model()->index(0, 0, m_ui->listViewTransition->rootIndex())); m_ui->listViewDisplacement->setRootIndex(tileDispIdx); + m_ui->listViewDisplacement->setCurrentIndex(m_ui->listViewDisplacement->model()->index(0, 0, m_ui->listViewDisplacement->rootIndex())); - m_ui->listView128->reset(); - m_ui->listView256->reset(); - m_ui->listViewTransition->reset(); - m_ui->listViewDisplacement->reset(); + //nlinfo("number of rows in displacement: %d", tileDispIdx.model()->rowCount(tileDispIdx)); + + //m_ui->listView128->reset(); + //m_ui->listView256->reset(); + //m_ui->listViewTransition->reset(); + //m_ui->listViewDisplacement->reset(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.h index 267eff50c..93cde3d8f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.h @@ -29,6 +29,7 @@ namespace Ui { } class TileModel; +class TileItemDelegate; class TileEditorMainWindow : public QMainWindow { @@ -59,6 +60,7 @@ private: QMenu *m_tileEditorMenu; TileModel *m_model; + TileItemDelegate *m_tileItemDelegate; }; #endif // TILE_EDITOR_MAIN_WINDOW_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.ui index 5897d29be..a7130bf9d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.ui @@ -30,6 +30,24 @@ Qt::ActionsContextMenu + + + 128 + 128 + + + + QListView::LeftToRight + + + true + + + QListView::IconMode + + + true + @@ -70,6 +88,24 @@ Qt::ActionsContextMenu + + + 256 + 256 + + + + QListView::LeftToRight + + + true + + + QListView::IconMode + + + true + @@ -113,12 +149,27 @@ Qt::ActionsContextMenu + + + 64 + 64 + + QListView::LeftToRight + + true + QListView::Batched + + QListView::IconMode + + + false + @@ -166,6 +217,27 @@ Qt::ActionsContextMenu + + + 32 + 32 + + + + QListView::LeftToRight + + + true + + + QListView::Fixed + + + QListView::IconMode + + + false + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp index 289bc4a83..04b044382 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp @@ -14,8 +14,12 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +#include + #include "tile_item.h" +//#include "tile_widget.h" + #include Node::Node() : m_parentItem(0) @@ -109,9 +113,11 @@ int Node::columnCount() const return m_itemData.count(); } -QVariant Node::data(int column) const +QVariant Node::data(int column, int role) const { - return m_itemData.value(column); + if(role == Qt::DisplayRole) + return m_itemData.value(column); + return QVariant(); } bool Node::setData(int column, const QVariant &value) @@ -157,14 +163,21 @@ TileSetNode::~TileSetNode() qDeleteAll(m_childItems); } -QVariant TileSetNode::data(int column) const +QVariant TileSetNode::data(int column, int role) const { - return QVariant(m_tileSetName); + if(role == Qt::DisplayRole) + return QVariant(m_tileSetName); + return QVariant(); +} + +int TileSetNode::columnCount() const +{ + return 1; } /////////////////////////////////////////////////// -TileTypeNode::TileTypeNode(TNodeTileType type, Node *parent) : m_nodeTileType(type) +TileTypeNode::TileTypeNode(TileModel::TNodeTileType type, Node *parent) : m_nodeTileType(type) { m_parentItem = parent; } @@ -174,42 +187,34 @@ TileTypeNode::~TileTypeNode() qDeleteAll(m_childItems); } -QVariant TileTypeNode::data(int column) const +QVariant TileTypeNode::data(int column, int role) const { - return QVariant(getTileTypeName(m_nodeTileType)); + if(role == Qt::DisplayRole) + return QVariant(TileModel::getTileTypeName(m_nodeTileType)); + return QVariant(); + } -TileTypeNode::TNodeTileType TileTypeNode::getTileType() +int TileTypeNode::columnCount() const +{ + return 1; +} + +TileModel::TNodeTileType TileTypeNode::getTileType() { return m_nodeTileType; } -const char *TileTypeNode::getTileTypeName(TNodeTileType type) -{ - switch(type) - { - case Tile128: - return "128"; - case Tile256: - return "256"; - case TileTransition: - return "Transition"; - case TileDisplacement: - return "Displacement"; - default: - break; - } - return "UNKNOWN"; -} + /////////////////////////////////////////////////// -TileItemNode::TileItemNode(int tileId, TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId) +TileItemNode::TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId) { m_tileFilename[channel] = filename; m_parentItem = parent; - nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileDiffuse].toStdString().c_str()); + nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toStdString().c_str()); } TileItemNode::~TileItemNode() @@ -217,14 +222,71 @@ TileItemNode::~TileItemNode() qDeleteAll(m_childItems); } -void TileItemNode::setTileFilename(TTileChannel channel, QString filename) +void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename) { m_tileFilename[channel] = filename; } -QVariant TileItemNode::data(int column) const +QVariant TileItemNode::data(int column, int role) const { - nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileDiffuse].toStdString().c_str()); + + + nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toStdString().c_str()); // find some way to know which file/bitmap to display - return QVariant(m_tileFilename[TileDiffuse]); + QString tileFilename = m_tileFilename[TileModel::TileDiffuse]; + //TileWidget *tile = m_tileWidget[TileModel::TileDiffuse]; + + // + // + // return QVariant(); + + //if(tile == NULL) + //{ + // + // + + // // Create a new tile widget. + // tile = new TileWidget(); + // tile->initWidget(tileFilename, tileFilename, tileSize); + //} + + if(role == TileModel::TilePixmapRole) + { + TileTypeNode *parent = dynamic_cast(m_parentItem); + if(parent == NULL) + return QVariant(); + + // Retrieve the target tile size. + uint32 tileSize = TileModel::getTileTypeSize(parent->getTileType()); + + if(tileFilename.isEmpty() || tileFilename == "empty") + tileFilename = ":/placeHolder/images/empty_image.png"; + + QPixmap pixmap;// = new QPixmap(); + if(!pixmap.load(tileFilename)) + nlinfo("failed to load %s", tileFilename.toStdString().c_str()); + + //pixmap.scaled(tileSize*100, tileSize*100); + + return pixmap; + } + else if(role == TileModel::TileFilenameRole) + { + return QVariant(tileFilename); + } + else if(role == TileModel::TileIndexRole) + { + return QVariant(tileFilename); + } + /*else if(role == Qt::TextAlignmentRole) + { + return QVariant(Qt::AlignHCenter|Qt::AlignVCenter); + }*/ + + return QVariant(); } + +int TileItemNode::columnCount() const +{ + return 1; +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h index eceb38a79..f89b20ab7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h @@ -22,6 +22,10 @@ #include #include +#include "tile_model.h" + +class TileWidget; + class Node { public: @@ -34,9 +38,9 @@ public: Node *child(int row); int childCount() const; int childNumber() const; - int columnCount() const; + virtual int columnCount() const; bool setData(int column, const QVariant &value); - virtual QVariant data(int column) const; + virtual QVariant data(int column, int role) const; bool insertChildren(int position, int count, int columns); bool removeChildren(int position, int count); @@ -60,7 +64,8 @@ class TileSetNode : public Node public: TileSetNode(QString tileSetName, Node *parent=0); virtual ~TileSetNode(); - QVariant data(int column) const; + QVariant data(int column, int role) const; + int columnCount() const; const QString &getTileSetName(); private: @@ -70,42 +75,29 @@ private: class TileTypeNode : public Node { public: - enum TNodeTileType - { - Tile128 = 0, - Tile256 = 1, - TileTransition = 2, - TileDisplacement = 3 - }; - TileTypeNode(TNodeTileType type, Node *parent=0); + TileTypeNode(TileModel::TNodeTileType type, Node *parent=0); virtual ~TileTypeNode(); - QVariant data(int column) const; + QVariant data(int column, int role) const; + int columnCount() const; - TNodeTileType getTileType(); - - static const char *getTileTypeName(TNodeTileType type); + TileModel::TNodeTileType getTileType(); private: - TNodeTileType m_nodeTileType; + TileModel::TNodeTileType m_nodeTileType; }; class TileItemNode : public Node { public: - enum TTileChannel - { - TileDiffuse = 0, - TileAdditive = 1, - TileAlpha = 2, - }; - - TileItemNode(int tileId, TTileChannel channel, QString filename, Node *parent=0); + TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent=0); virtual ~TileItemNode(); - QVariant data(int column) const; - void setTileFilename(TTileChannel channel, QString filename); + QVariant data(int column, int role) const; + int columnCount() const; + void setTileFilename(TileModel::TTileChannel channel, QString filename); private: int m_tileId; - QMap m_tileFilename; + QMap m_tileFilename; + QMap m_tileWidget; }; #endif // TILE_ITEM_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.cpp new file mode 100644 index 000000000..f689ff83e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.cpp @@ -0,0 +1,98 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include + +#include + +#include "tile_item_delegate.h" + +#include "tile_model.h" + +TileItemDelegate::TileItemDelegate() +{ + m_zoomFactor = ZoomNormal; +} + +TileItemDelegate::~TileItemDelegate() +{ +} + +void TileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyledItemDelegate::paint(painter,option,index); + + painter->save(); + + QFont font = QApplication::font(); + QFont SubFont = QApplication::font(); + //font.setPixelSize(font.weight()+); + font.setBold(true); + SubFont.setWeight(SubFont.weight()-2); + QFontMetrics fm(font); + + QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); + QString headerText = qvariant_cast(index.data(TileModel::TileFilenameRole)); + QString subText = qvariant_cast(index.data(TileModel::TileIndexRole)); + + QSize tileSize = tile.size(); + + QRect headerRect = option.rect; + QRect subheaderRect = option.rect; + QRect tileRect = subheaderRect; + + tileRect.setRight(tileSize.width()+30); + tileRect.setTop(tileRect.top()+5); + headerRect.setLeft(tileRect.right()); + subheaderRect.setLeft(tileRect.right()); + headerRect.setTop(headerRect.top()+5); + headerRect.setBottom(headerRect.top()+fm.height()); + + subheaderRect.setTop(headerRect.bottom()+2); + + + //painter->drawPixmap(QPoint(iconRect.right()/2,iconRect.top()/2),icon.pixmap(iconsize.width(),iconsize.height())); + painter->drawPixmap(QPoint(tileRect.left()+tileSize.width()/2+2,tileRect.top()+tileSize.height()/2+3),tile); + + painter->setFont(font); + painter->drawText(headerRect,headerText); + + + painter->setFont(SubFont); + painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText); + + painter->restore(); +} + +QSize TileItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const +{ + QPixmap tile = qvariant_cast(index.data(TileModel::TilePixmapRole)); + QSize tileSize = tile.size();//tile.actualSize(option.decorationSize); + QFont font = QApplication::font(); + QFontMetrics fm(font); + + return(QSize(tileSize.width(), tileSize.height()+fm.height()+8 )); +} + +TileItemDelegate::TZoomFactor TileItemDelegate::getZoomFactor() +{ + return m_zoomFactor; +} + +void TileItemDelegate::setZoomFactor(TileItemDelegate::TZoomFactor zoomFactor) +{ + m_zoomFactor = zoomFactor; +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.h new file mode 100644 index 000000000..b87a17344 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item_delegate.h @@ -0,0 +1,53 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +#ifndef TILE_ITEM_DELEGATE_H +#define TILE_ITEM_DELEGATE_H + +#include +#include +#include + +#include "ui_tile_widget.h" + +#include + +class TileItemDelegate : public QStyledItemDelegate + { + public: + + enum TZoomFactor + { + ZoomSmall = 0, + ZoomNormal = 1, + ZoomLarge = 2 + }; + + static const int PIXMAP_MARGIN = 5; + + TileItemDelegate(); + virtual ~TileItemDelegate(); + + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const; + + TZoomFactor getZoomFactor(); + void setZoomFactor(TZoomFactor zoomFactor); + + private: + TZoomFactor m_zoomFactor; + }; + +#endif // TILE_ITEM_DELEGATE_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp index d31289c21..19fa9409f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp @@ -88,11 +88,8 @@ QVariant TileModel::data(const QModelIndex &index, int role) const if(!index.isValid()) return QVariant(); - if(role != Qt::DisplayRole) - return QVariant(); - Node *item = static_cast(index.internalPointer()); - return item->data(index.column()); + return item->data(index.column(), role); } Qt::ItemFlags TileModel::flags(const QModelIndex &index) const @@ -106,7 +103,7 @@ Qt::ItemFlags TileModel::flags(const QModelIndex &index) const QVariant TileModel::headerData(int section, Qt::Orientation orientation, int role) const { if(orientation == Qt::Horizontal && role == Qt::DisplayRole) - return rootItem->data(section); + return rootItem->data(section,role); return QVariant(); } @@ -128,40 +125,75 @@ TileSetNode *TileModel::createTileSetNode(QString tileSetName) TileSetNode *tileSet = new TileSetNode(tileSetName); // child for 128x128 tiles - TileTypeNode *tile128= new TileTypeNode(TileTypeNode::Tile128); - + TileTypeNode *tile128= new TileTypeNode(Tile128); + tileSet->appendRow(tile128); + // child for 256x256 tiles - TileTypeNode *tile256= new TileTypeNode(TileTypeNode::Tile256); + TileTypeNode *tile256= new TileTypeNode(Tile256); + tileSet->appendRow(tile256); // child for transition tiles. - TileTypeNode *tileTrans= new TileTypeNode(TileTypeNode::TileTransition); + TileTypeNode *tileTrans= new TileTypeNode(TileTransition); + tileSet->appendRow(tileTrans); // Add the default transition tiles. // TODO tie this to CTileSet::count from NeL for(int transPos=0; transPos<48; transPos++) { - TileItemNode *transTile= new TileItemNode(transPos, TileItemNode::TileDiffuse, QString("filename").append(QString::number(transPos+1))); + TileItemNode *transTile= new TileItemNode(transPos, TileDiffuse, QString("empty")); tileTrans->appendRow(transTile); } // child for displacement tiles - TileTypeNode *tileDisp= new TileTypeNode(TileTypeNode::TileDisplacement); + TileTypeNode *tileDisp= new TileTypeNode(TileDisplacement); + tileSet->appendRow(tileDisp); // Add the default displacement tiles. // TODO tie this to CTileSet::CountDisplace from NeL for(int dispPos=0; dispPos<16; dispPos++) { - TileItemNode *dispTile= new TileItemNode(dispPos, TileItemNode::TileDiffuse, QString("filename").append(QString::number(dispPos+1))); + TileItemNode *dispTile= new TileItemNode(dispPos, TileDiffuse, QString("empty")); tileDisp->appendRow(dispTile); } // Append them in the correct order to the tile set. - tileSet->appendRow(tile128); - tileSet->appendRow(tile256); - tileSet->appendRow(tileTrans); - tileSet->appendRow(tileDisp); - this->appendRow(tileSet); return tileSet; +} + +const char *TileModel::getTileTypeName(TileModel::TNodeTileType type) +{ + switch(type) + { + case Tile128: + return "128"; + case Tile256: + return "256"; + case TileTransition: + return "Transition"; + case TileDisplacement: + return "Displacement"; + default: + break; + } + return "UNKNOWN"; +} + +uint32 TileModel::getTileTypeSize(TileModel::TNodeTileType type) +{ + switch(type) + { + case Tile128: + return 128; + case Tile256: + return 256; + case TileTransition: + return 64; + case TileDisplacement: + return 32; + default: + break; + } + return 0; } \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h index fba135812..aea6461b1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h @@ -29,6 +29,29 @@ class TileModel : public QAbstractItemModel Q_OBJECT public: + enum TTileChannel + { + TileDiffuse = 0, + TileAdditive = 1, + TileAlpha = 2, + }; + + enum TNodeTileType + { + Tile128 = 0, + Tile256 = 1, + TileTransition = 2, + TileDisplacement = 3 + }; + + enum TTileItemRole + { + TilePixmapRole = Qt::UserRole+1, + TileFilenameRole = Qt::UserRole+2, + TileIndexRole = Qt::UserRole+3 + }; + + TileModel(const QStringList &headers, QObject *parent); ~TileModel(); @@ -46,6 +69,9 @@ public: TileSetNode *createTileSetNode(QString tileSetName); + static const char *getTileTypeName(TNodeTileType type); + static uint32 getTileTypeSize(TileModel::TNodeTileType type); + private: Node *getItem(const QModelIndex &index) const;