2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QWidget>
|
2010-03-18 10:59:06 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPropertyAnimation>
|
2018-02-20 18:11:23 +01:00
|
|
|
#include <QTimer>
|
2010-03-18 10:59:06 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QPainter;
|
|
|
|
|
class QStackedLayout;
|
|
|
|
|
class QStatusBar;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-07-21 14:55:33 +02:00
|
|
|
class FancyTab : public QObject
|
|
|
|
|
{
|
2010-02-17 18:41:41 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2018-03-21 16:01:15 +01:00
|
|
|
Q_PROPERTY(qreal fader READ fader WRITE setFader)
|
2018-02-20 18:11:23 +01:00
|
|
|
|
2010-02-17 18:41:41 +01:00
|
|
|
public:
|
2018-02-20 18:11:23 +01:00
|
|
|
FancyTab(QWidget *tabbar)
|
|
|
|
|
: m_tabbar(tabbar)
|
|
|
|
|
{
|
|
|
|
|
m_animator.setPropertyName("fader");
|
|
|
|
|
m_animator.setTargetObject(this);
|
2010-02-18 13:57:33 +01:00
|
|
|
}
|
2018-02-20 18:11:23 +01:00
|
|
|
|
|
|
|
|
qreal fader() const { return m_fader; }
|
|
|
|
|
void setFader(qreal qreal);
|
2010-02-17 18:41:41 +01:00
|
|
|
|
|
|
|
|
void fadeIn();
|
|
|
|
|
void fadeOut();
|
|
|
|
|
|
|
|
|
|
QIcon icon;
|
|
|
|
|
QString text;
|
|
|
|
|
QString toolTip;
|
2016-05-19 11:50:45 +02:00
|
|
|
bool enabled = false;
|
|
|
|
|
bool hasMenu = false;
|
2010-02-18 13:57:33 +01:00
|
|
|
|
2010-02-17 18:41:41 +01:00
|
|
|
private:
|
2018-02-20 18:11:23 +01:00
|
|
|
QPropertyAnimation m_animator;
|
|
|
|
|
QWidget *m_tabbar;
|
|
|
|
|
qreal m_fader = 0;
|
2010-02-17 18:41:41 +01:00
|
|
|
};
|
2009-07-13 16:58:13 +02:00
|
|
|
|
|
|
|
|
class FancyTabBar : public QWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-02-20 18:11:23 +01:00
|
|
|
FancyTabBar(QWidget *parent = nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
bool event(QEvent *event) override;
|
2009-07-13 16:58:13 +02:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2008-12-02 12:01:29 +01:00
|
|
|
void paintTab(QPainter *painter, int tabIndex) const;
|
2018-02-20 18:11:23 +01:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
|
void enterEvent(QEvent *event) override;
|
|
|
|
|
void leaveEvent(QEvent *event) override;
|
2010-02-17 18:41:41 +01:00
|
|
|
bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
|
2009-07-13 16:58:13 +02:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
QSize sizeHint() const override;
|
|
|
|
|
QSize minimumSizeHint() const override;
|
2009-07-13 16:58:13 +02:00
|
|
|
|
2010-02-16 15:36:56 +01:00
|
|
|
void setTabEnabled(int index, bool enable);
|
|
|
|
|
bool isTabEnabled(int index) const;
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void insertTab(int index, const QIcon &icon, const QString &label, bool hasMenu)
|
|
|
|
|
{
|
|
|
|
|
auto tab = new FancyTab(this);
|
2010-02-17 18:41:41 +01:00
|
|
|
tab->icon = icon;
|
|
|
|
|
tab->text = label;
|
2016-05-19 11:50:45 +02:00
|
|
|
tab->hasMenu = hasMenu;
|
2009-07-13 16:58:13 +02:00
|
|
|
m_tabs.insert(index, tab);
|
2016-08-30 14:54:35 +02:00
|
|
|
if (m_currentIndex >= index)
|
|
|
|
|
++m_currentIndex;
|
2013-06-12 17:06:09 +02:00
|
|
|
updateGeometry();
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
2010-02-17 17:20:31 +01:00
|
|
|
void setEnabled(int index, bool enabled);
|
2018-02-20 18:11:23 +01:00
|
|
|
void removeTab(int index)
|
|
|
|
|
{
|
2010-02-17 18:41:41 +01:00
|
|
|
FancyTab *tab = m_tabs.takeAt(index);
|
|
|
|
|
delete tab;
|
2013-06-12 17:06:09 +02:00
|
|
|
updateGeometry();
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
void setCurrentIndex(int index);
|
|
|
|
|
int currentIndex() const { return m_currentIndex; }
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void setTabToolTip(int index, const QString &toolTip) { m_tabs[index]->toolTip = toolTip; }
|
2010-02-17 18:41:41 +01:00
|
|
|
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
|
2009-07-13 16:58:13 +02:00
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
void setIconsOnly(bool iconOnly);
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
int count() const { return m_tabs.count(); }
|
2009-07-13 16:58:13 +02:00
|
|
|
QRect tabRect(int index) const;
|
|
|
|
|
|
|
|
|
|
signals:
|
2016-05-19 11:50:45 +02:00
|
|
|
void currentChanged(int index);
|
|
|
|
|
void menuTriggered(int index, QMouseEvent *event);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QRect m_hoverRect;
|
2018-02-20 18:11:23 +01:00
|
|
|
int m_hoverIndex = -1;
|
|
|
|
|
int m_currentIndex = -1;
|
2018-04-26 16:09:16 +02:00
|
|
|
bool m_iconsOnly = false;
|
2018-02-20 18:11:23 +01:00
|
|
|
QList<FancyTab *> m_tabs;
|
2009-07-13 16:58:13 +02:00
|
|
|
QSize tabSizeHint(bool minimum = false) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FancyTabWidget : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-02-20 18:11:23 +01:00
|
|
|
FancyTabWidget(QWidget *parent = nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-05-19 11:50:45 +02:00
|
|
|
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu);
|
2008-12-02 12:01:29 +01:00
|
|
|
void removeTab(int index);
|
|
|
|
|
void setBackgroundBrush(const QBrush &brush);
|
|
|
|
|
void addCornerWidget(QWidget *widget);
|
|
|
|
|
void insertCornerWidget(int pos, QWidget *widget);
|
|
|
|
|
int cornerWidgetCount() const;
|
|
|
|
|
void setTabToolTip(int index, const QString &toolTip);
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int currentIndex() const;
|
|
|
|
|
QStatusBar *statusBar() const;
|
|
|
|
|
|
2010-02-16 15:36:56 +01:00
|
|
|
void setTabEnabled(int index, bool enable);
|
|
|
|
|
bool isTabEnabled(int index) const;
|
|
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
void setIconsOnly(bool iconsOnly);
|
|
|
|
|
|
2013-04-11 12:22:10 +02:00
|
|
|
bool isSelectionWidgetVisible() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
|
|
|
|
void currentAboutToShow(int index);
|
|
|
|
|
void currentChanged(int index);
|
2016-05-19 11:50:45 +02:00
|
|
|
void menuTriggered(int index, QMouseEvent *event);
|
2016-03-16 12:28:31 +01:00
|
|
|
void topAreaClicked(Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void setCurrentIndex(int index);
|
2013-04-11 12:22:10 +02:00
|
|
|
void setSelectionWidgetVisible(bool visible);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
private:
|
2008-12-02 12:01:29 +01:00
|
|
|
void showWidget(int index);
|
|
|
|
|
|
|
|
|
|
FancyTabBar *m_tabBar;
|
|
|
|
|
QWidget *m_cornerWidgetContainer;
|
|
|
|
|
QStackedLayout *m_modesStack;
|
|
|
|
|
QWidget *m_selectionWidget;
|
|
|
|
|
QStatusBar *m_statusBar;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|