adding support for pinning maps

This commit is contained in:
Alister
2021-12-28 11:20:53 +00:00
parent cdf814e87d
commit 8e61183cf8
3 changed files with 45 additions and 3 deletions

View File

@@ -17,6 +17,8 @@ namespace Noggit::Ui::Component
auto mapTable = parent->_project->ClientDatabase->LoadTable(table);
auto iterator = mapTable.Records();
auto pinnedMaps = std::vector<Widget::MapListData>();
auto maps = std::vector<Widget::MapListData>();
while (iterator.HasRecords())
{
auto record = iterator.Next();
@@ -30,12 +32,30 @@ namespace Noggit::Ui::Component
if (mapListData.MapTypeId < 0 || mapListData.MapTypeId > 5 || !World::IsEditableWorld(record))
continue;
auto mapListItem = new Widget::MapListItem(mapListData, parent->_continents_table);
if (mapListData.Pinned)
{
pinnedMaps.push_back(mapListData);
}
else
{
maps.push_back(mapListData);
}
}
pinnedMaps.insert(pinnedMaps.end(), maps.begin(), maps.end());
for(auto const & map : pinnedMaps)
{
auto mapListItem = new Widget::MapListItem(map, parent->_continents_table);
auto item = new QListWidgetItem(parent->_continents_table);
item->setSizeHint(mapListItem->minimumSizeHint());
item->setData(Qt::UserRole, QVariant(mapListData.MapId));
item->setData(Qt::UserRole, QVariant(map.MapId));
parent->_continents_table->setItemWidget(item, mapListItem);
}
parent->_project->ClientDatabase->UnloadTable(table);
}
};

View File

@@ -1,4 +1,5 @@
#include <noggit/ui/windows/noggitWindow/widgets/MapListItem.hpp>
#include <noggit/ui/FontAwesome.hpp>
namespace Noggit::Ui::Widget
{
@@ -75,6 +76,25 @@ namespace Noggit::Ui::Widget
project_last_edited_label->setGraphicsEffect(lastEditedEffect);
project_last_edited_label->setAutoFillBackground(true);
if(data.Pinned)
{
map_pinned_label = new QLabel("", this);
map_pinned_label->setPixmap(FontAwesomeIcon(FontAwesome::star).pixmap(QSize(16,16)));
map_pinned_label->setGeometry(150, 0, 125, 20);
map_pinned_label->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
map_pinned_label->setObjectName("project-pinned");
map_pinned_label->setStyleSheet("QLabel#project-pinned { font-size: 10px; }");
auto colour = new QGraphicsColorizeEffect(this);
colour->setColor(QColor(255,204,0));
colour->setStrength(1.0f);
map_pinned_label->setGraphicsEffect(colour);
map_pinned_label->setAutoFillBackground(true);
layout.addWidget(map_pinned_label);
}
layout.addWidget(project_version_icon);
layout.addWidget(project_name_label);
layout.addWidget(project_directory_label);
@@ -95,4 +115,4 @@ namespace Noggit::Ui::Widget
return parts.join(" ");
}
}
}

View File

@@ -17,6 +17,7 @@ namespace Noggit::Ui::Widget
int MapId;
int MapTypeId;
int ExpansionId;
bool Pinned;
};
class MapListItem : public QWidget
@@ -28,6 +29,7 @@ namespace Noggit::Ui::Widget
QLabel* project_directory_label;
QLabel* project_version_label;
QLabel* project_last_edited_label;
QLabel* map_pinned_label;
int _maxWidth;
public:
MapListItem(const MapListData& data, QWidget* parent);