add some file
authorjakub <jakub.jaszczynski@comarch.com>
Wed, 29 Dec 2010 14:10:28 +0000 (15:10 +0100)
committerjakub <jakub.jaszczynski@comarch.com>
Wed, 29 Dec 2010 14:10:28 +0000 (15:10 +0100)
src/mdictionary/qml/FlickableWebView.qml [new file with mode: 0644]
src/mdictionary/qml/ScrollBar.qml [new file with mode: 0644]

diff --git a/src/mdictionary/qml/FlickableWebView.qml b/src/mdictionary/qml/FlickableWebView.qml
new file mode 100644 (file)
index 0000000..42818ef
--- /dev/null
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import QtWebKit 1.0
+
+Flickable {
+    id: flickable
+    width: parent.width
+    contentWidth: Math.max(parent.width,webView.width)
+    contentHeight: Math.max(parent.height,webView.height)
+    anchors.top: headerSpace.bottom
+    anchors.bottom: parent.top
+    anchors.left: parent.left
+    anchors.right: parent.right
+    pressDelay: 200
+    onWidthChanged : {
+        if (width > webView.width*webView.contentsScale && webView.contentsScale < 1.0)
+            webView.contentsScale = width / webView.width * webView.contentsScale;
+    }
+
+    property alias url: webView.url
+
+    function doZoom(variable)   { webView.doZoom(variable,1,1) }
+
+    WebView {
+        id: webView
+        transformOrigin: Item.TopLeft
+        url: flickable.url
+        smooth: false
+        focus: true
+        preferredWidth: flickable.width
+        preferredHeight: flickable.height
+        contentsScale: 1
+        pressGrabTime: 0
+
+        function doZoom(zoom,centerX,centerY)
+        {
+            var tempX = flickable.width/2 - parent.x*zoom;
+            var tempY = flickable.height/2 - parent.y*zoom;
+            if (centerX) {
+                var sc = zoom*contentsScale;
+                scaleAnim.to = sc;
+                flickVX.from = flickable.contentX
+                flickVX.to = Math.max(0,Math.min(tempX-flickable.width/2,webView.width*sc-flickable.width))
+                finalX.value = flickVX.to
+                flickVY.from = flickable.contentY
+                flickVY.to = Math.max(0,Math.min(tempY-flickable.height/2,webView.height*sc-flickable.height))
+                finalY.value = flickVY.to
+                quickZoom.start()
+            }
+        }
+
+       onContentsSizeChanged: {
+           contentsScale = Math.min(1,flickable.width / contentsSize.width)
+       }
+
+       onDoubleClick: {
+            if (!heuristicZoom(clickX,clickY,2.5)) {
+                var zf = flickable.width / contentsSize.width
+                if (zf >= contentsScale)
+                    zf = 2.0/zoomFactor // zoom in (else zooming out)
+                doZoom(zf,clickX*zf,clickY*zf)
+            }
+        }
+
+        SequentialAnimation {
+            id: quickZoom
+
+            PropertyAction {
+                target: webView
+                property: "renderingEnabled"
+                value: false
+            }
+            ParallelAnimation {
+                NumberAnimation {
+                    id: scaleAnim
+                    target: webView
+                    property: "contentsScale"
+                    easing.type: Easing.Linear
+                    duration: 200
+                }
+                NumberAnimation {
+                    id: flickVX
+                    target: flickable
+                    property: "contentX"
+                    easing.type: Easing.Linear
+                    duration: 200
+                    from: 0
+                    to: 0
+                }
+                NumberAnimation {
+                    id: flickVY
+                    target: flickable
+                    property: "contentY"
+                    easing.type: Easing.Linear
+                    duration: 200
+                    from: 0
+                    to: 0
+                }
+            }
+            PropertyAction {
+                id: finalX
+                target: flickable
+                property: "contentX"
+                value: 0
+            }
+            PropertyAction {
+                id: finalY
+                target: flickable
+                property: "contentY"
+                value: 0
+            }
+            PropertyAction {
+                target: webView
+                property: "renderingEnabled"
+                value: true
+            }
+        }
+        onZoomTo: doZoom(zoom,centerX,centerY)
+    }
+}
diff --git a/src/mdictionary/qml/ScrollBar.qml b/src/mdictionary/qml/ScrollBar.qml
new file mode 100644 (file)
index 0000000..cf216d2
--- /dev/null
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+
+Item {
+    id: container
+
+    property variant scrollArea
+    property variant orientation: Qt.Vertical
+
+    opacity: 0
+
+    function position()
+    {
+        var ny = 0;
+        if (container.orientation == Qt.Vertical)
+            ny = scrollArea.visibleArea.yPosition * container.height;
+        else
+            ny = scrollArea.visibleArea.xPosition * container.width;
+        if (ny > 2) return ny; else return 2;
+    }
+
+    function size()
+    {
+        var nh, ny;
+
+        if (container.orientation == Qt.Vertical)
+            nh = scrollArea.visibleArea.heightRatio * container.height;
+        else
+            nh = scrollArea.visibleArea.widthRatio * container.width;
+
+        if (container.orientation == Qt.Vertical)
+            ny = scrollArea.visibleArea.yPosition * container.height;
+        else
+            ny = scrollArea.visibleArea.xPosition * container.width;
+
+        if (ny > 3) {
+            var t;
+            if (container.orientation == Qt.Vertical)
+                t = Math.ceil(container.height - 3 - ny);
+            else
+                t = Math.ceil(container.width - 3 - ny);
+            if (nh > t) return t; else return nh;
+        } else return nh + ny;
+    }
+
+ //Rectangle { anchors.fill: parent; color: "Black"; opacity: 0.5 }
+
+ /*   BorderImage {
+        source: "pics/scrollbar.png"
+        border { left: 1; right: 1; top: 1; bottom: 1 }
+        x: container.orientation == Qt.Vertical ? 2 : position()
+        width: container.orientation == Qt.Vertical ? container.width - 4 : size()
+        y: container.orientation == Qt.Vertical ? position() : 2
+        height: container.orientation == Qt.Vertical ? size() : container.height - 4
+    } */
+
+    states: State {
+        name: "visible"
+        when: container.orientation == Qt.Vertical ? scrollArea.movingVertically : scrollArea.movingHorizontally
+        PropertyChanges { target: container; opacity: 1.0 }
+    }
+
+    transitions: Transition {
+        from: "visible"; to: ""
+        NumberAnimation { properties: "opacity"; duration: 600 }
+    }
+}