File indexing completed on 2024-05-19 04:59:21

0001 /* ============================================================
0002 * VerticalTabs plugin for Falkon
0003 * Copyright (C) 2018 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 #pragma once
0019 
0020 #include <QAbstractButton>
0021 #include <QStyledItemDelegate>
0022 
0023 class QPushButton;
0024 
0025 class TabTreeView;
0026 class LoadingAnimator;
0027 
0028 class TabTreeCloseButton : public QAbstractButton
0029 {
0030     Q_OBJECT
0031     Q_PROPERTY(int showOnNormal READ showOnNormal WRITE setShowOnNormal)
0032     Q_PROPERTY(int showOnHovered READ showOnHovered WRITE setShowOnHovered)
0033     Q_PROPERTY(int showOnSelected READ showOnSelected WRITE setShowOnSelected)
0034 
0035 public:
0036     explicit TabTreeCloseButton(QWidget *parent = nullptr);
0037 
0038     int showOnNormal() const;
0039     void setShowOnNormal(int show);
0040 
0041     int showOnHovered() const;
0042     void setShowOnHovered(int show);
0043 
0044     int showOnSelected() const;
0045     void setShowOnSelected(int show);
0046 
0047     bool isVisible(bool hovered, bool selected) const;
0048 
0049 private:
0050     void paintEvent(QPaintEvent *event) override;
0051 
0052     int m_showOnNormal = 0;
0053     int m_showOnHovered = 1;
0054     int m_showOnSelected = 1;
0055 };
0056 
0057 class TabTreeDelegate : public QStyledItemDelegate
0058 {
0059 public:
0060     explicit TabTreeDelegate(TabTreeView *view);
0061 
0062     QRect expandButtonRect(const QModelIndex &index) const;
0063     QRect audioButtonRect(const QModelIndex &index) const;
0064     QRect closeButtonRect(const QModelIndex &index) const;
0065 
0066     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0067     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0068 
0069 private:
0070     TabTreeView *m_view;
0071     LoadingAnimator *m_loadingAnimator;
0072     TabTreeCloseButton *m_closeButton;
0073     int m_padding;
0074     int m_indentation;
0075 };