Fixed: #1163 icons show up small in table and full size in tooltip over icon cell - dblClk on cell opens filedialog for changing icon

This commit is contained in:
aquiles 2010-11-21 17:43:38 +01:00
parent 24bb6ada51
commit 7bb2f4edd4
2 changed files with 78 additions and 7 deletions

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Qt includes // Qt includes
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QSettings> #include <QSettings>
#include <QFileDialog>
// NeL includes // NeL includes
#include <nel/georges/u_form.h> #include <nel/georges/u_form.h>
@ -65,8 +66,8 @@ namespace NLQT
_ui.treeView->setItemDelegateForColumn(1, formdelegate); _ui.treeView->setItemDelegateForColumn(1, formdelegate);
//connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
// this, SLOT(doubleClicked (QModelIndex))); this, SLOT(doubleClicked (QModelIndex)));
connect(_ui.checkBoxParent, SIGNAL(toggled(bool)), connect(_ui.checkBoxParent, SIGNAL(toggled(bool)),
this, SLOT(filterRows())); this, SLOT(filterRows()));
connect(_ui.checkBoxDefaults, SIGNAL(toggled(bool)), connect(_ui.checkBoxDefaults, SIGNAL(toggled(bool)),
@ -239,26 +240,60 @@ namespace NLQT
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
{ {
if (index.column() == 1) // TODO: this is messy :( perhaps this can be done better
CGeorgesFormProxyModel * mp =
dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model());
CGeorgesFormModel *m =
dynamic_cast<CGeorgesFormModel *>(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; return;
} }
CFormItem *item = static_cast<CFormItem*>(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 value = item->data(1).toString();
QString path = CPath::lookup(value.toStdString(),false).c_str(); QString path = CPath::lookup(value.toStdString(),false).c_str();
// open eg parent files
if (!path.isEmpty() && !path.contains(".shape")) if (!path.isEmpty() && !path.contains(".shape"))
Q_EMIT changeFile(path); Q_EMIT changeFile(path);
if (path.contains(".shape")) if (path.contains(".shape"))
{ {
Modules::objView().resetScene(); Modules::objView().resetScene();
Modules::config().configRemapExtensions(); //Modules::config().configRemapExtensions();
Modules::objView().loadMesh(path.toStdString(),""); Modules::objView().loadMesh(path.toStdString(),"");
} }
int i = 0; int i = 0;
}
} }
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)

View file

@ -146,8 +146,40 @@ namespace NLQT
else if(value.contains(".tga") || value.contains(".png")) else if(value.contains(".tga") || value.contains(".png"))
{ {
QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str(); 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"); 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("<img src='%1'>").arg(path);
return imageTooltip;
}
} }
return QVariant(); return QVariant();
break; break;
@ -182,8 +214,9 @@ namespace NLQT
CFormItem *item = getItem(index); CFormItem *item = getItem(index);
bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
// TODO: ugly hack for updating icon too
if (result) if (result)
Q_EMIT dataChanged(index, index); Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent()));
return result; return result;
} }
@ -199,6 +232,9 @@ namespace NLQT
if(index.column() == 1) if(index.column() == 1)
returnValue |= Qt::ItemIsEditable; 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; return returnValue;