Addded find capabalities, fixes .

This commit is contained in:
Martin Rotter 2017-10-25 11:23:49 +02:00
parent 3fc911f652
commit 20c7d066a9
6 changed files with 70 additions and 16 deletions

@ -33,6 +33,10 @@ QTreeView[hideTree="true"]::branch:!has-chlidren:hasSiblings {
image: none;
}
QTextEdit {
selection-background-color: #3297FD;
}
QStatusBar::item {
border: none;
}

@ -2,6 +2,11 @@
—————
Added:
▪ Internal message web viewer (and also lighter message text viewer) now support (#63) text searching. How to use:
1. Select some messages, it now gets displayed in internal viewer.
2. Give focus to internal viewer (click somehwere in it).
3. Press standard "find" keyboard shortcut (CTRL+F on Windows).
4. Search box appears on the bottom if internal message previewer.
▪ New context menu internal web viewer action to open links in ext. browser (#80)
▪ New bindable menu action Messages -> Enable message preview, which can disable opening message preview in internal web viewer. (#141)

@ -14,7 +14,22 @@
#include <QToolTip>
void MessagePreviewer::createConnections() {
connect(m_ui->m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl& url) {
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_ui.m_searchWidget, &SearchTextWidget::searchForText, this, [this](const QString& text, bool backwards) {
if (backwards) {
m_ui.m_txtMessage->find(text, QTextDocument::FindFlag::FindBackward);
}
else {
m_ui.m_txtMessage->find(text);
}
});
connect(m_ui.m_txtMessage, &QTextBrowser::anchorClicked, [=](const QUrl& url) {
if (url.toString().startsWith(INTERNAL_URL_PASSATTACHMENT) &&
m_root != nullptr &&
m_root->getParentServiceRoot()->downloadAttachmentOnMyOwn(url)) {
@ -78,7 +93,7 @@ void MessagePreviewer::createConnections() {
&QAction::triggered,
this,
&MessagePreviewer::switchMessageImportance);
connect(m_ui->m_txtMessage,
connect(m_ui.m_txtMessage,
static_cast<void (QTextBrowser::*)(const QString&)>(&QTextBrowser::highlighted),
[=](const QString& text) {
Q_UNUSED(text)
@ -86,31 +101,31 @@ void MessagePreviewer::createConnections() {
});
}
MessagePreviewer::MessagePreviewer(QWidget* parent) : QWidget(parent),
m_ui(new Ui::MessagePreviewer), m_pictures(QStringList()) {
m_ui->setupUi(this);
m_ui->m_txtMessage->viewport()->setAutoFillBackground(true);
MessagePreviewer::MessagePreviewer(QWidget* parent) : QWidget(parent), m_pictures(QStringList()) {
m_ui.setupUi(this);
m_ui.m_txtMessage->viewport()->setAutoFillBackground(true);
m_toolBar = new QToolBar(this);
m_toolBar->setOrientation(Qt::Vertical);
m_ui->m_layout->addWidget(m_toolBar, 0, 0, -1, 1);
m_ui.m_layout->addWidget(m_toolBar, 0, 0, -1, 1);
createConnections();
m_actionSwitchImportance->setCheckable(true);
m_ui.m_searchWidget->hide();
reloadFontSettings();
clear();
}
MessagePreviewer::~MessagePreviewer() {}
void MessagePreviewer::reloadFontSettings() {
const Settings* settings = qApp->settings();
QFont fon;
fon.fromString(settings->value(GROUP(Messages), SETTING(Messages::PreviewerFontStandard)).toString());
m_ui->m_txtMessage->setFont(fon);
m_ui.m_txtMessage->setFont(fon);
}
void MessagePreviewer::clear() {
m_ui->m_txtMessage->clear();
m_ui.m_txtMessage->clear();
m_pictures.clear();
hide();
}
@ -125,10 +140,10 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
if (!m_root.isNull()) {
m_actionSwitchImportance->setChecked(m_message.m_isImportant);
m_ui->m_txtMessage->setHtml(prepareHtmlForMessage(m_message));
m_ui.m_txtMessage->setHtml(prepareHtmlForMessage(m_message));
updateButtons();
show();
m_ui->m_txtMessage->verticalScrollBar()->triggerAction(QScrollBar::SliderToMinimum);
m_ui.m_txtMessage->verticalScrollBar()->triggerAction(QScrollBar::SliderToMinimum);
}
}
@ -183,6 +198,23 @@ void MessagePreviewer::switchMessageImportance(bool checked) {
}
}
bool MessagePreviewer::eventFilter(QObject* watched, QEvent* event) {
Q_UNUSED(watched)
if (event->type() == QEvent::KeyPress) {
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
if (key_event->matches(QKeySequence::StandardKey::Find)) {
m_ui.m_searchWidget->clear();
m_ui.m_searchWidget->show();
m_ui.m_searchWidget->setFocus();
return true;
}
}
return false;
}
void MessagePreviewer::updateButtons() {
m_actionMarkRead->setEnabled(!m_message.m_isRead);
m_actionMarkUnread->setEnabled(m_message.m_isRead);

@ -22,8 +22,7 @@ class MessagePreviewer : public QWidget {
Q_OBJECT
public:
explicit MessagePreviewer(QWidget* parent = 0);
virtual ~MessagePreviewer();
explicit MessagePreviewer(QWidget* parent = nullptr);
void reloadFontSettings();
@ -38,6 +37,9 @@ class MessagePreviewer : public QWidget {
void markMessageAsReadUnread(RootItem::ReadStatus read);
void switchMessageImportance(bool checked);
protected:
bool eventFilter(QObject* watched, QEvent* event);
signals:
void markMessageRead(int id, RootItem::ReadStatus read);
void markMessageImportant(int id, RootItem::Importance important);
@ -50,7 +52,7 @@ class MessagePreviewer : public QWidget {
QToolBar* m_toolBar;
QScopedPointer<Ui::MessagePreviewer> m_ui;
Ui::MessagePreviewer m_ui;
Message m_message;
QStringList m_pictures;

@ -42,6 +42,9 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="SearchTextWidget" name="m_searchWidget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
@ -50,6 +53,12 @@
<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/>

@ -136,6 +136,8 @@ void WebBrowser::loadMessage(const Message& message, RootItem* root) {
}
bool WebBrowser::eventFilter(QObject* watched, QEvent* event) {
Q_UNUSED(watched)
if (event->type() == QEvent::KeyPress) {
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);