mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +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);
|
||||
|
||||
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->chkAntiAliasHQ, 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->cmbLastAlign, 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->cmbTestset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||
@ -309,6 +309,7 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTMathText& mt,
|
||||
durationSizingMS=ht.getTime()/1000.0;
|
||||
qDebug()<<" sizing in "<<durationSizingMS<<" ms\n";
|
||||
QPen p=painter.pen();
|
||||
if (ui->chkBigBox->isChecked()) {
|
||||
p.setColor("lightcoral");
|
||||
p.setStyle(Qt::DashLine);
|
||||
p.setWidth(2);
|
||||
@ -318,6 +319,7 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTMathText& mt,
|
||||
p.setColor("lightblue");
|
||||
painter.setPen(p);
|
||||
painter.drawLine(X, Y, X+s.width(), Y);
|
||||
}
|
||||
ht.start();
|
||||
p.setStyle(Qt::SolidLine);
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
QString name;
|
||||
@ -469,11 +517,7 @@ void TestForm::updateMath()
|
||||
|
||||
painter.begin(&pix);
|
||||
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->chkSmoothTransform->isChecked()) painter.setRenderHint(QPainter::QPainter::SmoothPixmapTransform);
|
||||
ht.start();
|
||||
|
||||
|
||||
@ -525,7 +569,7 @@ void TestForm::updateMath()
|
||||
QStringList sl=ui->edtSizes->text().split(",");
|
||||
ui->labRenderTimes->setText("");
|
||||
|
||||
for (int i=0; i<sl.size(); i++) {
|
||||
for (int i=0; i<sl.size()-1; i++) {
|
||||
bool ok=true;
|
||||
int size=sl[i].trimmed().toUInt(&ok);
|
||||
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();
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@ class TestForm : public QWidget
|
||||
Ui::TestForm *ui;
|
||||
JKQTPHighResTimer ht;
|
||||
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);
|
||||
};
|
||||
|
@ -588,7 +588,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<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>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
@ -685,7 +685,7 @@
|
||||
<item>
|
||||
<widget class="QLineEdit" name="edtSizes">
|
||||
<property name="text">
|
||||
<string>90,30,20,10</string>
|
||||
<string>90,30,20,10,12</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -699,6 +699,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QCheckBox" name="chkAntiAlias">
|
||||
<property name="text">
|
||||
@ -709,13 +719,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkAntiAliasHQ">
|
||||
<property name="text">
|
||||
<string>HQ anti-aliase</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkAntiAliasText">
|
||||
<property name="text">
|
||||
@ -726,13 +729,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkSmoothTransform">
|
||||
<property name="text">
|
||||
<string>smooth transform</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@ -746,6 +742,62 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</item>
|
||||
<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){
|
||||
if (getNodeTree()!=nullptr) {
|
||||
JKQTMathTextEnvironment ev;
|
||||
|
@ -253,11 +253,36 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
double getAscent(QPainter& painter);
|
||||
/** \brief return the detailes sizes of the text */
|
||||
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 */
|
||||
void draw(QPainter& painter, double x, double y, bool drawBoxes=false);
|
||||
/** \brief overloaded version of draw(QPainter& painter, double x, double y).
|
||||
/** \brief draw a representation to the object at the specified position \a x , \a 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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user