CharacterMapDialog.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /**
  20. * \class CharacterMapDialog
  21. * \brief Provides a character map dialog that shows available Unicode
  22. * characters to insert into a text field.
  23. * \ingroup ecma_draw_text
  24. */
  25. function CharacterMapDialog(parent) {
  26. this.parent = parent;
  27. }
  28. CharacterMapDialog.includeBasePath = includeBasePath;
  29. CharacterMapDialog.prototype.show = function() {
  30. var font, pointSize;
  31. var dlg = WidgetFactory.createWidget(CharacterMapDialog.includeBasePath,
  32. "CharacterMapDialog.ui", this.parent.dialog);
  33. //dlg.windowIcon = new QIcon(autoPath("scripts/Draw/Text/Text.svg"));
  34. var characterMap = new RCharacterWidget(dlg);
  35. var fontFamily = this.parent.comboFont
  36. .itemText(this.parent.comboFont.currentIndex);
  37. var bold = this.parent.actionTextBold.checked ? true : false;
  38. var italic = this.parent.actionTextItalic.checked ? true : false;
  39. pointSize = this.parent.comboSize.itemText(this.parent.comboSize.currentIndex)
  40. * this.parent.fontHeightFactor;
  41. var style = "";
  42. style += bold ? "Bold" : "";
  43. style += italic ? " Italic" : "";
  44. font = new QFont(fontFamily, pointSize, bold ? QFont.Bold : QFont.Normal, italic);
  45. characterMap.updateFont(font);
  46. characterMap.updateSize(pointSize.toString());
  47. characterMap.updateStyle(style);
  48. characterMap.updateFontMerging(true);
  49. characterMap.characterSelected.connect(this, function(character) {
  50. var textWidget = this.parent.dialog.findChild("Text");
  51. var cursor = textWidget.textCursor();
  52. cursor.insertText(character);
  53. var singleShot = new QTimer(this.parent.dialog);
  54. singleShot.singleShot = true;
  55. singleShot.timeout.connect(this, function() {
  56. dlg.accept();
  57. });
  58. singleShot.start(250);
  59. });
  60. var widgets = getWidgets(dlg);
  61. widgets["ScrollArea"].setWidget(characterMap);
  62. widgets["ZoomIn"].clicked.connect(this, function() {
  63. font = characterMap.getDisplayFont();
  64. pointSize = font.pointSize();
  65. ++pointSize;
  66. characterMap.updateSize(pointSize.toString());
  67. this.updateSlider(widgets["ZoomSlider"], pointSize);
  68. });
  69. widgets["ZoomOut"].clicked.connect(this, function() {
  70. font = characterMap.getDisplayFont();
  71. pointSize = font.pointSize();
  72. pointSize = Math.max(1, --pointSize);
  73. characterMap.updateSize(pointSize.toString());
  74. this.updateSlider(widgets["ZoomSlider"], pointSize);
  75. });
  76. widgets["ZoomSlider"].valueChanged.connect(this, function(value) {
  77. pointSize = Math.max(1, Math.round(value / 2));
  78. characterMap.updateSize(pointSize.toString());
  79. });
  80. font = characterMap.getDisplayFont();
  81. pointSize = font.pointSize();
  82. this.updateSlider(widgets["ZoomSlider"], pointSize);
  83. widgets["ScrollArea"].setFocus(Qt.MouseFocusReason);
  84. dlg.show();
  85. };
  86. CharacterMapDialog.prototype.updateSlider = function(slider, pointSize) {
  87. var value = Math.round(100 / 50 * pointSize);
  88. slider.setValue(value);
  89. };