| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544 |
- /**
- * 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 = "<font color='red'>%1</font>".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; i<candidates.length; i++) {
- var candidate = candidates[i];
- var fileInfo = new QFileInfo(candidate);
- if (fileInfo.exists()) {
- uiFile = candidate;
- }
- }
- var fileInfo = new QFileInfo(uiFile);
- if (!fileInfo.exists()) {
- qWarning("WidgetFactory: File %1 does not exist".arg(uiFile));
- return undefined;
- }
- var buf = RFileCache.getBuffer(uiFile);
- if (isNull(buf)) {
- return undefined;
- }
- //buf.open(new QIODevice.OpenMode(QIODevice.ReadOnly));
- var loader = new QUiLoader();
- loader.setWorkingDirectory(fileInfo.dir());
- var formWidget = loader.load(buf, parent);
- buf.close();
- destr(loader);
- if (isNull(formWidget)) {
- qDebug("WidgetFactory.createWidget: widget is NULL");
- }
- if (RS.getSystemId()==="osx") {
- WidgetFactory.installComboBoxEventFilter(formWidget);
- }
- WidgetFactory.adjustIcons(fileInfo.absolutePath(), formWidget);
- return formWidget;
- };
- /**
- * Creates a dialog from the given UI file.
- * Overrides exec for testing dashboard mode.
- */
- WidgetFactory.createDialog = function(basePath, uiFile, parent) {
- var dialog = WidgetFactory.createWidget(basePath, uiFile, parent);
- var flags = dialog.windowFlags();
- flags = makeQtWindowFlags(flags & ~(Qt.WindowContextHelpButtonHint));
- dialog.setWindowFlags(flags);
- // a global function might be defined to do additional
- // initialization for all dialogs (e.g. for testing purposes):
- if (typeof(initDialog)!=="undefined") {
- for (var i=0; i<initDialog.length; i++) {
- initDialog[i](dialog);
- }
- }
- return dialog;
- };
- /**
- * \return Settings key for the given group / object. Usually that is
- * [group, object name]. An array with two items is returned for group / name.
- */
- WidgetFactory.getKey = function(group, obj) {
- if (isDeleted(obj)) {
- return ["", ""];
- }
- var g = group;
- if (typeof(obj.property("SettingsGroup"))!="undefined") {
- g = obj.property("SettingsGroup");
- }
- var key = [g, obj.objectName];
- // correct key:
- if (isOfType(obj, QRadioButton) || isOfType(obj, QToolButton)) {
- // correct to button group name:
- if (isFunction(obj.group) && !isNull(obj.group())) {
- key = [g, obj.group().objectName];
- }
- else {
- var parent = obj.parent();
- // correct to group box (parent) name:
- if (parent && isOfType(parent, QGroupBox)) {
- key = [g, parent.objectName];
- }
- }
- }
- return key;
- };
- WidgetFactory.getKeyString = function(group, obj) {
- var keyTuple = WidgetFactory.getKey(group, obj);
- if (keyTuple[0].length===0) {
- return keyTuple[1];
- }
- else {
- return keyTuple[0] + "/" + keyTuple[1];
- }
- };
- WidgetFactory.saveSize = function(widget) {
- if (!widget) {
- return;
- }
- var name = widget.objectName;
- if (name.length===0) {
- return;
- }
- RSettings.setValue(name + "/Width", widget.width);
- RSettings.setValue(name + "/Height", widget.height);
- };
- WidgetFactory.restoreSize = function(widget) {
- if (!widget) {
- return;
- }
- var name = widget.objectName;
- if (name.length===0) {
- return;
- }
- var w = RSettings.getIntValue(name + "/Width", widget.width);
- var h = RSettings.getIntValue(name + "/Height", widget.height);
- widget.resize(w, h);
- };
- /**
- * Saves the current state of the given \c widget and all its child widgets.
- *
- * \param group Used internally for recursive calls.
- * \param document RDocument or RObject to store settings or \c undefined to store
- * settings in RSettings (user scope, config file).
- * \param map Array to use to store settings in. Used by the testing dashboard
- * recorder only.
- */
- WidgetFactory.saveState = function(widget, group, document, map) {
- if (!widget) {
- return;
- }
- if (typeof(WidgetFactory.requiresRestart) === "undefined") {
- WidgetFactory.requiresRestart = false;
- }
- group = (isNull(group) ? widget.objectName : group);
- // Qt5: QWebView has no scriptable children method:
- if (!isFunction(widget["children"])) {
- return;
- }
- var value;
- var data;
- var children = widget.children();
- for (var i = 0; i < children.length; ++i) {
- var c = children[i];
- if (!c || isDeleted(c) || c.toString().startsWith("QVariantAnimation") ||
- c.toString().startsWith("QWidgetAction") || c.objectName==="" ||
- c.objectName==="Icon" || c.objectName==="qt_toolbar_ext_button") {
- continue;
- }
- // ignore Qt internal widgets:
- if (typeof(c.objectName)!="undefined" &&
- c.objectName==="qt_toolbar_ext_button") {
- continue;
- }
- // ignore widgets that have been saved elsewhere (e.g. plugins might
- // save widgets contents by themselves in savePreferences):
- if (typeof(c.property("Saved")) != "undefined" && c.property("Saved")===true) {
- continue;
- }
- // skip children from other groups in this widget (for options toolbar):
- if (typeof(c.property("SettingsGroup")) != "undefined" && c.property("SettingsGroup") != group) {
- if (isNull(map)) {
- continue;
- }
- }
- var key = WidgetFactory.getKeyString(group, c);
- value = undefined;
- if (isOfType(c, QLineEdit)) {
- value = c.text;
- }
- else if (isOfType(c, QPlainTextEdit)) {
- value = c.toPlainText();
- }
- else if (isOfType(c, RMathLineEdit)) {
- //value = [c.text, c.getDefaultUnit()];
- value = c.text;
- }
- else if (isOfType(c, RMathComboBox)) {
- value = c.currentText;
- }
- else if (isOfType(c, QCheckBox)) {
- value = c.checked;
- }
- else if (isOfType(c, QRadioButton) ||
- isOfType(c, QToolButton) ||
- isOfType(c, QPushButton)) {
- if (!c.group() && !c.autoExclusive) {
- if (c.checkable) {
- value = c.checked;
- }
- }
- else {
- if (c.checked) {
- // if tool button or radio button is in a group,
- // the button group or group box handles the value:
- value = c.objectName;
- }
- }
- }
- else if (isOfType(c, QComboBox) || isOfType(c, QFontComboBox)) {
- var forceSaveText = false;
- var forceSaveIndex = false;
- if (typeof(c.property("ForceSaveText")) != "undefined"
- && c.property("ForceSaveText") === true) {
- forceSaveText = true;
- }
- if (typeof(c.property("ForceSaveIndex")) != "undefined"
- && c.property("ForceSaveIndex") === true) {
- forceSaveIndex = true;
- }
- if (forceSaveIndex == true) {
- value = c.currentIndex;
- }
- else if (forceSaveText === true || isNull(c.itemData(c.currentIndex))) {
- value = c.currentText;
- } else {
- value = c.itemData(c.currentIndex);
- }
- }
- else if (isOfType(c, RColorCombo)) {
- value = c.getColor();
- }
- else if (isOfType(c, RLineweightCombo)) {
- value = c.getLineweight();
- }
- else if (isOfType(c, RLinetypeCombo)) {
- value = c.getLinetypePattern();
- }
- else if (isOfType(c, QSpinBox) || isOfType(c, QDoubleSpinBox)) {
- value = c.value;
- }
- else if (isOfType(c, QSlider)) {
- value = c.value;
- }
- else if (isOfType(c, QListWidget)) {
- var items = [];
- if (c.count != 0) {
- for ( var j = 0; j < c.count; ++j) {
- items.push(c.item(j).text());
- }
- }
- value = items;
- // save user data of current item
- data = undefined;
- if (!isNull(c.currentItem())) {
- data = c.currentItem().data(Qt.UserRole);
- }
- if (!isNull(data)) {
- var dataKey = key + ".data";
- if (document) {
- if (isObject(document)) {
- document.setCustomProperty("QCAD", dataKey, data);
- }
- else {
- document.setVariable(dataKey, data);
- }
- } else {
- RSettings.setValue(dataKey, data);
- }
- }
- }
- else if (c.toString().startsWith("RFontChooserWidget")) {
- value = c.getChosenFont();
- }
- if (isNull(value)) {
- WidgetFactory.saveState(c, group, document, map);
- continue;
- }
- // save property
- if (typeof(c.property("SaveProperty")) != "undefined") {
- var prop = c.property("SaveProperty");
- RSettings.setValue(key + "." + prop, c[prop]);
- }
- // widgets with dynamic property "RequiresRestart" trigger a
- // restart application warning after changing preferences:
- if (typeof(c.property("RequiresRestart")) != "undefined"
- && c.property("RequiresRestart") === true) {
- WidgetFactory.requiresRestart = true;
- }
- // widgets can be ignored by setting the dynamic property
- // "SaveContents" = false
- var saveContents = true;
- if (typeof(c.property("SaveContents")) != "undefined"
- && c.property("SaveContents") === false) {
- saveContents = false;
- }
- if (saveContents) {
- if (document) {
- if (isObject(document)) {
- // save key / value pair to object:
- document.setCustomProperty("QCAD", key, value);
- }
- else {
- // save key / value pair to document:
- document.setVariable(key, value);
- }
- } else if (map) {
- // save key / value pair to map:
- map.put(key, value);
- } else {
- // save key / value pair to settings (e.g. ini file):
- RSettings.setValue(key, value);
- }
- }
- }
- };
- /**
- * Restores the state of the given \c widget to a previously saved state.
- *
- * \param group Used internally for recursive calls.
- * \param signalReceiver Object that receives signals whenever a child widget
- * changes its value.
- * \param reset True: Reset values to original values as defined in
- * designer (.ui file). \see resetState
- * \param document RDocument object or RObject to restore settings from or \c undefined
- * to restore settings from RSettings (user scope, config file).
- * \param map Map object to restore settings from.
- */
- WidgetFactory.restoreState = function(widget, group, signalReceiver, reset, document, map) {
- var f, index, j, hasData;
-
- var topLevelSet = false;
- if (isNull(WidgetFactory.topLevelWidget)) {
- widget.slotSettingChanged = function() {
- if (isFunction(this.settingChangedEvent)) {
- this.settingChangedEvent();
- }
- this.setProperty("hasChanged", true);
- };
- WidgetFactory.topLevelWidget = widget;
- topLevelSet = true;
- }
- group = (isNull(group) ? widget.objectName : group);
- reset = (isNull(reset) ? false : reset);
- if (isDeleted(widget)) {
- return;
- }
- // Qt5: QWebView has no scriptable children method:
- if (!isFunction(widget.children)) {
- return;
- }
- var children = widget.children();
- for ( var i = 0; i < children.length; ++i) {
- var c = children[i];
-
- if (!c || isDeleted(c)) {
- continue;
- }
- // ignore widgets without name:
- if (isNull(c.objectName) || c.objectName==="") {
- continue;
- }
- // ignore Qt internal widgets:
- if (c.objectName==="qt_toolbar_ext_button") {
- continue;
- }
- // ignore labels, widget actions:
- if (isOfType(c, QLabel) || isOfType(c, QWidgetAction)) {
- continue;
- }
- // skip children from other groups in this widget (for options toolbar):
- // but not if used from a test [map != undefined]
- if (isNull(map) && typeof (c.property("SettingsGroup")) != "undefined" && c.property("SettingsGroup") !== group) {
- continue;
- }
- // skip ignored children (future need?):
- //if (typeof(c["Ignore"])!="undefined" && c["Ignore"]==true) {
- // continue;
- //}
- // handle widgets which have their own reset method
- var hasOwnReset = false;
- if (typeof(c.property("hasOwnReset")) != "undefined" && c.property("hasOwnReset") == true) {
- hasOwnReset = true;
- }
- if (reset && hasOwnReset) {
- if (isFunction(c.resetState)) {
- c.resetState();
- }
- continue;
- }
-
- var key = WidgetFactory.getKeyString(group, c);
- var value = undefined;
- if (reset && !isNull(c.property("defaultValue")) && (typeof(c.property("SettingsGroup"))=="undefined" || c.property("SettingsGroup")===group)) {
- value = c.property("defaultValue");
- } else {
- if (!isNull(map)) {
- value = map.get(key);
- } else {
- if (!isNull(document)) {
- if (isObject(document)) {
- value = document.getCustomProperty("QCAD", key, undefined);
- }
- else {
- value = document.getVariable(key);
- }
- }
- // document / object has no value for key, try settings for default value:
- if (isNull(document) || isNull(value)) {
- value = RSettings.getValue(key);
- }
- }
- }
- // only process children if key delivered no value:
- if (isNull(value) || isOfType(c, QGroupBox)) {
- // never process internal children of these widgets:
- if (WidgetFactory.processChildren(c)) {
- WidgetFactory.restoreState(c, group, signalReceiver, reset, document, map);
- }
- }
- // don't restore widgets that have been restored elsewhere (e.g. script
- // add-ons might load widgets contents by themselves in initPreferences):
- // [but always restore widgets if used from a test (map != undefined)]
- if (isNull(map) && !reset && c.property("Loaded")===true) {
- value = undefined;
- }
- // restore property
- if (typeof(c.property("SaveProperty")) != "undefined") {
- var prop = c.property("SaveProperty");
- var val = RSettings.getValue(key + "." + prop);
- if (!isNull(val)) {
- c[prop] = val;
- }
- }
-
- if (isOfType(c, QLabel)) {
- continue;
- }
- // qDebug("restoring: ", c.objectName);
- // qDebug(" value: ", value);
- if (isOfType(c, QPlainTextEdit)) {
- if (!reset) {
- WidgetFactory.connect(c.textChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c.textChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.toPlainText());
- }
- if (!isNull(value)) {
- c.setPlainText(value);
- }
- continue;
- }
- if (isOfType(c, RMathLineEdit)) {
- if (!reset) {
- WidgetFactory.connect(c.valueChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c.valueChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- //c.defaultValue = [c.text, c.getDefaultUnit()];
- c.setProperty("defaultValue", c.text);
- c.slotTextChanged(c.text);
- }
- if (!isNull(value)) {
- // deprecated: value and default unit:
- if (isArray(value) && value.length===2) {
- if (isNull(value[0])) {
- c.text = "";
- }
- else {
- c.text = value[0].toString();
- }
- }
- else {
- if (isString(value)) {
- c.text = value;
- }
- else {
- c.text = "%1".arg(value);
- }
- }
- }
- continue;
- }
- if (isOfType(c, RMathComboBox)) {
- if (!reset) {
- WidgetFactory.connect(c.valueChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c.valueChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- //c.defaultValue = [c.text, c.getDefaultUnit()];
- c.setProperty("defaultValue", c.currentText);
- c.slotTextChanged(c.currentText);
- }
- if (!isNull(value)) {
- if (isString(value)) {
- c.currentText = value;
- }
- else {
- c.currentText = "%1".arg(value);
- }
- }
- continue;
- }
- if (isOfType(c, QLineEdit)) {
- if (!reset) {
- WidgetFactory.connect(c.textChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c.textChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.text);
- }
- if (!isNull(value)) {
- c.text = value.toString();
- }
- continue;
- }
- if (isOfType(c, QToolButton) || isOfType(c, QPushButton)) {
- if (isNull(c.group()) && !c.autoExclusive) {
- if (c.checkable) {
- if (!reset) {
- WidgetFactory.connect(c.toggled, signalReceiver, c.objectName);
- WidgetFactory.connect(c.toggled, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.checked);
- }
- if (!isNull(value)) {
- c.checked = (value === true || value === "true");
- }
- }
- else {
- if (!reset) {
- WidgetFactory.connect(c.clicked, signalReceiver, c.objectName, false);
- }
- }
- }
- else {
- if (!reset) {
- WidgetFactory.connect(c.toggled, signalReceiver, c.objectName);
- }
- }
- continue;
- }
- if (isOfType(c, QCheckBox)) {
- if (!reset) {
- WidgetFactory.connect(c.toggled, signalReceiver, c.objectName);
- WidgetFactory.connect(c.stateChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.checked);
- if (!isNull(signalReceiver)) {
- f = signalReceiver["slot"+c.objectName+"Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, c.checked);
- }
- }
- }
- if (!isNull(value)) {
- c.checked = (value === true || value == "true");
- }
- continue;
- }
- if (isOfType(c, QRadioButton)) {
- if (!c.group() && !c.autoExclusive) {
- WidgetFactory.connect(c.toggled, signalReceiver, c.objectName);
- WidgetFactory.connect(c.toggled, WidgetFactory.topLevelWidget, "Setting");
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.checked);
- }
- if (!isNull(value)) {
- c.checked = (value === true || value == "true");
- }
- }
- else {
- WidgetFactory.connect(c.toggled, signalReceiver, c.objectName);
- WidgetFactory.connect(c.toggled, WidgetFactory.topLevelWidget, "Setting");
- if (value==="true") {
- c.checked = true;
- }
- else {
- c.checked = (c.objectName == value);
- }
- }
- continue;
- }
- if (isOfType(c, QButtonGroup)) {
- if (!reset) {
- WidgetFactory.connect(c["buttonClicked(QAbstractButton*)"], signalReceiver, c.objectName);
- WidgetFactory.connect(c["buttonClicked(QAbstractButton*)"], WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- var button = c.checkedButton();
- if (!isNull(button) && !isNull(button.objectName)) {
- c.setProperty("defaultValue", button.objectName);
- if (!isNull(signalReceiver)) {
- f = signalReceiver["slot"+c.objectName+"Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, button);
- }
- }
- }
- }
- if (!isNull(value)) {
- var buttons = c.buttons();
- for (var k=0; k<buttons.length; k++) {
- if (buttons[k].objectName==value) {
- buttons[k].checked = true;
- if (!isNull(signalReceiver)) {
- f = signalReceiver["slot"+c.objectName+"Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, buttons[k]);
- }
- }
- break;
- }
- }
- }
- }
- if (isOfType(c, QComboBox) && c.editable) {
- if (!reset) {
- WidgetFactory.connect(c.editTextChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c.editTextChanged, WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.currentText);
- if (!isNull(signalReceiver)) {
- f = signalReceiver["slot" + c.objectName + "Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, c.currentText);
- }
- }
- }
- if (!isNull(value)) {
- index = c.findText(value);
- if (index !== -1) {
- c.currentIndex = index;
- continue;
- }
- c.setEditText(value);
- }
- continue;
- }
- if ((isOfType(c, QComboBox) && !c.editable) || isOfType(c, QFontComboBox)) {
- if (!reset) {
- WidgetFactory.connect(c['currentIndexChanged(int)'], signalReceiver, c.objectName);
- WidgetFactory.connect(c['currentIndexChanged(int)'], WidgetFactory.topLevelWidget, "Setting");
- }
- hasData = false;
- if (c.itemData(c.currentIndex)!=undefined || (c.count>0 && c.itemData(0)!=undefined)) {
- hasData = true;
- }
- if (isNull(c.property("defaultValue"))) {
- if (hasData) {
- if (c.currentIndex>=0 && c.currentIndex<c.count) {
- c.setProperty("defaultValue", c.itemData(c.currentIndex));
- }
- } else {
- c.setProperty("defaultValue", c.currentText);
- }
- if (signalReceiver!=undefined) {
- f = signalReceiver["slot" + c.objectName + "Changed"];
- if (typeof(f)=="function") {
- f.call(signalReceiver, c.currentIndex);
- }
- }
- }
- var forceSaveText = false;
- var forceSaveIndex = false;
- if (typeof(c.property("ForceSaveText")) != "undefined"
- && c.property("ForceSaveText") == true) {
- forceSaveText = true;
- }
- if (typeof(c.property("ForceSaveIndex")) != "undefined"
- && c.property("ForceSaveIndex") == true) {
- forceSaveIndex = true;
- }
- if (!isNull(value)) {
- index = -1;
- if (forceSaveIndex == true) {
- index = parseInt(value);
- }
- else if (forceSaveText == false && hasData) {
- index = c.findData(value);
- } else {
- if (isString(value)) {
- index = c.findText(value);
- }
- }
- if (index !== -1) {
- c.currentIndex = index;
- continue;
- }
- }
- continue;
- }
- if (isOfType(c, RColorCombo)) {
- if (!reset) {
- WidgetFactory.connect(c.editTextChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c["currentIndexChanged(int)"], WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.getColor());
- }
- if (!isNull(value)) {
- // color name given:
- if (isString(value)) {
- c.setColor(new RColor(value));
- }
- // color object given:
- else {
- if (isOfType(value, RColor)) {
- c.setColor(value);
- }
- else {
- qWarning("value is not of type RColor:", value);
- }
- }
- }
- continue;
- }
- if (isOfType(c, RLineweightCombo)) {
- if (!reset) {
- WidgetFactory.connect(c.editTextChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c["currentIndexChanged(int)"], WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.getLineweight());
- }
- if (!isNull(value)) {
- if (isString(value)) {
- value = parseInt(value, 10);
- }
- c.setLineweight(value);
- }
- continue;
- }
- if (isOfType(c, RLinetypeCombo)) {
- if (!reset) {
- WidgetFactory.connect(c.editTextChanged, signalReceiver, c.objectName);
- WidgetFactory.connect(c["currentIndexChanged(int)"], WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.getLinetypePattern());
- }
- if (!isNull(value)) {
- c.setLinetypePattern(value);
- }
- continue;
- }
- if (isOfType(c, QSpinBox) || isOfType(c, QDoubleSpinBox)) {
- if (!reset) {
- if (isOfType(c, QSpinBox)) {
- WidgetFactory.connect(c["valueChanged(int)"], signalReceiver, c.objectName);
- WidgetFactory.connect(c["valueChanged(int)"], WidgetFactory.topLevelWidget, "Setting");
- }
- else {
- WidgetFactory.connect(c["valueChanged(double)"], signalReceiver, c.objectName);
- WidgetFactory.connect(c["valueChanged(double)"], WidgetFactory.topLevelWidget, "Setting");
- }
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.value);
- if (signalReceiver!=undefined) {
- f = signalReceiver["slot" + c.objectName + "Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, c.value);
- }
- }
- }
- if (!isNull(value)) {
- if (isOfType(c, QSpinBox)) {
- c.value = parseInt(value);
- }
- else {
- c.value = parseFloat(value);
- }
- }
- continue;
- }
- if (isOfType(c, QSlider)) {
- if (!reset) {
- WidgetFactory.connect(c["valueChanged(int)"], signalReceiver, c.objectName);
- WidgetFactory.connect(c["valueChanged(int)"], WidgetFactory.topLevelWidget, "Setting");
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.value);
- if (signalReceiver!=undefined) {
- f = signalReceiver["slot" + c.objectName + "Changed"];
- if (isFunction(f)) {
- f.call(signalReceiver, c.value);
- }
- }
- }
- if (!isNull(value)) {
- c.value = value;
- }
- continue;
- }
- if (isOfType(c, QListWidget)) {
- // the SaveContents property is set to false
- // if the list contents should not be saved to
- // the configuration file or document:
- var saveContents = true;
- if (typeof(c.property("SaveContents")) != "undefined"
- && c.property("SaveContents") == false) {
- saveContents = false;
- }
- if (saveContents) {
- if (isNull(c.property("defaultValue"))) {
- var items = [];
- for (j = 0; j < c.count; ++j) {
- items.push(c.item(j).text());
- }
- c.setProperty("defaultValue", items);
- }
- if (!isNull(value)) {
- c.addItems(value);
- }
- } else {
- if (isNull(c.property("defaultValue")) && !isNull(c.currentItem())) {
- c.setProperty("defaultValue", c.currentItem().data(Qt.UserRole));
- }
- if (!isNull(value)) {
- for (j=0; j<c.count; ++j) {
- if (c.item(j).data(Qt.UserRole) == value) {
- c.currentRow = j;
- break;
- }
- }
- }
- }
- if (reset===false) {
- // restore user data of selected row
- hasData = false;
- if (!isNull(c.item(0)) && !isNull(c.item(0).data(Qt.UserRole))) {
- hasData = true;
- }
- if (hasData) {
- var data;
- var dataKey = key + ".data";
- if (!isNull(document)) {
- if (isObject(document)) {
- data = document.getCustomProperty("QCAD", key, undefined);
- }
- else {
- data = document.getVariable(dataKey);
- }
- }
- // document has no value for key,
- // try settings for default value
- if (isNull(document) || isNull(data)) {
- data = RSettings.getValue(dataKey);
- }
- if (!isNull(data)) {
- for (j = 0; j < c.count; ++j) {
- if (c.item(j).data(Qt.UserRole) == data.toString()) {
- c.currentRow = j;
- break;
- }
- }
- }
- }
- }
- if (!reset) {
- WidgetFactory.connect(c.itemChanged, signalReceiver, c.objectName);
- c.itemSelectionChanged.connect(WidgetFactory.topLevelWidget, WidgetFactory.topLevelWidget.slotSettingChanged);
- c.model().rowsInserted.connect(WidgetFactory.topLevelWidget, WidgetFactory.topLevelWidget.slotSettingChanged);
- }
-
- continue;
- }
- if (isOfType(c, RFontChooserWidget)) {
- if (!reset) {
- WidgetFactory.connect(c.valueChanged, signalReceiver, c.objectName);
- c.valueChanged.connect(WidgetFactory.topLevelWidget, WidgetFactory.topLevelWidget.slotSettingChanged);
- }
- if (isNull(c.property("defaultValue"))) {
- c.setProperty("defaultValue", c.getChosenFont());
- }
- if (!isNull(value)) {
- if (isString(value)) {
- var fnt = new QFont();
- fnt.fromString(value);
- value = fnt;
- }
- c.setChosenFont(value);
- }
- continue;
- }
- }
-
- if (topLevelSet) {
- WidgetFactory.topLevelWidget = undefined;
- }
- };
- /**
- * Resets values to original values as defined in designer (.ui file).
- */
- WidgetFactory.resetState = function(widget, group) {
- WidgetFactory.restoreState(widget, group, undefined, true);
- };
- WidgetFactory.processChildren = function(c) {
- if (isOfType(c, QSpinBox) ||
- isOfType(c, QDoubleSpinBox) ||
- isOfType(c, QComboBox) ||
- isOfType(c, QFontComboBox) ||
- isOfType(c, QPlainTextEdit) ||
- isOfType(c, RMathLineEdit) ||
- isOfType(c, RMathComboBox)) {
- return false;
- }
- return true;
- };
- /**
- * \internal
- */
- WidgetFactory.connect = function(sig, signalReceiver, objectName, isValue) {
- if (isNull(signalReceiver)) {
- return;
- }
- // connect signal to given function:
- // obsolete?
- if (isFunction(signalReceiver)) {
- sig.connect(signalReceiver);
- return;
- }
- // connect signal to automatically named slot of receiver object:
- var slot;
- if (isNull(isValue) || isValue===true) {
- slot = "slot" + objectName + "Changed";
- }
- else {
- slot = "slot" + objectName;
- }
- //if (eval("signalReceiver." + slot) != undefined) {
- if (!isNull(signalReceiver[slot])) {
- if (RSettings.getQtVersion() >= 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<children.length;++i) {
- var w = children[i];
- if (isNull(w)) {
- continue;
- }
- w.setProperty("SettingsGroup", settingsGroup);
- // add separator:
- if (isSeparator(w)) {
- a = targetWidget.addSeparator();
- a.objectName = w.objectName + "Action";
- ret.push(a);
- }
- // reparent required for non-widgets (e.g. QButtonGroup):
- else if (!isFunction(w.show)) {
- // these children would crash QCAD on exit if they are reparented:
- if (!w.toString().startsWith("QBoxLayout") &&
- !w.toString().startsWith("QFormInternal") &&
- !w.toString().startsWith("QVariantAnimation")) {
- w.setParent(targetWidget);
- }
- }
- // add widgets:
- else {
- if (isOfType(w, QLabel) || isOfType(w, QCheckBox)) {
- // prevent styles from overriding fixed size (e.g. for icon labels):
- if (w.sizePolicy.horizontalPolicy()!==QSizePolicy.Fixed) {
- w.styleSheet = "margin-left: 5px; margin-right: 5px;" + w.styleSheet;
- }
- }
- // add line edit or math edit with maximum width:
- if (isOfType(w, QLineEdit) || isOfType(w, RMathLineEdit) || isOfType(w, RMathComboBox)) {
- if (w.maximumWidth>=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<children.length;++i) {
- var w=children[i];
- // adjust icon for theme / dark mode:
- if (isOfType(w, QToolButton)) {
- var iconFile = autoIconPath(includeBasePath + "/" + w.objectName + ".svg");
- if (!isNull(iconFile)) {
- w.icon = new QIcon(iconFile);
- }
- }
- else {
- WidgetFactory.adjustIcons(includeBasePath, w);
- }
- }
- };
- WidgetFactory.initLineEditInfoTools = function(mathLineEdit) {
- };
- /**
- * Adds an "insert symbol" menu entry to the context menu of the given
- * line edit.
- *
- * \param lineEdit QLineEdit object
- * \param dimension bool Add symbols that are only appropriate for
- * dimension labels (<> 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<symbols.length; ++i) {
- var symbol = symbols[i];
- if (symbol.length===0) {
- subMenu.addSeparator();
- continue;
- }
- var symbolCode = symbol[0];
- var symbolCodeStr;
- var symbolSelf;
- if (isNumber(symbolCode)) {
- symbolCodeStr = symbolCode.toString(16);
- while (symbolCodeStr.length<4) {
- symbolCodeStr = "0" + symbolCodeStr;
- }
- symbolCodeStr = ", \\U+" + symbolCodeStr;
- symbolSelf = String.fromCharCode(symbolCode);
- }
- else {
- symbolCodeStr = "";
- symbolSelf = symbolCode;
- }
- var symbolText = symbol[1];
- var insertion = String.fromCharCode(symbol[0]);
- if (symbol.length===3) {
- insertion = symbol[2];
- }
- var action = subMenu.addAction(symbolSelf + "\t(" + symbolText + symbolCodeStr + ")");
- eval("action.triggered.connect(function() { lineEdit.setFocus(Qt.OtherFocusReason); lineEdit.insert(\"" + insertion + "\"); });");
- }
- var actions = menu.actions();
- menu.removeAction(actions[actions.length-1]);
- menu.removeAction(actions[actions.length-2]);
- var separatorAction = menu.insertSeparator(actions[0]);
- menu.insertMenu(separatorAction, subMenu);
- menu.exec(QCursor.pos());
- if (!isDeleted(menu)) {
- destr(menu);
- }
- });
- };
- WidgetFactory.initTextBrowser = function(textBrowser, slot) {
- textBrowser.openLinks = false;
- textBrowser.anchorClicked.connect(slot);
- };
- //WidgetFactory.initWebView = function(webView, linkHandler, slot) {
- // var webPage = webView.page();
- // webPage.linkDelegationPolicy = QWebPage.DelegateExternalLinks;
- // webPage.linkClicked.connect(linkHandler, slot);
- // var webSettings = webView.settings();
- // webSettings.setFontFamily(QWebSettings.StandardFont, EAction.getMainWindow().font.family());
- // if (RS.getSystemId()==="osx") {
- // webSettings.setFontSize(QWebSettings.DefaultFontSize, EAction.getMainWindow().font.pointSize());
- // }
- // if (!RSettings.isQt(5)) {
- // // make web view transparent:
- // var palette = webView.palette;
- // palette.setBrush(QPalette.Base, new QColor(0,0,0,0));
- // webPage.palette = palette;
- // webView.setAttribute(Qt.WA_OpaquePaintEvent, false);
- // }
- //};
- WidgetFactory.initLayerCombo = function(comboBox, doc, clear) {
- var i;
- if (isNull(doc)) {
- return;
- }
- if (isNull(clear)) {
- clear = true;
- }
- var existingLayerNames = [];
- if (clear) {
- comboBox.clear();
- }
- else {
- for (i=0; i<comboBox.count; i++) {
- var t = comboBox.itemText(i);
- existingLayerNames.push(t);
- }
- }
- comboBox.iconSize = new QSize(16, 10);
- var names = doc.getLayerNames();
- //names = RS.sortAlphanumerical(names);
- names.sort(Array.alphaNumericalSorter);
- for (i=0; i<names.length; i++) {
- var name = names[i];
- var layer = doc.queryLayer(name);
- if (existingLayerNames.containsIgnoreCase(layer.getName())) {
- // don't overwrite existing layers:
- continue;
- }
- var icon = RColor.getIcon(layer.getColor(), new QSize(comboBox.iconSize.width(),10));
- comboBox.addItem(icon, layer.getName());
- }
- };
- WidgetFactory.initBlockCombo = function(comboBox, doc, showSpaces) {
- if (isNull(doc)) {
- return;
- }
- if (isNull(showSpaces)) {
- showSpaces = false;
- }
- comboBox.clear();
- var names = doc.getBlockNames();
- names.sort(Array.alphaNumericalSorter);
- //names = RS.sortAlphanumerical(names);
- for (var i=0; i<names.length; i++) {
- var name = names[i];
- if (showSpaces || !name.startsWith("*")) {
- comboBox.addItem(name);
- }
- }
- };
- WidgetFactory.initList = function(list, groupName) {
- if (isNull(list)) {
- return;
- }
- if (RSettings.getBoolValue(groupName + "/EnableAlternatingRowColor", false)===true) {
- list.alternatingRowColors = true;
- var p = list.palette;
- var col = RSettings.getColorValue(groupName + "/AlternatingRowColor", new RColor(230, 235, 250));
- p.setColor(QPalette.AlternateBase, new QColor(col.red(), col.green(), col.blue(), col.alpha()));
- list.palette = p;
- }
- else {
- list.alternatingRowColors = false;
- }
- };
- WidgetFactory.initHAlignCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Left"), RS.HAlignLeft);
- comboBox.addItem(qsTr("Center"), RS.HAlignCenter);
- comboBox.addItem(qsTr("Right"), RS.HAlignRight);
- comboBox.addItem(qsTr("Aligned"), RS.HAlignAlign);
- comboBox.addItem(qsTr("Middle"), RS.HAlignMid);
- comboBox.addItem(qsTr("Fit"), RS.HAlignFit);
- };
- WidgetFactory.initVAlignCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Top"), RS.VAlignTop);
- comboBox.addItem(qsTr("Middle"), RS.VAlignMiddle);
- comboBox.addItem(qsTr("Base"), RS.VAlignBase);
- comboBox.addItem(qsTr("Bottom"), RS.VAlignBottom);
- };
- WidgetFactory.initDimlunitCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Scientific"), RS.Scientific);
- comboBox.addItem(qsTr("Decimal"), RS.Decimal);
- comboBox.addItem(qsTr("Engineering"), RS.Engineering);
- comboBox.addItem(qsTr("Architectural"), RS.ArchitecturalStacked);
- comboBox.addItem(qsTr("Fractional"), RS.FractionalStacked);
- };
- WidgetFactory.initDimtadCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Centered"), 0);
- comboBox.addItem(qsTr("Above"), 1);
- };
- WidgetFactory.initDimdsepCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(".", '.');
- comboBox.addItem(",", ',');
- };
- WidgetFactory.initDimzinCombo = function(comboBox) {
- comboBox.clear();
- //comboBox.addItem(qsTr("Suppress 0'0\" (unsupported)"), 0);
- comboBox.addItem(qsTr("Show trailing zeroes"), 0);
- comboBox.addItem(qsTr("Include 0'0\"") + " " + qsTr("(unsupported)"), 1);
- comboBox.addItem(qsTr("Include 0', suppress 0\"") + " " + qsTr("(unsupported)"), 2);
- comboBox.addItem(qsTr("Include 0\", suppress 0'") + " " + qsTr("(unsupported)"), 3);
- comboBox.addItem(qsTr("Suppress leading zeroes") + " " + qsTr("(unsupported)"), 4);
- comboBox.addItem(qsTr("Suppress trailing zeroes"), 8);
- comboBox.addItem(qsTr("Suppress leading / trailing zeroes") + " " + qsTr("(unsupported)"), 12);
- // comboBox.addItem(qsTr("Suppress 0'0\""), 0);
- // comboBox.addItem(qsTr("Include 0'0\""), 1);
- // comboBox.addItem(qsTr("Include 0', suppress 0\""), 2);
- // comboBox.addItem(qsTr("Include 0\", suppress 0'"), 3);
- };
- WidgetFactory.initDimdecCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem("0", 0);
- comboBox.addItem("1", 1);
- comboBox.addItem("2", 2);
- comboBox.addItem("3", 3);
- comboBox.addItem("4", 4);
- comboBox.addItem("5", 5);
- comboBox.addItem("6", 6);
- comboBox.addItem("7", 7);
- comboBox.addItem("8", 8);
- };
- WidgetFactory.initDimaunitCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Decimal Degrees"), RS.DegreesDecimal);
- comboBox.addItem(qsTr("Deg/min/sec"), RS.DegreesMinutesSeconds);
- comboBox.addItem(qsTr("Gradians"), RS.Gradians);
- comboBox.addItem(qsTr("Radians"), RS.Radians);
- comboBox.addItem(qsTr("Surveyor's units"), RS.Surveyors);
- };
- WidgetFactory.initDimazinCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Show trailing zeroes"), 0);
- comboBox.addItem(qsTr("Suppress leading zeroes") + " " + qsTr("(unsupported)"), 1);
- comboBox.addItem(qsTr("Suppress trailing zeroes"), 2);
- comboBox.addItem(qsTr("Suppress leading / trailing zeroes") + " " + qsTr("(unsupported)"), 3);
- };
- WidgetFactory.initDimadecCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem("0", 0);
- comboBox.addItem("1", 1);
- comboBox.addItem("2", 2);
- comboBox.addItem("3", 3);
- comboBox.addItem("4", 4);
- comboBox.addItem("5", 5);
- comboBox.addItem("6", 6);
- comboBox.addItem("7", 7);
- comboBox.addItem("8", 8);
- };
- WidgetFactory.initOrientationCombo = function(comboBox) {
- comboBox.clear();
- if (RSettings.isQt(5)) {
- comboBox.addItem("↻ " + qsTr("Clockwise"), RS.CW);
- comboBox.addItem("↺ " + qsTr("Counterclockwise"), RS.CCW);
- }
- else {
- comboBox.addItem(qsTr("Clockwise"), RS.CW);
- comboBox.addItem(qsTr("Counterclockwise"), RS.CCW);
- }
- };
- WidgetFactory.initArcSymbolTypeCombo = function(comboBox) {
- comboBox.clear();
- comboBox.addItem(qsTr("Preceding"), 0);
- comboBox.addItem(qsTr("Above"), 1);
- comboBox.addItem(qsTr("None"), 2);
- };
- WidgetFactory.installComboBoxEventFilter = function(widget) {
- if (isNull(widget)) {
- return;
- }
- if (!isQWidget(widget) || !isFunction(widget.children)) {
- return;
- }
- var children = widget.children();
- for ( var i = 0; i < children.length; ++i) {
- var c = children[i];
- if (!c || isDeleted(c)) {
- break;
- }
- if (isOfType(c, QSpinBox) ||
- isOfType(c, QComboBox) ||
- isOfType(c, QFontComboBox) ||
- isOfType(c, RColorCombo) ||
- isOfType(c, RLineweightCombo) ||
- isOfType(c, RLinetypeCombo)) {
- if (isFunction(c.installEventFilter)) {
- c.installEventFilter(new REventFilter(QEvent.Wheel.valueOf(), true));
- }
- c.focusPolicy = Qt.ClickFocus;
- continue;
- }
- WidgetFactory.installComboBoxEventFilter(c);
- }
- };
|