1import QtQuick 2.12 2import "../colors.js" as Colors 3 4Rectangle { 5 id: root 6 property real uiScale: 1 7 width: 300 * uiScale 8 height: 300 * uiScale 9 color: "#00000000" 10 property bool isCurrentItem 11 property string rootDir 12 property string searchID 13 property int captureTime 14 property int importTime 15 property int lastProcessedTime 16 property int rating 17 property string filename 18 property int thumbWritten 19 20 property string __thumbPath: (Qt.platform.os == "windows" ? 'file:///' : 'file://') + rootDir + '/'+ searchID.slice(0,4) + '/' + searchID + '.jpg' 21 22 signal tooltipWanted(string text, int x, int y) 23 signal selectImage() 24 signal enqueueImage() 25 signal rate(int ratingIn) 26 27 property bool flashing: false 28 29 Rectangle { 30 id: backgroundRect 31 anchors.fill: parent 32 //When they are equal in the DB, this sometimes turned on randomly. 33 //Subtracting 1 from the lastProcessedTime makes it not. 34 color: flashing ? Colors.medOrange : (importTime < (lastProcessedTime-1)) ? "green" : "#000000" 35 opacity: isCurrentItem ? .3 : .1 36 } 37 38 Loader { 39 id: loadThumb 40 asynchronous: true 41 anchors.centerIn: parent 42 //sourceComponent: thumbImage 43 } 44 45 Component { 46 id: thumbImage 47 Image { 48 id: thumb 49 width: 290 * uiScale 50 height: 290 * uiScale 51 fillMode: Image.PreserveAspectFit 52 source: root.__thumbPath 53 sourceSize.width: 290 * uiScale 54 sourceSize.height: 290 * uiScale 55 cache: false 56 } 57 } 58 Component { 59 id: thumbPlaceholder 60 Text { 61 id: thumbMissingText 62 width: 290 * uiScale 63 height: 290 * uiScale 64 horizontalAlignment: Text.AlignHCenter 65 verticalAlignment: Text.AlignVCenter 66 text: qsTr("Image file is\nunreadable") 67 color: "white" 68 font.pixelSize: 12.0 * uiScale 69 } 70 } 71 Component.onCompleted: { 72 if (thumbWritten === -1) { 73 loadThumb.sourceComponent = thumbPlaceholder 74 } 75 else { 76 loadThumb.sourceComponent = thumbImage 77 } 78 } 79 80 ToolTip { 81 id: tooltip 82 anchors.fill: loadThumb 83 tooltipText: root.filename + '\n' + organizeModel.getDateTimeString(root.captureTime) 84 Component.onCompleted: { 85 tooltip.tooltipWanted.connect(root.tooltipWanted) 86 } 87 } 88 Rectangle { 89 id: ratingRect 90 x: 0 91 y: rating >= 0 ? 0 : 295*uiScale 92 height: 5 * uiScale 93 width: (rating >= 0) ? root.width * rating/5 : root.width 94 color: ratingArea.pressed ? "#00000000" : ((rating >= 0) ? Colors.medOrange : "red") 95 } 96 MouseArea { 97 id: imageEnqueuer 98 anchors.fill: parent 99 onClicked: root.selectImage() 100 onDoubleClicked: { 101 root.enqueueImage() 102 root.flashing = true 103 enqueueBlinker.start() 104 } 105 } 106 Timer { 107 id: enqueueBlinker 108 interval: 200 109 onTriggered: root.flashing = false 110 } 111 112 MouseArea { 113 id: ratingArea 114 enabled: root.isCurrentItem 115 hoverEnabled: true 116 x: 0 117 y: 0 118 width: 300 * uiScale 119 height: 20 * uiScale 120 onClicked: { 121 root.rate(ratingArea.mouseX > root.width/10 ? Math.ceil(ratingArea.mouseX * 5 / root.width) : 0) 122 } 123 Rectangle { 124 id: tempRatingRect 125 x: 0 126 y: 0 127 width: Math.ceil(ratingArea.mouseX * 5 / root.width) * root.width / 5 128 height: ratingArea.containsMouse ? 20 * uiScale : 0 129 color: ratingArea.mouseX > root.width/10 ? Colors.medOrange : Colors.darkGray 130 border.width: 2*uiScale 131 border.color: Colors.medOrange 132 opacity: 0.8 133 } 134 } 135 onThumbWrittenChanged: { 136 if (thumbWritten === 1) { 137 loadThumb.source = "" 138 loadThumb.sourceComponent = thumbImage 139 } 140 else if (thumbWritten === -1) { 141 loadThumb.sourceComponent = thumbPlaceholder 142 } 143 //If it's 0, then we wait for it to become 1. 144 } 145} 146