You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.3 KiB

#include "emojitabbar.h"
#include <QPainter>
#include <QStyleOptionTab>
EmojiTabBar::EmojiTabBar(QWidget *parent)
: QTabBar(parent)
{
setDrawBase(false);
setExpanding(false);
setUsesScrollButtons(false);
}
void EmojiTabBar::paintEvent(QPaintEvent *event) {
Q_UNUSED(event);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
int w = width();
int h = height();
static const QColor bgColor(255, 255, 255);
static const QColor activeTextColor(0x33, 0x90, 0xEC);
static const QColor inactiveTextColor(0x8E, 0x8E, 0x93);
static const QColor activeBarColor(0x33, 0x90, 0xEC);
static const QColor separatorColor(0xE0, 0xE0, 0xE0);
p.fillRect(rect(), bgColor);
QFont f = font();
f.setPointSize(f.pointSize() - 1);
p.setFont(f);
int current = currentIndex();
for (int i = 0; i < count(); ++i) {
QRect r = tabRect(i);
if (!r.isValid()) continue;
bool active = (i == current);
p.setPen(active ? activeTextColor : inactiveTextColor);
p.drawText(r, Qt::AlignHCenter | Qt::AlignVCenter, tabText(i));
if (active) {
int barX = r.left() + 4;
int barW = r.width() - 8;
p.fillRect(QRect(barX, h - 3, barW, 3), activeBarColor);
}
}
p.fillRect(QRect(0, h - 1, w, 1), separatorColor);
}