Tabs
This commit is contained in:
parent
80f7bbdb47
commit
0fee3cf434
|
@ -3,26 +3,28 @@
|
|||
#include <QtWidgets/QHBoxLayout>
|
||||
#include "qtmaterialtabs_internal.h"
|
||||
#include "lib/qtmaterialstyle.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
/*!
|
||||
* \QtMaterialTabsPrivate
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialTabsPrivate::QtMaterialTabsPrivate(QtMaterialTabs *q)
|
||||
TabsPrivate::TabsPrivate(Tabs *q)
|
||||
: q_ptr(q)
|
||||
{
|
||||
}
|
||||
|
||||
QtMaterialTabsPrivate::~QtMaterialTabsPrivate()
|
||||
TabsPrivate::~TabsPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init()
|
||||
void TabsPrivate::TabsPrivate::init()
|
||||
{
|
||||
Q_Q(QtMaterialTabs);
|
||||
Q_Q(Tabs);
|
||||
|
||||
inkBar = new QtMaterialTabsInkBar(q);
|
||||
inkBar = new TabsInkBar(q);
|
||||
tabLayout = new QHBoxLayout;
|
||||
rippleStyle = Material::CenteredRipple;
|
||||
tab = -1;
|
||||
|
@ -30,7 +32,7 @@ void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init()
|
|||
useThemeColors = true;
|
||||
|
||||
q->setLayout(tabLayout);
|
||||
q->setStyle(&QtMaterialStyle::instance());
|
||||
q->setStyle(&Style::instance());
|
||||
|
||||
tabLayout->setSpacing(0);
|
||||
tabLayout->setMargin(0);
|
||||
|
@ -40,64 +42,64 @@ void QtMaterialTabsPrivate::QtMaterialTabsPrivate::init()
|
|||
* \QtMaterialTabs
|
||||
*/
|
||||
|
||||
QtMaterialTabs::QtMaterialTabs(QWidget *parent)
|
||||
Tabs::Tabs(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
d_ptr(new QtMaterialTabsPrivate(this))
|
||||
d_ptr(new TabsPrivate(this))
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
QtMaterialTabs::~QtMaterialTabs()
|
||||
Tabs::~Tabs()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setUseThemeColors(bool value)
|
||||
void Tabs::setUseThemeColors(bool value)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->useThemeColors = value;
|
||||
}
|
||||
|
||||
bool QtMaterialTabs::useThemeColors() const
|
||||
bool Tabs::useThemeColors() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
return d->useThemeColors;
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setHaloVisible(bool value)
|
||||
void Tabs::setHaloVisible(bool value)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->showHalo = value;
|
||||
updateTabs();
|
||||
}
|
||||
|
||||
bool QtMaterialTabs::isHaloVisible() const
|
||||
bool Tabs::isHaloVisible() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
return d->showHalo;
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setRippleStyle(Material::RippleStyle style)
|
||||
void Tabs::setRippleStyle(Material::RippleStyle style)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->rippleStyle = style;
|
||||
updateTabs();
|
||||
}
|
||||
|
||||
Material::RippleStyle QtMaterialTabs::rippleStyle() const
|
||||
Material::RippleStyle Tabs::rippleStyle() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
return d->rippleStyle;
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setInkColor(const QColor &color)
|
||||
void Tabs::setInkColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->inkColor = color;
|
||||
|
||||
|
@ -106,20 +108,20 @@ void QtMaterialTabs::setInkColor(const QColor &color)
|
|||
update();
|
||||
}
|
||||
|
||||
QColor QtMaterialTabs::inkColor() const
|
||||
QColor Tabs::inkColor() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
if (d->useThemeColors || !d->inkColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("accent1");
|
||||
return Style::instance().themeColor("accent1");
|
||||
} else {
|
||||
return d->inkColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setBackgroundColor(const QColor &color)
|
||||
void Tabs::setBackgroundColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->backgroundColor = color;
|
||||
|
||||
|
@ -128,20 +130,20 @@ void QtMaterialTabs::setBackgroundColor(const QColor &color)
|
|||
update();
|
||||
}
|
||||
|
||||
QColor QtMaterialTabs::backgroundColor() const
|
||||
QColor Tabs::backgroundColor() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
if (d->useThemeColors || !d->backgroundColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("primary1");
|
||||
return Style::instance().themeColor("primary1");
|
||||
} else {
|
||||
return d->backgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setTextColor(const QColor &color)
|
||||
void Tabs::setTextColor(const QColor &color)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
d->textColor = color;
|
||||
|
||||
|
@ -150,27 +152,27 @@ void QtMaterialTabs::setTextColor(const QColor &color)
|
|||
update();
|
||||
}
|
||||
|
||||
QColor QtMaterialTabs::textColor() const
|
||||
QColor Tabs::textColor() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
if (d->useThemeColors || !d->textColor.isValid()) {
|
||||
return QtMaterialStyle::instance().themeColor("canvas");
|
||||
return Style::instance().themeColor("canvas");
|
||||
} else {
|
||||
return d->textColor;
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setCurrentTab(QtMaterialTab *tab)
|
||||
void Tabs::setCurrentTab(Tab *tab)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
setCurrentTab(d->tabLayout->indexOf(tab));
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setCurrentTab(int index)
|
||||
void Tabs::setCurrentTab(int index)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
setTabActive(d->tab, false);
|
||||
d->tab = index;
|
||||
|
@ -180,11 +182,11 @@ void QtMaterialTabs::setCurrentTab(int index)
|
|||
emit currentChanged(index);
|
||||
}
|
||||
|
||||
void QtMaterialTabs::addTab(const QString &text, const QIcon &icon)
|
||||
void Tabs::addTab(const QString &text, const QIcon &icon)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
QtMaterialTab *tab = new QtMaterialTab(this);
|
||||
Tab *tab = new Tab(this);
|
||||
tab->setText(text);
|
||||
tab->setHaloVisible(isHaloVisible());
|
||||
tab->setRippleStyle(rippleStyle());
|
||||
|
@ -204,35 +206,35 @@ void QtMaterialTabs::addTab(const QString &text, const QIcon &icon)
|
|||
}
|
||||
}
|
||||
|
||||
int QtMaterialTabs::currentIndex() const
|
||||
int Tabs::currentIndex() const
|
||||
{
|
||||
Q_D(const QtMaterialTabs);
|
||||
Q_D(const Tabs);
|
||||
|
||||
return d->tab;
|
||||
}
|
||||
|
||||
void QtMaterialTabs::setTabActive(int index, bool active)
|
||||
void Tabs::setTabActive(int index, bool active)
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
QtMaterialTab *tab;
|
||||
Tab *tab;
|
||||
|
||||
if (index > -1) {
|
||||
tab = static_cast<QtMaterialTab *>(d->tabLayout->itemAt(index)->widget());
|
||||
tab = static_cast<Tab *>(d->tabLayout->itemAt(index)->widget());
|
||||
if (tab) {
|
||||
tab->setActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialTabs::updateTabs()
|
||||
void Tabs::updateTabs()
|
||||
{
|
||||
Q_D(QtMaterialTabs);
|
||||
Q_D(Tabs);
|
||||
|
||||
QtMaterialTab *tab;
|
||||
Tab *tab;
|
||||
for (int i = 0; i < d->tabLayout->count(); ++i) {
|
||||
QLayoutItem *item = d->tabLayout->itemAt(i);
|
||||
if ((tab = static_cast<QtMaterialTab *>(item->widget()))) {
|
||||
if ((tab = static_cast<Tab *>(item->widget()))) {
|
||||
tab->setRippleStyle(d->rippleStyle);
|
||||
tab->setHaloVisible(d->showHalo);
|
||||
tab->setBackgroundColor(backgroundColor());
|
||||
|
@ -240,3 +242,4 @@ void QtMaterialTabs::updateTabs()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,19 @@
|
|||
#include <QtWidgets/QWidget>
|
||||
#include <QIcon>
|
||||
#include "lib/qtmaterialtheme.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QtMaterialTabsPrivate;
|
||||
class QtMaterialTab;
|
||||
class TabsPrivate;
|
||||
class Tab;
|
||||
|
||||
class QtMaterialTabs : public QWidget
|
||||
class Tabs : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialTabs(QWidget *parent = 0);
|
||||
~QtMaterialTabs();
|
||||
explicit Tabs(QWidget *parent = 0);
|
||||
~Tabs();
|
||||
|
||||
void setUseThemeColors(bool value);
|
||||
bool useThemeColors() const;
|
||||
|
@ -36,7 +38,7 @@ public:
|
|||
|
||||
void addTab(const QString &text, const QIcon &icon = QIcon());
|
||||
|
||||
void setCurrentTab(QtMaterialTab *tab);
|
||||
void setCurrentTab(Tab *tab);
|
||||
void setCurrentTab(int index);
|
||||
|
||||
int currentIndex() const;
|
||||
|
@ -48,11 +50,11 @@ protected:
|
|||
void setTabActive(int index, bool active = true);
|
||||
void updateTabs();
|
||||
|
||||
const QScopedPointer<QtMaterialTabsPrivate> d_ptr;
|
||||
const QScopedPointer<TabsPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialTabs)
|
||||
Q_DECLARE_PRIVATE(QtMaterialTabs)
|
||||
Q_DISABLE_COPY(Tabs)
|
||||
Q_DECLARE_PRIVATE(Tabs)
|
||||
};
|
||||
|
||||
}
|
||||
#endif // QTMATERIALTABS_H
|
||||
|
|
|
@ -6,14 +6,16 @@
|
|||
#include <QEvent>
|
||||
#include "qtmaterialtabs.h"
|
||||
#include <QDebug>
|
||||
namespace md
|
||||
{
|
||||
|
||||
/*!
|
||||
* \class QtMaterialTabsInkBar
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialTabsInkBar::QtMaterialTabsInkBar(QtMaterialTabs *parent)
|
||||
: QtMaterialOverlayWidget(parent),
|
||||
TabsInkBar::TabsInkBar(Tabs *parent)
|
||||
: OverlayWidget(parent),
|
||||
m_tabs(parent),
|
||||
m_animation(new QPropertyAnimation(parent)),
|
||||
m_tween(0)
|
||||
|
@ -31,11 +33,11 @@ QtMaterialTabsInkBar::QtMaterialTabsInkBar(QtMaterialTabs *parent)
|
|||
setAttribute(Qt::WA_NoSystemBackground);
|
||||
}
|
||||
|
||||
QtMaterialTabsInkBar::~QtMaterialTabsInkBar()
|
||||
TabsInkBar::~TabsInkBar()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialTabsInkBar::refreshGeometry()
|
||||
void TabsInkBar::refreshGeometry()
|
||||
{
|
||||
QLayoutItem *item = m_tabs->layout()->itemAt(m_tabs->currentIndex());
|
||||
|
||||
|
@ -55,7 +57,7 @@ void QtMaterialTabsInkBar::refreshGeometry()
|
|||
}
|
||||
}
|
||||
|
||||
void QtMaterialTabsInkBar::animate()
|
||||
void TabsInkBar::animate()
|
||||
{
|
||||
raise();
|
||||
|
||||
|
@ -67,7 +69,7 @@ void QtMaterialTabsInkBar::animate()
|
|||
m_animation->start();
|
||||
}
|
||||
|
||||
bool QtMaterialTabsInkBar::eventFilter(QObject *obj, QEvent *event)
|
||||
bool TabsInkBar::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
|
@ -80,10 +82,10 @@ bool QtMaterialTabsInkBar::eventFilter(QObject *obj, QEvent *event)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return QtMaterialOverlayWidget::eventFilter(obj, event);
|
||||
return OverlayWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void QtMaterialTabsInkBar::paintEvent(QPaintEvent *event)
|
||||
void TabsInkBar::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
|
@ -98,8 +100,8 @@ void QtMaterialTabsInkBar::paintEvent(QPaintEvent *event)
|
|||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialTab::QtMaterialTab(QtMaterialTabs *parent)
|
||||
: QtMaterialFlatButton(parent),
|
||||
Tab::Tab(Tabs *parent)
|
||||
: FlatButton(parent),
|
||||
m_tabs(parent),
|
||||
m_active(false)
|
||||
{
|
||||
|
@ -119,25 +121,25 @@ QtMaterialTab::QtMaterialTab(QtMaterialTabs *parent)
|
|||
connect(this, SIGNAL(clicked(bool)), this, SLOT(activateTab()));
|
||||
}
|
||||
|
||||
QtMaterialTab::~QtMaterialTab()
|
||||
Tab::~Tab()
|
||||
{
|
||||
}
|
||||
|
||||
QSize QtMaterialTab::sizeHint() const
|
||||
QSize Tab::sizeHint() const
|
||||
{
|
||||
if (icon().isNull()) {
|
||||
return QtMaterialFlatButton::sizeHint();
|
||||
return FlatButton::sizeHint();
|
||||
} else {
|
||||
return QSize(40, iconSize().height()+46);
|
||||
}
|
||||
}
|
||||
|
||||
void QtMaterialTab::activateTab()
|
||||
void Tab::activateTab()
|
||||
{
|
||||
m_tabs->setCurrentTab(this);
|
||||
}
|
||||
|
||||
void QtMaterialTab::paintForeground(QPainter *painter)
|
||||
void Tab::paintForeground(QPainter *painter)
|
||||
{
|
||||
painter->setPen(foregroundColor());
|
||||
|
||||
|
@ -176,3 +178,4 @@ void QtMaterialTab::paintForeground(QPainter *painter)
|
|||
painter->fillRect(rect(), overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,18 +4,21 @@
|
|||
#include "lib/qtmaterialoverlaywidget.h"
|
||||
#include "qtmaterialflatbutton.h"
|
||||
|
||||
class QPropertyAnimation;
|
||||
class QtMaterialTabs;
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QtMaterialTabsInkBar : public QtMaterialOverlayWidget
|
||||
class QPropertyAnimation;
|
||||
class Tabs;
|
||||
|
||||
class TabsInkBar : public OverlayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal tweenValue WRITE setTweenValue READ tweenValue)
|
||||
|
||||
public:
|
||||
QtMaterialTabsInkBar(QtMaterialTabs *parent);
|
||||
~QtMaterialTabsInkBar();
|
||||
TabsInkBar(Tabs *parent);
|
||||
~TabsInkBar();
|
||||
|
||||
inline void setTweenValue(qreal value);
|
||||
inline qreal tweenValue() const;
|
||||
|
@ -28,33 +31,33 @@ protected:
|
|||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialTabsInkBar)
|
||||
Q_DISABLE_COPY(TabsInkBar)
|
||||
|
||||
QtMaterialTabs *const m_tabs;
|
||||
Tabs *const m_tabs;
|
||||
QPropertyAnimation *const m_animation;
|
||||
QRect m_geometry;
|
||||
QRect m_previousGeometry;
|
||||
qreal m_tween;
|
||||
};
|
||||
|
||||
inline void QtMaterialTabsInkBar::setTweenValue(qreal value)
|
||||
inline void TabsInkBar::setTweenValue(qreal value)
|
||||
{
|
||||
m_tween = value;
|
||||
refreshGeometry();
|
||||
}
|
||||
|
||||
inline qreal QtMaterialTabsInkBar::tweenValue() const
|
||||
inline qreal TabsInkBar::tweenValue() const
|
||||
{
|
||||
return m_tween;
|
||||
}
|
||||
|
||||
class QtMaterialTab : public QtMaterialFlatButton
|
||||
class Tab : public FlatButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialTab(QtMaterialTabs *parent);
|
||||
~QtMaterialTab();
|
||||
explicit Tab(Tabs *parent);
|
||||
~Tab();
|
||||
|
||||
inline void setActive(bool state);
|
||||
inline bool isActive() const;
|
||||
|
@ -68,21 +71,21 @@ protected:
|
|||
void paintForeground(QPainter *painter) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialTab)
|
||||
Q_DISABLE_COPY(Tab)
|
||||
|
||||
QtMaterialTabs *const m_tabs;
|
||||
Tabs *const m_tabs;
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
inline void QtMaterialTab::setActive(bool state)
|
||||
inline void Tab::setActive(bool state)
|
||||
{
|
||||
m_active = state;
|
||||
update();
|
||||
}
|
||||
|
||||
inline bool QtMaterialTab::isActive() const
|
||||
inline bool Tab::isActive() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // QTMATERIALTABS_INTERNAL_H
|
||||
|
|
|
@ -3,24 +3,26 @@
|
|||
|
||||
#include <QtGlobal>
|
||||
#include "lib/qtmaterialtheme.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QHBoxLayout;
|
||||
class QtMaterialTabs;
|
||||
class QtMaterialTabsInkBar;
|
||||
class Tabs;
|
||||
class TabsInkBar;
|
||||
|
||||
class QtMaterialTabsPrivate
|
||||
class TabsPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QtMaterialTabsPrivate)
|
||||
Q_DECLARE_PUBLIC(QtMaterialTabs)
|
||||
Q_DISABLE_COPY(TabsPrivate)
|
||||
Q_DECLARE_PUBLIC(Tabs)
|
||||
|
||||
public:
|
||||
QtMaterialTabsPrivate(QtMaterialTabs *q);
|
||||
~QtMaterialTabsPrivate();
|
||||
TabsPrivate(Tabs *q);
|
||||
~TabsPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
QtMaterialTabs *const q_ptr;
|
||||
QtMaterialTabsInkBar *inkBar;
|
||||
Tabs *const q_ptr;
|
||||
TabsInkBar *inkBar;
|
||||
QHBoxLayout *tabLayout;
|
||||
Material::RippleStyle rippleStyle;
|
||||
QColor inkColor;
|
||||
|
@ -30,5 +32,5 @@ public:
|
|||
bool showHalo;
|
||||
bool useThemeColors;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // QTMATERIALTABS_P_H
|
||||
|
|
Loading…
Reference in New Issue