Skip to content

Commit bd2ad9c

Browse files
committed
scale tooltip preview, size limit in config
1 parent 3c23a8e commit bd2ad9c

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
@@ -551,6 +551,7 @@ ConfigManager::ConfigManager(QObject *parent): QObject (parent),
551551
registerOption("Editor/ToolTip Help", &editorConfig->toolTipHelp, true, &pseudoDialog->checkBoxToolTipHelp2);
552552
registerOption("Editor/ToolTip Preview", &editorConfig->toolTipPreview, true, &pseudoDialog->checkBoxToolTipPreview);
553553
registerOption("Editor/ImageToolTip", &editorConfig->imageToolTip, true, &pseudoDialog->checkBoxImageToolTip);
554+
registerOption("Editor/ImageToolTipLoadMaxPixels", &editorConfig->imageToolTipLoadMaxPixels, 30);
554555
registerOption("Editor/MaxImageTooltipWidth", &editorConfig->maxImageTooltipWidth, 400);
555556
registerOption("Editor/ContextMenuKeyboardModifiers", &editorConfig->contextMenuKeyboardModifiers, Qt::ShiftModifier);
556557
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
@@ -8882,15 +8883,28 @@ void Texstudio::showImgPreview(const QString &fname)
88828883
//else
88838884
// p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
88848885
QRect screen = QGuiApplication::primaryScreen()->geometry();
8886+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
88858887
QPixmap img(imageName);
88868888
int w = qMin(img.width(), configManager.editorConfig->maxImageTooltipWidth);
88878889
w = qMin(w, screen.width() - 8);
8890+
#else
8891+
QImage img;
8892+
QImageReader reader(imageName);
8893+
reader.setAllocationLimit(4*configManager.editorConfig->imageToolTipLoadMaxPixels); // each pixel uses 4bytes
8894+
reader.read(&img);
8895+
int w = 0;
8896+
if (img != QImage()) {
8897+
int realw = qRound(img.width() * QGuiApplication::primaryScreen()->physicalDotsPerInch() / (img.dotsPerMeterX() * 2.54/100) );
8898+
w = qMin(realw, configManager.editorConfig->maxImageTooltipWidth);
8899+
w = qMin(w, screen.width() - 8);
8900+
}
8901+
#endif
88888902
QString text = QString("<img src=\"" + imageName + "\" width=%1 />").arg(w);
88898903
if (completerPreview) {
88908904
completerPreview = false;
88918905
emit imgPreview(text);
88928906
} else {
8893-
QToolTip::showText(p, text, nullptr);
8907+
QToolTip::showText(p, text, nullptr);
88948908
LatexEditorView::hideTooltipWhenLeavingLine = currentEditorView()->editor->cursor().lineNumber();
88958909
}
88968910
}

0 commit comments

Comments
 (0)