From cb2922f0bc5846ba0a75071f9e06a10f40fd150d Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 10 Sep 2020 20:11:50 +0200 Subject: [PATCH] Some unifications in msg viewer. --- src/librssguard/gui/messagepreviewer.cpp | 61 ++++++++++------- src/librssguard/gui/messagepreviewer.h | 15 ++--- src/librssguard/gui/messagepreviewer.ui | 65 ------------------- src/librssguard/gui/newspaperpreviewer.cpp | 1 - src/librssguard/librssguard.pro | 2 +- src/librssguard/services/abstract/label.h | 2 + .../services/abstract/labelsnode.h | 2 + 7 files changed, 51 insertions(+), 97 deletions(-) delete mode 100644 src/librssguard/gui/messagepreviewer.ui diff --git a/src/librssguard/gui/messagepreviewer.cpp b/src/librssguard/gui/messagepreviewer.cpp index a429750fc..122ade174 100755 --- a/src/librssguard/gui/messagepreviewer.cpp +++ b/src/librssguard/gui/messagepreviewer.cpp @@ -4,12 +4,17 @@ #include "gui/dialogs/formmain.h" #include "gui/messagebox.h" +#include "gui/searchtextwidget.h" #include "miscellaneous/application.h" #include "miscellaneous/databasequeries.h" #include "network-web/webfactory.h" #include "services/abstract/serviceroot.h" +#include "gui/messagetextbrowser.h" + +#include #include +#include #include #include #include @@ -17,20 +22,20 @@ void MessagePreviewer::createConnections() { installEventFilter(this); - connect(m_ui.m_searchWidget, &SearchTextWidget::cancelSearch, this, [this]() { - m_ui.m_txtMessage->textCursor().clearSelection(); - m_ui.m_txtMessage->moveCursor(QTextCursor::MoveOperation::Left); + connect(m_searchWidget, &SearchTextWidget::cancelSearch, this, [this]() { + m_txtMessage->textCursor().clearSelection(); + m_txtMessage->moveCursor(QTextCursor::MoveOperation::Left); }); - connect(m_ui.m_searchWidget, &SearchTextWidget::searchForText, this, [this](const QString& text, bool backwards) { + connect(m_searchWidget, &SearchTextWidget::searchForText, this, [this](const QString& text, bool backwards) { if (backwards) { - m_ui.m_txtMessage->find(text, QTextDocument::FindFlag::FindBackward); + m_txtMessage->find(text, QTextDocument::FindFlag::FindBackward); } else { - m_ui.m_txtMessage->find(text); + m_txtMessage->find(text); } }); - connect(m_ui.m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl& url) { + connect(m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl& url) { if (url.toString().startsWith(INTERNAL_URL_PASSATTACHMENT) && m_root != nullptr && m_root->getParentServiceRoot()->downloadAttachmentOnMyOwn(url)) { @@ -94,7 +99,7 @@ void MessagePreviewer::createConnections() { &QAction::triggered, this, &MessagePreviewer::switchMessageImportance); - connect(m_ui.m_txtMessage, + connect(m_txtMessage, QOverload::of(&QTextBrowser::highlighted), [=](const QUrl& url) { Q_UNUSED(url) @@ -102,16 +107,28 @@ void MessagePreviewer::createConnections() { }); } -MessagePreviewer::MessagePreviewer(QWidget* parent) : QWidget(parent) { - m_ui.setupUi(this); - m_ui.m_txtMessage->viewport()->setAutoFillBackground(true); - m_toolBar = new QToolBar(this); +MessagePreviewer::MessagePreviewer(QWidget* parent) + : QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)), + m_txtMessage(new MessageTextBrowser(this)), m_searchWidget(new SearchTextWidget(this)) { + + m_txtMessage->setAutoFillBackground(true); + m_txtMessage->setFrameShape(QFrame::StyledPanel); + m_txtMessage->setFrameShadow(QFrame::Plain); + m_txtMessage->setTabChangesFocus(true); + m_txtMessage->setOpenLinks(false); + m_txtMessage->viewport()->setAutoFillBackground(true); + m_toolBar->setOrientation(Qt::Vertical); - m_ui.m_layout->addWidget(m_toolBar, 0, 0, -1, 1); + + m_layout->setContentsMargins(3, 3, 3, 3); + m_layout->addWidget(m_txtMessage, 0, 1, 1, 1); + m_layout->addWidget(m_searchWidget, 1, 1, 1, 1); + m_layout->addWidget(m_toolBar, 0, 0, -1, 1); + createConnections(); m_actionSwitchImportance->setCheckable(true); - m_ui.m_searchWidget->hide(); + m_searchWidget->hide(); reloadFontSettings(); clear(); @@ -122,11 +139,11 @@ void MessagePreviewer::reloadFontSettings() { QFont fon; fon.fromString(settings->value(GROUP(Messages), SETTING(Messages::PreviewerFontStandard)).toString()); - m_ui.m_txtMessage->setFont(fon); + m_txtMessage->setFont(fon); } void MessagePreviewer::clear() { - m_ui.m_txtMessage->clear(); + m_txtMessage->clear(); m_pictures.clear(); hide(); } @@ -140,12 +157,12 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) { m_root = root; if (!m_root.isNull()) { - m_ui.m_searchWidget->hide(); + m_searchWidget->hide(); m_actionSwitchImportance->setChecked(m_message.m_isImportant); - m_ui.m_txtMessage->setHtml(prepareHtmlForMessage(m_message)); + m_txtMessage->setHtml(prepareHtmlForMessage(m_message)); updateButtons(); show(); - m_ui.m_txtMessage->verticalScrollBar()->triggerAction(QScrollBar::SliderToMinimum); + m_txtMessage->verticalScrollBar()->triggerAction(QScrollBar::SliderToMinimum); } } @@ -209,9 +226,9 @@ bool MessagePreviewer::eventFilter(QObject* watched, QEvent* event) { auto* key_event = static_cast(event); if (key_event->matches(QKeySequence::StandardKey::Find)) { - m_ui.m_searchWidget->clear(); - m_ui.m_searchWidget->show(); - m_ui.m_searchWidget->setFocus(); + m_searchWidget->clear(); + m_searchWidget->show(); + m_searchWidget->setFocus(); return true; } } diff --git a/src/librssguard/gui/messagepreviewer.h b/src/librssguard/gui/messagepreviewer.h index 8ec6cb296..cd3a3a989 100644 --- a/src/librssguard/gui/messagepreviewer.h +++ b/src/librssguard/gui/messagepreviewer.h @@ -5,19 +5,17 @@ #include -#include "ui_messagepreviewer.h" - #include "core/message.h" #include "services/abstract/rootitem.h" #include -namespace Ui { - class MessagePreviewer; -} - +class QGridLayout; class QToolBar; +class MessageTextBrowser; +class SearchTextWidget; + class MessagePreviewer : public QWidget { Q_OBJECT @@ -49,9 +47,10 @@ class MessagePreviewer : public QWidget { void updateButtons(); QString prepareHtmlForMessage(const Message& message); + QGridLayout* m_layout; QToolBar* m_toolBar; - - Ui::MessagePreviewer m_ui; + MessageTextBrowser* m_txtMessage; + SearchTextWidget* m_searchWidget; Message m_message; QStringList m_pictures; QPointer m_root; diff --git a/src/librssguard/gui/messagepreviewer.ui b/src/librssguard/gui/messagepreviewer.ui deleted file mode 100644 index 0de913bdc..000000000 --- a/src/librssguard/gui/messagepreviewer.ui +++ /dev/null @@ -1,65 +0,0 @@ - - - MessagePreviewer - - - - 0 - 0 - 502 - 396 - - - - - - - true - - - - 0 - - - 0 - - - - - true - - - QFrame::StyledPanel - - - QFrame::Plain - - - true - - - false - - - - - - - - - - - MessageTextBrowser - QTextBrowser -
messagetextbrowser.h
-
- - SearchTextWidget - QWidget -
searchtextwidget.h
- 1 -
-
- - -
diff --git a/src/librssguard/gui/newspaperpreviewer.cpp b/src/librssguard/gui/newspaperpreviewer.cpp index 2fb275655..a7966e36e 100644 --- a/src/librssguard/gui/newspaperpreviewer.cpp +++ b/src/librssguard/gui/newspaperpreviewer.cpp @@ -27,7 +27,6 @@ void NewspaperPreviewer::showMoreMessages() { connect(prev, &MessagePreviewer::markMessageRead, this, &NewspaperPreviewer::markMessageRead); connect(prev, &MessagePreviewer::markMessageImportant, this, &NewspaperPreviewer::markMessageImportant); - margins.setRight(0); prev->layout()->setContentsMargins(margins); prev->setFixedHeight(300); prev->loadMessage(msg, m_root); diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro index d7d403ffa..c8b28c22d 100644 --- a/src/librssguard/librssguard.pro +++ b/src/librssguard/librssguard.pro @@ -407,7 +407,7 @@ else { gui/messagetextbrowser.cpp \ gui/newspaperpreviewer.cpp - FORMS += gui/messagepreviewer.ui \ + FORMS += \ gui/newspaperpreviewer.ui } diff --git a/src/librssguard/services/abstract/label.h b/src/librssguard/services/abstract/label.h index 02ed79066..2bfd8faef 100755 --- a/src/librssguard/services/abstract/label.h +++ b/src/librssguard/services/abstract/label.h @@ -8,6 +8,8 @@ #include class Label : public RootItem { + Q_OBJECT + public: explicit Label(RootItem* parent_item = nullptr); diff --git a/src/librssguard/services/abstract/labelsnode.h b/src/librssguard/services/abstract/labelsnode.h index 7d7ff12af..db91fda09 100755 --- a/src/librssguard/services/abstract/labelsnode.h +++ b/src/librssguard/services/abstract/labelsnode.h @@ -6,6 +6,8 @@ #include "services/abstract/rootitem.h" class LabelsNode : public RootItem { + Q_OBJECT + public: explicit LabelsNode(RootItem* parent_item = nullptr); };