Some unifications in msg viewer.
This commit is contained in:
parent
3a0cbba696
commit
cb2922f0bc
@ -4,12 +4,17 @@
|
|||||||
|
|
||||||
#include "gui/dialogs/formmain.h"
|
#include "gui/dialogs/formmain.h"
|
||||||
#include "gui/messagebox.h"
|
#include "gui/messagebox.h"
|
||||||
|
#include "gui/searchtextwidget.h"
|
||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/databasequeries.h"
|
#include "miscellaneous/databasequeries.h"
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
|
||||||
|
#include "gui/messagetextbrowser.h"
|
||||||
|
|
||||||
|
#include <QGridLayout>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QPainter>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
@ -17,20 +22,20 @@
|
|||||||
void MessagePreviewer::createConnections() {
|
void MessagePreviewer::createConnections() {
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
|
|
||||||
connect(m_ui.m_searchWidget, &SearchTextWidget::cancelSearch, this, [this]() {
|
connect(m_searchWidget, &SearchTextWidget::cancelSearch, this, [this]() {
|
||||||
m_ui.m_txtMessage->textCursor().clearSelection();
|
m_txtMessage->textCursor().clearSelection();
|
||||||
m_ui.m_txtMessage->moveCursor(QTextCursor::MoveOperation::Left);
|
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) {
|
if (backwards) {
|
||||||
m_ui.m_txtMessage->find(text, QTextDocument::FindFlag::FindBackward);
|
m_txtMessage->find(text, QTextDocument::FindFlag::FindBackward);
|
||||||
}
|
}
|
||||||
else {
|
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) &&
|
if (url.toString().startsWith(INTERNAL_URL_PASSATTACHMENT) &&
|
||||||
m_root != nullptr &&
|
m_root != nullptr &&
|
||||||
m_root->getParentServiceRoot()->downloadAttachmentOnMyOwn(url)) {
|
m_root->getParentServiceRoot()->downloadAttachmentOnMyOwn(url)) {
|
||||||
@ -94,7 +99,7 @@ void MessagePreviewer::createConnections() {
|
|||||||
&QAction::triggered,
|
&QAction::triggered,
|
||||||
this,
|
this,
|
||||||
&MessagePreviewer::switchMessageImportance);
|
&MessagePreviewer::switchMessageImportance);
|
||||||
connect(m_ui.m_txtMessage,
|
connect(m_txtMessage,
|
||||||
QOverload<const QUrl&>::of(&QTextBrowser::highlighted),
|
QOverload<const QUrl&>::of(&QTextBrowser::highlighted),
|
||||||
[=](const QUrl& url) {
|
[=](const QUrl& url) {
|
||||||
Q_UNUSED(url)
|
Q_UNUSED(url)
|
||||||
@ -102,16 +107,28 @@ void MessagePreviewer::createConnections() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePreviewer::MessagePreviewer(QWidget* parent) : QWidget(parent) {
|
MessagePreviewer::MessagePreviewer(QWidget* parent)
|
||||||
m_ui.setupUi(this);
|
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)),
|
||||||
m_ui.m_txtMessage->viewport()->setAutoFillBackground(true);
|
m_txtMessage(new MessageTextBrowser(this)), m_searchWidget(new SearchTextWidget(this)) {
|
||||||
m_toolBar = new QToolBar(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_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();
|
createConnections();
|
||||||
|
|
||||||
m_actionSwitchImportance->setCheckable(true);
|
m_actionSwitchImportance->setCheckable(true);
|
||||||
m_ui.m_searchWidget->hide();
|
m_searchWidget->hide();
|
||||||
|
|
||||||
reloadFontSettings();
|
reloadFontSettings();
|
||||||
clear();
|
clear();
|
||||||
@ -122,11 +139,11 @@ void MessagePreviewer::reloadFontSettings() {
|
|||||||
QFont fon;
|
QFont fon;
|
||||||
|
|
||||||
fon.fromString(settings->value(GROUP(Messages), SETTING(Messages::PreviewerFontStandard)).toString());
|
fon.fromString(settings->value(GROUP(Messages), SETTING(Messages::PreviewerFontStandard)).toString());
|
||||||
m_ui.m_txtMessage->setFont(fon);
|
m_txtMessage->setFont(fon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagePreviewer::clear() {
|
void MessagePreviewer::clear() {
|
||||||
m_ui.m_txtMessage->clear();
|
m_txtMessage->clear();
|
||||||
m_pictures.clear();
|
m_pictures.clear();
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
@ -140,12 +157,12 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
|
|||||||
m_root = root;
|
m_root = root;
|
||||||
|
|
||||||
if (!m_root.isNull()) {
|
if (!m_root.isNull()) {
|
||||||
m_ui.m_searchWidget->hide();
|
m_searchWidget->hide();
|
||||||
m_actionSwitchImportance->setChecked(m_message.m_isImportant);
|
m_actionSwitchImportance->setChecked(m_message.m_isImportant);
|
||||||
m_ui.m_txtMessage->setHtml(prepareHtmlForMessage(m_message));
|
m_txtMessage->setHtml(prepareHtmlForMessage(m_message));
|
||||||
updateButtons();
|
updateButtons();
|
||||||
show();
|
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<QKeyEvent*>(event);
|
auto* key_event = static_cast<QKeyEvent*>(event);
|
||||||
|
|
||||||
if (key_event->matches(QKeySequence::StandardKey::Find)) {
|
if (key_event->matches(QKeySequence::StandardKey::Find)) {
|
||||||
m_ui.m_searchWidget->clear();
|
m_searchWidget->clear();
|
||||||
m_ui.m_searchWidget->show();
|
m_searchWidget->show();
|
||||||
m_ui.m_searchWidget->setFocus();
|
m_searchWidget->setFocus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,17 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "ui_messagepreviewer.h"
|
|
||||||
|
|
||||||
#include "core/message.h"
|
#include "core/message.h"
|
||||||
#include "services/abstract/rootitem.h"
|
#include "services/abstract/rootitem.h"
|
||||||
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
namespace Ui {
|
class QGridLayout;
|
||||||
class MessagePreviewer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
|
|
||||||
|
class MessageTextBrowser;
|
||||||
|
class SearchTextWidget;
|
||||||
|
|
||||||
class MessagePreviewer : public QWidget {
|
class MessagePreviewer : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -49,9 +47,10 @@ class MessagePreviewer : public QWidget {
|
|||||||
void updateButtons();
|
void updateButtons();
|
||||||
QString prepareHtmlForMessage(const Message& message);
|
QString prepareHtmlForMessage(const Message& message);
|
||||||
|
|
||||||
|
QGridLayout* m_layout;
|
||||||
QToolBar* m_toolBar;
|
QToolBar* m_toolBar;
|
||||||
|
MessageTextBrowser* m_txtMessage;
|
||||||
Ui::MessagePreviewer m_ui;
|
SearchTextWidget* m_searchWidget;
|
||||||
Message m_message;
|
Message m_message;
|
||||||
QStringList m_pictures;
|
QStringList m_pictures;
|
||||||
QPointer<RootItem> m_root;
|
QPointer<RootItem> m_root;
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>MessagePreviewer</class>
|
|
||||||
<widget class="QWidget" name="MessagePreviewer">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>502</width>
|
|
||||||
<height>396</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="autoFillBackground">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="m_layout">
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="MessageTextBrowser" name="m_txtMessage">
|
|
||||||
<property name="autoFillBackground">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="frameShape">
|
|
||||||
<enum>QFrame::StyledPanel</enum>
|
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Plain</enum>
|
|
||||||
</property>
|
|
||||||
<property name="tabChangesFocus">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="openLinks">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="SearchTextWidget" name="m_searchWidget" native="true"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>MessageTextBrowser</class>
|
|
||||||
<extends>QTextBrowser</extends>
|
|
||||||
<header>messagetextbrowser.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>SearchTextWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>searchtextwidget.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
@ -27,7 +27,6 @@ void NewspaperPreviewer::showMoreMessages() {
|
|||||||
connect(prev, &MessagePreviewer::markMessageRead, this, &NewspaperPreviewer::markMessageRead);
|
connect(prev, &MessagePreviewer::markMessageRead, this, &NewspaperPreviewer::markMessageRead);
|
||||||
connect(prev, &MessagePreviewer::markMessageImportant, this, &NewspaperPreviewer::markMessageImportant);
|
connect(prev, &MessagePreviewer::markMessageImportant, this, &NewspaperPreviewer::markMessageImportant);
|
||||||
|
|
||||||
margins.setRight(0);
|
|
||||||
prev->layout()->setContentsMargins(margins);
|
prev->layout()->setContentsMargins(margins);
|
||||||
prev->setFixedHeight(300);
|
prev->setFixedHeight(300);
|
||||||
prev->loadMessage(msg, m_root);
|
prev->loadMessage(msg, m_root);
|
||||||
|
@ -407,7 +407,7 @@ else {
|
|||||||
gui/messagetextbrowser.cpp \
|
gui/messagetextbrowser.cpp \
|
||||||
gui/newspaperpreviewer.cpp
|
gui/newspaperpreviewer.cpp
|
||||||
|
|
||||||
FORMS += gui/messagepreviewer.ui \
|
FORMS += \
|
||||||
gui/newspaperpreviewer.ui
|
gui/newspaperpreviewer.ui
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
class Label : public RootItem {
|
class Label : public RootItem {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Label(RootItem* parent_item = nullptr);
|
explicit Label(RootItem* parent_item = nullptr);
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "services/abstract/rootitem.h"
|
#include "services/abstract/rootitem.h"
|
||||||
|
|
||||||
class LabelsNode : public RootItem {
|
class LabelsNode : public RootItem {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LabelsNode(RootItem* parent_item = nullptr);
|
explicit LabelsNode(RootItem* parent_item = nullptr);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user