Skip to content

Commit

Permalink
scale tooltip preview, size limit in config
Browse files Browse the repository at this point in the history
  • Loading branch information
octaeder committed Sep 29, 2024
1 parent 3294a5c commit 4e60fba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/latexeditorview_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LatexEditorViewConfig
bool toolTipPreview;
bool toolTipHelp;
bool imageToolTip;
int imageToolTipLoadMaxPixels;
int maxImageTooltipWidth;
bool texdocHelpInInternalViewer;
bool monitorFilesForExternalChanges;
Expand Down
16 changes: 15 additions & 1 deletion src/texstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "execprogram.h"
#include <QTime>

#include <QImageReader>
#include <QScreen>

#ifndef QT_NO_DEBUG
Expand Down Expand Up @@ -8828,15 +8829,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("<img src=\"" + imageName + "\" width=%1 />").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();
}
}
Expand Down

0 comments on commit 4e60fba

Please sign in to comment.