/** * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved. * * This file is part of the QCAD project. * * QCAD is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QCAD is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QCAD. */ include("scripts/library.js"); include("scripts/map.js"); function WidgetFactory() { } WidgetFactory.includeBasePath = includeBasePath; /** * Creates a dialog with the given \c parent, based on the UI file * named \c uiFile in \c basePath. The dialog has a header area in * which a title and (error-)messages can be display through the * functions \c setTitle(title) and \c setText(text, error). */ WidgetFactory.createHeaderDialog = function(basePath, uiFile, parent) { var dlg = WidgetFactory.createDialog("scripts/Widgets", "Dialog.ui", parent); var header = dlg.findChild("header"); dlg.textFormat = header.text; dlg.setTitle = function(title) { var header = dlg.findChild("header"); header.text = dlg.textFormat.arg(title).arg(dlg.text); dlg.title = title; }; dlg.setText = function(text, error) { if (isNull(error)) { error = false; } var header = dlg.findChild("header"); var t = text; if (error) { t = "%1".arg(text); } header.text = dlg.textFormat.arg(dlg.title).arg(t); dlg.text = text; }; var inner = WidgetFactory.createWidget(basePath, uiFile, dlg); var w = dlg.findChild("inner"); var sizePolicy = w.sizePolicy; var layout = dlg.findChild("layout"); var i = layout.indexOf(w); layout.removeWidget(w); layout.insertWidget(i, inner); inner.sizePolicy = sizePolicy; return dlg; }; /** * Creates a widget with the given \c parent, based on the UI file * named \c uiFile in \c basePath. */ WidgetFactory.createWidget = function(basePath, uiFile, parent) { if (isNull(parent)) { parent = RMainWindowQt.getMainWindow(); } var candidates; if (!new QFileInfo(uiFile).isAbsolute()) { candidates = [ uiFile, basePath + "/" + uiFile ]; if (!uiFile.startsWith(":")) { candidates.push(":" + uiFile); } if (!basePath.startsWith(":")) { candidates.push(":" + basePath + "/" + uiFile); } } else { candidates = [ uiFile ]; } for (var i=0; i0 && c.itemData(0)!=undefined)) { hasData = true; } if (isNull(c.property("defaultValue"))) { if (hasData) { if (c.currentIndex>=0 && c.currentIndex= 0x060000) { sig.connect(signalReceiver, signalReceiver[slot]); } else { sig.connect(signalReceiver, slot); } } }; /** * Moves all child objects from sourceWidget to targetWidget (usually a toolbar). * * \return Array of actions that were added to targetWidget. */ WidgetFactory.moveChildren = function(sourceWidget, targetWidget, settingsGroup) { var ret = []; var a; // move child widgets of UI file based widget directly to // options toolbar. rendering of tool buttons greatly depends // on this (especially on macOS): var children = sourceWidget.children(); for(var i=0;i=1024) { w.maximumWidth = 75; } } if (isOfType(w, RMathLineEdit) || isOfType(w, RMathComboBox)) { WidgetFactory.initLineEditInfoTools(w); } a = targetWidget.addWidget(w); a.objectName = w.objectName + "Action"; ret.push(a); } // automatically set tool tip and icon for reset button: if (w.objectName==="Reset") { w.icon = new QIcon(WidgetFactory.includeBasePath + "/ResetToDefaults.svg"); w.toolTip = qsTr("Restore defaults"); } } return ret; }; WidgetFactory.adjustIcons = function(includeBasePath, widget) { if (isNull(widget) || !isFunction(widget.children)) { return; } var children = widget.children(); for(var i=0;i for measured value). */ WidgetFactory.initLineEdit = function(lineEdit, dimension) { lineEdit.contextMenuPolicy = Qt.CustomContextMenu; lineEdit.customContextMenuRequested.connect(function(pos) { var menu = lineEdit.createStandardContextMenu(); var subMenu = new QMenu(qsTr("Insert Symbol")); // TODO: split into submenus (math, greek, ...): var symbols = [ [0x00B0, qsTr("Degrees")], [0x00B1, qsTr("Plus/Minus")], [0x00F8, qsTr("Diameter")], [0x00F7, qsTr("Division")], [0x2248, qsTr("Almost Equal")], [0x2220, qsTr("Angle")], [0x2312, qsTr("Arc")], [0x2243, qsTr("Asymptotically Equal")], //[0xE100, qsTr("Boundary Line")], [0x2104, qsTr("Center Line")], [0x0394, qsTr("Delta")], [0x0278, qsTr("Electrical Phase")], //[0xE101, qsTr("Flow Line")], [0x2261, qsTr("Identity")], //[0xE200, qsTr("Initial Length")], //[0xE102, qsTr("Monument Line")], [0x00D7, qsTr("Multiplication")], [0x2260, qsTr("Not Equal")], [0x2126, qsTr("Ohm")], [0x03A9, qsTr("Omega")], [0x03C9, qsTr("omega")], [0x03A6, qsTr("Phi")], [0x0278, qsTr("phi")], [0x03C6, qsTr("Alt phi")], [0x03C0, qsTr("Pi")], [0x214A, qsTr("Property Line")], [0x2082, qsTr("Subscript 2")], [0x221A, qsTr("Square Root")], [0x25FB, qsTr("Square")], [0x00B2, qsTr("Squared")], [0x00B3, qsTr("Cubed")], ["\\SA^B;", qsTr("Stacked text"), "\\\\SA^B;"] ]; if (dimension===true) { symbols.unshift([]); symbols.unshift(["<>", qsTr("Measured value")]); } for (var i=0; i