Warning, /office/alkimia/plasma/applets/ForeignCurrencies/contents/ui/config/ConfigGeneral.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.2
0002 import QtQuick.Controls 1.3
0003 import QtQuick.Layouts 1.1
0004 import QtQuick.Dialogs 1.2
0005 import org.kde.plasma.core 2.0 as PlasmaCore
0006 
0007 Item {
0008 
0009     property string cfg_currencies
0010 
0011     ListModel {
0012         id: currenciesModel
0013         }
0014 
0015     Component.onCompleted: {
0016         var currencies = JSON.parse(plasmoid.configuration.currencies)
0017         currencies.forEach(function (line) {
0018             currenciesModel.append({
0019                 symbol: line.symbol
0020                 })
0021             })
0022         }
0023 
0024 
0025     function currenciesModelChanged() {
0026         var newCurrenciesArray = []
0027         for (var i = 0; i < currenciesModel.count; i++) {
0028             newCurrenciesArray.push({
0029                 symbol: currenciesModel.get(i).symbol
0030             })
0031         }
0032         cfg_currencies = JSON.stringify(newCurrenciesArray)
0033     }
0034 
0035 
0036     Dialog {
0037         id: addCurrencyDialog
0038         title: i18n("Add Currency Pair")
0039 
0040         width: 300
0041 
0042         standardButtons: StandardButton.Ok | StandardButton.Cancel
0043 
0044         onAccepted: {
0045             if (symbolField.text !== "") { 
0046                 console.log("symbol: " + symbolField.text);
0047                 currenciesModel.append({ symbol: symbolField.text });
0048                 currenciesModelChanged()
0049                 close()
0050                 }
0051             }
0052 
0053         TextField {
0054             id: symbolField
0055             placeholderText: i18n("Paste currency pair symbol here")
0056             width: parent.width
0057             }
0058 
0059         }
0060 
0061 
0062     ColumnLayout {
0063         anchors.left: parent.left
0064         anchors.right: parent.right
0065 
0066         Label {
0067             text: i18n("Currency Pairs")
0068             font.bold: true
0069             Layout.alignment: Qt.AlignLeft
0070             }
0071 
0072         Item { }
0073 
0074         TableView {
0075             id: currenciesTable
0076             width: parent.width
0077 
0078             TableViewColumn {
0079                 id: symbolIdCol
0080                 role: 'symbolId'
0081                 title: i18n("Symbol")
0082                 // width: parent.width * 0.6
0083 
0084                 delegate: Label {
0085                     text: styleData.value
0086                     elide: Text.ElideRight
0087                     anchors.left: parent ? parent.left : undefined
0088                     anchors.leftMargin: 5
0089                     anchors.right: parent ? parent.right : undefined
0090                     anchors.rightMargin: 5
0091                 }
0092             }
0093 
0094 
0095             TableViewColumn {
0096                 title: i18n("Action")
0097                 // width: parent.width * 0.2
0098 
0099                 delegate: Item {
0100 
0101                     GridLayout {
0102                         height: parent.height
0103                         columns: 3
0104                         rowSpacing: 0
0105 
0106                         Button {
0107                             iconName: 'go-up'
0108                             Layout.fillHeight: true
0109                             onClicked: {
0110                                 currenciesModel.move(styleData.row, styleData.row - 1, 1)
0111                                 currenciesModelChanged()
0112                             }
0113                             enabled: styleData.row > 0
0114                         }
0115 
0116                         Button {
0117                             iconName: 'go-down'
0118                             Layout.fillHeight: true
0119                             onClicked: {
0120                                 currenciesModel.move(styleData.row, styleData.row + 1, 1)
0121                                 currenciesModelChanged()
0122                             }
0123                             enabled: styleData.row < currenciesModel.count - 1
0124                         }
0125 
0126                         Button {
0127                             iconName: 'list-remove'
0128                             Layout.fillHeight: true
0129                             onClicked: {
0130                                 currenciesModel.remove(styleData.row)
0131                                 currenciesModelChanged()
0132                             }
0133                         }
0134                     }
0135                 }
0136 
0137             }
0138             model: currenciesModel
0139             Layout.preferredHeight: 150
0140             Layout.preferredWidth: parent.width
0141             Layout.columnSpan: 2
0142         }
0143 
0144         Row {
0145             Layout.columnSpan: 2
0146 
0147             Button {
0148                 iconName: 'list-add'
0149                 text: i18n("Add Currency Pair")
0150                 onClicked: {
0151                     addCurrencyDialog.open();
0152                     symbolField.text = ''
0153                     symbolField.focus = true
0154                 }
0155             }
0156 
0157         }
0158 
0159     }
0160 
0161 }