mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 17:46:18 +00:00
Changed: #1409 Tile Edit Qt - Adding some of the hierarchy logic to the list views.
--HG-- branch : branch-tile-edit-ovqt-plugin
This commit is contained in:
parent
5432f4eb58
commit
f57c47af54
5 changed files with 122 additions and 22 deletions
|
@ -75,8 +75,11 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||||
|
|
||||||
// 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);
|
||||||
m_ui->tileSetLV->setRootIndex(m_model->index(0,0));
|
//m_ui->tileSetLV->setRootIndex(m_model->index(0,0));
|
||||||
connect(m_ui->tileSetAddTB, SIGNAL(clicked()), this, SLOT(onTileSetAdd()));
|
connect(m_ui->tileSetAddTB, SIGNAL(clicked()), this, SLOT(onTileSetAdd()));
|
||||||
|
connect(m_ui->tileSetLV->selectionModel(),
|
||||||
|
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
||||||
|
this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &)));
|
||||||
|
|
||||||
// 128x128 List View
|
// 128x128 List View
|
||||||
m_ui->listView128->setModel(m_model);
|
m_ui->listView128->setModel(m_model);
|
||||||
|
@ -130,30 +133,71 @@ void TileEditorMainWindow::onTileSetAdd()
|
||||||
//else
|
//else
|
||||||
//{
|
//{
|
||||||
|
|
||||||
QModelIndex index = m_ui->tileSetLV->selectionModel()->currentIndex();
|
//QModelIndex index = m_ui->tileSetLV->selectionModel()->currentIndex();
|
||||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||||
|
|
||||||
if(index.isValid())
|
//if(index.isValid())
|
||||||
{
|
//{
|
||||||
if(!model->insertRow(index.row()+1, index.parent()))
|
// if(!model->insertRow(index.row()+1, index.parent()))
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
//updateActions()
|
// //updateActions()
|
||||||
|
|
||||||
for(int column=0; column<model->columnCount(index.parent()); column++)
|
// for(int column=0; column<model->columnCount(index.parent()); column++)
|
||||||
{
|
// {
|
||||||
QModelIndex child = model->index(index.row()+1, column, index.parent());
|
// QModelIndex child = model->index(index.row()+1, column, index.parent());
|
||||||
model->setData(child, QVariant(text), Qt::EditRole);
|
// model->setData(child, QVariant(text), Qt::EditRole);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
|
// Create the new tile set.
|
||||||
QVector<QVariant> items;
|
QVector<QVariant> items;
|
||||||
items.push_back(QVariant(text));
|
items.push_back(text);
|
||||||
TileItem *item = new TileItem(items, 0);
|
TileItem *tileSet = new TileItem(items);
|
||||||
model->appendRow(item);
|
|
||||||
|
// child for 128x128 tiles
|
||||||
|
QVector<QVariant> tiles128;
|
||||||
|
tiles128.push_back(QString("128"));
|
||||||
|
TileTypeTileItem *tile128= new TileTypeTileItem(tiles128);
|
||||||
|
|
||||||
|
// child for 256x256 tiles
|
||||||
|
QVector<QVariant> tiles256;
|
||||||
|
tiles256.push_back(QString("256"));
|
||||||
|
TileTypeTileItem *tile256= new TileTypeTileItem(tiles256);
|
||||||
|
|
||||||
|
|
||||||
|
// child for transition tiles.
|
||||||
|
QVector<QVariant> tilesTrans;
|
||||||
|
tilesTrans.push_back(QString("Transition"));
|
||||||
|
TileTypeTileItem *tileTrans= new TileTypeTileItem(tilesTrans);
|
||||||
|
|
||||||
|
// Add the default transition tiles.
|
||||||
|
// TODO tie this to CTileSet::count from NeL
|
||||||
|
for(int transPos=0; transPos < 48; transPos++)
|
||||||
|
{
|
||||||
|
QVector<QVariant> tileInfo;
|
||||||
|
tileInfo.push_back(QString("filename").append(QString::number(transPos+1)));
|
||||||
|
TileItem *transTile= new TileItem(tileInfo);
|
||||||
|
tileTrans->appendRow(transTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// child for displacement tiles
|
||||||
|
QVector<QVariant> tilesDisp;
|
||||||
|
tilesDisp.push_back(QString("Displacement"));
|
||||||
|
TileTypeTileItem *tileDisp= new TileTypeTileItem(tilesDisp);
|
||||||
|
|
||||||
|
// Append them in the correct order to the tile set.
|
||||||
|
tileSet->appendRow(tile128);
|
||||||
|
tileSet->appendRow(tile256);
|
||||||
|
tileSet->appendRow(tileTrans);
|
||||||
|
tileSet->appendRow(tileDisp);
|
||||||
|
|
||||||
|
model->appendRow(tileSet);
|
||||||
|
|
||||||
|
m_ui->tileSetLV->reset();
|
||||||
//updateActions()
|
//updateActions()
|
||||||
}
|
//}
|
||||||
|
|
||||||
// tileBank.addTileSet( text.toStdString() );
|
// tileBank.addTileSet( text.toStdString() );
|
||||||
|
|
||||||
|
@ -168,4 +212,20 @@ 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", "." , "PNG Bitmap(*.png);;All Files (*.*);;", &selectedFilter, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileEditorMainWindow::changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex)
|
||||||
|
{
|
||||||
|
|
||||||
|
QModelIndex tile128Idx = newIndex.child(0,0);
|
||||||
|
QModelIndex tile256Idx = newIndex.child(1,0);
|
||||||
|
QModelIndex tileTransIdx = newIndex.child(2,0);
|
||||||
|
QModelIndex tileDispIdx = newIndex.child(3,0);
|
||||||
|
|
||||||
|
|
||||||
|
m_ui->listView128->setRootIndex(newIndex);
|
||||||
|
m_ui->listView256->setRootIndex(tile256Idx);
|
||||||
|
m_ui->listViewTransition->setRootIndex(tileTransIdx);
|
||||||
|
m_ui->listViewDisplacement->setRootIndex(tileDispIdx);
|
||||||
|
// m_ui->listView128->setModelColumn
|
||||||
}
|
}
|
|
@ -46,6 +46,7 @@ public Q_SLOTS:
|
||||||
void onActionReplaceImage(bool triggered);
|
void onActionReplaceImage(bool triggered);
|
||||||
void onActionDeleteImage(bool triggered);
|
void onActionDeleteImage(bool triggered);
|
||||||
void onTileSetAdd();
|
void onTileSetAdd();
|
||||||
|
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onActionAddTile(int tabId);
|
void onActionAddTile(int tabId);
|
||||||
|
|
|
@ -468,7 +468,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QListView" name="tileSetLV"/>
|
<widget class="QTreeView" name="tileSetLV"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include "tile_item.h"
|
#include "tile_item.h"
|
||||||
|
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
TileItem::TileItem(const QVector<QVariant> &data, TileItem *parent)
|
TileItem::TileItem(const QVector<QVariant> &data, TileItem *parent)
|
||||||
{
|
{
|
||||||
parentItem = parent;
|
parentItem = parent;
|
||||||
|
@ -121,6 +123,11 @@ TileItem *TileItem::parent()
|
||||||
return parentItem;
|
return parentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileItem::setParent(TileItem *parent)
|
||||||
|
{
|
||||||
|
parentItem = parent;
|
||||||
|
}
|
||||||
|
|
||||||
void TileItem::appendRow(const QList<TileItem*> &items)
|
void TileItem::appendRow(const QList<TileItem*> &items)
|
||||||
{
|
{
|
||||||
Q_FOREACH(TileItem *item, items)
|
Q_FOREACH(TileItem *item, items)
|
||||||
|
@ -129,10 +136,33 @@ void TileItem::appendRow(const QList<TileItem*> &items)
|
||||||
|
|
||||||
void TileItem::appendRow(TileItem *item)
|
void TileItem::appendRow(TileItem *item)
|
||||||
{
|
{
|
||||||
|
nlinfo("number of children: %d", childItems.size());
|
||||||
|
item->setParent(this);
|
||||||
childItems.append(item);
|
childItems.append(item);
|
||||||
|
nlinfo("number of children: %d", childItems.size());
|
||||||
}
|
}
|
||||||
//QImage *TileItem::getTileImageFromChannel(int channel)
|
//QImage *TileItem::getTileImageFromChannel(int channel)
|
||||||
//{
|
//{
|
||||||
// return m_tileChannels[channel];
|
// return m_tileChannels[channel];
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////
|
||||||
|
|
||||||
|
TileTypeTileItem::TileTypeTileItem(const QVector<QVariant> &data, TileItem *parent) : TileItem(data,parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TileTypeTileItem::~TileTypeTileItem()
|
||||||
|
{
|
||||||
|
qDeleteAll(childItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant TileTypeTileItem::data(int column) const
|
||||||
|
{
|
||||||
|
QVariant val = itemData.value(column);
|
||||||
|
|
||||||
|
nlinfo("the column is %d and the value is '%s'. there are %d values",
|
||||||
|
column, val.toString().toStdString().c_str(), itemData.size());
|
||||||
|
return itemData.value(column);
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ class TileItem
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TileItem(const QVector<QVariant> &data, TileItem *parent=0);
|
TileItem(const QVector<QVariant> &data, TileItem *parent=0);
|
||||||
~TileItem();
|
virtual ~TileItem();
|
||||||
|
|
||||||
void appendChild(TileItem *child);
|
void appendChild(TileItem *child);
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
int row() const;
|
int row() const;
|
||||||
TileItem *parent();
|
TileItem *parent();
|
||||||
|
void setParent(TileItem *parent);
|
||||||
|
|
||||||
void appendRow(const QList<TileItem*> &items);
|
void appendRow(const QList<TileItem*> &items);
|
||||||
void appendRow(TileItem *item);
|
void appendRow(TileItem *item);
|
||||||
|
@ -53,7 +54,7 @@ public:
|
||||||
//int getTileIndex() { return m_tileIndex; }
|
//int getTileIndex() { return m_tileIndex; }
|
||||||
//QString getTileFilename() { return m_tileFilename; }
|
//QString getTileFilename() { return m_tileFilename; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
QList<TileItem*> childItems;
|
QList<TileItem*> childItems;
|
||||||
QVector<QVariant> itemData;
|
QVector<QVariant> itemData;
|
||||||
TileItem *parentItem;
|
TileItem *parentItem;
|
||||||
|
@ -63,4 +64,12 @@ private:
|
||||||
//QString m_tileFilename;
|
//QString m_tileFilename;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TileTypeTileItem : public TileItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TileTypeTileItem(const QVector<QVariant> &data, TileItem *parent=0);
|
||||||
|
virtual ~TileTypeTileItem();
|
||||||
|
QVariant data(int column) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // TILE_ITEM_H
|
#endif // TILE_ITEM_H
|
||||||
|
|
Loading…
Reference in a new issue