void SimpleNetworkVisualizationHandler::conserveSelection() {

	if(mOwner == 0 || !mSelectedElements.empty()) {
		return;
	}
	mSelectedElements.clear();

	QList<PaintItem*> selectedElements = mOwner->getSelectedItems();
	for(QListIterator<PaintItem*> i(selectedElements); i.hasNext();) {
		PaintItem *item = i.next();
		NeuronItem *neuronItem = dynamic_cast<NeuronItem*>(item);
		if(neuronItem != 0) {
			mSelectedElements.append(neuronItem->getNeuron());
			continue;
		}
		SynapseItem *synapseItem = dynamic_cast<SynapseItem*>(item);
		if(synapseItem != 0) {
			mSelectedElements.append(synapseItem->getSynapse());
			continue;
		}
		ModuleItem *moduleItem = dynamic_cast<ModuleItem*>(item);
		if(moduleItem != 0) {
			mSelectedElements.append(moduleItem->getNeuroModule());
			continue;
		}
		GroupItem *groupItem = dynamic_cast<GroupItem*>(item);
		if(groupItem != 0) {
			mSelectedElements.append(groupItem->getNeuronGroup());
			continue;
		}
	}
}
GroupItem*
DeviceInfoForm::CreateGroupItem(int groupIndex, int itemWidth)
{
    static const int GROUP_ITEM_HEIGHT = 50;

    static const wchar_t* pStringOfDeviceInfoType[DeviceInfoType::LENGTH] = { L"Device Name",
                                                                        L"MAC Address",
                                                                        L"IP Address",
                                                                        L"SSID",
                                                                        L"Device Status",
                                                                        L"Group Member Type",
                                                                        L"Device Category Type",
                                                                        L"WPS Configuration Modes" };

	GroupItem* pItem = new GroupItem();
	pItem->Construct(Dimension(GetClientAreaBounds().width, GROUP_ITEM_HEIGHT));

	// skip IP addrss and SSID
	if ((groupIndex >= DeviceInfoType::IP_ADDRESS) && (__pLocalDeviceInfo->GetGroupMemberType() == WIFI_DIRECT_GROUP_MEMBER_TYPE_NONE))
	{
		groupIndex += 2;
	}

	pItem->SetElement(pStringOfDeviceInfoType[groupIndex], null);
	return pItem;
}
Пример #3
0
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;
}
Пример #4
0
int GroupModel::getCount(const QDate &date, int vidId) const
{
	int res = 0;
	Q_FOREACH (Item* i, items)
	{
		GroupItem* gi = (GroupItem*)i;
		GroupParam p = gi->getParam();
		if ( (p.vid_id == vidId) && (p.bdtime.date() == date) )
		{
			res++;
		}
	}
Пример #5
0
void RxDev::on_pushButton_group_clicked()
{
    GroupItem * newGroup;
    newGroup = new GroupItem;
    newGroup->setLocation(findSpace(QPoint(0,55)));
newGroup->setColor(Qt::yellow);
newGroup->setPos(findSpace(QPoint(0,55)));
    if (newGroup->getGroupData()==true){
        scene->addItem(newGroup);
    }

}
void SimpleNetworkVisualizationHandler::updateVisualizationSet() {
	TRACE("SimpleNetworkVisualizationHandler::updateVisualizationSet");

	for(QListIterator<NeuronItem*> i(mNeurons); i.hasNext();) {
		NeuronItem *item = i.next();
		if(item->isActive()) {
			mOwner->addPaintItem(item);
		}
		else {
			mOwner->removePaintItem(item);
		}
	}
	for(QListIterator<NeuronItem*> i(mNeuronItemPool); i.hasNext();) {
		mOwner->removePaintItem(i.next());
	}
	for(QListIterator<SynapseItem*> i(mSynapses); i.hasNext();) {
		SynapseItem *item = i.next();
		if(item->isActive()) {
			mOwner->addPaintItem(item);
		}
		else {
			mOwner->removePaintItem(item);
		}
	}	
	for(QListIterator<SynapseItem*> i(mSynapseItemPool); i.hasNext();) {
		mOwner->removePaintItem(i.next());
	}
	for(QListIterator<ModuleItem*> i(mModules); i.hasNext();) {
		ModuleItem *item = i.next();
		if(item->isActive()) {
			mOwner->addPaintItem(item);
		}
		else {
			mOwner->removePaintItem(item);
		}
	}
	for(QListIterator<ModuleItem*> i(mModuleItemPool); i.hasNext();) {
		mOwner->removePaintItem(i.next());
	}
	for(QListIterator<GroupItem*> i(mGroups); i.hasNext();) {
		GroupItem *item = i.next();
		if(item->isActive()) {
			mOwner->addPaintItem(item);
		}
		else {
			mOwner->removePaintItem(item);
		}
	}
	for(QListIterator<GroupItem*> i(mGroupItemPool); i.hasNext();) {
		mOwner->removePaintItem(i.next());
	}
}
Пример #7
0
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;
}
Пример #8
0
Tizen::Ui::Controls::GroupItem*
EventListForm::CreateGroupItem(int groupIndex, int itemWidth)
{
	GroupItem* pItem = new (std::nothrow) GroupItem();
	pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
	pItem->SetBackgroundColor(Color(COLOR_ITEM_BACKGROUND));

	if (groupIndex == GROUP_INDEX_ALL_DAY_EVENT)
	{
		pItem->SetElement(L"모든 일정");
	}
	else
	{
		pItem->SetElement(L"일정 목록");
	}

	return pItem;
}
Пример #9
0
/**
 * 保持中のホストリストからグループリストを取得する。
 * @retval グループリスト
 */
std::vector<GroupItem>
HostList::GetGroupList()
{
	IPMSG_FUNC_ENTER( "std::vector<GroupItem> HostList::GetGroupList()" );
	std::vector<GroupItem> ret;
	HostList tmp = *this;
	tmp.sort( new IpMsgGetGroupListComparator() );
	std::string hostName = "", encodingName = "";
	for( std::vector<HostListItem>::iterator ixhost = tmp.begin(); ixhost != tmp.end(); ixhost++ ) {
		if ( hostName != ixhost->HostName() || encodingName != ixhost->EncodingName() ){
			GroupItem item;
			item.setGroupName( ixhost->GroupName() );
			item.setEncodingName( ixhost->EncodingName() );
			ret.push_back( item );
		}
		hostName = ixhost->HostName();
		encodingName = ixhost->EncodingName();
	}
	IPMSG_FUNC_RETURN( ret );
}
Osp::Ui::Controls::GroupItem* Form1::CreateGroupItem(int groupIndex, int itemWidth) {
    GroupItem* pItem = new GroupItem();
    pItem->Construct(Dimension(itemWidth, 32));
    String text;
    text.Format(100, L"Group #%d", groupIndex);

    /* You can also set a bitmap in group items,
     * just pass a Bitmap pointer as the second
     * parameter to the GroupItem::SetElement() */
    pItem->SetElement(text, null);

    /* You can set a custom background color to group items */
    // pItem->SetBackgroundColor(Color::COLOR_BLACK);

    /* You can set a custom text size */
    // pItem->SetTextSize(26);

    return pItem;

}
Пример #11
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);
}
Пример #12
0
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);
}
Пример #13
0
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();
}
Пример #14
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);
}
Пример #15
0
GroupItem*
PartnerListForm::CreateGroupItem(int groupIndex, float itemWidth)
{
	GroupItem* pItem = new (std::nothrow) GroupItem();
	pItem->Construct(FloatDimension(itemWidth, 76.0f));
	String text(L"");
	switch (groupIndex)
	{
	case GROUP_INDEX0:
		text.Append(Group_name[0]);

		break;
	case GROUP_INDEX1:
		text.Append(Group_name[1]);
		break;
	case GROUP_INDEX2:
		text.Append(Group_name[2]);
		break;
	case GROUP_INDEX3:
		text.Append(Group_name[3]);
		break;
	case GROUP_INDEX4:
		text.Append(Group_name[4]);
		break;
	case GROUP_INDEX5:
		text.Append(Group_name[5]);
		break;
	case GROUP_INDEX6:
		text.Append(Group_name[6]);
		break;
	case GROUP_INDEX7:
		text.Append(Group_name[7]);
		break;
	case GROUP_INDEX8:
		text.Append(Group_name[8]);
		break;
	case GROUP_INDEX9:
		text.Append(Group_name[9]);
		break;
	case GROUP_INDEX10:
		text.Append(Group_name[10]);
		break;
	case GROUP_INDEX11:
		text.Append(Group_name[11]);
		break;
	case GROUP_INDEX12:
		text.Append(Group_name[12]);
		break;
	case GROUP_INDEX13:
		text.Append(Group_name[13]);
		break;
	case GROUP_INDEX14:
		text.Append(Group_name[14]);
		break;
	case GROUP_INDEX15:
		text.Append(Group_name[15]);
		break;
	case GROUP_INDEX16:
		text.Append(Group_name[16]);
		break;
	case GROUP_INDEX17:
		text.Append(Group_name[17]);
		break;
	case GROUP_INDEX18:
		text.Append(Group_name[18]);
		break;
	case GROUP_INDEX19:
		text.Append(Group_name[19]);
		break;
	case GROUP_INDEX20:
		text.Append(Group_name[20]);
		break;
	case GROUP_INDEX21:
		text.Append(Group_name[21]);
		break;
	case GROUP_INDEX22:
		text.Append(Group_name[22]);
		break;
	case GROUP_INDEX23:
		text.Append(Group_name[23]);
		break;
	case GROUP_INDEX24:
		text.Append(Group_name[24]);
		break;
	case GROUP_INDEX25:
		text.Append(Group_name[25]);
		break;
	default:
		break;
	}
	pItem->SetElement(text, null);
	return pItem;
}
void SimpleNetworkVisualizationHandler::clearVisualization() {
	TRACE("SimpleNetworkVisualizationHandler::clearVisualization");

	QList<NeuronItem*> neurons = mNeurons;
	neurons << mNeuronItemPool;
	mNeurons.clear();
	mNeuronItemPool = neurons;
	for(QListIterator<NeuronItem*> i(mNeuronItemPool); i.hasNext();) {
		NeuronItem *item = i.next();
		QPointF pos = item->getGlobalPosition();
		item->setParent(0);
		item->setLocalPosition(pos);
		item->setNeuron(0);
		item->setActive(false);
		item->setHidden(true);
		item->setSelected(false);
	}
	QList<SynapseItem*> synapses = mSynapses;
	synapses << mSynapseItemPool;
	mSynapses.clear();
	mSynapseItemPool = synapses;
	for(QListIterator<SynapseItem*> i(mSynapseItemPool); i.hasNext();) {
		SynapseItem *item = i.next();
		QPointF pos = item->getGlobalPosition();
		item->setParent(0);
		item->setLocalPosition(pos);
		item->setSynapse(0);
		item->setActive(false);
		item->setHidden(true);
		item->setSelected(false);
	}
	QList<ModuleItem*> modules = mModules;
	modules << mModuleItemPool;
	mModules.clear();
	mModuleItemPool = modules;
	for(QListIterator<ModuleItem*> i(mModuleItemPool); i.hasNext();) {
		ModuleItem *item = i.next();
		QPointF pos = item->getGlobalPosition();
		item->setParent(0);
		item->setLocalPosition(pos);
		item->setModule(0);
		item->setActive(false);
		item->setHidden(true);
		item->setSelected(false);
		QList<PaintItem*> members = item->getMemberItems();
		for(QListIterator<PaintItem*> j(members); j.hasNext();) {
			PaintItem *it = j.next();
			item->removeMemberItem(it);
			it->setParent(0);
		}
	}
	QList<GroupItem*> groups = mGroups;
	groups << mGroupItemPool;
	mGroups.clear();
	mGroupItemPool = groups;
	for(QListIterator<GroupItem*> i(mGroupItemPool); i.hasNext();) {
		GroupItem *item = i.next();
		QPointF pos = item->getGlobalPosition();
		item->setParent(0);
		item->setLocalPosition(pos);
		item->setNeuronGroup(0);
		item->setActive(false);
		item->setHidden(true);
		item->setSelected(false);
	}

	mNeuronLookup.clear();
	mSynapseLookup.clear();
	mModuleLookup.clear();
	mGroupLookup.clear();

	updateVisualizationSet();


	while(mNeuronItemPool.size() > Math::max(0, mMaxSizeOfNeuronPool->get())) {
		NeuronItem *item = mNeuronItemPool.last();
		mNeuronItemPool.removeAll(item);
		delete item;
	}
	while(mSynapseItemPool.size() > Math::max(0, mMaxSizeOfSynapsePool->get())) {
		SynapseItem *item = mSynapseItemPool.last();
		mSynapseItemPool.removeAll(item);
		delete item;
	}
	while(mModuleItemPool.size() > Math::max(0, mMaxSizeOfModulePool->get())) {
		ModuleItem *item = mModuleItemPool.last();
		mModuleItemPool.removeAll(item);
		delete item;
	}
	while(mGroupItemPool.size() > Math::max(0, mMaxSizeOfGroupPool->get())) {
		GroupItem *item = mGroupItemPool.last();
		mGroupItemPool.removeAll(item);
		delete item;
	}
	
	if(mGridPosition.y() > 500) {
		mGridPosition = QPointF(20.0, 250.0);
	}

}
bool SimpleNetworkVisualizationHandler::updateNetworkView() {
	TRACE("SimpleNetworkVisualizationHandler::updateNetworkView");

	QMutexLocker locker(Neuro::getNeuralNetworkManager()->getNetworkExecutionMutex());
	
	QList<NeuronItem*> currentNeuronItems = mNeurons;
	QList<SynapseItem*> currentSynapseItems = mSynapses;
	QList<ModuleItem*> currentModuleItems = mModules;
	QList<GroupItem*> currentGroupItems = mGroups;

	for(QListIterator<ModuleItem*> i(currentModuleItems); i.hasNext();) {
		ModuleItem *moduleItem = i.next();
		QList<PaintItem*> members = moduleItem->getMemberItems();
		for(QListIterator<PaintItem*> j(members); j.hasNext();) {
			moduleItem->removeMemberItem(j.next());
		}
	}


	mNeurons.clear();
	mSynapses.clear();
	mModules.clear();
	mGroups.clear();

	if(mNetwork != 0) {

		//setup neurons
		QList<Neuron*> neurons = mNetwork->getNeurons();
		
		for(int i = 0; i < neurons.size(); ++i) {

			Neuron *neuron = neurons.at(i);

			NeuronItem *item = getNeuronItem(neuron);
			if(item == 0) {
				if(!mNeuronItemPool.empty()) {
					item = mNeuronItemPool.takeFirst();
				}
				if(item == 0) {
					item = mNeuronItemPrototype->createCopy();
				}
			}

			if(neuron->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				NetworkEditorUtil::setPaintItemLocation(item, 
						neuron->getProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION));
			}
			else {
				setLocationByGrid(item);
			}

			item->setNeuron(neuron);
			item->setActive(true);
			item->setHidden(false);

			if(!mNeurons.contains(item)) {
				mNeuronLookup.insert(neuron, item);
				mNeurons.append(item);
			}

			currentNeuronItems.removeAll(item);
		}

		//remove obsolete neuron items
		for(QListIterator<NeuronItem*> i(currentNeuronItems); i.hasNext();) {
			NeuronItem *item = i.next();
			item->setHidden(true);
			item->setActive(false);
			item->setToHiddenLayer(false);
			mNeuronLookup.remove(item->getNeuron());
			item->setNeuron(0);
			item->setParent(0);
			mNeuronItemPool.append(item);
		}

		//setup synapses
		QList<Synapse*> synapses = mNetwork->getSynapses();

		for(int i = 0; i < synapses.size(); ++i) {

			Synapse *synapse = synapses.at(i);

			SynapseItem *item = getSynapseItem(synapse);

			if(item == 0) {
				if(!mSynapseItemPool.empty()) {
					item = mSynapseItemPool.takeFirst();
				}
				if(item == 0) {
					item = mSynapseItemPrototype->createCopy();
				}
			}
			if(synapse->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				NetworkEditorUtil::setPaintItemLocation(item, 
						synapse->getProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION));
			}
			else {
				setLocationByGrid(item);
			}

			item->setSynapse(synapse);
			item->setActive(true);
			item->setHidden(false);

			if(!mSynapses.contains(item)) {
				mSynapseLookup.insert(synapse, item);
				mSynapses.append(item);
			}

			currentSynapseItems.removeAll(item);
		}

		//remove obsolete synapse items
		for(QListIterator<SynapseItem*> i(currentSynapseItems); i.hasNext();) {
			SynapseItem *item = i.next();
			item->setHidden(true);
			item->setActive(false);
			item->setToHiddenLayer(false);
			mSynapseLookup.remove(item->getSynapse());
			item->setSynapse(0);
			item->setParent(0);
			mSynapseItemPool.append(item);
		}

		//setup modules
		QList<NeuroModule*> modules = mNetwork->getNeuroModules();

		for(int i = 0; i < modules.size(); ++i) {

			NeuroModule *module = modules.at(i);

			ModuleItem *item = getModuleItem(module);

			if(item == 0) {
				if(!mModuleItemPool.empty()) {
					item = mModuleItemPool.takeFirst();
				}
				if(item == 0) {
					item = mModuleItemPrototype->createCopy();
				}
			}
			if(module->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				NetworkEditorUtil::setPaintItemLocation(item, 
						module->getProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION));
			}
			else {
				setLocationByGrid(item);
			}
			if(module->hasProperty(NeuralNetworkConstants::TAG_MODULE_SIZE)) {
				NetworkEditorUtil::setModuleItemSize(item, 
						module->getProperty(NeuralNetworkConstants::TAG_MODULE_SIZE));
			}

			item->setModule(module);
			item->setActive(true);
			item->setHidden(false);

			QList<PaintItem*> memberItems = item->getMemberItems();

			for(QListIterator<PaintItem*> k(memberItems); k.hasNext();) {
				PaintItem *it = k.next();
				QPointF pos = it->getGlobalPosition();
				item->removeMemberItem(it);
				it->setLocalPosition(pos);
			}

			if(!mModules.contains(item)) {
				mModuleLookup.insert(module, item);
				mModules.append(item);
			}
			currentModuleItems.removeAll(item);

			//add member neurons to module
			QRectF moduleBounds = item->getBoundingBox();
			QList<Neuron*> members = module->getNeurons();

			for(QListIterator<Neuron*> j(members); j.hasNext();) {
				Neuron *n = j.next();

				if(n == 0) {
					continue;
				}

				NeuronItem *neuronItem = getNeuronItem(n);
				if(neuronItem == 0) {
					continue;
				}
				QRectF neuronBounds = neuronItem->getBoundingBox();

				QPointF pos = neuronItem->getLocalPosition() - item->getGlobalPosition();
				pos.setX(Math::min(Math::max(pos.x(), (neuronBounds.width() / 2.0)),
						 moduleBounds.width() - (neuronBounds.width() / 2.0)));
				pos.setY(Math::min(Math::max(pos.y(), (neuronBounds.height() / 2.0)),
						 moduleBounds.height() - (neuronBounds.height() / 2.0)));
				

				neuronItem->setLocalPosition(pos);
				item->addMemberItem(neuronItem);
			}

			//add member synapses to module
			for(QListIterator<Synapse*> j(synapses); j.hasNext();) {		
				Synapse *s = j.next();
				if(s == 0) {
					continue;
				}
				Neuron *n = s->getSource();
				if(n == 0) {
					continue;
				}

				if(!members.contains(n)) {
					continue;
				}

				SynapseItem *synapseItem = getSynapseItem(s);
				if(synapseItem == 0) {
					continue;
				}
				synapseItem->setLocalPosition(
								synapseItem->getLocalPosition() - item->getGlobalPosition());

				item->addMemberItem(synapseItem);
			}	
		}

		//remove obsolete module items
		for(QListIterator<ModuleItem*> i(currentModuleItems); i.hasNext();) {
			ModuleItem *item = i.next();
			item->setHidden(true);
			item->setActive(false);
			item->setToHiddenLayer(false);
			mModuleLookup.remove(item->getNeuroModule());
			item->setModule(0);
			item->setParent(0);
			mModuleItemPool.append(item);
		}

		//check if submodules have to be added.
		for(int i = 0; i < modules.size(); ++i) {
			NeuroModule *module = modules.at(i);

			if(module == 0) {
				continue;
			}

			ModuleItem *moduleItem = getModuleItem(module);

			if(moduleItem == 0) {
				continue;
			}

			QList<NeuroModule*> subModules = module->getSubModules();

			for(QListIterator<NeuroModule*> j(subModules); j.hasNext();) {
				NeuroModule *subModule = j.next();

				if(subModule == 0) {
					continue;
				}

				ModuleItem *subModuleItem = getModuleItem(subModule);

				if(subModuleItem == 0) {
					continue;
				}

				subModuleItem->setLocalPosition(
						subModuleItem->getLocalPosition() - moduleItem->getGlobalPosition());
				moduleItem->addMemberItem(subModuleItem);
			}
		}

		//setup groups
		QList<NeuronGroup*> groups = mNetwork->getNeuronGroups();

		for(int i = 0; i < groups.size(); ++i) {

			NeuronGroup *group = groups.at(i);
			if(dynamic_cast<NeuroModule*>(group) != 0) {
				//ignore neuro modules
				continue;
			}

			GroupItem *item = getGroupItem(group);

			if(item == 0) {
				if(!mGroupItemPool.empty()) {
					item = mGroupItemPool.takeFirst();
				}
				if(item == 0) {
					item = mGroupItemPrototype->createCopy();
				}
			}
			if(group->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				NetworkEditorUtil::setPaintItemLocation(item, 
						group->getProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION));
			}
			else {
				setLocationByGrid(item);
			}

			item->setNeuronGroup(group);
			item->setActive(true);
			item->setHidden(false);

			if(!mGroups.contains(item)) {
				mGroupLookup.insert(group, item);
				mGroups.append(item);
			}

			currentGroupItems.removeAll(item);
		}

		//remove obsolete group items
		for(QListIterator<GroupItem*> i(currentGroupItems); i.hasNext();) {
			GroupItem *item = i.next();
			item->setHidden(true);
			item->setActive(false);
			item->setToHiddenLayer(false);
			mGroupLookup.remove(item->getNeuronGroup());
			item->setNeuronGroup(0);
			item->setParent(0);
			mGroupItemPool.append(item);
		}

		//update location property
		for(QListIterator<NeuronItem*> i(mNeurons); i.hasNext();) {
			NeuronItem *item = i.next();
			if(item == 0) {
				continue;
			}
			Neuron *neuron = item->getNeuron();
			if(neuron == 0 || neuron->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				continue;
			}
			neuron->setProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION, 
											QString::number(item->getGlobalPosition().x()) + "," 
											+ QString::number(item->getGlobalPosition().y()) + ",0");
		}
		for(QListIterator<SynapseItem*> i(mSynapses); i.hasNext();) {
			SynapseItem *item = i.next();
			if(item == 0) {
				continue;
			}
			Synapse *synapse = item->getSynapse();
			if(synapse == 0 || synapse->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				continue;
			}
			synapse->setProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION,
 											QString::number(item->getGlobalPosition().x()) + "," 
											+ QString::number(item->getGlobalPosition().y()) + ",0");
		}
		for(QListIterator<ModuleItem*> i(mModules); i.hasNext();) {
			ModuleItem *item = i.next();
			if(item == 0) {
				continue;
			}
			NeuroModule *module = item->getNeuroModule();
			if(module == 0 || module->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				continue;
			}
			module->setProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION,
											QString::number(item->getGlobalPosition().x()) + "," 
											+ QString::number(item->getGlobalPosition().y()) + ",0");
		}
		for(QListIterator<GroupItem*> i(mGroups); i.hasNext();) {
			GroupItem *item = i.next();
			if(item == 0) {
				continue;
			}
			NeuronGroup *group = item->getNeuronGroup();
			if(group == 0 || group->hasProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION)) {
				continue;
			}
			group->setProperty(NeuralNetworkConstants::TAG_ELEMENT_LOCATION,
											QString::number(item->getGlobalPosition().x()) + "," 
											+ QString::number(item->getGlobalPosition().y()) + ",0");
		}
	}
	else {
		clearVisualization();
	}
	updateVisualizationSet(); 
	
	if(mOwner != 0) {
		mOwner->updateHiddenLayerMode();
	}

	return true;
}