mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
JKQTMathText: improve documentation (fixes issue #74), add new draw()-variant, which accepts a QPointF
This commit is contained in:
parent
0f958cc2d6
commit
9a13e5127a
BIN
doc/images/jkqtmathtext/jkqtmathtext_draw_flags.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_draw_flags.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
doc/images/jkqtmathtext/jkqtmathtext_drawboxes.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_drawboxes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -251,11 +251,11 @@ TestForm::TestForm(QWidget *parent) :
|
|||||||
ui->cmbFont->setCurrentIndex(1);
|
ui->cmbFont->setCurrentIndex(1);
|
||||||
|
|
||||||
connect(ui->chkBoxes, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
connect(ui->chkBoxes, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
||||||
|
connect(ui->chkBigBox, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
||||||
connect(ui->chkAntiAlias, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
connect(ui->chkAntiAlias, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
||||||
connect(ui->chkAntiAliasHQ, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
|
||||||
connect(ui->chkAntiAliasText, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
connect(ui->chkAntiAliasText, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
||||||
connect(ui->chkSmoothTransform, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
|
||||||
connect(ui->chkSimulateBlackboard, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
connect(ui->chkSimulateBlackboard, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
|
||||||
|
connect(ui->cmbLastAlign, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbScript, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbScript, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbTestset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbTestset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
@ -309,15 +309,17 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTMathText& mt,
|
|||||||
durationSizingMS=ht.getTime()/1000.0;
|
durationSizingMS=ht.getTime()/1000.0;
|
||||||
qDebug()<<" sizing in "<<durationSizingMS<<" ms\n";
|
qDebug()<<" sizing in "<<durationSizingMS<<" ms\n";
|
||||||
QPen p=painter.pen();
|
QPen p=painter.pen();
|
||||||
p.setColor("lightcoral");
|
if (ui->chkBigBox->isChecked()) {
|
||||||
p.setStyle(Qt::DashLine);
|
p.setColor("lightcoral");
|
||||||
p.setWidth(2);
|
p.setStyle(Qt::DashLine);
|
||||||
painter.setPen(p);
|
p.setWidth(2);
|
||||||
QRectF r(X, Y-mt.getAscent(painter),s.width(), s.height());
|
painter.setPen(p);
|
||||||
painter.drawRect(r);
|
QRectF r(X, Y-mt.getAscent(painter),s.width(), s.height());
|
||||||
p.setColor("lightblue");
|
painter.drawRect(r);
|
||||||
painter.setPen(p);
|
p.setColor("lightblue");
|
||||||
painter.drawLine(X, Y, X+s.width(), Y);
|
painter.setPen(p);
|
||||||
|
painter.drawLine(X, Y, X+s.width(), Y);
|
||||||
|
}
|
||||||
ht.start();
|
ht.start();
|
||||||
p.setStyle(Qt::SolidLine);
|
p.setStyle(Qt::SolidLine);
|
||||||
p.setWidth(1);
|
p.setWidth(1);
|
||||||
@ -341,6 +343,52 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTMathText& mt,
|
|||||||
return mt.getDescent(painter)+mt.getAscent(painter)+40;
|
return mt.getDescent(painter)+mt.getAscent(painter)+40;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double TestForm::drawAligned(QPainter& painter, double X, double YY, JKQTMathText& mt, QString name) {
|
||||||
|
|
||||||
|
|
||||||
|
double Y=YY;
|
||||||
|
painter.save();
|
||||||
|
ht.start();
|
||||||
|
const QSizeF s=mt.getSize(painter);
|
||||||
|
const QRectF rect(X, Y, s.width()+32, s.height()+32);
|
||||||
|
int flags=Qt::AlignLeft|Qt::AlignTop;
|
||||||
|
switch(ui->cmbLastAlign->currentIndex()) {
|
||||||
|
case 0: flags=Qt::AlignLeft|Qt::AlignTop; break;
|
||||||
|
case 1: flags=Qt::AlignLeft|Qt::AlignVCenter; break;
|
||||||
|
case 2: flags=Qt::AlignLeft|Qt::AlignBottom; break;
|
||||||
|
case 3: flags=Qt::AlignHCenter|Qt::AlignTop; break;
|
||||||
|
case 4: flags=Qt::AlignHCenter|Qt::AlignVCenter; break;
|
||||||
|
case 5: flags=Qt::AlignHCenter|Qt::AlignBottom; break;
|
||||||
|
case 6: flags=Qt::AlignRight|Qt::AlignTop; break;
|
||||||
|
case 7: flags=Qt::AlignRight|Qt::AlignVCenter; break;
|
||||||
|
case 8: flags=Qt::AlignRight|Qt::AlignBottom; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPen p=painter.pen();
|
||||||
|
p.setColor("darkred");
|
||||||
|
p.setStyle(Qt::SolidLine);
|
||||||
|
p.setWidth(2);
|
||||||
|
painter.setPen(p);
|
||||||
|
painter.drawRect(rect);
|
||||||
|
p.setStyle(Qt::SolidLine);
|
||||||
|
p.setWidth(1);
|
||||||
|
p.setColor("black");
|
||||||
|
painter.setPen(p);
|
||||||
|
mt.draw(painter, flags, rect, ui->chkBoxes->isChecked());
|
||||||
|
p.setColor("blue");
|
||||||
|
painter.setPen(p);
|
||||||
|
|
||||||
|
QFont f;
|
||||||
|
f.setFamily("sans serif");
|
||||||
|
f.setUnderline(true);
|
||||||
|
f.setPointSize(10);
|
||||||
|
painter.setFont(f);
|
||||||
|
painter.drawText(X, Y-6, name+":");
|
||||||
|
painter.restore();
|
||||||
|
qDebug()<<name<<": width="<<s.width()<<" height="<<s.height()<<" ascent="<<mt.getAscent(painter)<<" descent="<<mt.getDescent(painter);
|
||||||
|
return rect.bottom()+40;
|
||||||
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *TestForm::createTree(JKQTMathTextNode *node, QTreeWidgetItem* parent)
|
QTreeWidgetItem *TestForm::createTree(JKQTMathTextNode *node, QTreeWidgetItem* parent)
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
@ -469,11 +517,7 @@ void TestForm::updateMath()
|
|||||||
|
|
||||||
painter.begin(&pix);
|
painter.begin(&pix);
|
||||||
if (ui->chkAntiAlias->isChecked()) painter.setRenderHint(QPainter::Antialiasing);
|
if (ui->chkAntiAlias->isChecked()) painter.setRenderHint(QPainter::Antialiasing);
|
||||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
|
||||||
if (ui->chkAntiAliasHQ->isChecked()) painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
|
||||||
#endif
|
|
||||||
if (ui->chkAntiAliasText->isChecked()) painter.setRenderHint(QPainter::TextAntialiasing);
|
if (ui->chkAntiAliasText->isChecked()) painter.setRenderHint(QPainter::TextAntialiasing);
|
||||||
if (ui->chkSmoothTransform->isChecked()) painter.setRenderHint(QPainter::QPainter::SmoothPixmapTransform);
|
|
||||||
ht.start();
|
ht.start();
|
||||||
|
|
||||||
|
|
||||||
@ -525,7 +569,7 @@ void TestForm::updateMath()
|
|||||||
QStringList sl=ui->edtSizes->text().split(",");
|
QStringList sl=ui->edtSizes->text().split(",");
|
||||||
ui->labRenderTimes->setText("");
|
ui->labRenderTimes->setText("");
|
||||||
|
|
||||||
for (int i=0; i<sl.size(); i++) {
|
for (int i=0; i<sl.size()-1; i++) {
|
||||||
bool ok=true;
|
bool ok=true;
|
||||||
int size=sl[i].trimmed().toUInt(&ok);
|
int size=sl[i].trimmed().toUInt(&ok);
|
||||||
if (!ok) size=10+i*5;
|
if (!ok) size=10+i*5;
|
||||||
@ -552,6 +596,14 @@ void TestForm::updateMath()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sl.size()>0) {
|
||||||
|
bool ok=true;
|
||||||
|
int size=sl.last().trimmed().toUInt(&ok);
|
||||||
|
if (!ok) size=font().pointSizeF();
|
||||||
|
mt.setFontSize(size);
|
||||||
|
Y+=drawAligned(painter, X1, Y, mt, QString("%1, %2pt, align: %3").arg(ui->cmbTestset->currentText()).arg(size).arg(ui->cmbLastAlign->currentText()));
|
||||||
|
}
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class TestForm : public QWidget
|
|||||||
Ui::TestForm *ui;
|
Ui::TestForm *ui;
|
||||||
JKQTPHighResTimer ht;
|
JKQTPHighResTimer ht;
|
||||||
double draw(QPainter& painter, double X, double YY, JKQTMathText& mt, QString name, double &durationSizingMS, double &durationTimingMS, QStringList *lstErrors=nullptr);
|
double draw(QPainter& painter, double X, double YY, JKQTMathText& mt, QString name, double &durationSizingMS, double &durationTimingMS, QStringList *lstErrors=nullptr);
|
||||||
|
double drawAligned(QPainter& painter, double X, double YY, JKQTMathText& mt, QString name);
|
||||||
|
|
||||||
QTreeWidgetItem* createTree(JKQTMathTextNode* node, QTreeWidgetItem *parent=NULL);
|
QTreeWidgetItem* createTree(JKQTMathTextNode* node, QTreeWidgetItem *parent=NULL);
|
||||||
};
|
};
|
||||||
|
@ -588,7 +588,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,2,0,2,0,0,1,0,0,0,0,0">
|
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,2,0,2,0,0,1,0,0,0,0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -685,7 +685,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="edtSizes">
|
<widget class="QLineEdit" name="edtSizes">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>90,30,20,10</string>
|
<string>90,30,20,10,12</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -699,6 +699,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="chkBigBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>big-box</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="chkAntiAlias">
|
<widget class="QCheckBox" name="chkAntiAlias">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -709,13 +719,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="chkAntiAliasHQ">
|
|
||||||
<property name="text">
|
|
||||||
<string>HQ anti-aliase</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="chkAntiAliasText">
|
<widget class="QCheckBox" name="chkAntiAliasText">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -726,13 +729,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="chkSmoothTransform">
|
|
||||||
<property name="text">
|
|
||||||
<string>smooth transform</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -746,6 +742,62 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>last-align</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cmbLastAlign">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>lt</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>lc</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>lb</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ct</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>cc</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>cb</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>rt</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>rc</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>rb</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="1">
|
<item row="9" column="1">
|
||||||
|
@ -1648,6 +1648,11 @@ void JKQTMathText::getSizeDetail(QPainter& painter, double& width, double& ascen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JKQTMathText::draw(QPainter &painter, QPointF x, bool drawBoxes)
|
||||||
|
{
|
||||||
|
draw(painter, x.x(), x.y(), drawBoxes);
|
||||||
|
}
|
||||||
|
|
||||||
void JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes){
|
void JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes){
|
||||||
if (getNodeTree()!=nullptr) {
|
if (getNodeTree()!=nullptr) {
|
||||||
JKQTMathTextEnvironment ev;
|
JKQTMathTextEnvironment ev;
|
||||||
|
@ -253,11 +253,36 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
|||||||
double getAscent(QPainter& painter);
|
double getAscent(QPainter& painter);
|
||||||
/** \brief return the detailes sizes of the text */
|
/** \brief return the detailes sizes of the text */
|
||||||
void getSizeDetail(QPainter& painter, double& width, double& ascent, double& descent, double& strikeoutPos);
|
void getSizeDetail(QPainter& painter, double& width, double& ascent, double& descent, double& strikeoutPos);
|
||||||
/** \brief draw a representation to the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> object at the specified position */
|
/** \brief draw a representation to the object at the specified position \a x , \a y
|
||||||
void draw(QPainter& painter, double x, double y, bool drawBoxes=false);
|
|
||||||
/** \brief overloaded version of draw(QPainter& painter, double x, double y).
|
|
||||||
*
|
*
|
||||||
* This version draws the text inside the given rectangle according to the specified flags.
|
* \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
|
||||||
|
* \param x position of the left border of the text/expression to be drawn (see sketch below)
|
||||||
|
* \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
|
||||||
|
*
|
||||||
|
* Here is an illustration of the geometry of the drawn text/expression:
|
||||||
|
* \image html jkqtmathtext/jkqtmathtext_node_geo.png
|
||||||
|
*/
|
||||||
|
void draw(QPainter& painter, QPointF x, bool drawBoxes=false);
|
||||||
|
/** \brief draw a representation to the object at the specified position \a x , \a y
|
||||||
|
*
|
||||||
|
* \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
|
||||||
|
* \param x x-position of the left border of the text/expression to be drawn (see sketch below)
|
||||||
|
* \param y y-position of the baseline of the text/expression to be drawn (see sketch below)
|
||||||
|
* \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
|
||||||
|
*
|
||||||
|
* Here is an illustration of the geometry of the drawn text/expression:
|
||||||
|
* \image html jkqtmathtext/jkqtmathtext_node_geo.png
|
||||||
|
*/
|
||||||
|
void draw(QPainter& painter, double x, double y, bool drawBoxes=false);
|
||||||
|
/** \brief draw into a rectangle \a rect with alignment defined in \a flags (see below)
|
||||||
|
*
|
||||||
|
* \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
|
||||||
|
* \param rect rectangle to draw the text/expression into (see sketch below)
|
||||||
|
* \param flags alignment within \a rect (see below), use e.g. \c Qt::AlignHCenter|Qt::AlignVCenter to center the expression inside \a rect
|
||||||
|
* \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
|
||||||
|
*
|
||||||
|
* These options are interpreted for \a flags (dark-red is the rectangle \a rect):
|
||||||
|
* \image html jkqtmathtext/jkqtmathtext_draw_flags.png
|
||||||
*/
|
*/
|
||||||
void draw(QPainter& painter, unsigned int flags, QRectF rect, bool drawBoxes=false);
|
void draw(QPainter& painter, unsigned int flags, QRectF rect, bool drawBoxes=false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user