Exemple #1
0
TreeWidget::TreeWidget(QWidget *parent) :
    QTreeWidget(parent)
{
    qRegisterMetaType<QList<QTreeWidgetItem *>>("QTreeWidgetItem");

    connect(this, SIGNAL(itemDropped(QList<QTreeWidgetItem*>)), SLOT(selectItems(QList<QTreeWidgetItem*>)), Qt::QueuedConnection);
}
Exemple #2
0
void VideoDock::dropEvent(QDropEvent *e)
{
	if (e)
	{
		const QMimeData *mimeData = e->mimeData();
		if (Functions::chkMimeData(mimeData))
		{
			const QStringList urls = Functions::getUrlsFromMimeData(mimeData, false);
			if (urls.size() == 1)
			{
				QString url = Functions::Url(urls[0]);
#ifdef Q_OS_WIN
				if (url.startsWith("file://"))
					url.remove(0, 7);
#endif
				if (!QFileInfo(url.mid(7)).isDir())
				{
					bool subtitles = false;
					QString fileExt = Functions::fileExt(url).toLower();
					if (!fileExt.isEmpty() && (fileExt == "ass" || fileExt == "ssa" || SubsDec::extensions().contains(fileExt)))
						subtitles = true;
#ifdef Q_OS_WIN
					if (subtitles && !url.contains("://"))
						url.prepend("file://");
#endif
					emit itemDropped(url, subtitles);
					e->accept();
				}
			}
		}
		QWidget::dropEvent(e);
	}
}
bool WizardEditor::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: okClicked(); break;
    case 1: applyClicked(); break;
    case 2: cancelClicked(); break;
    case 3: helpClicked(); break;
    case 4: addClicked(); break;
    case 5: removeClicked(); break;
    case 6: upClicked(); break;
    case 7: downClicked(); break;
    case 8: itemHighlighted((int)static_QUType_int.get(_o+1)); break;
    case 9: itemSelected((int)static_QUType_int.get(_o+1)); break;
    case 10: itemDragged((QListBoxItem*)static_QUType_ptr.get(_o+1)); break;
    case 11: itemDropped((QListBoxItem*)static_QUType_ptr.get(_o+1)); break;
    default:
	return WizardEditorBase::qt_invoke( _id, _o );
    }
    return TRUE;
}
void Form::dropEvent(QDropEvent *event)
{
	if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist"))
	{
		QTreeWidget *tree = dynamic_cast<QTreeWidget *>(event->source());
		
		
		QByteArray itemData = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
		QDataStream stream(&itemData, QIODevice::ReadOnly);
		
		int r, c;
		QMap<int, QVariant> v;
		stream >> r >> c >> v;
		
		QTreeWidgetItem *item = tree->topLevelItem(r);
		
		if( item )
		{
			itemDropped(item);
		}
	}
Exemple #5
0
void
TableView::dropEvent(QDropEvent* e)
{
    //  QTreeView::dropEvent(e);

    DropIndicatorPosition position = dropIndicatorPosition();

    switch (position) {
    case QAbstractItemView::OnItem:
    case QAbstractItemView::OnViewport:
    default:

        return;

    case QAbstractItemView::AboveItem:
    case QAbstractItemView::BelowItem:
        break;
    }
    TableItem* into = itemAt( e->pos() );

    if ( !into || _imp->draggedItems.empty() ) {
        return;
    }
    Q_EMIT aboutToDrop();
    int targetRow = into->row();

    //We only support full rows
    assert(selectionBehavior() == QAbstractItemView::SelectRows);

    ///Remove the items
    std::map<int, std::map<int, TableItem*> > rowMoved;
    for (std::list<TableItem*>::iterator it = _imp->draggedItems.begin(); it != _imp->draggedItems.end(); ++it) {
        rowMoved[(*it)->row()][(*it)->column()] = *it;
        TableItem* taken = _imp->model->takeItem( (*it)->row(), (*it)->column() );
        assert(taken == *it);
        Q_UNUSED(taken);
    }
    /// remove the rows in reverse order so that indexes are still valid
    for (std::map<int, std::map<int, TableItem*> >::reverse_iterator it = rowMoved.rbegin(); it != rowMoved.rend(); ++it) {
        _imp->model->removeRows(it->first);
        if (it->first <= targetRow) {
            --targetRow;
        }
    }
    _imp->draggedItems.clear();
    ///insert back at the correct position

    int nRows = _imp->model->rowCount();
    switch (position) {
    case QAbstractItemView::AboveItem: {
        _imp->model->insertRows( targetRow, rowMoved.size() );
        break;
    }
    case QAbstractItemView::BelowItem: {
        ++targetRow;
        if (targetRow > nRows) {
            targetRow = nRows;
        }
        _imp->model->insertRows( targetRow, rowMoved.size() );
        break;
    }
    default:
        assert(false);

        return;
    }
    ;

    int rowIndex = targetRow;
    for (std::map<int, std::map<int, TableItem*> >::iterator it = rowMoved.begin(); it != rowMoved.end(); ++it, ++rowIndex) {
        for (std::map<int, TableItem*>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
            _imp->model->setItem(rowIndex, it2->first, it2->second);
        }
    }

    Q_EMIT itemDropped();
} // TableView::dropEvent
Exemple #6
0
 /**
  * This is why we needed to subclass the QTreeWidget class.
  * We needed our own dropEvent for the dragging and dropping
  * of the tree widget items.
  */
 void MosaicTreeWidget::dropEvent(QDropEvent *event) {
   emit itemDropped(event->pos());
 }