void SeafileTabBar::paintEvent(QPaintEvent *event)
{
    QStylePainter p(this);
    QPainter painter;
    painter.begin(this);

    for (int index = 0, total = count(); index < total; index++) {
        const QRect rect = tabRect(index);

        // QStyleOptionTabV3 tab;
        // initStyleOption(&tab, index);

        // Draw the tab background
        painter.fillRect(rect, QColor(kTabsBackgroundColor));

        // Draw the tab icon in the center
        QPoint top_left;
        top_left.setX(rect.topLeft().x() + ((rect.width() - kTabIconSize) / 2));
        top_left.setY(rect.topLeft().y() + ((rect.height() - kTabIconSize) / 2));

        QIcon icon(currentIndex() == index ? highlighted_icons_[index]
                                           : icons_[index]);
        QRect icon_rect(top_left, QSize(kTabIconSize, kTabIconSize));
        // get the device pixel radio from current painter device
        int scale_factor = 1;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
        scale_factor = painter.device()->devicePixelRatio();
#endif // QT5
        QPixmap icon_pixmap(icon.pixmap(QSize(kTabIconSize, kTabIconSize) * scale_factor));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
        icon_pixmap.setDevicePixelRatio(scale_factor);
#endif // QT5
        painter.drawPixmap(icon_rect, icon_pixmap);

        int indicator_width = count() * rect.width() / 8;

        // Draw the selected tab indicator
        if (currentIndex() == index) {
            top_left.setX(rect.bottomLeft().x() + (rect.width() / 2) - (indicator_width / 2));
            top_left.setY(rect.bottomLeft().y() - kSelectedTabBorderBottomWidth + 1);
            QRect border_bottom_rect(top_left, QSize(indicator_width, kSelectedTabBorderBottomWidth));
            painter.fillRect(border_bottom_rect, QColor(kSelectedTabBorderBottomColor));
        }
    }
}
Beispiel #2
0
QPushButton *Dashboard::createButton(const QString &name){
    QPushButton *button = new QPushButton;
    button->setEnabled(false);

    QPixmap icon_pixmap(QString("image/system/button/%1.png").arg(name));
    QPixmap icon_pixmap_disabled(QString("image/system/button/%1-disabled.png").arg(name));

    QIcon icon(icon_pixmap);
    icon.addPixmap(icon_pixmap_disabled, QIcon::Disabled);

    //button->setIcon(icon);
    //button->setIconSize(icon_pixmap.size());
    button->setFixedSize(icon_pixmap.size());
    button->setObjectName(name);
    button->setProperty("game_control",true);

    button->setAttribute(Qt::WA_TranslucentBackground);

    return button;
}