void CompositorHelper::setReticlePosition(const glm::vec2& position, bool sendFakeEvent) { if (isHMD()) { glm::vec2 maxOverlayPosition = _currentDisplayPlugin->getRecommendedUiSize(); // FIXME don't allow negative mouseExtra glm::vec2 mouseExtra = (MOUSE_EXTENTS_PIXELS - maxOverlayPosition) / 2.0f; glm::vec2 minMouse = vec2(0) - mouseExtra; glm::vec2 maxMouse = maxOverlayPosition + mouseExtra; { QMutexLocker locker(&_reticleLock); _reticlePositionInHMD = glm::clamp(position, minMouse, maxMouse); } if (sendFakeEvent) { sendFakeMouseEvent(); } } else { // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies, // remove it after we're done const float REASONABLE_CHANGE = 50.0f; glm::vec2 oldPos = toGlm(QCursor::pos()); auto distance = glm::distance(oldPos, position); if (distance > REASONABLE_CHANGE) { qDebug() << "Contrller::ScriptingInterface ---- UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPos.x << "," << oldPos.y << " newPos:" << position.x << "," << position.y; } QCursor::setPos(position.x, position.y); } }
void CompositorHelper::setReticlePosition(const glm::vec2& position, bool sendFakeEvent) { if (isHMD()) { glm::vec2 maxOverlayPosition = _currentDisplayPlugin->getRecommendedUiSize(); // FIXME don't allow negative mouseExtra glm::vec2 mouseExtra = (MOUSE_EXTENTS_PIXELS - maxOverlayPosition) / 2.0f; glm::vec2 minMouse = vec2(0) - mouseExtra; glm::vec2 maxMouse = maxOverlayPosition + mouseExtra; { QMutexLocker locker(&_reticleLock); _reticlePositionInHMD = glm::clamp(position, minMouse, maxMouse); } if (sendFakeEvent) { sendFakeMouseEvent(); } } else { const QPoint point(position.x, position.y); QCursor::setPos(_renderingWidget->mapToGlobal(point)); } }
void RadialMap::Widget::mousePressEvent( QMouseEvent *e ) { //m_tip is hidden already by event filter //m_focus is set correctly (I've been strict, I assure you it is correct!) enum { Konqueror, Konsole, Center, Open, Copy, Delete }; if (m_focus && !m_focus->isFake()) { const KURL url = Widget::url( m_focus->file() ); const bool isDir = m_focus->file()->isDirectory(); if( e->button() == Qt::RightButton ) { KPopupMenu popup; popup.insertTitle( m_focus->file()->fullPath( m_tree ) ); if (isDir) { popup.insertItem( SmallIconSet( "konqueror" ), i18n( "Open &Konqueror Here" ), Konqueror ); if( url.protocol() == "file" ) popup.insertItem( SmallIconSet( "konsole" ), i18n( "Open &Konsole Here" ), Konsole ); if (m_focus->file() != m_tree) { popup.insertSeparator(); popup.insertItem( SmallIconSet( "viewmag" ), i18n( "&Center Map Here" ), Center ); } } else popup.insertItem( SmallIconSet( "fileopen" ), i18n( "&Open" ), Open ); popup.insertSeparator(); popup.insertItem( SmallIconSet( "editcopy" ), i18n( "&Copy to clipboard" ), Copy ); popup.insertSeparator(); popup.insertItem( SmallIconSet( "editdelete" ), i18n( "&Delete" ), Delete ); switch (popup.exec( e->globalPos(), 1 )) { case Konqueror: //KRun::runCommand will show an error message if there was trouble KRun::runCommand( QString( "kfmclient openURL \"%1\"" ).arg( url.url() ) ); break; case Konsole: // --workdir only works for local file paths KRun::runCommand( QString( "konsole --workdir \"%1\"" ).arg( url.path() ) ); break; case Center: case Open: goto section_two; case Copy: QApplication::clipboard()->setData( new KURLDrag( KURL::List( url ) ) ); break; case Delete: { const KURL url = Widget::url( m_focus->file() ); const QString message = m_focus->file()->isDirectory() ? i18n( "<qt>The directory at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted." ) : i18n( "<qt><i>'%1'</i> will be <b>permanently</b> deleted." ); const int userIntention = KMessageBox::warningContinueCancel( this, message.arg( url.prettyURL() ), QString::null, KGuiItem( i18n("&Delete"), "editdelete" ) ); if (userIntention == KMessageBox::Continue) { KIO::Job *job = KIO::del( url ); job->setWindow( this ); connect( job, SIGNAL(result( KIO::Job* )), SLOT(deleteJobFinished( KIO::Job* )) ); QApplication::setOverrideCursor( KCursor::workingCursor() ); } } default: //ensure m_focus is set for new mouse position sendFakeMouseEvent(); } } else { // not right mouse button section_two: const QRect rect( e->x() - 20, e->y() - 20, 40, 40 ); m_tip->hide(); // user expects this if (!isDir || e->button() == Qt::MidButton) { KIconEffect::visualActivate( this, rect ); new KRun( url, this, true ); //FIXME see above } else if (m_focus->file() != m_tree) { // is left click KIconEffect::visualActivate( this, rect ); emit activated( url ); //activate first, this will cause UI to prepare itself createFromCache( (Directory *)m_focus->file() ); } else emit giveMeTreeFor( url.upURL() ); } } }
void RadialMap::Widget::mousePressEvent(QMouseEvent *e) { //m_tip is hidden already by event filter //m_focus is set correctly (I've been strict, I assure you it is correct!) if (m_focus && !m_focus->isFake()) { const QUrl url = Widget::url(m_focus->file()); const bool isDir = m_focus->file()->isDir(); if (e->button() == Qt::RightButton) { QMenu popup; popup.setTitle(m_focus->file()->fullPath(m_tree)); QAction * actKonq = 0, * actKonsole = 0, *actViewMag = 0, * actFileOpen = 0, * actEditDel = 0; if (isDir) { actKonq = popup.addAction(QIcon::fromTheme("system-file-manager"), i18n("Open File Manager Here")); if (url.scheme() == "file") actKonsole = popup.addAction(QIcon::fromTheme("utilities-terminal"), i18n("Open Terminal Here")); if (m_focus->file() != m_tree) { popup.addSeparator(); actViewMag = popup.addAction(QIcon::fromTheme("zoom-original"), i18n("&Center Map Here")); } } else actFileOpen = popup.addAction(QIcon::fromTheme("document-open"), i18n("&Open")); popup.addSeparator(); actEditDel = popup.addAction(QIcon::fromTheme("edit-delete"), i18n("&Delete")); QAction * result = popup.exec(e->globalPos()); if (result == 0) result = (QAction *) - 1; // sanity if (result == actKonq) //KRun::runCommand will show an error message if there was trouble KRun::runCommand(QString("kfmclient openURL '%1'").arg(url.url()), this); else if (result == actKonsole) KRun::runCommand(QString("konsole --workdir '%1'").arg(url.url()), this); else if (result == actViewMag || result == actFileOpen) goto sectionTwo; else if (result == actEditDel) { const QUrl url = Widget::url(m_focus->file()); const QString message = (m_focus->file()->isDir() ? i18n("<qt>The folder at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted.</qt>", url.toDisplayString()) : i18n("<qt><i>'%1'</i> will be <b>permanently</b> deleted.</qt>", url.toDisplayString())); const int userIntention = KMessageBox::warningContinueCancel(this, message, QString(), KGuiItem(i18n("&Delete"), "edit-delete")); if (userIntention == KMessageBox::Continue) { KIO::Job *job = KIO::del(url); KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate()); ui->setWindow(this); connect(job, SIGNAL(result(KJob*)), SLOT(deleteJobFinished(KJob*))); QApplication::setOverrideCursor(Qt::BusyCursor); } } else //ensure m_focus is set for new mouse position sendFakeMouseEvent(); } else { sectionTwo: const QRect rect(e->x() - 20, e->y() - 20, 40, 40); m_tip.hide(); //user expects this if (!isDir || e->button() == Qt::MidButton) { #if 0 // TODO: PORTME KIconEffect::visualActivate(this, rect); #endif new KRun(url, this, true); //FIXME see above } else if (m_focus->file() != m_tree) { //is left mouse button #if 0 // TODO: PORTME KIconEffect::visualActivate(this, rect); #endif emit activated(url); //activate first, this will cause UI to prepare itself if (m_focus) createFromCache((Directory *)m_focus->file()); } } } }
void RadialMap::Widget::mousePressEvent(QMouseEvent *e) { if (!isEnabled()) return; //m_focus is set correctly (I've been strict, I assure you it is correct!) if (!m_focus || m_focus->isFake()) { return; } const QUrl url = Widget::url(m_focus->file()); const bool isDir = m_focus->file()->isFolder(); // Open file if (e->button() == Qt::MidButton || (e->button() == Qt::LeftButton && !isDir)) { new KRun(url, this, true); return; } if (e->button() == Qt::LeftButton) { if (m_focus->file() != m_tree) { emit activated(url); //activate first, this will cause UI to prepare itself createFromCache((Folder *)m_focus->file()); } else if (KIO::upUrl(url) != url) { emit giveMeTreeFor(KIO::upUrl(url)); } return; } if (e->button() != Qt::RightButton) { // Ignore other mouse buttons return; } // Actions in the right click menu QAction* openFileManager = 0; QAction* openTerminal = 0; QAction* centerMap = 0; QAction* openFile = 0; QAction* copyClipboard = 0; QAction* deleteItem = 0; QMenu popup; popup.setTitle(m_focus->file()->fullPath(m_tree)); if (isDir) { openFileManager = popup.addAction(QIcon::fromTheme(QLatin1String("system-file-manager")), i18n("Open &File Manager Here")); if (url.scheme() == QLatin1String("file")) { openTerminal = popup.addAction(QIcon::fromTheme(QLatin1String( "utilities-terminal" )), i18n("Open &Terminal Here")); } if (m_focus->file() != m_tree) { popup.addSeparator(); centerMap = popup.addAction(QIcon::fromTheme(QLatin1String( "zoom-in" )), i18n("&Center Map Here")); } } else { openFile = popup.addAction(QIcon::fromTheme(QLatin1String("document-open")), i18nc("Scan/open the path of the selected element", "&Open")); } popup.addSeparator(); copyClipboard = popup.addAction(QIcon::fromTheme(QLatin1String( "edit-copy" )), i18n("&Copy to clipboard")); if (m_focus->file() != m_tree) { popup.addSeparator(); deleteItem = popup.addAction(QIcon::fromTheme(QLatin1String( "edit-delete" )), i18n("&Delete")); } QAction* clicked = popup.exec(e->globalPos(), 0); if (openFileManager && clicked == openFileManager) { KRun::runUrl(url, QLatin1String( "inode/directory" ), this); } else if (openTerminal && clicked == openTerminal) { KToolInvocation::invokeTerminal(QString(),url.path()); } else if (centerMap && clicked == centerMap) { emit activated(url); //activate first, this will cause UI to prepare itself createFromCache((Folder *)m_focus->file()); } else if (openFile && clicked == openFile) { new KRun(url, this, true); } else if (clicked == copyClipboard) { QMimeData* mimedata = new QMimeData(); mimedata->setUrls(QList<QUrl>() << url); QApplication::clipboard()->setMimeData(mimedata , QClipboard::Clipboard); } else if (clicked == deleteItem && m_focus->file() != m_tree) { m_toBeDeleted = m_focus; const QUrl url = Widget::url(m_toBeDeleted->file()); const QString message = m_toBeDeleted->file()->isFolder() ? i18n("<qt>The folder at <i>'%1'</i> will be <b>recursively</b> and <b>permanently</b> deleted.</qt>", url.toString()) : i18n("<qt><i>'%1'</i> will be <b>permanently</b> deleted.</qt>", url.toString()); const int userIntention = KMessageBox::warningContinueCancel( this, message, QString(), KGuiItem(i18n("&Delete"), QLatin1String("edit-delete"))); if (userIntention == KMessageBox::Continue) { KIO::Job *job = KIO::del(url); connect(job, &KJob::finished, this, &RadialMap::Widget::deleteJobFinished); QApplication::setOverrideCursor(Qt::BusyCursor); setEnabled(false); } } else { //ensure m_focus is set for new mouse position sendFakeMouseEvent(); } }