Skip to content

Commit 273f867

Browse files
committed
scale tooltip preview, size limit in config
1 parent 87785c8 commit 273f867

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/configmanager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ ConfigManager::ConfigManager(QObject *parent): QObject (parent),
546546
registerOption("Editor/ToolTip Help", &editorConfig->toolTipHelp, true, &pseudoDialog->checkBoxToolTipHelp2);
547547
registerOption("Editor/ToolTip Preview", &editorConfig->toolTipPreview, true, &pseudoDialog->checkBoxToolTipPreview);
548548
registerOption("Editor/ImageToolTip", &editorConfig->imageToolTip, true, &pseudoDialog->checkBoxImageToolTip);
549+
registerOption("Editor/ImageToolTipLoadMaxPixels", &editorConfig->imageToolTipLoadMaxPixels, 30);
549550
registerOption("Editor/MaxImageTooltipWidth", &editorConfig->maxImageTooltipWidth, 400);
550551
registerOption("Editor/ContextMenuKeyboardModifiers", &editorConfig->contextMenuKeyboardModifiers, Qt::ShiftModifier);
551552
registerOption("Editor/ContextMenuSpellcheckingEntryLocation", &editorConfig->contextMenuSpellcheckingEntryLocation, 0, &pseudoDialog->comboBoxContextMenuSpellcheckingEntryLocation);

src/latexeditorview_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class LatexEditorViewConfig
4343
bool toolTipPreview;
4444
bool toolTipHelp;
4545
bool imageToolTip;
46+
int imageToolTipLoadMaxPixels;
4647
int maxImageTooltipWidth;
4748
bool texdocHelpInInternalViewer;
4849
bool monitorFilesForExternalChanges;

src/texstudio.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "execprogram.h"
7272
#include <QTime>
7373

74+
#include <QImageReader>
7475
#include <QScreen>
7576

7677
#ifndef QT_NO_DEBUG
@@ -8682,15 +8683,28 @@ void Texstudio::showImgPreview(const QString &fname)
86828683
//else
86838684
// p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
86848685
QRect screen = QGuiApplication::primaryScreen()->geometry();
8686+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
86858687
QPixmap img(imageName);
86868688
int w = qMin(img.width(), configManager.editorConfig->maxImageTooltipWidth);
86878689
w = qMin(w, screen.width() - 8);
8690+
#else
8691+
QImage img;
8692+
QImageReader reader(imageName);
8693+
reader.setAllocationLimit(4*configManager.editorConfig->imageToolTipLoadMaxPixels); // each pixel uses 4bytes
8694+
reader.read(&img);
8695+
int w = 0;
8696+
if (img != QImage()) {
8697+
int realw = qRound(img.width() * QGuiApplication::primaryScreen()->physicalDotsPerInch() / (img.dotsPerMeterX() * 2.54/100) );
8698+
w = qMin(realw, configManager.editorConfig->maxImageTooltipWidth);
8699+
w = qMin(w, screen.width() - 8);
8700+
}
8701+
#endif
86888702
QString text = QString("<img src=\"" + imageName + "\" width=%1 />").arg(w);
86898703
if (completerPreview) {
86908704
completerPreview = false;
86918705
emit imgPreview(text);
86928706
} else {
8693-
QToolTip::showText(p, text, nullptr);
8707+
QToolTip::showText(p, text, nullptr);
86948708
LatexEditorView::hideTooltipWhenLeavingLine = currentEditorView()->editor->cursor().lineNumber();
86958709
}
86968710
}

0 commit comments

Comments
 (0)