Пример #1
0
void UserList::drawItem(UserViewItemBase *base, QPainter *p, const QColorGroup &cg, int width, int margin)
{
    if (base->type() == GRP_ITEM){
        GroupItem *item = static_cast<GroupItem*>(base);
        p->setFont(font());
        QString text;
        if (item->id()){
            Group *grp = getContacts()->group(item->id());
            if (grp){
                text = grp->getName();
            }else{
                text = "???";
            }
        }else{
            text = i18n("Not in list");
        }
        int x = drawIndicator(p, 2 + margin, item, isGroupSelected(item->id()), cg);
        if (!CorePlugin::m_plugin->getUseSysColors())
            p->setPen(CorePlugin::m_plugin->getColorGroup());
        x = item->drawText(p, x, width, text);
        item->drawSeparator(p, x, width, cg);
        return;
    }
    if (base->type() == USR_ITEM){
        ContactItem *item = static_cast<ContactItem*>(base);
        int x = drawIndicator(p, 2 + margin, item, isSelected(item->id()), cg);
        if (!item->isSelected() || !hasFocus() || !CorePlugin::m_plugin->getUseDblClick()){
            if (CorePlugin::m_plugin->getUseSysColors()){
                if (item->status() != STATUS_ONLINE)
                    p->setPen(palette().disabled().text());
            }else{
                switch (item->status()){
                case STATUS_ONLINE:
                    break;
                case STATUS_AWAY:
                    p->setPen(CorePlugin::m_plugin->getColorAway());
                    break;
                case STATUS_NA:
                    p->setPen(CorePlugin::m_plugin->getColorNA());
                    break;
                case STATUS_DND:
                    p->setPen(CorePlugin::m_plugin->getColorDND());
                    break;
                default:
                    p->setPen(CorePlugin::m_plugin->getColorOffline());
                    break;
                }
            }
        }
        x = item->drawText(p, x, width, item->text(CONTACT_TEXT));
        return;
    }
    UserListBase::drawItem(base, p, cg, width, margin);
}
Пример #2
0
void UserViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    UserViewItemBase *base = dynamic_cast<UserViewItemBase*>(m_uv->itemFromIndex(index));
    if( NULL == base )
        return;

    painter->save();
    painter->translate(option.rect.x(), option.rect.y());

    QPainter *p = painter;
    QPalette cg = option.palette;
    int width = option.rect.width();
    int height = option.rect.height();
    QSize itemsize = option.rect.size();
    int margin = 1;

    switch( base->type() )
    {
    case GRP_ITEM:
        {
            GroupItem *item = static_cast<GroupItem*>(base);
            QString text = index.data( Qt::DisplayRole ).toString();
            QImage img = Image( ( option.state & QStyle::State_Open ) ? "expanded" : "collapsed");
            if (!img.isNull())
                p->drawImage(2 + margin, (height - img.height()) / 2, img);
            int x = 24 + margin;
            if (!( option.state & QStyle::State_Open ) && item->m_unread)
            {
                CommandDef *lcmdDefUnreadMessages = CorePlugin::instance()->messageTypes.find(item->m_unread);
                if (lcmdDefUnreadMessages)
                {
                    img = Image(lcmdDefUnreadMessages->icon);
                    if (!img.isNull())
                    {
                        if (m_uv->m_bUnreadBlink)
                            p->drawImage(x, (height - img.height()) / 2, img);
                        x += img.width() + 2;
                    }
                }
            }
            if (!CorePlugin::instance()->value("UseSysColors").toBool())
                p->setPen(CorePlugin::instance()->value("ColorGroup").toUInt());
            QFont f(option.font);
            if (CorePlugin::instance()->value("SmallGroupFont").toBool())
            {
                int size = f.pixelSize();
                if (size > 0)
                    f.setPixelSize(size * 3 / 4);
                else
                {
                    size = f.pointSize();
                    f.setPointSize(size * 3 / 4);
                }
            }
            f.setBold(true);
            p->setFont(f);
            x = drawText(p, x, itemsize, text);
            if (CorePlugin::instance()->value("GroupSeparator").toBool())
                drawSeparator(p, x, itemsize, m_uv->style());
            break;
        }
    case USR_ITEM:
        {
            ContactItem *item = static_cast<ContactItem*>(base);
            QFont f(option.font);
            if (item->style() & CONTACT_ITALIC)
            {
                if (CorePlugin::instance()->value("VisibleStyle").toUInt()  & STYLE_ITALIC)
                    f.setItalic(true);
                if (CorePlugin::instance()->value("VisibleStyle").toUInt()  & STYLE_UNDER)
                    f.setUnderline(true);
                if (CorePlugin::instance()->value("VisibleStyle").toUInt()  & STYLE_STRIKE)
                    f.setStrikeOut(true);
            }
            if (item->style() & CONTACT_UNDERLINE)
            {
                if (CorePlugin::instance()->value("AuthStyle").toUInt()  & STYLE_ITALIC)
                    f.setItalic(true);
                if (CorePlugin::instance()->value("AuthStyle").toUInt()  & STYLE_UNDER)
                    f.setUnderline(true);
                if (CorePlugin::instance()->value("AuthStyle").toUInt()  & STYLE_STRIKE)
                    f.setStrikeOut(true);
            }
            if (item->style() & CONTACT_STRIKEOUT)
            {
                if (CorePlugin::instance()->value("InvisibleStyle").toUInt()  & STYLE_ITALIC)
                    f.setItalic(true);
                if (CorePlugin::instance()->value("InvisibleStyle").toUInt()  & STYLE_UNDER)
                    f.setUnderline(true);
                if (CorePlugin::instance()->value("InvisibleStyle").toUInt()  & STYLE_STRIKE)
                    f.setStrikeOut(true);
            }
            int x = margin;
            QIcon mainIcon = index.data( Qt::DecorationRole ).value<QIcon>();
            if (!mainIcon.isNull())
            {
                QPixmap img = mainIcon.pixmap( 16 );
                x += 2;
                p->drawPixmap(x, ( height - img.height() ) / 2, img);
                x += img.width() + 2;
            }
            if (x < 24)
                x = 24;
            if (!item->isSelected() || !m_uv->hasFocus() || !CorePlugin::instance()->value("UseDblClick").toBool())
            {
                if (!CorePlugin::instance()->value("UseSysColors").toBool())
                {
                    switch (item->status())
                    {
                    case STATUS_ONLINE:
                        p->setPen(CorePlugin::instance()->value("ColorOnline").toUInt());
                        break;
                    case STATUS_FFC:
                        p->setPen(CorePlugin::instance()->value("ColorOnline").toUInt());
                        break;
                    case STATUS_AWAY:
                        p->setPen(CorePlugin::instance()->value("ColorAway").toUInt());
                        break;
                    case STATUS_NA:
                        p->setPen(CorePlugin::instance()->value("ColorNA").toUInt());
                        break;
                    case STATUS_DND:
                        p->setPen(CorePlugin::instance()->value("ColorDND").toUInt());
                        break;
                    default:
                        p->setPen(CorePlugin::instance()->value("ColorOffline").toUInt());
                        break;
                    }
                }
                if (item->status() != STATUS_ONLINE && item->status() != STATUS_FFC)
                    p->setPen(m_uv->palette().color(QPalette::Disabled,QPalette::Text));
            }
            if (item->m_bBlink)
                f.setBold(true);
            else
                f.setBold(false);

            p->setFont(f);
            QString highlight;
            QString text = index.data( Qt::DisplayRole ).toString();
            int pos=0;
            if(!m_uv->m_search.isEmpty())
            {
                pos=text.toUpper().indexOf(m_uv->m_search.toUpper());
                //Search for substring in contact name
                if (pos > -1)
                    highlight=text.mid(pos,m_uv->m_search.length());
            }
            int save_x = x;
            //p->setPen(QColor(0, 0, 0));
            x = drawText(p, x, itemsize, text);
            if (pos > 0)
                save_x = drawText(p, save_x, itemsize, text.left(pos)) - 4;
            x += 2;
            if (!highlight.isEmpty())
            {
                QPen oldPen = p->pen();
                QColor oldBg = p->background().color();
                p->setBackgroundMode(Qt::OpaqueMode);
                if (item == m_uv->m_searchItem)
                    if (item == m_uv->currentItem() && CorePlugin::instance()->value("UseDblClick").toBool())
                    {
                        p->setBackground(cg.color(QPalette::HighlightedText));
                        p->setPen(cg.color(QPalette::Highlight));
                    }
                    else
                    {
                        p->setBackground(cg.color(QPalette::Highlight));
                        p->setPen(cg.color(QPalette::HighlightedText));
                    }
                else
                {
                    p->setBackground(oldPen.color());
                    p->setPen(oldBg);
                }
                drawText(p, save_x, itemsize, highlight);
                p->setPen(oldPen);
                p->setBackground(oldBg);
                p->setBackgroundMode(Qt::TransparentMode);
            }
            unsigned xIcon = width;
            QString icons = index.data( SIM::ExtraIconsRole ).toString();
            while( !icons.isEmpty() ) 
            {
                QString icon = getToken(icons, ',');
                QImage img = Image(icon);
                if (!img.isNull())
                {
                    xIcon -= img.width() + 2;
                    if (xIcon < (unsigned)x)
                        break;
                    p->drawImage(xIcon, (height - img.height()) / 2, img);
                }
            }
            break;
        }
    case DIV_ITEM:
        {
            QString text = index.data( Qt::DisplayRole ).toString();
            QFont f(option.font);
            int size = f.pixelSize();
            if (size <= 0)
            {
                size = f.pointSize();
                f.setPointSize(size * 3 / 4);
            }
            else
                f.setPixelSize(size * 3 / 4);
            p->setFont(f);
            int x = drawText(p, 24 + margin, itemsize, text);
            drawSeparator(p, x, itemsize, m_uv->style());
            break;
        }
    }

    painter->restore();
}
Пример #3
0
void UserView::drawItem(UserViewItemBase *base, QPainter *p, const QColorGroup &cg, int width, int margin)
{
    if (base->type() == GRP_ITEM){
        GroupItem *item = static_cast<GroupItem*>(base);
        QFont f(font());
        int size = f.pixelSize();
        if (size <= 0){
            size = f.pointSize();
            f.setPointSize(size * 3 / 4);
        }else{
            f.setPixelSize(size * 3 / 4);
        }
        f.setBold(true);
        p->setFont(f);
        QString text;
        if (item->id()){
            Group *grp = getContacts()->group(item->id());
            if (grp){
                text = grp->getName();
            }else{
                text = "???";
            }
        }else{
            text = i18n("Not in list");
        }
        if (item->m_nContacts){
            text += " (";
            if (item->m_nContactsOnline){
                text += QString::number(item->m_nContactsOnline);
                text += "/";
            }
            text += QString::number(item->m_nContacts);
            text += ")";
        }
        const QPixmap &pict = Pict(item->isOpen() ? "expanded" : "collapsed");
        p->drawPixmap(2 + margin, (item->height() - pict.height()) / 2, pict);
        int x = 24 + margin;
        if (!item->isOpen() && item->m_unread){
            CommandDef *def = CorePlugin::m_plugin->messageTypes.find(item->m_unread);
            if (def){
                const QPixmap &pict = Pict(def->icon);
                if (m_bUnreadBlink)
                    p->drawPixmap(x, (item->height() - pict.height()) / 2, pict);
                x += pict.width() + 2;
            }
        }
        if (!CorePlugin::m_plugin->getUseSysColors())
            p->setPen(CorePlugin::m_plugin->getColorGroup());
        x = item->drawText(p, x, width, text);
        if (CorePlugin::m_plugin->getGroupSeparator())
            item->drawSeparator(p, x, width, cg);
        return;
    }
    if (base->type() == USR_ITEM){
        ContactItem *item = static_cast<ContactItem*>(base);
        QFont f(font());
        if (item->style() & CONTACT_ITALIC)
            f.setItalic(true);
        if (item->style() & CONTACT_UNDERLINE)
            f.setUnderline(true);
        if (item->style() & CONTACT_STRIKEOUT)
            f.setStrikeOut(true);
        if (item->m_bBlink){
            f.setBold(true);
        }else{
            f.setBold(false);
        }
        p->setFont(f);
        string icons = item->text(CONTACT_ICONS).latin1();
        string icon = getToken(icons, ',');
        if (item->m_unread && m_bUnreadBlink){
            CommandDef *def = CorePlugin::m_plugin->messageTypes.find(item->m_unread);
            if (def)
                icon = def->icon;
        }
        int x = margin;
        if (icon.length()){
            const QPixmap &pict = Pict(icon.c_str());
            x += 2;
            p->drawPixmap(x, (item->height() - pict.height()) / 2, pict);
            x += pict.width() + 2;
        }
        if (x < 24)
            x = 24;
        if (!item->isSelected() || !hasFocus() || !CorePlugin::m_plugin->getUseDblClick()){
            if (CorePlugin::m_plugin->getUseSysColors()){
                if (item->status() != STATUS_ONLINE)
                    p->setPen(palette().disabled().text());
            }else{
                switch (item->status()){
                case STATUS_ONLINE:
                    break;
                case STATUS_AWAY:
                    p->setPen(CorePlugin::m_plugin->getColorAway());
                    break;
                case STATUS_NA:
                    p->setPen(CorePlugin::m_plugin->getColorNA());
                    break;
                case STATUS_DND:
                    p->setPen(CorePlugin::m_plugin->getColorDND());
                    break;
                default:
                    p->setPen(CorePlugin::m_plugin->getColorOffline());
                    break;
                }
            }
        }
        QString highlight;
        QString text = item->text(CONTACT_TEXT);
        if (!m_search.isEmpty()){
            if (text.left(m_search.length()).upper() == m_search.upper())
                highlight = text.left(m_search.length());
        }
        int save_x = x;
        x = item->drawText(p, x, width, text);
        x += 2;
        if (!highlight.isEmpty()){
            QPen oldPen = p->pen();
            QColor oldBg = p->backgroundColor();
            p->setBackgroundMode(OpaqueMode);
            if (item == m_searchItem){
                if ((item == currentItem()) && CorePlugin::m_plugin->getUseDblClick()){
                    p->setBackgroundColor(cg.highlightedText());
                    p->setPen(cg.highlight());
                }else{
                    p->setBackgroundColor(cg.highlight());
                    p->setPen(cg.highlightedText());
                }
            }else{
                p->setBackgroundColor(oldPen.color());
                p->setPen(oldBg);
            }
            item->drawText(p, save_x, width, highlight);
            p->setPen(oldPen);
            p->setBackgroundColor(oldBg);
            p->setBackgroundMode(TransparentMode);
        }
        unsigned xIcon = width;
        while (icons.length()){
            icon = getToken(icons, ',');
            const QPixmap &pict = Pict(icon.c_str());
            xIcon -= pict.width() + 2;
            if (xIcon < (unsigned)x)
                break;
            p->drawPixmap(xIcon, (item->height() - pict.height()) / 2, pict);
        }
        return;
    }
    UserListBase::drawItem(base, p, cg, width, margin);
}