Warning, /office/calligra/gemini/qml/StageDocumentPage.qml is written in an unsupported language. File is not indexed.

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2014 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  *  This program is free software; you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation; either version 2 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program; if not, write to the Free Software
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017  */
0018 
0019 import QtQuick 2.0
0020 import org.kde.kirigami 2.7 as Kirigami
0021 import "components"
0022 import org.kde.calligra 1.0 as Calligra
0023 
0024 Item {
0025     id: base;
0026     signal canvasInteractionStarted();
0027     property alias document: stageDocument;
0028     property alias textEditor: stageDocument.textEditor;
0029     property QtObject canvas: stageCanvas;
0030     property alias source: stageDocument.source;
0031     property alias navigateMode: controllerFlickable.enabled;
0032     property double toolbarOpacity: 1;
0033     Calligra.Document {
0034         id: stageDocument;
0035         onStatusChanged: {
0036             if(status == Calligra.DocumentStatus.Loading) {
0037                 baseLoadingDialog.visible = true;
0038             }
0039             else if(status == Calligra.DocumentStatus.Loaded) {
0040                 console.debug("doc and part: " + stageDocument.document + " " + stageDocument.part);
0041                 mainWindow.setDocAndPart(stageDocument.document, stageDocument.part);
0042                 baseLoadingDialog.hideMe();
0043 //                 thumbnailSize = Qt.size(Settings.theme.adjustedPixel(280), Settings.theme.adjustedPixel(360));
0044             }
0045         }
0046     }
0047     onNavigateModeChanged: {
0048         if(navigateMode === true) {
0049             // This means we've just changed back from having edited stuff.
0050             // Consequently we want to deselect all selections. Tell the canvas about that.
0051             stageCanvas.deselectEverything();
0052             toolManager.requestToolChange("InteractionTool");
0053         }
0054     }
0055     Item {
0056         anchors {
0057             top: parent.top;
0058             left: stageNavigator.right;
0059             right: parent.right;
0060             bottom: parent.bottom;
0061             topMargin: Settings.theme.adjustedPixel(86);
0062         }
0063         clip: true;
0064         Rectangle {
0065             anchors.fill: parent;
0066             color: "#4e5359";
0067         }
0068         
0069         Item {
0070             anchors.centerIn: parent;
0071             
0072             width: Math.min(stageDocument.documentSize.width, parent.width);
0073             height: Math.min(stageDocument.documentSize.height, parent.height);
0074         
0075             Calligra.View {
0076                 id: stageCanvas;
0077                 anchors.fill: parent;
0078                 document: stageDocument;
0079             }
0080 //             Calligra.PresentationCanvas {
0081 //                 id: stageCanvas;
0082 //                 
0083 //                 anchors.fill: parent;
0084 // 
0085 //                 onLoadingBegun: baseLoadingDialog.visible = true;
0086 //                 onLoadingFinished: {
0087 //                     console.debug("doc and part: " + doc() + " " + part());
0088 //                     mainWindow.setDocAndPart(doc(), part());
0089 //                     baseLoadingDialog.hideMe();
0090 //                 }
0091 //                 onCurrentSlideChanged: navigatorListView.positionViewAtIndex(currentSlide, ListView.Contain);
0092 //             }
0093 
0094             Flickable {
0095                 id: controllerFlickable;
0096                 anchors {
0097                     top: parent.top;
0098                     left: parent.left;
0099                     right: parent.right;
0100                     bottom: enabled ? parent.bottom : parent.top;
0101                 }
0102 
0103                 boundsBehavior: stageDocument.documentSize.width < base.width ? Flickable.StopAtBounds : Flickable.DragAndOvershootBounds;
0104 
0105                 Calligra.ViewController {
0106                     id: controllerItem;
0107                     objectName: "controllerItem";
0108                     view: stageCanvas;
0109                     flickable: controllerFlickable;
0110                     minimumZoomFitsWidth: true;
0111                     Calligra.LinkArea {
0112                         anchors.fill: parent;
0113                         document: stageDocument;
0114                         onClicked: console.debug("clicked somewhere without a link");
0115                         onLinkClicked: console.debug("clicked on the link: " + linkTarget);
0116                         controllerZoom: controllerItem.zoom;
0117                     }
0118                 }
0119 
0120                 PinchArea {
0121                     x: controllerFlickable.contentX;
0122                     y: controllerFlickable.contentY;
0123                     height: controllerFlickable.height;
0124                     width: controllerFlickable.width;
0125 
0126                     onPinchStarted: {
0127                         base.canvasInteractionStarted();
0128                     }
0129                     onPinchUpdated: {
0130                         var newCenter = mapToItem( controllerFlickable, pinch.center.x, pinch.center.y );
0131                         controllerItem.zoomAroundPoint(pinch.scale - pinch.previousScale, newCenter.x, newCenter.y );
0132                     }
0133                     onPinchFinished: {
0134                         controllerFlickable.returnToBounds();
0135                     }
0136 
0137                     MouseArea {
0138                         anchors.fill: parent;
0139                         onClicked: {
0140                             if(mouse.x < width / 6) {
0141                                 if(stageDocument.currentIndex === 0) {
0142                                     stageDocument.currentIndex = stageCanvas.indexCount() - 1;
0143                                 }
0144                                 else {
0145                                     stageDocument.currentIndex = stageDocument.currentIndex - 1;
0146                                 }
0147                             }
0148                             else if(mouse.x > width * 5 / 6) {
0149                                 var currentIndex = stageDocument.currentIndex;
0150                                 stageDocument.currentIndex = stageDocument.currentIndex + 1;
0151                                 if(currentIndex === stageDocument.currentIndex) {
0152                                     stageDocument.currentIndex = 0;
0153                                 }
0154                             }
0155                             base.canvasInteractionStarted();
0156                         }
0157                         onDoubleClicked: {
0158                             if(mouse.x < width / 6 || mouse.x > width * 5 / 6) {
0159                                 // don't accept double-clicks in the navigation zone
0160                                 return;
0161                             }
0162                             toolManager.requestToolChange("InteractionTool");
0163                             base.navigateMode = false;
0164                             base.canvasInteractionStarted();
0165                         }
0166                     }
0167                 }
0168             }
0169         }
0170     }
0171     Item {
0172         id: stageNavigator;
0173         anchors {
0174             top: parent.top;
0175             left: parent.left;
0176             bottom: parent.bottom;
0177         }
0178         width: Settings.theme.adjustedPixel(240);
0179         Rectangle {
0180             anchors.fill: parent;
0181             color: "#4e5359";
0182         }
0183         Rectangle {
0184             anchors {
0185                 top: parent.top;
0186                 right: parent.right;
0187                 bottom: parent.bottom;
0188             }
0189             width: 1;
0190             color: "black";
0191             opacity: 0.1;
0192         }
0193         ListView {
0194             id: navigatorListView;
0195             anchors {
0196                 fill: parent;
0197                 topMargin: Settings.theme.adjustedPixel(86);
0198             }
0199             model: Calligra.ContentsModel {
0200                     id: stageNavigatorModel;
0201                     document: stageDocument;
0202                     thumbnailSize: Qt.size(Settings.theme.adjustedPixel(104) * 2, (navigatorListView.width - Settings.theme.adjustedPixel(56)) * 2);
0203                 }
0204             delegate: Item {
0205                 height: Settings.theme.adjustedPixel(136);
0206                 width: ListView.view.width;
0207                 Rectangle {
0208                     anchors.fill: parent;
0209                     opacity: index === stageDocument.currentIndex ? 0.6 : 0;
0210                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0211                     color: "#00adf5";
0212                 }
0213                 Label {
0214                     anchors {
0215                         top: parent.top;
0216                         left: parent.left;
0217                         bottom: parent.bottom;
0218                     }
0219                     width: Settings.theme.adjustedPixel(40);
0220                     color: index === stageDocument.currentIndex ? "white" : "#c1cdd1";
0221                     text: index + 1;
0222                     horizontalAlignment: Text.AlignHCenter;
0223                     verticalAlignment: Text.AlignVCenter;
0224                 }
0225                 Calligra.ImageDataItem {
0226                     anchors {
0227                         top: parent.top;
0228                         right: parent.right;
0229                         bottom: parent.bottom;
0230                         margins: Settings.theme.adjustedPixel(16);
0231                     }
0232                     width: parent.width - Settings.theme.adjustedPixel(56);
0233                     data: model.thumbnail;
0234                 }
0235                 MouseArea {
0236                     anchors.fill: parent;
0237                     onClicked: {
0238                         stageDocument.currentIndex = index;
0239                         base.canvasInteractionStarted();
0240                     }
0241                 }
0242             }
0243         }
0244     }
0245 }