mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +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,20 +566,37 @@ QString iconName(FuncRequest const & f, bool unknown)
|
||||
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 pixmap;
|
||||
QString imagedir = path;
|
||||
FileName fname = imageLibFileSearch(imagedir, name, ext, theGuiApp()->imageSearchMode());
|
||||
QString fpath = toqstr(fname.absFileName());
|
||||
QPixmap pixmap = QPixmap();
|
||||
|
||||
if (pixmap.load(fpath)) {
|
||||
if (getPixmap(pixmap, fpath)) {
|
||||
return pixmap;
|
||||
} else {
|
||||
}
|
||||
|
||||
QStringList exts = ext.split(",");
|
||||
fpath = ":/" + path + name + ".";
|
||||
for (int i = 0; i < exts.size(); ++i) {
|
||||
if (pixmap.load(fpath + exts.at(i)))
|
||||
if (getPixmap(pixmap, fpath + exts.at(i))) {
|
||||
return pixmap;
|
||||
}
|
||||
}
|
||||
@ -592,6 +609,7 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
|
||||
QIcon getIcon(FuncRequest const & f, bool unknown)
|
||||
{
|
||||
#if (QT_VERSION >= 0x040600)
|
||||
@ -610,13 +628,13 @@ QIcon getIcon(FuncRequest const & f, bool unknown)
|
||||
return QIcon();
|
||||
|
||||
//LYXERR(Debug::GUI, "Found icon: " << icon);
|
||||
QPixmap pm;
|
||||
if (!pm.load(icon)) {
|
||||
QPixmap pixmap = QPixmap();
|
||||
if (!getPixmap(pixmap,icon)) {
|
||||
LYXERR0("Cannot load icon " << icon << " please verify resource system!");
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
return QIcon(pm);
|
||||
return QIcon(pixmap);
|
||||
}
|
||||
|
||||
|
||||
@ -2423,6 +2441,9 @@ void GuiApplication::execBatchCommands()
|
||||
#ifdef Q_OS_MAC
|
||||
#if QT_VERSION > 0x040600
|
||||
setAttribute(Qt::AA_MacDontSwapCtrlAndMeta,lyxrc.mac_dontswap_ctrl_meta);
|
||||
#endif
|
||||
#if QT_VERSION > 0x050100
|
||||
setAttribute(Qt::AA_UseHighDpiPixmaps,true);
|
||||
#endif
|
||||
// Create the global default menubar which is shown for the dialogs
|
||||
// and if no GuiView is visible.
|
||||
|
@ -247,7 +247,12 @@ extern GuiApplication * guiApp;
|
||||
QString iconName(FuncRequest const & f, bool unknown);
|
||||
|
||||
/// \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);
|
||||
/// 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.
|
||||
QIcon getIcon(FuncRequest const & f, bool unknown);
|
||||
|
@ -141,8 +141,9 @@ bool GuiImage::clip(Params const & params)
|
||||
// No clipping is necessary.
|
||||
return false;
|
||||
|
||||
int const new_width = params.bb.xr - params.bb.xl;
|
||||
int const new_height = params.bb.yt - params.bb.yb;
|
||||
double const pixelRatio = is_transformed_ ? transformed_.devicePixelRatio() : original_.devicePixelRatio();
|
||||
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_;
|
||||
|
||||
@ -185,7 +186,8 @@ bool GuiImage::scale(Params const & params)
|
||||
if (params.scale == 100)
|
||||
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)
|
||||
// Due to a bug in Qt, LyX will crash for certain
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "TocModel.h"
|
||||
|
||||
#include "qt_helpers.h"
|
||||
#include "support/filetools.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/KeySymbol.h"
|
||||
@ -109,6 +110,7 @@
|
||||
#include <QSplitter>
|
||||
#include <QStackedWidget>
|
||||
#include <QStatusBar>
|
||||
#include <QSvgRenderer>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
@ -149,7 +151,8 @@ namespace {
|
||||
class BackgroundWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
BackgroundWidget()
|
||||
BackgroundWidget(int width, int height)
|
||||
: width_(width), height_(height)
|
||||
{
|
||||
LYXERR(Debug::GUI, "show banner: " << lyxrc.show_banner);
|
||||
if (!lyxrc.show_banner)
|
||||
@ -157,32 +160,40 @@ public:
|
||||
/// The text to be written on top of the pixmap
|
||||
QString const text = lyx_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_);
|
||||
pain.setPen(QColor(0, 0, 0));
|
||||
double const multiplier = splashPixelRatio() / pixelRatio();
|
||||
int const size = static_cast<int>(toqstr(lyxrc.font_sizes[FONT_SIZE_LARGE]).toDouble() * multiplier);
|
||||
int const x = static_cast<int>(190 * multiplier);
|
||||
int const y = static_cast<int>(225 * multiplier);
|
||||
qreal const fsize = fontSize();
|
||||
QPointF const position = textPosition();
|
||||
LYXERR(Debug::GUI,
|
||||
"widget pixel ratio: " << pixelRatio() <<
|
||||
" splash pixel ratio: " << splashPixelRatio() <<
|
||||
" version text size,position: " << size << "@" << x << "+" << y);
|
||||
" version text size,position: " << fsize << "@" << position.x() << "+" << position.y());
|
||||
QFont font;
|
||||
// The font used to display the version info
|
||||
font.setStyleHint(QFont::SansSerif);
|
||||
font.setWeight(QFont::Bold);
|
||||
font.setPointSize(size);
|
||||
font.setPointSizeF(fsize);
|
||||
pain.setFont(font);
|
||||
pain.drawText(x, y, text);
|
||||
pain.drawText(position, text);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
void paintEvent(QPaintEvent *)
|
||||
{
|
||||
int const w = static_cast<int>(splash_.width() / splashPixelRatio());
|
||||
int const h = static_cast<int>(splash_.height() / splashPixelRatio());
|
||||
int const w = width_;
|
||||
int const h = height_;
|
||||
int const x = (width() - w) / 2;
|
||||
int const y = (height() - h) / 2;
|
||||
LYXERR(Debug::GUI,
|
||||
@ -207,6 +218,8 @@ public:
|
||||
|
||||
private:
|
||||
QPixmap splash_;
|
||||
int const width_;
|
||||
int const height_;
|
||||
|
||||
/// Current ratio between physical pixels and device-independent pixels
|
||||
double pixelRatio() const {
|
||||
@ -217,6 +230,26 @@ private:
|
||||
#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
|
||||
double splashPixelRatio() const {
|
||||
#if QT_VERSION >= 0x050000
|
||||
@ -264,7 +297,7 @@ struct GuiView::GuiViewPrivate
|
||||
}
|
||||
|
||||
splitter_ = new QSplitter;
|
||||
bg_widget_ = new BackgroundWidget;
|
||||
bg_widget_ = new BackgroundWidget(400, 250);
|
||||
stack_widget_ = new QStackedWidget;
|
||||
stack_widget_->addWidget(bg_widget_);
|
||||
stack_widget_->addWidget(splitter_);
|
||||
|
@ -460,6 +460,10 @@ void Loader::Impl::createPixmap()
|
||||
if (idx != string::npos && idx > 3) {
|
||||
if (filename.substr(idx - 3, 3) == "@2x") {
|
||||
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