Exemple #1
0
/*!
  \e override to activate anchors.
*/
void QTextBrowser::viewportMouseReleaseEvent( QMouseEvent* e )
{
    if ( e->button() == LeftButton ) {
	if ( !d->buttonDown.isEmpty() && anchorAt( e->pos() ) == d->buttonDown ) {
	    setSource( d->buttonDown );
	}
    }
    d->buttonDown = QString::null;
    QTextView::viewportMouseReleaseEvent( e );
}
void OutputWindow::mouseMoveEvent(QMouseEvent *e)
{
    // Cursor was dragged to make a selection, deactivate links
    if (d->mousePressed && textCursor().hasSelection())
        d->linksActive = false;

    if (!d->linksActive || anchorAt(e->pos()).isEmpty())
        viewport()->setCursor(Qt::IBeamCursor);
    else
        viewport()->setCursor(Qt::PointingHandCursor);
    QPlainTextEdit::mouseMoveEvent(e);
}
Exemple #3
0
bool HelpWindow::hasAnchorAt(const QPoint& pos)
{
    lastAnchor = anchorAt(pos);
    if (lastAnchor.isEmpty()) 
        return false;
    lastAnchor = source().resolved(lastAnchor).toString();
    if (lastAnchor.at(0) == QLatin1Char('#')) {
        QString src = source().toString();
        int hsh = src.indexOf(QLatin1Char('#'));
        lastAnchor = (hsh>=0 ? src.left(hsh) : src) + lastAnchor;
    }
    return true;
}
void OutputWindow::mouseReleaseEvent(QMouseEvent *e)
{
    d->mousePressed = false;

    if (d->linksActive) {
        const QString href = anchorAt(e->pos());
        if (d->formatter)
            d->formatter->handleLink(href);
    }

    // Mouse was released, activate links again
    d->linksActive = true;

    QPlainTextEdit::mouseReleaseEvent(e);
}
Exemple #5
0
QMenu *LHMailBrowser::createPopupMenu( const QPoint& pos )
{
	QMenu *m = new QMenu(0);
	QString link = anchorAt( pos );
	if (link.isEmpty())
	{
		delete m;
		//return QTextBrowser::createPopupMenu(pos);
		return 0;
	}
	qDebug()<<"link right click: "<<link<<"\n";

	emit popupForLink(link, m);

	return m;
}
// Copied (with modifications) from QTextBrowser
void PsiTextView::mouseReleaseEvent(QMouseEvent *e)
{
	QTextEdit::mouseReleaseEvent(e);

	if (!(e->button() & Qt::LeftButton))
		return;

	const QString anchor = anchorAt(e->pos());

	if (anchor.isEmpty())
		return;

	if (!textCursor().hasSelection()
		|| (anchor == d->anchorOnMousePress && d->hadSelectionOnMousePress))
		URLObject::getInstance()->popupAction(anchor);
}
void ViewWindow::mouseReleaseEvent ( QMouseEvent * event )
{
	if ( event->button() == Qt::MidButton )
	{
		QString link = anchorAt( event->pos() );

		if ( !link.isEmpty() )
		{
			setTabKeeper( link );
			::mainWindow->onOpenPageInNewBackgroundTab();
			return;
		}
	}

	QWebView::mouseReleaseEvent( event );
}
// Copied (with modifications) from QTextBrowser
void PsiTextView::mousePressEvent(QMouseEvent *e)
{
	d->anchorOnMousePress = anchorAt(e->pos());
	if (!textCursor().hasSelection() && !d->anchorOnMousePress.isEmpty()) {
		QTextCursor cursor = textCursor();
		QPoint mapped = QPoint(e->pos().x() + horizontalScrollBar()->value(),
							   e->pos().y() + verticalScrollBar()->value()); // from QTextEditPrivate::mapToContents
		const int cursorPos = document()->documentLayout()->hitTest(mapped, Qt::FuzzyHit);
		if (cursorPos != -1)
			cursor.setPosition(cursorPos);
		setTextCursor(cursor);
	}

	QTextEdit::mousePressEvent(e);

	d->hadSelectionOnMousePress = textCursor().hasSelection();
}
void ViewWindow::contextMenuEvent(QContextMenuEvent *e)
{
	// From Qt Assistant
	QMenu *m = new QMenu(0);
	QString link = anchorAt( e->pos() );

	if ( !link.isEmpty() )
	{
		m->addAction( i18n("Open Link in a new tab\tShift+LMB"), ::mainWindow, SLOT( onOpenPageInNewTab() ) );
		m->addAction( i18n("Open Link in a new background tab\tCtrl+LMB"), ::mainWindow, SLOT( onOpenPageInNewBackgroundTab() ) );
		m->addSeparator();
		setTabKeeper( link );
	}

	::mainWindow->setupPopupMenu( m );
	m->exec( e->globalPos() );
	delete m;
}
void FLogTextBrowser::contextMenuEvent(QContextMenuEvent *event)
{
	flist_copylink = anchorAt(event->pos());
	QTextCursor cursor = textCursor();
	QMenu *menu = new QMenu;
	QAction *action;
	if(flist_copylink.isEmpty()) {
		//Plain text selected
	} else if(flist_copylink.startsWith(QSL("https://www.f-list.net/c/"))) {
		flist_copyname = flist_copylink.mid(QSL("https://www.f-list.net/c/").length());
		if(flist_copyname.endsWith(QChar('/'))) {
			flist_copyname = flist_copyname.left(flist_copyname.length() - 1);
		}
		menu->addAction(QSL("Open Profile"), this, &FLogTextBrowser::openProfile);
		//todo: Get the list of available sessions. Create a submenu with all available characters if there is more than one (or this session isn't vlaid).
		menu->addAction(QSL("Open PM"), this, &FLogTextBrowser::openPrivateMessage);
		menu->addAction(QSL("Copy Profile Link"), this, &FLogTextBrowser::copyLink);
		menu->addAction(QSL("Copy Name"), this, &FLogTextBrowser::copyName);
		menu->addSeparator();
	} else if(flist_copylink.startsWith(QSL("#AHI-"))) {
		flist_copyname = flist_copylink.mid(5);
		//todo: Get the list of available sessions. Create a submenu with all available characters if there is more than one (or this session isn't vlaid).
		menu->addAction(QSL("Join Channel"), this, &FLogTextBrowser::joinChannel);
		//todo: Maybe get the name the plain text of the link and make that available for copying?
		menu->addAction(QSL("Copy Channel ID"), this, &FLogTextBrowser::copyName);
		menu->addSeparator();
	} else if(flist_copylink.startsWith(QSL("#CSA-"))) {
		flist_copyname = flist_copylink.mid(5);
		//todo: If possible, get which session this actually came from and use that.
		menu->addAction(QSL("Confirm Staff Report"), this, &FLogTextBrowser::confirmReport);
		menu->addAction(QSL("Copy Call ID"), this, &FLogTextBrowser::copyName);
		menu->addSeparator();
	} else {
		menu->addAction(QSL("Copy Link"), this, &FLogTextBrowser::copyLink);
		menu->addSeparator();
	}
	action = menu->addAction(QSL("Copy Selection"), this, &FLogTextBrowser::copy);
	action->setEnabled(cursor.hasSelection());
	menu->addAction(QSL("Select All"), this, &FLogTextBrowser::selectAll);

	menu->exec(event->globalPos());
	delete menu;
}
Exemple #11
0
void HelpViewer::contextMenuEvent(QContextMenuEvent *e)
{
    QMenu menu(QLatin1String(""), 0);

    QUrl link;
    QAction *copyAnchorAction = 0;
    if (hasAnchorAt(e->pos())) {
        link = anchorAt(e->pos());
        if (link.isRelative())
            link = source().resolved(link);
        copyAnchorAction = menu.addAction(tr("Copy &Link Location"));
        copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid());

        menu.addAction(tr("Open Link in New Tab\tCtrl+LMB"), this,
            SLOT(openLinkInNewTab()));
        menu.addSeparator();
    }
    menu.addActions(parentWidget->globalActions());
    QAction *action = menu.exec(e->globalPos());
    if (action == copyAnchorAction)
        QApplication::clipboard()->setText(link.toString());
}
Exemple #12
0
void HelpWindow::contextMenuEvent(QContextMenuEvent *e)
{
    QMenu menu(QLatin1String(""), 0);

    QUrl link;
    QAction *copyAnchorAction = 0;
    if (hasAnchorAt(e->pos())) {
        link = anchorAt(e->pos());
        if (link.isRelative())            
            link = source().resolved(link);
        copyAnchorAction = menu.addAction(tr("Copy &Link Location"));
        copyAnchorAction->setEnabled(!link.isEmpty() && link.isValid());

        menu.addAction(tr("Open Link in New Tab"),
                       this, SLOT(openLinkInNewPage()));
        menu.addAction(tr("Open Link in New Window\tShift+LMB"),
                       this, SLOT(openLinkInNewWindow()));
    }
    mw->setupPopupMenu(&menu);
    QAction *action = menu.exec(e->globalPos());
    if (action == copyAnchorAction)
        QApplication::clipboard()->setText(link.toString());
}
/*!\obsolete
  Returns the anchor at the requested position. The QPainter is needed for font size
  calculations. An empty string is returned if no anchor is specified for this certain
  position.

  This function will be removed in 3.0
*/
QString QSimpleRichText::anchor( QPainter*, const QPoint& pos )
{
    return anchorAt( pos );
}
QMenu *QWidgetTextControl::createStandardContextMenu(const QPointF &pos, QWidget *parent)
{
	Q_D(QWidgetTextControl);

	const bool showTextSelectionActions = d->interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse);

	d->linkToCopy = QString();
	if (!pos.isNull())
		d->linkToCopy = anchorAt(pos);

	if (d->linkToCopy.isEmpty() && !showTextSelectionActions)
		return 0;

	QMenu *menu = new QMenu(parent);
	QAction *a;

	if (d->interactionFlags & Qt::TextEditable) {
		a = menu->addAction(tr("&Undo") + ACCEL_KEY(QKeySequence::Undo), this, SLOT(undo()));
		a->setEnabled(d->doc->isUndoAvailable());
		setActionIcon(a, QStringLiteral("edit-undo"));
		a = menu->addAction(tr("&Redo") + ACCEL_KEY(QKeySequence::Redo), this, SLOT(redo()));
		a->setEnabled(d->doc->isRedoAvailable());
		setActionIcon(a, QStringLiteral("edit-redo"));
		menu->addSeparator();

		a = menu->addAction(tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut), this, SLOT(cut()));
		a->setEnabled(d->cursor.hasSelection());
		setActionIcon(a, QStringLiteral("edit-cut"));
	}

	if (showTextSelectionActions) {
		a = menu->addAction(tr("&Copy") + ACCEL_KEY(QKeySequence::Copy), this, SLOT(copy()));
		a->setEnabled(d->cursor.hasSelection());
		setActionIcon(a, QStringLiteral("edit-copy"));
	}

	if ((d->interactionFlags & Qt::LinksAccessibleByKeyboard)
			|| (d->interactionFlags & Qt::LinksAccessibleByMouse)) {

		a = menu->addAction(tr("Copy &Link Location"), this, SLOT(_q_copyLink()));
		a->setEnabled(!d->linkToCopy.isEmpty());
	}

	if (d->interactionFlags & Qt::TextEditable) {
#if !defined(QT_NO_CLIPBOARD)
		a = menu->addAction(tr("&Paste") + ACCEL_KEY(QKeySequence::Paste), this, SLOT(paste()));
		a->setEnabled(canPaste());
		setActionIcon(a, QStringLiteral("edit-paste"));
#endif
		a = menu->addAction(tr("Delete"), this, SLOT(_q_deleteSelected()));
		a->setEnabled(d->cursor.hasSelection());
		setActionIcon(a, QStringLiteral("edit-delete"));
	}


	if (showTextSelectionActions) {
		menu->addSeparator();
		a = menu->addAction(tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll), this, SLOT(selectAll()));
		a->setEnabled(!d->doc->isEmpty());
	}

	if ((d->interactionFlags & Qt::TextEditable) && qApp->styleHints()->useRtlExtensions()) {
		menu->addSeparator();
		QUnicodeControlCharacterMenu *ctrlCharacterMenu = new QUnicodeControlCharacterMenu(this, menu);
		menu->addMenu(ctrlCharacterMenu);
	}

	return menu;
}
//	WChatLog::QTextEdit::contextMenuEvent()
void
WChatLog::contextMenuEvent(QContextMenuEvent * pEventContextMenu)
	{
	//WTextBrowser::contextMenuEvent(pEvent);
	IEvent * pEventSelected = NULL;

	WMenu oMenu;

	// Find out which event the context menu is for
	const QPoint ptEvent = pEventContextMenu->pos();
	QTextCursor oCursor = cursorForPosition(ptEvent);
	OTextBlockUserDataEvent * pUserData = (OTextBlockUserDataEvent *)oCursor.block().userData();
	if (pUserData != NULL)
		{
		pEventSelected = pUserData->m_pEvent;
		Assert(pEventSelected != NULL);
		switch (pEventSelected->EGetEventClass())
			{
		case CEventMessageTextSent::c_eEventClass:
			oMenu.ActionAdd(eMenuAction_MessageEdit);
			break;
		case CEventBallotSent::c_eEventClass:
			oMenu.ActionAdd(eMenuAction_BallotReSend);
			oMenu.ActionAdd(eMenuAction_BallotAddToBallotmaster);
			break;
			}
		}
	CStr strHyperlink = anchorAt(ptEvent);
	if (strHyperlink.PathUrl_FIsValidHyperlinkNonCambrian())
		oMenu.ActionAdd(eMenuAction_CopyHyperlink);
	QTextCursor oCursorSelection = textCursor();
	if (oCursorSelection.hasSelection())
		oMenu.ActionAdd(eMenuAction_Copy);
	oMenu.ActionAdd(eMenuAction_SelectAll);
	oMenu.ActionAdd(eMenuAction_DebugSendChatLog);

	EMenuAction eMenuAction = oMenu.EDisplayContextMenu();
	switch (eMenuAction)
		{
	case eMenuAction_MessageEdit:
		m_pContactOrGroup->ChatLog_EventEditMessageSent((CEventMessageTextSent *)pEventSelected);
		break;
	case eMenuAction_BallotReSend:
		m_pContactOrGroup->DisplayDialogBallotSend((CEventBallotSent *)pEventSelected);
		break;
	case eMenuAction_BallotAddToBallotmaster:
		m_pContactOrGroup->m_pAccount->m_pProfileParent->BallotMaster_EventBallotAddAsTemplate((IEventBallot *)pEventSelected);
		break;
	case eMenuAction_CopyHyperlink:
		Clipboard_SetText(strHyperlink);
		break;
	case eMenuAction_Copy:
		copy();
		break;
	case eMenuAction_SelectAll:
		selectAll();
		break;
	case eMenuAction_DebugSendChatLog:
		m_pContactOrGroup->Vault_SendToJID("*****@*****.**");
		} // switch

	} // contextMenuEvent()