File indexing completed on 2024-11-24 04:53:02
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 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 "OnePanelAtTimeWidget.h" 0024 #include <QAction> 0025 #include <QMainWindow> 0026 #include <QToolBar> 0027 #include "CompleteMessageWidget.h" 0028 #include "MailBoxTreeView.h" 0029 #include "MessageListWidget.h" 0030 #include "MsgListView.h" 0031 0032 namespace Gui { 0033 0034 OnePanelAtTimeWidget::OnePanelAtTimeWidget(QMainWindow *mainWindow, MailBoxTreeView *mboxTree, MessageListWidget *msgListWidget, 0035 CompleteMessageWidget *messageWidget, QToolBar *toolbar, QAction *actionGoBack): 0036 QStackedWidget(mainWindow), m_mainWindow(mainWindow), m_mboxTree(mboxTree), m_msgListWidget(msgListWidget), 0037 m_messageWidget(messageWidget), m_toolbar(toolbar), m_actionGoBack(actionGoBack) 0038 { 0039 addWidget(m_mboxTree); 0040 addWidget(m_msgListWidget); 0041 addWidget(m_messageWidget); 0042 setCurrentWidget(m_mboxTree); 0043 0044 connect(m_msgListWidget->tree, &QAbstractItemView::clicked, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper); 0045 connect(m_msgListWidget->tree, &QAbstractItemView::activated, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper); 0046 connect(m_mboxTree, &QAbstractItemView::clicked, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper); 0047 connect(m_mboxTree, &QAbstractItemView::activated, this, &OnePanelAtTimeWidget::slotOneAtTimeGoDeeper); 0048 connect(m_actionGoBack.data(), &QAction::triggered, this, &OnePanelAtTimeWidget::slotOneAtTimeGoBack); 0049 0050 // The list view is configured to auto-emit activated(QModelIndex) after a short while when the user has navigated 0051 // to an index through keyboard. Of course, this doesn't play terribly well with this layout. 0052 m_msgListWidget->tree->setAutoActivateAfterKeyNavigation(false); 0053 0054 m_toolbar->insertAction(m_toolbar->actions().isEmpty() ? nullptr : m_toolbar->actions()[0], m_actionGoBack); 0055 addAction(m_actionGoBack); 0056 } 0057 0058 OnePanelAtTimeWidget::~OnePanelAtTimeWidget() 0059 { 0060 while (count()) { 0061 QWidget *w = widget(0); 0062 removeWidget(w); 0063 w->show(); 0064 } 0065 m_msgListWidget->tree->setAutoActivateAfterKeyNavigation(true); 0066 0067 if (m_toolbar) { 0068 m_toolbar->removeAction(m_actionGoBack); 0069 } 0070 0071 // The size of the widgets is still wrong. Let's fix this. 0072 if (m_mainWindow->isMaximized()) { 0073 m_mainWindow->showNormal(); 0074 m_mainWindow->showMaximized(); 0075 } else { 0076 m_mainWindow->resize(m_mainWindow->sizeHint()); 0077 } 0078 } 0079 0080 void OnePanelAtTimeWidget::slotOneAtTimeGoBack() 0081 { 0082 if (currentIndex() > 0) 0083 setCurrentIndex(currentIndex() - 1); 0084 0085 m_actionGoBack->setEnabled(currentIndex() > 0); 0086 } 0087 0088 void OnePanelAtTimeWidget::slotOneAtTimeGoDeeper() 0089 { 0090 QWidget *w = qobject_cast<QWidget*>(sender()); 0091 Q_ASSERT(w); 0092 0093 // Careful here: some of the events are, unfortunately, emitted twice (one for clicked(), another time for activated()) 0094 if (!w->isVisible()) 0095 return; 0096 0097 if (currentIndex() < count() - 1) 0098 setCurrentIndex(currentIndex() + 1); 0099 0100 m_actionGoBack->setEnabled(currentIndex() > 0); 0101 } 0102 0103 }