Properly scale some icons for HiDPI (#12695)

This commit is contained in:
Juergen Spitzmueller 2023-03-11 14:49:07 +01:00
parent 5f7ae3ade5
commit 8863d6d785
5 changed files with 60 additions and 15 deletions

View File

@ -114,6 +114,7 @@
#include <QSocketNotifier>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QSvgRenderer>
#include <QTimer>
#include <QTranslator>
#include <QThreadPool>
@ -2666,6 +2667,30 @@ bool GuiApplication::unhide(Buffer * buf)
}
QPixmap GuiApplication::getScaledPixmap(QString imagedir, QString name) const
{
qreal dpr = 1.0;
// Consider device/pixel ratio (HiDPI)
if (currentView())
dpr = currentView()->devicePixelRatio();
// We render SVG directly for HiDPI scalability
QPixmap pm = getPixmap(imagedir, name, "svgz,png");
FileName fname = imageLibFileSearch(imagedir, name, "svgz,png");
QString fpath = toqstr(fname.absFileName());
if (!fpath.isEmpty()) {
QSvgRenderer svgRenderer(fpath);
if (svgRenderer.isValid()) {
pm = QPixmap(pm.size() * dpr);
pm.fill(Qt::transparent);
QPainter painter(&pm);
svgRenderer.render(&painter);
pm.setDevicePixelRatio(dpr);
}
}
return pm;
}
Clipboard & GuiApplication::clipboard()
{
return d->clipboard_;

View File

@ -94,6 +94,9 @@ public:
/// Return true if current position is RTL of if no document is open and interface if RTL
bool rtlContext() const;
/// Scale Pixmaps properly (also for HiDPI)
QPixmap getScaledPixmap(QString imagedir, QString name) const;
///
Clipboard & clipboard();
///

View File

@ -614,7 +614,8 @@ void PreambleModule::editExternal() {
preambleTE->setReadOnly(true);
theFormats().edit(*current_id_, tempfilename, format);
editPB->setText(qt_("&End Edit"));
QIcon warn(getPixmap("images/", "emblem-shellescape", "svgz,png"));
QIcon warn(guiApp ? guiApp->getScaledPixmap("images/", "emblem-shellescape-user")
: getPixmap("images/", "emblem-shellescape", "svgz,png"));
editPB->setIcon(warn);
changed();
}
@ -793,7 +794,8 @@ void LocalLayout::editExternal() {
locallayoutTE->setReadOnly(true);
theFormats().edit(*current_id_, tempfilename, format);
editPB->setText(qt_("&End Edit"));
QIcon warn(getPixmap("images/", "emblem-shellescape", "svgz,png"));
QIcon warn(guiApp ? guiApp->getScaledPixmap("images/", "emblem-shellescape-user")
: getPixmap("images/", "emblem-shellescape", "svgz,png"));
editPB->setIcon(warn);
validatePB->setEnabled(false);
hideConvert();
@ -1960,8 +1962,10 @@ void GuiDocument::filterModules(QString const & str)
return 0 < b.name.localeAwareCompare(a.name);
});
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user")
: getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system")
: getPixmap("images/", "lyxfiles-system", "svgz,png"));
int i = 0;
for (modInfoStruct const & m : modInfoList) {
@ -4672,8 +4676,10 @@ void GuiDocument::updateAvailableModules()
modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
return 0 < b.name.localeAwareCompare(a.name);
});
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user")
: getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system")
: getPixmap("images/", "lyxfiles-system", "svgz,png"));
int i = 0;
QFont catfont;
catfont.setBold(true);

View File

@ -214,8 +214,10 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
//filesLW->setViewMode(QListView::ListMode);
filesLW->setIconSize(QSize(22, 22));
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user")
: getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system")
: getPixmap("images/", "lyxfiles-system", "svgz,png"));
fileTypeCO->addItem(qt_("User and System Files"), toqstr("all"));
fileTypeCO->addItem(user_icon, qt_("User Files Only"), toqstr("user"));
fileTypeCO->addItem(system_icon, qt_("System Files Only"), toqstr("system"));
@ -308,8 +310,10 @@ void GuiLyXFiles::on_filesLW_itemClicked(QTreeWidgetItem * item, int)
setLanguage();
QString const realpath = getRealPath();
filesLW->currentItem()->setData(0, Qt::ToolTipRole, realpath);
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user")
: getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system")
: getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon file_icon = (realpath.startsWith(toqstr(package().user_support().absFileName()))) ?
user_icon : system_icon;
item->setIcon(0, file_icon);
@ -410,10 +414,16 @@ void GuiLyXFiles::updateContents()
languageCO->model()->sort(0);
filesLW->clear();
QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_folder_icon(getPixmap("images/", "lyxfiles-user-folder", "svgz,png"));
QIcon system_folder_icon(getPixmap("images/", "lyxfiles-system-folder", "svgz,png"));
QIcon user_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user")
: getPixmap("images/", "lyxfiles-user", "svgz,png"));
QIcon system_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system")
: getPixmap("images/", "lyxfiles-system", "svgz,png"));
QIcon user_folder_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-user-folder")
: getPixmap("images/", "lyxfiles-user-folder", "svgz,png"));
QIcon system_folder_icon(guiApp ? guiApp->getScaledPixmap("images/", "lyxfiles-system-folder")
: getPixmap("images/", "lyxfiles-system-folder", "svgz,png"));
QStringList cats;
QMap<QString, QString>::const_iterator it = files.constBegin();
QFont capfont;

View File

@ -155,7 +155,8 @@ void PanelStack::markPanelValid(QString const & name, bool valid)
item->setIcon(0, QIcon());
item->setToolTip(0, QString());
} else {
QIcon warn(getPixmap("images/", "emblem-shellescape", "svgz,png"));
QIcon warn(guiApp ? guiApp->getScaledPixmap("images/", "emblem-shellescape-user")
: getPixmap("images/", "emblem-shellescape", "svgz,png"));
item->setIcon(0, warn);
item->setToolTip(0, qt_("This section contains invalid input. Please fix!"));
}