From aebb38a8f1e223934ff3093fc87a557156f10366 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Tue, 23 Aug 2016 11:51:56 +0200
Subject: Improve chat view font handling

This changes the minimal font scaling to 0.8em, so that the
font size in the chat view can be smaller than the font size
in the rest of the application.

At 1.0em the font in the chat view has the same size as the
rest of the application.

Also changed fixed pixel sizes in main.css to relative
percentage sizes.

Test-Information:

Verified the font size in the chat view is the same as the
font size for the contact lists at 1.0em on Windows and OS X
with Qt 5.5.1.

Change-Id: Ib625f11cea0aacd31edee27c2dc89df5e2cbd1c4

diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index f369e35..f8ced92 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -19,6 +19,7 @@
 #include <QTimer>
 #include <QVBoxLayout>
 #include <QWebFrame>
+#include <QWebSettings>
 #include <QtDebug>
 
 #include <Swiften/Base/FileSize.h>
@@ -49,6 +50,10 @@ const QString QtWebKitChatView::ButtonFileTransferAcceptRequest = QString("filet
 const QString QtWebKitChatView::ButtonFileTransferOpenFile = QString("filetransfer-openfile");
 const QString QtWebKitChatView::ButtonMUCInvite = QString("mucinvite");
 
+namespace {
+    const double minimalFontScaling = 0.8;
+}
+
 QtWebKitChatView::QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll) : QtChatView(parent), window_(window), eventStream_(eventStream), fontSizeSteps_(0), disableAutoScroll_(disableAutoScroll), previousMessageKind_(PreviosuMessageWasNone), previousMessageWasSelf_(false), showEmoticons_(false), insertingLastLine_(false), idCounter_(0) {
     theme_ = theme;
 
@@ -301,14 +306,14 @@ void QtWebKitChatView::decreaseFontSize() {
 
 void QtWebKitChatView::resizeFont(int fontSizeSteps) {
     fontSizeSteps_ = fontSizeSteps;
-    double size = 1.0 + 0.2 * fontSizeSteps_;
+    double size = minimalFontScaling + 0.2 * fontSizeSteps_;
     QString sizeString(QString().setNum(size, 'g', 3) + "em");
 
     // Set the font size in the <style id="text-resize-style"> element in the theme <head> element.
     QWebElement resizableTextStyle = document_.findFirst("style#text-resize-style");
     assert(!resizableTextStyle.isNull());
     resizableTextStyle.setInnerXml(QString("span.swift_resizable { font-size: %1;}").arg(sizeString));
-    webView_->setFontSizeIsMinimal(size == 1.0);
+    webView_->setFontSizeIsMinimal(size == minimalFontScaling);
 }
 
 void QtWebKitChatView::resetView() {
@@ -341,6 +346,8 @@ void QtWebKitChatView::resetView() {
     QWebElement body = document_.findFirst("body");
     assert(!body.isNull());
     body.setAttribute("onscroll", "chatwindow.verticalScrollBarPositionChanged(document.body.scrollTop / (document.body.scrollHeight - window.innerHeight))");
+
+    webView_->settings()->setFontSize(QWebSettings::DefaultFontSize, QApplication::font().pointSize());
 }
 
 static QWebElement findElementWithID(QWebElement document, QString elementName, QString id) {
diff --git a/Swift/resources/themes/Default/main.css b/Swift/resources/themes/Default/main.css
index 35b55c7..05e7a04 100644
--- a/Swift/resources/themes/Default/main.css
+++ b/Swift/resources/themes/Default/main.css
@@ -2,7 +2,6 @@
 
 body {
     font-family: 'Lato', sans-serif;
-    font-size: 14px;
     margin: 0;
     padding: 0;
 }
@@ -72,7 +71,7 @@ body {
     color: #ffd180;
     border-top: solid 1px #ffd180;
     margin-left: 20px;
-    margin-right: 20px;;
+    margin-right: 20px;
 }
 
 /* Left column content */
@@ -104,7 +103,7 @@ body {
     margin-bottom: 1px;
     margin-right: 10px;
     color: #f9f9f9;
-    font-size: 10px;
+    font-size: 80%;
     font-weight: 300;
 }
 
@@ -119,7 +118,7 @@ body {
     margin-bottom: 1px;
     margin-right: 10px;
     color: #f9f9f9;
-    font-size: 10px;
+    font-size: 80%;
     font-weight: 300;
 }
 
@@ -217,7 +216,6 @@ body {
     display: table-cell;
     border: inherit;
     margin-left: 175px;
-    font-size: 14px;
     color: #595959;
     vertical-align: top;
 
-- 
cgit v0.10.2-6-g49f6