TextPreferences.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("../../EAction.js");
  20. include("../../WidgetFactory.js");
  21. function TextPreferences(guiAction) {
  22. EAction.call(this, guiAction);
  23. }
  24. TextPreferences.prototype = new EAction();
  25. TextPreferences.getPreferencesCategory = function() {
  26. return [qsTr("Draw"), qsTr("Text")];
  27. };
  28. TextPreferences.initPreferences = function(pageWidget, calledByPrefDialog, document) {
  29. var cbUseReducedList = pageWidget.findChild("UseReducedFontList");
  30. var lReducedList = pageWidget.findChild("ReducedFontList");
  31. var bCheckAll = pageWidget.findChild("CheckAll");
  32. var bUncheckAll = pageWidget.findChild("UncheckAll");
  33. lReducedList.enabled = cbUseReducedList.checked;
  34. // add CAD fonts to list:
  35. var cadList = RFontList.getNames();
  36. lReducedList.addItems(cadList);
  37. // add system fonts to list:
  38. var families;
  39. if (RSettings.getQtVersion() >= 0x060000) {
  40. families = QFontDatabase.families();
  41. }
  42. else {
  43. var fontDb = new RFontDatabase();
  44. families = fontDb.families();
  45. }
  46. lReducedList.addItems(families);
  47. var list = RSettings.getValue("Text/ReducedFontList", []);
  48. if (isNull(list)) {
  49. list = [];
  50. }
  51. for (var row = 0; row<lReducedList.count; row++) {
  52. var item = lReducedList.item(row);
  53. var flags;
  54. if (RSettings.getQtVersion() >= 0x060000) {
  55. flags = makeQtItemFlags(item.flags(), Qt.ItemIsUserCheckable);
  56. }
  57. else {
  58. flags = new Qt.ItemFlags(item.flags() | Qt.ItemIsUserCheckable);
  59. }
  60. // always check 'standard' and make it immutable:
  61. if (item.text().toLowerCase()==="standard") {
  62. item.setCheckState(Qt.Checked);
  63. if (RSettings.getQtVersion() >= 0x060000) {
  64. flags = makeQtItemFlags(item.flags() & ~(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled));
  65. }
  66. else {
  67. flags = new Qt.ItemFlags(item.flags() & ~(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled));
  68. }
  69. }
  70. else if (list.contains(item.text())) {
  71. item.setCheckState(Qt.Checked);
  72. }
  73. else {
  74. item.setCheckState(Qt.Unchecked);
  75. }
  76. item.setFlags(flags);
  77. }
  78. bCheckAll.clicked.connect(function() {
  79. for (var row = 0; row<lReducedList.count; row++) {
  80. var item = lReducedList.item(row);
  81. item.setCheckState(Qt.Checked);
  82. }
  83. });
  84. bUncheckAll.clicked.connect(function() {
  85. for (var row = 0; row<lReducedList.count; row++) {
  86. var item = lReducedList.item(row);
  87. if (item.text().toLowerCase()==="standard") {
  88. continue;
  89. }
  90. item.setCheckState(Qt.Unchecked);
  91. }
  92. });
  93. lReducedList.setProperty("Loaded", true);
  94. };
  95. TextPreferences.savePreferences = function(pageWidget, calledByPrefDialog, document) {
  96. var cbUseReducedList = pageWidget.findChild("UseReducedFontList");
  97. var lReducedList = pageWidget.findChild("ReducedFontList");
  98. var list = [];
  99. if (cbUseReducedList.checked) {
  100. for (var row = 0; row<lReducedList.count; row++) {
  101. var item = lReducedList.item(row);
  102. if (item.checkState()===Qt.Checked) {
  103. list.push(item.text());
  104. }
  105. }
  106. }
  107. RSettings.setValue("Text/ReducedFontList", list);
  108. lReducedList.setProperty("Saved", true);
  109. };