mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 21:11:39 +00:00
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:
parent
24bb6ada51
commit
7bb2f4edd4
2 changed files with 78 additions and 7 deletions
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// Qt includes
|
||||
#include <QtGui/QWidget>
|
||||
#include <QSettings>
|
||||
#include <QFileDialog>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/georges/u_form.h>
|
||||
|
@ -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,27 +240,61 @@ 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<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;
|
||||
}
|
||||
|
||||
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 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)
|
||||
{
|
||||
|
|
|
@ -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("<img src='%1'>").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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue