";
+ } else if (alignment==MTHARight) {
+ html+="
";
+ }
+ }
+ html+="
";
+ html+=textTransform(text, currentEv).toHtmlEscaped();
+ html+="
";
+ if (isMultiLine) html+="
";
+ html+=currentEv.toHtmlAfter(defaultEv, parentMathText);
+ return true;
+}
+
+void JKQTMathTextVerbatimNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, const JKQTMathTextNodeSize *prevNodeSize)
+{
+ transformEnvironment(currentEv);
+ const LayoutInfo l=calcLayout(painter, currentEv);
+ width=l.width;
+ overallHeight=l.overallHeight;
+ baselineHeight=l.baselineHeight;
+ strikeoutPos=l.strikeoutPos;
+}
+
+void JKQTMathTextVerbatimNode::transformEnvironment(JKQTMathTextEnvironment ¤tEv) const
+{
+ currentEv.font=MTEtypewriter;
+}
+
+JKQTMathTextVerbatimNode::LayoutInfo JKQTMathTextVerbatimNode::calcLayout(QPainter &painter, const JKQTMathTextEnvironment& currentEv) const
+{
+ LayoutInfo l;
+ QFont f=currentEv.getFont(parentMathText);
+ f.setStyleStrategy(QFont::PreferDefault);
+ f.setFixedPitch(true);
+ const QFontMetricsF fm(f);
+ const double linespacing=fm.lineSpacing()*lineSpacingFactor;
+ const double fleading=fm.leading();
+ const double synLeading=fm.lineWidth();
+ const double lineLeading=((fabs(fleading)>1e-6)?fleading:synLeading)*lineSpacingFactor;
+
+ if (text.size()<=0) {
+ return l;
+ }
+ l.lines=textTransform(text, currentEv).split('\n');
+
+ // from now on we have at least one child node!!!
+
+ QList
widths, heights, ascents, descents, strikeouts;
+ double heightSum=0;
+ QList ysFromFirstLine; // y-position of each line, where the first line is always at y=0 (i.e. ysFromFirstLine[0]==0)
+ double y=0;
+ for (int i=0; i0) {
+ const double deltaLine=qMax(linespacing, descents.last()+lineLeading+fm.ascent());
+ heightSum=heightSum+deltaLine;
+ y=y+deltaLine;
+ }
+ widths<)
with contributions from: Razi Alavizadeh
@@ -32,19 +32,50 @@ class JKQTMathText; // forward
// JKQTMATHTEXT_LIB_EXPORT
+/** \brief base class for nodes representing text in the syntax tree
+ * \ingroup jkqtmathtext_items
+ *
+ * This node is a collection of tools, necessary to draw text. It
+ * is the base for nodes, such as:
+ * - JKQTMathTextTextNode
+ * - JKQTMathTextVerbatimNode
+ * .
+ */
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextBaseNode: public JKQTMathTextNode {
+ public:
+ explicit JKQTMathTextTextBaseNode(JKQTMathText* parent, const QString& text);
+ virtual ~JKQTMathTextTextBaseNode() override;
+ /** \copydoc JKQTMathTextNode::toHtml() */
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ /** \copydoc text */
+ QString getText() const;
+ protected:
+ /** \brief text-contents of the node */
+ QString text;
+ /** \brief draw a given \a txt in the font defined by \a currentEv at (\a x , \a y ) using the given \a painter
+ *
+ * This function implements drawing of synthesized fonts, e.g. MTEblackboard when JKQTMathText::isFontBlackboardSimulated() is \c true .
+ */
+ void drawString(QPainter& painter, const JKQTMathTextEnvironment& currentEv, double x, double y, const QString& txt) const;
+ /** \brief draw a given \a txt in the font \a f using additional informaion (but not currentEv::getFont() ) from \a currentEv at (\a x , \a y ) using the given \a painter
+ *
+ * This function implements drawing of synthesized fonts, e.g. MTEblackboard when JKQTMathText::isFontBlackboardSimulated() is \c true .
+ */
+ void drawString(QPainter& painter, const JKQTMathTextEnvironment ¤tEv, const QFont& f, double x, double y, const QString& txt) const;
+ /** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
+ virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const;
+};
+
+
/** \brief subclass representing one text node in the syntax tree
* \ingroup jkqtmathtext_items
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode: public JKQTMathTextTextBaseNode {
public:
explicit JKQTMathTextTextNode(JKQTMathText* parent, const QString& text, bool addWhitespace, bool stripInnerWhitepace=false);
virtual ~JKQTMathTextTextNode() override;
/** \copydoc JKQTMathTextNode::draw() */
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- /** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc text */
- QString getText() const;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
protected:
@@ -52,27 +83,86 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode: public JKQTMathTextNode {
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \brief calculates the size of the node, much like JKQTMathTextNode::getSizeInternal(), but returns additional properties that can be reused for drawing */
void getSizeInternalAndData(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, QStringList& textpart, QList& fontForcedUpright, QList& textpartXPos) ;
- /** \brief text-contents of the node */
- QString text;
/** \brief split text for Math-Mode into section with "normal" text and "forced upright" text */
static void splitTextForMathMode(const QString& txt, QStringList& textpart, QList& fontForcedUpright);
- /** \brief transforms the text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
- virtual QString textTransform(const QString& text, JKQTMathTextEnvironment currentEv, bool forSize=false);
+ /** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
+ virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const override;
};
-/** \brief subclass representing one text node in the syntax tree
+
+/** \brief subclass representing a verbatim (plain-text) node with support for line-breaks in the syntax tree
* \ingroup jkqtmathtext_items
+ *
+ * The layout of the lines can left-aligned, right-aligned or centered.
+ *
+ * \image html jkqtmathtext_verticallist.png
+ *
+ * \image html jkqtmathtext_verticalalignment.png
+ *
+ * \image html jkqtmathtext_horizontalalignment.png
*/
-class JKQTMATHTEXT_LIB_EXPORT MTplainTextNode: public JKQTMathTextTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerbatimNode: public JKQTMathTextTextBaseNode {
public:
- explicit MTplainTextNode(JKQTMathText* parent, const QString& text, bool addWhitespace, bool stripInnerWhitepace=false);
+ explicit JKQTMathTextVerbatimNode(JKQTMathText* parent, const QString& text, bool visibleWhitespace=false, JKQTMathTextHorizontalAlignment _alignment=MTHALeft, double _linespacingFactor=1.0, JKQTMathTextVerticalOrientation _verticalOrientation=MTVOFirstLine);
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
+ /** \copydoc alignment */
+ JKQTMathTextHorizontalAlignment getAlignment() const;
+ /** \copydoc verticalOrientation */
+ JKQTMathTextVerticalOrientation getVerticalOrientation() const;
+ /** \copydoc lineSpacingFactor */
+ double getLineSpacingFactor() const;
+ /** \copydoc visibleWhitespace */
+ bool getVisibleWhitespace() const;
+ /** \copydoc JKQTMathTextNode::draw() */
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
+ /** \copydoc JKQTMathTextNode::toHtml() */
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
protected:
- /** \copydoc JKQTMathTextTextNode::textTransform() */
- virtual QString textTransform(const QString& text, JKQTMathTextEnvironment currentEv, bool forSize=false) override;
+ /** \brief alignment scheme used to lay out all lines
+ *
+ * \image html jkqtmathtext_horizontalalignment.png
+ */
+ JKQTMathTextHorizontalAlignment alignment;
+ /** \brief spacing of the separate lines, as factor of the default line-spacing [Default: 1].
+ *
+ * This property can be used to move the lines closer together or farther apart.
+ *
+ * \image html jkqtmathtext_verticallist.png
+ */
+ double lineSpacingFactor;
+ /** \brief vertical orientation of the baseline of the whole block (with respect to the single lines)
+ *
+ * \image html jkqtmathtext_verticalorientation.png
+ */
+ JKQTMathTextVerticalOrientation verticalOrientation;
+ /** \brief when \c true, whitespaces are displayed with a visible character */
+ bool visibleWhitespace;
+
+ /** \copydoc JKQTMathTextNode::getSizeInternal() */
+ virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
+ /** \brief sets all necessary settings in \a currentEv for drawing this node */
+ virtual void transformEnvironment(JKQTMathTextEnvironment& currentEv) const;
+
+ /** \brief describes the layout of the whole node */
+ struct LayoutInfo: public JKQTMathTextNodeSize {
+ LayoutInfo();
+ /** \brief the text from JKQTMathTextVerbatimNode::text, split into lines */
+ QStringList lines;
+ /** \brief drawing position for each line */
+ QList X;
+ };
+ /** \brief calclates the layout of the whole block/node
+ *
+ * \note This function does NOT call transformEnvironment();
+ * it has to be called before calling this!
+ */
+ LayoutInfo calcLayout(QPainter& painter, const JKQTMathTextEnvironment& currentEv) const;
+ /** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
+ virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const override;
};
+
#endif // JKQTMATHTEXTTEXTNODE_H
diff --git a/lib/jkqtplotter/jkqtplotter.h b/lib/jkqtplotter/jkqtplotter.h
index c966c10c88..1dcb49d702 100644
--- a/lib/jkqtplotter/jkqtplotter.h
+++ b/lib/jkqtplotter/jkqtplotter.h
@@ -419,7 +419,7 @@ JKQTPLOTTER_LIB_EXPORT void initJKQTPlotterResources();
* \section JKQTPLOTTER_USEQTCREATOR How to use JKQTPlotter in the Qt Form Designer
*
* As JKQTPlotter is a standard Qt widget, you can also use it in Qt UI-files designed with the Qt From Designer (e.g. from within QTCreator).
- * For this to work you have to use the Promote QWidget"-feature of the form designer. The steps you need to take are detailed below:
+ * For this to work you have to use the Promote QWidget"-feature of the form designer. The steps you need to take are detailed below:
*
* - add a new UI-file to your project and open it in the Form Editor. Then right-click the form and select `Promote Widgets ...`:
*