2013-11-26 14:14:36 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2016-04-24 10:17:13 +02:00
|
|
|
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
2018-01-01 14:50:36 +01:00
|
|
|
* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
|
2013-11-26 14:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#ifndef COMBOTABBAR_H
|
|
|
|
#define COMBOTABBAR_H
|
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2017-01-21 12:23:24 +01:00
|
|
|
#include "wheelhelper.h"
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
#include <QTabBar>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QAbstractButton>
|
|
|
|
#include <QEasingCurve>
|
2013-12-24 17:21:10 +01:00
|
|
|
#include <QStyleOption>
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
class QScrollArea;
|
|
|
|
class QPropertyAnimation;
|
|
|
|
class QHBoxLayout;
|
|
|
|
|
|
|
|
class TabBarScrollWidget;
|
|
|
|
class TabBarHelper;
|
|
|
|
class ToolButton;
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT ComboTabBar : public QWidget
|
2013-11-26 14:14:36 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
|
|
|
|
Q_PROPERTY(int count READ count)
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum SizeType {
|
|
|
|
PinnedTabWidth,
|
|
|
|
ActiveTabMinimumWidth,
|
|
|
|
NormalTabMinimumWidth,
|
|
|
|
NormalTabMaximumWidth,
|
|
|
|
OverflowedTabWidth,
|
|
|
|
ExtraReservedWidth
|
|
|
|
};
|
|
|
|
|
2017-12-31 23:11:25 +01:00
|
|
|
enum DropIndicatorPosition {
|
|
|
|
BeforeTab,
|
|
|
|
AfterTab
|
|
|
|
};
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
explicit ComboTabBar(QWidget* parent = 0);
|
|
|
|
|
|
|
|
int addTab(const QString &text);
|
|
|
|
int addTab(const QIcon &icon, const QString &text);
|
|
|
|
|
|
|
|
int insertTab(int index, const QString &text);
|
|
|
|
int insertTab(int index, const QIcon &icon, const QString &text, bool pinned = false);
|
|
|
|
|
|
|
|
void removeTab(int index);
|
|
|
|
void moveTab(int from, int to);
|
|
|
|
|
|
|
|
bool isTabEnabled(int index) const;
|
|
|
|
void setTabEnabled(int index, bool enabled);
|
|
|
|
|
|
|
|
QColor tabTextColor(int index) const;
|
|
|
|
void setTabTextColor(int index, const QColor &color);
|
|
|
|
|
|
|
|
QRect tabRect(int index) const;
|
2018-01-08 13:22:20 +01:00
|
|
|
QRect draggedTabRect() const;
|
2018-01-01 14:50:36 +01:00
|
|
|
QPixmap tabPixmap(int index) const;
|
2014-04-19 18:47:44 +02:00
|
|
|
|
|
|
|
// Returns tab index at pos, or -1
|
2013-11-26 14:14:36 +01:00
|
|
|
int tabAt(const QPoint &pos) const;
|
2014-04-19 18:47:44 +02:00
|
|
|
|
|
|
|
// Returns true if there is an empty area at pos
|
|
|
|
// (returns false if there are buttons or other widgets on the pos)
|
2014-03-15 23:46:10 +01:00
|
|
|
bool emptyArea(const QPoint &pos) const;
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
int mainTabBarCurrentIndex() const;
|
|
|
|
int currentIndex() const;
|
|
|
|
int count() const;
|
|
|
|
|
|
|
|
void setDrawBase(bool drawTheBase);
|
|
|
|
bool drawBase() const;
|
|
|
|
|
|
|
|
Qt::TextElideMode elideMode() const;
|
|
|
|
void setElideMode(Qt::TextElideMode elide);
|
|
|
|
|
|
|
|
QString tabText(int index) const;
|
|
|
|
void setTabText(int index, const QString &text);
|
|
|
|
|
|
|
|
void setTabToolTip(int index, const QString &tip);
|
|
|
|
QString tabToolTip(int index) const;
|
|
|
|
|
|
|
|
bool tabsClosable() const;
|
|
|
|
void setTabsClosable(bool closable);
|
|
|
|
|
|
|
|
void setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget);
|
|
|
|
QWidget* tabButton(int index, QTabBar::ButtonPosition position) const;
|
|
|
|
|
|
|
|
QTabBar::SelectionBehavior selectionBehaviorOnRemove() const;
|
|
|
|
void setSelectionBehaviorOnRemove(QTabBar::SelectionBehavior behavior);
|
|
|
|
|
|
|
|
bool expanding() const;
|
|
|
|
void setExpanding(bool enabled);
|
|
|
|
|
|
|
|
bool isMovable() const;
|
|
|
|
void setMovable(bool movable);
|
|
|
|
|
|
|
|
bool documentMode() const;
|
|
|
|
void setDocumentMode(bool set);
|
|
|
|
|
|
|
|
int pinnedTabsCount() const;
|
|
|
|
int normalTabsCount() const;
|
|
|
|
bool isPinned(int index) const;
|
|
|
|
|
2017-01-27 16:51:14 +01:00
|
|
|
void setFocusPolicy(Qt::FocusPolicy policy);
|
2013-11-26 14:14:36 +01:00
|
|
|
void setObjectName(const QString &name);
|
|
|
|
void setMouseTracking(bool enable);
|
|
|
|
|
|
|
|
void insertCloseButton(int index);
|
|
|
|
void setCloseButtonsToolTip(const QString &tip);
|
|
|
|
|
2016-01-25 13:33:05 +01:00
|
|
|
QTabBar::ButtonPosition iconButtonPosition() const;
|
|
|
|
QTabBar::ButtonPosition closeButtonPosition() const;
|
|
|
|
|
|
|
|
QSize iconButtonSize() const;
|
|
|
|
QSize closeButtonSize() const;
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
bool validIndex(int index) const;
|
|
|
|
void setCurrentNextEnabledIndex(int offset);
|
|
|
|
|
|
|
|
bool usesScrollButtons() const;
|
|
|
|
void setUsesScrollButtons(bool useButtons);
|
|
|
|
|
2017-12-31 23:11:25 +01:00
|
|
|
void showDropIndicator(int index, DropIndicatorPosition position);
|
|
|
|
void clearDropIndicator();
|
|
|
|
|
2014-02-13 15:42:25 +01:00
|
|
|
bool isDragInProgress() const;
|
2015-10-11 10:51:16 +02:00
|
|
|
bool isScrollInProgress() const;
|
2014-03-18 17:35:44 +01:00
|
|
|
bool isMainBarOverflowed() const;
|
|
|
|
|
2014-03-31 09:50:54 +02:00
|
|
|
// Width of all widgets in the corner
|
|
|
|
int cornerWidth(Qt::Corner corner) const;
|
|
|
|
// Add widget to the left/right corner
|
2014-03-18 17:35:44 +01:00
|
|
|
void addCornerWidget(QWidget* widget, Qt::Corner corner);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
2017-01-28 10:31:45 +01:00
|
|
|
// Duration of tab slide animation when releasing dragged tab
|
|
|
|
static int slideAnimationDuration();
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
public Q_SLOTS:
|
2013-11-26 14:14:36 +01:00
|
|
|
void setUpLayout();
|
|
|
|
void ensureVisible(int index = -1, int xmargin = -1);
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
Q_SIGNALS:
|
2014-03-13 12:07:05 +01:00
|
|
|
void overFlowChanged(bool overFlow);
|
|
|
|
void currentChanged(int index);
|
|
|
|
void tabCloseRequested(int index);
|
|
|
|
void tabMoved(int from, int to);
|
|
|
|
void scrollBarValueChanged(int value);
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
private Q_SLOTS:
|
2013-12-24 12:28:51 +01:00
|
|
|
void setMinimumWidths();
|
2013-11-26 14:14:36 +01:00
|
|
|
void slotCurrentChanged(int index);
|
|
|
|
void slotTabCloseRequested(int index);
|
|
|
|
void slotTabMoved(int from, int to);
|
|
|
|
void closeTabFromButton();
|
2014-02-11 23:28:41 +01:00
|
|
|
void updateTabBars();
|
2014-03-30 16:40:36 +02:00
|
|
|
void emitOverFlowChanged();
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int mainTabBarWidth() const;
|
|
|
|
int pinTabBarWidth() const;
|
2014-03-13 12:07:05 +01:00
|
|
|
|
2015-10-11 10:51:16 +02:00
|
|
|
bool event(QEvent *event);
|
2013-11-26 14:14:36 +01:00
|
|
|
void wheelEvent(QWheelEvent* event);
|
|
|
|
bool eventFilter(QObject* obj, QEvent* ev);
|
2014-03-31 09:45:41 +02:00
|
|
|
void paintEvent(QPaintEvent* ev);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
virtual int comboTabBarPixelMetric(SizeType sizeType) const;
|
|
|
|
virtual QSize tabSizeHint(int index, bool fast = false) const;
|
|
|
|
virtual void tabInserted(int index);
|
|
|
|
virtual void tabRemoved(int index);
|
|
|
|
|
|
|
|
private:
|
2014-03-13 12:07:05 +01:00
|
|
|
TabBarHelper* mainTabBar() const;
|
2013-11-26 14:14:36 +01:00
|
|
|
TabBarHelper* localTabBar(int index = -1) const;
|
|
|
|
|
2014-03-13 12:07:05 +01:00
|
|
|
int toLocalIndex(int globalIndex) const;
|
2018-01-08 13:22:20 +01:00
|
|
|
QRect mapFromLocalTabRect(const QRect &rect, QWidget *tabBar) const;
|
2013-11-26 14:14:36 +01:00
|
|
|
void updatePinnedTabBarVisibility();
|
|
|
|
|
|
|
|
QHBoxLayout* m_mainLayout;
|
2014-03-18 17:35:44 +01:00
|
|
|
QHBoxLayout* m_leftLayout;
|
|
|
|
QHBoxLayout* m_rightLayout;
|
|
|
|
QWidget* m_leftContainer;
|
|
|
|
QWidget* m_rightContainer;
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
TabBarHelper* m_mainTabBar;
|
|
|
|
TabBarHelper* m_pinnedTabBar;
|
|
|
|
|
|
|
|
TabBarScrollWidget* m_mainTabBarWidget;
|
|
|
|
TabBarScrollWidget* m_pinnedTabBarWidget;
|
|
|
|
|
|
|
|
QString m_closeButtonsToolTip;
|
|
|
|
bool m_mainBarOverFlowed;
|
2014-03-30 16:40:36 +02:00
|
|
|
bool m_lastAppliedOverflow;
|
2013-11-26 14:14:36 +01:00
|
|
|
bool m_usesScrollButtons;
|
2014-04-01 18:47:19 +02:00
|
|
|
bool m_blockCurrentChangedSignal;
|
2014-03-31 09:50:54 +02:00
|
|
|
|
2017-01-21 12:23:24 +01:00
|
|
|
WheelHelper m_wheelHelper;
|
|
|
|
|
2014-03-31 09:50:54 +02:00
|
|
|
friend class TabBarHelper;
|
2014-04-01 18:47:19 +02:00
|
|
|
friend class TabStackedWidget;
|
2013-11-26 14:14:36 +01:00
|
|
|
};
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT TabBarHelper : public QTabBar
|
2013-11-26 14:14:36 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-01-08 10:14:15 +01:00
|
|
|
Q_PROPERTY(int tabPadding READ tabPadding WRITE setTabPadding)
|
2018-01-08 16:49:48 +01:00
|
|
|
Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor)
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
public:
|
2014-05-02 22:16:48 +02:00
|
|
|
explicit TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
2018-01-08 10:14:15 +01:00
|
|
|
int tabPadding() const;
|
|
|
|
void setTabPadding(int padding);
|
|
|
|
|
2018-01-08 16:49:48 +01:00
|
|
|
QColor baseColor() const;
|
|
|
|
void setBaseColor(const QColor &color);
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
void setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget);
|
|
|
|
|
|
|
|
QSize tabSizeHint(int index) const;
|
|
|
|
QSize baseClassTabSizeHint(int index) const;
|
|
|
|
|
2018-01-08 13:22:20 +01:00
|
|
|
QRect draggedTabRect() const;
|
2018-01-01 14:50:36 +01:00
|
|
|
QPixmap tabPixmap(int index) const;
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
bool isActiveTabBar();
|
|
|
|
void setActiveTabBar(bool activate);
|
|
|
|
|
2014-02-10 19:49:09 +01:00
|
|
|
void removeTab(int index);
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
void setScrollArea(QScrollArea* scrollArea);
|
|
|
|
void useFastTabSizeHint(bool enabled);
|
2014-02-13 15:42:25 +01:00
|
|
|
|
2017-12-31 23:11:25 +01:00
|
|
|
void showDropIndicator(int index, ComboTabBar::DropIndicatorPosition position);
|
|
|
|
void clearDropIndicator();
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
bool isDisplayedOnViewPort(int globalLeft, int globalRight);
|
2014-02-13 15:42:25 +01:00
|
|
|
bool isDragInProgress() const;
|
2013-11-26 14:14:36 +01:00
|
|
|
|
2016-04-24 10:17:13 +02:00
|
|
|
static void initStyleBaseOption(QStyleOptionTabBarBase* optTabBase, QTabBar* tabbar, QSize size);
|
2014-03-31 09:45:41 +02:00
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
public Q_SLOTS:
|
2013-11-26 14:14:36 +01:00
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool event(QEvent* ev);
|
|
|
|
void paintEvent(QPaintEvent* event);
|
|
|
|
void mousePressEvent(QMouseEvent* event);
|
2018-01-08 15:36:55 +01:00
|
|
|
void mouseMoveEvent(QMouseEvent *event);
|
2013-11-26 14:14:36 +01:00
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
|
|
|
|
2018-01-08 13:22:20 +01:00
|
|
|
int dragOffset(QStyleOptionTab *option, int tabIndex) const;
|
2014-05-02 22:15:36 +02:00
|
|
|
void initStyleOption(QStyleOptionTab* option, int tabIndex) const;
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
ComboTabBar* m_comboTabBar;
|
|
|
|
QScrollArea* m_scrollArea;
|
|
|
|
|
2018-01-08 10:14:15 +01:00
|
|
|
int m_tabPadding = -1;
|
2018-01-08 16:49:48 +01:00
|
|
|
QColor m_baseColor;
|
2013-11-26 14:14:36 +01:00
|
|
|
int m_pressedIndex;
|
2013-11-27 22:27:24 +01:00
|
|
|
bool m_dragInProgress;
|
2018-01-08 15:36:55 +01:00
|
|
|
QPoint m_dragStartPosition;
|
2018-01-09 15:31:35 +01:00
|
|
|
class QMovableTabWidget *m_movingTab = nullptr;
|
2013-11-26 14:14:36 +01:00
|
|
|
bool m_activeTabBar;
|
2014-05-02 22:16:48 +02:00
|
|
|
bool m_isPinnedTabBar;
|
2013-11-26 14:14:36 +01:00
|
|
|
bool m_useFastTabSizeHint;
|
2017-12-31 23:11:25 +01:00
|
|
|
int m_dropIndicatorIndex = -1;
|
|
|
|
ComboTabBar::DropIndicatorPosition m_dropIndicatorPosition;
|
2013-11-26 14:14:36 +01:00
|
|
|
};
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT TabScrollBar : public QScrollBar
|
2013-11-26 14:14:36 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TabScrollBar(QWidget* parent = 0);
|
|
|
|
~TabScrollBar();
|
|
|
|
|
2015-10-11 10:51:16 +02:00
|
|
|
bool isScrolling() const;
|
|
|
|
|
2014-02-12 16:20:13 +01:00
|
|
|
void animateToValue(int to, QEasingCurve::Type type = QEasingCurve::OutQuad);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QPropertyAnimation* m_animation;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT TabBarScrollWidget : public QWidget
|
2013-11-26 14:14:36 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TabBarScrollWidget(QTabBar* tabBar, QWidget* parent = 0);
|
|
|
|
|
|
|
|
QTabBar* tabBar();
|
|
|
|
QScrollArea* scrollArea();
|
|
|
|
TabScrollBar* scrollBar();
|
|
|
|
|
|
|
|
void scrollByWheel(QWheelEvent* event);
|
|
|
|
|
2014-03-31 09:45:41 +02:00
|
|
|
int scrollButtonsWidth() const;
|
2013-11-26 14:14:36 +01:00
|
|
|
bool usesScrollButtons() const;
|
|
|
|
void setUsesScrollButtons(bool useButtons);
|
|
|
|
|
2014-01-22 16:57:04 +01:00
|
|
|
bool isOverflowed() const;
|
2013-12-24 00:01:18 +01:00
|
|
|
int tabAt(const QPoint &pos) const;
|
2013-12-23 21:24:41 +01:00
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
public Q_SLOTS:
|
2013-11-26 14:14:36 +01:00
|
|
|
void ensureVisible(int index = -1, int xmargin = 132);
|
2014-02-12 16:20:13 +01:00
|
|
|
void scrollToLeft(int n = 5, QEasingCurve::Type type = QEasingCurve::OutQuad);
|
|
|
|
void scrollToRight(int n = 5, QEasingCurve::Type type = QEasingCurve::OutQuad);
|
2013-11-26 14:14:36 +01:00
|
|
|
void scrollToLeftEdge();
|
|
|
|
void scrollToRightEdge();
|
|
|
|
void setUpLayout();
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
private Q_SLOTS:
|
2013-11-26 14:14:36 +01:00
|
|
|
void overFlowChanged(bool overflowed);
|
|
|
|
void scrollStart();
|
2014-03-30 16:40:36 +02:00
|
|
|
void updateScrollButtonsState();
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
2014-03-30 16:40:36 +02:00
|
|
|
void resizeEvent(QResizeEvent* event);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
QTabBar* m_tabBar;
|
|
|
|
QScrollArea* m_scrollArea;
|
|
|
|
TabScrollBar* m_scrollBar;
|
|
|
|
ToolButton* m_rightScrollButton;
|
|
|
|
ToolButton* m_leftScrollButton;
|
|
|
|
bool m_usesScrollButtons;
|
2014-02-12 16:20:13 +01:00
|
|
|
int m_totalDeltas;
|
2013-11-26 14:14:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class for close button on tabs
|
|
|
|
// * taken from qtabbar.cpp
|
|
|
|
class CloseButton : public QAbstractButton
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-02-16 11:46:46 +01:00
|
|
|
CloseButton(QWidget *parent = nullptr);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
2018-02-16 11:46:46 +01:00
|
|
|
QSize sizeHint() const override;
|
|
|
|
|
|
|
|
void enterEvent(QEvent *event) override;
|
|
|
|
void leaveEvent(QEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2013-11-26 14:14:36 +01:00
|
|
|
};
|
|
|
|
#endif // COMBOTABBAR_H
|