Warning, /office/calligra/gemini/qml/MainPage.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 "components"
0021 import "panels"
0022 import org.calligra 1.0
0023 import org.kde.calligra 1.0 as Calligra
0024 import org.kde.kirigami 2.7 as Kirigami
0025 
0026 Kirigami.Page {
0027     id: base;
0028     property string pageName: "MainPage";
0029     // Not very Kirigami-ish, but we're just going to leave the base interaction for now
0030     topPadding: 0;
0031     leftPadding: 0;
0032     rightPadding: 0;
0033     bottomPadding: 0;
0034     function openFileReal(fileName) {
0035         if(Settings.currentFileClass === WORDS_MIME_TYPE) {
0036             viewLoader.sourceComponent = wordsView;
0037         } else if(Settings.currentFileClass === STAGE_MIME_TYPE) {
0038             viewLoader.sourceComponent = stageView;
0039         } else {
0040             if(Settings.currentFile !== "") {
0041                 console.debug("BANG!");
0042             }
0043         }
0044         if(viewLoader.item) {
0045             if(fileName.indexOf("://") > 0) {
0046                 viewLoader.item.source = fileName;
0047             } else {
0048                 if(fileName[0] !== "/") {
0049                     fileName = "/" + fileName;
0050                 }
0051                 viewLoader.item.source = "file://" + fileName;
0052             }
0053         }
0054     }
0055     ToolManager {
0056         id: toolManager;
0057         onCurrentToolChanged: console.debug("Current tool is now " + currentTool.toolId());
0058     }
0059     Loader {
0060         id: viewLoader;
0061         anchors {
0062             top: toolbar.top;
0063             left: parent.left;
0064             right: parent.right;
0065             bottom: parent.bottom;
0066         }
0067     }
0068     Connections {
0069         target: viewLoader.item;
0070         // ok, so this looks weird, but we explicitly want to keep the notes
0071         // panel open unless they're interacting with the other gui bits, not
0072         // if they're moving through the document
0073         onCanvasInteractionStarted: closeToolbarMenus(notesButton);
0074     }
0075     Component { id: stageView; StageDocumentPage {} }
0076     Component { id: wordsView; WordsDocumentPage {} }
0077     function closeToolbarMenus(sender) {
0078         if(sender !== textStyleButton) { textStyleButton.checked = false; }
0079         if(sender !== imageToolsButton) { imageToolsButton.checked = false; }
0080         if(sender !== optionsButton1) { optionsButton1.checked = false; }
0081         if(sender !== notesButton) { notesButton.checked = false; }
0082         if(sender !== optionsButton2) { optionsButton2.checked = false; }
0083     }
0084     Item {
0085         id: toolbar;
0086         anchors {
0087             top: parent.top;
0088             left: parent.left;
0089             right: parent.right;
0090         }
0091         opacity: viewLoader.item ? viewLoader.item.toolbarOpacity : 1;
0092         Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0093         height: Settings.theme.adjustedPixel(86);
0094         MouseArea {
0095             anchors.fill: parent;
0096             // same logic as on canvas interaction - close menus, leave notes menu open
0097             onClicked: closeToolbarMenus(notesButton);
0098         }
0099         Rectangle {
0100             anchors.fill: parent;
0101             color: Settings.theme.color("components/toolbar/base");
0102             opacity: 0.96;
0103         }
0104         Rectangle {
0105             anchors {
0106                 left: parent.left;
0107                 right: parent.right;
0108                 bottom: parent.bottom;
0109             }
0110             height: 1;
0111             color: "black";
0112             opacity: 0.1;
0113         }
0114         Item {
0115             id: appButton;
0116             height: parent.height;
0117             width: Settings.theme.adjustedPixel(110);
0118             Rectangle {
0119                 anchors.fill: parent;
0120                 color: "#f2b200";
0121             }
0122             Image {
0123                 anchors {
0124                     left: parent.left;
0125                     verticalCenter: parent.verticalCenter;
0126                 }
0127                 height: Settings.theme.adjustedPixel(32);
0128                 width: height;
0129                 source: Settings.theme.icon("Arrow-Back-FileBrowse-1");
0130                 sourceSize.width: width > height ? height : width;
0131                 sourceSize.height: width > height ? height : width;
0132             }
0133             Image {
0134                 anchors {
0135                     right: parent.right;
0136                     rightMargin: Kirigami.Units.largeSpacing;
0137                     verticalCenter: parent.verticalCenter;
0138                 }
0139                 height: Settings.theme.adjustedPixel(86) - Kirigami.Units.largeSpacing * 2;
0140                 width: height;
0141                 source: Settings.theme.icon("Calligra-MockIcon-1");
0142                 sourceSize.width: width > height ? height : width;
0143                 sourceSize.height: width > height ? height : width;
0144             }
0145             MouseArea {
0146                 anchors.fill: parent;
0147                 onClicked: {
0148                     closeToolbarMenus();
0149                     if(viewLoader.item.canvas.document.document.isModified()) {
0150                         saveBeforeExitDialog.show();
0151                     }
0152                     else {
0153                         applicationWindow().pageStack.layers.pop();
0154                     }
0155                 }
0156             }
0157         }
0158         Row {
0159             anchors {
0160                 left: appButton.right;
0161                 leftMargin: 20;
0162                 verticalCenter: parent.verticalCenter;
0163             }
0164             height: Settings.theme.adjustedPixel(66);
0165             spacing: Settings.theme.adjustedPixel(8);
0166             CohereButton {
0167                 anchors.verticalCenter: parent.verticalCenter;
0168                 text: "SAVE";
0169                 textColor: Settings.theme.color("components/toolbar/text");
0170                 font: Settings.theme.font("toolbar");
0171                 onClicked: {
0172                     closeToolbarMenus();
0173                     viewLoader.item.canvas.document.save();
0174                 }
0175             }
0176             CohereButton {
0177                 anchors.verticalCenter: parent.verticalCenter;
0178                 text: "UNDO";
0179                 textColor: Settings.theme.color("components/toolbar/text");
0180                 font: Settings.theme.font("toolbar");
0181                 enabled: typeof(undoaction) !== "undefined" ? undoaction.enabled : false;
0182                 onClicked: {
0183                     closeToolbarMenus();
0184                     undoaction.trigger();
0185                 }
0186             }
0187             Button {
0188                 height: parent.height;
0189                 width: height * 2;
0190                 text: "REDO";
0191                 textColor: Settings.theme.color("components/toolbar/text");
0192                 font: Settings.theme.font("toolbar");
0193                 enabled: typeof(redoaction) !== "undefined" ? redoaction.enabled : false;
0194                 onClicked: {
0195                     closeToolbarMenus();
0196                     redoaction.trigger();
0197                 }
0198             }
0199             Item {
0200                 height: parent.height;
0201                 width: Settings.theme.adjustedPixel(8);
0202             }
0203             CohereButton {
0204                 anchors.verticalCenter: parent.verticalCenter;
0205                 text: "DONE"
0206                 textColor: Settings.theme.color("components/toolbar/text");
0207                 font: Settings.theme.font("toolbar");
0208                 visible: viewLoader.item ? !viewLoader.item.navigateMode : false;
0209                 onClicked: {
0210                     closeToolbarMenus();
0211                     viewLoader.item.navigateMode = true;
0212                 }
0213             }
0214         }
0215         Row {
0216             id: toolbarTextTool
0217             anchors.centerIn: parent;
0218             height: Settings.theme.adjustedPixel(54);
0219             spacing: Settings.theme.adjustedPixel(4);
0220             opacity: (toolManager.currentTool !== null && toolManager.currentTool.toolId() === "TextToolFactory_ID") ? 1 : 0;
0221             Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0222             Button {
0223                 id: textStyleButton;
0224                 image: Settings.theme.icon("SVG-Icon-TextStyle-1");
0225                 imageMargin: 2;
0226                 height: parent.height; width: height;
0227                 textColor: Settings.theme.color("components/toolbar/text");
0228                 checkable: true; checkedMargin: 0;
0229                 radius: 4;
0230                 onClicked: closeToolbarMenus(textStyleButton);
0231                 Rectangle {
0232                     anchors.horizontalCenter: parent.horizontalCenter;
0233                     anchors.top: parent.bottom;
0234                     height: Kirigami.Units.largeSpacing;
0235                     width: height;
0236                     color: "#e8e9ea";
0237                     rotation: 45;
0238                     opacity: parent.checked ? 1 : 0;
0239                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0240                 }
0241                 TextStylePanel {
0242                     id: textStylePanel;
0243                     document: viewLoader.item ? viewLoader.item.document : null;
0244                     textEditor: viewLoader.item ? viewLoader.item.textEditor : null;
0245                     zoomLevel: viewLoader.item && viewLoader.item.canvas && viewLoader.item.canvas.zoomAction ? viewLoader.item.canvas.zoomAction.effectiveZoom : 1;
0246                 }
0247             }
0248             Item { height: parent.height; width: 1; }
0249             Rectangle { color: Settings.theme.color("components/toolbar/text"); opacity: 0.3; height: parent.height; width: 1; }
0250             Item { height: parent.height; width: 1; }
0251             Label {
0252                 text: textStylePanel.cursorFont.family;
0253                 height: parent.height; width: Constants.GridWidth;
0254                 color: Settings.theme.color("components/toolbar/text");
0255                 font: Settings.theme.font("toolbar");
0256                 horizontalAlignment: Text.AlignLeft;
0257             }
0258             Label {
0259                 text: textStylePanel.cursorFont.pointSize;
0260                 height: parent.height; width: Constants.GridWidth / 2;
0261                 color: Settings.theme.color("components/toolbar/text");
0262                 font: Settings.theme.font("toolbar");
0263                 horizontalAlignment: Text.AlignRight
0264                 verticalAlignment: Text.AlignVCenter;
0265             }
0266             Item { height: parent.height; width: 1; }
0267             Rectangle { color: Settings.theme.color("components/toolbar/text"); opacity: 0.3; height: parent.height; width: 1; }
0268             Item { height: parent.height; width: 1; }
0269             Button {
0270                 image: Settings.theme.icon("SVG-Icon-Bold-1");
0271                 imageMargin: 4;
0272                 height: parent.height; width: height;
0273                 textColor: Settings.theme.color("components/toolbar/text");
0274                 radius: 4;
0275                 checkedMargin: 0;
0276                 checked: textStylePanel.cursorFont ? textStylePanel.cursorFont.bold : false;
0277                 onClicked: closeToolbarMenus();
0278             }
0279             Button {
0280                 image: Settings.theme.icon("SVG-Icon-Italic-1");
0281                 imageMargin: 4;
0282                 height: parent.height; width: height;
0283                 textColor: Settings.theme.color("components/toolbar/text");
0284                 radius: 4;
0285                 checkedMargin: 0;
0286                 checked: textStylePanel.cursorFont ? textStylePanel.cursorFont.italic : false;
0287                 onClicked: closeToolbarMenus();
0288             }
0289             Button {
0290                 image: Settings.theme.icon("SVG-Icon-Underline-1");
0291                 imageMargin: 4;
0292                 height: parent.height; width: height;
0293                 textColor: Settings.theme.color("components/toolbar/text");
0294                 radius: 4;
0295                 checkedMargin: 0;
0296                 checked: textStylePanel.cursorFont ? textStylePanel.cursorFont.underline : false;
0297                 onClicked: closeToolbarMenus();
0298             }
0299             Item { height: parent.height; width: 1; }
0300             Rectangle { color: Settings.theme.color("components/toolbar/text"); opacity: 0.3; height: parent.height; width: 1; }
0301             Item { height: parent.height; width: 1; }
0302             Button {
0303                 image: Settings.theme.icon("SVG-Icon-BulletList-1");
0304                 imageMargin: 4;
0305                 height: parent.height; width: height;
0306                 textColor: Settings.theme.color("components/toolbar/text");
0307                 onClicked: closeToolbarMenus();
0308             }
0309             Button {
0310                 image: Settings.theme.icon("SVG-Icon-TextAlignment-1");
0311                 imageMargin: 4;
0312                 height: parent.height; width: height;
0313                 textColor: Settings.theme.color("components/toolbar/text");
0314                 onClicked: closeToolbarMenus();
0315             }
0316         }
0317         Row {
0318             id: toolbarImageTool
0319             anchors.centerIn: parent;
0320             height: Settings.theme.adjustedPixel(54);
0321             spacing: Settings.theme.adjustedPixel(4);
0322             opacity: (toolManager.currentTool !== null && toolManager.currentTool.toolId() === "InteractionTool") ? 1 : 0;
0323             Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0324             Button {
0325                 image: Settings.theme.icon("SVG-Icon-Image");
0326                 imageMargin: 4;
0327                 height: parent.height; width: height;
0328                 onClicked: closeToolbarMenus();
0329             }
0330             Item { height: parent.height; width: 1; }
0331             Rectangle { color: Settings.theme.color("components/toolbar/text"); opacity: 0.3; height: parent.height; width: 1; }
0332             Item { height: parent.height; width: 1; }
0333             Button {
0334                 image: Settings.theme.icon("SVG-Icon-Pen");
0335                 imageMargin: 4;
0336                 height: parent.height; width: height;
0337                 onClicked: closeToolbarMenus();
0338             }
0339             Button {
0340                 image: Settings.theme.icon("SVG-Icon-Fill");
0341                 imageMargin: 4;
0342                 height: parent.height; width: height;
0343                 onClicked: closeToolbarMenus();
0344             }
0345             Button {
0346                 image: Settings.theme.icon("SVG-Icon-Lines");
0347                 imageMargin: 4;
0348                 height: parent.height; width: height;
0349                 onClicked: closeToolbarMenus();
0350             }
0351             Button {
0352                 image: Settings.theme.icon("SVG-Icon-Shadow");
0353                 imageMargin: 4;
0354                 height: parent.height; width: height;
0355                 onClicked: closeToolbarMenus();
0356             }
0357             Item { height: parent.height; width: 1; }
0358             Rectangle { color: Settings.theme.color("components/toolbar/text"); opacity: 0.3; height: parent.height; width: 1; }
0359             Item { height: parent.height; width: 1; }
0360             Button {
0361                 id: imageToolsButton;
0362                 height: parent.height; width: height;
0363                 image: Settings.theme.icon("SVG-Icon-ImageAdjustment-1");
0364                 imageMargin: 4;
0365                 checkable: true; checkedMargin: 0;
0366                 radius: 4;
0367                 onClicked: closeToolbarMenus(imageToolsButton);
0368                 Rectangle {
0369                     anchors.horizontalCenter: parent.horizontalCenter;
0370                     anchors.top: parent.bottom;
0371                     height: Kirigami.Units.largeSpacing;
0372                     width: height;
0373                     color: "#22282f";
0374                     rotation: 45;
0375                     opacity: parent.checked ? 0.96 : 0;
0376                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0377                 }
0378                 ImageToolsPanel { canvas: viewLoader.item && viewLoader.item.canvas ? viewLoader.item.canvas : null; }
0379             }
0380         }
0381         Row {
0382             anchors {
0383                 right: parent.right;
0384                 verticalCenter: parent.verticalCenter;
0385                 rightMargin: Settings.theme.adjustedPixel(10);
0386             }
0387             height: Settings.theme.adjustedPixel(66);
0388             spacing: Settings.theme.adjustedPixel(10);
0389             visible: notesPanel.canvas ? false : true;
0390 //             Button {
0391 //                 height: parent.height; width: height;
0392 //                 image: Settings.theme.icon("SVG-Icon-AddShape-1");
0393 //                 onClicked: closeToolbarMenus();
0394 //             }
0395 //             Button {
0396 //                 height: parent.height; width: height;
0397 //                 image: Settings.theme.icon("SVG-Icon-Animations-1");
0398 //                 onClicked: closeToolbarMenus();
0399 //             }
0400             Button {
0401                 height: parent.height; width: height;
0402                 image: Settings.theme.icon("SVG-Icon-PlayPresentation-1");
0403                 onClicked: {
0404                     applicationWindow().pageStack.layers.push(presentationDJMode);
0405                     closeToolbarMenus();
0406                     if(mainWindow.lastScreen() > 0) {
0407                         // don't do the whole song and dance with presenting unless we've got a useful
0408                         // external screen to do the presentation on. For on-device presentations, we
0409                         // need desktop controls anyway, so heuristics say - presentation in touch need
0410                         // external screen.
0411                         mainWindow.fullScreen = true;
0412                         DocumentManager.doc().setPresentationMonitor(mainWindow.lastScreen());
0413                         DocumentManager.doc().setPresenterViewEnabled(false);
0414                         mainWindow.desktopKoView.startPresentationFromBeginning();
0415                     }
0416                 }
0417                 Calligra.ContentsModel {
0418                     id: presentationModel
0419                     document: viewLoader.item ? viewLoader.item.document : null;
0420                     thumbnailSize: Qt.size(base.width, base.height);
0421                 }
0422                 Component { id: presentationDJMode; PresentationDJMode { }}//canvas: viewLoader.item ? viewLoader.item.canvas : null; } }
0423             }
0424             Button {
0425                 id: optionsButton1;
0426                 height: parent.height;
0427                 width: height;
0428                 image: Settings.theme.icon("SVG-Icon-Options-1");
0429                 checkable: true;
0430                 radius: 4;
0431                 checkedColor: "#00adf5";
0432                 checkedOpacity: 0.6;
0433                 onClicked: closeToolbarMenus(optionsButton1);
0434                 Rectangle {
0435                     anchors.horizontalCenter: parent.horizontalCenter;
0436                     anchors.top: parent.bottom;
0437                     height: Kirigami.Units.largeSpacing;
0438                     width: height;
0439                     color: "#4e5359";
0440                     rotation: 45;
0441                     opacity: parent.checked ? 0.96 : 0;
0442                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0443                 }
0444                 OptionsPanel { onInteractionStarted: closeToolbarMenus(); }
0445             }
0446         }
0447         Row {
0448             anchors {
0449                 right: parent.right;
0450                 verticalCenter: parent.verticalCenter;
0451                 rightMargin: Settings.theme.adjustedPixel(10);
0452             }
0453             height: Settings.theme.adjustedPixel(66);
0454             spacing: Settings.theme.adjustedPixel(10);
0455             visible: notesPanel.canvas ? true : false;
0456 //             Button {
0457 //                 height: parent.height; width: height;
0458 //                 image: Settings.theme.icon("SVG-Icon-AddShape-1");
0459 //                 onClicked: closeToolbarMenus();
0460 //             }
0461             Button {
0462                 id: notesButton;
0463                 height: parent.height; width: height;
0464                 image: Settings.theme.icon("SVG-Icon-AddNote-1");
0465                 checkable: true;
0466                 radius: 4;
0467                 checkedColor: "#00adf5";
0468                 checkedOpacity: 0.6;
0469                 onClicked: closeToolbarMenus(notesButton);
0470                 Rectangle {
0471                     anchors.horizontalCenter: parent.horizontalCenter;
0472                     anchors.top: parent.bottom;
0473                     height: Kirigami.Units.largeSpacing;
0474                     width: height;
0475                     color: "#e8e9ea";
0476                     rotation: 45;
0477                     opacity: parent.checked ? 1 : 0;
0478                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0479                 }
0480                 NotesPanel {
0481                     id: notesPanel;
0482                     anchors {
0483                         top: parent.bottom;
0484                         right: parent.right;
0485                         rightMargin: - (parent.width + 20);
0486                         topMargin: 4;
0487                     }
0488                     opacity: parent.checked ? 1 : 0;
0489                     canvas: viewLoader.item && viewLoader.item.canvas && viewLoader.item.canvas.notes ? viewLoader.item.canvas : null;
0490                 }
0491             }
0492             Button {
0493                 id: optionsButton2;
0494                 height: parent.height;
0495                 width: height;
0496                 image: Settings.theme.icon("SVG-Icon-Options-1");
0497                 checkable: true;
0498                 radius: 4;
0499                 checkedColor: "#00adf5";
0500                 checkedOpacity: 0.6;
0501                 onClicked: closeToolbarMenus(optionsButton2);
0502                 OptionsPanel { onInteractionStarted: closeToolbarMenus(); }
0503                 Rectangle {
0504                     anchors.horizontalCenter: parent.horizontalCenter;
0505                     anchors.top: parent.bottom;
0506                     height: Kirigami.Units.largeSpacing + 2;
0507                     width: height;
0508                     color: "#4e5359";
0509                     rotation: 45;
0510                     opacity: parent.checked ? 0.96 : 0;
0511                     Behavior on opacity { NumberAnimation { duration: Kirigami.Units.shortDuration; } }
0512                 }
0513             }
0514         }
0515     }
0516     Dialog {
0517         id: saveBeforeExitDialog;
0518         title: "Save?";
0519         message: "The document was modified. Would you like to save it before closing it?";
0520         buttons: [ "Save", "Discard", "Cancel" ]
0521         onButtonClicked: {
0522             if(button === 0) {
0523                 viewLoader.item.canvas.document.save();
0524             }
0525             else if(button === 1) {
0526                 viewLoader.item.canvas.document.setModified(false);
0527                 applicationWindow().pageStack.layers.pop();
0528             }
0529         }
0530     }
0531 }