Exemplo n.º 1
0
QIcon IconFactory::appIcon(AppIconFlags flags)
{
    const bool running = flags.testFlag(AppIconRunning);
    const QString suffix = running ? "-busy" : "-normal";
    const QString sessionName = qApp->property("CopyQ_session_name").toString();

    QIcon icon;

    if (sessionName.isEmpty())
        icon = QIcon::fromTheme("copyq" + suffix);

    if (icon.isNull()) {
        const QString resourceSuffix = running ? "-running" : "";
        QPixmap pix = imageFromPrefix(suffix + ".svg", "icon" + resourceSuffix);

        if (!sessionName.isEmpty()) {
            const QColor color1(0x7f, 0xca, 0x9b);
            const QColor color2 = sessionNameToColor(sessionName);
            replaceColor(&pix, color1, color2);
        }

        icon.addPixmap(pix);
    }

    if (flags.testFlag(AppIconDisabled)) {
        QIcon disabledIcon;
        foreach (const QSize &size, icon.availableSizes())
            disabledIcon.addPixmap(icon.pixmap(size, QIcon::Disabled));
        return disabledIcon;
    }
Exemplo n.º 2
0
QIcon IconFactory::appIcon(AppIconFlags flags)
{
    QPixmap pix = flags.testFlag(AppIconRunning)
            ? imageFromPrefix("-busy.svg", "icon-running")
            : imageFromPrefix("-normal.svg", "icon");

    const QString sessionName = qApp->property("CopyQ_session_name").toString();
    if (!sessionName.isEmpty()) {
        const QColor color1 = QColor(0x7f, 0xca, 0x9b);
        const QColor color2 = sessionNameToColor(sessionName);
        replaceColor(&pix, color1, color2);
    }

    if (flags.testFlag(AppIconDisabled)) {
        QPainter p(&pix);
        p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
        p.fillRect(pix.rect(), QColor(100, 100, 100, 100));
    }

    return QIcon(pix);
}