diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index b0a8853e..d1ada3ea 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -12,8 +12,9 @@ import "./delegates" Rectangle { anchors.fill: parent - SystemPalette { id: colors; colorGroup: SystemPalette.Active } - SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Disabled } + property var colors: currentActivePalette + property var systemInactive: SystemPalette { colorGroup: SystemPalette.Disabled } + property var inactiveColors: currentInactivePalette ? currentInactivePalette : systemInactive property int avatarSize: 32 color: colors.window diff --git a/resources/qml/delegates/TimelineRow.qml b/resources/qml/delegates/TimelineRow.qml index 28a2ec8c..3019deb1 100644 --- a/resources/qml/delegates/TimelineRow.qml +++ b/resources/qml/delegates/TimelineRow.qml @@ -1,5 +1,5 @@ import QtQuick 2.6 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.3 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 import QtQuick.Window 2.2 @@ -48,8 +48,12 @@ RowLayout { id: replyButton flat: true Layout.preferredHeight: 16 - ToolTip.visible: hovered - ToolTip.text: qsTr("Reply") + + ToolTip { + visible: replyButton.hovered + text: qsTr("Reply") + palette: colors + } // disable background, because we don't want a border on hover background: Item { @@ -74,8 +78,12 @@ RowLayout { id: optionsButton flat: true Layout.preferredHeight: 16 - ToolTip.visible: hovered - ToolTip.text: qsTr("Options") + + ToolTip { + visible: optionsButton.hovered + text: qsTr("Options") + palette: colors + } // disable background, because we don't want a border on hover background: Item { @@ -98,6 +106,7 @@ RowLayout { Menu { y: optionsButton.height id: contextMenu + palette: colors MenuItem { text: qsTr("Read receipts") @@ -127,13 +136,16 @@ RowLayout { text: model.timestamp.toLocaleTimeString("HH:mm") color: inactiveColors.text - ToolTip.visible: ma.containsMouse - ToolTip.text: Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleLongDate) - MouseArea{ id: ma anchors.fill: parent hoverEnabled: true } + + ToolTip { + visible: ma.containsMouse + text: Qt.formatDateTime(model.timestamp, Qt.DefaultLocaleLongDate) + palette: colors + } } } diff --git a/src/Utils.cpp b/src/Utils.cpp index d458dbcc..5a1447ac 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -323,19 +323,29 @@ utils::linkifyMessage(const QString &body) return doc; } -QByteArray escapeRawHtml(const QByteArray &data) { - QByteArray buffer; - const size_t length = data.size(); - buffer.reserve(length); - for(size_t pos = 0; pos != length; ++pos) { - switch(data.at(pos)) { - case '&': buffer.append("&"); break; - case '<': buffer.append("<"); break; - case '>': buffer.append(">"); break; - default: buffer.append(data.at(pos)); break; - } - } - return buffer; +QByteArray +escapeRawHtml(const QByteArray &data) +{ + QByteArray buffer; + const size_t length = data.size(); + buffer.reserve(length); + for (size_t pos = 0; pos != length; ++pos) { + switch (data.at(pos)) { + case '&': + buffer.append("&"); + break; + case '<': + buffer.append("<"); + break; + case '>': + buffer.append(">"); + break; + default: + buffer.append(data.at(pos)); + break; + } + } + return buffer; } QString diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp index 13025864..057f03de 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp @@ -3,13 +3,51 @@ #include #include #include +#include #include #include +#include "ChatPage.h" #include "Logging.h" #include "MxcImageProvider.h" +#include "UserSettingsPage.h" #include "dialogs/ImageOverlay.h" +void +TimelineViewManager::updateColorPalette() +{ + UserSettings settings; + if (settings.theme() == "light") { + QPalette lightActive(/*windowText*/ QColor("#333"), + /*button*/ QColor("#333"), + /*light*/ QColor(), + /*dark*/ QColor(220, 220, 220, 120), + /*mid*/ QColor(), + /*text*/ QColor("#333"), + /*bright_text*/ QColor(), + /*base*/ QColor("white"), + /*window*/ QColor("white")); + view->rootContext()->setContextProperty("currentActivePalette", lightActive); + view->rootContext()->setContextProperty("currentInactivePalette", lightActive); + } else if (settings.theme() == "dark") { + QPalette darkActive(/*windowText*/ QColor("#caccd1"), + /*button*/ QColor("#caccd1"), + /*light*/ QColor(), + /*dark*/ QColor(45, 49, 57, 120), + /*mid*/ QColor(), + /*text*/ QColor("#caccd1"), + /*bright_text*/ QColor(), + /*base*/ QColor("#202228"), + /*window*/ QColor("#202228")); + darkActive.setColor(QPalette::Highlight, QColor("#e7e7e9")); + view->rootContext()->setContextProperty("currentActivePalette", darkActive); + view->rootContext()->setContextProperty("currentInactivePalette", darkActive); + } else { + view->rootContext()->setContextProperty("currentActivePalette", QPalette()); + view->rootContext()->setContextProperty("currentInactivePalette", nullptr); + } +} + TimelineViewManager::TimelineViewManager(QWidget *parent) : imgProvider(new MxcImageProvider()) { @@ -23,8 +61,14 @@ TimelineViewManager::TimelineViewManager(QWidget *parent) container = QWidget::createWindowContainer(view, parent); container->setMinimumSize(200, 200); view->rootContext()->setContextProperty("timelineManager", this); + updateColorPalette(); view->engine()->addImageProvider("MxcImage", imgProvider); view->setSource(QUrl("qrc:///qml/TimelineView.qml")); + + connect(dynamic_cast(parent), + &ChatPage::themeChanged, + this, + &TimelineViewManager::updateColorPalette); } void diff --git a/src/timeline2/TimelineViewManager.h b/src/timeline2/TimelineViewManager.h index 6a6d3c6b..b14e78ff 100644 --- a/src/timeline2/TimelineViewManager.h +++ b/src/timeline2/TimelineViewManager.h @@ -71,6 +71,7 @@ public slots: void initWithMessages(const std::map &msgs); void setHistoryView(const QString &room_id); + void updateColorPalette(); void queueTextMessage(const QString &msg); void queueReplyMessage(const QString &reply, const RelatedInfo &related);