bool convertiblePairTypes(SbkConverter* firstConverter, bool firstCheckExact, SbkConverter* secondConverter, bool secondCheckExact, PyObject* pyIn) { assert(firstConverter); assert(secondConverter); assert(pyIn); if (!PySequence_Check(pyIn)) return false; if (PySequence_Size(pyIn) != 2) return false; AutoDecRef firstItem(PySequence_GetItem(pyIn, 0)); if (firstCheckExact) { if (!PyObject_TypeCheck(firstItem, firstConverter->pythonType)) return false; } else if (!isPythonToCppConvertible(firstConverter, firstItem)) { return false; } AutoDecRef secondItem(PySequence_GetItem(pyIn, 1)); if (secondCheckExact) { if (!PyObject_TypeCheck(secondItem, secondConverter->pythonType)) return false; } else if (!isPythonToCppConvertible(secondConverter, secondItem)) { return false; } return true; }
QMimeData *mimeData() { // create a list of the URL:s that we want to drag KUrl::List urls; QStringList labels; for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { AttachmentIconItem *item = static_cast<AttachmentIconItem *>( it ); if ( item->isBinary() ) { urls.append( tempFileForAttachment( item->attachment() ) ); } else { urls.append( item->uri() ); } labels.append( KUrl::toPercentEncoding( item->label() ) ); } } if ( selectionMode() == Q3IconView::NoSelection ) { AttachmentIconItem *item = static_cast<AttachmentIconItem *>( currentItem() ); if ( item ) { urls.append( item->uri() ); labels.append( KUrl::toPercentEncoding( item->label() ) ); } } QMap<QString, QString> metadata; metadata["labels"] = labels.join( ":" ); QMimeData *mimeData = new QMimeData; urls.populateMimeData( mimeData, metadata ); return mimeData; }
void OCompletionBox::setItems( const QStringList& items ) { bool block = signalsBlocked(); blockSignals( true ); QListBoxItem* item = firstItem(); if ( !item ) { insertStringList( items ); } else { for ( QStringList::ConstIterator it = items.begin(); it != items.end(); it++) { if ( item ) { ((OCompletionBoxItem*)item)->reuse( *it ); item = item->next(); } else { insertItem( new QListBoxText( *it ) ); } } QListBoxItem* tmp = item; while ( (item = tmp ) ) { tmp = item->next(); delete item; } triggerUpdate( false ); } blockSignals( block ); d->down_workaround = true; }
BOOL _XList::movePosition( int curPosition, int newPosition ) { if( curPosition == newPosition ) return FALSE; _XItem* curItem = getItem( curPosition ); if( !curItem ) return FALSE; if( firstItem()==curItem ) { if( newPosition == 0 ) return FALSE; removeItem( curItem ); resetList(); for(int i=0; i < newPosition; i++) nextItem(); insertItem( curItem ); return TRUE; } if( newPosition > 0 ) { removeItem( curItem ); resetList(); for(int i=0; i < newPosition; i++) nextItem(); insertItem( curItem ); } else // 리스트의 헤더로 옮기고자 할때 헤더 재설정 { removeItem( curItem ); resetList(); insertItem( curItem ); setAnchor( curItem ); } return TRUE; }
QDragObject *QtFileIconView::dragObject() { if ( !currentItem() ) return 0; QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ); QtFileIconDrag *drag = new QtFileIconDrag( viewport() ); drag->setPixmap( *currentItem()->pixmap(), QPoint( currentItem()->pixmapRect().width() / 2, currentItem()->pixmapRect().height() / 2 ) ); for ( QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); item; item = (QtFileIconViewItem*)item->nextItem() ) { if ( item->isSelected() ) { QIconDragItem id; id.setData( QCString( item->filename() ) ); drag->append( id, QRect( item->pixmapRect( FALSE ).x() - orig.x(), item->pixmapRect( FALSE ).y() - orig.y(), item->pixmapRect().width(), item->pixmapRect().height() ), QRect( item->textRect( FALSE ).x() - orig.x(), item->textRect( FALSE ).y() - orig.y(), item->textRect().width(), item->textRect().height() ), QString( item->filename() ) ); } } return drag; }
BOOL _XList::movePosition( _XItem* curPosItem, int newPosition ) { if( !curPosItem || newPosition > this->itemcount-1 ) return FALSE; // 옮기려는 스프라이트가 조상(리스트의 헤더)일때 조상 재설정 if( firstItem()==curPosItem ) { if( newPosition == 0 ) return FALSE; setAnchor( curPosItem->getright() ); curPosItem->unlink(); resetList(); for(int i=0; i < newPosition; i++) nextItem(); insertItem( curPosItem ); return TRUE; } if( newPosition > 0 ) { curPosItem->unlink(); resetList(); for(int i=0; i < newPosition; i++) nextItem(); insertItem( curPosItem ); } else // 리스트의 헤더로 옮기고자 할때 헤더 재설정 { curPosItem->unlink(); resetList(); insertItem( curPosItem ); setAnchor( curPosItem ); } return TRUE; }
virtual Q3DragObject *dragObject () { int count = 0; for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { ++count; } } QPixmap pixmap; if ( count > 1 ) { pixmap = KIconLoader::global()->loadIcon( "mail-attachment", KIconLoader::Desktop ); } if ( pixmap.isNull() ) { pixmap = static_cast<AttachmentIconItem *>( currentItem() )->icon(); } QPoint hotspot( pixmap.width() / 2, pixmap.height() / 2 ); QDrag *drag = new QDrag( this ); drag->setMimeData( mimeData() ); drag->setPixmap( pixmap ); drag->setHotSpot( hotspot ); drag->exec( Qt::CopyAction ); return 0; }
/* Function for .... */ State dequeue(Queue *qp) { State s = firstItem(qp->list); qp->list = removeFirstNode(qp->list); if ( isEmptyList(qp->list) ) { qp->lastNode = NULL; } return s; }
void ProfileNodePool::destroy(void) { T* pItem = firstItem(); while (pItem != unusedItem()) (pItem++)->destroy(); if (nextPool) nextPool->destroy(); free(this); }
//pickup first item under player void cGameServer::doPickup(int id) { //get slot of item at player int itemSlot = topmostItemAt(player[id].map,player[id].x,player[id].y); //return if no items if(itemSlot == -1) return; int invSlot=-1; int qty=ml_items.item[itemSlot].qty; if(getWeight(id) + ml_items.item[itemSlot].weight * abs(qty) > maxWeight(id)) { sendChatMsg(itod(id),"^RIt's too heavy.."); return; } //check if can stack if(ml_items.item[itemSlot].qty>0) { invSlot = firstItem(id,ml_items.item[itemSlot].item_template); if(invSlot!=-1) { //combine and remove ml_items.item[player[id].inventory[invSlot]].qty+=ml_items.item[itemSlot].qty; updateItem(player[id].inventory[invSlot]); removeItem(itemSlot); } } //check for empty space for new item if space not found if(invSlot==-1) invSlot=nextInventorySlot(id); //if past inventory limit then exit if(invSlot==-1) return; //if not combined and removed then move item into inventory from map if(ml_items.item[itemSlot].qty!=0) { ml_items.item[itemSlot].map=-1; ml_items.item[itemSlot].owner=id; ml_items.item[itemSlot].slot=invSlot; ml_items.item[itemSlot].life=10; updateItem(itemSlot); player[id].inventory[invSlot]=itemSlot; } //update clients sendInventoryAdd(itod(id),ml_items.item[player[id].inventory[invSlot]].graphic,ml_items.item[player[id].inventory[invSlot]].name,invSlot,qty); sendRemoveMapItem(player[id].map,player[id].x,player[id].y); }
void MontageView::drawPoints(const QPointArray& pa, QValueList<int>& corners, int correct) { if(ccv::debug) std::cerr << "MontageView::drawPoints - pa = " << pa.count() << " corners = " << corners.count() << "\n"; QIconViewItem* item = firstItem(); if( !item ) return; m_dirty = true; QImage img = item->pixmap()->convertToImage(); int item_nr = 0; bool failed = corners[item_nr] != correct; for( uint i=0; i<pa.count()+1; ++i ){ if( corners[item_nr] == 0 ) { QPixmap pm(img); item->setPixmap( pm ); item = item->nextItem(); if( !item ) return; img = item->pixmap()->convertToImage(); item_nr++; failed = corners[item_nr] != correct; } if(ccv::debug) std::cerr << " Point: " << i << " Image: " << item_nr << " (" << pa[i].x() << "," << pa[i].y() << ")" << " Corners: " << corners[item_nr] << "\n"; if( !failed ) { img.setPixel( pa[i].x() , pa[i].y()-1, qRgb(255,255,0) ); img.setPixel( pa[i].x()-1, pa[i].y() , qRgb(255,255,0) ); img.setPixel( pa[i].x() , pa[i].y() , qRgb(255,0,0) ); img.setPixel( pa[i].x()+1, pa[i].y() , qRgb(255,255,0) ); img.setPixel( pa[i].x() , pa[i].y()+1, qRgb(255,255,0) ); } else { img.setPixel( pa[i].x() , pa[i].y()-1, qRgb(255,0,0) ); img.setPixel( pa[i].x()-1, pa[i].y() , qRgb(255,0,0) ); img.setPixel( pa[i].x() , pa[i].y() , qRgb(255,255,0) ); img.setPixel( pa[i].x()+1, pa[i].y() , qRgb(255,0,0) ); img.setPixel( pa[i].x() , pa[i].y()+1, qRgb(255,0,0) ); } corners[item_nr]--; } }
void QtFileIconView::setViewMode( ViewMode m ) { if ( m == vm ) return; vm = m; QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); for ( ; item; item = (QtFileIconViewItem*)item->nextItem() ) item->viewModeChanged( vm ); arrangeItemsInGrid(); }
void MontageView::resetIcons() { if( !m_dirty ) return; m_dirty = false; // FixMe: This should be optimized by caching the old images instead for( QIconViewItem* item = firstItem(); item; item = item->nextItem() ) { QPixmap pm = *item->pixmap(); QSize size = pm.size(); QImage icon( item->text() ); pm = icon.smoothScale( size ); } }
QDragObject *KURLBarListBox::dragObject() { KURL::List urls; KURLBarItem *item = static_cast< KURLBarItem * >(firstItem()); while(item) { if(item->isSelected()) urls.append(item->url()); item = static_cast< KURLBarItem * >(item->next()); } if(!urls.isEmpty()) // ### use custom drag-object with description etc.? return new KURLDrag(urls, this, "urlbar drag"); return 0L; }
void OSItemList::setItemIds(const std::vector<OSItemId>& itemIds) { if (qobject_cast<ScriptsListView*>(this)) { std::vector<OSItem*> myItems = items(); size_t n = myItems.size(); if ((n > 0) && (itemIds.size() == n)) { bool doNothing = true; for (size_t i = 0; i < n; ++i) { if (std::find(itemIds.begin(),itemIds.end(),myItems[i]->itemId()) == itemIds.end()) { doNothing = false; break; } } if (doNothing) { return; } } } QLayoutItem* child; while( (child = m_vLayout->takeAt(0)) != nullptr ){ QWidget* widget = child->widget(); if (widget){ delete widget; } delete child; } m_vLayout->addStretch(); m_selectedItem = nullptr; for (const OSItemId& itemId : itemIds){ OSItem* item = OSItem::makeItem(itemId, OSItemType::ListItem); if (item){ addItem(item, false); } } selectItem(firstItem()); m_dirty = true; QTimer::singleShot(0, this, SLOT(refresh())); }
static unsigned int releaseDevices(deviceList *devList) { usbDeviceList *list = (usbDeviceList*)devList; unsigned int count = list->deviceList.count; usbDevice *head, *prev = NULL; /* loop, but if head does not change then sleep a bit */ while((head = (usbDevice*)firstItem(&list->deviceList)) != NULL) { if (head != prev) releaseDevice(&head->info); else sleep(100); prev = head; } /* illegal to access the list after this call */ free(list); return count; }
//We reimplement this method to add automatic change of the grid size void GofunIconView::arrangeItemsInGrid(bool update) { int b_height, b_width = 0; QIconViewItem* item = firstItem(); while(item) { //if(item->height() > b_height) //Outcommented because we currently don't need // b_height = item->height(); //it anyways, but maybe in a later implementation if(item->width() > b_width) b_width = item->width(); item = item->nextItem(); } if(gridX() != b_width && b_width) setGridX(b_width); //if(gridY() != b_width && b_height) //FIXME: If we uncomment this we end up with // setGridY(b_height); //an endless loop and bugs all the way. Not of high priority thought. QIconView::arrangeItemsInGrid(update); }
void TemplateIconView::addTemplateIcons(KileDocument::Type type) { if(!m_templateManager) return; QString emptyIcon = KGlobal::dirs()->findResource("appdata", "pics/"+ QString(DEFAULT_EMPTY_ICON) + ".png" ); KileTemplate::Info emptyDocumentInfo; emptyDocumentInfo.name = DEFAULT_EMPTY_CAPTION; emptyDocumentInfo.icon = emptyIcon; emptyDocumentInfo.type = type; TemplateItem *emp = new TemplateItem(this, emptyDocumentInfo); setSelected(emp, true); if(type == KileDocument::LaTeX) { // disable non standard templates QMap<QString,bool> map; map["Scrartcl"] = false; map["Scrbook"] = false; map["Scrreprt"] = false; map["Scrlttr2"] = false; map["Beamer"] = false; map["Prosper"] = false; map["HA-prosper"] = false; // split search results and look, which class files are present QStringList list = QStringList::split("\n",m_output); for ( QStringList::Iterator it=list.begin(); it!=list.end(); ++it ) { QString filename = QFileInfo(*it).fileName(); if ( filename=="scrartcl.cls" ) { map["Scrartcl"] = true; map["Scrbook"] = true; map["Scrreprt"] = true; map["Scrlttr2"] = true; } else if ( filename=="beamer.cls" ) map["Beamer"] = true; else if ( filename=="prosper.cls" ) map["Prosper"] = true; else if ( filename=="HA-prosper.sty" ) map["HA-prosper"] = true; } KileTemplate::TemplateList templateList = m_templateManager->getTemplates(KileDocument::LaTeX); // insert all standard templates, all user defined templates // and those templates, which have a present class for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i) { KileTemplate::Info info = *i; QString classname = info.name; if ( !map.contains(classname) || map[classname]==true ) { new TemplateItem(this, info); } } } else { KileTemplate::TemplateList templateList = m_templateManager->getTemplates(type); for (KileTemplate::TemplateListIterator i=templateList.begin(); i != templateList.end(); ++i) { new TemplateItem(this, *i); } } // sort all items (item for 'Empty Document' will always be the first one) sort(); // set the default item, if its given for ( QIconViewItem *item = firstItem(); item; item = item->nextItem() ) { if ( static_cast<TemplateItem*>(item)->name() == m_selicon ) { setSelected(item, true); ensureItemVisible(item); } } }
void TIconView::focusInEvent ( QFocusEvent* event ) { if(event->reason() == QFocusEvent::Tab) setSelected(firstItem(), true); }
static bool updateDeviceList(deviceList *devList) { usbDeviceList *list = (usbDeviceList*)devList; struct libusb_device *dev, **usbList; unsigned int pos, count = 0, newCount = 0; usbDevice *devPos; ssize_t listSize, listPos; /* fedora 19 seems to process udev triggers before the device is ready */ usleep(1000); /* initialize usb TODO: should call libusb_exit at the end? */ libusb_init(NULL); /* the next two return counts of busses and devices respectively */ listSize = libusb_get_device_list(NULL, &usbList); /* search for the first device we find */ for(listPos = 0; listPos < listSize; listPos++) { struct libusb_device_descriptor descriptor; dev = usbList[listPos]; libusb_get_device_descriptor(dev, &descriptor); for(pos = 0; list->ids[pos].idVendor != INVALID_VENDOR; pos++) /* continue if we are not examining the correct device */ if (descriptor.idVendor == list->ids[pos].idVendor && descriptor.idProduct == list->ids[pos].idProduct) { int busIndex; /* couldn't find the bus index as a number anywhere */ busIndex = libusb_get_bus_number(dev); /* found a device instance, now find position in * current list */ devPos = (usbDevice*)firstItem(&list->deviceList); setError(devPos, NULL, LIBUSB_SUCCESS); while(devPos != NULL && (devPos->busIndex < busIndex || (devPos->busIndex == busIndex && devPos->devIndex < libusb_get_device_address(dev)))) /* used to release devices here, since they * are no longer used, however, this races * with reinsertion of the device, and * therefore reuse of the ID. Additionally, * unplugs are detected now, so it is no * longer necessary. */ devPos = (usbDevice*)devPos->header.next; /* append or insert a new device */ if (devPos == NULL || devPos->busIndex != busIndex || devPos->devIndex != libusb_get_device_address(dev)) { if (list->describe) checkInUse(dev, true); else if (claimDevice(dev, list->ids + pos, list, devPos)) /* count how many devices we added */ newCount++; /* keep a count of the number of devices */ count++; } } } libusb_free_device_list(usbList, 0); /* deref devices */ if (wouldOutput(LOG_DEBUG) && newCount > 0) { unsigned int index = 0; message(LOG_DEBUG, "Handling %d device(s):\n", count); devPos = (usbDevice*)list->deviceList.head; for(; devPos; devPos = (usbDevice*)devPos->header.next) message(LOG_DEBUG, " %d) usb:%d.%d id=%d addr=%p\n", index++, devPos->busIndex, devPos->devIndex, devPos->info.id, (void*)devPos); } return true; }
void MessageOutput::checkMaxItems() { if ( count() >= m_maxItems ) removeItem( index(firstItem()) ); }