Skip to content
Snippets Groups Projects
GridItem.qml 11.7 KiB
Newer Older
/*****************************************************************************
 * Copyright (C) 2019 VLC authors and VideoLAN
 *
 * This program 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 2 of the License, or
 * ( at your option ) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtQml.Models 2.2
import QtGraphicalEffects 1.0
import org.videolan.medialib 0.1

import "qrc:///widgets/" as Widgets
Rectangle {
    color: "transparent"
    property url image
    property string title: ""
    property string subtitle: ""
    property bool selected: false

    property alias sourceSize: cover.sourceSize
    property string infoLeft: ""
Abel Tesfaye's avatar
Abel Tesfaye committed
    property string resolution: ""
    property bool isVideo: false
    property bool isNew: false
    property double progress: 0
Abel Tesfaye's avatar
Abel Tesfaye committed
    property string channel: ""
    property real pictureWidth: isVideo ? VLCStyle.video_normal_width : VLCStyle.cover_small
    property real pictureHeight: isVideo ? VLCStyle.video_normal_height : VLCStyle.cover_small
    width: gridItem.width
    height: gridItem.height
    signal playClicked
    signal addToPlaylistClicked
    signal itemClicked(Item menuParent, int key, int modifier)
    signal itemDoubleClicked(Item menuParent, int keys, int modifier)
Abel Tesfaye's avatar
Abel Tesfaye committed
    signal contextMenuButtonClicked(Item menuParent)
    Keys.onMenuPressed: root.contextMenuButtonClicked(cover_bg)

    Accessible.role: Accessible.Cell
    Accessible.name: title

        id: gridItem
        width: childrenRect.width
        height: childrenRect.height
        MouseArea {
            id: mouseArea
            hoverEnabled: true
            onClicked: {
                if (mouse.button === Qt.RightButton)
                    contextMenuButtonClicked(cover_bg);
                else {
                    root.itemClicked(cover_bg,mouse.button, mouse.modifiers);
                }
            }
            onDoubleClicked: {
                root.itemDoubleClicked(cover_bg,mouse.buttons, mouse.modifiers)
            }
            width: childrenRect.width
            height: childrenRect.height
Abel Tesfaye's avatar
Abel Tesfaye committed
            acceptedButtons: Qt.RightButton | Qt.LeftButton
            Keys.onMenuPressed: root.contextMenuButtonClicked(cover_bg)
Abel Tesfaye's avatar
Abel Tesfaye committed
            Item {
                id: picture
                width: root.pictureWidth
                height: root.pictureHeight
Abel Tesfaye's avatar
Abel Tesfaye committed
                anchors.top: mouseArea.top
                property bool highlighted: selected || root.activeFocus
                Rectangle {
                    id: cover_bg
                    width: picture.width
                    height: picture.height


                    color: VLCStyle.colors.getBgColor(
                               selected, mouseArea.containsMouse,
                               root.activeFocus)
Abel Tesfaye's avatar
Abel Tesfaye committed
                        id: cover
                        anchors.fill: parent
                        anchors.margins: VLCStyle.margin_normal
Abel Tesfaye's avatar
Abel Tesfaye committed
                        source: image
Abel Tesfaye's avatar
Abel Tesfaye committed
                        Behavior on anchors.margins {
                            SmoothedAnimation {
                                velocity: 100
                            }
                        }
Abel Tesfaye's avatar
Abel Tesfaye committed
                            value: root.progress
                            visible: isVideo && root.progress > 0
Abel Tesfaye's avatar
Abel Tesfaye committed
                            anchors {
Abel Tesfaye's avatar
Abel Tesfaye committed
                                bottom: parent.bottom
                                left: parent.left
                                right: parent.right
                            }
                        }
Abel Tesfaye's avatar
Abel Tesfaye committed
                    }
Abel Tesfaye's avatar
Abel Tesfaye committed
                        id: resolutionLabel
                        visible: root.resolution !== ""
Abel Tesfaye's avatar
Abel Tesfaye committed
                        anchors {
Abel Tesfaye's avatar
Abel Tesfaye committed
                            top: cover.top
                            left: cover.left
Abel Tesfaye's avatar
Abel Tesfaye committed
                            topMargin: VLCStyle.margin_xxsmall
                            leftMargin: VLCStyle.margin_xxsmall
                        }
                        text: root.resolution
                    }
Abel Tesfaye's avatar
Abel Tesfaye committed
                        anchors {
Abel Tesfaye's avatar
Abel Tesfaye committed
                            top: cover.top
                            left: resolutionLabel.right
Abel Tesfaye's avatar
Abel Tesfaye committed
                            topMargin: VLCStyle.margin_xxsmall
                            leftMargin: VLCStyle.margin_xxxsmall
                        }
Abel Tesfaye's avatar
Abel Tesfaye committed
                        text: root.channel
                        color: "limegreen"
Abel Tesfaye's avatar
Abel Tesfaye committed
                    }
                    states: [
                        State {
                            name: "visiblebig"
Abel Tesfaye's avatar
Abel Tesfaye committed
                            PropertyChanges {
                                target: cover
                                anchors.margins: VLCStyle.margin_xxsmall
                            }
                            when: mouseArea.containsMouse
                        },
                        State {
                            name: "hiddenbig"
Abel Tesfaye's avatar
Abel Tesfaye committed
                            PropertyChanges {
                                target: cover
                                anchors.margins: VLCStyle.margin_xxsmall
                            }
                            when: !mouseArea.containsMouse
                                  && picture.highlighted
                        },
                        State {
                            name: "hiddensmall"
Abel Tesfaye's avatar
Abel Tesfaye committed
                            PropertyChanges {
                                target: cover
                                anchors.margins: VLCStyle.margin_xsmall
                            }
                            when: !mouseArea.containsMouse
                                  && !picture.highlighted
                        }
                    ]
Abel Tesfaye's avatar
Abel Tesfaye committed
            }
Abel Tesfaye's avatar
Abel Tesfaye committed
            Rectangle {
                id: textHolderRect
Abel Tesfaye's avatar
Abel Tesfaye committed
                width: picture.width
                height: childrenRect.height
                anchors.top: picture.bottom
                color: "transparent"
                Rectangle {
                    id: textTitleRect
                    height: childrenRect.height
                    color: "transparent"
                    clip: true
                    property bool showTooltip: false
                    anchors {
                        left: parent.left
                        right: parent.right
                        rightMargin: VLCStyle.margin_small
                        leftMargin: VLCStyle.margin_small
Abel Tesfaye's avatar
Abel Tesfaye committed
                    ToolTip {
                        visible: textTitleRect.showTooltip
                        x: (parent.width/2) - (width/2)
                        y: (parent.height/2) - (height/2)
                        text: root.title
                    }
Abel Tesfaye's avatar
Abel Tesfaye committed
                    Text {
                        id: textTitle
                        text: root.title
Abel Tesfaye's avatar
Abel Tesfaye committed
                        color: VLCStyle.colors.text
                        font.pixelSize: VLCStyle.fontSize_normal
                        property bool _needsToScroll: (textTitleRect.width < textTitle.width)

                        state: ((mouseArea.containsMouse || picture.highlighted)
Abel Tesfaye's avatar
Abel Tesfaye committed
                                && textTitle._needsToScroll) ? "HOVERED" : "RELEASED"
Abel Tesfaye's avatar
Abel Tesfaye committed
                        states: [
                            State {
                                name: "HOVERED"
                                PropertyChanges {
                                    target: textTitle
                                    x: textTitleRect.width - textTitle.width - VLCStyle.margin_small
                                }
                            },
                            State {
                                name: "RELEASED"
                                PropertyChanges {
                                    target: textTitle
                                    x: 0
Abel Tesfaye's avatar
Abel Tesfaye committed
                            }
                        ]
                        transitions: [
                            Transition {
                                from: "RELEASED"
                                to: "HOVERED"
Abel Tesfaye's avatar
Abel Tesfaye committed
                                SequentialAnimation {
                                    PauseAnimation {
                                        duration: 1000
                                    }
                                    SmoothedAnimation {
                                        property: "x"
                                        maximumEasingTime: 0
                                        velocity: 25
                                    }
                                    PauseAnimation {
                                        duration: 2000
                                    }
                                    ScriptAction {
                                        script: textTitle.state = "RELEASED"
Abel Tesfaye's avatar
Abel Tesfaye committed
                }
Abel Tesfaye's avatar
Abel Tesfaye committed
                MouseArea {
                    id: titleMouseArea
                    anchors.fill: parent
                    hoverEnabled: true
                    onClicked: textTitleRect.showTooltip = true
                    onExited: textTitleRect.showTooltip = false
                }
Abel Tesfaye's avatar
Abel Tesfaye committed

                Text {
                    id: subtitleTxt
                    anchors {
                        left: parent.left
                        right: parent.right
                        top: textTitleRect.bottom
                        rightMargin: VLCStyle.margin_small
                        leftMargin: VLCStyle.margin_small
                    }
                    text: root.subtitle
Abel Tesfaye's avatar
Abel Tesfaye committed
                    font.weight: Font.Light
                    elide: Text.ElideRight
                    font.pixelSize: VLCStyle.fontSize_small
                    color: VLCStyle.colors.lightText
                    horizontalAlignment: Qt.AlignHCenter
                RowLayout {
                    visible: isVideo
                    anchors {
Abel Tesfaye's avatar
Abel Tesfaye committed
                        top: subtitleTxt.top
                        left: parent.left
                        right: parent.right
Abel Tesfaye's avatar
Abel Tesfaye committed
                        rightMargin: VLCStyle.margin_small
                        leftMargin: VLCStyle.margin_small
                        topMargin: VLCStyle.margin_xxxsmall
                    }
                    Text {
                        Layout.alignment: Qt.AlignLeft
                        font.pixelSize: VLCStyle.fontSize_small
                        color: VLCStyle.colors.videosGridInfoLeft
                        text: infoLeft
                    }
                    Text {
                        visible: root.isNew
                        Layout.alignment: Qt.AlignRight
                        font.pixelSize: VLCStyle.fontSize_small
                        color: VLCStyle.colors.accent
                        text: "NEW"
Abel Tesfaye's avatar
Abel Tesfaye committed
                        font.bold: true