From 7bb2f4edd497f3c98496c1a261f52d2a9b938432 Mon Sep 17 00:00:00 2001 From: aquiles Date: Sun, 21 Nov 2010 17:43:38 +0100 Subject: [PATCH] Fixed: #1163 icons show up small in table and full size in tooltip over icon cell - dblClk on cell opens filedialog for changing icon --- .../src/georges_treeview_dialog.cpp | 47 ++++++++++++++++--- .../src/georgesform_model.cpp | 38 ++++++++++++++- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp index 2ab35f92d..5c6289a43 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . // Qt includes #include #include +#include // NeL includes #include @@ -65,8 +66,8 @@ namespace NLQT _ui.treeView->setItemDelegateForColumn(1, formdelegate); - //connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), - // this, SLOT(doubleClicked (QModelIndex))); + connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), + this, SLOT(doubleClicked (QModelIndex))); connect(_ui.checkBoxParent, SIGNAL(toggled(bool)), this, SLOT(filterRows())); connect(_ui.checkBoxDefaults, SIGNAL(toggled(bool)), @@ -239,26 +240,60 @@ namespace NLQT void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) { - if (index.column() == 1) + // TODO: this is messy :( perhaps this can be done better + CGeorgesFormProxyModel * mp = + dynamic_cast(_ui.treeView->model()); + CGeorgesFormModel *m = + dynamic_cast(mp->sourceModel()); + QModelIndex in = mp->mapToSource(index); + + // col containing additional stuff like icons + if (index.column() == 2) { - //QTreeView::doubleClicked(index); + QModelIndex in2 = m->index(in.row(),in.column()-1,in.parent()); + CFormItem *item = m->getItem(in2); + QString value = item->data(1).toString(); + + QString path = CPath::lookup(value.toStdString(),false).c_str(); + + if(value.contains(".tga") || value.contains(".png")) + { + QString file = QFileDialog::getOpenFileName( + this, + "Select a new image", + path, + "Images (*.png *.tga)" + ); + QFileInfo info = QFileInfo(file); + + // TODO? + // right way would be another delegate but im too lazy :) + // so for now i just call it directly + m->setData(in2, info.fileName()); + } return; } - CFormItem *item = static_cast(index.internalPointer()); + // col containing the display values + if (index.column() == 1) + { + //TODO rework this + CFormItem *item = m->getItem(in); QString value = item->data(1).toString(); QString path = CPath::lookup(value.toStdString(),false).c_str(); + // open eg parent files if (!path.isEmpty() && !path.contains(".shape")) Q_EMIT changeFile(path); if (path.contains(".shape")) { Modules::objView().resetScene(); - Modules::config().configRemapExtensions(); + //Modules::config().configRemapExtensions(); Modules::objView().loadMesh(path.toStdString(),""); } int i = 0; + } } void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp index e9a89479c..05bdc1d5e 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp @@ -146,8 +146,40 @@ namespace NLQT else if(value.contains(".tga") || value.contains(".png")) { QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); + if(path.isEmpty()) + { + path = ":/images/pqrticles.png"; + } + return QIcon(path); + } + } + return QVariant(); + break; + } + case Qt::ToolTipRole: + { + if (p_index.column() == 2) + { + QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent()); + CFormItem *item = getItem(in); + QString value = item->data(1).toString(); + + if (value.contains(".shape")) + { return QIcon(":/images/pqrticles.png"); } + else if(value.contains(".tga") || value.contains(".png")) + { + QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); + if(path.isEmpty()) + { + path = ":/images/pqrticles.png"; + } + + QString imageTooltip = QString("").arg(path); + + return imageTooltip; + } } return QVariant(); break; @@ -182,8 +214,9 @@ namespace NLQT CFormItem *item = getItem(index); bool result = item->setData(index.column(), value); + // TODO: ugly hack for updating icon too if (result) - Q_EMIT dataChanged(index, index); + Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent())); return result; } @@ -199,6 +232,9 @@ namespace NLQT if(index.column() == 1) returnValue |= Qt::ItemIsEditable; + // TODO? + // col 2 should go here too but i dont want to do another delegate + // so for now i just connected the dblClick in the dialog return returnValue;