harbour-fernschreiber/qml/components/StickerSetOverlay.qml

171 lines
5.5 KiB
QML
Raw Normal View History

2021-02-12 01:39:56 +03:00
/*
Copyright (C) 2020-21 Sebastian J. Wolf and other contributors
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import "./messageContent"
import "../js/functions.js" as Functions
import "../js/twemoji.js" as Emoji
import "../js/debug.js" as Debug
Flickable {
id: stickerSetOverlayFlickable
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
contentHeight: stickerSetContentColumn.height
clip: true
property string stickerSetId;
property var stickerSet;
property bool setLoaded: false;
signal requestClose;
Component.onCompleted: {
if (!stickerManager.hasStickerSet(stickerSetId)) {
tdLibWrapper.getStickerSet(stickerSetId);
} else {
stickerSet = stickerManager.getStickerSet(stickerSetId);
}
}
Connections {
target: tdLibWrapper
onStickerSetReceived: {
if (stickerSet.id === stickerSetOverlayFlickable.stickerSetId) {
stickerSetOverlayFlickable.stickerSet = stickerSet;
}
}
}
Timer {
id: stickerSetLoadedTimer
interval: 100
running: true
repeat: false
onTriggered: {
stickerSetOverlayFlickable.setLoaded = true;
}
}
Rectangle {
id: stickerSetContentBackground
color: Theme.overlayBackgroundColor
opacity: 0.7
anchors.fill: parent
MouseArea {
anchors.fill: parent
onClicked: {
stickerSetOverlayFlickable.requestClose();
}
}
}
Column {
id: stickerSetContentColumn
spacing: Theme.paddingMedium
width: parent.width
height: parent.height
Row {
id: stickerSetTitleRow
width: parent.width - ( 2 * Theme.horizontalPageMargin )
height: overlayStickerTitleText.height + ( 2 * Theme.paddingMedium )
anchors.horizontalCenter: parent.horizontalCenter
Label {
id: overlayStickerTitleText
width: parent.width - ( installSetButton.visible ? installSetButton.width : 0 ) - closeSetButton.width
text: stickerSet.title
font.pixelSize: Theme.fontSizeExtraLarge
font.weight: Font.ExtraBold
maximumLineCount: 1
truncationMode: TruncationMode.Fade
textFormat: Text.StyledText
anchors.verticalCenter: parent.verticalCenter
}
IconButton {
id: installSetButton
icon.source: "image://theme/icon-m-add"
anchors.verticalCenter: parent.verticalCenter
visible: !stickerSet.is_installed
onClicked: {
tdLibWrapper.changeStickerSet(stickerSet.id, true);
}
}
IconButton {
id: closeSetButton
icon.source: "image://theme/icon-m-clear"
anchors.verticalCenter: parent.verticalCenter
onClicked: {
stickerSetOverlayFlickable.requestClose();
}
}
}
SilicaGridView {
id: stickerSetGridView
width: parent.width - ( 2 * Theme.horizontalPageMargin )
height: parent.height - stickerSetTitleRow.height - Theme.paddingMedium
anchors.horizontalCenter: parent.horizontalCenter
cellWidth: chatPage.isLandscape ? (width / 5) : (width / 3);
cellHeight: cellWidth
visible: count > 0
clip: true
model: stickerSet.stickers
delegate: Item {
width: stickerSetGridView.cellWidth - Theme.paddingSmall
height: stickerSetGridView.cellHeight - Theme.paddingSmall
Image {
id: singleStickerImage
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : ""
anchors.fill: parent
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerSetLoadedTimer.restart();
}
}
}
Label {
font.pixelSize: Theme.fontSizeHuge
anchors.fill: parent
maximumLineCount: 1
truncationMode: TruncationMode.Fade
text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.file.local.is_downloading_completed
}
}
VerticalScrollDecorator {}
}
}
}