示例#1
0
TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) {
  // Graphical settings
  setRootIsDecorated(false);
  setAllColumnsShowFocus(true);
  setItemsExpandable(false);
  setSelectionMode(QAbstractItemView::ExtendedSelection);
  // Context menu
  setContextMenuPolicy(Qt::CustomContextMenu);
  connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
  // Set header
  QStringList header;
  header << "#";
  header << tr("URL");
  header << tr("Status");
  header << tr("Peers");
  header << tr("Message");
  setHeaderItem(new QTreeWidgetItem(header));
  dht_item = new QTreeWidgetItem(QStringList() << "" << "** [DHT] **");
  insertTopLevelItem(0, dht_item);
  setRowColor(0, QColor("grey"));
  pex_item = new QTreeWidgetItem(QStringList() << "" << "** [PeX] **");
  insertTopLevelItem(1, pex_item);
  setRowColor(1, QColor("grey"));
  lsd_item = new QTreeWidgetItem(QStringList() << "" << "** [LSD] **");
  insertTopLevelItem(2, lsd_item);
  setRowColor(2, QColor("grey"));
  editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
  connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
  deleteHotkey = new QShortcut(QKeySequence(QKeySequence::Delete), this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut);
  copyHotkey = new QShortcut(QKeySequence(Qt::ControlModifier + Qt::Key_C), this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut);

  loadSettings();
}
示例#2
0
void ItemBoxTreeWidget::addCategory(const Category &cat, int index)
{
//    if (cat.itemCount() == 0)
//        return;

    const bool isScratchPad = cat.type() == Category::Scratchpad;
    ItemBoxCategoryListView *categoryView = 0;
    QTreeWidgetItem *cat_item = 0;

    if (isScratchPad) {
        const int idx = ensureScratchpad();
        categoryView = categoryViewAt(idx);
        cat_item = topLevelItem(idx);
    } else {
        const int existingIndex = indexOfCategory(cat.id());
        if (existingIndex == -1) {
            cat_item = new QTreeWidgetItem();
            cat_item->setData(0, Qt::UserRole, QVariant(cat.id()));
            cat_item->setText(0, cat.name());
            setTopLevelRole(NORMAL_ITEM, cat_item);
            // insert before scratchpad
            const int scratchPadIndex = indexOfScratchpad();
            if (scratchPadIndex == -1) {
                if(index == -1) {
                    addTopLevelItem(cat_item);
                } else {
                    insertTopLevelItem(index, cat_item);
                }

            } else {
                insertTopLevelItem(scratchPadIndex, cat_item);
            }
            setItemExpanded(cat_item, true);
            categoryView = addCategoryView(cat_item, m_iconMode);
        } else {
            categoryView = categoryViewAt(existingIndex);
            cat_item = topLevelItem(existingIndex);
        }
    }
    // The same categories are read from the file $HOME, avoid duplicates
    const int widgetCount = cat.itemCount();
    for (int i = 0; i < widgetCount; ++i) {
        const Item w = cat.item(i);
        if (!categoryView->containsItem(w.name())) {
            categoryView->addItem(w, w.icon(), isScratchPad);
        }
    }
    adjustSubListSize(cat_item);

}
示例#3
0
bool MenuBarTree::dropMimeData(QTreeWidgetItem * parent, int index, const QMimeData * data, Qt::DropAction action)
{

	if (data->hasText())
	{
		QString txt = data->text();
		QTreeWidgetItem* item;
		if (txt == "separator")
			item = new MenuBarSeparatorItem(0);
		else
		{
			QAction * act = CommandManager::instance()->getAction(txt.toStdString().c_str());
			if (!act) return false;
			item = new MenuBarCommandItem(0, act);
		}


		if (parent)
			parent->insertChild(index, item);
		else
			insertTopLevelItem(index, item);


		return true;

	}

	return false;

}
示例#4
0
void VDirectoryTree::updateItemDirectChildren(QTreeWidgetItem *p_item)
{
    QPointer<VDirectory> parentDir;
    if (p_item) {
        parentDir = getVDirectory(p_item);
    } else {
        parentDir = m_notebook->getRootDir();
    }

    const QVector<VDirectory *> &dirs = parentDir->getSubDirs();

    QHash<VDirectory *, QTreeWidgetItem *> itemDirMap;
    int nrChild = p_item ? p_item->childCount() : topLevelItemCount();
    for (int i = 0; i < nrChild; ++i) {
        QTreeWidgetItem *item = p_item ? p_item->child(i) : topLevelItem(i);
        itemDirMap.insert(getVDirectory(item), item);
    }

    for (int i = 0; i < dirs.size(); ++i) {
        VDirectory *dir = dirs[i];
        QTreeWidgetItem *item = itemDirMap.value(dir, NULL);
        if (item) {
            if (p_item) {
                p_item->removeChild(item);
                p_item->insertChild(i, item);
            } else {
                int topIdx = indexOfTopLevelItem(item);
                takeTopLevelItem(topIdx);
                insertTopLevelItem(i, item);
            }

            itemDirMap.remove(dir);
        } else {
            // Insert a new item
            if (p_item) {
                item = new QTreeWidgetItem(p_item);
            } else {
                item = new QTreeWidgetItem(this);
            }

            fillTreeItem(item, dir);
            buildSubTree(item, 1);
        }

        expandSubTree(item);
    }

    // Delete items without corresponding VDirectory
    for (auto iter = itemDirMap.begin(); iter != itemDirMap.end(); ++iter) {
        QTreeWidgetItem *item = iter.value();
        if (p_item) {
            p_item->removeChild(item);
        } else {
            int topIdx = indexOfTopLevelItem(item);
            takeTopLevelItem(topIdx);
        }

        delete item;
    }
}
示例#5
0
void IfcTreeWidget::slotModelLoadingDone()
{
	std::set<int> set_visited;
	shared_ptr<IfcProject> project = m_system->getGeometryConverter()->getIfcPPModel()->getIfcProject();
	if( project )
	{
		
		QTreeWidgetItem* project_item = resolveTreeItems( project, set_visited );
		if( project_item != NULL )
		{
			m_block_selection_signals = true;
			blockSignals(true);
			insertTopLevelItem( 0, project_item );
			setCurrentItem( project_item );
			blockSignals(false);
			m_block_selection_signals = false;
		}
	}

	QTreeWidgetItem* item_outside = new QTreeWidgetItem();
	item_outside->setText( 0, "OutsideSpatialStructure" );

	boost::unordered_map<int,shared_ptr<IfcPPObject> >&	map_outside = m_system->getGeometryConverter()->getObjectsOutsideSpatialStructure();
	for( auto it = map_outside.begin(); it != map_outside.end(); ++it )
	{
		shared_ptr<IfcPPObject>& ifc_object = it->second;
		QTreeWidgetItem* object_item = resolveTreeItems( ifc_object, set_visited );
		if( object_item != NULL )
		{
			blockSignals(true);
			item_outside->addChild( object_item );
			blockSignals(false);
		}
	}

	if( map_outside.size() > 0 )
	{
		m_block_selection_signals = true;
		blockSignals( true );
		insertTopLevelItem( topLevelItemCount(), item_outside );
		setCurrentItem( item_outside );
		blockSignals( false );
		m_block_selection_signals = false;
	}
}
/**
 * inserts a gallery into Tree Widget
 * \param gallery gallery we are inserting, needed to create widget data
 * \param parent parent widget to which we are adding, default NULL
 */
MTreeWidgetItem* MTreeWidget::insert(mcore::MGallery* gallery, MTreeWidgetItem* parent)
{
    // creates a new widget item based on gallery data
    MTreeWidgetItem* item = new MTreeWidgetItem(this, gallery);
    parent ? parent->addChild(item) : insertTopLevelItem(0, item);

    sortItems(0, Qt::AscendingOrder); // sort in alphabetical order

    return item;
}
示例#7
0
TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) {
  // Graphical settings
  setRootIsDecorated(false);
  setAllColumnsShowFocus(true);
  setItemsExpandable(false);
  setSelectionMode(QAbstractItemView::ExtendedSelection);
  // Context menu
  setContextMenuPolicy(Qt::CustomContextMenu);
  connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
  // Set header
  QStringList header;
  header << "#";
  header << tr("URL");
  header << tr("Status");
  header << tr("Received");
  header << tr("Seeds");
  header << tr("Peers");
  header << tr("Downloaded");
  header << tr("Message");
  setHeaderItem(new QTreeWidgetItem(header));
  dht_item = new QTreeWidgetItem({ "",  "** [DHT] **", "", "0", "", "", "0" });
  insertTopLevelItem(0, dht_item);
  setRowColor(0, QColor("grey"));
  pex_item = new QTreeWidgetItem({ "",  "** [PeX] **", "", "0", "", "", "0" });
  insertTopLevelItem(1, pex_item);
  setRowColor(1, QColor("grey"));
  lsd_item = new QTreeWidgetItem({ "",  "** [LSD] **", "", "0", "", "", "0" });
  insertTopLevelItem(2, lsd_item);
  setRowColor(2, QColor("grey"));
  editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
  connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
  deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut);
  copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut);

    // This hack fixes reordering of first column with Qt5.
    // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
    QTableView unused;
    unused.setVerticalHeader(this->header());
    this->header()->setParent(this);
    unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));

  loadSettings();
}
示例#8
0
void MenuBarTree::insertMenu()
{
	QTreeWidgetItem* item = currentItem();
	QString title = tr("New Menu");
	MenuBarSubmenuItem * insItem = new MenuBarSubmenuItem(0, title);
	if (!item)
		addTopLevelItem(insItem);
	else if (indexOfTopLevelItem(item) >= 0)
		insertTopLevelItem(indexOfTopLevelItem(item), insItem);
	else
		item->parent()->insertChild(item->parent()->indexOfChild(item), insItem);
}
示例#9
0
void BookMarks::reloadBookmarks() {
    clear();
    QSetIterator<QString> it(Settings::bookmarkPaths);
    while (it.hasNext()) {
        QString itemPath = it.next();
        QTreeWidgetItem *item = new QTreeWidgetItem(this);
        item->setText(0, QFileInfo(itemPath).fileName());
        item->setIcon(0, QIcon(":/images/bookmarks.png"));
        item->setToolTip(0, itemPath);
        insertTopLevelItem(0, item);
    }
}
示例#10
0
void TrackerList::moveSelectionUp() {
  BitTorrent::TorrentHandle *const torrent = properties->getCurrentTorrent();
  if (!torrent) {
    clear();
    return;
  }
  QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
  if (selected_items.isEmpty()) return;
  bool change = false;
  foreach (QTreeWidgetItem *item, selected_items) {
    int index = indexOfTopLevelItem(item);
    if (index > NB_STICKY_ITEM) {
      insertTopLevelItem(index-1, takeTopLevelItem(index));
      change = true;
    }
  }
QTreeWidgetItem *CollectionTreeWidget::addArtist(QString artist, unsigned int id) {
    if (id == 0) {
        QSqlTableModel *model = service->artistModel();

        // SQLite uses two single quotes to escape a single quote! :)
        QString filter = "name = '" + QString(artist).replace("'","''") + "'";
        model->setFilter(filter);
        model->select();

        while (model->canFetchMore()) model->fetchMore();
        int total = model->rowCount();
        if (total > 0) {
            id = model->record(0).value(model->fieldIndex("id")).toInt();
        }
        else {
            qDebug("ERROR: no artist found! -- " + model->filter().toUtf8());
            return NULL;
        }
    }

    QList<QTreeWidgetItem*> artistList = findItems(artist, Qt::MatchExactly, 0);
    if (artistList.isEmpty()) {
        CollectionTreeWidgetItem *item = new CollectionTreeWidgetItem(LevelArtist, id, (QTreeWidget*)0);
        item->setText(0, artist);
        item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);

        // Set font to bold
        QFont font = item->font(0);
        font.setBold(true);
        item->setFont(0, font);

        // Set icon
        item->setIcon(0, IconFactory::fromTheme("folder"));

        // Insert item
        insertTopLevelItem(0, item);
        sortItems(0, Qt::AscendingOrder);

        return item;
    }
    else {
        return artistList.first();
    }
}
示例#12
0
query_lvitem*
query_listview::create_branch_current(const tag_node* root)
{
  // Current messages (not archived)
  m_item_current = new query_lvitem(tr("Current messages"));
  insertTopLevelItem(index_branch_current, m_item_current);

  m_item_current_all = new query_lvitem(m_item_current, query_lvitem::nonproc_all, tr("All"));

  make_item_current_tags(root);
  m_item_current_prio = new query_lvitem(m_item_current, query_lvitem::current_prio, tr("Prioritized"));

  m_item_current_untagged = new query_lvitem(m_item_current, query_lvitem::nonproc_not_tagged, QString::null);
  update_tag_current_counter(0); // update counts of Current->[Not tagged] branch


  m_item_current->setExpanded(true);
  return m_item_current;
}
示例#13
0
QcTreeWidget::ItemPtr QcTreeWidget::insertItem (
  const QcTreeWidget::ItemPtr & parent, int index, const QVariantList & varList )
{
  int itemCount = topLevelItemCount();
  if( index < 0 || index > itemCount ) return ItemPtr();

  QStringList strings;
  for( int i = 0; i < varList.count(); ++i )
    strings << varList[i].toString();

  Item *item = new Item( strings );
  if( !parent ) insertTopLevelItem( index, item );
  else parent->insertChild( index, item );

  if( !item->treeWidget() ) {
    delete item;
    return ItemPtr();
  }

  return item->safePtr();
}
示例#14
0
文件: tabtree.cpp 项目: rygwdn/CopyQ
void TabTree::insertTab(const QString &path, int index, bool selected)
{
    QStringList pathComponents = path.split('/');
    QTreeWidgetItem *item = findLastTreeItem(*this, &pathComponents);

    foreach (const QString &text, pathComponents) {
        QTreeWidgetItem *parent = item;

        if (parent != NULL) {
            int to = 0;
            for ( ; to < parent->childCount(); ++to ) {
                 const int index2 = getTabIndex(parent->child(to));
                 if (index2 != -1 && index < index2)
                     break;
            }
            int from = parent->childCount();
            item = new QTreeWidgetItem(parent);
            if (from != to)
                parent->insertChild(to, parent->takeChild(from));
        } else {
            int to = 0;
            for ( ; to < topLevelItemCount(); ++to ) {
                 const int index2 = getTabIndex(topLevelItem(to));
                 if (index2 != -1 && index < index2)
                     break;
            }
            int from = topLevelItemCount();
            item = new QTreeWidgetItem(this);
            if (from != to)
                insertTopLevelItem(to, takeTopLevelItem(from));
        }

        item->setExpanded(true);
        item->setData(0, DataIndex, -1);
        item->setData(0, DataText, text);

        labelItem(item);
    }
void KeepassGroupView::dropEvent( QDropEvent * event ){
	if(LastHoverItem){
		LastHoverItem->setBackgroundColor(0,QApplication::palette().color(QPalette::Base));
		LastHoverItem->setForeground(0,QBrush(QApplication::palette().color(QPalette::Text)));
	}
	
	if(DragType==EntryDrag){
		entryDropEvent(event);
		return;
	}

	if(InsLinePos!=-1){
		int RemoveLine=InsLinePos;
		InsLinePos=-1;
		viewport()->update(QRegion(0,RemoveLine-2,viewport()->width(),4));
	}
	GroupViewItem* Item=(GroupViewItem*)itemAt(event->pos());
	
	if(!Item){
		qDebug("Append at the end");
		db->moveGroup(DragItem->GroupHandle,NULL,-1);
		if(DragItem->parent()){
			DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
		}
		else{
			takeTopLevelItem(indexOfTopLevelItem(DragItem));
		}
		insertTopLevelItem(topLevelItemCount(),DragItem);
		if(topLevelItemCount()>1){
			if(topLevelItem(topLevelItemCount()-2)==SearchResultItem){
				takeTopLevelItem(topLevelItemCount()-2);
				insertTopLevelItem(topLevelItemCount(),SearchResultItem);	
			}			
		}
		emit fileModified();
	}
	else{
		if (DragItem->GroupHandle==Item->GroupHandle)
			return;
		
		QRect ItemRect=visualItemRect(Item);
		if(event->pos().y()>ItemRect.y()+2 && event->pos().y()<ItemRect.y()+ItemRect.height()-2){
			qDebug("Append as child of '%s'",((char*)Item->text(0).toUtf8().data()));
			db->moveGroup(DragItem->GroupHandle,Item->GroupHandle,-1);
			if(DragItem->parent()){
				DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
			}
			else{
				takeTopLevelItem(indexOfTopLevelItem(DragItem));
			}
			Item->insertChild(Item->childCount(),DragItem);
			emit fileModified();
		}
		else{
			if(event->pos().y()>ItemRect.y()+2){
				qDebug("Insert behind sibling '%s'",((char*)Item->text(0).toUtf8().data()));
				if(DragItem->parent()){
					DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
				}
				else{
					takeTopLevelItem(indexOfTopLevelItem(DragItem));
				}				
				if(Item->parent()){
					int index=Item->parent()->indexOfChild(Item)+1;
					db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index);
					Item->parent()->insertChild(index,DragItem);
				}
				else{
					int index=indexOfTopLevelItem(Item)+1;
					db->moveGroup(DragItem->GroupHandle,NULL,index);
					insertTopLevelItem(index,DragItem);	
				}
				emit fileModified();
			}
			else{	
				qDebug("Insert before sibling '%s'",((char*)Item->text(0).toUtf8().data()));
				if(DragItem->parent()){
					DragItem->parent()->takeChild(DragItem->parent()->indexOfChild(DragItem));
				}
				else{
					takeTopLevelItem(indexOfTopLevelItem(DragItem));
				}				
				if(Item->parent()){
					int index=Item->parent()->indexOfChild(Item);
					db->moveGroup(DragItem->GroupHandle,((GroupViewItem*)Item->parent())->GroupHandle,index);
					Item->parent()->insertChild(index,DragItem);
				}
				else{
					int index=indexOfTopLevelItem(Item);
					db->moveGroup(DragItem->GroupHandle,NULL,index);
					insertTopLevelItem(index,DragItem);	
				}
				emit fileModified();	
			}
		}
		
		
	}
	
}
示例#16
0
TrackerList::TrackerList(PropertiesWidget *properties)
    : QTreeWidget()
    , m_properties(properties)
{
    // Set header
    // Must be set before calling loadSettings() otherwise the header is reset on restart
    setHeaderLabels(headerLabels());
    // Load settings
    loadSettings();
    // Graphical settings
    setRootIsDecorated(false);
    setAllColumnsShowFocus(true);
    setItemsExpandable(false);
    setSelectionMode(QAbstractItemView::ExtendedSelection);
    header()->setStretchLastSection(false); // Must be set after loadSettings() in order to work
    // Ensure that at least one column is visible at all times
    if (visibleColumnsCount() == 0)
        setColumnHidden(COL_URL, false);
    // To also mitigate the above issue, we have to resize each column when
    // its size is 0, because explicitly 'showing' the column isn't enough
    // in the above scenario.
    for (unsigned int i = 0; i < COL_COUNT; ++i)
        if ((columnWidth(i) <= 0) && !isColumnHidden(i))
            resizeColumnToContents(i);
    // Context menu
    setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
    // Header context menu
    header()->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&)));
    // Set DHT, PeX, LSD items
    m_DHTItem = new QTreeWidgetItem({ "",  "** [DHT] **", "", "0", "", "", "0" });
    insertTopLevelItem(0, m_DHTItem);
    setRowColor(0, QColor("grey"));
    m_PEXItem = new QTreeWidgetItem({ "",  "** [PeX] **", "", "0", "", "", "0" });
    insertTopLevelItem(1, m_PEXItem);
    setRowColor(1, QColor("grey"));
    m_LSDItem = new QTreeWidgetItem({ "",  "** [LSD] **", "", "0", "", "", "0" });
    insertTopLevelItem(2, m_LSDItem);
    setRowColor(2, QColor("grey"));
    // Set static items alignment
    m_DHTItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
    m_PEXItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
    m_LSDItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
    m_DHTItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
    m_PEXItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
    m_LSDItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
    m_DHTItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
    m_PEXItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
    m_LSDItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
    m_DHTItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
    m_PEXItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
    m_LSDItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
    // Set header alignment
    headerItem()->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter));
    headerItem()->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
    headerItem()->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
    headerItem()->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
    headerItem()->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
    // Set hotkeys
    m_editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
    connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
    m_deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut);
    m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut);

    // This hack fixes reordering of first column with Qt5.
    // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
    QTableView unused;
    unused.setVerticalHeader(header());
    header()->setParent(this);
    unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
}
示例#17
0
void EffectsListWidget::initList(QMenu *effectsMenu, KActionCategory *effectActions, QString categoryFile, bool transitionMode)
{
    QString current;
    QString currentFolder;
    bool found = false;
    effectsMenu->clear();

    if (currentItem()) {
        current = currentItem()->text(0);
        if (currentItem()->parent())
            currentFolder = currentItem()->parent()->text(0);
        else if (currentItem()->data(0, TypeRole) == EffectsList::EFFECT_FOLDER)
            currentFolder = currentItem()->text(0);
    }

    QTreeWidgetItem *misc = NULL;
    QTreeWidgetItem *audio = NULL;
    QTreeWidgetItem *custom = NULL;
    QList <QTreeWidgetItem *> folders;

    if (!categoryFile.isEmpty()) {
        QDomDocument doc;
        QFile file(categoryFile);
        doc.setContent(&file, false);
        file.close();
        QStringList folderNames;
        QDomNodeList groups = doc.documentElement().elementsByTagName(QStringLiteral("group"));
        for (int i = 0; i < groups.count(); ++i) {
            folderNames << i18n(groups.at(i).firstChild().firstChild().nodeValue().toUtf8().constData());
        }
        for (int i = 0; i < topLevelItemCount(); ++i) {
            topLevelItem(i)->takeChildren();
            QString currentName = topLevelItem(i)->text(0);
            if (currentName != i18n("Misc") && currentName != i18n("Audio") && currentName != i18nc("Folder Name", "Custom") && !folderNames.contains(currentName)) {
                takeTopLevelItem(i);
                --i;
            }
        }

        for (int i = 0; i < groups.count(); ++i) {
            QTreeWidgetItem *item = findFolder(folderNames.at(i));
            if (item) {
                item->setData(0, IdRole, groups.at(i).toElement().attribute(QStringLiteral("list")));
            } else {
                item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(folderNames.at(i)));
                item->setData(0, TypeRole, QString::number((int) EffectsList::EFFECT_FOLDER));
                item->setData(0, IdRole, groups.at(i).toElement().attribute(QStringLiteral("list")));
                item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
                item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
                insertTopLevelItem(0, item);
            }
            folders.append(item);
        }

        misc = findFolder(i18n("Misc"));
        if (misc == NULL) {
            misc = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18n("Misc")));
            misc->setData(0, TypeRole, QString::number((int) EffectsList::EFFECT_FOLDER));
            misc->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            insertTopLevelItem(0, misc);
        }

        audio = findFolder(i18n("Audio"));
        if (audio == NULL) {
            audio = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18n("Audio")));
            audio->setData(0, TypeRole, QString::number((int) EffectsList::EFFECT_FOLDER));
            audio->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            insertTopLevelItem(0, audio);
        }

        custom = findFolder(i18nc("Folder Name", "Custom"));
        if (custom == NULL) {
            custom = new QTreeWidgetItem((QTreeWidget*)0, QStringList(i18nc("Folder Name", "Custom")));
            custom->setData(0, TypeRole, QString::number((int) EffectsList::EFFECT_FOLDER));
            custom->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            insertTopLevelItem(0, custom);
        }
    }

    //insertTopLevelItems(0, folders);
    if (transitionMode) {
        loadEffects(&MainWindow::transitions, misc, &folders, EffectsList::TRANSITION_TYPE, current, &found);
    }
    else {
        loadEffects(&MainWindow::videoEffects, misc, &folders, EffectsList::EFFECT_VIDEO, current, &found);
        loadEffects(&MainWindow::audioEffects, audio, &folders, EffectsList::EFFECT_AUDIO, current, &found);
        loadEffects(&MainWindow::customEffects, custom, static_cast<QList<QTreeWidgetItem *> *>(0), EffectsList::EFFECT_CUSTOM, current, &found);
        if (!found && !currentFolder.isEmpty()) {
            // previously selected effect was removed, focus on its parent folder
            for (int i = 0; i < topLevelItemCount(); ++i) {
                if (topLevelItem(i)->text(0) == currentFolder) {
                    setCurrentItem(topLevelItem(i));
                    break;
                }
            }
        }
    }
    setSortingEnabled(true);
    sortByColumn(0, Qt::AscendingOrder);

    // populate effects menu
    QMenu *sub1 = NULL;
    QMenu *sub2 = NULL;
    QMenu *sub3 = NULL;
    QMenu *sub4 = NULL;
    for (int i = 0; i < topLevelItemCount(); ++i) {
        if (topLevelItem(i)->data(0, TypeRole) == EffectsList::TRANSITION_TYPE) {
            QTreeWidgetItem *item = topLevelItem(i);
            QAction *a = new QAction(item->icon(0), item->text(0), effectsMenu);
            QStringList data = item->data(0, IdRole).toStringList();
            QString id = data.at(1);
            if (id.isEmpty()) id = data.at(0);
            a->setData(data);
            a->setIconVisibleInMenu(false);
            effectsMenu->addAction(a);
            effectActions->addAction("transition_" + id, a);
            continue;
        }
        if (!topLevelItem(i)->childCount())
            continue;
        QMenu *sub = new QMenu(topLevelItem(i)->text(0), effectsMenu);
        effectsMenu->addMenu(sub);
        int effectsInCategory = topLevelItem(i)->childCount();
        bool hasSubCategories = false;
        if (effectsInCategory > 60) {
            // create subcategories if there are too many effects
            hasSubCategories = true;
            sub1 = new QMenu(i18nc("menu name for effects names between these 2 letters", "0 - F"), sub);
            sub->addMenu(sub1);
            sub2 = new QMenu(i18nc("menu name for effects names between these 2 letters", "G - L"), sub);
            sub->addMenu(sub2);
            sub3 = new QMenu(i18nc("menu name for effects names between these 2 letters", "M - R"), sub);
            sub->addMenu(sub3);
            sub4 = new QMenu(i18nc("menu name for effects names between these 2 letters", "S - Z"), sub);
            sub->addMenu(sub4);
        }
        for (int j = 0; j < effectsInCategory; ++j) {
            QTreeWidgetItem *item = topLevelItem(i)->child(j);
            QAction *a = new QAction(item->icon(0), item->text(0), sub);
            QStringList data = item->data(0, IdRole).toStringList();
            QString id = data.at(1);
            if (id.isEmpty()) id = data.at(0);
            a->setData(data);
            a->setIconVisibleInMenu(false);
            if (hasSubCategories) {
                // put action in sub category
                QRegExp rx("^[s-z].+");
                if (rx.exactMatch(item->text(0).toLower())) {
                    sub4->addAction(a);
                } else {
                    rx.setPattern(QStringLiteral("^[m-r].+"));
                    if (rx.exactMatch(item->text(0).toLower())) {
                        sub3->addAction(a);
                    }
                    else {
                        rx.setPattern(QStringLiteral("^[g-l].+"));
                        if (rx.exactMatch(item->text(0).toLower())) {
                            sub2->addAction(a);
                        }
                        else sub1->addAction(a);
                    }
                }
            }
            else sub->addAction(a);
            effectActions->addAction("video_effect_" + id, a);
        }
    }
}