Warning, /pim/kube/framework/qml/SelectableItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  Copyright (C) 2017 Michael Bohlender, <bohlender@kolabsys.com>
0003  *  Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
0004  *
0005  *  This program is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU General Public License as published by
0007  *  the Free Software Foundation; either version 2 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License along
0016  *  with this program; if not, write to the Free Software Foundation, Inc.,
0017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 
0020 import QtQuick 2.7
0021 import QtQuick.Controls 2.2
0022 import org.kube.framework 1.0 as Kube
0023 import QtQuick.Layouts 1.3
0024 
0025 QtObject {
0026     id: root
0027     property string text: ""
0028     property var layout: null
0029     property var visualParent: layout ? layout.parent : null
0030     onVisualParentChanged: {
0031         component.createObject(visualParent)
0032     }
0033 
0034     /**
0035      * This assumes a layout filled with labels.
0036      * We iterate over all elements, extract the text, insert a linebreak after every line and a space otherwise.
0037      */
0038     function gatherText() {
0039         var gatheredText = "";
0040         var length = layout.visibleChildren.length
0041         for (var i = 0; i < length; i++) {
0042             var item = layout.visibleChildren[i]
0043 
0044             if (item && item.text) {
0045                 gatheredText += item.text;
0046             }
0047             if (layout.columns && (((i + 1) % layout.columns) == 0)) {
0048                 gatheredText += "\n";
0049             } else if (i != length - 1){
0050                 gatheredText += " ";
0051             }
0052         }
0053         // console.warn("Gathered text: ", gatheredText)
0054         return gatheredText
0055     }
0056 
0057     property var comp: Component {
0058         id: component
0059         ContextMenuOverlay {
0060             id: menu
0061             anchors.fill: visualParent
0062             Kube.TextButton {
0063                 id: button
0064                 text: qsTr("Copy")
0065                 onClicked: {
0066                     if (root.text) {
0067                         clipboard.text = root.text
0068                     } else {
0069                         clipboard.text = gatherText()
0070                     }
0071                     menu.close()
0072                 }
0073                 Kube.Clipboard {
0074                     id: clipboard
0075                 }
0076             }
0077         }
0078     }
0079 }