Warning, /graphics/peruse/src/app/qml/viewers/ViewerBase.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright (C) 2015 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 * 0020 */ 0021 0022 import QtQuick 2.12 0023 import QtQuick.Controls 2.12 as QtControls 0024 import QtQuick.Layouts 1.12 as QtLayouts 0025 import org.kde.kirigami 2.13 as Kirigami 0026 0027 /** 0028 * @brief a base for holding the image browser. 0029 * 0030 * It keeps track of the comic data and deals with all sorts 0031 * of side functions like keeping track of the current page, 0032 * right to left mode and the controls. 0033 * 0034 * This is slightly different between filetypes. 0035 */ 0036 Item { 0037 id: root; 0038 signal goNextPage(); 0039 signal goPreviousPage(); 0040 signal goPage(int pageNumber); 0041 // Fired when the viewer has completed loading the file. 0042 // Success is true if this was successful, and false otherwise. 0043 signal loadingCompleted(bool success); 0044 property string file; 0045 property string title; 0046 property int currentPage: -1; 0047 property bool rtlMode: false; 0048 property int zoomMode: 0; 0049 property int pageCount; 0050 property var pagesModel; 0051 property list<QtObject> viewerActions; 0052 property Component thumbnailComponent; 0053 signal restoreCurrentPage(); 0054 0055 /** 0056 * Whether or not the viewer supports frame based navigation 0057 */ 0058 property bool hasFrames: false; 0059 signal nextFrame(); 0060 signal previousFrame(); 0061 0062 // This all looks a little silly, however, without this, we can't double-click on the 0063 // page (which is, these days, used for zooming purposes). It also works around some 0064 // minor small annoyances, like accidental swiping when the finger doesn't leave the 0065 // surface of the page when switching occurs. 0066 function startToggleControls() { 0067 controlsToggler.start(); 0068 } 0069 function abortToggleControls() { 0070 controlsToggler.stop(); 0071 } 0072 Timer { 0073 id: controlsToggler; 0074 interval: 500; 0075 running: false; 0076 repeat: false; 0077 onTriggered: { 0078 if(applicationWindow().controlsVisible === true) { 0079 applicationWindow().controlsVisible = false; 0080 } 0081 else { 0082 applicationWindow().controlsVisible = true; 0083 } 0084 } 0085 } 0086 0087 function activateExternalLink(link) { 0088 linkActivator.showLink(link); 0089 } 0090 0091 Kirigami.OverlaySheet { 0092 id: linkActivator 0093 function showLink(link) { 0094 linkActivator.link = link; 0095 open(); 0096 } 0097 showCloseButton: true 0098 header: QtLayouts.RowLayout { 0099 Kirigami.Heading { 0100 text: i18nc("Title for a dialog offering the user to open a link to some external resource", "Open External Link?") 0101 QtLayouts.Layout.fillWidth: true; 0102 elide: Text.ElideRight; 0103 } 0104 QtControls.ToolButton { 0105 icon.name: "dialog-ok"; 0106 text: i18nc("label for a button which activates an external link", "Open Link"); 0107 onClicked: { 0108 Qt.openUrlExternally(linkActivator.link); 0109 linkActivator.close(); 0110 } 0111 } 0112 } 0113 property string link 0114 QtLayouts.ColumnLayout { 0115 QtLayouts.Layout.preferredWidth: root.width * .7 0116 QtControls.Label { 0117 QtLayouts.Layout.fillWidth: true 0118 text: i18n("The link you just clicked points to somewhere outside of the book. Please check the details of the link below, to make sure that you really do want to open it, or just close this sheet.") 0119 wrapMode: Text.Wrap 0120 } 0121 QtControls.Label { 0122 id: httpOrFileLink 0123 // For the http(s) case, if we got to here, we can assume we have been given a reasonably laid out link 0124 visible: linkActivator.link.toLowerCase().startsWith("http") || linkActivator.link.toLowerCase().startsWith("file:") 0125 textFormat: Text.PlainText 0126 QtLayouts.Layout.fillWidth: true 0127 wrapMode: Text.Wrap 0128 horizontalAlignment: Text.AlignHCenter 0129 text: linkActivator.link 0130 } 0131 QtControls.Label { 0132 id: mailtoLink 0133 visible: linkActivator.link.toLowerCase().startsWith("mailto:") 0134 textFormat: Text.PlainText 0135 QtLayouts.Layout.fillWidth: true 0136 wrapMode: Text.Wrap 0137 text: { 0138 if (theThings.length > 2) { 0139 // This is a weird one, and likely means there's things like a BCC or whatnot in there, 0140 // so let's just show people the entire link 0141 return i18n("Compose an email to %1, based on the following link:\n\n%2", email, linkActivator.link); 0142 } else if (subject.length > 0 && body.length > 0) { 0143 return i18n("Compose an email for %1 with the subject \"%2\" and the following body:\n\n%3", email, subject, body); 0144 } else if (subject.length > 0) { 0145 return i18n("Compose an email for %1 with the subject \"%2\"", email, subject); 0146 } else { 0147 return i18n("Compose email for: %1", email) 0148 } 0149 } 0150 property string email: linkActivator.link.slice(0, linkActivator.link.indexOf("?") - 1) 0151 property string subject: getThingValue("subject", theThings) 0152 property string body: getThingValue("body", theThings) 0153 0154 property var theThings: linkActivator.link.slice(linkActivator.link.indexOf("?")).split("&") 0155 // Technically we could just refer to theThings directly, but this way we can use this bindingly 0156 function getThingValue(whatThing, fromWhat) { 0157 var theValue = ""; 0158 for (var i = 0; i < fromWhat.length; ++i) { 0159 if (fromWhat[i].toLowerCase().startsWith(whatThing + "=")) { 0160 theValue = fromWhat[i].slice(whatThing.length); 0161 } 0162 } 0163 return theValue; 0164 } 0165 } 0166 QtControls.Label { 0167 visible: mailtoLink.visible === false && httpOrFileLink.visible === false 0168 textFormat: Text.PlainText 0169 QtLayouts.Layout.fillWidth: true 0170 wrapMode: Text.Wrap 0171 text: linkActivator.link 0172 } 0173 } 0174 } 0175 }