2013-11-26 14:14:36 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
2014-04-02 20:41:49 +02:00
|
|
|
* Copyright (C) 2014 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"
|
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;
|
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_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
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
void setMaxVisiblePinnedTab(int max);
|
|
|
|
|
|
|
|
void setObjectName(const QString &name);
|
|
|
|
void setMouseTracking(bool enable);
|
|
|
|
|
|
|
|
void insertCloseButton(int index);
|
|
|
|
void setCloseButtonsToolTip(const QString &tip);
|
|
|
|
|
|
|
|
QTabBar::ButtonPosition iconButtonPosition();
|
|
|
|
QTabBar::ButtonPosition closeButtonPosition();
|
|
|
|
|
|
|
|
bool validIndex(int index) const;
|
|
|
|
void setCurrentNextEnabledIndex(int offset);
|
|
|
|
|
|
|
|
bool usesScrollButtons() const;
|
|
|
|
void setUsesScrollButtons(bool useButtons);
|
|
|
|
|
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
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setUpLayout();
|
|
|
|
void ensureVisible(int index = -1, int xmargin = -1);
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
2014-03-13 12:07:05 +01:00
|
|
|
signals:
|
|
|
|
void overFlowChanged(bool overFlow);
|
|
|
|
void currentChanged(int index);
|
|
|
|
void tabCloseRequested(int index);
|
|
|
|
void tabMoved(int from, int to);
|
|
|
|
void scrollBarValueChanged(int value);
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
private 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;
|
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
|
|
|
|
|
|
|
friend class TabBarHelper;
|
2014-04-01 18:47:19 +02:00
|
|
|
friend class TabStackedWidget;
|
2013-11-26 14:14:36 +01:00
|
|
|
};
|
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_EXPORT TabBarHelper : public QTabBar
|
2013-11-26 14:14:36 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-05-02 22:16:48 +02:00
|
|
|
explicit TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar);
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2014-03-31 09:45:41 +02:00
|
|
|
static void initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size);
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
public slots:
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void resetDragState();
|
2014-12-25 12:46:31 +01:00
|
|
|
void tabWasMoved(int from, int to);
|
2013-11-26 14:14:36 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool event(QEvent* ev);
|
|
|
|
void paintEvent(QPaintEvent* event);
|
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
|
|
|
|
2014-05-02 22:15:36 +02:00
|
|
|
void initStyleOption(QStyleOptionTab* option, int tabIndex) const;
|
|
|
|
|
2014-12-25 12:46:31 +01:00
|
|
|
void tabInserted(int index);
|
|
|
|
void tabRemoved(int index);
|
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
ComboTabBar* m_comboTabBar;
|
|
|
|
QScrollArea* m_scrollArea;
|
|
|
|
|
|
|
|
int m_pressedIndex;
|
|
|
|
int m_pressedGlobalX;
|
2013-11-27 22:27:24 +01:00
|
|
|
bool m_dragInProgress;
|
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;
|
|
|
|
};
|
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_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
|
|
|
|
2013-11-26 14:14:36 +01:00
|
|
|
public slots:
|
|
|
|
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();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
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:
|
|
|
|
CloseButton(QWidget* parent = 0);
|
|
|
|
|
|
|
|
QSize sizeHint() const;
|
|
|
|
QSize minimumSizeHint() const;
|
|
|
|
|
|
|
|
void enterEvent(QEvent* event);
|
|
|
|
void leaveEvent(QEvent* event);
|
|
|
|
void paintEvent(QPaintEvent* event);
|
|
|
|
};
|
|
|
|
#endif // COMBOTABBAR_H
|