diff options
| author | Mikko Syrjä <mikko@syrja.org> | 2019-07-25 00:38:16 +0300 |
|---|---|---|
| committer | Mikko Syrjä <mikko@syrja.org> | 2019-07-25 00:38:16 +0300 |
| commit | 7202148aeeaac7e5ed0dce3bfc501b5200314757 (patch) | |
| tree | c6434bb6a4e97668c21ee5e41ffee4946ddcbfc6 | |
| parent | 6cbf0f778c804e643592d306e3e2c93a3a82904e (diff) | |
| download | symedit-7202148aeeaac7e5ed0dce3bfc501b5200314757.tar.gz symedit-7202148aeeaac7e5ed0dce3bfc501b5200314757.zip | |
Implemented rotated text editing.
| -rw-r--r-- | Editor.qml | 31 | ||||
| -rw-r--r-- | help/eng/format.rst | 25 | ||||
| -rw-r--r-- | help/eng/tools.rst | 15 | ||||
| -rw-r--r-- | help/eng/usage.rst | 9 | ||||
| -rw-r--r-- | help/fin/format.rst | 29 | ||||
| -rw-r--r-- | help/fin/tools.rst | 17 | ||||
| -rw-r--r-- | help/fin/usage.rst | 8 | ||||
| -rw-r--r-- | main.qml | 4 | ||||
| -rw-r--r-- | symbol.cpp | 84 | ||||
| -rw-r--r-- | symbol.h | 6 | ||||
| -rw-r--r-- | symedit.cpp | 7 | ||||
| -rw-r--r-- | symedit.h | 2 |
12 files changed, 133 insertions, 104 deletions
@@ -97,8 +97,11 @@ Rectangle { if ( tool === Editor.Tool.TextHorizontal ) { - if ( manager.addTextItem(Operation.Text, Qt.point(endx, endy), textvalue, colorindex, alignment) ) + if ( manager.addTextItem(Operation.Text, Qt.point(endx, endy), Qt.point(endx, endy), textvalue, colorindex, alignment) ) + { symbol = manager.getSymbol(true) + canvas.requestPaint() + } } else if ( startx != endx || starty != endy ) { @@ -158,7 +161,8 @@ Rectangle } else if ( tool === Editor.Tool.TextRotated ) { - //## + if ( manager.addTextItem(Operation.Text, Qt.point(startx, starty), Qt.point(endx, endy), textvalue, colorindex, alignment) ) + symbol = manager.getSymbol(true) } } else // activate last @@ -258,23 +262,27 @@ Rectangle } } - function painttext(context, string, point, active) + function painttext(context, string, point, end, active) { var currentwidth = context.lineWidth context.lineWidth = textsize * (preview ? zoommin : zoomscale) / 2 var fontsize = 30 * textsize * (preview ? zoommin : zoomscale) context.font = fontsize.toString() + "px sans-serif" var position = Qt.point((point.x + max + offsetx) * scalexy, (max - point.y + offsety) * scalexy) - context.fillText(string, position.x, position.y) - context.strokeText(string, position.x, position.y) - if ( !preview ) + context.translate(position.x, position.y) + if ( point.x !== end.x || point.y !== end.y ) // rotate + context.rotate(Math.atan2(point.y - end.y, end.x - point.x)) + context.fillText(string, 0, 0) + context.strokeText(string, 0, 0) + if ( !preview ) // attach point { if ( active ) context.fillStyle = editcolor - context.beginPath().ellipse(position.x - 5, position.y - 5, zoomscale * 10, zoomscale * 10).fill() + context.beginPath().ellipse(zoomscale * -5 , zoomscale * -5, zoomscale * 10, zoomscale * 10).fill() if ( active ) context.fillStyle = paintcolor } + context.resetTransform() context.lineWidth = currentwidth } @@ -353,8 +361,9 @@ Rectangle } else if ( operation === Operation.Text ) { + point = manager.getItemPoint(index) setalignment(context, manager.getItemAlign(index)) - painttext(context, manager.getItemText(index), position, index === active) + painttext(context, manager.getItemText(index), position, point, index === active) } } } @@ -444,11 +453,9 @@ Rectangle { setalignment(context, alignment) if ( tool === Editor.Tool.TextHorizontal ) - painttext(context, textvalue, Qt.point(mousex, mousey), true) + painttext(context, textvalue, Qt.point(mousex, mousey), Qt.point(mousex, mousey), true) else if ( tool === Editor.Tool.TextRotated ) - { - //## - } + painttext(context, textvalue, Qt.point(startx, starty), Qt.point(mousex, mousey), true) } } diff --git a/help/eng/format.rst b/help/eng/format.rst index 86dfd68..8e43a66 100644 --- a/help/eng/format.rst +++ b/help/eng/format.rst @@ -3,12 +3,16 @@ Symbol format ============= -xxx +Format contains drawing commands separated by semicolons. Symbol coordinate area is 100x100 and origin is at center. Coordinate X component is horizontal from left to right and Y component is vertical from bottom to top. Angle zero direction points to right and rotation is counter-clockwise. + +For example, application crosshair logo can be defined like this: + +``R50;U-50,0;D50,0;U0,50;D0,-50`` Commands -------- -Commands are separated by semicolons. Coordinate X is horizontal component from left to right and Y is vertical component from bottom to top. +Following drawing commads are available. **U** - Change position ^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,7 +45,7 @@ Parameters: X,Y (``B40,40``) **C** - Set color index ^^^^^^^^^^^^^^^^^^^^^^^ -Sets parameter to current drawing color index. +Sets parameter to current drawing color index. Affects until changed. Parameters: I (``C3``) @@ -54,7 +58,20 @@ Sets area fill type index to one of the following values: 1. Area fill using background color 2. Area fill using current color -Fill type works with rectangle and circle commands. Border is drawn only when the fill type is zero. +Fill type works with rectangle and circle commands. Border is drawn only when the fill type is zero. Affects until changed. Parameters: I (``F2``) +**G** - Set 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 +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Sets parameter to text alignment (1-12). Default is 9 (bottom left corner). Affects until changed. + +Parameters: I (``J9``) diff --git a/help/eng/tools.rst b/help/eng/tools.rst index 8274414..64ec2c3 100644 --- a/help/eng/tools.rst +++ b/help/eng/tools.rst @@ -78,13 +78,20 @@ Draws circle with center and radius. .. xxx Draws quarter circle with center and radius. -.. |text image| image:: ../../image/text.png +.. |text horizontal image| image:: ../../image/text_horizontal.png + :scale: 50 % +.. |text rotated image| image:: ../../image/text_rotated.png :scale: 50 % -|text image| Text -^^^^^^^^^^^^^^^^^ +|text horizontal image| Horizontal text +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Draws horizontal text to given position. + +|text rotated image| Rotated text +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Draws text to given position. +Draws text to given position using other point as direction. Settings -------- diff --git a/help/eng/usage.rst b/help/eng/usage.rst index 196394f..92e7073 100644 --- a/help/eng/usage.rst +++ b/help/eng/usage.rst @@ -1,7 +1,7 @@ Application usage ================= -xxx +Application can be used directly for editing single symbol defintion files or it can be called from other programs and controlled by command line parameters. Command line ------------ @@ -31,12 +31,12 @@ Displays command line help. file ^^^^ -Symbol file name. Symbol file is simple text file containing symbol definition. +Symbol file name. Symbol file is simple text file containing single symbol definition. See :ref:`symbol-format-label`. User interface -------------- -xxx +User interface is traditional desktop interface. All tools are available as menu commands and important ones also as toolbar buttons. Menu ^^^^ @@ -54,7 +54,8 @@ See :doc:`tools`. Editor ^^^^^^ -xxx +Editing works by selecting first drawing tool from the menu or toolbar. Pressing the mouse button starts new element adding and releasing the button saves it. Already created elements cannot be modified. They must first be deleted and then redrawed. + Statusbar ^^^^^^^^^ diff --git a/help/fin/format.rst b/help/fin/format.rst index cf9bd3d..37b6f64 100644 --- a/help/fin/format.rst +++ b/help/fin/format.rst @@ -3,12 +3,16 @@ Symbolin formaatti ================== -xxx +Formaatti koostuu puolipisteellä erotetuista piirtokomennoista. Symbolin koordinaattialue on kooltaan 100x100 ja origo on keskellä. Koordinaatiston X on vaakasuora komponentti vasemmalta oikealle ja Y on pystysuora komponentti alhaalta ylös. Kulmien nollasuunta on oikealle ja kiertosuunta vastapäivään. + +Esimerkiksi ohjelman logona oleva hiusristikko määritellään seuraavasti: + +``R50;U-50,0;D50,0;U0,50;D0,-50`` Komennot -------- -Komennot erotetaan toisistaan puolipisteillä. Koordinaatiston X on vaakasuora komponentti vasemmalta oikealle ja Y on pystysuora komponentti alhaalta ylös. +Käytettävissä ovat seuraavat piirtokomennot. **U** - Muuta sijaintia ^^^^^^^^^^^^^^^^^^^^^^^ @@ -41,9 +45,9 @@ Parametrit: X,Y (``B40,40``) **C** - Aseta väri-indeksi ^^^^^^^^^^^^^^^^^^^^^^^^^^ -Asettaa parametrin piirron väri-ideksiksi. +Asettaa parametrin piirron väri-ideksiksi. Voimassa kunnes muutetaan. -Parameters: I (``C3``) +Parametrit: I (``C3``) **F** - Aseta alueen täyttö ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -54,7 +58,20 @@ Asettaa alueen täytöksi jonkin seuraavan tyypin: 1. Alueen täyttö taustavärillä 2. Alueen täyttö nykyisellä värillä -Alueen täyttö toimii suorakaiteen ja ympyrän kanssa. Reunaviiva piirretään vain, jos täyttö on nolla. +Alueen täyttö toimii suorakaiteen ja ympyrän kanssa. Reunaviiva piirretään vain, jos täyttö on nolla. Voimassa kunnes muutetaan. + +Parametrit: I (``F2``) + +**G** - Aseta 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 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Parameters: I (``F2``) +Asettaa parametrin tekstin asemoinniksi (1-12). Oletus on 9 (vasen alakulma). Voimassa kunnes muutetaan. +Parametrit: I (``J9``) diff --git a/help/fin/tools.rst b/help/fin/tools.rst index 6ba291e..25d3218 100644 --- a/help/fin/tools.rst +++ b/help/fin/tools.rst @@ -24,7 +24,7 @@ Valitsee hiirellä osoitetun kohteen aktiiviseksi. Alueet valitaan osoittamalla |line image| Viiva ^^^^^^^^^^^^^^^^^^ -Piirtää kahden pisteen viivan. Peräkkäiset kahden pisteen viivat muodostavat murtoviivan ja sulkeminen alkupisteeseen muodosta alueen. +Piirtää kahden pisteen viivan. Peräkkäiset kahden pisteen viivat muodostavat murtoviivan ja sulkeminen alkupisteeseen muodostaa alueen. .. |rect corner image| image:: ../../image/rectangle_corner.png :scale: 50 % @@ -78,13 +78,20 @@ Piirtää ympyrän keskipisteestä kehälle. .. xxx Piirtää neljännesympyrän keskipisteestä kehälle. -.. |text image| image:: ../../image/text.png +.. |text horizontal image| image:: ../../image/text_horizontal.png :scale: 50 % +.. |text rotated image| image:: ../../image/text_rotated.png + :scale: 50 % + +|text horizontal image| Vaakasuora teksti +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -|text image| Teksti -^^^^^^^^^^^^^^^^^^^ +Piirtää vaakasuoran tekstin osoitettuun kohtaan. + +|text rotated image| Käännetty teksti +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Piirtää tekstin annettuun kohtaan. +Piirtää tekstin osoitettuun kohtaan käyttäen suuntana toista sijaintia. Asetukset --------- diff --git a/help/fin/usage.rst b/help/fin/usage.rst index 6b7507f..f543f48 100644 --- a/help/fin/usage.rst +++ b/help/fin/usage.rst @@ -1,7 +1,7 @@ Ohjelman käyttö =============== -xxx +Ohjelmaa voidaan käyttää suoraan yksittäisten symbolitiedostojen editointiin tai sitä voidaan kutsua muista ohjelmista komentoriviparametreilla ohjattuna. Komentorivi ----------- @@ -31,12 +31,12 @@ Näyttää komentorivin ohjeen. file ^^^^ -Symbolitiedoston nimi. Symbolitiedosto on tekstitiedosto, joka sisältää symbolin määrittelyn. +Symbolitiedoston nimi. Symbolitiedosto on tekstitiedosto, joka sisältää yksittäisen symbolin määrittelyn. Katso :ref:`symbol-format-label`. Käyttöliitymä ------------- -xxx +Käyttöliitymä on perinteinen työpöytäkäyttöliittymä. Kaikki työkalut ovat käytettävissä valikon kautta ja tärkeimmät myös työkalupalkin painikkeina. Valikko ^^^^^^^ @@ -54,7 +54,7 @@ Katso :doc:`tools`. Editori ^^^^^^^ -xxx +Editointi tapahtuu valitsemalla ensin valikosta tai työkalupalkista piirtotyökalu. Hiiren painikkeen painaminen aloittaa uuden elementin lisäämisen ja painikkeen vapauttaminen tallentaa sen. Luotuja elementtejä ei voi muuttaa, vaan ne on ensin poistettaba ja piirrettävä sitten uudet. Tilarivi ^^^^^^^^ @@ -107,7 +107,7 @@ ApplicationWindow */ MenuSeparator { } MenuTool { text: qsTrId("id_menu_tool_text_horizontal"); tool: Editor.Tool.TextHorizontal } -// MenuTool { text: qsTrId("id_menu_tool_text_rotated"); tool: Editor.Tool.TextRotated } + MenuTool { text: qsTrId("id_menu_tool_text_rotated"); tool: Editor.Tool.TextRotated } } Menu { @@ -175,7 +175,7 @@ ApplicationWindow */ BarSeparator { } BarTool { image: "image/text_horizontal.png"; tooltip: qsTrId("id_tooltip_tool_text_horizontal"); tool: Editor.Tool.TextHorizontal } -// BarTool { image: "image/text_rotated.png"; tooltip: qsTrId("id_tooltip_tool_text_rotated"); tool: Editor.Tool.TextRotated } + BarTool { image: "image/text_rotated.png"; tooltip: qsTrId("id_tooltip_tool_text_rotated"); tool: Editor.Tool.TextRotated } } RowLayout { @@ -28,37 +28,23 @@ SymEditSymbol::Item::Item() : Operation(Operation::None), Fill(0), Align(9) /*! \param operation Item operation. \param point Item position. + \param end End position. \param value Item value. \param color Item color index. \param fill Item area fill. */ -SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, int value, int color, int fill) - : Operation(operation), Point(point), Value(value), Color(color), Fill(fill), Align(9) +SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill) + : Operation(operation), Point(point), End(end), Value(value), Color(color), Fill(fill), Align(0) { } -SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QString value, int color, int align) - : Operation(operation), Point(point), Value(0), Text(value), Color(color), Fill(0), Align(align) +SymEditSymbol::Item::Item(Operation::Type operation, QPoint point, QPoint end, QString value, int color, int align) + : Operation(operation), Point(point), End(end), Value(0), Text(value), Color(color), Fill(0), Align(align) { } //@} -//! Constructor. -/*! - \param operation Item operation. - \param point Item position. - \param end End position. - \param value Item value. - \param color Item color index. - \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), Value(value), Color(color), Fill(fill), Align(0) -{ - -} - // // symbol functions // @@ -76,7 +62,7 @@ void SymEditSymbol::Load(const QString& buffer) { Items.clear(); QPoint position(0, 0); - int color = 1, fill = 0, align = 9; + int color = 1, fill = 0, align = 9, angle = 0; for ( const auto& string : buffer.split(';', QString::SkipEmptyParts) ) { int type = string.at(0).toLatin1(); @@ -102,12 +88,20 @@ void SymEditSymbol::Load(const QString& buffer) fill = value; else if ( type == 'J' ) align = value; + else if ( type == 'G' ) + angle = value; else if ( type == 'R' ) - Items.push_back(Item(Operation::Circle, position, value, color, fill)); - else if ( type == '!' ) - Items.push_back(Item(Operation::Text, position, string.mid(1), color, align)); - else if ( type == '$' || type == '#' ) - Items.push_back(Item(Operation::Text, position, string, color, align)); + Items.push_back(Item(Operation::Circle, position, position, value, color, fill)); + else if ( type == '!' || type == '$' || type == '#' ) + { + QPoint end = position; + if ( angle ) + { + 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, color, align)); + } } } ActiveIndex = static_cast<int>(Items.size()) - 1; @@ -138,7 +132,7 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const buffer.clear(); QPoint position(0, 0); - int index = 0, color = 1, fill = 0, align = 9; + int index = 0, color = 1, fill = 0, align = 9, angle = 0; for ( const auto& item : Items ) { if ( rich && index == ActiveIndex ) @@ -172,6 +166,11 @@ QString& SymEditSymbol::Save(QString& buffer, bool rich) const } case Operation::Text: { + int temp = 0; + if ( item.Point.y() != item.End.y() || item.Point.x() != item.End.x() ) + temp = static_cast<int>(atan2(item.End.y() - item.Point.y(), item.End.x() - item.Point.x()) / ConstPi * 200.0); + if ( temp != angle ) + angle = appendoption('G', buffer, temp); if ( item.Color != color ) color = appendoption('C', buffer, item.Color); if ( item.Align != align ) @@ -213,23 +212,7 @@ void SymEditSymbol::Clear() Items.clear(); } -//! Add symbol item. -/*! - \param operation Item operation. - \param point Item position. - \param value Item value. - \param color Item color index. - \param fill Item area fill. - \return Reference to item. -*/ -SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, int value, int color, int fill) -{ - Item item(operation, point, value, color, fill); - ActiveIndex = static_cast<int>(Items.size()); - Items.push_back(item); - return Items.back(); -} - +//@{ //! Add symbol item. /*! \param operation Item operation. @@ -247,23 +230,14 @@ SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint po Items.push_back(item); return Items.back(); } - -//! Add symbol item. -/*! - \param operation Item operation. - \param point Item position. - \param value Item value. - \param color Item color index. - \param align Item text alignment. - \return Reference to item. -*/ -SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QString value, int color, int align) +SymEditSymbol::Item& SymEditSymbol::AddItem(Operation::Type operation, QPoint point, QPoint end, QString value, int color, int align) { - Item item(operation, point, value, color, align); + Item item(operation, point, end, value, color, align); ActiveIndex = static_cast<int>(Items.size()); Items.push_back(item); return Items.back(); } +//@} //! Remove item. /*! @@ -32,9 +32,8 @@ public: { public: Item(); - Item(Operation::Type operation, QPoint point, int value, int color, int fill); Item(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill); - Item(Operation::Type operation, QPoint point, QString value, int color, int align); + Item(Operation::Type operation, QPoint point, QPoint end, QString value, int color, int align); Operation::Type Operation; //!< Item operation. QPoint Point; //!< Item coordinates. @@ -50,9 +49,8 @@ public: QString& Save(QString& buffer, bool rich = false) const; void Clear(); - Item& AddItem(Operation::Type operation, QPoint point, int value, int color, int fill); Item& AddItem(Operation::Type operation, QPoint point, QPoint end, int value, int color, int fill); - Item& AddItem(Operation::Type operation, QPoint point, QString text, int color, int align); + Item& AddItem(Operation::Type operation, QPoint point, QPoint end, QString value, int color, int align); bool RemoveItem(int index); int SelectItem(QPoint point) const; diff --git a/symedit.cpp b/symedit.cpp index cc892d9..8030ddf 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -205,7 +205,7 @@ QString SymEditManager::getSymbol(bool rich) const bool SymEditManager::addPointItem(int operation, QPoint point, int value, int color, int fill) { undosave(); - Symbol.AddItem(static_cast<Operation::Type>(operation), point, value, color, fill); + Symbol.AddItem(static_cast<Operation::Type>(operation), point, point, value, color, fill); return true; } @@ -230,17 +230,18 @@ bool SymEditManager::addLineItem(int operation, QPoint point, QPoint end, int va /*! \param operation Item operation. \param point Text position. + \param point End position. \param value Text value. \param color Color index. \param align Text alignment. \return True for success. */ -bool SymEditManager::addTextItem(int operation, QPoint point, QString value, int color, int align) +bool SymEditManager::addTextItem(int operation, QPoint point, QPoint end, QString value, int color, int align) { if ( !value.isEmpty() ) { undosave(); - Symbol.AddItem(static_cast<Operation::Type>(operation), point, value, color, align); + Symbol.AddItem(static_cast<Operation::Type>(operation), point, end, value, color, align); return true; } return false; @@ -58,7 +58,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, QString value, int color, int align); + Q_INVOKABLE bool addTextItem(int operation, QPoint point, QPoint end, QString value, int color, int align); Q_INVOKABLE bool removeItem(); Q_INVOKABLE int getItemCount() const; |
