Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Function: contextMenuEvent()
//-----------------------------------------------------------------------------
void CellEditTableView::contextMenuEvent( QContextMenuEvent* event ) {
    pressedPoint_ = event->pos();

    QModelIndex index = indexAt(pressedPoint_);

    if (index.isValid()) {
        QMenu menu(this);		
        menu.addAction(&copyAction_);
        menu.addAction(&pasteAction_);	
        menu.addAction(&clearAction_);


        QMimeData const* mime = QApplication::clipboard()->mimeData();
        pasteAction_.setEnabled(mime != 0 && mime->hasImage() && mime->imageData().isValid() && model()->data(index,Qt::EditRole).isValid());	

        clearAction_.setEnabled(model()->data(index,Qt::EditRole).isValid());
        menu.exec(event->globalPos());    
    }

    event->accept();
}
Exemplo n.º 2
0
void XTreeView::sShowMenu(const QPoint &pntThis)
{
  QModelIndex item = indexAt(pntThis);
  if (item.isValid())
  {
    _menu->clear();
    emit populateMenu(_menu, item);

    bool disableExport = FALSE;
    if(_x_preferences)
      disableExport = (_x_preferences->value("DisableExportContents")=="t");
    if(!disableExport)
    {
      _menu->addSeparator();
      _menu->addAction(tr("Export Contents..."),  this, SLOT(sExport()));
    }

    if (! _menu->isEmpty())
      _menu->popup(mapToGlobal(pntThis));
  }
}
Exemplo n.º 3
0
void ConfListView::contextMenuEvent(QContextMenuEvent * event)
{
    const QModelIndex &index = indexAt(event->pos());

    QString number = index.sibling(index.row(), ConfListModel::ID).data().toString();
    QString roomName = index.sibling(index.row(), ConfListModel::NAME).data().toString();
    QString roomNumber = index.sibling(index.row(), ConfListModel::NUMBER).data().toString();

    QMenu *menu = new QMenu(this);

    QAction *action = new QAction(
        tr("Get in room %1 (%2)").arg(roomName).arg(roomNumber), menu);

    action->setProperty("number", number);
    connect(action, SIGNAL(triggered(bool)),
	    parentWidget(), SLOT(openConfRoom()));
    connect(action, SIGNAL(triggered(bool)),
	    parentWidget(), SLOT(phoneConfRoom()));

    menu->addAction(action);
    menu->exec(QCursor::pos());
}
Exemplo n.º 4
0
void DirTreeView::dropEvent(QDropEvent *event)
{
    if (event->mimeData()->hasFormat(UrlListMimeData::format()))
    {
        FileSystemSortFilterProxyModel* proxyModel =
                qobject_cast<FileSystemSortFilterProxyModel*>(model());
        QFileSystemModel* dirModel =
                qobject_cast<QFileSystemModel*>(proxyModel->sourceModel());

        emit dropped(UrlListMimeData::listFrom(event->mimeData()),
                     dirModel->filePath(
                         proxyModel->mapToSource(indexAt(event->pos()))),
                     event->dropAction() == Qt::CopyAction);

        event->setDropAction(event->dropAction());
        event->accept();

        return;
    }

    event->ignore();
}
Exemplo n.º 5
0
void TTreeWidget::mouseReleaseEvent( QMouseEvent *event )
{
    QModelIndex indexClicked = indexAt(event->pos());
    if( mIsVarTree && indexClicked.isValid() && mClickedItem == indexClicked )
    {
        QRect vrect = visualRect(indexClicked);
        int itemIndentation = vrect.x() - visualRect(rootIndex()).x();
        QRect rect = QRect(header()->sectionViewportPosition(0) + itemIndentation,
                           vrect.y(), style()->pixelMetric(QStyle::PM_IndicatorWidth), vrect.height());
        if(rect.contains(event->pos()))
        {
            QTreeWidgetItem * clicked = itemFromIndex( indexClicked );
            if ( ! ( clicked->flags()&Qt::ItemIsUserCheckable ) )
                return;
            if ( clicked->checkState( 0 ) == Qt::Unchecked )
            {
                clicked->setCheckState( 0, Qt::Checked );
                //get all children and see what ones we can save
                QList< QTreeWidgetItem * > list;
                getAllChildren( clicked, list );
                QListIterator< QTreeWidgetItem * > it(list);
                LuaInterface * lI = mpHost->getLuaInterface();
                VarUnit * vu = lI->getVarUnit();
                while( it.hasNext() )
                {
                    QTreeWidgetItem * item = it.next();
                    if ( ! vu->shouldSave( item ) )
                        item->setCheckState( 0, Qt::Unchecked );
                }
            }
            else
            {
                clicked->setCheckState( 0, Qt::Unchecked );
            }
            return;
        }
    }
    QTreeWidget::mouseReleaseEvent(event);
}
Exemplo n.º 6
0
void PatternCollection::dropEvent(QDropEvent *event)
{
    if(event->source() == this) {
        // Note: Implement this by hand on Windows, to work around a bug in QT 5.4.1
#if defined Q_OS_WIN
        if(event->mimeData()->formats().at(0) == "application/x-qabstractitemmodeldatalist") {
            QByteArray itemData =
              event->mimeData()->data("application/x-qabstractitemmodeldatalist");
            QDataStream stream(&itemData, QIODevice::ReadOnly);

            int row, column;
            QMap<int, QVariant> v;
            stream >> row >> column >> v;

            // Insert the item in an appropriate place
            QModelIndex dropIndex = indexAt(event->pos());

            if(dropIndex.row() == row) {
                return;
            }

            QListWidgetItem* item = takeItem(row);
            if(dropIndex.row() == -1) {
                addItem(item);
            }
            else {
                int destinationRow = dropIndex.row();

                if(dropIndex.row() > row) {
                    destinationRow--;
                }
                insertItem(destinationRow, item);
            }
            setCurrentItem(item);
        }
#else
        QListWidget::dropEvent(event);
#endif
    }
Exemplo n.º 7
0
    void FocusableListView::mouseMoveEvent(QMouseEvent * _e)
    {
        if (selectByMouseHoverEnabled_)
        {
            const auto index = indexAt(_e->pos());
            if (index.isValid())
            {
                auto sm = selectionModel();
                auto prevSelected = sm->currentIndex();

                {
                    QSignalBlocker sb(sm);
                    sm->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
                }

                if (prevSelected.isValid())
                    model()->dataChanged(prevSelected, prevSelected);
            }
        }

        QListView::mouseMoveEvent(_e);
    }
Exemplo n.º 8
0
void TreePropView::mousePressEvent(QMouseEvent *event)
{
    QModelIndex index = indexAt(event->pos());
    if (index.isValid()&& (event->button() == Qt::LeftButton)) {
        if (index.parent().isValid()) {
            if (!index.column()==0)
                edit(index);
        } else if (!rootIsDecorated()) {
            setExpanded(index,!isExpanded(index));
            if (isExpanded(index))
                model()->setData(index,m_iconOpen,Qt::DecorationRole);
            else
                model()->setData(index,m_iconClosed,Qt::DecorationRole);
        }
        setCurrentIndex(index);
        return;
    }
    if (index.column()==0)
        return;

    QTreeView::mousePressEvent(event);
}
void CCollectionView::dropEvent(QDropEvent *event)
{
	qDebug() << QString("dropEvent");
	const QMimeData* data = event->mimeData();

    if (data && data->hasFormat("application/x-muroa-playlist-diff")) {
        event->setDropAction(Qt::MoveAction);
        event->accept();

        CCollectionModel* plModel = reinterpret_cast<CCollectionModel*>(model());

        CModelDiff md(data->data("application/x-muroa-playlist-diff"));
        QModelIndex currentIdx = indexAt( event->pos());
        md.setInsertPos(currentIdx.row());
        md.setDestination(E_COLLECTION);

        qDebug() << QString("Move [%1,%2] to %3").arg(md.getSelectedIndexes().at(0)).arg(md.getSelectedIndexes().at(md.getNumSelected() - 1 )).arg(md.getInsertPos());

        // plModel->makeDiff(&md);
        m_diffBuilder->diff(md);
    }
}
Exemplo n.º 10
0
void MyTableWidgetAnim::tableContextMenuRequest(QPoint point)
{
    QModelIndex index = indexAt(point);
    int row = index.row();
    int column = index.column();

    QMenu *menu = new QMenu;

    QAction *actionRender = NULL;
    QAction *interpolateForward = NULL;

    if(row == 0)
    {
        actionRender = menu->addAction(tr("Render this frame"));
    }
    else
    {
        if(column < columnCount() - 1)
        {
            interpolateForward = menu->addAction(tr("Interpolate next frames"));
        }
    }

    QAction *selectedItem = menu->exec(viewport()->mapToGlobal(point));

    if (selectedItem)
    {
        if (selectedItem == actionRender)
        {
            gFlightAnimation->RenderFrame(column);
        }
        else if (selectedItem == interpolateForward)
        {
            gFlightAnimation->InterpolateForward(row, column);
        }
    }

    delete menu;
}
Exemplo n.º 11
0
void FavoriteTreeView::contextMenuEvent(QContextMenuEvent *event)
{


    if (indexAt(event->pos()).parent().isValid())
    {
        QMenu menu(this);
        menu.addAction(mRenameAction);
        menu.addAction(mDeleteAction);
        menu.exec(event->globalPos());
    }

    else  {
        QMenu menu(this);
        menu.addAction(mCollapseAction);
        menu.exec(event->globalPos());
    }




}
Exemplo n.º 12
0
void
mail_listview::popup_ctxt_menu_headers(const QPoint& pos)
{
  QModelIndex index = indexAt(pos);
  if (!index.isValid())
    return;
  QMenu* menu = make_header_menu(this);
  QAction* action = menu->exec(mapToGlobal(pos));
  
  if (action!=NULL && action->data().isValid()) {
    int section = action->data().toInt();
    if (action->isChecked()) {
      // show
      header()->showSection(section);
    }
    else {
      header()->hideSection(section);
    }
    compute_visible_sections();
  }
  delete menu;
}
Exemplo n.º 13
0
void QtRosterWidget::mouseMoveEvent(QMouseEvent *event)
 {
	if (!(event->buttons() & Qt::LeftButton)) {
		return;
	}
	if ((event->pos() - dragStartPosition).manhattanLength()< QApplication::startDragDistance()) {
		return;
	}
	clickedIndex=indexAt(event->pos());
	if (!clickedIndex.isValid()) {
		return;
	}
	QDrag *drag = new QDrag(this);
	QMimeData *mimeData = new QMimeData();
	RosterItem* item = static_cast<RosterItem*>(clickedIndex.internalPointer());
	ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
	std::string jid=contact->getJID().toString();
	QString str=QString::P2QSTRING(jid);
	mimeData->setText(str);
	drag->setMimeData(mimeData);
	drag->exec(Qt::CopyAction | Qt::MoveAction);     
 }
void KexiRelationsTableFieldList::dragMoveEvent(QDragMoveEvent* event)
{
    QModelIndex receiver = indexAt(event->pos());
    if (!receiver.isValid() || !KexiFieldDrag::canDecode(event))
        return;
    QString sourceMimeType;
    QString srcTable;
    QStringList srcFields;
    QString srcField;

    if (!KexiFieldDrag::decode(event, sourceMimeType, srcTable, srcFields)) {
        event->ignore();
        return;
    }

    if (sourceMimeType != "kexi/table" && sourceMimeType == "kexi/query") {
        event->ignore();
        return;
    }

    if (srcFields.count() != 1) {
        event->ignore();
        return;
    }

    srcField = srcFields[0];

    if (srcTable == schema()->name()) {
        event->ignore();
        return;
    }

    QString f = model()->data(receiver, Qt::DisplayRole).toString();

    kDebug() << "Source:" << srcTable << "Dest:" << schema()->name();

    if (!srcField.trimmed().startsWith("*") && !f.startsWith("*"))
        event->acceptProposedAction();
}
Exemplo n.º 15
0
bool BookTreeView::viewportEvent(QEvent* event)
{
    if (event->type() == QEvent::ToolTip) {
        QHelpEvent *helpEvent = (QHelpEvent *) event;
        QModelIndex book = indexAt(helpEvent->pos());

        // if it's not a book don't show anything
        if (book.data(CollectionTreeModel::UrlRole).isNull()) {
            return  QTreeView::viewportEvent(event);
        }

        QString location = book.data(CollectionTreeModel::UrlRole).toString();
        QString summary = book.data(CollectionTreeModel::SummaryRole).toString();
        QString cacheKey = book.data(CollectionTreeModel::LargePreviewRole).toString();

        emit dataRequested(location, summary, cacheKey);

        return true;
    } else {
        return QTreeView::viewportEvent(event);
    }
}
Exemplo n.º 16
0
//***********************************************************************************************
//***********************************************************************************************
//***********************************************************************************************
// Mouse Events:
//***********************************************************************************************
void ScatterView::mousePressEvent(QMouseEvent *event)
{
    QWidget::mousePressEvent(event);
    origin = event->pos();

	if(!selection) return;
	int labelval = indexAt(origin);

	Qt::KeyboardModifiers modifiers = event->modifiers();
	if( selMode == 1 )
	{
		selectionRegion.append(origin);
		this->repaint();
	}
	else
	{
		if(modifiers == Qt::ControlModifier && labelval >= 0)
			selection->toggle( labelval );
		else if(modifiers == Qt::NoModifier && labelval >= 0)
			selection->select( labelval );
	}
}
Exemplo n.º 17
0
void ItemViewWidget::dropEvent(QDropEvent *event)
{
	if (m_viewMode == TreeViewMode)
	{
		QTreeView::dropEvent(event);

		return;
	}

	QDropEvent mutableEvent(QPointF((visualRect(m_model->index(0, 0)).x() + 1), event->posF().y()), Qt::MoveAction, event->mimeData(), event->mouseButtons(), event->keyboardModifiers(), event->type());

	QTreeView::dropEvent(&mutableEvent);

	if (!mutableEvent.isAccepted())
	{
		return;
	}

	event->accept();

	m_dropRow = indexAt(event->pos()).row();

	if (m_dragRow <= m_dropRow)
	{
		--m_dropRow;
	}

	if (dropIndicatorPosition() == QAbstractItemView::BelowItem)
	{
		++m_dropRow;
	}

	m_isModified = true;

	emit modified();

	QTimer::singleShot(50, this, SLOT(updateDropSelection()));
}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// Function: ComponentTreeView::contextMenuEvent()
//-----------------------------------------------------------------------------
void ComponentTreeView::contextMenuEvent( QContextMenuEvent* event )
{
	QModelIndex index = indexAt(event->pos());

	if (!index.isValid()) {
		return;
	}
	
	// save the position where click occurred
	pressedPoint_ = event->pos();
    ComponentEditorItem* item = getPressedItem();
	
	// if item can be opened then show the context menu
    QMenu menu(this);

    if (item->canBeOpened())
    {
        menu.addActions(item->actions());
    }
    menu.exec(event->globalPos());

	event->accept();
}
Exemplo n.º 19
0
void ColumnNameView::mousePressEvent(QMouseEvent *press)
{
	QModelIndex atClick = indexAt(press->pos());
	if (!atClick.isValid())
		return;

	QRect indexRect = visualRect(atClick);
	QPixmap pix(indexRect.width(), indexRect.height());
	pix.fill(QColor(0,0,0,0));
	render(&pix, QPoint(0, 0),QRegion(indexRect));

	QDrag *drag = new QDrag(this);
	QMimeData *mimeData = new QMimeData;
	mimeData->setData(subsurface_mimedata, atClick.data().toByteArray());
	model()->removeRow(atClick.row());
	drag->setPixmap(pix);
	drag->setMimeData(mimeData);
	if (drag->exec() == Qt::IgnoreAction){
		model()->insertRow(model()->rowCount());
		QModelIndex idx = model()->index(model()->rowCount()-1, 0);
		model()->setData(idx, mimeData->data(subsurface_mimedata));
	}
}
Exemplo n.º 20
0
void ProposalTreeWidget::contextMenuEvent(QContextMenuEvent * e)
{
	mClickedIndex = indexAt( e->pos() );

	if(!isAddRemoveEnabled())
		return;

	QMenu menu(this);
	menu.addAction(tr("Add Proposal"), this, SLOT(newProposalItem()));
	if(model()->rowCount())
	{
		menu.addAction(tr("Clear"), this, SLOT(onActionClear()));
	}

	if(mClickedIndex.isValid())
	{
		menu.addAction(tr("Remove"), this, SLOT(onActionRemove()));
	}

	menu.raise(); // cover overlay
	menu.exec( mapToGlobal(e->pos()) );

}
Exemplo n.º 21
0
TableView::TableView(QWidget *parent)
	: QTableView(parent)
	, _model(new UniqueLibraryItemModel(this))
	, _jumpToWidget(new JumpToWidget(this))
{
	_model->proxy()->setDynamicSortFilter(false);
	this->setModel(_model->proxy());
	this->setVerticalScrollMode(ScrollPerPixel);
	LibraryScrollBar *vScrollBar = new LibraryScrollBar(this);
	this->setVerticalScrollBar(vScrollBar);
	connect(_jumpToWidget, &JumpToWidget::aboutToScrollTo, this, &TableView::jumpTo);
	connect(_model->proxy(), &UniqueLibraryFilterProxyModel::aboutToHighlightLetters, _jumpToWidget, &JumpToWidget::highlightLetters);
	connect(vScrollBar, &QAbstractSlider::valueChanged, this, [=](int) {
		QModelIndex iTop = indexAt(viewport()->rect().topLeft());
		_jumpToWidget->setCurrentLetter(_model->currentLetter(iTop.sibling(iTop.row(), 1)));
	});
	this->installEventFilter(this);
	horizontalHeader()->resizeSection(0, SettingsPrivate::instance()->coverSize());

	connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &, const QItemSelection &) {
		setDirtyRegion(QRegion(viewport()->rect()));
	});
}
Exemplo n.º 22
0
void HistoryView::contextMenuEvent(QContextMenuEvent* event)
{
    const QModelIndex index = indexAt(event->pos());
    if (!index.isValid() || index.data(HistoryModel::IsTopLevelRole).toBool()) {
        return;
    }

    m_clickedIndex = index;

    QMenu menu;
    menu.addAction(tr("Open link in current tab"), this, SLOT(openLinkInCurrentTab()));
    menu.addAction(tr("Open link in new tab"), this, SLOT(openLinkInNewTab()));
    menu.addSeparator();
    menu.addAction(tr("Copy title"), this, SLOT(copyTitle()));
    menu.addAction(tr("Copy address"), this, SLOT(copyAddress()));
    menu.addSeparator();
    menu.addAction(tr("Remove"), this, SLOT(removeItems()));

    // Prevent choosing first option with double rightclick
    QPoint pos = viewport()->mapToGlobal(event->pos());
    QPoint p(pos.x(), pos.y() + 1);
    menu.exec(p);
}
Exemplo n.º 23
0
void rePropertyTree::mousePressEvent( QMouseEvent *event )
{
	QTreeView::mousePressEvent(event);
	QModelIndex idx = indexAt(event->pos());
	qDebug() << idx.row() << idx.column();
	if ((model()->flags(idx) & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))
	{
		setCurrentIndex(idx);
		edit(idx);
	}
	/*
	if (idx.isValid()) {
		if ((item != m_editorPrivate->editedItem()) && (event->button() == Qt::LeftButton)
			&& (header()->logicalIndexAt(event->pos().x()) == 1)
			&& ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) {
				editItem(item, 1);
		} else if (!m_editorPrivate->hasValue(item) && m_editorPrivate->markPropertiesWithoutValue() && !rootIsDecorated()) {
			if (event->pos().x() + header()->offset() < 20)
				item->setExpanded(!item->isExpanded());
		}
	}
	*/
}
Exemplo n.º 24
0
bool multiView::eventFilter ( QObject* object, QEvent* event )
{
	if ( event->type() == QEvent::MouseButtonRelease )
	{
		QMouseEvent* mouse = static_cast<QMouseEvent*> ( event );
		QModelIndex index = indexAt ( mouse->pos() );

		if ( index.isValid() )
		{
			QModelIndexList selectedList = selectedIndexes();

			for ( int i = 0 ; i < selectedList.size() ; ++i )
			{
				parentMcb->switchCheckstate ( selectedList.at ( i ).row() );
			}
			return true;
		}
	}
	else if ( event->type() == QEvent::KeyPress )
	{
		QKeyEvent* key = static_cast<QKeyEvent*> ( event );

		if ( ( key->key() == Qt::Key_Return ) || ( key->key() == Qt::Key_Enter ) )
		{
			QModelIndexList selectedList = selectedIndexes();

			for ( int i = 0 ; i < selectedList.size() ; ++i )
			{
				parentMcb->switchCheckstate ( selectedList.at ( i ).row() );
			}

			return true;
		}
	}

	return false;
}
Exemplo n.º 25
0
void QInstructionList::mousePressEvent(QMouseEvent* evt) {
	//Get the clicked index
	QModelIndex index = indexAt(evt->pos());

	//if nothing was clicked, just clear the selection
	if(index.isValid()) {
		//get the clicked item
		QTableWidgetItem* item = this->itemAt(evt->pos());
		QTableWidgetItem* tmp = 0;

		//select the clicked index
		selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
		selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);

		//if the item exists, check above and below it for any lines that have the same address
		if(item) {
			for(int i = row(item) - 1; i >= 0; i--) {
				if((tmp = this->item(i, 0)) && tmp->data(32).toInt() == item->data(32).toInt())  {
					selectionModel()->select(indexFromItem(tmp), QItemSelectionModel::Select | QItemSelectionModel::Rows);
				} else {
					break;
				}
			}
			for(int i = row(item) + 1; i < this->rowCount(); i++) {
				if((tmp = this->item(i,0)) && tmp->data(32).toInt() == item->data(32).toInt()) {
					selectionModel()->select(indexFromItem(tmp), QItemSelectionModel::Select | QItemSelectionModel::Rows);
				} else {
					break;
				}
			}

		}
	} else {
		clearSelection();
		selectionModel()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Clear);
	}
}
Exemplo n.º 26
0
bool ItemsTreeView::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == this && event->type() == QEvent::KeyPress
            && currentIndex().isValid()) {
        QKeyEvent *ke = static_cast<QKeyEvent*>(event);
        if ((ke->key() == Qt::Key_Delete
                || ke->key() == Qt::Key_Backspace)
                && ke->modifiers() == 0) {
            emit closeActivated(currentIndex());
        }
    } else if (obj == viewport()
               && event->type() == QEvent::MouseButtonRelease) {
        QMouseEvent * me = static_cast<QMouseEvent*>(event);
        if (me->button() == Qt::MiddleButton
                && me->modifiers() == Qt::NoModifier) {
            QModelIndex index = indexAt(me->pos());
            if (index.isValid()) {
                emit closeActivated(index);
                return true;
            }
        }
    }
    return false;
}
Exemplo n.º 27
0
void FeedsView::contextMenuEvent(QContextMenuEvent *event) {
  const QModelIndex clicked_index = indexAt(event->pos());

  if (clicked_index.isValid()) {
    const QModelIndex mapped_index = model()->mapToSource(clicked_index);
    RootItem *clicked_item = sourceModel()->itemForIndex(mapped_index);

    if (clicked_item->kind() == RootItemKind::Category) {
      // Display context menu for categories.
      initializeContextMenuCategories(clicked_item)->exec(event->globalPos());
    }
    else if (clicked_item->kind() == RootItemKind::Feed) {
      // Display context menu for feeds.
      initializeContextMenuFeeds(clicked_item)->exec(event->globalPos());
    }
    else {
      initializeContextMenuOtherItem(clicked_item)->exec(event->globalPos());
    }
  }
  else {
    // Display menu for empty space.
    initializeContextMenuEmptySpace()->exec(event->globalPos());
  }
}
Exemplo n.º 28
0
void
FirehoseView::mouseMoveEvent( QMouseEvent* event )
{
    if (!(event->buttons() & Qt::LeftButton))
        return;
    
    if ((event->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance())
        return;
       
    QDrag *drag = new QDrag( this );
    QModelIndex i = indexAt( event->pos() );
    PlayableMimeData* mimeData = PlayableMimeData::createFromUser( i.data().toString() );
    mimeData->setImageData( i.data( Qt::DecorationRole ).value<QImage>() );
    
    drag->setMimeData(mimeData);
    
    QPixmap pixmap;
    {
        QImage image( m_itemRects[ i ].size(), QImage::Format_ARGB32_Premultiplied );
        QPainter painter( &image );
        painter.eraseRect( image.rect() );
        QStyleOptionViewItem opt;
        opt.font = font();
        opt.palette = viewport()->palette();
        opt.state = QStyle::State_Active;
        opt.rect = m_itemRects[ i ];
        opt.rect.moveTo( 0, 0 );
        delegate->paint( &painter, opt, i );
        pixmap = QPixmap::fromImage( image );
    }
    drag->setPixmap( pixmap );
    drag->setHotSpot( event->pos() - QPoint( 0, m_itemRects[ i ].top()) );
    
    drag->exec();
    
}
Exemplo n.º 29
0
bool KNMusicTreeViewBase::event(QEvent *event)
{
    if(event->type()==QEvent::ToolTip)
    {
        //Get the help event from the event.
        QHelpEvent *helpEvent=static_cast<QHelpEvent *>(event);
        //Get the right position of the index.
        QPoint indexPosition=QPoint(helpEvent->pos().x(),
                                    helpEvent->pos().y()-header()->height());
        //If the pointer is on the header, hide the detail tooltip.
        if(indexPosition.y()<0)
        {
            KNMusicGlobal::detailTooltip()->hide();
            return false;
        }
        //Locate the index via the position.
        QModelIndex mouseIndex=indexAt(indexPosition);
        if(mouseIndex.isValid())
        {
            if(verticalScrollBar()->isVisible() &&
                    indexPosition.x()>(viewport()->rect().right()-verticalScrollBar()->width()))
            {
                KNMusicGlobal::detailTooltip()->hide();
            }
            else
            {
                KNMusicGlobal::detailTooltip()->setPreviewIndex(m_proxyModel->musicModel(),
                                                                m_proxyModel->mapToSource(mouseIndex),
                                                                helpEvent->globalPos());
                KNMusicGlobal::detailTooltip()->showTooltip();
            }
        }
        return true;
    }
    return QTreeView::event(event);
}
Exemplo n.º 30
0
void ScheduleView::contextMenu(const QPoint & point) {

	QModelIndex index = indexAt(point);
	if (!index.isValid())
		return;

	QMenu menu;
	QAction *action;

	// Find selected dates
	QItemSelectionModel *selection_model = selectionModel();
	QModelIndexList selection = selection_model->selectedIndexes();

	// Single date selected
	if (selection.size() == 1) {
		selected_date = dynamic_cast<CalendarModel*>(model())->date(selection[0]);

		action = menu.addAction(tr("Weekly"));
		connect(action, SIGNAL(triggered()), SLOT(scheduleWeeklyBackup()));

		action = menu.addAction(tr("Once"));
		connect(action, SIGNAL(triggered()), SLOT(scheduleOneBackup()));

		action = menu.addAction(tr("Daily"));
		connect(action, SIGNAL(triggered()), SLOT(scheduleDailyBackup()));

	} else {
//		action = menu.addAction(tr("Once"));
//		connect(action, SIGNAL(triggered()), SLOT(scheduleBackup()));
//
//		action = menu.addAction(tr("Weekly"));
//		connect(action, SIGNAL(triggered()), SLOT(scheduleWeeklyBackup()));
	}

	menu.exec(viewport()->mapToGlobal(point));
}