本文整理汇总了C++中QDragEnterEvent类的典型用法代码示例。如果您正苦于以下问题:C++ QDragEnterEvent类的具体用法?C++ QDragEnterEvent怎么用?C++ QDragEnterEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDragEnterEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool FormFile::eventFilter(QObject *watched, QEvent *event)
{
if(watched == ui->lvServer)
{
if(event->type() == QEvent::DragEnter)
{
QDragEnterEvent* dee = dynamic_cast<QDragEnterEvent*>(event);
dee->acceptProposedAction();
return true;
}
else if(event->type() == QEvent::Drop)
{
QDropEvent* de = dynamic_cast<QDropEvent*>(event);
QList<QUrl>urls = de->mimeData()->urls();
if(urls.isEmpty())
{
return true;
}
QString path = urls.first().toLocalFile();
//上传文件
updateFile(path, path.split("/").last());
return true;
}
}
return QWidget::eventFilter(watched, event);
}
示例2: switch
bool DockedMdiArea::event(QEvent *event)
{
// Listen for desktop file manager drop and emit a signal once a file is
// dropped.
switch (event->type()) {
case QEvent::DragEnter: {
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
if (!uiFiles(e->mimeData()).empty()) {
e->acceptProposedAction();
return true;
}
}
break;
case QEvent::Drop: {
QDropEvent *e = static_cast<QDropEvent*>(event);
const QStringList files = uiFiles(e->mimeData());
const QStringList::const_iterator cend = files.constEnd();
for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it) {
emit fileDropped(*it);
}
e->acceptProposedAction();
return true;
}
break;
default:
break;
}
return QMdiArea::event(event);
}
示例3: eventFilter
// Eventfilter: Only needed under Windows.
// Without this, files dropped in the line edit have URL-encoding.
// This eventfilter decodes the filenames as needed by KDiff3.
bool OpenDialog::eventFilter(QObject* o, QEvent* e)
{
if ( e->type()==QEvent::DragEnter )
{
QDragEnterEvent* d = static_cast<QDragEnterEvent*>(e);
d->setAccepted( d->mimeData()->hasUrls() );
return true;
}
if (e->type()==QEvent::Drop)
{
QDropEvent* d = static_cast<QDropEvent*>(e);
if ( !d->mimeData()->hasUrls() )
return false;
QList<QUrl> lst = d->mimeData()->urls();
if ( lst.count() > 0 )
{
static_cast<QLineEdit*>(o)->setText( QDir::toNativeSeparators( lst[0].toLocalFile() ) );
static_cast<QLineEdit*>(o)->setFocus();
}
return true;
}
return false;
}
示例4: mousePressEvent
bool QDesignerToolBar::eventFilter( QObject *o, QEvent *e )
{
if ( !o || !e || o->inherits( "QDockWindowHandle" ) || o->inherits( "QDockWindowTitleBar" ) )
return QToolBar::eventFilter( o, e );
if ( o == this && e->type() == QEvent::MouseButtonPress &&
( ( QMouseEvent*)e )->button() == LeftButton ) {
mousePressEvent( (QMouseEvent*)e );
return TRUE;
}
if ( o == this )
return QToolBar::eventFilter( o, e );
if ( e->type() == QEvent::MouseButtonPress ) {
QMouseEvent *ke = (QMouseEvent*)e;
fixObject( o );
if ( !o )
return FALSE;
buttonMousePressEvent( ke, o );
return TRUE;
} else if(e->type() == QEvent::ContextMenu ) {
QContextMenuEvent *ce = (QContextMenuEvent*)e;
fixObject( o );
if( !o )
return FALSE;
buttonContextMenuEvent( ce, o );
return TRUE;
} else if ( e->type() == QEvent::MouseMove ) {
QMouseEvent *ke = (QMouseEvent*)e;
fixObject( o );
if ( !o )
return FALSE;
buttonMouseMoveEvent( ke, o );
return TRUE;
} else if ( e->type() == QEvent::MouseButtonRelease ) {
QMouseEvent *ke = (QMouseEvent*)e;
fixObject( o );
if ( !o )
return FALSE;
buttonMouseReleaseEvent( ke, o );
return TRUE;
} else if ( e->type() == QEvent::DragEnter ) {
QDragEnterEvent *de = (QDragEnterEvent*)e;
if ( de->provides( "application/x-designer-actions" ) ||
de->provides( "application/x-designer-actiongroup" ) ||
de->provides( "application/x-designer-separator" ) )
de->accept();
} else if ( e->type() == QEvent::DragMove ) {
QDragMoveEvent *de = (QDragMoveEvent*)e;
if ( de->provides( "application/x-designer-actions" ) ||
de->provides( "application/x-designer-actiongroup" ) ||
de->provides( "application/x-designer-separator" ) )
de->accept();
}
return QToolBar::eventFilter( o, e );
}
示例5: if
bool CloudView::eventFilter(QObject *obj, QEvent *event)
{
if (obj == mHeader) {
static QPoint oldPos;
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *ev = (QMouseEvent *)event;
oldPos = ev->globalPos();
return true;
} else if (event->type() == QEvent::MouseMove) {
QMouseEvent *ev = (QMouseEvent *)event;
const QPoint delta = ev->globalPos() - oldPos;
MainWindow *win = seafApplet->mainWindow();
win->move(win->x() + delta.x(), win->y() + delta.y());
oldPos = ev->globalPos();
return true;
}
} else if (obj == mDropArea) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent *ev = (QDragEnterEvent *)event;
if (ev->mimeData()->hasUrls() && ev->mimeData()->urls().size() == 1) {
const QUrl url = ev->mimeData()->urls().at(0);
if (url.scheme() == "file") {
QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
path = utils::mac::fix_file_id_url(path);
#endif
if (QFileInfo(path).isDir()) {
ev->acceptProposedAction();
}
}
}
return true;
} else if (event->type() == QEvent::Drop) {
QDropEvent *ev = (QDropEvent *)event;
const QUrl url = ev->mimeData()->urls().at(0);
QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
path = utils::mac::fix_file_id_url(path);
#endif
ev->setDropAction(Qt::CopyAction);
ev->accept();
showCreateRepoDialog(path);
return true;
}
}
return QWidget::eventFilter(obj, event);
}
示例6: eventFilter
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::DragEnter)
{
QDragEnterEvent *dragEvent = (QDragEnterEvent*)event;
// accept only folders
QList<QUrl> urls = dragEvent->mimeData()->urls();
for (const QUrl url: urls)
{
if (url.isLocalFile())
{
QFileInfo info(url.toLocalFile());
if (info.isFile())
{
return false;
}
}
}
dragEvent->setDropAction(Qt::LinkAction);
dragEvent->acceptProposedAction();
return true;
}
else if (event->type() == QEvent::Drop)
{
QList<QUrl> urls = ((QDropEvent*)event)->mimeData()->urls();
QStringList files;
for (const QUrl url: urls)
{
if (url.isLocalFile())
{
QFileInfo info(url.toLocalFile());
if (info.isFile())
files.append(url.toLocalFile());
else if (info.isDir())
filesList->addFolder(info.absoluteFilePath());
}
}
filesList->addFiles(files);
return true;
}
return QMainWindow::eventFilter(object, event);
}
示例7: eventFilter
bool KDMUsersWidget::eventFilter( QObject *, QEvent *e )
{
if (e->type() == QEvent::DragEnter) {
QDragEnterEvent *ee = (QDragEnterEvent *)e;
ee->setAccepted( K3URLDrag::canDecode( ee ) );
return true;
}
if (e->type() == QEvent::Drop) {
userButtonDropEvent( (QDropEvent *)e );
return true;
}
return false;
}
示例8: switch
bool ContextHelp::eventFilter( QObject * watched, QEvent * e )
{
// kDebug() << k_funcinfo << "watched="<<watched<<endl;
if ( (watched != m_pEditor) && (watched != m_pEditor->editorViewport()) )
return false;
switch ( e->type() )
{
case QEvent::DragEnter:
{
QDragEnterEvent * dragEnter = static_cast<QDragEnterEvent*>(e);
if ( !QString( dragEnter->format() ).startsWith("ktechlab/") )
break;
dragEnter->acceptAction();
return true;
}
case QEvent::Drop:
{
QDropEvent * dropEvent = static_cast<QDropEvent*>(e);
if ( !QString( dropEvent->format() ).startsWith("ktechlab/") )
break;
dropEvent->accept();
QString type;
QDataStream stream( dropEvent->encodedData( dropEvent->format() ) /*, IO_ReadOnly */ );
stream >> type;
LibraryItem * li = itemLibrary()->libraryItem( type );
if ( !li )
return true;
m_pEditor->insertURL( "ktechlab-help:///" + type, li->name() );
return true;
}
default:
break;
}
return false;
}
示例9: if
bool CloudView::eventFilter(QObject *obj, QEvent *event)
{
if (obj == mHeader) {
static QPoint oldPos;
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *ev = (QMouseEvent *)event;
oldPos = ev->globalPos();
return true;
} else if (event->type() == QEvent::MouseMove) {
QMouseEvent *ev = (QMouseEvent *)event;
const QPoint delta = ev->globalPos() - oldPos;
MainWindow *win = seafApplet->mainWindow();
win->move(win->x() + delta.x(), win->y() + delta.y());
oldPos = ev->globalPos();
return true;
}
} else if (obj == mDropArea) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent *ev = (QDragEnterEvent *)event;
if (ev->mimeData()->hasUrls() && ev->mimeData()->urls().size() == 1) {
const QUrl url = ev->mimeData()->urls().at(0);
if (url.isLocalFile()) {
QString path = url.toLocalFile();
if (QFileInfo(path).isDir()) {
ev->acceptProposedAction();
}
}
}
return true;
} else if (event->type() == QEvent::Drop) {
QDropEvent *ev = (QDropEvent *)event;
const QUrl url = ev->mimeData()->urls().at(0);
QString path = url.toLocalFile();
showCreateRepoDialog(path);
return true;
}
}
return QWidget::eventFilter(obj, event);
}
示例10: indexAt
bool SessionListWidget::event(QEvent *event)
{
#ifndef QUTIM_MOBILE_UI
if (event->type() == QEvent::ToolTip) {
if (QHelpEvent *help = static_cast<QHelpEvent*>(event)) {
int index = indexAt(help->pos()).row();
if (index != -1) {
ChatUnit *unit = session(index)->getUnit();
ToolTip::instance()->showText(help->globalPos(), unit, this);
return true;
}
}
} else if (event->type() == QEvent::DragEnter) {
QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
if (const MimeObjectData *data = qobject_cast<const MimeObjectData*>(dragEvent->mimeData())) {
ChatUnit *u = qobject_cast<ChatUnit*>(data->object());
if (u)
dragEvent->acceptProposedAction();
}
return true;
} else if (event->type() == QEvent::Drop) {
QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
if (const MimeObjectData *mimeData
= qobject_cast<const MimeObjectData*>(dropEvent->mimeData())) {
if (ChatUnit *u = qobject_cast<ChatUnit*>(mimeData->object())) {
ChatLayerImpl::get(u,true)->activate();
dropEvent->setDropAction(Qt::CopyAction);
dropEvent->accept();
return true;
}
}
} else
#endif
if (event->type() == QEvent::ContextMenu) {
QContextMenuEvent *ev = static_cast<QContextMenuEvent*>(event);
ChatSessionImpl *s = session(row(itemAt(ev->pos())));
if(s) {
s->unit()->showMenu(ev->globalPos());
return true;
}
}
return QListWidget::event(event);
}
示例11: switch
bool EditTagDialog::eventFilter(QObject* o, QEvent* e) {
if (o == ui_->art) {
switch (e->type()) {
case QEvent::MouseButtonRelease:
cover_menu_->popup(static_cast<QMouseEvent*>(e)->globalPos());
break;
case QEvent::DragEnter: {
QDragEnterEvent* event = static_cast<QDragEnterEvent*>(e);
if (AlbumCoverChoiceController::CanAcceptDrag(event)) {
event->acceptProposedAction();
}
break;
}
case QEvent::Drop: {
const QDropEvent* event = static_cast<QDropEvent*>(e);
const QModelIndexList sel =
ui_->song_list->selectionModel()->selectedIndexes();
Song* song = GetFirstSelected();
const QString cover =
album_cover_choice_controller_->SaveCover(song, event);
if (!cover.isEmpty()) {
UpdateCoverOf(*song, sel, cover);
}
break;
}
default:
break;
}
}
return false;
}
示例12: eventFilter
bool ClassSpaceChecker::eventFilter(QObject *object, QEvent *evt)
{
if(evt->type() == QEvent::FocusOut)
{
if(object == ui.tableWidgetResult)
{
ui.lineEdit_Result->setText(prevTotalResultStr_);
}
return QMainWindow::eventFilter(object, evt);
}
if(object == ui.comboBox_JarFile
|| object == ui.lineEdit_MapFile
)
{
if(evt->type() == QEvent::DragEnter)
{
QDragEnterEvent *e = (QDragEnterEvent*)evt;
const QMimeData *mimeData = e->mimeData();
if (mimeData->hasUrls())
{
int cnt = 0;
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size(); ++i)
{
QString path = urlList.at(i).toLocalFile();
if( !QFileInfo(path).isFile() )
continue;
if(path.indexOf(".jar", 0, Qt::CaseInsensitive) < 0
&& path.indexOf(".zip", 0, Qt::CaseInsensitive) < 0
&& path.indexOf(".txt", 0, Qt::CaseInsensitive) < 0
)
continue;
if(urlList.size() == 1)
{
if(object == ui.comboBox_JarFile)
{
if(path.indexOf(".jar", 0, Qt::CaseInsensitive) < 0
&& path.indexOf(".zip", 0, Qt::CaseInsensitive) < 0
)
continue;
}
else if(object == ui.lineEdit_MapFile)
{
if(path.indexOf(".txt", 0, Qt::CaseInsensitive) < 0)
continue;
}
}
cnt++;
}
if( cnt > 0 )
e->acceptProposedAction();
}
qDebug() << evt << mimeData->text();
}
else if(evt->type() == QEvent::DragLeave)
{
QDragLeaveEvent *e = (QDragLeaveEvent*)evt;
e->accept();
}
else if(evt->type() == QEvent::DragMove)
{
QDragMoveEvent *e = (QDragMoveEvent*)evt;
e->acceptProposedAction();
}
else if(evt->type() == QEvent::Drop)
{
QDropEvent *e = (QDropEvent*)evt;
const QMimeData* mimeData = e->mimeData();
if (mimeData->hasUrls())
{
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size(); ++i)
{
QString path = urlList.at(i).toLocalFile();
if(path.indexOf(".txt", 0, Qt::CaseInsensitive) >= 0)
ui.lineEdit_MapFile->setText(path);
if(path.indexOf(".jar", 0, Qt::CaseInsensitive) >= 0 || path.indexOf(".zip", 0, Qt::CaseInsensitive) >= 0)
{
checkAndJarFilePreset(path);
}
}
}
}
}
return QMainWindow::eventFilter(object, evt);
}
示例13: app
bool
PlayerWidget::eventFilter(QObject *object, QEvent *event)
{
if(object == m_layeredWidget) {
if(event->type() == QEvent::DragEnter) {
QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent *>(event);
KUrl::List urls = KUrl::List::fromMimeData(dragEnterEvent->mimeData());
if(!urls.isEmpty())
dragEnterEvent->accept();
else
dragEnterEvent->ignore();
return true;
} else if(event->type() == QEvent::DragMove) {
return true; // eat event
} else if(event->type() == QEvent::Drop) {
QDropEvent *dropEvent = static_cast<QDropEvent *>(event);
KUrl::List urls = KUrl::List::fromMimeData(dropEvent->mimeData());
if(!urls.isEmpty()) {
for(KUrl::List::ConstIterator it = urls.begin(), end = urls.end(); it != end; ++it) {
const KUrl &url = *it;
if(url.protocol() != "file")
continue;
app()->openVideo(url);
break;
}
}
return true; // eat event
} else if(event->type() == QEvent::KeyPress) {
// NOTE: when on full screen mode, the keyboard input is received but
// for some reason it doesn't trigger the correct actions automatically
// so we process the event and handle the issue ourselves.
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
return app()->triggerAction(QKeySequence((keyEvent->modifiers() & ~Qt::KeypadModifier) + keyEvent->key()));
} else if(event->type() == QEvent::MouseMove) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(mouseEvent->globalPos() != m_currentCursorPos) {
m_currentCursorPos = mouseEvent->globalPos();
if(m_layeredWidget->cursor().shape() == Qt::BlankCursor)
m_layeredWidget->unsetCursor();
if(m_fullScreenControls->isAttached())
m_fullScreenControls->toggleVisible(true);
}
}
} else if(object == m_infoControlsGroupBox || object->parent() == m_infoControlsGroupBox) {
if(event->type() != QEvent::MouseButtonRelease)
return QWidget::eventFilter(object, event);
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if(mouseEvent->button() != Qt::RightButton)
return QWidget::eventFilter(object, event);
KMenu menu;
QAction *action = menu.addAction(i18n("Show editable position control"));
action->setCheckable(true);
action->setChecked(app()->playerConfig()->showPositionTimeEdit());
if(menu.exec(mouseEvent->globalPos()) == action)
app()->playerConfig()->toggleShowPositionTimeEdit();
return true; // eat event
}
return QWidget::eventFilter(object, event);
}
示例14: switch
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type())
{
case QEvent::KeyRelease:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
//int mask = Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier;
//if(keyEvent->modifiers() == mask)
//{
//}
break;
}
case QEvent::DragEnter:
{
QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent*>(event);
const QMimeData* mimeData = dragEnterEvent->mimeData();
// check for our needed mime type, here a file or a list of files
if (!mimeData->hasUrls())
break;
QList<QUrl> urlList = mimeData->urls();
for (int i = 0; i < urlList.size(); ++i)
{
qDebug() << urlList.at(i).toString();
if (urlList.at(i).toString().endsWith(".torrent"))
{
dragEnterEvent->acceptProposedAction();
return true;
}
}
break;
}
case QEvent::Drop:
{
QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
const QMimeData* mimeData = dropEvent->mimeData();
// check for our needed mime type, here a file or a list of files
if (!mimeData->hasUrls())
break;
QStringList pathList;
QList<QUrl> urlList = mimeData->urls();
// extract the local paths of the files
for (int i = 0; i < urlList.size(); ++i)
{
pathList.append(urlList.at(i).toLocalFile());
}
//addTorrents(pathList);
return true;
}
default:
break;
}
return QObject::eventFilter(watched, event);
}
示例15: eventFilter
bool HashBox::eventFilter(QObject* object, QEvent* event)
{
if (object == dropWidget) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent* dragEnterEvent = static_cast<QDragEnterEvent*>(event);
if (dragEnterEvent) {
/* print out mimeType */
showFormats("HashBox::dragEnterEvent", dragEnterEvent->mimeData()->formats());
if (dragEnterEvent->mimeData()->hasUrls()) {
std::cerr << "HashBox::dragEnterEvent() Accepting Urls" << std::endl;
dragEnterEvent->acceptProposedAction();
} else {
std::cerr << "HashBox::dragEnterEvent() No Urls" << std::endl;
}
}
} else if (event->type() == QEvent::Drop) {
QDropEvent* dropEvent = static_cast<QDropEvent*>(event);
if (dropEvent) {
if (Qt::CopyAction & dropEvent->possibleActions()) {
/* print out mimeType */
showFormats("HashBox::dropEvent", dropEvent->mimeData()->formats());
QStringList files;
if (dropEvent->mimeData()->hasUrls()) {
std::cerr << "HashBox::dropEvent() Urls:" << std::endl;
QList<QUrl> urls = dropEvent->mimeData()->urls();
QList<QUrl>::iterator uit;
for (uit = urls.begin(); uit != urls.end(); ++uit) {
QString localpath = uit->toLocalFile();
std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
std::cerr << "or As Local File: " << localpath.toStdString() << std::endl;
if (localpath.isEmpty() == false) {
//Check that the file does exist and is not a directory
QDir dir(localpath);
if (dir.exists()) {
std::cerr << "HashBox::dropEvent() directory not accepted." << std::endl;
QMessageBox mb(tr("Drop file error."), tr("Directory can't be dropped, only files are accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
mb.exec();
} else if (QFile::exists(localpath)) {
files.push_back(localpath);
} else {
std::cerr << "HashBox::dropEvent() file does not exists."<< std::endl;
QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
mb.exec();
}
}
}
}
addAttachments(files,mDefaultTransferFlags);
dropEvent->setDropAction(Qt::CopyAction);
dropEvent->accept();
} else {
std::cerr << "HashBox::dropEvent() Rejecting uncopyable DropAction" << std::endl;
}
}
}
}
// pass the event on to the parent class
return QScrollArea::eventFilter(object, event);
}