File indexing completed on 2024-06-16 05:01:29

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 #ifndef MSGLISTVIEW_H
0023 #define MSGLISTVIEW_H
0024 
0025 #include <QHeaderView>
0026 #include <QTreeView>
0027 #include "Imap/Model/FavoriteTagsModel.h"
0028 
0029 class QSignalMapper;
0030 
0031 namespace Imap {
0032 namespace Mailbox {
0033 class PrettyMsgListModel;
0034 }
0035 }
0036 
0037 namespace Gui {
0038 
0039 /** @short A slightly tweaked QTreeView optimized for showing a list of messages in one mailbox
0040 
0041 The optimizations (or rather modifications) include:
0042 - automatically expanding a whole subtree when root item is expanded
0043 - setting up reasonable size hints for all columns
0044 */
0045 class MsgListView : public QTreeView
0046 {
0047     Q_OBJECT
0048 public:
0049     explicit MsgListView(QWidget *parent, Imap::Mailbox::FavoriteTagsModel *m_favoriteTagsModel);
0050     virtual ~MsgListView() {}
0051     void setModel(QAbstractItemModel *model);
0052     void setAutoActivateAfterKeyNavigation(bool enabled);
0053     void updateActionsAfterRestoredState();
0054     virtual int sizeHintForColumn(int column) const;
0055     QHeaderView::ResizeMode resizeModeForColumn(const int column) const;
0056 protected:
0057     void keyPressEvent(QKeyEvent *ke);
0058     void keyReleaseEvent(QKeyEvent *ke);
0059     virtual void startDrag(Qt::DropActions supportedActions);
0060     bool event(QEvent *event);
0061     /** @short Returns a list of all selected and related (collapsed) message indexes for column 0 */
0062     QModelIndexList selectedTree() const;
0063 private slots:
0064     void slotFixSize();
0065     /** @short Expand all items below current root index */
0066     void slotExpandWholeSubtree(const QModelIndex &rootIndex);
0067     /** @short Update header actions for showing/hiding columns */
0068     void slotUpdateHeaderActions();
0069     /** @short Show/hide a corresponding column */
0070     void slotHeaderSectionVisibilityToggled(int section);
0071     /** @short Get ThreadingMsgListModel index and call the next handler */
0072     void slotMsgListModelRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
0073     /** @short Keep the cursor in place for better keyboard usability */
0074     void slotThreadingMsgListModelRowAboutToBeRemoved(const QModelIndex &index);
0075     /** @short Pick up the change of the sort critera */
0076     void slotHandleSortCriteriaChanged(int column, Qt::SortOrder order);
0077     /** @short conditionally emits activated(currentIndex()) for keyboard events */
0078     void slotCurrentActivated();
0079     void slotHandleNewColumns(int oldCount, int newCount);
0080 private:
0081     /** @short Try to move the cursor to next message */
0082     void setCurrentIndexToNextValid(const QModelIndex &current);
0083     static Imap::Mailbox::PrettyMsgListModel *findPrettyMsgListModel(QAbstractItemModel *model);
0084 
0085     QSignalMapper *headerFieldsMapper;
0086     QTimer *m_naviActivationTimer;
0087     bool m_autoActivateAfterKeyNavigation;
0088     bool m_autoResizeSections;
0089 
0090     friend class MainWindow; // needs access to slotHandleNewColumns
0091 };
0092 
0093 }
0094 
0095 #endif // MSGLISTVIEW_H