diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 96f17a6a9..022d88c0b 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -551,6 +551,7 @@ ConfigManager::ConfigManager(QObject *parent): QObject (parent), registerOption("Editor/ToolTip Help", &editorConfig->toolTipHelp, true, &pseudoDialog->checkBoxToolTipHelp2); registerOption("Editor/ToolTip Preview", &editorConfig->toolTipPreview, true, &pseudoDialog->checkBoxToolTipPreview); registerOption("Editor/ImageToolTip", &editorConfig->imageToolTip, true, &pseudoDialog->checkBoxImageToolTip); + registerOption("Editor/ImageToolTipLoadMaxPixels", &editorConfig->imageToolTipLoadMaxPixels, 30); registerOption("Editor/MaxImageTooltipWidth", &editorConfig->maxImageTooltipWidth, 400); registerOption("Editor/ContextMenuKeyboardModifiers", &editorConfig->contextMenuKeyboardModifiers, Qt::ShiftModifier); registerOption("Editor/ContextMenuSpellcheckingEntryLocation", &editorConfig->contextMenuSpellcheckingEntryLocation, 0, &pseudoDialog->comboBoxContextMenuSpellcheckingEntryLocation); diff --git a/src/latexeditorview_config.h b/src/latexeditorview_config.h index 01a0a5df2..0f8de066a 100644 --- a/src/latexeditorview_config.h +++ b/src/latexeditorview_config.h @@ -43,6 +43,7 @@ class LatexEditorViewConfig bool toolTipPreview; bool toolTipHelp; bool imageToolTip; + int imageToolTipLoadMaxPixels; int maxImageTooltipWidth; bool texdocHelpInInternalViewer; bool monitorFilesForExternalChanges; diff --git a/src/texstudio.cpp b/src/texstudio.cpp index c284f2538..313768ad8 100644 --- a/src/texstudio.cpp +++ b/src/texstudio.cpp @@ -71,6 +71,7 @@ #include "execprogram.h" #include +#include #include #ifndef QT_NO_DEBUG @@ -8917,15 +8918,28 @@ void Texstudio::showImgPreview(const QString &fname) //else // p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition())); QRect screen = QGuiApplication::primaryScreen()->geometry(); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QPixmap img(imageName); int w = qMin(img.width(), configManager.editorConfig->maxImageTooltipWidth); w = qMin(w, screen.width() - 8); +#else + QImage img; + QImageReader reader(imageName); + reader.setAllocationLimit(4*configManager.editorConfig->imageToolTipLoadMaxPixels); // each pixel uses 4bytes + reader.read(&img); + int w = 0; + if (img != QImage()) { + int realw = qRound(img.width() * QGuiApplication::primaryScreen()->physicalDotsPerInch() / (img.dotsPerMeterX() * 2.54/100) ); + w = qMin(realw, configManager.editorConfig->maxImageTooltipWidth); + w = qMin(w, screen.width() - 8); + } +#endif QString text = QString("").arg(w); if (completerPreview) { completerPreview = false; emit imgPreview(text); } else { - QToolTip::showText(p, text, nullptr); + QToolTip::showText(p, text, nullptr); LatexEditorView::hideTooltipWhenLeavingLine = currentEditorView()->editor->cursor().lineNumber(); } }