Created
January 21, 2012 16:09
-
-
Save nowrep/1653169 to your computer and use it in GitHub Desktop.
Paste&Go action in LocationBar context menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void LocationBar::contextMenuEvent(QContextMenuEvent* event) | |
{ | |
Q_UNUSED(event) | |
if (!m_pasteAndGoAction) { | |
m_pasteAndGoAction = new QAction(QIcon::fromTheme("edit-paste"), tr("Paste And &Go"), this); | |
m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V")); | |
connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo())); | |
} | |
QMenu* tempMenu = createStandardContextMenu(); | |
m_menu->clear(); | |
int i = 0; | |
foreach (QAction* act, tempMenu->actions()) { | |
act->setParent(m_menu); | |
tempMenu->removeAction(act); | |
m_menu->addAction(act); | |
if (i == 5) { | |
m_menu->addAction(m_pasteAndGoAction); | |
} | |
++i; | |
} | |
delete tempMenu; | |
m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty()); | |
//Prevent choosing first option with double rightclick | |
QPoint pos = QCursor::pos(); | |
QPoint p(pos.x(), pos.y() + 1); | |
m_menu->popup(p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment