Improved fix for #9966

* provide GuiApplication::typewriterSystemFont() to get a fixed font consistently
* enlarge fixed font on Mac because of the too small default Qt system font
* use it in source pane, progress view, log view and document preamble editor
This commit is contained in:
Stephan Witt 2016-04-15 11:49:04 +02:00
parent 4807338ba9
commit 87c85303c5
6 changed files with 42 additions and 20 deletions

View File

@ -82,6 +82,7 @@
#include <queue> #include <queue>
#include <QFontDatabase>
#include <QByteArray> #include <QByteArray>
#include <QClipboard> #include <QClipboard>
#include <QDateTime> #include <QDateTime>
@ -2557,11 +2558,41 @@ QString const GuiApplication::sansFontName()
QString const GuiApplication::typewriterFontName() QString const GuiApplication::typewriterFontName()
{ {
QFont font; return QFontInfo(typewriterSystemFont()).family();
font.setStyleHint(QFont::TypeWriter); }
font.setFamily("monospace");
return QFontInfo(font).family();
namespace {
// We cannot use QFont::fixedPitch() because it doesn't
// return the fact but only if it is requested.
static bool isFixedPitch(const QFont & font) {
const QFontInfo fi(font);
return fi.fixedPitch();
}
}
QFont const GuiApplication::typewriterSystemFont()
{
#if QT_VERSION >= 0x050200
QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
#else
QFont font("monospace");
#endif
if (!isFixedPitch(font)) {
// try to enforce a real monospaced font
font.setStyleHint(QFont::Monospace);
if (!isFixedPitch(font)) {
font.setStyleHint(QFont::TypeWriter);
if (!isFixedPitch(font)) font.setFamily("courier");
}
}
#ifdef Q_OS_MAC
// On a Mac the result is too small and it's not practical to
// rely on Qtconfig utility to change the system settings of Qt.
font.setPointSize(12);
#endif
return font;
} }

View File

@ -25,6 +25,7 @@
class QAbstractItemModel; class QAbstractItemModel;
class QIcon; class QIcon;
class QSessionManager; class QSessionManager;
class QFont;
namespace lyx { namespace lyx {
@ -145,6 +146,8 @@ public:
/// return a suitable monospaced font name. /// return a suitable monospaced font name.
QString const typewriterFontName(); QString const typewriterFontName();
QFont const typewriterSystemFont();
/// ///
void unregisterView(GuiView * gv); void unregisterView(GuiView * gv);
/// ///

View File

@ -453,10 +453,7 @@ PreambleModule::PreambleModule() : current_id_(0)
// This is not a memory leak. The object will be destroyed // This is not a memory leak. The object will be destroyed
// with this. // with this.
(void) new LaTeXHighlighter(preambleTE->document()); (void) new LaTeXHighlighter(preambleTE->document());
QFont font(guiApp->typewriterFontName()); preambleTE->setFont(guiApp->typewriterSystemFont());
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
preambleTE->setFont(font);
preambleTE->setWordWrapMode(QTextOption::NoWrap); preambleTE->setWordWrapMode(QTextOption::NoWrap);
setFocusProxy(preambleTE); setFocusProxy(preambleTE);
connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed())); connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));

View File

@ -133,10 +133,7 @@ GuiLog::GuiLog(GuiView & lv)
highlighter = new LogHighlighter(logTB->document()); highlighter = new LogHighlighter(logTB->document());
logTB->setReadOnly(true); logTB->setReadOnly(true);
QFont font(guiApp->typewriterFontName()); logTB->setFont(guiApp->typewriterSystemFont());
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
logTB->setFont(font);
} }

View File

@ -71,10 +71,7 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
widget_->adjustSize(); widget_->adjustSize();
setWidget(widget_); setWidget(widget_);
QFont font(guiApp->typewriterFontName()); widget_->outTE->setFont(guiApp->typewriterSystemFont());
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
widget_->outTE->setFont(font);
widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7); widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
connect(widget_->debugNoneRB, SIGNAL(clicked()), connect(widget_->debugNoneRB, SIGNAL(clicked()),

View File

@ -86,10 +86,7 @@ ViewSourceWidget::ViewSourceWidget()
viewSourceTV->setReadOnly(true); viewSourceTV->setReadOnly(true);
///dialog_->viewSourceTV->setAcceptRichText(false); ///dialog_->viewSourceTV->setAcceptRichText(false);
// this is personal. I think source code should be in fixed-size font // this is personal. I think source code should be in fixed-size font
QFont font(guiApp->typewriterFontName()); viewSourceTV->setFont(guiApp->typewriterSystemFont());
font.setFixedPitch(true);
font.setStyleHint(QFont::TypeWriter);
viewSourceTV->setFont(font);
// again, personal taste // again, personal taste
viewSourceTV->setWordWrapMode(QTextOption::NoWrap); viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
} }