Warning, /office/calligra/components/examples/Viewer.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * Copyright (C) 2013 Arjen Hiemstra <ahiemstra@heimr.nl>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 
0023 import QtQuick 2.0
0024 import QtQuick.Controls 1.0
0025 import QtQuick.Layouts 1.0
0026 import QtQuick.Dialogs 1.0
0027 import org.kde.calligra 1.0 as Calligra
0028 
0029 ApplicationWindow {
0030     id: window;
0031     width: 1024;
0032     height: 600;
0033 
0034     title: (doc.source != "" ? doc.source + " - " : "") + "Calligra Viewer";
0035 
0036     menuBar: MenuBar {
0037         Menu {
0038             title: "File";
0039 
0040             MenuItem { action: openAction; }
0041             MenuSeparator { }
0042             MenuItem { action: quitAction; }
0043         }
0044 
0045         Menu {
0046             title: "View";
0047             MenuItem { action: zoomInAction; }
0048             MenuItem { action: zoomOutAction; }
0049         }
0050     }
0051 
0052     toolBar: ToolBar {
0053         id: toolbar;
0054 
0055         RowLayout {
0056             ToolButton { action: openAction; }
0057             ToolButton { action: zoomInAction; }
0058             ToolButton { action: zoomOutAction; }
0059         }
0060     }
0061 
0062     SplitView {
0063         id: centralWidget;
0064         anchors.fill: parent;
0065 
0066         ScrollView {
0067             ListView {
0068                 id: contents;
0069 
0070                 property int thumbnailWidth: 120;
0071                 property int thumbnailHeight: doc.documentType == Calligra.DocumentType.TextDocument ? 180 : 90;
0072 
0073                 model: Calligra.ContentsModel {
0074                     document: doc;
0075                     thumbnailSize.width: contents.thumbnailWidth;
0076                     thumbnailSize.height: contents.thumbnailHeight;
0077                 }
0078 
0079                 delegate: Rectangle {
0080                     width: ListView.view.width;
0081                     height: ListView.view.thumbnailHeight + 30;
0082                     color: doc.currentIndex == model.contentIndex ? "lightBlue" : index % 2 == 0 ? "white" : "lightGrey";
0083 
0084                     Calligra.ImageDataItem {
0085                         id: thumbnail;
0086                         anchors.top: parent.top;
0087                         anchors.horizontalCenter: parent.horizontalCenter;
0088 
0089                         width: parent.ListView.view.thumbnailWidth;
0090                         height: parent.ListView.view.thumbnailHeight;
0091 
0092                         data: model.thumbnail;
0093                     }
0094 
0095                     Label {
0096                         anchors {
0097                             bottom: parent.bottom;
0098                             left: parent.left;
0099                             right: parent.right;
0100                         }
0101 
0102                         text: model.title;
0103                         elide: Text.ElideRight;
0104                         horizontalAlignment: Text.AlignHCenter;
0105                     }
0106 
0107                     MouseArea {
0108                         anchors.fill: parent;
0109                         onClicked: doc.currentIndex = model.contentIndex;
0110                     }
0111                 }
0112             }
0113         }
0114 
0115         Item {
0116             Calligra.View {
0117                 id: v;
0118                 anchors.fill: parent;
0119                 document: doc;
0120             }
0121 
0122             ScrollView {
0123                 id: f;
0124                 anchors.fill: parent;
0125 
0126                 Calligra.ViewController {
0127                     id: controller;
0128                     view: v;
0129                     flickable: f.flickableItem;
0130                     minimumZoomFitsWidth: true;
0131                     Calligra.LinkArea {
0132                         anchors.fill: parent;
0133                         document: doc;
0134                         onClicked: console.debug("clicked somewhere without a link");
0135                         onLinkClicked: console.debug("clicked on the link: " + linkTarget);
0136                         controllerZoom: controller.zoom;
0137                     }
0138                 }
0139             }
0140         }
0141     }
0142 
0143     Calligra.Document {
0144         id: doc;
0145     }
0146 
0147     FileDialog {
0148         id: fileDialog;
0149         title: "Open a Document";
0150         nameFilters: [
0151             "OpenDocument Document (*.odt *.ods *.odp)",
0152             "Microsoft Office Document (*.doc *.docx *.xls *.xlsx *.ppt *.pptx)",
0153             "All Files (*)"
0154         ];
0155 
0156         onAccepted: doc.source = fileDialog.fileUrl;
0157     }
0158 
0159     Action {
0160         id: openAction;
0161 
0162         iconName: "document-open";
0163         text: "Open";
0164         tooltip: "Open a document.";
0165         shortcut: "Ctrl+o";
0166 
0167         onTriggered: fileDialog.open();
0168     }
0169 
0170     Action {
0171         id: quitAction;
0172 
0173         iconName: "application-exit"
0174         text: "Quit";
0175         tooltip: "Quit the application.";
0176         shortcut: "Ctrl+q";
0177 
0178         onTriggered: Qt.quit();
0179     }
0180 
0181     Action {
0182         id: zoomInAction;
0183 
0184         iconName: "zoom-in";
0185         text: "Zoom In";
0186         tooltip: "Zoom In";
0187         shortcut: "Ctrl+=";
0188 
0189         onTriggered: controller.zoomAroundPoint(0.1, v.width / 2, v.height / 2);
0190     }
0191 
0192     Action {
0193         id: zoomOutAction;
0194 
0195         iconName: "zoom-out";
0196         text: "Zoom Out";
0197         tooltip: "Zoom Out";
0198         shortcut: "Ctrl+-";
0199 
0200         onTriggered: controller.zoomAroundPoint(-0.1, v.width / 2, v.height / 2);
0201     }
0202 }