0.9beta
[feedingit] / src / qml / ArticleDisplay.qml
1 import Qt 4.7
2 import QtWebKit 1.0
3 import "common" as Common
4
5 Rectangle {
6     x: parent.width; /*height: parent.height;*/
7     width: parent.width;
8     height: parent.height
9     property alias zoomEnabled: slider.visible;
10     property alias value: slider.value;
11     //anchors.top: parent.top; anchors.bottom: parent.bottom;
12     color: "white";
13
14     Flickable {
15         id: flickable
16         //anchors.fill: screen;
17         height: parent.height;
18         width: parent.width;
19         contentWidth: webView.width*webView.scale; //Math.max(screen.width,webView.width*webView.scale)
20         contentHeight: Math.max(screen.height,webView.height*webView.scale)
21         //contentWidth: childrenRect.width; contentHeight: childrenRect.height
22
23         flickDeceleration: 1000;
24
25         WebView {
26             id: webView
27             url: articleDisplay.url;
28             preferredWidth: flickable.width
29             preferredHeight: flickable.height
30             //scale: 1.25;
31             transformOrigin: Item.TopLeft
32             scale: slider.value;
33             settings.defaultFontSize: 24
34         }
35     }
36
37     Common.Slider {
38         id: slider; visible: false
39         minimum: 0.2;
40         maximum: 2;
41         property real prevScale: 1
42         anchors {
43             bottom: parent.bottom; bottomMargin: 65
44             left: parent.left; leftMargin: 25
45             right: parent.right; rightMargin: 25
46         }
47         onValueChanged: {
48             if (webView.width * value > flickable.width) {
49                 var xoff = (flickable.width/2 + flickable.contentX) * value / prevScale;
50                 flickable.contentX = xoff - flickable.width/2;
51             }
52             if (webView.height * value > flickable.height) {
53                 var yoff = (flickable.height/2 + flickable.contentY) * value / prevScale;
54                 flickable.contentY = yoff - flickable.height/2;
55             }
56             prevScale = value;
57         }
58         Component.onCompleted: {value=0; value=1; }
59     }
60 }