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

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2013-2014  S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
0004 * Copyright (C) 2018       David Rosca <nowrep@gmail.com>
0005 *
0006 * This program is free software: you can redistribute it and/or modify
0007 * it under the terms of the GNU General Public License as published by
0008 * the Free Software Foundation, either version 3 of the License, or
0009 * (at your option) any later version.
0010 *
0011 * This program is distributed in the hope that it will be useful,
0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 * GNU General Public License for more details.
0015 *
0016 * You should have received a copy of the GNU General Public License
0017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 * ============================================================ */
0019 #ifndef TABSTACKEDWIDGET_H
0020 #define TABSTACKEDWIDGET_H
0021 
0022 #include "qzcommon.h"
0023 
0024 #include <QWidget>
0025 
0026 class ComboTabBar;
0027 
0028 class QStackedWidget;
0029 class QVBoxLayout;
0030 
0031 
0032 class FALKON_EXPORT TabStackedWidget : public QWidget
0033 {
0034     Q_OBJECT
0035 public:
0036     explicit TabStackedWidget(QWidget* parent = nullptr);
0037     ~TabStackedWidget() override;
0038 
0039     ComboTabBar* tabBar();
0040     void setTabBar(ComboTabBar* tb);
0041 
0042     bool documentMode() const;
0043     void setDocumentMode(bool enabled);
0044 
0045     int addTab(QWidget* widget, const QString &label, bool pinned = false);
0046     int insertTab(int index, QWidget* widget, const QString &label, bool pinned = false);
0047 
0048     QString tabText(int index) const;
0049     void setTabText(int index, const QString &label);
0050 
0051     QString tabToolTip(int index) const;
0052     void setTabToolTip(int index, const QString &tip);
0053 
0054     int pinUnPinTab(int index, const QString &title = QString());
0055 
0056     void removeTab(int index);
0057     void moveTab(int from, int to);
0058 
0059     int currentIndex() const;
0060     QWidget* currentWidget() const;
0061     QWidget* widget(int index) const;
0062     int indexOf(QWidget* widget) const;
0063     int count() const;
0064 
0065 Q_SIGNALS:
0066     void currentChanged(int index);
0067     void tabCloseRequested(int index);
0068     void pinStateChanged(int index, bool pinned);
0069 
0070 public Q_SLOTS:
0071     void setCurrentIndex(int index);
0072     void setCurrentWidget(QWidget* widget);
0073     void setUpLayout();
0074 
0075 private Q_SLOTS:
0076     void showTab(int index);
0077     void tabWasMoved(int from, int to);
0078     void tabWasRemoved(int index);
0079 
0080 protected:
0081     bool eventFilter(QObject* obj, QEvent* event) override;
0082     void keyPressEvent(QKeyEvent* event) override;
0083 
0084 private:
0085     bool validIndex(int index) const;
0086     void selectTabOnRemove();
0087 
0088     QStackedWidget* m_stack;
0089     ComboTabBar* m_tabBar;
0090     QVBoxLayout* m_mainLayout;
0091     bool m_dirtyTabBar;
0092 
0093     int m_currentIndex;
0094     int m_previousIndex;
0095 };
0096 
0097 #endif // TABSTACKEDWIDGET_H