diff --git a/resources/qml/emoji/StickerPicker.qml b/resources/qml/emoji/StickerPicker.qml index f84fe06f..ce4d5200 100644 --- a/resources/qml/emoji/StickerPicker.qml +++ b/resources/qml/emoji/StickerPicker.qml @@ -138,6 +138,8 @@ Menu { section.delegate: sectionHeading section.labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart + spacing: Nheko.paddingSmall + ScrollHelper { flickable: parent anchors.fill: parent @@ -148,38 +150,40 @@ Menu { delegate: Row { required property var row; + spacing: Nheko.paddingSmall + Repeater { model: row - delegate: AbstractButton { - width: stickerDim - height: stickerDim - hoverEnabled: true - ToolTip.text: ":" + modelData.shortcode + ": - " + modelData.body - ToolTip.visible: hovered - // TODO: maybe add favorites at some point? - onClicked: { - console.debug("Picked " + modelData.descriptor); - stickerPopup.close(); - callback(modelData.descriptor); - } + delegate: AbstractButton { + width: stickerDim + height: stickerDim + hoverEnabled: true + ToolTip.text: ":" + modelData.shortcode + ": - " + modelData.body + ToolTip.visible: hovered + // TODO: maybe add favorites at some point? + onClicked: { + console.debug("Picked " + modelData.descriptor); + stickerPopup.close(); + callback(modelData.descriptor); + } - contentItem: Image { - height: stickerDim - width: stickerDim - source: modelData.url.replace("mxc://", "image://MxcImage/") + "?scale" - fillMode: Image.PreserveAspectFit - } + contentItem: Image { + height: stickerDim + width: stickerDim + source: modelData.url.replace("mxc://", "image://MxcImage/") + "?scale" + fillMode: Image.PreserveAspectFit + } - background: Rectangle { - anchors.fill: parent - color: hovered ? Nheko.colors.highlight : 'transparent' - radius: 5 - } + background: Rectangle { + anchors.fill: parent + color: hovered ? Nheko.colors.highlight : 'transparent' + radius: 5 + } + } + } } - } - } ScrollBar.vertical: ScrollBar { id: emojiScroll diff --git a/src/GridImagePackModel.cpp b/src/GridImagePackModel.cpp index 59bfae80..59b1725a 100644 --- a/src/GridImagePackModel.cpp +++ b/src/GridImagePackModel.cpp @@ -8,6 +8,7 @@ #include +#include "Cache.h" #include "Cache_p.h" Q_DECLARE_METATYPE(StickerImage) @@ -104,7 +105,7 @@ GridImagePackModel::data(const QModelIndex &index, int role) const const auto &pack = packs[rowToPack[index.row()]]; switch (role) { case Roles::PackName: - return pack.packname; + return nameFromPack(pack); case Roles::Row: { std::size_t offset = static_cast(index.row()) - pack.firstRow; QList imgs; @@ -135,7 +136,7 @@ GridImagePackModel::data(const QModelIndex &index, int role) const switch (role) { case Roles::PackName: - return pack.packname; + return nameFromPack(pack); case Roles::Row: { QList imgs; for (auto img = firstIndex; @@ -162,6 +163,25 @@ GridImagePackModel::data(const QModelIndex &index, int role) const return {}; } +QString +GridImagePackModel::nameFromPack(const PackDesc &pack) const +{ + if (!pack.packname.isEmpty()) { + return pack.packname; + } + + if (!pack.state_key.empty()) { + return QString::fromStdString(pack.state_key); + } + + if (!pack.room_id.empty()) { + auto info = cache::singleRoomInfo(pack.room_id); + return QString::fromStdString(info.name); + } + + return tr("Account Pack"); +} + void GridImagePackModel::setSearchString(QString key) { diff --git a/src/GridImagePackModel.h b/src/GridImagePackModel.h index 06dfe734..8da61b8e 100644 --- a/src/GridImagePackModel.h +++ b/src/GridImagePackModel.h @@ -85,4 +85,6 @@ private: trie> trie_; std::vector> currentSearchResult; std::vector rowToFirstRowEntryFromSearch; + + QString nameFromPack(const PackDesc &pack) const; };