Пример #1
0
void ServiceButton::startDrag()
{
    QString path = _service->desktopEntryPath();

    // If the path to the desktop file is relative, try to get the full
    // path from KStdDirs.
    path = locate("apps", path);

    KURL url;
    url.setPath(path);
    emit dragme(KURL::List(url), labelIcon());
}
Пример #2
0
void BrowserButton::startDrag()
{
    KUrl url(topMenu->path());
    emit dragme(KUrl::List(url), labelIcon());
}
Пример #3
0
void PanelButton::drawButtonLabel(QPainter *p)
{
    QPixmap icon = labelIcon();
    bool active = isDown() || isOn();

    if (active)
    {
        icon = icon.convertToImage().smoothScale(icon.width() - 2,
                                                 icon.height() - 2);
    }

    if (!m_buttonText.isEmpty() && orientation() == Horizontal)
    {
        int h = height();
        int w = width();
        int y = (h - icon.height())/2;
        p->save();
        QFont f = font();

        double fontPercent = m_fontPercent;
        if (active)
        {
            fontPercent *= .8;
        }
        f.setPixelSize(KMIN(h, KMAX(int(float(h) * m_fontPercent), 16)));
        QFontMetrics fm(f);
        p->setFont(f);

        /* Draw shadowed text */
        bool reverse = QApplication::reverseLayout();
        QPainter::TextDirection rtl = reverse ? QPainter::RTL : QPainter::LTR;

        if (!reverse && !icon.isNull())
        {
            /* Draw icon */
            p->drawPixmap(3, y, icon);
        }

        int tX = reverse ? 3 : icon.width() + KMIN(25, KMAX(5, fm.width('m') / 2));
        int tY = fm.ascent() + ((h - fm.height()) / 2);

        QColor shadCol = KickerLib::shadowColor(m_textColor);

        // get a transparent pixmap
        QPainter pixPainter;
        QPixmap textPixmap(w, h);

        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask(textPixmap.createHeuristicMask(true));

        // draw text
        pixPainter.begin(&textPixmap);
        pixPainter.setPen(m_textColor);
        pixPainter.setFont(p->font()); // get the font from the root painter
        pixPainter.drawText(tX, tY, m_buttonText, -1, rtl);
        pixPainter.end();

        if (!s_textShadowEngine)
        {
            KShadowSettings* shadset = new KShadowSettings();
            shadset->setOffsetX(0);
            shadset->setOffsetY(0);
            shadset->setThickness(1);
            shadset->setMaxOpacity(96);
            s_textShadowEngine = new KShadowEngine(shadset);
        }

        // draw shadow
        QImage img = s_textShadowEngine->makeShadow(textPixmap, shadCol);
        p->drawImage(0, 0, img);
        p->save();
        p->setPen(m_textColor);
        p->drawText(tX, tY, m_buttonText, -1, rtl);
        p->restore();

        if (reverse && !icon.isNull())
        {
            p->drawPixmap(w - icon.width() - 3, y, icon);
        }

        p->restore();
    }
    else if (!icon.isNull())
    {
        int y = (height() - icon.height()) / 2;
        int x = (width()  - icon.width()) / 2;
        p->drawPixmap(x, y, icon);
    }

    if (m_drawArrow && (m_highlight || active))
    {
        QStyle::PrimitiveElement e = QStyle::PE_ArrowUp;
        int arrowSize = style().pixelMetric(QStyle::PM_MenuButtonIndicator);
        QRect r((width() - arrowSize)/2, 0, arrowSize, arrowSize);

        switch (m_arrowDirection)
        {
            case KPanelExtension::Top:
                e = QStyle::PE_ArrowUp;
                break;
            case KPanelExtension::Bottom:
                e = QStyle::PE_ArrowDown;
                r.moveBy(0, height() - arrowSize);
                break;
            case KPanelExtension::Right:
                e = QStyle::PE_ArrowRight;
                r = QRect(width() - arrowSize, (height() - arrowSize)/2, arrowSize, arrowSize);
                break;
            case KPanelExtension::Left:
                e = QStyle::PE_ArrowLeft;
                r = QRect(0, (height() - arrowSize)/2, arrowSize, arrowSize);
                break;
            case KPanelExtension::Floating:
                if (orientation() == Horizontal)
                {
                    e = QStyle::PE_ArrowDown;
                    r.moveBy(0, height() - arrowSize);
                }
                else if (QApplication::reverseLayout())
                {
                    e = QStyle::PE_ArrowLeft;
                    r = QRect(0, (height() - arrowSize)/2, arrowSize, arrowSize);
                }
                else
                {
                    e = QStyle::PE_ArrowRight;
                    r = QRect(width() - arrowSize, (height() - arrowSize)/2, arrowSize, arrowSize);
                }
                break;
        }

        int flags = QStyle::Style_Enabled;
        if (active)
        {
            flags |= QStyle::Style_Down;
        }
        style().drawPrimitive(e, p, r, colorGroup(), flags);
    }
}