File indexing completed on 2024-06-09 05:18:07
0001 /* 0002 0003 SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "foldertreewidget.h" 0011 #include "mailcommon/mailutil.h" 0012 #include "mailcommon_export.h" 0013 0014 #include <Akonadi/Collection> 0015 #include <Akonadi/EntityTreeView> 0016 0017 class QMouseEvent; 0018 0019 namespace Akonadi 0020 { 0021 class CollectionStatisticsDelegate; 0022 } 0023 0024 namespace MailCommon 0025 { 0026 /** 0027 * This is an enhanced EntityTreeView specially suited for the folders in KMail's 0028 * main folder widget. 0029 */ 0030 class MAILCOMMON_EXPORT FolderTreeView : public Akonadi::EntityTreeView 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 explicit FolderTreeView(QWidget *parent = nullptr, bool showUnreadCount = true); 0036 0037 explicit FolderTreeView(KXMLGUIClient *xmlGuiClient, QWidget *parent = nullptr, bool showUnreadCount = true); 0038 0039 ~FolderTreeView() override; 0040 0041 void selectNextUnreadFolder(bool confirm = false); 0042 void selectPrevUnreadFolder(bool confirm = false); 0043 0044 void showStatisticAnimation(bool anim); 0045 0046 void disableContextMenuAndExtraColumn(); 0047 0048 void setTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy); 0049 0050 void restoreHeaderState(const QByteArray &data); 0051 0052 [[nodiscard]] Akonadi::Collection currentFolder() const; 0053 0054 void disableSaveConfig(); 0055 void readConfig(); 0056 0057 void updatePalette(); 0058 0059 void keyboardSearch(const QString &) override; 0060 0061 void setEnableDragDrop(bool enabled); 0062 0063 protected: 0064 enum Move { 0065 Next = 0, 0066 Previous = 1, 0067 }; 0068 0069 void init(bool showUnreadCount); 0070 void selectModelIndex(const QModelIndex &); 0071 void setCurrentModelIndex(const QModelIndex &); 0072 QModelIndex selectNextFolder(const QModelIndex ¤t); 0073 bool isUnreadFolder(const QModelIndex ¤t, QModelIndex &nextIndex, FolderTreeView::Move move, bool confirm); 0074 void writeConfig(); 0075 0076 void setSortingPolicy(FolderTreeWidget::SortingPolicy policy, bool writeInConfig = false); 0077 0078 void mousePressEvent(QMouseEvent *e) override; 0079 0080 public Q_SLOTS: 0081 void slotFocusNextFolder(); 0082 void slotFocusPrevFolder(); 0083 void slotSelectFocusFolder(); 0084 void slotFocusFirstFolder(); 0085 void slotFocusLastFolder(); 0086 0087 protected Q_SLOTS: 0088 void slotHeaderContextMenuRequested(const QPoint &); 0089 void slotHeaderContextMenuChangeIconSize(bool); 0090 void slotHeaderContextMenuChangeHeader(bool); 0091 void slotHeaderContextMenuChangeToolTipDisplayPolicy(bool); 0092 void slotHeaderContextMenuChangeSortingPolicy(bool); 0093 0094 Q_SIGNALS: 0095 void changeTooltipsPolicy(FolderTreeWidget::ToolTipDisplayPolicy); 0096 void manualSortingChanged(bool actif); 0097 void newTabRequested(bool); 0098 0099 private: 0100 enum SearchDirection { ForwardSearch, BackwardSearch }; 0101 0102 MAILCOMMON_NO_EXPORT QModelIndex indexAbove(const QModelIndex ¤t) const; 0103 MAILCOMMON_NO_EXPORT QModelIndex indexBelow(const QModelIndex ¤t) const; 0104 MAILCOMMON_NO_EXPORT QModelIndex lastChild(const QModelIndex ¤t) const; 0105 MAILCOMMON_NO_EXPORT QModelIndex nextUnreadCollection(const QModelIndex ¤t, SearchDirection direction) const; 0106 0107 MAILCOMMON_NO_EXPORT bool ignoreUnreadFolder(const Akonadi::Collection &, bool) const; 0108 MAILCOMMON_NO_EXPORT bool allowedToEnterFolder(const Akonadi::Collection &, bool) const; 0109 MAILCOMMON_NO_EXPORT bool trySelectNextUnreadFolder(const QModelIndex &, SearchDirection, bool); 0110 0111 FolderTreeWidget::ToolTipDisplayPolicy mToolTipDisplayPolicy; 0112 FolderTreeWidget::SortingPolicy mSortingPolicy; 0113 Akonadi::CollectionStatisticsDelegate *mCollectionStatisticsDelegate = nullptr; 0114 bool mbDisableContextMenuAndExtraColumn = false; 0115 bool mbDisableSaveConfig = false; 0116 }; 0117 }