Exemple #1
0
void TabBarPrivate::layoutButtons()
{
    int bw = tabbar->height();
    int w = tabbar->width();
    offset = bw * 4;

    if (tabbar->isLeftToRight()) {
        scrollFirstButton->setGeometry(0, 0, bw, bw);
        scrollFirstButton->setIcon(QIcon(QPixmap(arrow_leftmost_xpm)));
        scrollBackButton->setGeometry(bw, 0, bw, bw);
        scrollBackButton->setIcon(QIcon(QPixmap(arrow_left_xpm)));
        scrollForwardButton->setGeometry(bw*2, 0, bw, bw);
        scrollForwardButton->setIcon(QIcon(QPixmap(arrow_right_xpm)));
        scrollLastButton->setGeometry(bw*3, 0, bw, bw);
        scrollLastButton->setIcon(QIcon(QPixmap(arrow_rightmost_xpm)));
    } else {
        scrollFirstButton->setGeometry(w - bw, 0, bw, bw);
        scrollFirstButton->setIcon(QIcon(QPixmap(arrow_rightmost_xpm)));
        scrollBackButton->setGeometry(w - 2*bw, 0, bw, bw);
        scrollBackButton->setIcon(QIcon(QPixmap(arrow_right_xpm)));
        scrollForwardButton->setGeometry(w - 3*bw, 0, bw, bw);
        scrollForwardButton->setIcon(QIcon(QPixmap(arrow_left_xpm)));
        scrollLastButton->setGeometry(w - 4*bw, 0, bw, bw);
        scrollLastButton->setIcon(QIcon(QPixmap(arrow_leftmost_xpm)));
    }
}
Exemple #2
0
void TabBarPrivate::drawTab(QPainter& painter, QRect& rect, const QString& text, bool active)
{
    QPolygon polygon;

    if (tabbar->isLeftToRight())
        polygon << QPoint(rect.x(), rect.y())
        << QPoint(rect.x(), rect.bottom() - 3)
        << QPoint(rect.x() + 2, rect.bottom())
        << QPoint(rect.right() - 4, rect.bottom())
        << QPoint(rect.right() - 2, rect.bottom() - 2)
        << QPoint(rect.right() + 5, rect.top());
    else
        polygon << QPoint(rect.right(), rect.top())
        << QPoint(rect.right(), rect.bottom() - 3)
        << QPoint(rect.right() - 2, rect.bottom())
        << QPoint(rect.x() + 4, rect.bottom())
        << QPoint(rect.x() + 2, rect.bottom() - 2)
        << QPoint(rect.x() - 5, rect.top());

    painter.save();

    // fill it first
    QBrush bg = tabbar->palette().background();
    if (active)
        bg = tabbar->palette().base();
    painter.setBrush(bg);
    painter.setPen(QPen(Qt::NoPen));
    painter.drawPolygon(polygon);

    // draw the lines
    painter.setPen(tabbar->palette().color(QPalette::Dark));
    painter.setRenderHint(QPainter::Antialiasing);
    if (!active) {
        const bool reverseLayout = tabbar->isRightToLeft();
        painter.drawLine(rect.x() - (reverseLayout ? 5 : 0), rect.y(),
                         rect.right() + (reverseLayout ? 0 : 5), rect.top());
    }

    painter.drawPolyline(polygon);

    painter.setPen(tabbar->palette().color(QPalette::ButtonText));
    QFont f = font(active);
    painter.setFont(f);
    QFontMetrics fm = painter.fontMetrics();
    int tx =  rect.x() + (rect.width() - fm.width(text)) / 2;
    int ty =  rect.y() + (rect.height() - fm.height()) / 2 + fm.ascent();
    painter.drawText(tx, ty, text);

    painter.restore();
}
Exemple #3
0
void TabBarPrivate::layoutTabs()
{
    tabRects.clear();

    QFont f = font(true);
    QFontMetrics fm(f, tabbar);
    if (tabbar->isLeftToRight()) {
        // left to right
        int x = 0;
        for (int c = 0; c < tabs.count(); c++) {
            QRect rect;
            if (c >= firstTab - 1) {
                QString text = tabs[ c ];
                int tw = fm.width(text) + 4;
                rect = QRect(x, 0, tw + 20, tabbar->height());
                x = x + tw + 20;
            }
            tabRects.append(rect);
        }

        lastTab = tabRects.count();
        for (int i = 0; i < tabRects.count(); i++)
            if (tabRects[i].right() - 10 + offset > tabbar->width()) {
                lastTab = i;
                break;
            }
    } else {
        // right to left
        int x = tabbar->width() - offset;
        for (int c = 0; c < tabs.count(); c++) {
            QRect rect;
            if (c >= firstTab - 1) {
                QString text = tabs[ c ];
                int tw = fm.width(text) + 4;
                rect = QRect(x - tw - 20, 0, tw + 20, tabbar->height());
                x = x - tw - 20;
            }
            tabRects.append(rect);
        }

        lastTab = tabRects.count();
        for (int i = tabRects.count() - 1; i > 0; i--)
            if (tabRects[i].left() > 0) {
                lastTab = i + 1;
                break;
            }
    }
}