diff options
| author | Mikko Syrjä <mikko@syrja.org> | 2019-08-20 22:04:50 +0300 |
|---|---|---|
| committer | Mikko Syrjä <mikko@syrja.org> | 2019-08-20 22:04:50 +0300 |
| commit | 40b74ae2545969c993f8ad7c92647cec663862b0 (patch) | |
| tree | 9daf6ccff4e3608cfb09caf6164775462320d763 | |
| parent | ece6dc5e58de32eb8409f1065356713dc947958c (diff) | |
| download | symedit-40b74ae2545969c993f8ad7c92647cec663862b0.tar.gz symedit-40b74ae2545969c993f8ad7c92647cec663862b0.zip | |
Added text size unit handling.
| -rw-r--r-- | Editor.qml | 15 | ||||
| -rw-r--r-- | help/eng/format.rst | 30 | ||||
| -rw-r--r-- | help/eng/tools.rst | 2 | ||||
| -rw-r--r-- | help/fin/format.rst | 30 | ||||
| -rw-r--r-- | help/fin/tools.rst | 2 | ||||
| -rw-r--r-- | main.qml | 26 | ||||
| -rw-r--r-- | symbol.cpp | 39 | ||||
| -rw-r--r-- | symbol.h | 5 | ||||
| -rw-r--r-- | symedit.cpp | 49 | ||||
| -rw-r--r-- | symedit.h | 3 |
10 files changed, 120 insertions, 81 deletions
@@ -98,7 +98,7 @@ Rectangle { if ( tool === Editor.Tool.TextHorizontal ) { - if ( manager.addTextItem(Operation.Text, Qt.point(endx, endy), Qt.point(endx, endy), textvalue, textsize, colorindex, alignment) ) + if ( manager.addTextItem(Operation.Text, Qt.point(endx, endy), Qt.point(endx, endy), textvalue, textsize, sizeunit, colorindex, alignment) ) { symbol = manager.getSymbol(true) canvas.requestPaint() @@ -162,7 +162,7 @@ Rectangle } else if ( tool === Editor.Tool.TextRotated ) { - if ( manager.addTextItem(Operation.Text, Qt.point(startx, starty), Qt.point(endx, endy), textvalue, textsize, colorindex, alignment) ) + if ( manager.addTextItem(Operation.Text, Qt.point(startx, starty), Qt.point(endx, endy), textvalue, textsize, sizeunit, colorindex, alignment) ) symbol = manager.getSymbol(true) } } @@ -263,10 +263,10 @@ Rectangle } } - function painttext(context, string, point, end, size, active) + function painttext(context, string, point, end, size, unit, active) { var currentwidth = context.lineWidth - size = Math.abs(size ? size : 2.5) * (preview ? zoommin : zoomscale) / symbolsize + size = (unit === 2 ? symbolsize * size / 10.0 : (size ? size : 2.5)) * (preview ? zoommin : zoomscale) / symbolsize context.lineWidth = size * 10 var fontsize = 300 * size context.font = fontsize.toString() + "px sans-serif" @@ -364,9 +364,10 @@ Rectangle else if ( operation === Operation.Text ) { var size = manager.getItemSize(index); + var unit = manager.getItemUnit(index); point = manager.getItemPoint(index) setalignment(context, manager.getItemAlign(index)) - painttext(context, manager.getItemText(index), position, point, size, index === active) + painttext(context, manager.getItemText(index), position, point, size, unit, index === active) } } } @@ -456,9 +457,9 @@ Rectangle { setalignment(context, alignment) if ( tool === Editor.Tool.TextHorizontal ) - painttext(context, textvalue, Qt.point(mousex, mousey), Qt.point(mousex, mousey), textsize, true) + painttext(context, textvalue, Qt.point(mousex, mousey), Qt.point(mousex, mousey), textsize, sizeunit, true) else if ( tool === Editor.Tool.TextRotated ) - painttext(context, textvalue, Qt.point(startx, starty), Qt.point(mousex, mousey), textsize, true) + painttext(context, textvalue, Qt.point(startx, starty), Qt.point(mousex, mousey), textsize, sizeunit, true) } } diff --git a/help/eng/format.rst b/help/eng/format.rst index 8e43a66..087e538 100644 --- a/help/eng/format.rst +++ b/help/eng/format.rst @@ -42,15 +42,15 @@ Draws rectangle using previous position and parameter coordinates as corners. Parameters: X,Y (``B40,40``) -**C** - Set color index -^^^^^^^^^^^^^^^^^^^^^^^ +**C** - Color index +^^^^^^^^^^^^^^^^^^^ Sets parameter to current drawing color index. Affects until changed. Parameters: I (``C3``) -**F** - Set area fill type -^^^^^^^^^^^^^^^^^^^^^^^^^^ +**F** - Area fill type +^^^^^^^^^^^^^^^^^^^^^^ Sets area fill type index to one of the following values: @@ -62,16 +62,30 @@ Fill type works with rectangle and circle commands. Border is drawn only when th Parameters: I (``F2``) -**G** - Set text angle -^^^^^^^^^^^^^^^^^^^^^^ +**G** - Text angle +^^^^^^^^^^^^^^^^^^ Sets parameter to text angle as gons. Horizontal text angle is zero and rotation is counter-clockwise. Affects until changed. Parameters: I (``G50``) -**J** - Set text alignment -^^^^^^^^^^^^^^^^^^^^^^^^^^ +**J** - Text alignment +^^^^^^^^^^^^^^^^^^^^^^ Sets parameter to text alignment (1-12). Default is 9 (bottom left corner). Affects until changed. Parameters: I (``J9``) + +**S** - Text absolute size +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Sets parameter to text size as millimeters (positive) or meters (negative). Default zero uses application settings. Affects until changed. + +Parameters: S (``S2.5``) + +**P** - Text relative size +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Sets parameter to text size as a percentage of symbol size. Default zero uses application settings. Affects until changed. + +Parameters: P (``P50``) diff --git a/help/eng/tools.rst b/help/eng/tools.rst index bd3d00e..01f07ba 100644 --- a/help/eng/tools.rst +++ b/help/eng/tools.rst @@ -140,7 +140,7 @@ Text alignment value 1-12. Text size ^^^^^^^^^ -Text size. +Text size and unit. Text ^^^^ diff --git a/help/fin/format.rst b/help/fin/format.rst index 37b6f64..91b033c 100644 --- a/help/fin/format.rst +++ b/help/fin/format.rst @@ -42,15 +42,15 @@ Piirtää suorakaiteen käyttäen edellistä sijantia ja parametrin koordinaatte Parametrit: X,Y (``B40,40``) -**C** - Aseta väri-indeksi -^^^^^^^^^^^^^^^^^^^^^^^^^^ +**C** - Väri-indeksi +^^^^^^^^^^^^^^^^^^^^ Asettaa parametrin piirron väri-ideksiksi. Voimassa kunnes muutetaan. Parametrit: I (``C3``) -**F** - Aseta alueen täyttö -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**F** - Alueen täyttö +^^^^^^^^^^^^^^^^^^^^^ Asettaa alueen täytöksi jonkin seuraavan tyypin: @@ -62,16 +62,30 @@ Alueen täyttö toimii suorakaiteen ja ympyrän kanssa. Reunaviiva piirretään Parametrit: I (``F2``) -**G** - Aseta tekstin kulma -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**G** - Tekstin kulma +^^^^^^^^^^^^^^^^^^^^^ Asettaa parametrin tekstin kulmaksi gooneina. Vaakasuoran tekstin kulma on nolla ja kiertosuunta on vastapäivään. Voimassa kunnes muutetaan. Parametrit: I (``G50``) -**J** - Aseta tekstin asemointi -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**J** - Tekstin asemointi +^^^^^^^^^^^^^^^^^^^^^^^^^ Asettaa parametrin tekstin asemoinniksi (1-12). Oletus on 9 (vasen alakulma). Voimassa kunnes muutetaan. Parametrit: I (``J9``) + +**S** - Tekstin absoluuttinen koko +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Asettaa parametrin tekstin kooksi millimetreinä (positiivinen) tai metreinä (negatiivinen). Oletus nolla käyttää sovelluksen asetuksia. Voimassa kunnes muutetaan. + +Parametrit: S (``S2.5``) + +**P** - Tekstin suhteellinen koko +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Asettaa parametrin tekstin kooksi prosentteina symbolin koosta. Oletus nolla käyttää sovelluksen asetuksia. Voimassa kunnes muutetaan. + +Parametrit: P (``P50``) diff --git a/help/fin/tools.rst b/help/fin/tools.rst index 22e530b..cf151d4 100644 --- a/help/fin/tools.rst +++ b/help/fin/tools.rst @@ -140,7 +140,7 @@ Tekstin asemointi 1-12. Tekstin koko ^^^^^^^^^^^^ -Tekstin koko. +Tekstin koko ja yksikkö. Teksti ^^^^^^ @@ -25,6 +25,7 @@ ApplicationWindow property int fillitem: 0 property int alignment: 1 property real textsize: 2.5 + property int sizeunit: 0 property string textvalue: textfield.text property int tool: 0 @@ -219,7 +220,7 @@ ApplicationWindow ComboBox { id: symbollist - implicitWidth: 60 + implicitWidth: 70 model: [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0" ] onCurrentIndexChanged: { symbolsize = currentIndex + 1; editor.update() } function setSize() { currentIndex = symbolsize - 1 } @@ -273,7 +274,7 @@ ApplicationWindow ComboBox { id: alignlist - implicitWidth: 60 + implicitWidth: 70 model: [ qsTrId("id_toolbar_align_top_right"), @@ -297,11 +298,19 @@ ApplicationWindow ComboBox { id: sizelist + implicitWidth: 70 + model: [ "0.0", "0.5", "1.0", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", + "5.5", "6.0", "6.5", "7.0", "7.5", "8.0", "8.5", "9.0", "9.5", "10.0" ] + onCurrentIndexChanged: { textsize = currentIndex / 2.0; editor.update() } + function setSize() { currentIndex = textsize * 2 } + } + ComboBox + { + id: unitlist implicitWidth: 60 - model: [ "-5.0", "-4.5", "-4.0", "-3.5", "-3.0", "-2.5", "-2.0", "-1.5", "-1.0", "-0.5", - "0.0", "0.5", "1.0", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0" ] - onCurrentIndexChanged: { textsize = currentIndex / 2 - 5; editor.update() } - function setSize() { currentIndex = textsize * 2 + 10 } + model: [ "mm", "m", "%" ] + onCurrentIndexChanged: { sizeunit = currentIndex; editor.update() } + function setUnit() { currentIndex = sizeunit } } BarSeparator { } Text { text: qsTrId("id_toolbar_text_field") } @@ -367,7 +376,8 @@ ApplicationWindow onColorindexChanged: { manager.setIntSetting("ColorIndex", colorindex) } onFillitemChanged: { manager.setIntSetting("FillItem", fillitem) } onAlignmentChanged: { manager.setIntSetting("Alignment", alignment) } - onTextsizeChanged: { manager.setRealSetting("TextSize", textsize) } + onTextsizeChanged: { manager.setRealSetting("TextSize", textsize); editor.update() } + onSizeunitChanged: { manager.setIntSetting("SizeUnit", sizeunit) } onTextvalueChanged: { manager.setTextSetting("TextValue", textvalue) } onToolChanged: { manager.setIntSetting("Tool", tool) } @@ -388,6 +398,7 @@ ApplicationWindow fillitem = manager.getIntSetting("FillItem") alignment = manager.getIntSetting("Alignment") textsize = manager.getRealSetting("TextSize") + sizeunit = manager.getIntSetting("SizeUnit") textfield.text = manager.getTextSetting("TextValue") tool = manager.getIntSetting("Tool") @@ -401,6 +412,7 @@ ApplicationWindow filllist.setFill() alignlist.setAlign() sizelist.setSize() + unitlist.setUnit() symbol = manager.getSymbol(true) @@ -18,7 +18,7 @@ namespace Operation const SymEditSymbol::Item gDefaultItem; //!< Empty default item. //! Constructor. -SymEditSymbol::Item::Item() : Operation(Operation::None), Fill(0), Align(9) +SymEditSymbol::Item::Item() : Operation(Operation::None), Fill(0), Align(9), Unit(0) { } @@ -33,7 +33,7 @@ SymEditSymbol::Item::Item() : Operation(Operation::None), Fill(0), Align(9) \param fill Item area fill. */ SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill) - : Operation(operation), Point(point), End(end), Size(0.0), Value(value), Color(color), Fill(fill), Align(0) + : Operation(operation), Point(point), End(end), Size(0.0), Value(value), Color(color), Fill(fill), Align(0), Unit(0) { } @@ -45,11 +45,12 @@ SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, i \param end End position. \param text Text string. \param size Text size. + \param unit Size unit. \param color Item color index. \param align Text alignment. */ -SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int color, int align) - : Operation(operation), Point(point), End(end), Text(text), Size(size), Value(0), Color(color), Fill(0), Align(align) +SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align) + : Operation(operation), Point(point), End(end), Text(text), Size(size), Value(0), Color(color), Fill(0), Align(align), Unit(unit) { } @@ -72,7 +73,7 @@ void SymEditSymbol::Load(const QString& buffer) Items.clear(); QPoint position(0, 0); double size = 0.0; - int color = 1, fill = 0, align = 9, angle = 0; + int color = 1, fill = 0, align = 9, angle = 0, unit = 0; for ( const auto& string : buffer.split(';', QString::SkipEmptyParts) ) { int type = string.at(0).toLatin1(); @@ -98,8 +99,12 @@ void SymEditSymbol::Load(const QString& buffer) fill = value; else if ( type == 'J' ) align = value; - else if ( type == 'S' ) + else if ( type == 'S' || type == 'P' ) + { size = string.mid(1).toDouble(); + unit = (type == 'P' ? 2 : (size < 0.0 ? 1 : 0)); + size = fabs(size) * (type == 'P' ? 10.0 : 1.0); + } else if ( type == 'G' ) angle = value; else if ( type == 'R' ) @@ -112,7 +117,7 @@ void SymEditSymbol::Load(const QString& buffer) double radian = angle / 200.0 * ConstPi; end = QPoint(static_cast<int>(cos(radian) * 100.0), static_cast<int>(sin(radian) * 100.0)); } - Items.push_back(Item(Operation::Text, position, end, type == '!' ? string.mid(1) : string, size, color, align)); + Items.push_back(Item(Operation::Text, position, end, type == '!' ? string.mid(1) : string, size, unit, color, align)); } } } @@ -145,7 +150,7 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const buffer.clear(); QPoint position(0, 0); double size = 0.0; - int index = 0, color = 1, fill = 0, align = 9, angle = 0; + int index = 0, color = 1, fill = 0, align = 9, angle = 0, unit = 0; for ( const auto& item : Items ) { if ( rich && index == ActiveIndex ) @@ -188,12 +193,12 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const color = appendoption('C', buffer, item.Color); if ( item.Align != align ) align = appendoption('J', buffer, item.Align); - if ( item.Size != size ) + if ( item.Size != size || item.Unit != unit ) { -// size = appendoption('S', buffer, item.Size); QString value; - size = item.Size; - buffer.append('S').append(value.setNum(size)).append(';'); + unit = item.Unit; + size = item.Size * (unit == 2 ? 10.0 : 1.0); + buffer.append(unit == 2 ? 'P' : 'S').append(value.setNum(size * (unit == 1 ? -1.0 : 1.0))).append(';'); } if ( item.Point != position ) appendpoint(buffer.append('U'), item.Point, 2); @@ -255,14 +260,16 @@ SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint po \param operation Item operation. \param point Start position. \param end End position. - \param value Item value. + \param text Text string. + \param size Text size. + \param unit Size unit. \param color Item color index. - \param fill Item area fill. + \param align Text alignment. \return Reference to item. */ -SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int color, int align) +SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align) { - Item item(operation, point, end, text, size, color, align); + Item item(operation, point, end, text, size, unit, color, align); ActiveIndex = static_cast<int>(Items.size()); Items.push_back(item); return Items.back(); @@ -33,7 +33,7 @@ public: public: Item(); Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill); - Item(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int color, int align); + Item(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align); Operation::Type Operation; //!< Item operation. QPoint Point; //!< Item coordinates. @@ -44,6 +44,7 @@ public: int Color; //!< Color index. int Fill; //!< Fill area. int Align; //!< Text alignment. + int Unit; //!< Size unit. }; void Load(const QString& buffer); @@ -51,7 +52,7 @@ public: void Clear(); Item& AddItem(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill); - Item& AddItem(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int color, int align); + Item& AddItem(Operation::Type operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align); bool RemoveItem(int index); int SelectItem(QPoint point) const; diff --git a/symedit.cpp b/symedit.cpp index 76ad9a8..1cc1784 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -22,6 +22,7 @@ SymEditSettings::SymEditSettings() IntValues.emplace("ColorIndex", 1); IntValues.emplace("FillItem", 0); IntValues.emplace("Alignment", 9); + IntValues.emplace("SizeUnit", 0); IntValues.emplace("Tool", 1); RealValues.emplace("SymbolSize", 5.0); @@ -54,6 +55,7 @@ void SymEditSettings::Load() // IntValues.at("FillItem") = settings.value("editor/fill", 0).toInt(); // RealValues.at("TextSize") = settings.value("editor/size", 0.0).toDouble(); IntValues.at("Alignment") = settings.value("editor/align", 9).toInt(); + IntValues.at("SizeUnit") = settings.value("editor/unit", 0).toInt(); TextValues.at("TextValue") = settings.value("editor/text").toString(); IntValues.at("Tool") = settings.value("editor/tool", 1).toInt(); @@ -80,6 +82,7 @@ void SymEditSettings::Save() const settings.setValue("editor/fill", IntValues.at("FillItem")); settings.setValue("editor/size", RealValues.at("TextSize")); settings.setValue("editor/align", IntValues.at("Alignment")); + settings.setValue("editor/unit", IntValues.at("SizeUnit")); settings.setValue("editor/text", TextValues.at("TextValue")); settings.setValue("editor/tool", IntValues.at("Tool")); @@ -252,16 +255,17 @@ bool SymEditManager::addLineItem(int operation, QPoint point, QPoint end, int va \param point End position. \param text Text string. \param size Text size. + \param unit Size unit. \param color Color index. \param align Text alignment. \return True for success. */ -bool SymEditManager::addTextItem(int operation, QPoint point, QPoint end, QString text, double size, int color, int align) +bool SymEditManager::addTextItem(int operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align) { if ( !text.isEmpty() ) { undosave(); - Symbol.AddItem(static_cast<Operation::Type>(operation), point, end, text, size, color, align); + Symbol.AddItem(static_cast<Operation::Type>(operation), point, end, text, size, unit, color, align); return true; } return false; @@ -300,10 +304,7 @@ int SymEditManager::getItemCount() const int SymEditManager::getItemOperation(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Operation; - } + return Symbol.GetItem(index).Operation; return Operation::None; } @@ -333,10 +334,7 @@ QPoint SymEditManager::getItemPosition(int index) const int SymEditManager::getItemValue(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Value; - } + return Symbol.GetItem(index).Value; return 0; } QPoint SymEditManager::getItemPoint(int index) const @@ -353,48 +351,39 @@ QPoint SymEditManager::getItemPoint(int index) const QString SymEditManager::getItemText(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Text; - } + return Symbol.GetItem(index).Text; return ""; } int SymEditManager::getItemColor(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Color; - } + return Symbol.GetItem(index).Color; return 1; } int SymEditManager::getItemFill(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Fill; - } + return Symbol.GetItem(index).Fill; return 0; } int SymEditManager::getItemAlign(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Align; - } + return Symbol.GetItem(index).Align; return 0; } double SymEditManager::getItemSize(int index) const { if ( Symbol.GetItemCount() ) - { - const auto& item = Symbol.GetItem(index); - return item.Size; - } + return Symbol.GetItem(index).Size; return 0.0; } +int SymEditManager::getItemUnit(int index) const +{ + if ( Symbol.GetItemCount() ) + return Symbol.GetItem(index).Unit; + return 0; +} //@} //! Select item nearest to point. @@ -61,7 +61,7 @@ public: Q_INVOKABLE bool addPointItem(int operation, QPoint point, int value, int color, int fill); Q_INVOKABLE bool addLineItem(int operation, QPoint point, QPoint end, int value, int color, int fill); - Q_INVOKABLE bool addTextItem(int operation, QPoint point, QPoint end, QString text, double size, int color, int align); + Q_INVOKABLE bool addTextItem(int operation, QPoint point, QPoint end, QString text, double size, int unit, int color, int align); Q_INVOKABLE bool removeItem(); Q_INVOKABLE int getItemCount() const; @@ -74,6 +74,7 @@ public: Q_INVOKABLE int getItemFill(int index) const; Q_INVOKABLE int getItemAlign(int index) const; Q_INVOKABLE double getItemSize(int index) const; + Q_INVOKABLE int getItemUnit(int index) const; Q_INVOKABLE int selectItem(QPoint point) const; Q_INVOKABLE bool setActiveIndex(int index); |
