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); }
void UserList::contentsMouseReleaseEvent(QMouseEvent *e) { QListViewItem *list_item = itemAt(contentsToViewport(e->pos())); if (list_item == NULL) return; switch (static_cast<UserViewItemBase*>(list_item)->type()){ case USR_ITEM:{ ContactItem *item = static_cast<ContactItem*>(list_item); if (isSelected(item->id())){ for (list<unsigned>::iterator it = selected.begin(); it != selected.end(); ++it){ if ((*it) == item->id()){ selected.erase(it); break; } } }else{ selected.push_back(item->id()); } item->repaint(); item->parent()->repaint(); emit selectChanged(); break; } case GRP_ITEM:{ GroupItem *item = static_cast<GroupItem*>(list_item); if (isGroupSelected(item->id())){ for (QListViewItem *i = item->firstChild(); i; i = i->nextSibling()){ ContactItem *ci = static_cast<ContactItem*>(i); list<unsigned>::iterator it; for (it = selected.begin(); it != selected.end(); ++it){ if ((*it) == ci->id()){ selected.erase(it); break; } } ci->repaint(); } }else{ for (QListViewItem *i = item->firstChild(); i; i = i->nextSibling()){ ContactItem *ci = static_cast<ContactItem*>(i); list<unsigned>::iterator it; for (it = selected.begin(); it != selected.end(); ++it) if ((*it) == ci->id()) break; if (it == selected.end()){ selected.push_back(ci->id()); ci->repaint(); } } } item->repaint(); emit selectChanged(); break; } } m_pressedItem = NULL; }
GroupItem *UserListBase::findGroupItem(unsigned id, QListViewItem *p) { for (QListViewItem *item = p ? p->firstChild() : firstChild(); item; item = item->nextSibling()){ UserViewItemBase *i = static_cast<UserViewItemBase*>(item); if (i->type() == GRP_ITEM){ GroupItem *grpItem = static_cast<GroupItem*>(item); if (grpItem->id() == id) return grpItem; } if (item->isExpandable()){ GroupItem *res = findGroupItem(id, item); if (res) return res; } } return NULL; }
void *UserListBase::processEvent(Event *e) { if (e->type() == EventRepaintView) viewport()->repaint(); if (m_bInit){ switch (e->type()){ case EventGroupCreated:{ Group *g = (Group*)(e->param()); addGroupForUpdate(g->id()); break; } case EventGroupChanged:{ Group *g = (Group*)(e->param()); addGroupForUpdate(g->id()); break; } case EventGroupDeleted:{ Group *g = (Group*)(e->param()); for (list<unsigned long>::iterator it = updGroups.begin(); it != updGroups.end(); ++it){ if (*it == g->id()){ updGroups.erase(it); break; } } QListViewItem *item = findGroupItem(g->id()); deleteItem(item); break; } case EventContactCreated:{ Contact *c = (Contact*)(e->param()); if (!c->getIgnore() && (c->getTemporary() == 0)) addContactForUpdate(c->id()); break; } case EventContactStatus: case EventContactChanged:{ Contact *c = (Contact*)(e->param()); if (!c->getIgnore() && (c->getTemporary() == 0)){ addContactForUpdate(c->id()); }else{ Event e(EventContactDeleted, c); processEvent(&e); } break; } case EventMessageReceived:{ Message *msg = (Message*)(e->param()); if (msg->type() == MessageStatus){ Contact *contact = getContacts()->contact(msg->contact()); if (contact) addContactForUpdate(contact->id()); } break; } case EventContactDeleted:{ Contact *g = (Contact*)(e->param()); for (list<unsigned long>::iterator it = updContacts.begin(); it != updContacts.end(); ++it){ if (*it == g->id()){ updContacts.erase(it); break; } } ContactItem *item = findContactItem(g->id()); if (item){ if (m_groupMode){ GroupItem *grpItem = static_cast<GroupItem*>(item->parent()); grpItem->m_nContacts--; if (item->m_bOnline) grpItem->m_nContactsOnline--; addGroupForUpdate(grpItem->id()); deleteItem(item); if ((m_groupMode == 2) && (grpItem->firstChild() == NULL) && m_bShowOnline){ DivItem *div = static_cast<DivItem*>(grpItem->parent()); if (div->state() == DIV_OFFLINE){ deleteItem(grpItem); if (div->firstChild() == NULL) deleteItem(div); } } }else{ QListViewItem *p = item->parent(); deleteItem(item); if (p->firstChild() == NULL) deleteItem(p); } } break; } } } return ListView::processEvent(e); }
void UserListBase::drawUpdates() { m_bDirty = false; updTimer->stop(); QListViewItem *item; list<unsigned long>::iterator it; for (it = updGroups.begin(); it != updGroups.end(); ++it){ Group *group = getContacts()->group(*it); if (group == NULL) continue; switch (m_groupMode){ case 1: item = findGroupItem(group->id()); if (item){ static_cast<GroupItem*>(item)->update(group); repaintItem(item); }else{ new GroupItem(this, group, true); } break; case 2: for (item = firstChild(); item; item = item->nextSibling()){ UserViewItemBase *i = static_cast<UserViewItemBase*>(item); if (i->type() != DIV_ITEM) continue; DivItem *divItem = static_cast<DivItem*>(i); GroupItem *grpItem = findGroupItem(group->id(), divItem); if (grpItem){ grpItem->update(group); repaintItem(grpItem); }else{ new GroupItem(divItem, group, divItem->state() == DIV_OFFLINE); } } break; } } updGroups.clear(); DivItem *itemOnline = NULL; DivItem *itemOffline = NULL; if (updContacts.size()){ if (m_groupMode != 1){ for (item = firstChild(); item != NULL; item = item->nextSibling()){ UserViewItemBase *i = static_cast<UserViewItemBase*>(item); if (i->type() != DIV_ITEM) continue; DivItem *divItem = static_cast<DivItem*>(i); if (divItem->state() == DIV_ONLINE) itemOnline = divItem; if (divItem->state() == DIV_OFFLINE) itemOffline = divItem; } } } for (it = updContacts.begin(); it != updContacts.end(); ++it){ Contact *contact = getContacts()->contact(*it); if (contact == NULL) continue; ContactItem *contactItem; GroupItem *grpItem; unsigned style; string icons; unsigned status = getUserStatus(contact, style, icons); unsigned unread = getUnread(contact->id()); bool bShow = false; ListUserData *data = (ListUserData*)(contact->getUserData(CorePlugin::m_plugin->list_data_id)); if (data && data->ShowAllways) bShow = true; switch (m_groupMode){ case 0: if (status == STATUS_OFFLINE){ if (itemOnline){ contactItem = findContactItem(contact->id(), itemOnline); if (contactItem){ deleteItem(contactItem); if (itemOnline->firstChild() == NULL){ deleteItem(itemOnline); itemOnline = NULL; } } } if ((unread == 0) && !bShow && m_bShowOnline){ if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ deleteItem(contactItem); if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } break; } if (itemOffline == NULL){ itemOffline = new DivItem(this, DIV_OFFLINE); setOpen(itemOffline, true); } contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(itemOffline); repaintItem(contactItem); }else{ contactItem = new ContactItem(itemOffline, contact, status, style, icons.c_str(), unread); } }else{ if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); if (contactItem){ deleteItem(contactItem); if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } if (itemOnline == NULL){ itemOnline = new DivItem(this, DIV_ONLINE); setOpen(itemOnline, true); } contactItem = findContactItem(contact->id(), itemOnline); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(itemOnline); repaintItem(contactItem); }else{ contactItem = new ContactItem(itemOnline, contact, status, style, icons.c_str(), unread); } } break; case 1: contactItem = findContactItem(contact->id()); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if (((status == STATUS_OFFLINE) && (unread == 0) && !bShow && m_bShowOnline) || (contact->getGroup() != grpItem->id())){ grpItem->m_nContacts--; if (contactItem->m_bOnline) grpItem->m_nContactsOnline--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; grpItem = NULL; } } if ((status != STATUS_OFFLINE) || unread || bShow || !m_bShowOnline){ if (grpItem == NULL) grpItem = findGroupItem(contact->getGroup()); if (grpItem){ if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(grpItem); repaintItem(contactItem); if (!m_bShowOnline && (contactItem->m_bOnline != (status != STATUS_OFFLINE))){ if (status == STATUS_OFFLINE){ grpItem->m_nContactsOnline--; contactItem->m_bOnline = false; }else{ grpItem->m_nContactsOnline++; contactItem->m_bOnline = true; } addGroupForUpdate(grpItem->id()); } }else{ contactItem = new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; if (!m_bShowOnline && (status != STATUS_OFFLINE)){ grpItem->m_nContactsOnline++; contactItem->m_bOnline = true; } addGroupForUpdate(grpItem->id()); } } } break; case 2: contactItem = findContactItem(contact->id(), itemOnline); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if ((status == STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){ grpItem->m_nContacts--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; } } if (itemOffline){ contactItem = findContactItem(contact->id(), itemOffline); grpItem = NULL; if (contactItem){ grpItem = static_cast<GroupItem*>(contactItem->parent()); if ((status != STATUS_OFFLINE) || (grpItem->id() != contact->getGroup())){ grpItem->m_nContacts--; addGroupForUpdate(grpItem->id()); deleteItem(contactItem); contactItem = NULL; if (m_bShowOnline && (grpItem->firstChild() == NULL)){ deleteItem(grpItem); grpItem = NULL; if (itemOffline->firstChild() == NULL){ deleteItem(itemOffline); itemOffline = NULL; } } } } } if ((unread == 0) && !bShow && (status == STATUS_OFFLINE) && m_bShowOnline) break; DivItem *divItem; if (status == STATUS_OFFLINE){ if (itemOffline == NULL){ itemOffline = new DivItem(this, DIV_OFFLINE); setOpen(itemOffline, true); } divItem = itemOffline; }else{ divItem = itemOnline; } grpItem = findGroupItem(contact->getGroup(), divItem); if (grpItem == NULL){ Group *grp = getContacts()->group(contact->getGroup()); if (grp == NULL) break; grpItem = new GroupItem(divItem, grp, true); } contactItem = findContactItem(contact->id(), grpItem); if (contactItem){ if (contactItem->update(contact, status, style, icons.c_str(), unread)) addSortItem(grpItem); }else{ new ContactItem(grpItem, contact, status, style, icons.c_str(), unread); grpItem->m_nContacts++; addGroupForUpdate(grpItem->id()); } } } updContacts.clear(); for (list<QListViewItem*>::iterator it_sort = sortItems.begin(); it_sort != sortItems.end(); ++it_sort){ (*it_sort)->sort(); } sortItems.clear(); }
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); }