File indexing completed on 2024-05-12 04:58:07

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #ifndef HISTORYTREEVIEW_H
0019 #define HISTORYTREEVIEW_H
0020 
0021 #include <QTreeView>
0022 
0023 class History;
0024 class HistoryFilterModel;
0025 class HeaderView;
0026 
0027 class HistoryTreeView : public QTreeView
0028 {
0029     Q_OBJECT
0030 public:
0031     enum ViewType {
0032         HistoryManagerViewType,
0033         HistorySidebarViewType
0034     };
0035 
0036     explicit HistoryTreeView(QWidget* parent = nullptr);
0037 
0038     ViewType viewType() const;
0039     void setViewType(ViewType type);
0040 
0041     // Returns empty url if more than one (or zero) urls are selected
0042     QUrl selectedUrl() const;
0043 
0044     HeaderView* header() const;
0045 
0046 Q_SIGNALS:
0047     // Open url in current tab
0048     void urlActivated(const QUrl &url);
0049     // Open url in new tab
0050     void urlCtrlActivated(const QUrl &url);
0051     // Open url in new window
0052     void urlShiftActivated(const QUrl &url);
0053     // Context menu signal with point mapped to global
0054     void contextMenuRequested(const QPoint &point);
0055 
0056 public Q_SLOTS:
0057     void search(const QString &string);
0058     void removeSelectedItems();
0059 
0060 protected:
0061     void contextMenuEvent(QContextMenuEvent* event) override;
0062     void mouseMoveEvent(QMouseEvent* event) override;
0063     void mousePressEvent(QMouseEvent* event) override;
0064     void mouseReleaseEvent(QMouseEvent* event) override;
0065     void mouseDoubleClickEvent(QMouseEvent* event) override;
0066     void keyPressEvent(QKeyEvent* event) override;
0067 
0068     void drawRow(QPainter* painter, const QStyleOptionViewItem &options, const QModelIndex &index) const override;
0069 
0070 private:
0071     History* m_history;
0072     HistoryFilterModel* m_filter;
0073     HeaderView* m_header;
0074     ViewType m_type;
0075 };
0076 
0077 #endif // HISTORYTREEVIEW_H