From e56f07bfc531003b4d928df5e370be8a9a442d31 Mon Sep 17 00:00:00 2001 From: sfb Date: Mon, 27 Feb 2012 08:40:23 -0600 Subject: [PATCH] Changed: #1409 Removing the tile item delegate, modifying the model with custom roles for view modes. --- .../tile_editor/tile_editor_main_window.cpp | 41 +++++++++-- .../tile_editor/tile_editor_main_window.h | 9 ++- .../tile_editor/tile_editor_main_window.ui | 40 ++++++++++- .../src/plugins/tile_editor/tile_item.cpp | 49 ++++++------- .../tile_editor/tile_item_delegate.cpp | 70 +++++++++++++------ .../plugins/tile_editor/tile_item_delegate.h | 4 ++ .../src/plugins/tile_editor/tile_model.cpp | 51 ++++++++++++++ .../src/plugins/tile_editor/tile_model.h | 19 ++++- 8 files changed, 223 insertions(+), 60 deletions(-) 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 301f3564a..c367addbe 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 @@ -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 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) 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 93cde3d8f..8233d16d3 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 @@ -23,6 +23,7 @@ #include "nel/misc/sheet_id.h" #include +#include 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; }; 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 a7130bf9d..7bf82ca05 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 @@ -161,14 +161,17 @@ true + + QListView::Adjust + - QListView::Batched + QListView::SinglePass QListView::IconMode - false + true @@ -678,6 +681,9 @@ true + + true + Index @@ -689,6 +695,9 @@ true + + true + Filename @@ -744,6 +753,33 @@ Delete Image + + + true + + + Zoom 50% + + + + + true + + + true + + + Zoom 100% + + + + + true + + + Zoom 200% + + 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 04b044382..adf381dc0 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 @@ -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(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(); } 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 index f689ff83e..43751d612 100644 --- 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 @@ -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(index.data(TileModel::TilePixmapRole)); - QString headerText = qvariant_cast(index.data(TileModel::TileFilenameRole)); - QString subText = qvariant_cast(index.data(TileModel::TileIndexRole)); + QString tileFileText = qvariant_cast(index.data(TileModel::TileFilenameRole)); + QString tileIdText = qvariant_cast(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(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; + } } \ 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 index b87a17344..1b7058b48 100644 --- 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 @@ -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 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 19fa9409f..cd5c1c4ce 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 @@ -19,6 +19,8 @@ #include +#include + TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractItemModel(parent) { QVector 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(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; + }; } \ 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 aea6461b1..e9884cd61 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 @@ -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 m_tiles; //int m_activeEditChannel; Node *rootItem;