void MainWindow::insertItem() { if (!listWidget->currentItem()) return; QString itemText = QInputDialog::getText(this, tr("Insert Item"), tr("Input text for the new item:")); if (itemText.isNull()) return; //! [6] QListWidgetItem *newItem = new QListWidgetItem; newItem->setText(itemText); //! [6] int row = listWidget->row(listWidget->currentItem()); //! [7] listWidget->insertItem(row, newItem); //! [7] QString toolTipText = tr("Tooltip:") + itemText; QString statusTipText = tr("Status tip:") + itemText; QString whatsThisText = tr("What's This?:") + itemText; //! [8] newItem->setToolTip(toolTipText); newItem->setStatusTip(toolTipText); newItem->setWhatsThis(whatsThisText); //! [8] }
FunctionListWidget::FunctionListWidget(QWidget *parent) : QListWidget(parent) { QString skeleton; QString statusTip; QHashIterator<enum FunctionNames, QString> i(presetFunctions.fcnNames()); while (i.hasNext()) { i.next(); QListWidgetItem *functionItem = new QListWidgetItem(this); functionItem->setText(i.value()); skeleton = presetFunctions.fcnSkeleton(i.key()); statusTip = presetFunctions.fcnStatusTip(i.key()); functionItem->setStatusTip(skeleton + statusTip); functionItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); } sortItems(); setMouseTracking(true); // add connections connect(this, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemSkeleton(QListWidgetItem*))); }
void IPProcessList::addProcessItem(QString processID, QString text, QString keywords, IPLProcess::IPLProcessCategory category) { // load icon from png file and add background color based on the process category QFileInfo iconFile(_mainWindow->processIconPath(processID)); if(!iconFile.exists()) { iconFile = QFileInfo(_mainWindow->processIconPath("Plugin")); } QPixmap transparentIcon(iconFile.absoluteFilePath()); QPixmap finalIcon(25,25); QPainter painter(&finalIcon); painter.fillRect(0,0,25,25,_categoryColors.at(category)); painter.drawPixmap(0,0,25,25,transparentIcon); QListWidgetItem* newItem = new QListWidgetItem(finalIcon, text); newItem->setToolTip(processID); newItem->setStatusTip(keywords); newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); addItem(newItem); }
//---------------------------------------------------------------------------------------- void ZoneListWidget::prepareView() { _createImages(mIcons); listWidget->clear(); Ogre::String filename; Ogre::String itemname; ImageMap::iterator it = mIcons.begin(); ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object")); if(!factory)return; while(it != mIcons.end()) { QImage pImg(it->second, 96, 96, QImage::Format_ARGB32); QPixmap pmap = QPixmap::fromImage(pImg); QListWidgetItem *item = new QListWidgetItem(QIcon(pmap),(factory->getZoneTemplate(it->first))->mName.c_str() , listWidget); item->setData(Qt::UserRole,QVariant(it->first));//key to ZoneTemplatesMap item->setToolTip((factory->getZoneTemplate(it->first))->mShortDesc.c_str());// a short description of the zone item->setStatusTip((factory->getZoneTemplate(it->first))->mLongDesc.c_str());//a detailed description listWidget->addItem(item); delete [] it->second; it++; } mIcons.clear(); }
//添加网络item int PlaylistWindow::addItemFromNet(const QString &additem, const QString &link,int id, bool playNow) { QListWidgetItem *item = new QListWidgetItem(additem,listWidget); int row = listWidget->row(item); //添加索引字符 QString index = ""; if(row<9) { index.append("0").append(QString::number(row+1,10).append(". ")); } else { index = QString::number(row+1,10).append(". "); } item->setText(index.append(item->text())); //设置item高度 item->setSizeHint(QSize(100,30)); item->setIcon(QIcon(":/image/net.ico")); item->setWhatsThis(QString::number(id,10)); item->setToolTip(additem); //设置media的类型 item->setStatusTip(QString::number(MEDIA_TYPE_MUSIC,10)); this->setItemNormalView(item); //添加到playlist 并将第一条设置为当前播放item playlist->addMedia(QUrl(link)); // this->setItemPlay(row); if (playNow){ this->doubleClicked = false; playlist->setCurrentIndex(row); } //qDebug("%d",playlist->currentIndex()); return MEDIA_TYPE_MUSIC; }
//从本地添加items int PlaylistWindow::addItemFromLocal(const QStringList &addList,bool playNow) { int mediaType; bool flag=true; for(int i=0;i<addList.length();i++) { QString label = addList.at(i); QFileInfo fileInfo(label); if(fileInfo.exists()) { QStringList list = label.split("/"); QListWidgetItem *item = new QListWidgetItem(list.last(),listWidget); int row = listWidget->row(item); //添加索引字符 QString index = ""; if(row<9) { index.append("0").append(QString::number(row+1,10).append(". ")); } else { index = QString::number(row+1,10).append(". "); } item->setText(index.append(item->text())); //设置item高度 item->setSizeHint(QSize(100,30)); item->setToolTip(label); //设置media的类型 int type = getMediaType(label); if(type != -1){ if(type == MEDIA_TYPE_MUSIC){ item->setIcon(QIcon(":/image/music.gif")); } else{ item->setIcon(QIcon(":/image/video.ico")); } item->setStatusTip(QString::number(type,10)); } this->setItemNormalView(item); //添加到playlist 并将第一条设置为当前播放item qDebug() << playlist->mediaCount(); playlist->addMedia(QUrl::fromLocalFile(label)); if(flag){ flag=false; mediaType = type; if(playNow){ //this->setItemPlay(row); playlist->setCurrentIndex(row); }else{ listWidget->setCurrentItem(item); } } } else { continue; } } return mediaType; }
//---------------------------------------------------------------------------------------- void ZoneListWidget::updateZoneInfo(int key) { //TODO: there's gotta be a better way to do this... //update zone description ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object")); if(!factory)return; ZoneInfo* zone = factory->getZoneTemplate(key); for(int i=0;i<listWidget->count();i++) { QListWidgetItem *item = listWidget->item(i); if(item->data(Qt::UserRole).toInt()==key) { item->setToolTip(zone->mShortDesc.c_str());// a short description of the zone item->setStatusTip(zone->mLongDesc.c_str());//a detailed description } } }
//---------------------------------------------------------------------------------------- void ZoneListWidget::addZone(int key) { ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object")); if(!factory)return; ZoneInfo* zone = factory->getZoneTemplate(key); if(zone) { #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX QIcon icon("/usr/share/qtOgitor/Plugins/Icons/zone.svg"); #else QIcon icon("../Plugins/Icons/zone.svg"); #endif QListWidgetItem *item = new QListWidgetItem(icon,zone->mName.c_str() , listWidget); item->setData(Qt::UserRole,QVariant(key));//key to ZoneTemplatesMap item->setToolTip(zone->mShortDesc.c_str());// a short description of the zone item->setStatusTip(zone->mLongDesc.c_str());//a detailed description listWidget->addItem(item); } }
static PyObject *meth_QListWidgetItem_setStatusTip(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; { const QString* a0; int a0State = 0; QListWidgetItem *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QListWidgetItem, &sipCpp, sipType_QString,&a0, &a0State)) { sipCpp->setStatusTip(*a0); sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QListWidgetItem, sipName_setStatusTip, doc_QListWidgetItem_setStatusTip); return NULL; }
// ================ // PUBLIC SLOTS // ================ void DirWidget::LoadDir(QString dir, QList<LFileInfo> list){ if(dir.isEmpty()){ return; } //nothing to do QTime time; if(DEBUG){time.start(); } qDebug() << "Load Dir:" << dir; QString lastdir = CDIR; //for some checks later QString lastbasedir = normalbasedir; CDIR = dir; if(CDIR.endsWith("/") && CDIR.length() > 1){ CDIR.chop(1); } CLIST = list; //save for later canmodify = QFileInfo(CDIR).isWritable(); if(DEBUG){ qDebug() << "Clear UI:" <<time.elapsed(); } //Clear the status text if(!canmodify){ui->label_status->setText(tr("(Limited Access) ")); } else{ ui->label_status->setText(""); } //Hide the extra buttons for a moment ui->tool_goToPlayer->setVisible(false); ui->tool_goToImages->setVisible(false); ui->tool_new_dir->setVisible(canmodify); ui->tool_new_file->setVisible(canmodify); //Set the drag/drop info as appripriate if(canmodify){ listWidget->setWhatsThis(CDIR); treeWidget->setWhatsThis(CDIR); }else{ listWidget->setWhatsThis(""); treeWidget->setWhatsThis(""); } bool updateThumbs = (lastdir != CDIR); //Determine if this is an internal ZFS snapshot bool loadsnaps = false; if(DEBUG){ qDebug() << "Load Snap Info:" << time.elapsed(); } if( dir.contains(ZSNAPDIR) ){ //This is a zfs snapshot - only update the saved paths necessary to rotate between snapshots/system snaprelpath = dir.section(ZSNAPDIR,1,1000).section("/",1,1000); //the relative path inside the snapshot if(snaprelpath.endsWith("/")){ snaprelpath.chop(1); } normalbasedir = dir.section(ZSNAPDIR,0,0)+"/"+snaprelpath; //Update the new base directory if(normalbasedir.endsWith("/")){ normalbasedir.chop(1); } line_dir->setText(normalbasedir); //See if this was a manual move to the directory, or an internal move QString tmp = dir.section(ZSNAPDIR,0,0); if(tmp != snapbasedir.section(ZSNAPDIR,0,0)){ loadsnaps = true; //different snapshot loaded - need to update internally } }else{ //This is a normal directory - prompt for snapshot information line_dir->setText(CDIR); normalbasedir = CDIR; if(!snapbasedir.isEmpty()){ watcher->removePath(snapbasedir); } snapbasedir.clear(); loadsnaps = true; } if(loadsnaps){ //kick this off while still loading the dir contents ui->group_snaps->setEnabled(false); //to prevent the snap updates to be automatically used ui->group_snaps->setVisible(false); ui->slider_snap->setRange(1,1); emit findSnaps(ID, normalbasedir); } if(DEBUG){ qDebug() << "Update History:" <<time.elapsed(); } //Now update the history for this browser //qDebug() << "History:" << history << normalbasedir << lastbasedir; if(!history.isEmpty() && history.last() == normalbasedir && lastbasedir!=normalbasedir ){ //We went back one - remove this from the history history.takeLast(); ui->actionBack->setEnabled(!history.isEmpty()); //qDebug() << " - Duplicate: removed item"; }else if(lastbasedir!=normalbasedir){ //not a refresh or internal snapshot change //qDebug() << " - New History Item:" << normalbasedir; history << normalbasedir; ui->actionBack->setEnabled(history.length()>1); } if(DEBUG){ qDebug() << "Update Watcher:" << time.elapsed(); } //Clear the current watcher if(!watcher->directories().isEmpty()){ watcher->removePaths(watcher->directories()); } if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); } watcher->addPath(CDIR); // add sessionsettings to watcher so date_format can be update based on user settings watcher->addPath(sessionsettings_config_file); ui->actionStopLoad->setVisible(true); stopload = false; //Clear the display widget (if a new directory) if(DEBUG){ qDebug() << "Clear Browser Widget:" << time.elapsed(); } double scrollpercent = -1; if(updateThumbs){ needThumbs.clear(); } if(lastbasedir != normalbasedir){ if(showDetails){ treeWidget->clear(); } else{ listWidget->clear(); } QApplication::processEvents(); //make sure it is cleared right away }else{ //Need to be smarter about which items need to be removed // - compare the old/new lists and remove any items not in the new listing (new items taken care of below) QStringList newfiles; //just the filenames for(int i=0; i<CLIST.length(); i++){ newfiles << CLIST[i].fileName(); } if(showDetails){ for(int i=0; i<treeWidget->topLevelItemCount(); i++){ if( !newfiles.contains(treeWidget->topLevelItem(i)->whatsThis(0).section("/",-1)) ){ if(!updateThumbs){ needThumbs.removeAll( treeWidget->topLevelItem(i)->whatsThis(0).section("::::",1,50)); } delete treeWidget->takeTopLevelItem(i); i--; } } QApplication::processEvents(); //make sure the scrollbar is up to date after removals scrollpercent = treeWidget->verticalScrollBar()->value()/( (double) treeWidget->verticalScrollBar()->maximum()); }else{ for(int i=0; i<listWidget->count(); i++){ if( !newfiles.contains(listWidget->item(i)->text()) ){ if(!updateThumbs){ needThumbs.removeAll( listWidget->item(i)->whatsThis().section("::::",1,50)); } delete listWidget->takeItem(i); i--; } } QApplication::processEvents(); //make sure the scrollbar is up to date after removals scrollpercent = listWidget->horizontalScrollBar()->value()/( (double) listWidget->horizontalScrollBar()->maximum()); } } //end check for CDIR reload //Now fill the display widget bool hasimages, hasmultimedia; hasimages = hasmultimedia = false; int numdirs = 0; qint64 filebytes = 0; //Setup the timer to see when we should process events /*QTimer updatetime; updatetime.setInterval(1000); //1 second updates updatetime.setSingleShot(true); updatetime.start();*/ QTime updatetime = QTime::currentTime().addMSecs(500); if(DEBUG){ qDebug() << "Start Loop over items:" << time.elapsed(); } for(int i=0; i<list.length(); i++){ if(stopload){ ui->actionStopLoad->setVisible(false); return; } //stop right now if(!hasimages && list[i].isImage()){ hasimages = true; ui->tool_goToImages->setVisible(true); } else if(!hasmultimedia && list[i].isAVFile()){ hasmultimedia = true; ui->tool_goToPlayer->setVisible(true); } //Update statistics if(list[i].isDir()){ numdirs++; } else{ filebytes += list[i].size(); } watcher->addPath(list[i].absoluteFilePath()); if(showDetails){ //Now create all the individual items for the details tree CQTreeWidgetItem *it; bool addnew = false; //See if an item already exists for this file QList<QTreeWidgetItem*> items = treeWidget->findItems(list[i].fileName(),Qt::MatchExactly,0); //NOTE: This requires column 0 to be the name if(items.isEmpty()){ it = new CQTreeWidgetItem(); addnew = true; }else{ // Safe downcasting because CQTreeWidgetItem only redefines the virtual function bool opearot<. Not new methos added. it = static_cast<CQTreeWidgetItem *> (items.first()); } //Now update the entry contents it->setWhatsThis(0, QString(canmodify ? "cut": "copy")+"::::"+list[i].absoluteFilePath()); for(int t=0; t<listDetails.length(); t++){ switch(listDetails[t]){ case NAME: it->setText(t,list[i].fileName()); it->setStatusTip(t, list[i].fileName()); //Since the icon/image is based on the filename - only update this for a new item // (This is the slowest part of the routine) if(list[i].isImage()&& (addnew || updateThumbs)){ if(showThumbs){ it->setIcon(t, LXDG::findIcon("fileview-preview","image-x-generic") ); needThumbs << list[i].fileName(); }else{ it->setIcon(t, LXDG::findIcon(list[i].iconfile(),"image-x-generic") ); } }else if(addnew){ it->setIcon(t, LXDG::findIcon(list[i].iconfile(),"unknown") ); } break; case SIZE: if(!list[i].isDir()){ it->setText(t, LUtils::BytesToDisplaySize(list[i].size()) ); } break; case TYPE: it->setText(t, list[i].mimetype()); break; case DATEMOD: { QStringList datetime_format = getDateFormat(); // Save datetime in WhatThis value. Lately will be used by CQTreeWidgetItem for sorting by date it->setWhatsThis(t, list[i].lastModified().toString("yyyyMMddhhmmsszzz")); // Default configurition. Fallback to Qt::DefaultLocaleShortDate for formats if(datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().toString(Qt::DefaultLocaleShortDate) ); // Date is setted but time not. Time goes to default else if(!datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(Qt::DefaultLocaleShortDate)); // Time is setted but date not. Date goes to default else if(datetime_format.at(0).isEmpty() && !datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().date().toString(Qt::DefaultLocaleShortDate) + " " + list[i].lastModified().time().toString(datetime_format.at(1))); // Both time and date setted. else it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(datetime_format.at(1))); break; } case DATECREATE: { QStringList datetime_format = getDateFormat(); it->setWhatsThis(DATECREATE, list[i].lastModified().toString("yyyyMMddhhmmsszzz")); if(datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().toString(Qt::DefaultLocaleShortDate) ); else if(!datetime_format.at(0).isEmpty() && datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(Qt::DefaultLocaleShortDate)); else if(datetime_format.at(0).isEmpty() && !datetime_format.at(1).isEmpty()) it->setText(t, list[i].lastModified().date().toString(Qt::DefaultLocaleShortDate) + " " + list[i].lastModified().time().toString(datetime_format.at(1))); else it->setText(t, list[i].lastModified().date().toString(datetime_format.at(0)) + " " + list[i].lastModified().time().toString(datetime_format.at(1))); break; } } } if(addnew){ treeWidget->addTopLevelItem(it); } if(tmpSel.contains(list[i].absoluteFilePath())){ it->setSelected(true); } if(lastdir == CDIR+"/"+list[i].fileName()){ treeWidget->setCurrentItem(it); treeWidget->scrollToItem(it); } }else{ //Create all the individual items for the basic list QListWidgetItem *it; //See if there is an existing item to re-use bool addnew = false; QList<QListWidgetItem*> items = listWidget->findItems(list[i].fileName(), Qt::MatchExactly); if(items.isEmpty()){ it = new QListWidgetItem(); addnew = true; }else{ it = items.first(); } it->setWhatsThis( QString(canmodify ? "cut": "copy")+"::::"+list[i].absoluteFilePath()); //used for drag and drop it->setText(list[i].fileName()); it->setStatusTip(list[i].fileName()); //Since the icon/image is based on the filename - only update this for a new items (non-thumbnail) // (This is the slowest part of the routine) if(list[i].isImage() && (addnew || updateThumbs) ){ if(showThumbs){ it->setIcon(LXDG::findIcon("fileview-preview","image-x-generic") ); needThumbs << list[i].fileName(); }else{ it->setIcon(LXDG::findIcon(list[i].iconfile(),"image-x-generic") ); } }else if(addnew){ it->setIcon(LXDG::findIcon(list[i].iconfile(),"unknown") ); } listWidget->addItem(it); if(tmpSel.contains(list[i].absoluteFilePath())){ it->setSelected(true); } if(lastdir == CDIR+"/"+list[i].fileName()){ listWidget->setCurrentItem(it); listWidget->scrollToItem(it); } } if(QTime::currentTime() > updatetime){ QApplication::processEvents(); updatetime = QTime::currentTime().addMSecs(500); }//keep the UI snappy while loading a directory if(DEBUG){ qDebug() << " - item finished:" << i << time.elapsed(); } } tmpSel.clear(); if(DEBUG){ qDebug() << "Done with item loop:" << time.elapsed() << list.length(); } ui->actionStopLoad->setVisible(false); //Another check to ensure the current item is visible (or return to the same scroll position) if(stopload){ return; } //stop right now if(scrollpercent<0){ if(showDetails){ for(int t=0; t<treeWidget->columnCount(); t++){treeWidget->resizeColumnToContents(t); } if(treeWidget->currentItem()!=0){ treeWidget->scrollToItem(treeWidget->currentItem()); } }else{ if(listWidget->currentItem()!=0){ listWidget->scrollToItem(listWidget->currentItem()); } } }else{ if(showDetails){ treeWidget->verticalScrollBar()->setValue( qRound(treeWidget->verticalScrollBar()->maximum()*scrollpercent) ); }else{ listWidget->horizontalScrollBar()->setValue( qRound(listWidget->horizontalScrollBar()->maximum()*scrollpercent) ); } } if(stopload){ return; } //stop right now if(DEBUG){ qDebug() << "Assemble Status Message:" << time.elapsed(); } //Assemble any status message QString stats = QString(tr("Capacity: %1")).arg(LOS::FileSystemCapacity(CDIR)); if(list.length()>0){ stats.prepend("\t"); if(numdirs < list.length()){ //Has Files stats.prepend( QString(tr("Files: %1 (%2)")).arg(QString::number(list.length()-numdirs), LUtils::BytesToDisplaySize(filebytes)) ); } if(numdirs > 0){ //Has Dirs if(numdirs<list.length()){ stats.prepend(" / "); }//has files output already stats.prepend( QString(tr("Dirs: %1")).arg(QString::number(numdirs)) ); } } if(stopload){ return; } //stop right now if(!canmodify){ stats.prepend(tr("(Limited Access) ")); } ui->label_status->setText( stats.simplified() ); if(DEBUG){ qDebug() << "DONE:" << time.elapsed(); } if(showThumbs){ thumbThread = QtConcurrent::run(this, &DirWidget::startLoadThumbs); } }
void Details :: describePlanet() { fileIndex = qBound(0, fileIndex, filesCount() - 1); bool exists = planet != A::Planet_None; positionLabel -> setVisible(exists); aspectsList -> setVisible(exists); powerLabel -> setVisible(exists); if (!exists) return; const A::Planet& p = file(fileIndex)->horoscope().planets[planet]; QString powerText = A::describePowerInHtml(p, file(fileIndex)->horoscope()); if (!powerText.isEmpty()) powerText = "<p align='center'><b><i>" + QString("<font color='#71aeec' size='+2'>+%1</font> | " "<font color='#dfb096' size='+2'>%2</font>") .arg(p.power.dignity) .arg(p.power.deficient) + "</i></b></p>" + powerText; positionLabel -> setText(A::describePlanetCoordInHtml(p)); powerLabel -> setText(powerText); aspectsList->clear(); A::AspectList list; QString tag1, tag2; if (filesCount() == 1) { list = file()->horoscope().aspects; aspects->setTitle(tr("Aspects")); } else { list = calculateSynastryAspects(); aspects->setTitle(tr("Synastry aspects")); tag1 = "#1"; tag2 = "#2"; } foreach (const A::Aspect& asp, list) { if (*asp.planet1 != p && *asp.planet2 != p) continue; QListWidgetItem* item = new QListWidgetItem; item->setIcon(QIcon(asp.d->userData["icon"].toString())); item->setText(A::describeAspect(asp)); item->setToolTip(A::describeAspectFull(asp, tag1, tag2)); item->setStatusTip(QString("%1+%2+%3").arg(asp.d->name) .arg(asp.planet1->name) .arg(asp.planet2->name)); aspectsList->addItem(item); } QListWidgetItem* item = new QListWidgetItem("..."); item->setToolTip(tr("more")); item->setWhatsThis("more"); item->setTextAlignment(Qt::AlignCenter); aspectsList->addItem(item); if (expandedAspects) expandAspects(); else updateListHeight(aspectsList); }