Files
qt-creator/src/plugins/coreplugin/fancytabwidget.h

182 lines
5.0 KiB
C
Raw Normal View History

/****************************************************************************
2008-12-02 12:01:29 +01:00
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator.
2008-12-02 12:01:29 +01: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
** 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.
**
** 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
**
****************************************************************************/
2008-12-02 14:09:21 +01:00
#pragma once
2008-12-02 12:01:29 +01:00
#include <QIcon>
#include <QWidget>
#include <QTimer>
#include <QPropertyAnimation>
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
Q_PROPERTY(float fader READ fader WRITE setFader)
public:
FancyTab(QWidget *tabbar) : enabled(false), tabbar(tabbar), m_fader(0) {
animator.setPropertyName("fader");
animator.setTargetObject(this);
}
2010-02-17 18:41:41 +01:00
float fader() { return m_fader; }
2010-02-19 16:16:31 +01:00
void setFader(float value);
2010-02-17 18:41:41 +01:00
void fadeIn();
void fadeOut();
QIcon icon;
QString text;
QString toolTip;
bool enabled;
2010-02-17 18:41:41 +01:00
private:
QPropertyAnimation animator;
2010-02-17 18:41:41 +01:00
QWidget *tabbar;
float m_fader;
};
class FancyTabBar : public QWidget
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
FancyTabBar(QWidget *parent = 0);
~FancyTabBar();
bool event(QEvent *event);
2008-12-02 12:01:29 +01:00
void paintEvent(QPaintEvent *event);
void paintTab(QPainter *painter, int tabIndex) const;
void mousePressEvent(QMouseEvent *);
2008-12-02 12:01:29 +01:00
void mouseMoveEvent(QMouseEvent *);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
2010-02-17 18:41:41 +01:00
bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); }
QSize sizeHint() const;
QSize minimumSizeHint() const;
void setTabEnabled(int index, bool enable);
bool isTabEnabled(int index) const;
void insertTab(int index, const QIcon &icon, const QString &label) {
2010-02-17 18:41:41 +01:00
FancyTab *tab = new FancyTab(this);
tab->icon = icon;
tab->text = label;
m_tabs.insert(index, tab);
updateGeometry();
}
void setEnabled(int index, bool enabled);
void removeTab(int index) {
2010-02-17 18:41:41 +01:00
FancyTab *tab = m_tabs.takeAt(index);
delete tab;
updateGeometry();
}
void setCurrentIndex(int index);
int currentIndex() const { return m_currentIndex; }
2010-02-17 18:41:41 +01:00
void setTabToolTip(int index, QString toolTip) { m_tabs[index]->toolTip = toolTip; }
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
2010-07-21 14:55:33 +02:00
QIcon tabIcon(int index) const { return m_tabs.at(index)->icon; }
2010-02-17 18:41:41 +01:00
QString tabText(int index) const { return m_tabs.at(index)->text; }
int count() const {return m_tabs.count(); }
QRect tabRect(int index) const;
signals:
void currentChanged(int);
2008-12-02 12:01:29 +01:00
public slots:
void emitCurrentIndex();
2008-12-02 12:01:29 +01:00
private:
static const int m_rounding;
static const int m_textPadding;
QRect m_hoverRect;
int m_hoverIndex;
int m_currentIndex;
2010-02-17 18:41:41 +01:00
QList<FancyTab*> m_tabs;
QTimer m_triggerTimer;
QSize tabSizeHint(bool minimum = false) const;
2008-12-02 12:01:29 +01:00
};
class FancyTabWidget : public QWidget
{
Q_OBJECT
public:
FancyTabWidget(QWidget *parent = 0);
void insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label);
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);
void paintEvent(QPaintEvent *event);
int currentIndex() const;
QStatusBar *statusBar() const;
void setTabEnabled(int index, bool enable);
bool isTabEnabled(int index) const;
bool isSelectionWidgetVisible() const;
2008-12-02 12:01:29 +01:00
signals:
void currentAboutToShow(int index);
void currentChanged(int index);
void topAreaClicked(Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
2008-12-02 12:01:29 +01:00
public slots:
void setCurrentIndex(int index);
void setSelectionWidgetVisible(bool visible);
2008-12-02 12:01:29 +01: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