Add a dark mode, fixes #7

This commit is contained in:
Jeena 2016-07-20 17:32:33 +02:00
parent cca7f55760
commit 9a0e2e523a
7 changed files with 54 additions and 10 deletions

View file

@ -10,6 +10,11 @@ body {
font-weight: lighter; font-weight: lighter;
} }
body.nightmode {
background: #111;
color: #aaa;
}
h1 { h1 {
font-weight: lighter; font-weight: lighter;
font-size: 1.4em; font-size: 1.4em;
@ -24,6 +29,10 @@ h1 {
display: block; display: block;
} }
.nightmode #date {
border-bottom-color: #333;
}
.starred:after { .starred:after {
content: "*"; content: "*";
} }
@ -35,6 +44,10 @@ header p {
font-size: 0.8em; font-size: 0.8em;
} }
.nightmode header p {
color: #888;
}
a { a {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;

View file

@ -47,3 +47,8 @@ function setFont(font, size) {
document.body.style.fontFamily = font; document.body.style.fontFamily = font;
document.body.style.fontSize = size + "pt"; document.body.style.fontSize = size + "pt";
} }
function setNightmode(nightmode) {
if(nightmode) document.body.className = "nightmode";
else document.body.className = "";
}

View file

@ -12,10 +12,12 @@ Item {
property ApplicationWindow app property ApplicationWindow app
property int textFontSize: 14 property int textFontSize: 14
property bool nightmode
property int scrollJump: 48 property int scrollJump: 48
property int pageJump: parent.height property int pageJump: parent.height
Layout.minimumWidth: 400 Layout.minimumWidth: 400
onTextFontSizeChanged: webView.setDefaults() onTextFontSizeChanged: webView.setDefaults()
onNightmodeChanged: webView.setDefaults()
function scrollDown(jump) { function scrollDown(jump) {
if(!jump) { if(!jump) {
@ -60,6 +62,7 @@ Item {
var defFont = ', system, -apple-system, ".SFNSDisplay-Regular", "Helvetica Neue", "Lucida Grande"'; var defFont = ', system, -apple-system, ".SFNSDisplay-Regular", "Helvetica Neue", "Lucida Grande"';
webView.runJavaScript("document.body.style.fontFamily = \"'" + fontLabel.font.family + "'" + defFont + "\";"); webView.runJavaScript("document.body.style.fontFamily = \"'" + fontLabel.font.family + "'" + defFont + "\";");
webView.runJavaScript("document.body.style.fontSize = '" + content.textFontSize + "pt';"); webView.runJavaScript("document.body.style.fontSize = '" + content.textFontSize + "pt';");
webView.runJavaScript("setNightmode(" + (content.nightmode ? "true" : "false") + ")")
} }

View file

@ -4,6 +4,7 @@ import QtQuick.Controls 1.3
Item { Item {
property int textFontSize: 14 property int textFontSize: 14
property int smallfontSize: 11 property int smallfontSize: 11
property bool nightmode
Component.onCompleted: fixFontSize() Component.onCompleted: fixFontSize()
onTextFontSizeChanged: fixFontSize() onTextFontSizeChanged: fixFontSize()
@ -16,17 +17,15 @@ Item {
height: column.height + 20 height: column.height + 20
width: parent.parent.parent.width width: parent.parent.parent.width
Rectangle { Item {
anchors.fill: parent anchors.fill: parent
color: "transparent"
Rectangle { Item {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 15 anchors.leftMargin: 15
anchors.rightMargin: 15 anchors.rightMargin: 15
anchors.topMargin: 10 anchors.topMargin: 10
anchors.bottomMargin: 10 anchors.bottomMargin: 10
color: "transparent"
Column { Column {
id: column id: column
@ -38,7 +37,7 @@ Item {
text: feedTitle text: feedTitle
font.pointSize: smallfontSize font.pointSize: smallfontSize
textFormat: Text.PlainText textFormat: Text.PlainText
color: "gray" color: nightmode ? "#888" : "gray"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
@ -46,14 +45,14 @@ Item {
text: date.toLocaleString(Qt.locale(), Locale.ShortFormat) text: date.toLocaleString(Qt.locale(), Locale.ShortFormat)
font.pointSize: smallfontSize font.pointSize: smallfontSize
textFormat: Text.PlainText textFormat: Text.PlainText
color: "gray" color: nightmode ? "#888" : "gray"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
} }
Label { Label {
text: title text: title
color: read ? "gray" : "black" color: nightmode ? (read ? "#888" : "#aaa") : (read ? "gray" : "black")
font.pointSize: textFontSize font.pointSize: textFontSize
textFormat: Text.RichText textFormat: Text.RichText
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@ -64,7 +63,7 @@ Item {
text: excerpt text: excerpt
font.pointSize: smallfontSize font.pointSize: smallfontSize
textFormat: Text.RichText textFormat: Text.RichText
color: "gray" color: nightmode ? "#888" : "gray"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere wrapMode: Text.WrapAtWordBoundaryOrAnywhere
renderType: Text.NativeRendering renderType: Text.NativeRendering
width: parent.width width: parent.width
@ -76,7 +75,7 @@ Item {
anchors.top: parent.bottom anchors.top: parent.bottom
width: parent.width width: parent.width
height: 1 height: 1
color: "lightgray" color: nightmode ? "#222" : "lightgray"
} }
} }

View file

@ -11,6 +11,7 @@ ScrollView {
property Content content property Content content
property Post previousPost property Post previousPost
property int textFontSize: 14 property int textFontSize: 14
property bool nightmode
style: ScrollViewStyle { style: ScrollViewStyle {
transientScrollBars: true transientScrollBars: true
@ -39,6 +40,7 @@ ScrollView {
delegate: Component { delegate: Component {
PostListItem { PostListItem {
textFontSize: item.textFontSize textFontSize: item.textFontSize
nightmode: app.nightmode
} }
} }
@ -47,7 +49,7 @@ ScrollView {
Rectangle { Rectangle {
width: listView.currentItem.width width: listView.currentItem.width
height: listView.currentItem.height height: listView.currentItem.height
color: "lightblue" color: nightmode ? "#222" : "lightblue"
opacity: 0.5 opacity: 0.5
y: listView.currentItem.y y: listView.currentItem.y
} }

View file

@ -67,6 +67,12 @@ MenuBar {
Menu { Menu {
visible: menuBar.visible visible: menuBar.visible
title: qsTr("View") title: qsTr("View")
MenuItem {
text: qsTr("Night mode")
shortcut: "1"
onTriggered: app.toggleNightmode()
}
MenuItem { MenuItem {
text: qsTr("Zoom In") text: qsTr("Zoom In")
shortcut: "Ctrl++" shortcut: "Ctrl++"

View file

@ -9,6 +9,7 @@ ApplicationWindow {
id: app id: app
title: "FeedTheMonkey" title: "FeedTheMonkey"
visible: true visible: true
color: nightmode ? "#111" : "#eee"
minimumWidth: 480 minimumWidth: 480
minimumHeight: 320 minimumHeight: 320
@ -26,6 +27,7 @@ ApplicationWindow {
property int defaultTextFontSizeIndex: 3 property int defaultTextFontSizeIndex: 3
property int textFontSizeIndex: defaultTextFontSizeIndex property int textFontSizeIndex: defaultTextFontSizeIndex
property int textFontSize: fontSizes[textFontSizeIndex] property int textFontSize: fontSizes[textFontSizeIndex]
property bool nightmode: false
Settings { Settings {
id: settings id: settings
@ -36,6 +38,7 @@ ApplicationWindow {
property alias height: app.height property alias height: app.height
property alias sidebarWidth: sidebar.width property alias sidebarWidth: sidebar.width
property alias textFontSizeIndex: app.textFontSizeIndex property alias textFontSizeIndex: app.textFontSizeIndex
property alias nightmode: app.nightmode
} }
property TheMenuBar menu: TheMenuBar { property TheMenuBar menu: TheMenuBar {
@ -61,6 +64,10 @@ ApplicationWindow {
} }
} }
function toggleNightmode() {
app.nightmode = !app.nightmode
}
function zoomIn() { function zoomIn() {
if(textFontSizeIndex + 1 < fontSizes.length) { if(textFontSizeIndex + 1 < fontSizes.length) {
textFontSize = fontSizes[++textFontSizeIndex] textFontSize = fontSizes[++textFontSizeIndex]
@ -95,6 +102,9 @@ ApplicationWindow {
case Qt.Key_k: case Qt.Key_k:
sidebar.previous() sidebar.previous()
break break
case Qt.Key_1:
toggleNightmode()
break
case Qt.Key_Home: case Qt.Key_Home:
content.scrollUp() content.scrollUp()
break break
@ -133,6 +143,10 @@ ApplicationWindow {
orientation: Qt.Horizontal orientation: Qt.Horizontal
visible: serverLogin.loggedIn() visible: serverLogin.loggedIn()
focus: true focus: true
handleDelegate: Rectangle {
width: 1
color: app.nightmode ? "#333" : "#aaa"
}
Sidebar { Sidebar {
id: sidebar id: sidebar
@ -142,6 +156,7 @@ ApplicationWindow {
Layout.minimumWidth: 200 Layout.minimumWidth: 200
implicitWidth: 300 implicitWidth: 300
textFontSize: app.textFontSize textFontSize: app.textFontSize
nightmode: app.nightmode
} }
Content { Content {
@ -151,6 +166,7 @@ ApplicationWindow {
Layout.minimumWidth: 200 Layout.minimumWidth: 200
implicitWidth: 624 implicitWidth: 624
textFontSize: app.textFontSize textFontSize: app.textFontSize
nightmode: app.nightmode
} }
Keys.onPressed: keyPressed(event) Keys.onPressed: keyPressed(event)