1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
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 "OnePanelAtTimeWidget.h"
25 #include <QMainWindow>
27 #include "CompleteMessageWidget.h"
28 #include "MailBoxTreeView.h"
29 #include "MessageListWidget.h"
30 #include "MsgListView.h"
34 OnePanelAtTimeWidget::OnePanelAtTimeWidget(QMainWindow
*mainWindow
, MailBoxTreeView
*mboxTree
, MessageListWidget
*msgListWidget
,
35 CompleteMessageWidget
*messageWidget
, QToolBar
*toolbar
, QAction
*actionGoBack
):
36 QStackedWidget(mainWindow
), m_mainWindow(mainWindow
), m_mboxTree(mboxTree
), m_msgListWidget(msgListWidget
),
37 m_messageWidget(messageWidget
), m_toolbar(toolbar
), m_actionGoBack(actionGoBack
)
39 addWidget(m_mboxTree
);
40 addWidget(m_msgListWidget
);
41 addWidget(m_messageWidget
);
42 setCurrentWidget(m_mboxTree
);
44 connect(m_msgListWidget
->tree
, &QAbstractItemView::clicked
, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper
);
45 connect(m_msgListWidget
->tree
, &QAbstractItemView::activated
, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper
);
46 connect(m_mboxTree
, &QAbstractItemView::clicked
, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper
);
47 connect(m_mboxTree
, &QAbstractItemView::activated
, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper
);
48 connect(m_actionGoBack
.data(), &QAction::triggered
, this, &OnePanelAtTimeWidget::slotOneAtTimeGoBack
);
50 // The list view is configured to auto-emit activated(QModelIndex) after a short while when the user has navigated
51 // to an index through keyboard. Of course, this doesn't play terribly well with this layout.
52 m_msgListWidget
->tree
->setAutoActivateAfterKeyNavigation(false);
54 m_toolbar
->insertAction(m_toolbar
->actions().isEmpty() ? nullptr : m_toolbar
->actions()[0], m_actionGoBack
);
55 addAction(m_actionGoBack
);
58 OnePanelAtTimeWidget::~OnePanelAtTimeWidget()
61 QWidget
*w
= widget(0);
65 m_msgListWidget
->tree
->setAutoActivateAfterKeyNavigation(true);
68 m_toolbar
->removeAction(m_actionGoBack
);
71 // The size of the widgets is still wrong. Let's fix this.
72 if (m_mainWindow
->isMaximized()) {
73 m_mainWindow
->showNormal();
74 m_mainWindow
->showMaximized();
76 m_mainWindow
->resize(m_mainWindow
->sizeHint());
80 void OnePanelAtTimeWidget::slotOneAtTimeGoBack()
82 if (currentIndex() > 0)
83 setCurrentIndex(currentIndex() - 1);
85 m_actionGoBack
->setEnabled(currentIndex() > 0);
88 void OnePanelAtTimeWidget::slotOneAtTimeGoDeeper()
90 QWidget
*w
= qobject_cast
<QWidget
*>(sender());
93 // Careful here: some of the events are, unfortunately, emitted twice (one for clicked(), another time for activated())
97 if (currentIndex() < count() - 1)
98 setCurrentIndex(currentIndex() + 1);
100 m_actionGoBack
->setEnabled(currentIndex() > 0);