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
jkqtmathtextboxinstructionnode.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 JKQTMATHTEXTBOXINSTRUCTIONNODE_H
25#define JKQTMATHTEXTBOXINSTRUCTIONNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include "jkqtmathtext/nodes/jkqtmathtextinstructionnode.h"
30#include <QPainter>
31#include <functional>
32
33class JKQTMathText; // forward
34// JKQTMATHTEXT_LIB_EXPORT
35
36
37/** \brief subclass representing an instruction node which draws a (possibly colored) box around it's contents
38 * i.e. it represents instructions like \c \\fbox{...}, \c \\colorbox{color}{...}, ...
39 * \ingroup jkqtmathtext_items
40 */
42 public:
43 explicit JKQTMathTextBoxInstructionNode(JKQTMathText* parent, const QString& name, JKQTMathTextNode* child, const QStringList& parameters=QStringList());
45 /** \copydoc JKQTMathTextNode::getTypeName() */
46 virtual QString getTypeName() const override;
47 /** \copydoc JKQTMathTextNode::draw() */
48 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
49 /** \copydoc JKQTMathTextNode::toHtml() */
50 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
51
52 /** \brief returns true, if the given \a instructionName can be represented by this node
53 * \see instructions
54 */
55 static bool supportsInstructionName(const QString& instructionName);
56 /** \brief returns the number of additional string parameters, required for the given \a instructionName
57 * \see instructions
58 */
59 static size_t countParametersOfInstruction(const QString& instructionName);
60 /** \brief sets \a insideMath to \c true if inside the node is to be parsed in math mode and \c false else
61 * \see instructions
62 */
63 static void modifyInMathEnvironment(const QString& instructionName, bool& insideMath, bool &insideMathTextStyle, const QStringList &params=QStringList());
64 protected:
65 /** \copydoc JKQTMathTextNode::getSizeInternal() */
66 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
67 /** \brief set all properties in \a ev, as appropriate for the represented instruction */
69
70 /** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
72 /** \brief this functor implements the instruction */
73 typedef std::function<void(JKQTMathTextEnvironment& ev, const QStringList& parameters)> ModifyEnvironmentFunctor;
75 /** \brief this functor returns the QPen to use for the box outline */
76 typedef std::function<QPen(JKQTMathTextEnvironment& ev, const QStringList& parameters, JKQTMathText* parent)> GetBoxPenFunctor;
77 /** \brief generates a QPen with the lineWidth associated with the QFont of the environment (using QFontMetricsF::lineWidth() ) */
79 /** \brief generates an invisible pen with 0 width */
81 /** \brief this functor returns the QBrush to use for the box fill */
82 typedef std::function<QBrush(JKQTMathTextEnvironment& ev, const QStringList& parameters, JKQTMathText* parent)> GetBoxBrushFunctor;
83 /** \brief generates an invisible QBrush */
85 /** \brief default padding factor 0.5 xWidth */
86 static double DefaultPadding;
87 /** \brief default constructor, creates a NOP-instruction that does nothing */
89 /** \brief constructor */
90 InstructionProperties(const ModifyEnvironmentFunctor& _modifier, const GetBoxPenFunctor& _pen, const GetBoxBrushFunctor& _brush, double _paddingFactor=DefaultPadding, size_t _NParams=0);
91 /** \brief constructor */
92 InstructionProperties(const GetBoxPenFunctor& _pen, const GetBoxBrushFunctor& _brush, double _paddingFactor=DefaultPadding, size_t _NParams=0);
93 /** \brief number of parameters for this node */
94 size_t NParams;
95 /** \brief functor that modifies a JKQTMathTextEnvironment */
97 /** \brief functor that creates a QPen for the box outline */
99 /** \brief functor that creates a QBrush for the box fill */
101 /** \brief padding of the box, as a factor to xWidth of the current font */
103 /** \brief draw a double-line */
105 /** \brief rounding radius (rx=ry) of the box, as a factor to xWidth of the current font */
107 };
108
109 /** \brief defines all implemented instructions in this node
110 *
111 * \note this is the customization point for new instructions!
112 */
113 static const QHash<QString, InstructionProperties>& instructions();
114};
115
116
117
118
119
120#endif // JKQTMATHTEXTBOXINSTRUCTIONNODE_H
121
122
123
124
125
126
127
128
129
subclass representing an instruction node which draws a (possibly colored) box around it's contents i...
Definition jkqtmathtextboxinstructionnode.h:41
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
static size_t countParametersOfInstruction(const QString &instructionName)
returns the number of additional string parameters, required for the given instructionName
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
static const QHash< QString, InstructionProperties > & instructions()
defines all implemented instructions in this node
static bool supportsInstructionName(const QString &instructionName)
returns true, if the given instructionName can be represented by this node
JKQTMathTextBoxInstructionNode(JKQTMathText *parent, const QString &name, JKQTMathTextNode *child, const QStringList &parameters=QStringList())
virtual QString getTypeName() const override
return the name of this class as a string
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
virtual ~JKQTMathTextBoxInstructionNode() override
static void modifyInMathEnvironment(const QString &instructionName, bool &insideMath, bool &insideMathTextStyle, const QStringList &params=QStringList())
sets insideMath to true if inside the node is to be parsed in math mode and false else
bool setupMTenvironment(JKQTMathTextEnvironment &ev) const
set all properties in ev, as appropriate for the represented instruction
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
subclass representing an instruction node with exactly one argument and possibly additional parameter...
Definition jkqtmathtextinstructionnode.h:45
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionN...
Definition jkqtmathtextboxinstructionnode.h:71
std::function< QBrush(JKQTMathTextEnvironment &ev, const QStringList &parameters, JKQTMathText *parent)> GetBoxBrushFunctor
this functor returns the QBrush to use for the box fill
Definition jkqtmathtextboxinstructionnode.h:82
ModifyEnvironmentFunctor modifier
functor that modifies a JKQTMathTextEnvironment
Definition jkqtmathtextboxinstructionnode.h:96
double paddingFactor
padding of the box, as a factor to xWidth of the current font
Definition jkqtmathtextboxinstructionnode.h:102
static ModifyEnvironmentFunctor NoModification
Definition jkqtmathtextboxinstructionnode.h:74
InstructionProperties(const ModifyEnvironmentFunctor &_modifier, const GetBoxPenFunctor &_pen, const GetBoxBrushFunctor &_brush, double _paddingFactor=DefaultPadding, size_t _NParams=0)
constructor
static GetBoxBrushFunctor NoBrush
generates an invisible QBrush
Definition jkqtmathtextboxinstructionnode.h:84
static GetBoxPenFunctor NoPen
generates an invisible pen with 0 width
Definition jkqtmathtextboxinstructionnode.h:80
InstructionProperties(const GetBoxPenFunctor &_pen, const GetBoxBrushFunctor &_brush, double _paddingFactor=DefaultPadding, size_t _NParams=0)
constructor
size_t NParams
number of parameters for this node
Definition jkqtmathtextboxinstructionnode.h:94
std::function< void(JKQTMathTextEnvironment &ev, const QStringList &parameters)> ModifyEnvironmentFunctor
this functor implements the instruction
Definition jkqtmathtextboxinstructionnode.h:73
static double DefaultPadding
default padding factor 0.5 xWidth
Definition jkqtmathtextboxinstructionnode.h:86
static GetBoxPenFunctor DefaultPen
generates a QPen with the lineWidth associated with the QFont of the environment (using QFontMetricsF...
Definition jkqtmathtextboxinstructionnode.h:78
bool doubleLine
draw a double-line
Definition jkqtmathtextboxinstructionnode.h:104
std::function< QPen(JKQTMathTextEnvironment &ev, const QStringList &parameters, JKQTMathText *parent)> GetBoxPenFunctor
this functor returns the QPen to use for the box outline
Definition jkqtmathtextboxinstructionnode.h:76
GetBoxPenFunctor pen
functor that creates a QPen for the box outline
Definition jkqtmathtextboxinstructionnode.h:98
GetBoxBrushFunctor brush
functor that creates a QBrush for the box fill
Definition jkqtmathtextboxinstructionnode.h:100
double roundingFactor
rounding radius (rx=ry) of the box, as a factor to xWidth of the current font
Definition jkqtmathtextboxinstructionnode.h:106
InstructionProperties()
default constructor, creates a NOP-instruction that does nothing
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393