* 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
#include <queue>
+#include <QFontDatabase>
#include <QByteArray>
#include <QClipboard>
#include <QDateTime>
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;
}
class QAbstractItemModel;
class QIcon;
class QSessionManager;
+class QFont;
namespace lyx {
/// return a suitable monospaced font name.
QString const typewriterFontName();
+ QFont const typewriterSystemFont();
+
///
void unregisterView(GuiView * gv);
///
// 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()));
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());
}
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()),
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);
}