Skip to content

Commit e6be967

Browse files
committed
scale tooltip preview, size limit in config
1 parent a477774 commit e6be967

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
@@ -8760,15 +8761,28 @@ void Texstudio::showImgPreview(const QString &fname)
87608761
//else
87618762
// p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
87628763
QRect screen = QGuiApplication::primaryScreen()->geometry();
8764+
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
87638765
QPixmap img(imageName);
87648766
int w = qMin(img.width(), configManager.editorConfig->maxImageTooltipWidth);
87658767
w = qMin(w, screen.width() - 8);
8768+
#else
8769+
QImage img;
8770+
QImageReader reader(imageName);
8771+
reader.setAllocationLimit(4*configManager.editorConfig->imageToolTipLoadMaxPixels); // each pixel uses 4bytes
8772+
reader.read(&img);
8773+
int w = 0;
8774+
if (img != QImage()) {
8775+
int realw = qRound(img.width() * QGuiApplication::primaryScreen()->physicalDotsPerInch() / (img.dotsPerMeterX() * 2.54/100) );
8776+
w = qMin(realw, configManager.editorConfig->maxImageTooltipWidth);
8777+
w = qMin(w, screen.width() - 8);
8778+
}
8779+
#endif
87668780
QString text = QString("<img src=\"" + imageName + "\" width=%1 />").arg(w);
87678781
if (completerPreview) {
87688782
completerPreview = false;
87698783
emit imgPreview(text);
87708784
} else {
8771-
QToolTip::showText(p, text, nullptr);
8785+
QToolTip::showText(p, text, nullptr);
87728786
LatexEditorView::hideTooltipWhenLeavingLine = currentEditorView()->editor->cursor().lineNumber();
87738787
}
87748788
}

0 commit comments

Comments
 (0)