mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
#9130 Text in main work area isn't rendered with high resolution
Improved icon and pixmap handling with SVG images and high physical resolution displays. This results in much better looking icons and splash banner.
This commit is contained in:
parent
0933df0011
commit
c053a9394d
@ -566,22 +566,39 @@ QString iconName(FuncRequest const & f, bool unknown)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool getPixmap(QPixmap & pixmap, QString const & path)
|
||||||
|
{
|
||||||
|
if (pixmap.load(path)) {
|
||||||
|
if (path.endsWith(".svgz") || path.endsWith(".svg") ) {
|
||||||
|
GuiApplication const * guiApp = theGuiApp();
|
||||||
|
if (guiApp != 0) {
|
||||||
|
pixmap.setDevicePixelRatio(guiApp->pixelRatio());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap getPixmap(QString const & path, QString const & name, QString const & ext)
|
QPixmap getPixmap(QString const & path, QString const & name, QString const & ext)
|
||||||
{
|
{
|
||||||
QPixmap pixmap;
|
|
||||||
QString imagedir = path;
|
QString imagedir = path;
|
||||||
FileName fname = imageLibFileSearch(imagedir, name, ext, theGuiApp()->imageSearchMode());
|
FileName fname = imageLibFileSearch(imagedir, name, ext, theGuiApp()->imageSearchMode());
|
||||||
QString fpath = toqstr(fname.absFileName());
|
QString fpath = toqstr(fname.absFileName());
|
||||||
|
QPixmap pixmap = QPixmap();
|
||||||
|
|
||||||
if (pixmap.load(fpath)) {
|
if (getPixmap(pixmap, fpath)) {
|
||||||
return pixmap;
|
return pixmap;
|
||||||
} else {
|
}
|
||||||
QStringList exts = ext.split(",");
|
|
||||||
fpath = ":/" + path + name + ".";
|
QStringList exts = ext.split(",");
|
||||||
for (int i = 0; i < exts.size(); ++i) {
|
fpath = ":/" + path + name + ".";
|
||||||
if (pixmap.load(fpath + exts.at(i)))
|
for (int i = 0; i < exts.size(); ++i) {
|
||||||
|
if (getPixmap(pixmap, fpath + exts.at(i))) {
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool const list = ext.contains(",");
|
bool const list = ext.contains(",");
|
||||||
@ -592,6 +609,7 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex
|
|||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QIcon getIcon(FuncRequest const & f, bool unknown)
|
QIcon getIcon(FuncRequest const & f, bool unknown)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= 0x040600)
|
#if (QT_VERSION >= 0x040600)
|
||||||
@ -610,13 +628,13 @@ QIcon getIcon(FuncRequest const & f, bool unknown)
|
|||||||
return QIcon();
|
return QIcon();
|
||||||
|
|
||||||
//LYXERR(Debug::GUI, "Found icon: " << icon);
|
//LYXERR(Debug::GUI, "Found icon: " << icon);
|
||||||
QPixmap pm;
|
QPixmap pixmap = QPixmap();
|
||||||
if (!pm.load(icon)) {
|
if (!getPixmap(pixmap,icon)) {
|
||||||
LYXERR0("Cannot load icon " << icon << " please verify resource system!");
|
LYXERR0("Cannot load icon " << icon << " please verify resource system!");
|
||||||
return QIcon();
|
return QIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QIcon(pm);
|
return QIcon(pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2423,6 +2441,9 @@ void GuiApplication::execBatchCommands()
|
|||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#if QT_VERSION > 0x040600
|
#if QT_VERSION > 0x040600
|
||||||
setAttribute(Qt::AA_MacDontSwapCtrlAndMeta,lyxrc.mac_dontswap_ctrl_meta);
|
setAttribute(Qt::AA_MacDontSwapCtrlAndMeta,lyxrc.mac_dontswap_ctrl_meta);
|
||||||
|
#endif
|
||||||
|
#if QT_VERSION > 0x050100
|
||||||
|
setAttribute(Qt::AA_UseHighDpiPixmaps,true);
|
||||||
#endif
|
#endif
|
||||||
// Create the global default menubar which is shown for the dialogs
|
// Create the global default menubar which is shown for the dialogs
|
||||||
// and if no GuiView is visible.
|
// and if no GuiView is visible.
|
||||||
|
@ -247,7 +247,12 @@ extern GuiApplication * guiApp;
|
|||||||
QString iconName(FuncRequest const & f, bool unknown);
|
QString iconName(FuncRequest const & f, bool unknown);
|
||||||
|
|
||||||
/// \return the pixmap for the given path, name and extension.
|
/// \return the pixmap for the given path, name and extension.
|
||||||
|
/// in case of errors a warning is produced and an empty pixmap is returned.
|
||||||
QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
|
QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
|
||||||
|
/// Load the file at \param path and convert it to a pixmap.
|
||||||
|
/// \return true on success otherwise invalidate the pixmap and return false.
|
||||||
|
/// The caller is responsible for error reporting.
|
||||||
|
bool getPixmap(QPixmap & pixmap, QString const & path);
|
||||||
|
|
||||||
/// \return an icon for the given action.
|
/// \return an icon for the given action.
|
||||||
QIcon getIcon(FuncRequest const & f, bool unknown);
|
QIcon getIcon(FuncRequest const & f, bool unknown);
|
||||||
|
@ -141,8 +141,9 @@ bool GuiImage::clip(Params const & params)
|
|||||||
// No clipping is necessary.
|
// No clipping is necessary.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int const new_width = params.bb.xr - params.bb.xl;
|
double const pixelRatio = is_transformed_ ? transformed_.devicePixelRatio() : original_.devicePixelRatio();
|
||||||
int const new_height = params.bb.yt - params.bb.yb;
|
int const new_width = static_cast<int>((params.bb.xr - params.bb.xl) * pixelRatio);
|
||||||
|
int const new_height = static_cast<int>((params.bb.yt - params.bb.yb) * pixelRatio);
|
||||||
|
|
||||||
QImage const & image = is_transformed_ ? transformed_ : original_;
|
QImage const & image = is_transformed_ ? transformed_ : original_;
|
||||||
|
|
||||||
@ -185,7 +186,8 @@ bool GuiImage::scale(Params const & params)
|
|||||||
if (params.scale == 100)
|
if (params.scale == 100)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
qreal scale = qreal(params.scale) / 100.0;
|
double const pixelRatio = is_transformed_ ? transformed_.devicePixelRatio() : original_.devicePixelRatio();
|
||||||
|
qreal scale = qreal(params.scale) / 100.0 * pixelRatio;
|
||||||
|
|
||||||
#if (QT_VERSION >= 0x040500) && (QT_VERSION <= 0x040502)
|
#if (QT_VERSION >= 0x040500) && (QT_VERSION <= 0x040502)
|
||||||
// Due to a bug in Qt, LyX will crash for certain
|
// Due to a bug in Qt, LyX will crash for certain
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "TocModel.h"
|
#include "TocModel.h"
|
||||||
|
|
||||||
#include "qt_helpers.h"
|
#include "qt_helpers.h"
|
||||||
|
#include "support/filetools.h"
|
||||||
|
|
||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
#include "frontends/KeySymbol.h"
|
#include "frontends/KeySymbol.h"
|
||||||
@ -109,6 +110,7 @@
|
|||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <QSvgRenderer>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -149,7 +151,8 @@ namespace {
|
|||||||
class BackgroundWidget : public QWidget
|
class BackgroundWidget : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BackgroundWidget()
|
BackgroundWidget(int width, int height)
|
||||||
|
: width_(width), height_(height)
|
||||||
{
|
{
|
||||||
LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
|
LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
|
||||||
if (!lyxrc.show_banner)
|
if (!lyxrc.show_banner)
|
||||||
@ -157,32 +160,40 @@ public:
|
|||||||
/// The text to be written on top of the pixmap
|
/// The text to be written on top of the pixmap
|
||||||
QString const text = lyx_version ?
|
QString const text = lyx_version ?
|
||||||
qt_("version ") + lyx_version : qt_("unknown version");
|
qt_("version ") + lyx_version : qt_("unknown version");
|
||||||
splash_ = getPixmap("images/", "banner", "svgz,png");
|
QString imagedir = "images/";
|
||||||
|
FileName fname = imageLibFileSearch(imagedir, "banner", "svgz");
|
||||||
|
QSvgRenderer svgRenderer(toqstr(fname.absFileName()));
|
||||||
|
if (svgRenderer.isValid()) {
|
||||||
|
splash_ = QPixmap(splashSize());
|
||||||
|
QPainter painter(&splash_);
|
||||||
|
svgRenderer.render(&painter);
|
||||||
|
splash_.setDevicePixelRatio(pixelRatio());
|
||||||
|
} else {
|
||||||
|
splash_ = getPixmap("images/", "banner", "png");
|
||||||
|
}
|
||||||
|
|
||||||
QPainter pain(&splash_);
|
QPainter pain(&splash_);
|
||||||
pain.setPen(QColor(0, 0, 0));
|
pain.setPen(QColor(0, 0, 0));
|
||||||
double const multiplier = splashPixelRatio() / pixelRatio();
|
qreal const fsize = fontSize();
|
||||||
int const size = static_cast<int>(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble() * multiplier);
|
QPointF const position = textPosition();
|
||||||
int const x = static_cast<int>(190 * multiplier);
|
|
||||||
int const y = static_cast<int>(225 * multiplier);
|
|
||||||
LYXERR(Debug::GUI,
|
LYXERR(Debug::GUI,
|
||||||
"widget pixel ratio: " << pixelRatio() <<
|
"widget pixel ratio: " << pixelRatio() <<
|
||||||
" splash pixel ratio: " << splashPixelRatio() <<
|
" splash pixel ratio: " << splashPixelRatio() <<
|
||||||
" version text size,position: " << size << "@" << x << "+" << y);
|
" version text size,position: " << fsize << "@" << position.x() << "+" << position.y());
|
||||||
QFont font;
|
QFont font;
|
||||||
// The font used to display the version info
|
// The font used to display the version info
|
||||||
font.setStyleHint(QFont::SansSerif);
|
font.setStyleHint(QFont::SansSerif);
|
||||||
font.setWeight(QFont::Bold);
|
font.setWeight(QFont::Bold);
|
||||||
font.setPointSize(size);
|
font.setPointSizeF(fsize);
|
||||||
pain.setFont(font);
|
pain.setFont(font);
|
||||||
pain.drawText(x, y, text);
|
pain.drawText(position, text);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *)
|
void paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
int const w = static_cast<int>(splash_.width() / splashPixelRatio());
|
int const w = width_;
|
||||||
int const h = static_cast<int>(splash_.height() / splashPixelRatio());
|
int const h = height_;
|
||||||
int const x = (width() - w) / 2;
|
int const x = (width() - w) / 2;
|
||||||
int const y = (height() - h) / 2;
|
int const y = (height() - h) / 2;
|
||||||
LYXERR(Debug::GUI,
|
LYXERR(Debug::GUI,
|
||||||
@ -207,6 +218,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap splash_;
|
QPixmap splash_;
|
||||||
|
int const width_;
|
||||||
|
int const height_;
|
||||||
|
|
||||||
/// Current ratio between physical pixels and device-independent pixels
|
/// Current ratio between physical pixels and device-independent pixels
|
||||||
double pixelRatio() const {
|
double pixelRatio() const {
|
||||||
@ -217,6 +230,26 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal fontSize() {
|
||||||
|
return toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF textPosition() {
|
||||||
|
return QPointF(splashWidth()/2 - 16, splashHeigth() - 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize splashSize() {
|
||||||
|
return QSize(width_ * pixelRatio(),height_ * pixelRatio());
|
||||||
|
}
|
||||||
|
|
||||||
|
double splashWidth() {
|
||||||
|
return splash_.width()/splashPixelRatio();
|
||||||
|
}
|
||||||
|
|
||||||
|
double splashHeigth() {
|
||||||
|
return splash_.height()/splashPixelRatio();
|
||||||
|
}
|
||||||
|
|
||||||
/// Ratio between physical pixels and device-independent pixels of splash image
|
/// Ratio between physical pixels and device-independent pixels of splash image
|
||||||
double splashPixelRatio() const {
|
double splashPixelRatio() const {
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
@ -264,7 +297,7 @@ struct GuiView::GuiViewPrivate
|
|||||||
}
|
}
|
||||||
|
|
||||||
splitter_ = new QSplitter;
|
splitter_ = new QSplitter;
|
||||||
bg_widget_ = new BackgroundWidget;
|
bg_widget_ = new BackgroundWidget(400, 250);
|
||||||
stack_widget_ = new QStackedWidget;
|
stack_widget_ = new QStackedWidget;
|
||||||
stack_widget_->addWidget(bg_widget_);
|
stack_widget_->addWidget(bg_widget_);
|
||||||
stack_widget_->addWidget(splitter_);
|
stack_widget_->addWidget(splitter_);
|
||||||
|
@ -460,6 +460,10 @@ void Loader::Impl::createPixmap()
|
|||||||
if (idx != string::npos && idx > 3) {
|
if (idx != string::npos && idx > 3) {
|
||||||
if (filename.substr(idx - 3, 3) == "@2x") {
|
if (filename.substr(idx - 3, 3) == "@2x") {
|
||||||
params_.pixel_ratio = 2.0;
|
params_.pixel_ratio = 2.0;
|
||||||
|
} else if (cached_item_->filename().extension() == "svgz") {
|
||||||
|
params_.pixel_ratio = 4.0;
|
||||||
|
} else if (cached_item_->filename().extension() == "svg") {
|
||||||
|
params_.pixel_ratio = 4.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user