mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 17:29:10 +00:00
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.
--HG-- branch : branch-tile-edit-ovqt-plugin
This commit is contained in:
parent
04c6c1b48a
commit
99ec1aab27
9 changed files with 443 additions and 87 deletions
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "tile_model.h"
|
#include "tile_model.h"
|
||||||
#include "tile_item.h"
|
#include "tile_item.h"
|
||||||
|
#include "tile_item_delegate.h"
|
||||||
|
|
||||||
TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent),
|
||||||
|
@ -72,6 +73,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << "Tile Set";
|
headers << "Tile Set";
|
||||||
m_model = new TileModel(headers, this);
|
m_model = new TileModel(headers, this);
|
||||||
|
m_tileItemDelegate = new TileItemDelegate();
|
||||||
|
|
||||||
// Set up the tile set list view.
|
// Set up the tile set list view.
|
||||||
m_ui->tileSetLV->setModel(m_model);
|
m_ui->tileSetLV->setModel(m_model);
|
||||||
|
@ -82,6 +84,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &)));
|
this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &)));
|
||||||
|
|
||||||
// 128x128 List View
|
// 128x128 List View
|
||||||
|
m_ui->listView128->setItemDelegate(m_tileItemDelegate);
|
||||||
m_ui->listView128->setModel(m_model);
|
m_ui->listView128->setModel(m_model);
|
||||||
m_ui->listView128->addAction(m_ui->actionAddTile);
|
m_ui->listView128->addAction(m_ui->actionAddTile);
|
||||||
m_ui->listView128->addAction(m_ui->actionDeleteTile);
|
m_ui->listView128->addAction(m_ui->actionDeleteTile);
|
||||||
|
@ -89,6 +92,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
m_ui->listView128->addAction(m_ui->actionDeleteImage);
|
m_ui->listView128->addAction(m_ui->actionDeleteImage);
|
||||||
|
|
||||||
// 256x256 List View
|
// 256x256 List View
|
||||||
|
m_ui->listView256->setItemDelegate(m_tileItemDelegate);
|
||||||
m_ui->listView256->setModel(m_model);
|
m_ui->listView256->setModel(m_model);
|
||||||
m_ui->listView256->addAction(m_ui->actionAddTile);
|
m_ui->listView256->addAction(m_ui->actionAddTile);
|
||||||
m_ui->listView256->addAction(m_ui->actionDeleteTile);
|
m_ui->listView256->addAction(m_ui->actionDeleteTile);
|
||||||
|
@ -96,14 +100,17 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
m_ui->listView256->addAction(m_ui->actionDeleteImage);
|
m_ui->listView256->addAction(m_ui->actionDeleteImage);
|
||||||
|
|
||||||
// Transition List View
|
// Transition List View
|
||||||
|
m_ui->listViewTransition->setItemDelegate(m_tileItemDelegate);
|
||||||
m_ui->listViewTransition->setModel(m_model);
|
m_ui->listViewTransition->setModel(m_model);
|
||||||
m_ui->listViewTransition->addAction(m_ui->actionReplaceImage);
|
m_ui->listViewTransition->addAction(m_ui->actionReplaceImage);
|
||||||
m_ui->listViewTransition->addAction(m_ui->actionDeleteImage);
|
m_ui->listViewTransition->addAction(m_ui->actionDeleteImage);
|
||||||
|
|
||||||
// Displacement List View
|
// Displacement List View
|
||||||
|
m_ui->listViewDisplacement->setItemDelegate(m_tileItemDelegate);
|
||||||
m_ui->listViewDisplacement->setModel(m_model);
|
m_ui->listViewDisplacement->setModel(m_model);
|
||||||
m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage);
|
m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage);
|
||||||
m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage);
|
m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage);
|
||||||
|
|
||||||
|
|
||||||
// Connect context menu actions up.
|
// Connect context menu actions up.
|
||||||
connect(m_ui->actionAddTile, SIGNAL(triggered(bool)), this, SLOT(onActionAddTile(bool)));
|
connect(m_ui->actionAddTile, SIGNAL(triggered(bool)), this, SLOT(onActionAddTile(bool)));
|
||||||
|
@ -168,11 +175,15 @@ void TileEditorMainWindow::onTileSetAdd()
|
||||||
//}
|
//}
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
|
||||||
|
// Create and append the new tile set to the model.
|
||||||
TileSetNode *tileSet = model->createTileSetNode(text);
|
TileSetNode *tileSet = model->createTileSetNode(text);
|
||||||
|
|
||||||
|
// Retrieve how many rows there currently are and set the current index using that.
|
||||||
m_ui->tileSetLV->reset();
|
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;
|
QFileDialog::Options options;
|
||||||
QString selectedFilter;
|
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)
|
void TileEditorMainWindow::changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex)
|
||||||
{
|
{
|
||||||
const QModelIndex &tile128Idx = newIndex.child(0,0);
|
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||||
const QModelIndex &tile256Idx = newIndex.child(1,0);
|
|
||||||
const QModelIndex &tileTransIdx = newIndex.child(2,0);
|
QModelIndex tile128Idx = model->index(0, 0, newIndex);
|
||||||
const QModelIndex &tileDispIdx = newIndex.child(3,0);
|
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->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->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->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->setRootIndex(tileDispIdx);
|
||||||
|
m_ui->listViewDisplacement->setCurrentIndex(m_ui->listViewDisplacement->model()->index(0, 0, m_ui->listViewDisplacement->rootIndex()));
|
||||||
|
|
||||||
m_ui->listView128->reset();
|
//nlinfo("number of rows in displacement: %d", tileDispIdx.model()->rowCount(tileDispIdx));
|
||||||
m_ui->listView256->reset();
|
|
||||||
m_ui->listViewTransition->reset();
|
//m_ui->listView128->reset();
|
||||||
m_ui->listViewDisplacement->reset();
|
//m_ui->listView256->reset();
|
||||||
|
//m_ui->listViewTransition->reset();
|
||||||
|
//m_ui->listViewDisplacement->reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TileModel;
|
class TileModel;
|
||||||
|
class TileItemDelegate;
|
||||||
|
|
||||||
class TileEditorMainWindow : public QMainWindow
|
class TileEditorMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,7 @@ private:
|
||||||
QMenu *m_tileEditorMenu;
|
QMenu *m_tileEditorMenu;
|
||||||
|
|
||||||
TileModel *m_model;
|
TileModel *m_model;
|
||||||
|
TileItemDelegate *m_tileItemDelegate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILE_EDITOR_MAIN_WINDOW_H
|
#endif // TILE_EDITOR_MAIN_WINDOW_H
|
||||||
|
|
|
@ -30,6 +30,24 @@
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::ActionsContextMenu</enum>
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>128</width>
|
||||||
|
<height>128</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="flow">
|
||||||
|
<enum>QListView::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="viewMode">
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
@ -70,6 +88,24 @@
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::ActionsContextMenu</enum>
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>256</width>
|
||||||
|
<height>256</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="flow">
|
||||||
|
<enum>QListView::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="viewMode">
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
@ -113,12 +149,27 @@
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::ActionsContextMenu</enum>
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="flow">
|
<property name="flow">
|
||||||
<enum>QListView::LeftToRight</enum>
|
<enum>QListView::LeftToRight</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="layoutMode">
|
<property name="layoutMode">
|
||||||
<enum>QListView::Batched</enum>
|
<enum>QListView::Batched</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="viewMode">
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
|
@ -166,6 +217,27 @@
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::ActionsContextMenu</enum>
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>32</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="flow">
|
||||||
|
<enum>QListView::LeftToRight</enum>
|
||||||
|
</property>
|
||||||
|
<property name="isWrapping" stdset="0">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="resizeMode">
|
||||||
|
<enum>QListView::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="viewMode">
|
||||||
|
<enum>QListView::IconMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="uniformItemSizes">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -14,8 +14,12 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
#include "tile_item.h"
|
#include "tile_item.h"
|
||||||
|
|
||||||
|
//#include "tile_widget.h"
|
||||||
|
|
||||||
#include <nel/misc/debug.h>
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
Node::Node() : m_parentItem(0)
|
Node::Node() : m_parentItem(0)
|
||||||
|
@ -109,9 +113,11 @@ int Node::columnCount() const
|
||||||
return m_itemData.count();
|
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)
|
bool Node::setData(int column, const QVariant &value)
|
||||||
|
@ -157,14 +163,21 @@ TileSetNode::~TileSetNode()
|
||||||
qDeleteAll(m_childItems);
|
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;
|
m_parentItem = parent;
|
||||||
}
|
}
|
||||||
|
@ -174,42 +187,34 @@ TileTypeNode::~TileTypeNode()
|
||||||
qDeleteAll(m_childItems);
|
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;
|
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_tileFilename[channel] = filename;
|
||||||
m_parentItem = parent;
|
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()
|
TileItemNode::~TileItemNode()
|
||||||
|
@ -217,14 +222,71 @@ TileItemNode::~TileItemNode()
|
||||||
qDeleteAll(m_childItems);
|
qDeleteAll(m_childItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileItemNode::setTileFilename(TTileChannel channel, QString filename)
|
void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename)
|
||||||
{
|
{
|
||||||
m_tileFilename[channel] = 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
|
// 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<TileTypeNode*>(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;
|
||||||
|
}
|
|
@ -22,6 +22,10 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "tile_model.h"
|
||||||
|
|
||||||
|
class TileWidget;
|
||||||
|
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -34,9 +38,9 @@ public:
|
||||||
Node *child(int row);
|
Node *child(int row);
|
||||||
int childCount() const;
|
int childCount() const;
|
||||||
int childNumber() const;
|
int childNumber() const;
|
||||||
int columnCount() const;
|
virtual int columnCount() const;
|
||||||
bool setData(int column, const QVariant &value);
|
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 insertChildren(int position, int count, int columns);
|
||||||
bool removeChildren(int position, int count);
|
bool removeChildren(int position, int count);
|
||||||
|
@ -60,7 +64,8 @@ class TileSetNode : public Node
|
||||||
public:
|
public:
|
||||||
TileSetNode(QString tileSetName, Node *parent=0);
|
TileSetNode(QString tileSetName, Node *parent=0);
|
||||||
virtual ~TileSetNode();
|
virtual ~TileSetNode();
|
||||||
QVariant data(int column) const;
|
QVariant data(int column, int role) const;
|
||||||
|
int columnCount() const;
|
||||||
|
|
||||||
const QString &getTileSetName();
|
const QString &getTileSetName();
|
||||||
private:
|
private:
|
||||||
|
@ -70,42 +75,29 @@ private:
|
||||||
class TileTypeNode : public Node
|
class TileTypeNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
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();
|
virtual ~TileTypeNode();
|
||||||
QVariant data(int column) const;
|
QVariant data(int column, int role) const;
|
||||||
|
int columnCount() const;
|
||||||
|
|
||||||
TNodeTileType getTileType();
|
TileModel::TNodeTileType getTileType();
|
||||||
|
|
||||||
static const char *getTileTypeName(TNodeTileType type);
|
|
||||||
private:
|
private:
|
||||||
TNodeTileType m_nodeTileType;
|
TileModel::TNodeTileType m_nodeTileType;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TileItemNode : public Node
|
class TileItemNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum TTileChannel
|
TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent=0);
|
||||||
{
|
|
||||||
TileDiffuse = 0,
|
|
||||||
TileAdditive = 1,
|
|
||||||
TileAlpha = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
TileItemNode(int tileId, TTileChannel channel, QString filename, Node *parent=0);
|
|
||||||
virtual ~TileItemNode();
|
virtual ~TileItemNode();
|
||||||
QVariant data(int column) const;
|
QVariant data(int column, int role) const;
|
||||||
void setTileFilename(TTileChannel channel, QString filename);
|
int columnCount() const;
|
||||||
|
void setTileFilename(TileModel::TTileChannel channel, QString filename);
|
||||||
private:
|
private:
|
||||||
int m_tileId;
|
int m_tileId;
|
||||||
QMap<TTileChannel, QString> m_tileFilename;
|
QMap<TileModel::TTileChannel, QString> m_tileFilename;
|
||||||
|
QMap<TileModel::TTileChannel, TileWidget*> m_tileWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILE_ITEM_H
|
#endif // TILE_ITEM_H
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QtGui/QtGui>
|
||||||
|
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
|
#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<QPixmap>(index.data(TileModel::TilePixmapRole));
|
||||||
|
QString headerText = qvariant_cast<QString>(index.data(TileModel::TileFilenameRole));
|
||||||
|
QString subText = qvariant_cast<QString>(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<QPixmap>(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;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#ifndef TILE_ITEM_DELEGATE_H
|
||||||
|
#define TILE_ITEM_DELEGATE_H
|
||||||
|
|
||||||
|
#include <QtGui/QWidget>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include "ui_tile_widget.h"
|
||||||
|
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
|
||||||
|
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
|
|
@ -88,11 +88,8 @@ QVariant TileModel::data(const QModelIndex &index, int role) const
|
||||||
if(!index.isValid())
|
if(!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if(role != Qt::DisplayRole)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
Node *item = static_cast<Node*>(index.internalPointer());
|
Node *item = static_cast<Node*>(index.internalPointer());
|
||||||
return item->data(index.column());
|
return item->data(index.column(), role);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags TileModel::flags(const QModelIndex &index) const
|
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
|
QVariant TileModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||||
return rootItem->data(section);
|
return rootItem->data(section,role);
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -128,40 +125,75 @@ TileSetNode *TileModel::createTileSetNode(QString tileSetName)
|
||||||
TileSetNode *tileSet = new TileSetNode(tileSetName);
|
TileSetNode *tileSet = new TileSetNode(tileSetName);
|
||||||
|
|
||||||
// child for 128x128 tiles
|
// child for 128x128 tiles
|
||||||
TileTypeNode *tile128= new TileTypeNode(TileTypeNode::Tile128);
|
TileTypeNode *tile128= new TileTypeNode(Tile128);
|
||||||
|
tileSet->appendRow(tile128);
|
||||||
|
|
||||||
// child for 256x256 tiles
|
// child for 256x256 tiles
|
||||||
TileTypeNode *tile256= new TileTypeNode(TileTypeNode::Tile256);
|
TileTypeNode *tile256= new TileTypeNode(Tile256);
|
||||||
|
tileSet->appendRow(tile256);
|
||||||
|
|
||||||
// child for transition tiles.
|
// child for transition tiles.
|
||||||
TileTypeNode *tileTrans= new TileTypeNode(TileTypeNode::TileTransition);
|
TileTypeNode *tileTrans= new TileTypeNode(TileTransition);
|
||||||
|
tileSet->appendRow(tileTrans);
|
||||||
|
|
||||||
// Add the default transition tiles.
|
// Add the default transition tiles.
|
||||||
// TODO tie this to CTileSet::count from NeL
|
// TODO tie this to CTileSet::count from NeL
|
||||||
for(int transPos=0; transPos<48; transPos++)
|
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);
|
tileTrans->appendRow(transTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// child for displacement tiles
|
// child for displacement tiles
|
||||||
TileTypeNode *tileDisp= new TileTypeNode(TileTypeNode::TileDisplacement);
|
TileTypeNode *tileDisp= new TileTypeNode(TileDisplacement);
|
||||||
|
tileSet->appendRow(tileDisp);
|
||||||
|
|
||||||
// Add the default displacement tiles.
|
// Add the default displacement tiles.
|
||||||
// TODO tie this to CTileSet::CountDisplace from NeL
|
// TODO tie this to CTileSet::CountDisplace from NeL
|
||||||
for(int dispPos=0; dispPos<16; dispPos++)
|
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);
|
tileDisp->appendRow(dispTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append them in the correct order to the tile set.
|
// 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);
|
this->appendRow(tileSet);
|
||||||
|
|
||||||
return 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;
|
||||||
}
|
}
|
|
@ -29,6 +29,29 @@ class TileModel : public QAbstractItemModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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(const QStringList &headers, QObject *parent);
|
||||||
~TileModel();
|
~TileModel();
|
||||||
|
|
||||||
|
@ -46,6 +69,9 @@ public:
|
||||||
|
|
||||||
TileSetNode *createTileSetNode(QString tileSetName);
|
TileSetNode *createTileSetNode(QString tileSetName);
|
||||||
|
|
||||||
|
static const char *getTileTypeName(TNodeTileType type);
|
||||||
|
static uint32 getTileTypeSize(TileModel::TNodeTileType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Node *getItem(const QModelIndex &index) const;
|
Node *getItem(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue