File indexing completed on 2024-11-24 04:52:58
0001 /* Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "CompleteMessageWidget.h" 0024 #include <QKeyEvent> 0025 #include <QPropertyAnimation> 0026 #include <QScrollArea> 0027 #include <QScrollBar> 0028 #include <QVBoxLayout> 0029 #include "Common/SettingsNames.h" 0030 #include "Gui/EmbeddedWebView.h" 0031 #include "Gui/FindBar.h" 0032 #include "Gui/MessageView.h" 0033 #include "UiUtils/IconLoader.h" 0034 0035 namespace Gui { 0036 0037 CompleteMessageWidget::CompleteMessageWidget(QWidget *parent, QSettings *settings, Plugins::PluginManager *pluginManager, 0038 Imap::Mailbox::FavoriteTagsModel *m_favoriteTags) 0039 : QWidget(parent) 0040 , FindBarMixin(this), settings(settings) 0041 { 0042 setWindowIcon(UiUtils::loadIcon(QStringLiteral("mail-mark-read"))); 0043 messageView = new MessageView(this, settings, pluginManager, m_favoriteTags); 0044 area = new QScrollArea(); 0045 area->setWidget(messageView); 0046 area->setWidgetResizable(true); 0047 QVBoxLayout *layout = new QVBoxLayout(this); 0048 layout->setContentsMargins(0, 0, 0, 0); 0049 layout->addWidget(area); 0050 animator = new QPropertyAnimation(area->verticalScrollBar(), "value", this); 0051 animator->setDuration(250); // the default, maybe play with values 0052 animator->setEasingCurve(QEasingCurve::InOutCubic); // InOutQuad? 0053 0054 layout->addWidget(m_findBar); 0055 connect(messageView, &MessageView::searchRequestedBy, 0056 this, [this](EmbeddedWebView *w) { 0057 searchRequestedBy(w); 0058 }); 0059 // because the FindBarMixin is not a QObject, we have to use lambda above, otherwise a cast 0060 // from FindBarMixin * to QObject * fails 0061 0062 auto geometry = settings->value(Common::SettingsNames::completeMessageWidgetGeometry); 0063 if (geometry.isValid()) { 0064 restoreGeometry(geometry.toByteArray()); 0065 } else { 0066 resize(800, 600); 0067 } 0068 } 0069 0070 void CompleteMessageWidget::keyPressEvent(QKeyEvent *ke) 0071 { 0072 if (ke->key() == Qt::Key_Home) { 0073 animator->setEndValue(area->verticalScrollBar()->minimum()); 0074 animator->start(); 0075 } else if (ke->key() == Qt::Key_End) { 0076 animator->setEndValue(area->verticalScrollBar()->maximum()); 0077 animator->start(); 0078 } else if (ke->key() == Qt::Key_Space || ke->key() == Qt::Key_Backspace) { 0079 const int delta = area->verticalScrollBar()->pageStep() * (ke->key() == Qt::Key_Backspace ? -1 : 1); 0080 const int start = animator->state() == QAbstractAnimation::Running ? animator->endValue().toInt() : area->verticalScrollBar()->value(); 0081 if (animator->state() == QAbstractAnimation::Running) { 0082 animator->stop(); 0083 } 0084 animator->setEndValue(qMin(qMax(start + delta, area->verticalScrollBar()->minimum()), area->verticalScrollBar()->maximum())); 0085 animator->start(); 0086 } else { // noop, but hey. 0087 QWidget::keyPressEvent(ke); 0088 } 0089 } 0090 0091 void CompleteMessageWidget::closeEvent(QCloseEvent *event) 0092 { 0093 settings->setValue(Common::SettingsNames::completeMessageWidgetGeometry, saveGeometry()); 0094 } 0095 0096 }