From 57f3d85e157f2818c1685869183a7edf55845fe2 Mon Sep 17 00:00:00 2001 From: octaeder <102688820+octaeder@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:05:32 +0200 Subject: [PATCH] scale tooltip preview, size limit in config --- src/configmanager.cpp | 1 + src/latexeditorview_config.h | 1 + src/texstudio.cpp | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/configmanager.cpp b/src/configmanager.cpp index d069867efa..35ffa47ae9 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -546,6 +546,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 daa88211cb..f2570ec4fc 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 f9381d62de..9dde469538 100644 --- a/src/texstudio.cpp +++ b/src/texstudio.cpp @@ -71,6 +71,7 @@ #include "execprogram.h" #include +#include #include #ifndef QT_NO_DEBUG @@ -8682,15 +8683,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(); } }