1 /* Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "CompleteMessageWidget.h"
25 #include <QPropertyAnimation>
26 #include <QScrollArea>
28 #include <QVBoxLayout>
29 #include "Gui/EmbeddedWebView.h"
30 #include "Gui/FindBar.h"
31 #include "Gui/MessageView.h"
32 #include "UiUtils/IconLoader.h"
36 CompleteMessageWidget::CompleteMessageWidget(QWidget
*parent
, QSettings
*settings
, Plugins::PluginManager
*pluginManager
)
40 setWindowIcon(UiUtils::loadIcon(QStringLiteral("mail-mark-read")));
41 messageView
= new MessageView(this, settings
, pluginManager
);
42 area
= new QScrollArea();
43 area
->setWidget(messageView
);
44 area
->setWidgetResizable(true);
45 QVBoxLayout
*layout
= new QVBoxLayout(this);
46 layout
->setContentsMargins(0, 0, 0, 0);
47 layout
->addWidget(area
);
48 animator
= new QPropertyAnimation(area
->verticalScrollBar(), "value", this);
49 animator
->setDuration(250); // the default, maybe play with values
50 animator
->setEasingCurve(QEasingCurve::InOutCubic
); // InOutQuad?
52 layout
->addWidget(m_findBar
);
53 connect(messageView
, &MessageView::searchRequestedBy
,
54 this, [this](EmbeddedWebView
*w
) {
57 // because the FindBarMixin is not a QObject, we have to use lambda above, otherwise a cast
58 // from FindBarMixin * to QObject * fails
61 void CompleteMessageWidget::keyPressEvent(QKeyEvent
*ke
)
63 if (ke
->key() == Qt::Key_Home
) {
64 animator
->setEndValue(area
->verticalScrollBar()->minimum());
66 } else if (ke
->key() == Qt::Key_End
) {
67 animator
->setEndValue(area
->verticalScrollBar()->maximum());
69 } else if (ke
->key() == Qt::Key_Space
|| ke
->key() == Qt::Key_Backspace
) {
70 const int delta
= area
->verticalScrollBar()->pageStep() * (ke
->key() == Qt::Key_Backspace
? -1 : 1);
71 const int start
= animator
->state() == QAbstractAnimation::Running
? animator
->endValue().toInt() : area
->verticalScrollBar()->value();
72 if (animator
->state() == QAbstractAnimation::Running
) {
75 animator
->setEndValue(qMin(qMax(start
+ delta
, area
->verticalScrollBar()->minimum()), area
->verticalScrollBar()->maximum()));
77 } else { // noop, but hey.
78 QWidget::keyPressEvent(ke
);