]> git.lyx.org Git - lyx.git/commitdiff
Improved fix for #9966
authorStephan Witt <switt@lyx.org>
Fri, 15 Apr 2016 09:49:04 +0000 (11:49 +0200)
committerStephan Witt <switt@lyx.org>
Fri, 15 Apr 2016 09:49:04 +0000 (11:49 +0200)
* 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

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiLog.cpp
src/frontends/qt4/GuiProgressView.cpp
src/frontends/qt4/GuiViewSource.cpp

index 12f99d55970661c47aa0b1b05527ad6d18688153..6fb5499981d07fdf36eb972153b98f4f84dbab46 100644 (file)
@@ -82,6 +82,7 @@
 
 #include <queue>
 
+#include <QFontDatabase>
 #include <QByteArray>
 #include <QClipboard>
 #include <QDateTime>
@@ -2557,11 +2558,41 @@ QString const GuiApplication::sansFontName()
 
 QString const GuiApplication::typewriterFontName()
 {
-       QFont font;
-       font.setStyleHint(QFont::TypeWriter);
-       font.setFamily("monospace");
+       return QFontInfo(typewriterSystemFont()).family();
+}
 
-       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;
 }
 
 
index 350adc871893f885bff413caa9bd651ccaf9fd73..861810daec4dcfce88beede8d54cf0aee6cf2771 100644 (file)
@@ -25,6 +25,7 @@
 class QAbstractItemModel;
 class QIcon;
 class QSessionManager;
+class QFont;
 
 namespace lyx {
 
@@ -145,6 +146,8 @@ public:
 
        /// return a suitable monospaced font name.
        QString const typewriterFontName();
+       QFont const typewriterSystemFont();
+
        ///
        void unregisterView(GuiView * gv);
        ///
index e4dff1d9818a21701227d745a1a58418572e3775..2eedec9fe0512ad0a2a42d0c72d72b104179ea3b 100644 (file)
@@ -453,10 +453,7 @@ PreambleModule::PreambleModule() : current_id_(0)
        // This is not a memory leak. The object will be destroyed
        // with this.
        (void) new LaTeXHighlighter(preambleTE->document());
-       QFont font(guiApp->typewriterFontName());
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       preambleTE->setFont(font);
+       preambleTE->setFont(guiApp->typewriterSystemFont());
        preambleTE->setWordWrapMode(QTextOption::NoWrap);
        setFocusProxy(preambleTE);
        connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
index dec7c25c7e38378ded520686de7b083697fdf90e..23ba276d8a70cc74c27cfd344444b95a129cfe5b 100644 (file)
@@ -133,10 +133,7 @@ GuiLog::GuiLog(GuiView & lv)
        highlighter = new LogHighlighter(logTB->document());
 
        logTB->setReadOnly(true);
-       QFont font(guiApp->typewriterFontName());
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       logTB->setFont(font);
+       logTB->setFont(guiApp->typewriterSystemFont());
 }
 
 
index fa157865e766f09c3f99a657e84fd2b01c4adea9..af455f2b880918ef3ad2b53ff2d27ce16dc09b9f 100644 (file)
@@ -71,10 +71,7 @@ GuiProgressView::GuiProgressView(GuiView & parent, Qt::DockWidgetArea area,
        widget_->adjustSize();
        setWidget(widget_);
 
-       QFont font(guiApp->typewriterFontName());
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       widget_->outTE->setFont(font);
+       widget_->outTE->setFont(guiApp->typewriterSystemFont());
        widget_->tabWidget->widget(0)->setContentsMargins(-5, -7, 0, -7);
 
        connect(widget_->debugNoneRB, SIGNAL(clicked()),
index e528222dad5b6bcaff2e5997141549bca3756d1e..192a163faf203dfe9b341fa3a67463ec21732749 100644 (file)
@@ -86,10 +86,7 @@ ViewSourceWidget::ViewSourceWidget()
        viewSourceTV->setReadOnly(true);
        ///dialog_->viewSourceTV->setAcceptRichText(false);
        // this is personal. I think source code should be in fixed-size font
-       QFont font(guiApp->typewriterFontName());
-       font.setFixedPitch(true);
-       font.setStyleHint(QFont::TypeWriter);
-       viewSourceTV->setFont(font);
+       viewSourceTV->setFont(guiApp->typewriterSystemFont());
        // again, personal taste
        viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
 }