Warning, /graphics/peruse/src/app/qml/listcomponents/BookTileTall.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  * SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 import QtQuick 2.12
0009 import QtQuick.Controls 2.12 as QtControls
0010 import QtQuick.Layouts 1.2
0011 import org.kde.kirigami 2.14 as Kirigami
0012 
0013 /**
0014  * @brief A button to select a book to read with a nice big thumbnail.
0015  */
0016 FocusScope {
0017     id: root;
0018     property bool selected: false;
0019     property alias title: bookTitle.text;
0020     property var author: [];
0021     property string filename;
0022     property int categoryEntriesCount;
0023     property string currentPage;
0024     property string totalPages;
0025     property double progress: currentPage / totalPages;
0026     property string thumbnail;
0027     property bool pressIndicator: false;
0028     signal bookSelected(string filename, int currentPage);
0029     /// FIXME This signal will also forward the MouseEvent, but the type is not recognised, so we can't
0030     /// add it to the signature. Certainly would be nice if that were possible, though, right?
0031     /// @see https://bugreports.qt.io/browse/QTBUG-41441
0032     signal pressAndHold();
0033 
0034     enabled: visible;
0035     clip: true;
0036 
0037     Rectangle {
0038         id: stateIndicator
0039 
0040         anchors.fill: parent
0041         z: 1
0042 
0043         color: "transparent"
0044         opacity: 0.4
0045 
0046         radius: 3
0047     }
0048 
0049     MouseArea {
0050         anchors.fill: parent;
0051         onClicked: root.bookSelected(root.filename, root.currentPage);
0052         onPressAndHold: root.pressAndHold(mouse);
0053 //         onPressed: root.pressIndicator ? pressIndicatorAnimation.start():0;
0054 //         onReleased: {pressIndicatorAnimation.stop(); pressIndicator.width = 0;pressIndicator.height = 0;}
0055 
0056         TextMetrics {
0057             id: bookTitleSize
0058             font: bookTitle.font
0059             text: bookTitle.text
0060         }
0061 
0062         ColumnLayout {
0063             spacing: 0;
0064             anchors {
0065                 fill: parent;
0066                 margins: Kirigami.Units.largeSpacing
0067             }
0068             Item {
0069                 id: bookCover;
0070                 Layout.fillHeight: true
0071                 Layout.fillWidth: true
0072                 Layout.alignment: Qt.AlignHCenter
0073                 Rectangle {
0074                     id: tileBg;
0075                     anchors.centerIn: coverImage;
0076                     width: Math.max(coverImage.paintedWidth, Kirigami.Units.iconSizes.large) + Kirigami.Units.smallSpacing * 2;
0077                     height: Math.max(coverImage.paintedHeight, Kirigami.Units.iconSizes.large) + Kirigami.Units.smallSpacing * 2;
0078                     color: root.selected ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor;
0079                     border {
0080                         width: 2;
0081                         color: root.selected ? Kirigami.Theme.highlightedTextColor : "transparent"
0082                     }
0083                     radius: 7
0084                 }
0085                 Kirigami.Icon {
0086                     id: coverImage;
0087                     anchors {
0088                         fill: parent;
0089                         margins: Kirigami.Units.largeSpacing;
0090                     }
0091                     source: root.thumbnail === "Unknown role" ? "" : root.thumbnail;
0092                     placeholder: "application-vnd.oasis.opendocument.text";
0093                     fallback: "paint-unknown"
0094                 }
0095                 Item {
0096                     anchors {
0097                         right: tileBg.right
0098                         bottom: tileBg.bottom
0099                         rightMargin: - Kirigami.Units.largeSpacing
0100                         bottomMargin: - Kirigami.Units.largeSpacing
0101                     }
0102                     width: bookTitleSize.boundingRect.height * 2
0103                     height: width
0104                     visible: root.progress > 0
0105                     Rectangle {
0106                         anchors.fill: parent
0107                         radius: width / 2
0108                         opacity: .9
0109                         color: Kirigami.Theme.activeBackgroundColor
0110                     }
0111                     QtControls.Label {
0112                         text: i18nc("A percentage of progress", "%1%", Math.floor(100 * root.progress))
0113                         anchors.fill: parent
0114                         horizontalAlignment: Text.AlignHCenter
0115                         verticalAlignment: Text.AlignVCenter
0116                         color: Kirigami.Theme.activeTextColor
0117                     }
0118                 }
0119             }
0120 
0121             QtControls.Label {
0122                 id: bookTitle;
0123                 elide: Text.ElideMiddle;
0124                 horizontalAlignment: Text.AlignHCenter
0125                 Layout.fillWidth: true
0126                 Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
0127                 Layout.bottomMargin: Kirigami.Units.smallSpacing
0128             }
0129 
0130             QtControls.Label {
0131                 function getCombinedName(stringList) {
0132                     var combined = "";
0133                     for (var i = 0; i < stringList.length; ++i) {
0134                         if (combined.length > 0 && i == stringList.length - 1) {
0135                             combined += i18nc("The last item in a list of author names when there is more than one", ", and %1", stringList[i]);
0136                         }
0137                         else if (combined.length > 0) {
0138                             combined += i18nc("An item in a list of authors (but not the last)", ", %1", stringList[i]);
0139                         }
0140                         else {
0141                             combined += i18nc("The first author in a list of authors", "by %1", stringList[i]);
0142                         }
0143                     }
0144                     return combined;
0145                 }
0146                 elide: Text.ElideMiddle;
0147                 text: root.author.length > 0 ? getCombinedName(root.author) : i18nc("Author name used when there are no known authors for a book", "by an unknown author");
0148                 horizontalAlignment: Text.AlignHCenter
0149                 Layout.fillWidth: true
0150                 Layout.maximumHeight: bookTitleSize.boundingRect.height
0151                 Layout.minimumHeight: Layout.maximumHeight
0152                 Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
0153                 Layout.bottomMargin: Kirigami.Units.smallSpacing
0154             }
0155         }
0156     }
0157 }