Esempio n. 1
0
const KPixmap &SUSE2Handler::buttonPixmap(ButtonIcon type, int size, ButtonStatus status)
{
    if (m_pixmaps[status][type]) {
        if (status != Shadow && m_pixmaps[status][type]->size() == QSize(size, size))
            return *m_pixmaps[status][type];
        else if (status == Shadow && m_pixmaps[status][type]->size() == QSize(size+4, size+4))
            return *m_pixmaps[status][type];
    }

    // no matching pixmap found, create a new one...

    delete m_pixmaps[status][type];
    m_pixmaps[status][type] = 0;

    QColor aDecoFgDark = alphaBlendColors(getColor(TitleGradientTo, true), Qt::black, 50);
    QColor aDecoFgLight = alphaBlendColors(getColor(TitleGradientTo, true), Qt::white, 50);
    QColor iDecoFgDark = alphaBlendColors(getColor(TitleGradientTo, false), Qt::black, 50);
    QColor iDecoFgLight = alphaBlendColors(getColor(TitleGradientTo, false), Qt::white, 50);

    if (m_customIconColors && !m_useTitleProps) {
        aDecoFgDark = m_aFgColor;
        aDecoFgLight = m_aBgColor;
        iDecoFgDark = m_iFgColor;
        iDecoFgLight = m_iBgColor;
    }

    KPixmap icon = IconEngine::icon(type, size);
    QImage img = icon.convertToImage();

    KPixmap *pixmap;
    QImage tmpImage;
    ShadowEngine se;
    QPainter painter;
    KPixmap tmpShadow;
    switch (status) {
        case ActiveUp:
            if (m_useTitleProps)
                tmpImage = recolorImage(&img, getColor(TitleFont, true));
            else
                tmpImage = recolorImage(&img, aDecoFgDark);

            pixmap = new KPixmap(tmpImage);
            break;
        case ActiveDown:
            if (m_useTitleProps)
                tmpImage = recolorImage(&img, getColor(TitleFont, true));
            else
                tmpImage = recolorImage(&img, aDecoFgLight);

            pixmap = new KPixmap(tmpImage);
            break;
        case InactiveUp:
            if (m_useTitleProps)
                tmpImage = recolorImage(&img, getColor(TitleFont, false));
            else
                tmpImage = recolorImage(&img, iDecoFgDark);

            pixmap = new KPixmap(tmpImage);
            break;
        case InactiveDown:
            if (m_useTitleProps)
                tmpImage = recolorImage(&img, getColor(TitleFont, false));
            else
                tmpImage = recolorImage(&img, iDecoFgLight);

            pixmap = new KPixmap(tmpImage);
            break;
        case Shadow:
            // prepare shadow
            tmpShadow = QPixmap(icon.width()+4, icon.height()+4);
            tmpShadow.fill(QColor(0,0,0));
            tmpShadow.setMask(tmpShadow.createHeuristicMask(true));
            painter.begin(&tmpShadow);
            painter.setPen(white);
            painter.drawPixmap(0,0, icon);
            painter.end();
            tmpImage = se.makeShadow(tmpShadow, QColor(0, 0, 0));
            pixmap = new KPixmap(tmpImage);
            break;
        default:
            pixmap = new KPixmap();
    }

    m_pixmaps[status][type] = pixmap;
    return *pixmap;
}
Esempio n. 2
0
void KniftyClient::update_captionBuffer()
{
    if (!KniftyHandler::initialized()) return;

    const uint maxCaptionLength = 300; // truncate captions longer than this!
    QString captionText(caption() );
    if (captionText.length() > maxCaptionLength) {
        captionText.truncate(maxCaptionLength);
        captionText.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(captionText);

    QPixmap textPixmap;
    QPainter painter;
    if(KniftyHandler::titleShadow())
    {
        // prepare the shadow
        textPixmap = QPixmap(captionWidth+2*2, s_titleHeight ); // 2*2 px shadow space
        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask( textPixmap.createHeuristicMask(TRUE) );
        painter.begin(&textPixmap);
        painter.setFont(s_titleFont);
        painter.setPen(white);
        painter.drawText(textPixmap.rect(), AlignCenter, captionText );
        painter.end();
    }

    QImage shadow;
    ShadowEngine se;

    // active
    aCaptionBuffer->resize(captionWidth+4, s_titleHeight ); // 4 px shadow
    painter.begin(aCaptionBuffer);
    painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        shadow = se.makeShadow(textPixmap, QColor(0, 0, 0));
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, true));
    painter.drawText(aCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();


    // inactive
    iCaptionBuffer->resize(captionWidth+4, s_titleHeight );
    painter.begin(iCaptionBuffer);
    painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, false));
    painter.drawText(iCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();

    captionBufferDirty = false;
}