JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtmathtextmatrixnode.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3 with contributions from: Razi Alavizadeh
4
5
6
7 This software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License (LGPL) as published by
9 the Free Software Foundation, either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License (LGPL) for more details.
16
17 You should have received a copy of the GNU Lesser General Public License (LGPL)
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22
23
24#ifndef JKQTMATHTEXTMATRIXNODE_H
25#define JKQTMATHTEXTMATRIXNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include <QPainter>
30
31class JKQTMathText; // forward
32// JKQTMATHTEXT_LIB_EXPORT
33
34
35/** \brief subclass representing a \c \\begin{matrix} , \c \\begin{tabular} , \c \\begin{array} , ... node
36 * \ingroup jkqtmathtext_items
37 *
38 * Definition of the matrix geometry
39 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
40 *
41 *
42 * Two examples:
43 * \image html jkqtmathtext/jkqtmathtext_tabular.png
44 *
45 * \image html jkqtmathtext/jkqtmathtext_array.png
46 */
48 public:
49 /** \brief types of lines */
50 enum LineType {
51 LTnone, /*!< \brief noline */
52 LTline, /*!< \brief single line */
53 LTdoubleline, /*!< \brief double line */
54 LTheavyline, /*!< \brief heavier/thick line */
55 LTdashed, /*!< \brief single dashed line */
56 LTdoubleDashed, /*!< \brief double dashed line */
57 LTdefault=LTnone
58 };
59 JKQTMathTextMatrixNode(JKQTMathText* parent, const QVector<QVector<JKQTMathTextNode*> >& children, const QString& columnSpec=QString());
60 JKQTMathTextMatrixNode(JKQTMathText* parent, const QString& columnSpec=QString());
61 virtual ~JKQTMathTextMatrixNode() override;
62 /** \brief sets the child nodes */
63 void setChildren(const QVector<QVector<JKQTMathTextNode*> >& children);
64 /** \copydoc horizontalLineBottomRow */
65 void setRowBottomLine(int col, LineType line);
66 /** \copydoc horizontalLineTop */
67 void setTopLine(LineType line);
68 /** \copydoc JKQTMathTextNode::getTypeName() */
69 virtual QString getTypeName() const override;
70 /** \copydoc JKQTMathTextNode::draw() */
71 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
72 /** \copydoc JKQTMathTextNode::toHtml() */
73 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
74 /** \brief returns the child nodes */
75 QVector<QVector<JKQTMathTextNode*> > getChildrenMatrix() const;
76 /** \copydoc columns */
77 int getColumns() const;
78 /** \copydoc lines */
79 int getLines() const;
80 /** \copydoc JKQTMathTextMultiChildNode::getChildren() */
81 virtual QList<JKQTMathTextNode*> getChildren() override;
82 /** \copydoc JKQTMathTextMultiChildNode::childCount() */
83 virtual int childCount() const override;
84 /** \copydoc JKQTMathTextMultiChildNode::clearChildren() */
85 virtual void clearChildren(bool deleteChildren=true) override;
86 /** \copydoc JKQTMathTextMultiChildNode::deleteChild() */
87 virtual void deleteChild(int i) override;
88 /** \copydoc JKQTMathTextMultiChildNode::getChild() */
89 virtual JKQTMathTextNode* getChild(int i) override;
90 /** \copydoc JKQTMathTextMultiChildNode::getChild() */
91 virtual const JKQTMathTextNode* getChild(int i) const override;
92 /** \copydoc JKQTMathTextMultiChildNode::getChild() */
93 virtual JKQTMathTextNode* replaceChild(int i, JKQTMathTextNode* newChild) override;
94 protected:
95 /** \brief describes the layout of the whole node */
98 /** \brief widths of the columns */
99 QVector<double> colwidth;
100 /** \brief widths of the cells */
101 QVector<QVector<double> > cellwidth;
102 inline double& getCellwidth(int line, int col) {
103 return cellwidth[line].operator[](col);
104 }
105 inline const double& getCellwidth(int line, int col) const {
106 return cellwidth[line].operator[](col);
107 }
108 /** \brief heights of the rows */
109 QVector<double> rowheight;
110 /** \brief ascents of the rows */
111 QVector<double> rowascent;
116
117 };
118 /** \brief calclates the layout of the whole block/node
119 *
120 * \note This function does NOT call transformEnvironment();
121 * it has to be called before calling this!
122 */
123 LayoutInfo calcLayout(QPainter& painter, const JKQTMathTextEnvironment& currentEv) const;
124 /** \copydoc JKQTMathTextNode::getSizeInternal() */
125 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
126 /** \copydoc JKQTMathTextNode::setDrawBoxes() */
127 virtual void setDrawBoxes(bool draw) override;
128 /** \brief child nodes making up the matrix, vector of rows */
129 QVector<QVector<JKQTMathTextNode*> > children;
130 /** \brief alignment of the columns */
131 QVector<JKQTMathTextHorizontalAlignment> columnAlignment;
132 /** \brief lines to the right of each column */
133 QMap<int,LineType> verticalLineRHSColumn;
134 /** \brief line at the left of the table */
136 /** \brief lines to the bottom of each row */
137 QMap<int,LineType> horizontalLineBottomRow;
138 /** \brief line at the top of the table */
140
141 /** \brief number of columns in the matrix */
143 /** \brief number of rows in the matrix */
144 int lines;
145
146 /** \brief draw a vertical line starting at pixel position (\a x, \a y ) with length \a height, using linetype \a lt, width \a linewidth and \a color */
147 static void drawVLine(QPainter& painter, double x, double y, double height, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation);
148 /** \brief draw a horizontal line starting at pixel position (\a x, \a y ) with length \a width, using linetype \a lt, width \a linewidth and \a color */
149 static void drawHLine(QPainter& painter, double x, double y, double width, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation);
150 /** \brief parses a column specifier */
151 void parseColumnSpec(const QString& columnspec);
152 /** \copydoc JKQTMathTextMultiChildNode::clearChildren() */
153 void clearChildrenImpl(bool deleteChildren);
154};
155
156#endif // JKQTMATHTEXTMATRIXNODE_H
157
158
159
160
161
162
163
164
165
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
subclass representing a \begin{matrix} , \begin{tabular} , \begin{array} , ... node
Definition jkqtmathtextmatrixnode.h:47
void setTopLine(LineType line)
line at the top of the table
void parseColumnSpec(const QString &columnspec)
parses a column specifier
virtual void clearChildren(bool deleteChildren=true) override
clear all children, deleting them if deleteChildren==true
LayoutInfo calcLayout(QPainter &painter, const JKQTMathTextEnvironment &currentEv) const
calclates the layout of the whole block/node
QVector< QVector< JKQTMathTextNode * > > children
child nodes making up the matrix, vector of rows
Definition jkqtmathtextmatrixnode.h:129
virtual QString getTypeName() const override
return the name of this class as a string
JKQTMathTextMatrixNode(JKQTMathText *parent, const QString &columnSpec=QString())
LineType horizontalLineTop
line at the top of the table
Definition jkqtmathtextmatrixnode.h:139
void clearChildrenImpl(bool deleteChildren)
clear all children, deleting them if deleteChildren==true
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
int lines
number of rows in the matrix
Definition jkqtmathtextmatrixnode.h:144
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
virtual void setDrawBoxes(bool draw) override
enables the drawing of colored boxes (for DEBUGGING) around the actual output of the node
QVector< QVector< JKQTMathTextNode * > > getChildrenMatrix() const
returns the child nodes
virtual void deleteChild(int i) override
delete the i-th child
LineType
types of lines
Definition jkqtmathtextmatrixnode.h:50
@ LTnone
noline
Definition jkqtmathtextmatrixnode.h:51
@ LTheavyline
heavier/thick line
Definition jkqtmathtextmatrixnode.h:54
@ LTline
single line
Definition jkqtmathtextmatrixnode.h:52
@ LTdoubleDashed
double dashed line
Definition jkqtmathtextmatrixnode.h:56
@ LTdashed
single dashed line
Definition jkqtmathtextmatrixnode.h:55
@ LTdoubleline
double line
Definition jkqtmathtextmatrixnode.h:53
void setRowBottomLine(int col, LineType line)
lines to the bottom of each row
LineType verticalLineLeft
line at the left of the table
Definition jkqtmathtextmatrixnode.h:135
static void drawVLine(QPainter &painter, double x, double y, double height, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation)
draw a vertical line starting at pixel position (x, y ) with length height, using linetype lt,...
virtual int childCount() const override
returns the number of child nodes
QMap< int, LineType > verticalLineRHSColumn
lines to the right of each column
Definition jkqtmathtextmatrixnode.h:133
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
static void drawHLine(QPainter &painter, double x, double y, double width, LineType lt, double linewidth, double linewidthHeavy, QColor color, double doublelineseparation)
draw a horizontal line starting at pixel position (x, y ) with length width, using linetype lt,...
virtual ~JKQTMathTextMatrixNode() override
int columns
number of columns in the matrix
Definition jkqtmathtextmatrixnode.h:142
virtual JKQTMathTextNode * replaceChild(int i, JKQTMathTextNode *newChild) override
returns the i-th child node
virtual JKQTMathTextNode * getChild(int i) override
returns the i-th child node
QVector< JKQTMathTextHorizontalAlignment > columnAlignment
alignment of the columns
Definition jkqtmathtextmatrixnode.h:131
void setChildren(const QVector< QVector< JKQTMathTextNode * > > &children)
sets the child nodes
QMap< int, LineType > horizontalLineBottomRow
lines to the bottom of each row
Definition jkqtmathtextmatrixnode.h:137
JKQTMathTextMatrixNode(JKQTMathText *parent, const QVector< QVector< JKQTMathTextNode * > > &children, const QString &columnSpec=QString())
virtual const JKQTMathTextNode * getChild(int i) const override
returns the i-th child node
int getLines() const
number of rows in the matrix
int getColumns() const
number of columns in the matrix
virtual QList< JKQTMathTextNode * > getChildren() override
returns a list of all child node
subclass representing a node in the syntax tree, that has two children
Definition jkqtmathtextnode.h:202
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
describes the layout of the whole node
Definition jkqtmathtextmatrixnode.h:96
double bottomPadding
Definition jkqtmathtextmatrixnode.h:115
QVector< double > rowascent
ascents of the rows
Definition jkqtmathtextmatrixnode.h:111
QVector< QVector< double > > cellwidth
widths of the cells
Definition jkqtmathtextmatrixnode.h:101
const double & getCellwidth(int line, int col) const
Definition jkqtmathtextmatrixnode.h:105
double topPadding
Definition jkqtmathtextmatrixnode.h:114
QVector< double > colwidth
widths of the columns
Definition jkqtmathtextmatrixnode.h:99
QVector< double > rowheight
heights of the rows
Definition jkqtmathtextmatrixnode.h:109
double leftPadding
Definition jkqtmathtextmatrixnode.h:112
double & getCellwidth(int line, int col)
Definition jkqtmathtextmatrixnode.h:102
double rightPadding
Definition jkqtmathtextmatrixnode.h:113
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393