Warning, /education/labplot/src/kdefrontend/welcomescreen/NewsDelegate.qml is written in an unsupported language. File is not indexed.
0001 /*************************************************************************** 0002 File : NewsDelegate.qml 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2019 Ferencz Kovacs (kferike98@gmail.com) 0006 Description : Delegate item for RssNews 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, * 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0019 * GNU General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the Free Software * 0023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0024 * Boston, MA 02110-1301 USA * 0025 * * 0026 ***************************************************************************/ 0027 0028 import QtQuick 2.6 0029 0030 Column { 0031 id: delegate 0032 width: delegate.ListView.view.width 0033 spacing: 8 0034 0035 // Returns a string representing how long ago an event occurred 0036 function timeSinceEvent(pubDate) { 0037 var result = pubDate; 0038 0039 // We need to modify the pubDate read from the RSS feed 0040 // so the JavaScript Date object can interpret it 0041 var d = pubDate.replace(',','').split(' '); 0042 if (d.length != 6) 0043 return result; 0044 0045 var date = new Date([d[0], d[2], d[1], d[3], d[4], 'GMT' + d[5]].join(' ')); 0046 0047 if (!isNaN(date.getDate())) { 0048 var age = new Date() - date; 0049 var minutes = Math.floor(Number(age) / 60000); 0050 if (minutes < 1440) { 0051 if (minutes < 2) 0052 result = qsTr("Just now"); 0053 else if (minutes < 60) 0054 result = '' + minutes + ' ' + qsTr("minutes ago") 0055 else if (minutes < 120) 0056 result = qsTr("1 hour ago"); 0057 else 0058 result = '' + Math.floor(minutes/60) + ' ' + qsTr("hours ago"); 0059 } 0060 else { 0061 result = date.toDateString(); 0062 } 0063 } 0064 return result; 0065 } 0066 0067 Rectangle { height: 8; color: "#4f4c4c"; width: delegate.width; } 0068 0069 Text { 0070 id: titleText 0071 0072 text: title 0073 width: delegate.width 0074 wrapMode: Text.WordWrap 0075 font.pixelSize: 26 0076 font.bold: true 0077 } 0078 0079 Text { 0080 id: categ 0081 0082 text: "Category: " + category 0083 width: delegate.width 0084 font.pixelSize: 12 0085 textFormat: Text.RichText 0086 font.italic: true 0087 } 0088 0089 Text { 0090 width: delegate.width 0091 font.pixelSize: 12 0092 textFormat: Text.RichText 0093 font.italic: true 0094 text: timeSinceEvent(pubDate) + " (<a href=\"" + link + "\">Link</a>)" 0095 onLinkActivated: { 0096 Qt.openUrlExternally(link) 0097 } 0098 } 0099 0100 Text { 0101 id: descriptionText 0102 0103 text: description 0104 width: parent.width 0105 wrapMode: Text.WordWrap 0106 font.pixelSize: 14 0107 textFormat: Text.StyledText 0108 horizontalAlignment: Qt.AlignLeft 0109 } 0110 }