shade inactive tabs
This commit is contained in:
parent
2a7f9cdd56
commit
9ddb4d6fb0
|
@ -135,7 +135,7 @@ void Tabs::addTab(const QString &text, const QIcon &icon)
|
|||
|
||||
Tab *tab = createTab(text);
|
||||
tab->setIcon(icon);
|
||||
tab->setIconSize(QSize(24, 24));
|
||||
tab->setIconSize(QSize(22, 22));
|
||||
}
|
||||
|
||||
void Tabs::setRippleStyle(Material::RippleStyle style)
|
||||
|
@ -188,8 +188,14 @@ void Tabs::switchTab()
|
|||
{
|
||||
Q_D(Tabs);
|
||||
|
||||
Tab *oldTab = static_cast<Tab *>(d->tabLayout->itemAt(d->tab)->widget());
|
||||
if (oldTab) {
|
||||
oldTab->setActive(false);
|
||||
}
|
||||
|
||||
Tab *tab = static_cast<Tab *>(sender());
|
||||
if (tab) {
|
||||
tab->setActive(true);
|
||||
d->tab = d->tabLayout->indexOf(tab);
|
||||
d->inkBar->animate();
|
||||
emit currentChanged(d->tab);
|
||||
|
@ -212,6 +218,7 @@ Tab *Tabs::createTab(const QString &text)
|
|||
if (-1 == d->tab) {
|
||||
d->tab = 0;
|
||||
d->inkBar->refreshGeometry();
|
||||
tab->setActive(true);
|
||||
}
|
||||
|
||||
connect(tab, SIGNAL(clicked()), this, SLOT(switchTab()));
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <QEvent>
|
||||
#include <QDebug>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include "tabs.h"
|
||||
|
||||
TabsInkBar::TabsInkBar(Tabs *parent)
|
||||
|
@ -110,7 +109,7 @@ QSize Tab::sizeHint() const
|
|||
if (icon().isNull()) {
|
||||
return FlatButton::sizeHint();
|
||||
} else {
|
||||
return QSize(40, iconSize().height() + 48);
|
||||
return QSize(40, iconSize().height() + 46);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,28 +133,41 @@ void Tab::paintEvent(QPaintEvent *event)
|
|||
QStylePainter style(this);
|
||||
|
||||
if (!icon().isNull()) {
|
||||
style.translate(0, 10);
|
||||
style.translate(0, 12);
|
||||
}
|
||||
|
||||
QStyleOptionButton option;
|
||||
initStyleOption(&option);
|
||||
option.features |= QStyleOptionButton::Flat;
|
||||
option.iconSize = QSize(-1, -1); // Let's not draw the icon right now
|
||||
option.iconSize = QSize(-1, -1); // Prevent icon from being drawn twice
|
||||
|
||||
style.drawControl(QStyle::CE_PushButtonLabel, option);
|
||||
|
||||
if (!icon().isNull()) {
|
||||
const QSize &size = iconSize();
|
||||
QRect iconPos(QPoint((width()-size.width())/2, 0), size);
|
||||
icon().paint(&painter, iconPos, Qt::AlignCenter, QIcon::Normal);
|
||||
QRect iconRect(QPoint((width()-size.width())/2, 0), size);
|
||||
icon().paint(&painter, iconRect, Qt::AlignCenter, QIcon::Normal);
|
||||
}
|
||||
|
||||
if (!_active) {
|
||||
QColor overlayColor = backgroundColor();
|
||||
overlayColor.setAlphaF(0.36);
|
||||
|
||||
QBrush overlay;
|
||||
overlay.setStyle(Qt::SolidPattern);
|
||||
overlay.setColor(overlayColor);
|
||||
painter.fillRect(rect(), overlay);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LAYOUT
|
||||
QPainter debug(this);
|
||||
QPen pen;
|
||||
pen.setColor(Qt::red);
|
||||
pen.setWidth(5);
|
||||
painter.setPen(pen);
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(rect());
|
||||
pen.setWidth(2);
|
||||
debug.setPen(pen);
|
||||
debug.setBrush(Qt::NoBrush);
|
||||
debug.drawRect(rect());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Tab::init()
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
explicit Tab(QString text, QWidget *parent = 0);
|
||||
~Tab();
|
||||
|
||||
inline void setActive(bool state) { _active = state; update(); }
|
||||
inline bool isActive() const { return _active; }
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
@ -54,6 +57,8 @@ private:
|
|||
Q_DISABLE_COPY(Tab)
|
||||
|
||||
void init();
|
||||
|
||||
bool _active;
|
||||
};
|
||||
|
||||
#endif // TABS_INTERNAL_H
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
QT += core gui qml svg
|
||||
QT += core gui qml
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
|
|
Loading…
Reference in New Issue