mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
first round of Qt6 compatibility changes
This commit is contained in:
parent
e275651881
commit
4ded1a2028
@ -6,3 +6,7 @@ set(CMAKE_AUTOUIC ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGL REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGL REQUIRED)
|
||||
if(${QT_VERSION_MAJOR}>=6)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGLWidgets REQUIRED)
|
||||
|
||||
endif()
|
||||
|
@ -400,7 +400,9 @@ 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();
|
||||
|
@ -25,6 +25,12 @@
|
||||
#ifdef QT_XML_LIB
|
||||
# include <QtXml/QtXml>
|
||||
#endif
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
#include<QRegularExpression>
|
||||
#include<QRegularExpressionMatch>
|
||||
#else
|
||||
#include<QRegExp>
|
||||
#endif
|
||||
|
||||
const int JKQTPImageTools::PALETTE_ICON_WIDTH = 64;
|
||||
const int JKQTPImageTools::PALETTE_IMAGEICON_HEIGHT = 64;
|
||||
@ -2609,7 +2615,7 @@ JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUTLinInterpolate(const QMap<doub
|
||||
{
|
||||
QList<QPair<double, QRgb> > itemsi;
|
||||
for (auto it=items.begin(); it!=items.end(); ++it) {
|
||||
itemsi.append(qMakePair<double, QRgb>(it.key(), it.value()));
|
||||
itemsi.append(QPair<double, QRgb>(it.key(), it.value()));
|
||||
}
|
||||
return JKQTPBuildColorPaletteLUTLinInterpolateSorted(itemsi, lut_size);
|
||||
}
|
||||
@ -2618,7 +2624,7 @@ JKQTPImageTools::LUTType JKQTPBuildColorPaletteLUT(const QMap<double, QRgb> &ite
|
||||
{
|
||||
QList<QPair<double, QRgb> > itemsi;
|
||||
for (auto it=items.begin(); it!=items.end(); ++it) {
|
||||
itemsi.append(qMakePair<double, QRgb>(it.key(), it.value()));
|
||||
itemsi.append(QPair<double, QRgb>(it.key(), it.value()));
|
||||
}
|
||||
return JKQTPBuildColorPaletteLUTSorted(itemsi, lut_size);
|
||||
}
|
||||
@ -2820,26 +2826,48 @@ QVector<int> JKQTPImageTools::registerPalettesFromFile(const QString &filename,
|
||||
bool has4=false;
|
||||
bool rgb255=false;
|
||||
QList<QPair<double, QRgb> > pal;
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
QRegularExpression rx3("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", QRegularExpression::CaseInsensitiveOption|QRegularExpression::InvertedGreedinessOption);
|
||||
QRegularExpression rx4("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", QRegularExpression::CaseInsensitiveOption|QRegularExpression::InvertedGreedinessOption);
|
||||
#else
|
||||
QRegExp rx3("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", Qt::CaseInsensitive);
|
||||
rx3.setMinimal(false);
|
||||
QRegExp rx4("\\s*([0-9eE.+-]+)\\s*([,\\t ])\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*\\2\\s*([0-9eE.+-]+)\\s*", Qt::CaseInsensitive);
|
||||
rx4.setMinimal(false);
|
||||
#endif
|
||||
|
||||
// determine format
|
||||
for (int i=slt.size()-1; i>=0; i--) {
|
||||
slt[i]=slt[i].trimmed();
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
const auto m4=rx4.match(slt[i]);
|
||||
const auto m3=rx3.match(slt[i]);
|
||||
if (m4.hasMatch()) {
|
||||
const double r=JKQTPImagePlot_QStringToDouble(m4.captured(3));
|
||||
const double g=JKQTPImagePlot_QStringToDouble(m4.captured(4));
|
||||
const double b=JKQTPImagePlot_QStringToDouble(m4.captured(5));
|
||||
#else
|
||||
if (rx4.indexIn(slt[i])>=0) {
|
||||
const double r=JKQTPImagePlot_QStringToDouble(rx4.cap(3));
|
||||
const double g=JKQTPImagePlot_QStringToDouble(rx4.cap(4));
|
||||
const double b=JKQTPImagePlot_QStringToDouble(rx4.cap(5));
|
||||
#endif
|
||||
has4=true;
|
||||
double r=JKQTPImagePlot_QStringToDouble(rx4.cap(3));
|
||||
double g=JKQTPImagePlot_QStringToDouble(rx4.cap(4));
|
||||
double b=JKQTPImagePlot_QStringToDouble(rx4.cap(5));
|
||||
if (r>1.0 || g>1.0 || b>1.0) {
|
||||
rgb255=true;
|
||||
}
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
} else if (m3.hasMatch()) {
|
||||
const double r=JKQTPImagePlot_QStringToDouble(m3.captured(1));
|
||||
const double g=JKQTPImagePlot_QStringToDouble(m3.captured(3));
|
||||
const double b=JKQTPImagePlot_QStringToDouble(m3.captured(4));
|
||||
#else
|
||||
} else if (rx3.indexIn(slt[i])>=0) {
|
||||
has4=false;
|
||||
double r=JKQTPImagePlot_QStringToDouble(rx3.cap(1));
|
||||
double g=JKQTPImagePlot_QStringToDouble(rx3.cap(3));
|
||||
double b=JKQTPImagePlot_QStringToDouble(rx3.cap(4));
|
||||
#endif
|
||||
has4=false;
|
||||
if (r>1.0 || g>1.0 || b>1.0) {
|
||||
rgb255=true;
|
||||
}
|
||||
@ -2852,6 +2880,20 @@ QVector<int> JKQTPImageTools::registerPalettesFromFile(const QString &filename,
|
||||
for (int i=0; i<slt.size(); i++) {
|
||||
double x=0;
|
||||
double r=0, g=0, b=0;
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
const auto m4=rx4.match(slt[i]);
|
||||
const auto m3=rx3.match(slt[i]);
|
||||
if (has4 && m4.hasMatch()) {
|
||||
x=JKQTPImagePlot_QStringToDouble(m4.captured(1));
|
||||
r=JKQTPImagePlot_QStringToDouble(m4.captured(3));
|
||||
g=JKQTPImagePlot_QStringToDouble(m4.captured(4));
|
||||
b=JKQTPImagePlot_QStringToDouble(m4.captured(5));
|
||||
} else if (!has4 && m3.hasMatch()) {
|
||||
x=i;
|
||||
r=JKQTPImagePlot_QStringToDouble(m3.captured(1));
|
||||
g=JKQTPImagePlot_QStringToDouble(m3.captured(3));
|
||||
b=JKQTPImagePlot_QStringToDouble(m3.captured(4));
|
||||
#else
|
||||
if (has4 && rx4.indexIn(slt[i])>=0) {
|
||||
x=JKQTPImagePlot_QStringToDouble(rx4.cap(1));
|
||||
r=JKQTPImagePlot_QStringToDouble(rx4.cap(3));
|
||||
@ -2863,15 +2905,16 @@ QVector<int> JKQTPImageTools::registerPalettesFromFile(const QString &filename,
|
||||
g=JKQTPImagePlot_QStringToDouble(rx3.cap(3));
|
||||
b=JKQTPImagePlot_QStringToDouble(rx3.cap(4));
|
||||
//qDebug()<<r<<g<<b;
|
||||
#endif
|
||||
} else {
|
||||
ok=false;
|
||||
break;
|
||||
}
|
||||
if (ok) {
|
||||
if (!rgb255) {
|
||||
pal<<qMakePair(x, qRgb(qBound(0,static_cast<int>(round(255*r)), 255), qBound(0,static_cast<int>(round(255*g)), 255), qBound(0,static_cast<int>(round(255*b)), 255)));
|
||||
pal<<QPair<double,QRgb>(x, qRgb(qBound(0,static_cast<int>(round(255*r)), 255), qBound(0,static_cast<int>(round(255*g)), 255), qBound(0,static_cast<int>(round(255*b)), 255)));
|
||||
} else {
|
||||
pal<<qMakePair(x, qRgb(qBound(0,static_cast<int>(round(r)), 255), qBound(0,static_cast<int>(round(g)), 255), qBound(0,static_cast<int>(round(b)), 255)));
|
||||
pal<<QPair<double,QRgb>(x, qRgb(qBound(0,static_cast<int>(round(r)), 255), qBound(0,static_cast<int>(round(g)), 255), qBound(0,static_cast<int>(round(b)), 255)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,12 @@ Copyright (c) 2008-2020 Jan W. Krieger (<jan@jkrieger.de>)
|
||||
#include <ctype.h>
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
#include<QRegularExpression>
|
||||
#include<QRegularExpressionMatch>
|
||||
#else
|
||||
#include<QRegExp>
|
||||
#endif
|
||||
|
||||
std::string jkqtp_tolower(const std::string& s){
|
||||
std::string d;
|
||||
@ -527,6 +532,24 @@ QString jkqtp_QColor2String(QColor color, bool useSpecialTransparencySyntax) {
|
||||
|
||||
QColor jkqtp_String2QColor(const QString &color)
|
||||
{
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
QRegularExpression rxP("(.+)\\s*,\\s*(\\d+\\.?\\d+)\\%");
|
||||
QRegularExpression rxNP("(.+)\\s*,\\s*([\\d]+)");
|
||||
const auto mP=rxP.match(color);
|
||||
if (mP.hasMatch()) {
|
||||
QColor col(mP.captured(1));
|
||||
double a=QLocale::c().toDouble(mP.captured(2));
|
||||
col.setAlphaF(a/100.0);
|
||||
return col;
|
||||
}
|
||||
const auto mNP=rxNP.match(color);
|
||||
if (mNP.hasMatch()) {
|
||||
QColor col(mNP.captured(1));
|
||||
double a=QLocale::c().toInt(mNP.captured(2));
|
||||
col.setAlphaF(a/255.0);
|
||||
return col;
|
||||
}
|
||||
#else
|
||||
QRegExp rxP("(.+)\\s*,\\s*(\\d+\\.?\\d+)\\%");
|
||||
QRegExp rxNP("(.+)\\s*,\\s*([\\d]+)");
|
||||
if (rxP.exactMatch(color)) {
|
||||
@ -541,6 +564,7 @@ QColor jkqtp_String2QColor(const QString &color)
|
||||
col.setAlphaF(a/255.0);
|
||||
return col;
|
||||
}
|
||||
#endif
|
||||
return QColor(color);
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,14 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QLocale>
|
||||
#include <QtCore>
|
||||
#if (QT_VERSION>QT_VERSION_CHECK(5, 3, 0))
|
||||
# include <QScreen>
|
||||
# include <QGuiApplication>
|
||||
#else
|
||||
# include <QDesktopWidget>
|
||||
#endif
|
||||
|
||||
void jksaveWidgetGeometry(QSettings& settings, QWidget* widget, const QString& prefix) {
|
||||
settings.setValue(prefix+"pos", widget->pos());
|
||||
@ -34,11 +39,15 @@ void jksaveWidgetGeometry(QSettings& settings, QWidget* widget, const QString& p
|
||||
|
||||
void jkloadWidgetGeometry(QSettings& settings, QWidget* widget, QPoint defaultPosition, QSize defaultSize, const QString& prefix) {
|
||||
QPoint pos = settings.value(prefix+"pos", defaultPosition).toPoint();
|
||||
QSize size = settings.value(prefix+"size", defaultSize).toSize();
|
||||
|
||||
widget->resize(size.boundedTo(QApplication::desktop()->screenGeometry(widget).size()));
|
||||
if (pos.x()<0 || pos.x()>QApplication::desktop()->screenGeometry(widget).width()) pos.setX(0);
|
||||
if (pos.y()<0 || pos.y()>QApplication::desktop()->screenGeometry(widget).height()) pos.setY(0);
|
||||
const QSize size = settings.value(prefix+"size", defaultSize).toSize();
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(5, 3, 0))
|
||||
const auto widgeo = widget->screen()->geometry();
|
||||
#else
|
||||
const auto widgeo = QApplication::desktop()->screenGeometry(widget);
|
||||
#endif
|
||||
widget->resize(size.boundedTo(widgeo.size()));
|
||||
if (pos.x()<0 || pos.x()>widgeo.width()) pos.setX(0);
|
||||
if (pos.y()<0 || pos.y()>widgeo.height()) pos.setY(0);
|
||||
widget->move(pos);
|
||||
}
|
||||
|
||||
@ -78,21 +87,39 @@ QString jkVariantListToString(const QList<QVariant>& data, const QString& separa
|
||||
for (int i=0; i<data.size(); i++) {
|
||||
if (i>0) r=r+separator;
|
||||
QVariant v=data[i];
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
if (v.typeId()==QMetaType::Bool) r=r+loc.toString(v.toBool());
|
||||
else if (v.typeId()==QMetaType::Char) r=r+loc.toString(v.toInt());
|
||||
else if (v.typeId()==QMetaType::QDate) r=r+loc.toString(v.toDate());
|
||||
else if (v.typeId()==QMetaType::QDateTime) r=r+loc.toString(v.toDateTime());
|
||||
else if (v.typeId()==QMetaType::Double) r=r+loc.toString(v.toDouble());
|
||||
else if (v.typeId()==QMetaType::Int) r=r+loc.toString(v.toInt());
|
||||
else if (v.typeId()==QMetaType::LongLong) r=r+loc.toString(v.toLongLong());
|
||||
else if (v.typeId()==QMetaType::QString) r=r+QString("\"%1\"").arg(v.toString().replace("\"", "_").replace("\t", " ").replace("\r", "").replace("\n", " ").replace(",", " ").replace(";", " "));
|
||||
else if (v.typeId()==QMetaType::QTime) r=r+loc.toString(v.toTime());
|
||||
else if (v.typeId()==QMetaType::UInt) r=r+loc.toString(v.toUInt());
|
||||
else if (v.typeId()==QMetaType::ULongLong) r=r+loc.toString(v.toULongLong());
|
||||
else r=r+v.toString();
|
||||
|
||||
#else
|
||||
# define QVARIANT_TYPESBASE QVariant
|
||||
switch (v.type()) {
|
||||
case QVariant::Bool: r=r+loc.toString(v.toBool()); break;
|
||||
case QVariant::Char: r=r+loc.toString(v.toInt()); break;
|
||||
case QVariant::Date: r=r+loc.toString(v.toDate()); break;
|
||||
case QVariant::DateTime: r=r+loc.toString(v.toDateTime()); break;
|
||||
case QVariant::Double: r=r+loc.toString(v.toDouble()); break;
|
||||
case QVariant::Int: r=r+loc.toString(v.toInt()); break;
|
||||
case QVariant::LongLong: r=r+loc.toString(v.toLongLong()); break;
|
||||
case QVariant::String: r=r+QString("\"%1\"").arg(v.toString().replace("\"", "_").replace("\t", " ").replace("\r", "").replace("\n", " ").replace(",", " ").replace(";", " ")); break;
|
||||
case QVariant::Time: r=r+loc.toString(v.toTime()); break;
|
||||
case QVariant::UInt: r=r+loc.toString(v.toUInt()); break;
|
||||
case QVariant::ULongLong: r=r+loc.toString(v.toULongLong()); break;
|
||||
|
||||
case QVARIANT_TYPESBASE::Bool: r=r+loc.toString(v.toBool()); break;
|
||||
case QVARIANT_TYPESBASE::Char: r=r+loc.toString(v.toInt()); break;
|
||||
case QVARIANT_TYPESBASE::Date: r=r+loc.toString(v.toDate()); break;
|
||||
case QVARIANT_TYPESBASE::DateTime: r=r+loc.toString(v.toDateTime()); break;
|
||||
case QVARIANT_TYPESBASE::Double: r=r+loc.toString(v.toDouble()); break;
|
||||
case QVARIANT_TYPESBASE::Int: r=r+loc.toString(v.toInt()); break;
|
||||
case QVARIANT_TYPESBASE::LongLong: r=r+loc.toString(v.toLongLong()); break;
|
||||
case QVARIANT_TYPESBASE::String: r=r+QString("\"%1\"").arg(v.toString().replace("\"", "_").replace("\t", " ").replace("\r", "").replace("\n", " ").replace(",", " ").replace(";", " ")); break;
|
||||
case QVARIANT_TYPESBASE::Time: r=r+loc.toString(v.toTime()); break;
|
||||
case QVARIANT_TYPESBASE::UInt: r=r+loc.toString(v.toUInt()); break;
|
||||
case QVARIANT_TYPESBASE::ULongLong: r=r+loc.toString(v.toULongLong()); break;
|
||||
//case : r=r+loc.toString(v.); break;
|
||||
default: r=r+v.toString(); break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -101,7 +128,11 @@ JKQTCOMMON_LIB_EXPORT QString jkqtp_filenameize(const QString& data) {
|
||||
QString r;
|
||||
QString data1=data.simplified();
|
||||
for (int i=0; i<data1.size(); i++) {
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
const auto c=data1[i];
|
||||
#else
|
||||
QCharRef c=data1[i];
|
||||
#endif
|
||||
if (c.isLetterOrNumber() || (c=='-') || (c=='_') || (c=='.')) {
|
||||
r+=c;
|
||||
} else {
|
||||
@ -167,7 +198,11 @@ QString jkqtp_MouseButton2String(Qt::MouseButton button, bool useNONE)
|
||||
}
|
||||
if (button==Qt::LeftButton) return "LEFT";
|
||||
if (button==Qt::RightButton) return "RIGHT";
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
if (button==Qt::MiddleButton) return "MIDDLE";
|
||||
#else
|
||||
if (button==Qt::MidButton) return "MIDDLE";
|
||||
#endif
|
||||
if (button==Qt::BackButton) return "BACK";
|
||||
if (button==Qt::ForwardButton) return "FORWARD";
|
||||
if (button==Qt::TaskButton) return "TASK";
|
||||
@ -200,7 +235,11 @@ Qt::MouseButton jkqtp_String2MouseButton(const QString &button)
|
||||
auto but=button.toUpper().trimmed();
|
||||
if (but=="LEFT") return Qt::LeftButton;
|
||||
if (but=="RIGHT") return Qt::RightButton;
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
if (but=="MIDDLE") return Qt::MiddleButton;
|
||||
#else
|
||||
if (but=="MIDDLE") return Qt::MidButton;
|
||||
#endif
|
||||
if (but=="BACK") return Qt::BackButton;
|
||||
if (but=="FORWARD") return Qt::ForwardButton;
|
||||
if (but=="TASK") return Qt::TaskButton;
|
||||
|
@ -79,7 +79,10 @@ if(JKQtPlotter_BUILD_STATIC_LIBS)
|
||||
endif()
|
||||
target_compile_features(${lib_name} PUBLIC cxx_std_11)
|
||||
target_link_libraries(${lib_name} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::OpenGL JKQTCommonLib)
|
||||
target_include_directories(${lib_name} PUBLIC
|
||||
if(${QT_VERSION_MAJOR}>=6)
|
||||
target_link_libraries(${lib_name} PUBLIC t${QT_VERSION_MAJOR}::OpenGLWidgets)
|
||||
endif()
|
||||
target_include_directories(${lib_name} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
@ -69,7 +69,11 @@ void JKQTFPPlot::paint(QPainter& painter) {
|
||||
}
|
||||
|
||||
JKQTFastPlotter::JKQTFastPlotter(QWidget *parent) :
|
||||
QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel | QGL::Rgba), parent)//, mutexRepaint(QMutex::Recursive), mutexRepaintData(QMutex::Recursive), mutexRepaintSystem(QMutex::Recursive)
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
JKQTFASTPLOTTER_BASE(parent)
|
||||
#else
|
||||
JKQTFASTPLOTTER_BASE(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel | QGL::Rgba), parent)//, mutexRepaint(QMutex::Recursive), mutexRepaintData(QMutex::Recursive), mutexRepaintSystem(QMutex::Recursive)
|
||||
#endif
|
||||
{
|
||||
mouseDragStart=QPoint(0,0);
|
||||
mouseDragEnd=QPoint(0,0);
|
||||
@ -263,7 +267,7 @@ void JKQTFastPlotter::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
|
||||
void JKQTFastPlotter::resizeEvent(QResizeEvent *event) {
|
||||
QGLWidget::resizeEvent(event);
|
||||
JKQTFASTPLOTTER_BASE::resizeEvent(event);
|
||||
if (width() > image.width() || height() > image.height()) {
|
||||
QImage newImage(QSize(width(), height()), QImage::Format_ARGB32);
|
||||
image=newImage;
|
||||
@ -350,7 +354,7 @@ void JKQTFastPlotter::plotSystem(QPainter& painter) {
|
||||
systemPath.moveTo(x2p(x), internalPlotBorderTop+plotHeight+tickLength);
|
||||
systemPath.lineTo(x2p(x), internalPlotBorderTop+plotHeight-tickLength);
|
||||
QString text=QLocale::system().toString(x);
|
||||
painter.drawText(QPointF(x2p(x)-fmTicks.width(text)/2.0, internalPlotBorderTop+plotHeight+fmTicks.ascent()+fmTicks.width("x")/2.0+tickLength), text);
|
||||
painter.drawText(QPointF(x2p(x)-fmTicks.boundingRect(text).width()/2.0, internalPlotBorderTop+plotHeight+fmTicks.ascent()+fmTicks.boundingRect("x").width()/2.0+tickLength), text);
|
||||
}
|
||||
if (xAxisLog) {
|
||||
x=x*10.0;
|
||||
@ -368,7 +372,7 @@ void JKQTFastPlotter::plotSystem(QPainter& painter) {
|
||||
systemPath.moveTo(x2p(x), internalPlotBorderTop+plotHeight+tickLength);
|
||||
systemPath.lineTo(x2p(x), internalPlotBorderTop+plotHeight-tickLength);
|
||||
QString text=QLocale::system().toString(x);
|
||||
painter.drawText(QPointF(x2p(x)-fmTicks.width(text)/2.0, internalPlotBorderTop+plotHeight+fmTicks.ascent()+fmTicks.width("x")/2.0+tickLength), text);
|
||||
painter.drawText(QPointF(x2p(x)-fmTicks.boundingRect(text).width()/2.0, internalPlotBorderTop+plotHeight+fmTicks.ascent()+fmTicks.boundingRect("x").width()/2.0+tickLength), text);
|
||||
}
|
||||
if (xAxisLog) {
|
||||
x=x/10.0;
|
||||
@ -387,7 +391,7 @@ void JKQTFastPlotter::plotSystem(QPainter& painter) {
|
||||
systemPath.moveTo(internalPlotBorderLeft-tickLength, y2p(y));
|
||||
systemPath.lineTo(internalPlotBorderLeft+tickLength, y2p(y));
|
||||
QString text=QLocale::system().toString(y);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft-fmTicks.width("x")/2.0-fmTicks.width(text)-tickLength, y2p(y)+fmTicks.ascent()/2.0), text);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft-fmTicks.boundingRect("x").width()/2.0-fmTicks.boundingRect(text).width()-tickLength, y2p(y)+fmTicks.ascent()/2.0), text);
|
||||
}
|
||||
if (yAxisLog) {
|
||||
y=y*10.0;
|
||||
@ -405,7 +409,7 @@ void JKQTFastPlotter::plotSystem(QPainter& painter) {
|
||||
systemPath.moveTo(internalPlotBorderLeft-tickLength, y2p(y));
|
||||
systemPath.lineTo(internalPlotBorderLeft+tickLength, y2p(y));
|
||||
QString text=QLocale::system().toString(y);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft-fmTicks.width("x")/2.0-fmTicks.width(text)-tickLength, y2p(y)+fmTicks.ascent()/2.0), text);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft-fmTicks.boundingRect("x").width()/2.0-fmTicks.boundingRect(text).width()-tickLength, y2p(y)+fmTicks.ascent()/2.0), text);
|
||||
}
|
||||
if (yAxisLog) {
|
||||
y=y/10.0;
|
||||
@ -453,11 +457,11 @@ void JKQTFastPlotter::plotSystem(QPainter& painter) {
|
||||
if (xAxisLabelVisible) {
|
||||
painter.setPen(pSystem);
|
||||
painter.setFont(fLabels);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft+plotWidth-fmLabels.width(xAxisLabel), internalPlotBorderTop+plotHeight+fmTicks.height()+fmTicks.width("x")/2.0+fmLabels.ascent()+tickLength), xAxisLabel);
|
||||
painter.drawText(QPointF(internalPlotBorderLeft+plotWidth-fmLabels.boundingRect(xAxisLabel).width(), internalPlotBorderTop+plotHeight+fmTicks.height()+fmTicks.boundingRect("x").width()/2.0+fmLabels.ascent()+tickLength), xAxisLabel);
|
||||
}
|
||||
if (yAxisLabelVisible) {
|
||||
painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.translate(fmLabels.ascent(), internalPlotBorderTop+fmLabels.width(yAxisLabel));
|
||||
painter.translate(fmLabels.ascent(), internalPlotBorderTop+fmLabels.boundingRect(yAxisLabel).width());
|
||||
painter.rotate(-90);
|
||||
painter.drawText(QPointF(0, 0), yAxisLabel);
|
||||
|
||||
|
@ -34,7 +34,13 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <QMutex>
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
#include <QtOpenGLWidgets/QOpenGLWidget>
|
||||
#define JKQTFASTPLOTTER_BASE QOpenGLWidget
|
||||
#else
|
||||
#include <QGLWidget>
|
||||
#define JKQTFASTPLOTTER_BASE QGLWidget
|
||||
#endif
|
||||
#include "jkqtcommon/jkqtpmathtools.h"
|
||||
#ifdef DEBUG_TIMING
|
||||
# include "jkqtcommon/jkqtphighrestimer.h"
|
||||
@ -83,7 +89,13 @@ class JKQTFPPlot;
|
||||
.
|
||||
|
||||
*/
|
||||
class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter : public QGLWidget {
|
||||
class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter :
|
||||
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
|
||||
public QOpenGLWidget
|
||||
#else
|
||||
public QGLWidget
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <QApplication>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
const double JKQTMathText::ABS_MIN_LINEWIDTH=0.02;
|
||||
|
||||
QPainterPath makeHBracePath(double x, double ybrace, double width, double bw, double cubicshrink=0.5, double cubiccontrolfac=0.3) {
|
||||
@ -277,14 +278,14 @@ void JKQTMathText::MTtextNode::getSizeInternal(QPainter& painter, JKQTMathText::
|
||||
QRectF tbr=parent->getTightBoundingRect(f, txt, painter.device()); //fm.tightBoundingRect(txt);
|
||||
if (txt=="|") {
|
||||
br=fm.boundingRect("X");
|
||||
tbr=QRectF(0,0,fm.width("X"), fm.ascent());//fm.boundingRect("X");
|
||||
tbr=QRectF(0,0,fm.boundingRect("X").width(), fm.ascent());//fm.boundingRect("X");
|
||||
br.setWidth(0.7*br.width());
|
||||
}
|
||||
width=br.width();//width(text);
|
||||
|
||||
if (txt.size()>0) {
|
||||
if (txt[0].isSpace() /*&& br.width()<=0*/) width=width+fm.boundingRect("I").width();
|
||||
if (txt.size()>1 && txt[txt.size()-1].isSpace() /*&& (fm.boundingRect("a ").width()==fm.boundingRect("a").width())*/) width=width+fm.width("I");
|
||||
if (txt.size()>1 && txt[txt.size()-1].isSpace() /*&& (fm.boundingRect("a ").width()==fm.boundingRect("a").width())*/) width=width+fm.boundingRect("I").width();
|
||||
}
|
||||
|
||||
//qDebug()<<"text: "<<text<<" "<<tbr.height()<<tbr.top()<<tbr.bottom();
|
||||
@ -340,7 +341,7 @@ double JKQTMathText::MTtextNode::draw(QPainter& painter, double x, double y, JKQ
|
||||
QFontMetricsF fm(f, painter.device());
|
||||
/*if (txt.size()>1 && txt[txt.size()-1].isSpace()) {
|
||||
QFontMetricsF fm(f, painter.device());
|
||||
//if ((fm.width("a ")==fm.width("a"))) dx=fm.boundingRect("I").width();
|
||||
//if ((fm.QFMF_WIDTH("a ")==fm.QFMF_WIDTH("a"))) dx=fm.boundingRect("I").QFMF_WIDTH();
|
||||
}*/
|
||||
|
||||
if (!hasDigits || !f.italic()) {
|
||||
@ -367,7 +368,7 @@ double JKQTMathText::MTtextNode::draw(QPainter& painter, double x, double y, JKQ
|
||||
painter.setFont(ff);
|
||||
painter.drawText(QPointF(xx, y), QString(txt[i]));
|
||||
}
|
||||
xx=xx+fmff.width(txt[i]);
|
||||
xx=xx+fmff.boundingRect(txt[i]).width();
|
||||
} else {
|
||||
if (currentEv.font==MTEblackboard && parent->blackboardSimulated) {
|
||||
QPainterPath path;
|
||||
@ -377,7 +378,7 @@ double JKQTMathText::MTtextNode::draw(QPainter& painter, double x, double y, JKQ
|
||||
painter.setFont(f);
|
||||
painter.drawText(QPointF(xx, y), QString(txt[i]));
|
||||
}
|
||||
xx=xx+fm.width(txt[i]);
|
||||
xx=xx+fm.boundingRect(txt[i]).width();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@ -465,7 +466,7 @@ void JKQTMathText::MTinstruction1Node::getSizeInternal(QPainter& painter, JKQTMa
|
||||
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
|
||||
if (name=="colorbox" || name=="fbox" || name=="boxed") {
|
||||
QFontMetricsF fm(ev.getFont(parent));
|
||||
double xw=fm.width("x");
|
||||
double xw=fm.boundingRect("x").width();
|
||||
width+=xw;
|
||||
overallHeight+=xw;
|
||||
baselineHeight+=xw/2.0;
|
||||
@ -488,7 +489,7 @@ double JKQTMathText::MTinstruction1Node::draw(QPainter& painter, double x, doubl
|
||||
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
|
||||
QPen p=painter.pen();
|
||||
QFontMetricsF fm(currentEv.getFont(parent));
|
||||
double xw=fm.width("x");
|
||||
double xw=fm.boundingRect("x").width();
|
||||
p.setColor(fcol);
|
||||
painter.setPen(p);
|
||||
painter.drawRect(QRectF(x,y-baselineHeight-xw/2,width+xw,overallHeight+xw));
|
||||
@ -2860,11 +2861,11 @@ void JKQTMathText::MTsymbolNode::getSizeInternal(QPainter& painter, JKQTMathText
|
||||
if (currentEv.insideMath) width=qMax(parent->getTightBoundingRect(f, symb, painter.device()).width(),parent->getTightBoundingRect(f, "i", painter.device()).width());//fm.width(symbol);
|
||||
else width=fm.boundingRect(symb).width();//fm.width(symbol);
|
||||
|
||||
width=qMax(fm.width("j"), width);
|
||||
width=qMax(fm.boundingRect("j").width(), width);
|
||||
if (symb.isEmpty()) {
|
||||
width=fm.width("a");
|
||||
if (symbolName=="|") width=fm.width("1")*0.8;
|
||||
else if (symbolName=="infty") width=fm.width("M");
|
||||
width=fm.boundingRect("a").width();
|
||||
if (symbolName=="|") width=fm.boundingRect("1").width()*0.8;
|
||||
else if (symbolName=="infty") width=fm.boundingRect("M").width();
|
||||
else if (symbolName=="quad" || symbolName=="qquad") width=parent->getTightBoundingRect(f, "M", painter.device()).width();
|
||||
else if (symbolName==" " || symbolName=="space") width=parent->getTightBoundingRect(f, "x", painter.device()).width();
|
||||
else if (symbolName==";") width=parent->getTightBoundingRect(f, "x", painter.device()).width()*0.75;
|
||||
@ -2933,7 +2934,7 @@ double JKQTMathText::MTsymbolNode::draw(QPainter& painter, double x, double y, J
|
||||
p.setWidthF(fm.lineWidth());
|
||||
p.setStyle(Qt::SolidLine);
|
||||
painter.setPen(p);
|
||||
double xwi=fm.width("x");
|
||||
double xwi=fm.boundingRect("x").width();
|
||||
if (!props.symbol.isEmpty()) {
|
||||
// if the symbol has been recognized in the constructor: draw the symbol
|
||||
painter.drawText(QPointF(x+shift, y+props.yfactor*overallHeight), props.symbol);
|
||||
@ -2949,7 +2950,7 @@ double JKQTMathText::MTsymbolNode::draw(QPainter& painter, double x, double y, J
|
||||
f1.setItalic(false);
|
||||
painter.setFont(f1);
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.translate(x+shift+fm1.width("8")/3.0, y-fm1.xHeight());
|
||||
painter.translate(x+shift+fm1.boundingRect("8").width()/3.0, y-fm1.xHeight());
|
||||
painter.rotate(90);
|
||||
painter.drawText(QPointF(0,0), "8");
|
||||
|
||||
@ -2961,7 +2962,7 @@ double JKQTMathText::MTsymbolNode::draw(QPainter& painter, double x, double y, J
|
||||
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||
painter.translate(x+shift, y);
|
||||
painter.drawText(QPointF(0,0), "|");
|
||||
painter.translate(fm1.width("8")/3.0, 0);
|
||||
painter.translate(fm1.boundingRect("8").width()/3.0, 0);
|
||||
painter.drawText(QPointF(0,0), "|");
|
||||
|
||||
|
||||
@ -4876,7 +4877,9 @@ void JKQTMathTextLabel::internalPaint()
|
||||
//qDebug()<<"internalPaint(): "<<p.begin(&buffer);
|
||||
p.begin(&buffer);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
#endif
|
||||
p.setRenderHint(QPainter::TextAntialiasing);
|
||||
size=m_mathText->getSize(p);
|
||||
p.end();
|
||||
@ -4889,7 +4892,9 @@ void JKQTMathTextLabel::internalPaint()
|
||||
//qDebug()<<"internalPaint(): "<<p.begin(&buffer);
|
||||
p.begin(&buffer);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
#endif
|
||||
p.setRenderHint(QPainter::TextAntialiasing);
|
||||
m_mathText->draw(p,alignment(), QRectF(QPointF(0,0), size));
|
||||
p.end();
|
||||
|
@ -3753,11 +3753,13 @@ void JKQTBasePlotter::saveAsPixelImage(const QString& filename, bool displayPrev
|
||||
png.fill(Qt::transparent);
|
||||
JKQTPEnhancedPainter painter;
|
||||
painter.begin(&png);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::NonCosmeticDefaultPen, true);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::Antialiasing);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::TextAntialiasing);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::SmoothPixmapTransform);
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::NonCosmeticDefaultPen, true);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::HighQualityAntialiasing);
|
||||
#endif
|
||||
|
||||
/*calcPlotScaling(painter);
|
||||
gridPaint(painter, png.rect().size());*/\
|
||||
@ -3809,11 +3811,13 @@ void JKQTBasePlotter::copyPixelImage() {
|
||||
png.fill(Qt::transparent);
|
||||
JKQTPEnhancedPainter painter;
|
||||
painter.begin(&png);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::NonCosmeticDefaultPen, true);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::Antialiasing);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::TextAntialiasing);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::SmoothPixmapTransform);
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::NonCosmeticDefaultPen, true);
|
||||
painter.setRenderHint(JKQTPEnhancedPainter::HighQualityAntialiasing);
|
||||
#endif
|
||||
|
||||
/*calcPlotScaling(painter);
|
||||
gridPaint(painter, png.rect().size());*/
|
||||
|
@ -59,7 +59,9 @@ QImage JKQTPPlotElement::generateKeyMarker(QSize size)
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
|
||||
#endif
|
||||
QRectF rect(0,0,size.width(),size.height());
|
||||
drawKeyMarker(painter, rect);
|
||||
}
|
||||
@ -414,6 +416,7 @@ void JKQTPXYGraph::setXYColumns(int xCol, int yCol)
|
||||
setYColumn(yCol);
|
||||
}
|
||||
|
||||
#if QT_VERSION<QT_VERSION_CHECK(6,0,0)
|
||||
void JKQTPXYGraph::setXYColumns(std::pair<int, int> xyColPair)
|
||||
{
|
||||
setXColumn(xyColPair.first);
|
||||
@ -425,6 +428,7 @@ void JKQTPXYGraph::setXYColumns(std::pair<size_t, size_t> xyColPair)
|
||||
setXColumn(xyColPair.first);
|
||||
setYColumn(xyColPair.second);
|
||||
}
|
||||
#endif
|
||||
|
||||
void JKQTPXYGraph::setXYColumns(QPair<int, int> xyColPair)
|
||||
{
|
||||
|
@ -605,10 +605,12 @@ public slots:
|
||||
void setXYColumns(size_t xCol, size_t yCol);
|
||||
/** \brief sets xColumn and yColumn at the same time */
|
||||
void setXYColumns(int xCol, int yCol);
|
||||
#if QT_VERSION<QT_VERSION_CHECK(6,0,0)
|
||||
/** \brief sets xColumn and yColumn at the same time */
|
||||
void setXYColumns(std::pair<int,int> xyColPair);
|
||||
/** \brief sets xColumn and yColumn at the same time */
|
||||
void setXYColumns(std::pair<size_t,size_t> xyColPair);
|
||||
#endif
|
||||
/** \brief sets xColumn and yColumn at the same time */
|
||||
void setXYColumns(QPair<int,int> xyColPair);
|
||||
/** \brief sets xColumn and yColumn at the same time */
|
||||
|
Loading…
Reference in New Issue
Block a user