mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Small image pack editor improvements
- add missing mimetype - allow removal of images from pack - allow GIF as a format - don't divide size by 2 if the image is very small already
This commit is contained in:
parent
15bf643347
commit
374ad0a816
3 changed files with 34 additions and 1 deletions
|
@ -90,7 +90,7 @@ ApplicationWindow {
|
|||
|
||||
folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
|
||||
fileMode: FileDialog.OpenFiles
|
||||
nameFilters: [qsTr("Stickers (*.png *.webp)")]
|
||||
nameFilters: [qsTr("Stickers (*.png *.webp *.gif)")]
|
||||
onAccepted: imagePack.addStickers(files)
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,21 @@ ApplicationWindow {
|
|||
Layout.alignment: Qt.AlignRight
|
||||
}
|
||||
|
||||
MatrixText {
|
||||
text: qsTr("Remove from pack")
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Remove")
|
||||
onClicked: {
|
||||
let temp = currentImageIndex;
|
||||
currentImageIndex = -1;
|
||||
imagePack.remove(temp);
|
||||
}
|
||||
Layout.alignment: Qt.AlignRight
|
||||
}
|
||||
|
||||
|
||||
Item {
|
||||
Layout.columnSpan: 2
|
||||
Layout.fillHeight: true
|
||||
|
|
|
@ -310,11 +310,15 @@ SingleImagePackModel::addStickers(QList<QUrl> files)
|
|||
auto sz = img.size() / 2;
|
||||
if (sz.width() > 512 || sz.height() > 512) {
|
||||
sz.scale(512, 512, Qt::AspectRatioMode::KeepAspectRatio);
|
||||
} else if (img.height() < 128 && img.width() < 128) {
|
||||
sz = img.size();
|
||||
}
|
||||
|
||||
info.h = sz.height();
|
||||
info.w = sz.width();
|
||||
info.size = bytes.size();
|
||||
info.mimetype =
|
||||
QMimeDatabase().mimeTypeForFile(f.toLocalFile()).name().toStdString();
|
||||
|
||||
auto filename = f.fileName().toStdString();
|
||||
http::client()->upload(
|
||||
|
@ -334,6 +338,19 @@ SingleImagePackModel::addStickers(QList<QUrl> files)
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SingleImagePackModel::remove(int idx)
|
||||
{
|
||||
if (idx < (int)shortcodes.size() && idx >= 0) {
|
||||
beginRemoveRows(QModelIndex(), idx, idx);
|
||||
auto s = shortcodes.at(idx);
|
||||
shortcodes.erase(shortcodes.begin() + idx);
|
||||
pack.images.erase(s);
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SingleImagePackModel::addImageCb(std::string uri, std::string filename, mtx::common::ImageInfo info)
|
||||
{
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
|
||||
Q_INVOKABLE void save();
|
||||
Q_INVOKABLE void addStickers(QList<QUrl> files);
|
||||
Q_INVOKABLE void remove(int index);
|
||||
|
||||
signals:
|
||||
void globallyEnabledChanged();
|
||||
|
|
Loading…
Reference in a new issue