demos/declarative/flickr/mobile/ImageDetails.qml
changeset 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 import Qt 4.7
       
    43 import "../common" as Common
       
    44 
       
    45 Flipable {
       
    46     id: container
       
    47 
       
    48     property variant frontContainer: containerFront
       
    49     property string photoTitle: ""
       
    50     property string photoTags: ""
       
    51     property int photoWidth
       
    52     property int photoHeight
       
    53     property string photoType
       
    54     property string photoAuthor
       
    55     property string photoDate
       
    56     property string photoUrl
       
    57     property int rating: 2
       
    58     property variant prevScale: 1.0
       
    59 
       
    60     signal closed
       
    61 
       
    62     transform: Rotation {
       
    63         id: itemRotation
       
    64         origin.x: container.width / 2;
       
    65         axis.y: 1; axis.z: 0
       
    66     }
       
    67 
       
    68     front: Item {
       
    69         id: containerFront; anchors.fill: container
       
    70 
       
    71         Rectangle {
       
    72             anchors.fill: parent
       
    73             color: "black"; opacity: 0.4
       
    74         }
       
    75 
       
    76         Column {
       
    77             spacing: 10
       
    78             anchors {
       
    79                 left: parent.left; leftMargin: 20
       
    80                 right: parent.right; rightMargin: 20
       
    81                 top: parent.top; topMargin: 180
       
    82             }
       
    83             Text { font.bold: true; color: "white"; elide: Text.ElideRight; text: container.photoTitle }
       
    84             Text { color: "white"; elide: Text.ElideRight; text: "<b>Size:</b> " + container.photoWidth + 'x' + container.photoHeight }
       
    85             Text { color: "white"; elide: Text.ElideRight; text: "<b>Type:</b> " + container.photoType }
       
    86             Text { color: "white"; elide: Text.ElideRight; text: "<b>Author:</b> " + container.photoAuthor }
       
    87             Text { color: "white"; elide: Text.ElideRight; text: "<b>Published:</b> " + container.photoDate }
       
    88             Text { color: "white"; elide: Text.ElideRight; text: container.photoTags == "" ? "" : "<b>Tags:</b> " }
       
    89             Text { color: "white"; elide: Text.ElideRight; text: container.photoTags }
       
    90         }
       
    91     }
       
    92 
       
    93     back: Item {
       
    94         anchors.fill: container
       
    95 
       
    96         Rectangle { anchors.fill: parent; color: "black"; opacity: 0.4 }
       
    97 
       
    98         Common.Progress {
       
    99             anchors.centerIn: parent; width: 200; height: 18
       
   100             progress: bigImage.progress; visible: bigImage.status != Image.Ready
       
   101         }
       
   102 
       
   103         Flickable {
       
   104             id: flickable; anchors.fill: parent; clip: true
       
   105             contentWidth: imageContainer.width; contentHeight: imageContainer.height
       
   106 
       
   107             Item {
       
   108                 id: imageContainer
       
   109                 width: Math.max(bigImage.width * bigImage.scale, flickable.width);
       
   110                 height: Math.max(bigImage.height * bigImage.scale, flickable.height);
       
   111 
       
   112                 Image {
       
   113                     id: bigImage; source: container.photoUrl; scale: slider.value
       
   114                     anchors.centerIn: parent; smooth: !flickable.movingVertically
       
   115                     onStatusChanged : {
       
   116                         // Default scale shows the entire image.
       
   117                         if (status == Image.Ready && width != 0) {
       
   118                             slider.minimum = Math.min(flickable.width / width, flickable.height / height);
       
   119                             prevScale = Math.min(slider.minimum, 1);
       
   120                             slider.value = prevScale;
       
   121                         }
       
   122                     }
       
   123                 }
       
   124             }
       
   125         }
       
   126 
       
   127         Text {
       
   128             text: "Image Unavailable"
       
   129             visible: bigImage.status == Image.Error
       
   130             anchors.centerIn: parent; color: "white"; font.bold: true
       
   131         }
       
   132 
       
   133         Common.Slider {
       
   134             id: slider; visible: { bigImage.status == Image.Ready && maximum > minimum }
       
   135             anchors {
       
   136                 bottom: parent.bottom; bottomMargin: 65
       
   137                 left: parent.left; leftMargin: 25
       
   138                 right: parent.right; rightMargin: 25
       
   139             }
       
   140             onValueChanged: {
       
   141                 if (bigImage.width * value > flickable.width) {
       
   142                     var xoff = (flickable.width/2 + flickable.contentX) * value / prevScale;
       
   143                     flickable.contentX = xoff - flickable.width/2;
       
   144                 }
       
   145                 if (bigImage.height * value > flickable.height) {
       
   146                     var yoff = (flickable.height/2 + flickable.contentY) * value / prevScale;
       
   147                     flickable.contentY = yoff - flickable.height/2;
       
   148                 }
       
   149                 prevScale = value;
       
   150             }
       
   151         }
       
   152     }
       
   153 
       
   154     states: State {
       
   155         name: "Back"
       
   156         PropertyChanges { target: itemRotation; angle: 180 }
       
   157     }
       
   158 
       
   159     transitions: Transition {
       
   160         SequentialAnimation {
       
   161             PropertyAction { target: bigImage; property: "smooth"; value: false }
       
   162             NumberAnimation { easing.type: Easing.InOutQuad; properties: "angle"; duration: 500 }
       
   163             PropertyAction { target: bigImage; property: "smooth"; value: !flickable.movingVertically }
       
   164         }
       
   165     }
       
   166 }