mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Show icons for objects
This commit is contained in:
parent
0fffa846b4
commit
2a3c603822
@ -29,6 +29,23 @@
|
|||||||
|
|
||||||
static CBasicLogConfigurator * logConfig;
|
static CBasicLogConfigurator * logConfig;
|
||||||
|
|
||||||
|
QJsonValue jsonFromPixmap(const QPixmap &p)
|
||||||
|
{
|
||||||
|
QBuffer buffer;
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
p.save(&buffer, "PNG");
|
||||||
|
auto const encoded = buffer.data().toBase64();
|
||||||
|
return {QLatin1String(encoded)};
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap pixmapFromJson(const QJsonValue &val)
|
||||||
|
{
|
||||||
|
auto const encoded = val.toString().toLatin1();
|
||||||
|
QPixmap p;
|
||||||
|
p.loadFromData(QByteArray::fromBase64(encoded), "PNG");
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
loadDLLClasses();
|
loadDLLClasses();
|
||||||
@ -38,8 +55,7 @@ void init()
|
|||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow)
|
||||||
objPreview(128, 128)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -333,19 +349,42 @@ void MainWindow::addGroupIntoCatalog(const std::string & groupName, bool staticO
|
|||||||
for(int templateId = 0; templateId < templates.size(); ++templateId)
|
for(int templateId = 0; templateId < templates.size(); ++templateId)
|
||||||
{
|
{
|
||||||
auto templ = templates[templateId];
|
auto templ = templates[templateId];
|
||||||
|
|
||||||
|
//selecting file
|
||||||
|
const std::string & afile = templ.editorAnimationFile.empty() ? templ.animationFile : templ.editorAnimationFile;
|
||||||
|
|
||||||
|
//creating picture
|
||||||
|
QPixmap preview(128, 128);
|
||||||
|
preview.fill(QColor(255, 255, 255));
|
||||||
|
QPainter painter(&preview);
|
||||||
|
Animation animation(afile);
|
||||||
|
animation.preload();
|
||||||
|
auto picture = animation.getImage(0);
|
||||||
|
if(picture && picture->width() && picture->height())
|
||||||
|
{
|
||||||
|
qreal xscale = qreal(128) / qreal(picture->width()), yscale = qreal(128) / qreal(picture->height());
|
||||||
|
qreal scale = std::min(xscale, yscale);
|
||||||
|
painter.scale(scale, scale);
|
||||||
|
painter.drawImage(QPoint(0, 0), *picture);
|
||||||
|
}
|
||||||
|
|
||||||
|
//add parameters
|
||||||
QJsonObject data{{"id", QJsonValue(ID)},
|
QJsonObject data{{"id", QJsonValue(ID)},
|
||||||
{"subid", QJsonValue(secondaryID)},
|
{"subid", QJsonValue(secondaryID)},
|
||||||
{"template", QJsonValue(templateId)},
|
{"template", QJsonValue(templateId)},
|
||||||
{"animationEditor", QString::fromStdString(templ.editorAnimationFile)},
|
{"animationEditor", QString::fromStdString(templ.editorAnimationFile)},
|
||||||
{"animation", QString::fromStdString(templ.animationFile)}};
|
{"animation", QString::fromStdString(templ.animationFile)},
|
||||||
|
{"preview", jsonFromPixmap(preview)}};
|
||||||
|
|
||||||
|
//do not have extra level
|
||||||
if(singleTemplate)
|
if(singleTemplate)
|
||||||
{
|
{
|
||||||
|
itemType->setIcon(QIcon(preview));
|
||||||
itemType->setData(data);
|
itemType->setData(data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto * item = new QStandardItem(QString::fromStdString(templ.stringID));
|
auto * item = new QStandardItem(QIcon(preview), QString::fromStdString(templ.stringID));
|
||||||
item->setData(data);
|
item->setData(data);
|
||||||
itemType->appendRow(item);
|
itemType->appendRow(item);
|
||||||
}
|
}
|
||||||
@ -406,7 +445,6 @@ void MainWindow::loadObjectsTree()
|
|||||||
addGroupIntoCatalog("MISC", false, Obj::CORPSE);
|
addGroupIntoCatalog("MISC", false, Obj::CORPSE);
|
||||||
addGroupIntoCatalog("MISC", false, Obj::MARLETTO_TOWER);
|
addGroupIntoCatalog("MISC", false, Obj::MARLETTO_TOWER);
|
||||||
addGroupIntoCatalog("MISC", false, Obj::DERELICT_SHIP);
|
addGroupIntoCatalog("MISC", false, Obj::DERELICT_SHIP);
|
||||||
addGroupIntoCatalog("MISC", false, Obj::DRAGON_UTOPIA);
|
|
||||||
addGroupIntoCatalog("MISC", false, Obj::FAERIE_RING);
|
addGroupIntoCatalog("MISC", false, Obj::FAERIE_RING);
|
||||||
addGroupIntoCatalog("MISC", false, Obj::FLOTSAM);
|
addGroupIntoCatalog("MISC", false, Obj::FLOTSAM);
|
||||||
addGroupIntoCatalog("MISC", false, Obj::FOUNTAIN_OF_FORTUNE);
|
addGroupIntoCatalog("MISC", false, Obj::FOUNTAIN_OF_FORTUNE);
|
||||||
@ -445,6 +483,7 @@ void MainWindow::loadObjectsTree()
|
|||||||
addGroupIntoCatalog("RESOURCES", false, Obj::TREASURE_CHEST);
|
addGroupIntoCatalog("RESOURCES", false, Obj::TREASURE_CHEST);
|
||||||
addGroupIntoCatalog("RESOURCES", false, Obj::SPELL_SCROLL);
|
addGroupIntoCatalog("RESOURCES", false, Obj::SPELL_SCROLL);
|
||||||
addGroupIntoCatalog("BANKS", false, Obj::CREATURE_BANK);
|
addGroupIntoCatalog("BANKS", false, Obj::CREATURE_BANK);
|
||||||
|
addGroupIntoCatalog("BANKS", false, Obj::DRAGON_UTOPIA);
|
||||||
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR1);
|
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR1);
|
||||||
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR2);
|
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR2);
|
||||||
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR3);
|
addGroupIntoCatalog("DWELLINGS", false, Obj::CREATURE_GENERATOR3);
|
||||||
@ -609,28 +648,17 @@ void MainWindow::on_toolErase_clicked()
|
|||||||
|
|
||||||
void MainWindow::preparePreview(const QModelIndex &index, bool createNew)
|
void MainWindow::preparePreview(const QModelIndex &index, bool createNew)
|
||||||
{
|
{
|
||||||
objPreview.fill(QColor(255, 255, 255));
|
scenePreview->clear();
|
||||||
|
|
||||||
auto data = objectsModel.itemFromIndex(objectBrowser->mapToSource(index))->data().toJsonObject();
|
auto data = objectsModel.itemFromIndex(objectBrowser->mapToSource(index))->data().toJsonObject();
|
||||||
|
|
||||||
if(!data.empty())
|
if(!data.empty())
|
||||||
{
|
{
|
||||||
auto animfile = data["animationEditor"];
|
auto preview = data["preview"];
|
||||||
if(animfile != QJsonValue::Undefined)
|
if(preview != QJsonValue::Undefined)
|
||||||
{
|
{
|
||||||
if(animfile.toString().isEmpty())
|
QPixmap objPreview = pixmapFromJson(preview);
|
||||||
animfile = data["animation"];
|
scenePreview->addPixmap(objPreview);
|
||||||
|
|
||||||
QPainter painter(&objPreview);
|
|
||||||
Animation animation(animfile.toString().toStdString());
|
|
||||||
animation.preload();
|
|
||||||
auto picture = animation.getImage(0);
|
|
||||||
if(picture && picture->width() && picture->height())
|
|
||||||
{
|
|
||||||
qreal xscale = qreal(128) / qreal(picture->width()), yscale = qreal(128) / qreal(picture->height());
|
|
||||||
qreal scale = std::min(xscale, yscale);
|
|
||||||
painter.scale(scale, scale);
|
|
||||||
painter.drawImage(QPoint(0, 0), *picture);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto objId = data["id"].toInt();
|
auto objId = data["id"].toInt();
|
||||||
auto objSubId = data["subid"].toInt();
|
auto objSubId = data["subid"].toInt();
|
||||||
@ -652,9 +680,6 @@ void MainWindow::preparePreview(const QModelIndex &index, bool createNew)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scenePreview->clear();
|
|
||||||
scenePreview->addPixmap(objPreview);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ private:
|
|||||||
QGraphicsScene * sceneMini;
|
QGraphicsScene * sceneMini;
|
||||||
QGraphicsScene * scenePreview;
|
QGraphicsScene * scenePreview;
|
||||||
QPixmap minimap;
|
QPixmap minimap;
|
||||||
QPixmap objPreview;
|
|
||||||
|
|
||||||
std::unique_ptr<CMap> map;
|
std::unique_ptr<CMap> map;
|
||||||
QString filename;
|
QString filename;
|
||||||
|
@ -274,6 +274,15 @@
|
|||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
<enum>QAbstractItemView::SelectItems</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>32</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="indentation">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
<property name="sortingEnabled">
|
<property name="sortingEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -66,22 +66,3 @@ bool ObjectBrowser::filterAcceptsRowText(int source_row, const QModelIndex &sour
|
|||||||
return (filter.isNull() || filter.isEmpty() || item->text().contains(filter, Qt::CaseInsensitive));
|
return (filter.isNull() || filter.isEmpty() || item->text().contains(filter, Qt::CaseInsensitive));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool ObjectBrowser::filterAcceptsRowItself(int source_row, const QModelIndex & source_parent) const
|
|
||||||
{
|
|
||||||
//accept if any of the parents is accepted on it's own merits
|
|
||||||
QModelIndex parent = source_parent;
|
|
||||||
while(parent.isValid())
|
|
||||||
{
|
|
||||||
if (filterAcceptsRowItself(parent.row(), parent.parent()))
|
|
||||||
return true;
|
|
||||||
parent = parent.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
//accept if any of the children is accepted on it's own merits
|
|
||||||
if (hasAcceptedChildren(source_row, source_parent))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user