Changed: #1409 Removing the tile item delegate, modifying the model with custom roles for view modes.

--HG--
branch : branch-tile-edit-ovqt-plugin
This commit is contained in:
sfb 2012-02-27 08:40:23 -06:00
parent 99ec1aab27
commit f6f664452d
8 changed files with 223 additions and 60 deletions

View file

@ -43,7 +43,6 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
Core::ICore *core = Core::ICore::instance();
Core::MenuManager *menuManager = core->menuManager();
QMenu *m_tileEditorMenu;
// Create tile rotation drop down toolbar menu.
m_rotationMenu = new QMenu(tr("Rotate Tile"), m_ui->toolBar);
m_rotationMenu->setIcon(QIcon(":/tileRotation/images/rotation0.png"));
@ -57,7 +56,17 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
// Create the tile zoom menu.
m_zoomMenu = new QMenu(tr("Zoom"), m_ui->toolBar);
m_zoomActionGroup = new QActionGroup(this);
m_zoomSignalMapper = new QSignalMapper(this);
QList<QAction*> zoomActions;
zoomActions.push_back(m_ui->actionZoom50);
zoomActions.push_back(m_ui->actionZoom100);
zoomActions.push_back(m_ui->actionZoom200);
m_zoomActionGroup->addAction(m_ui->actionZoom50);
m_zoomActionGroup->addAction(m_ui->actionZoom100);
m_zoomActionGroup->addAction(m_ui->actionZoom200);
m_zoomMenu->addActions(zoomActions);
m_ui->toolBar->addAction(m_zoomMenu->menuAction());
m_tileEditorMenu = new QMenu(tr("Tile Editor"), core->menuManager()->menuBar());
m_tileDisplayMenu = new QMenu(tr("Tile Display"), m_ui->toolBar);
@ -84,7 +93,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &)));
// 128x128 List View
m_ui->listView128->setItemDelegate(m_tileItemDelegate);
//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);
@ -92,7 +101,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
m_ui->listView128->addAction(m_ui->actionDeleteImage);
// 256x256 List View
m_ui->listView256->setItemDelegate(m_tileItemDelegate);
//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);
@ -100,13 +109,13 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
m_ui->listView256->addAction(m_ui->actionDeleteImage);
// Transition List View
m_ui->listViewTransition->setItemDelegate(m_tileItemDelegate);
//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->setItemDelegate(m_tileItemDelegate);
m_ui->listViewDisplacement->setModel(m_model);
m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage);
m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage);
@ -117,6 +126,20 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
connect(m_ui->actionDeleteTile, SIGNAL(triggered(bool)), this, SLOT(onActionDeleteTile(bool)));
connect(m_ui->actionReplaceImage, SIGNAL(triggered(bool)), this, SLOT(onActionReplaceImage(bool)));
connect(m_ui->actionDeleteImage, SIGNAL(triggered(bool)), this, SLOT(onActioneleteImage(bool)));
connect(m_ui->actionTileDisplayFilename, SIGNAL(toggled(bool)), m_model, SLOT(selectFilenameDisplay(bool)));
connect(m_ui->actionTileDisplayIndex, SIGNAL(toggled(bool)), m_model, SLOT(selectIndexDisplay(bool)));
//connect(m_ui->tileViewTabWidget, SIGNAL(currentChanged(int)), m_tileItemDelegate, SLOT(currentTab(int)));
// Connect the zoom buttons.
connect(m_ui->actionZoom50, SIGNAL(triggered()), m_zoomSignalMapper, SLOT(map()));
m_zoomSignalMapper->setMapping(m_ui->actionZoom50, 0);
connect(m_ui->actionZoom100, SIGNAL(triggered()), m_zoomSignalMapper, SLOT(map()));
m_zoomSignalMapper->setMapping(m_ui->actionZoom100, 1);
connect(m_ui->actionZoom200, SIGNAL(triggered()), m_zoomSignalMapper, SLOT(map()));
m_zoomSignalMapper->setMapping(m_ui->actionZoom200, 2);
connect(m_zoomSignalMapper, SIGNAL(mapped(int)), m_model, SLOT(onZoomFactor(int)));
}
TileEditorMainWindow::~TileEditorMainWindow()
@ -125,6 +148,14 @@ TileEditorMainWindow::~TileEditorMainWindow()
delete m_undoStack;
delete m_rotationMenu;
delete m_zoomMenu;
delete m_tileDisplayMenu;
delete m_tileEditorMenu;
delete m_zoomMenu;
delete m_zoomActionGroup;
delete m_zoomSignalMapper;
}
void TileEditorMainWindow::onActionAddTile(bool triggered)

View file

@ -23,6 +23,7 @@
#include "nel/misc/sheet_id.h"
#include <QtGui/QUndoStack>
#include <QSignalMapper>
namespace Ui {
class TileEditorMainWindow;
@ -47,7 +48,7 @@ public Q_SLOTS:
void onActionReplaceImage(bool triggered);
void onActionDeleteImage(bool triggered);
void onTileSetAdd();
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
private:
void onActionAddTile(int tabId);
@ -55,10 +56,14 @@ private:
Ui::TileEditorMainWindow *m_ui;
QUndoStack *m_undoStack;
QMenu *m_rotationMenu;
QMenu *m_zoomMenu;
QMenu *m_tileDisplayMenu;
QMenu *m_tileEditorMenu;
QMenu *m_zoomMenu;
QActionGroup *m_zoomActionGroup;
QSignalMapper *m_zoomSignalMapper;
TileModel *m_model;
TileItemDelegate *m_tileItemDelegate;
};

View file

@ -161,14 +161,17 @@
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
<enum>QListView::SinglePass</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
@ -678,6 +681,9 @@
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Index</string>
</property>
@ -689,6 +695,9 @@
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Filename</string>
</property>
@ -744,6 +753,33 @@
<string>Delete Image</string>
</property>
</action>
<action name="actionZoom50">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Zoom 50%</string>
</property>
</action>
<action name="actionZoom100">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Zoom 100%</string>
</property>
</action>
<action name="actionZoom200">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Zoom 200%</string>
</property>
</action>
</widget>
<resources>
<include location="tile_editor.qrc"/>

View file

@ -115,7 +115,10 @@ int Node::columnCount() const
QVariant Node::data(int column, int role) const
{
if(role == Qt::DisplayRole)
if(role == Qt::DisplayRole ||
role == TileModel::TileFilenameIndexRole ||
role == TileModel::TileFilenameRole ||
role == TileModel::TileIndexRole)
return m_itemData.value(column);
return QVariant();
}
@ -165,7 +168,10 @@ TileSetNode::~TileSetNode()
QVariant TileSetNode::data(int column, int role) const
{
if(role == Qt::DisplayRole)
if(role == Qt::DisplayRole ||
role == TileModel::TileFilenameIndexRole ||
role == TileModel::TileFilenameRole ||
role == TileModel::TileIndexRole)
return QVariant(m_tileSetName);
return QVariant();
}
@ -189,7 +195,10 @@ TileTypeNode::~TileTypeNode()
QVariant TileTypeNode::data(int column, int role) const
{
if(role == Qt::DisplayRole)
if(role == Qt::DisplayRole ||
role == TileModel::TileFilenameIndexRole ||
role == TileModel::TileFilenameRole ||
role == TileModel::TileIndexRole)
return QVariant(TileModel::getTileTypeName(m_nodeTileType));
return QVariant();
@ -228,29 +237,11 @@ void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString file
}
QVariant TileItemNode::data(int column, int role) const
{
nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toStdString().c_str());
{
// find some way to know which file/bitmap to display
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)
if(role == TileModel::TilePixmapRole || role == Qt::DecorationRole)
{
TileTypeNode *parent = dynamic_cast<TileTypeNode*>(m_parentItem);
if(parent == NULL)
@ -270,18 +261,22 @@ QVariant TileItemNode::data(int column, int role) const
return pixmap;
}
else if(role == Qt::DisplayRole)
{
return QVariant(tileFilename);
}
else if(role == TileModel::TileFilenameRole)
{
return QVariant(tileFilename);
}
else if(role == TileModel::TileIndexRole)
{
return QVariant(tileFilename);
return QVariant("("+QString::number(m_tileId)+")");
}
/*else if(role == Qt::TextAlignmentRole)
else if(role == TileModel::TileFilenameIndexRole)
{
return QVariant(Qt::AlignHCenter|Qt::AlignVCenter);
}*/
return QVariant(tileFilename + " ("+QString::number(m_tileId)+")");
}
return QVariant();
}

View file

@ -25,6 +25,7 @@
TileItemDelegate::TileItemDelegate()
{
m_zoomFactor = ZoomNormal;
m_imageHint = 128;
}
TileItemDelegate::~TileItemDelegate()
@ -38,41 +39,48 @@ void TileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
painter->save();
QFont font = QApplication::font();
QFont SubFont = QApplication::font();
//font.setPixelSize(font.weight()+);
font.setBold(true);
SubFont.setWeight(SubFont.weight()-2);
//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));
QString tileFileText = qvariant_cast<QString>(index.data(TileModel::TileFilenameRole));
QString tileIdText = qvariant_cast<QString>(index.data(TileModel::TileIndexRole));
QSize tileSize = tile.size();
QRect headerRect = option.rect;
QRect subheaderRect = option.rect;
QRect tileRect = subheaderRect;
//QRect headerRect = option.rect;
QRect rect(option.rect);
//QRect tileRect(option.rect);
int textHeight = fm.height();
int iconPosModX = PIXMAP_MARGIN + (tile.width() / 2);
int iconPosModY = (option.rect.height() - tile.height()) / 2;
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());
painter->drawPixmap(rect.adjusted(iconPosModX, iconPosModY, iconPosModX, iconPosModY).topLeft(), tile);
subheaderRect.setTop(headerRect.bottom()+2);
//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(targetrect, pixmap, sourcerect)
//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->drawPixmap(QPoint(tileRect.left()+tileSize.width()/2+2,tileRect.top()+tileSize.height()/2+3),tile);
painter->setFont(font);
painter->drawText(headerRect,headerText);
//painter->setFont(font);
//painter->drawText(headerRect,headerText);
painter->setFont(SubFont);
painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText);
//painter->setFont(SubFont);
//painter->drawText(subheaderRect.left(),subheaderRect.top()+17,subText);
painter->restore();
}
@ -80,11 +88,11 @@ void TileItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
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);
QSize tileSize = tile.size();
QFont font = QApplication::font();
QFontMetrics fm(font);
return(QSize(tileSize.width(), tileSize.height()+fm.height()+8 ));
return(QSize(tileSize.width()+(2*PIXMAP_MARGIN), tileSize.height()+fm.height()+(2*PIXMAP_MARGIN)));
}
TileItemDelegate::TZoomFactor TileItemDelegate::getZoomFactor()
@ -95,4 +103,20 @@ TileItemDelegate::TZoomFactor TileItemDelegate::getZoomFactor()
void TileItemDelegate::setZoomFactor(TileItemDelegate::TZoomFactor zoomFactor)
{
m_zoomFactor = zoomFactor;
}
// SLOTS
void TileItemDelegate::currentTab(int index)
{
if(index == 1)
{
nlinfo("switching delegate to 1 or 256");
m_imageHint = 256;
}
else
{
nlinfo("switching delegate to 0,2,3 or 128");
m_imageHint = 128;
}
}

View file

@ -46,8 +46,12 @@ class TileItemDelegate : public QStyledItemDelegate
TZoomFactor getZoomFactor();
void setZoomFactor(TZoomFactor zoomFactor);
public Q_SLOTS:
void currentTab(int index);
private:
TZoomFactor m_zoomFactor;
int m_imageHint;
};
#endif // TILE_ITEM_DELEGATE_H

View file

@ -19,6 +19,8 @@
#include <QStringList>
#include <nel/misc/debug.h>
TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractItemModel(parent)
{
QVector<QVariant> rootData;
@ -26,6 +28,10 @@ TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractIte
rootData << header;
rootItem = new Node(rootData);
m_tileZoomFactor = TileZoom100;
m_indexDisplay = true;
m_fileDisplay = true;
}
TileModel::~TileModel()
@ -89,6 +95,18 @@ QVariant TileModel::data(const QModelIndex &index, int role) const
return QVariant();
Node *item = static_cast<Node*>(index.internalPointer());
// Translate the display role to the settings-specific role.
if(role == Qt::DisplayRole)
{
if(m_indexDisplay && m_fileDisplay)
role = TileFilenameIndexRole;
else if(m_fileDisplay)
role = TileFilenameRole;
else if(m_indexDisplay)
role = TileIndexRole;
}
return item->data(index.column(), role);
}
@ -196,4 +214,37 @@ uint32 TileModel::getTileTypeSize(TileModel::TNodeTileType type)
break;
}
return 0;
}
void TileModel::selectFilenameDisplay(bool selected)
{
m_fileDisplay = selected;
}
void TileModel::selectIndexDisplay(bool selected)
{
m_indexDisplay = selected;
}
void TileModel::onZoomFactor(int level)
{
switch(level)
{
// Zoom Level 50%
case 0:
nlinfo("zooming to 50%");
m_tileZoomFactor = TileZoom50;
break;
case 1:
nlinfo("zooming to 100%");
m_tileZoomFactor = TileZoom100;
break;
case 2:
nlinfo("zooming to 200%");
m_tileZoomFactor = TileZoom200;
break;
default:
nlwarning("Invalid Time Zoom Factor passed.");
break;
};
}

View file

@ -48,7 +48,15 @@ public:
{
TilePixmapRole = Qt::UserRole+1,
TileFilenameRole = Qt::UserRole+2,
TileIndexRole = Qt::UserRole+3
TileIndexRole = Qt::UserRole+3,
TileFilenameIndexRole = Qt::UserRole+4
};
enum TTileZoomFactor
{
TileZoom50 = 0,
TileZoom100 = 1,
TileZoom200 = 2
};
@ -72,9 +80,18 @@ public:
static const char *getTileTypeName(TNodeTileType type);
static uint32 getTileTypeSize(TileModel::TNodeTileType type);
public Q_SLOTS:
void selectFilenameDisplay(bool selected);
void selectIndexDisplay(bool selected);
void onZoomFactor(int level);
private:
Node *getItem(const QModelIndex &index) const;
bool m_fileDisplay;
bool m_indexDisplay;
TTileZoomFactor m_tileZoomFactor;
//QList<TileItem*> m_tiles;
//int m_activeEditChannel;
Node *rootItem;