From 653a13aa80ed888c34eb4370d12db253b209ecb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Tr=C3=B6scher?= Date: Mon, 22 Aug 2011 15:43:51 +0200 Subject: custom contextMenu for urlBar provides a custom contextMenu for urlbar and ads "paste & go" action. i'll provide a "edit-searchEngines" action later. REVIEW: 102383 REVIEWED-BY: adjam modified: src/urlbar/urlbar.cpp modified: src/urlbar/urlbar.h --- src/urlbar/urlbar.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/urlbar/urlbar.h | 4 ++++ 2 files changed, 60 insertions(+) (limited to 'src/urlbar') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 17ba4bb9..04d96983 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -58,6 +58,7 @@ #include #include #include +#include @@ -460,6 +461,49 @@ void UrlBar::mouseDoubleClickEvent(QMouseEvent *event) } +void UrlBar::contextMenuEvent(QContextMenuEvent* event) +{ + KMenu menu; + const bool clipboardFilled = !rApp->clipboard()->text().isEmpty(); + + // Cut + KAction *a = KStandardAction::cut(this, SLOT(cut()), this); + a->setEnabled(hasSelectedText()); + menu.addAction(a); + + // Copy + a = KStandardAction::copy(this, SLOT(copy()), this); + a->setEnabled(hasSelectedText()); + menu.addAction(a); + + // Paste + a = KStandardAction::paste(this, SLOT(paste()), this); + a->setEnabled(clipboardFilled); + menu.addAction(a); + + // Paste & Go + a = new KAction(i18n("Paste && Go"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(pasteAndGo())); + a->setEnabled(clipboardFilled); + menu.addAction(a); + + // Delete + a = new KAction(KIcon("edit-delete"), i18n("Delete"), this); + connect(a, SIGNAL(triggered(bool)), this, SLOT(delSlot())); + a->setEnabled(hasSelectedText()); + menu.addAction(a); + + menu.addSeparator(); + + // Select All + a = KStandardAction::selectAll(this, SLOT(selectAll()), this); + a->setEnabled(!text().isEmpty()); + menu.addAction(a); + + menu.exec(event->globalPos()); +} + + IconButton *UrlBar::addRightIcon(UrlBar::icon ic) { IconButton *rightIcon = new IconButton(this); @@ -644,3 +688,15 @@ void UrlBar::addFavorite() updateRightIcons(); } + + +void UrlBar::pasteAndGo() +{ + activated(rApp->clipboard()->text()); +} + + +void UrlBar::delSlot() +{ + del(); +} diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 58e9b5fb..7059725b 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -115,12 +115,16 @@ private Q_SLOTS: void refreshFavicon(); + void pasteAndGo(); + void delSlot(); + protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); void focusInEvent(QFocusEvent *event); void dropEvent(QDropEvent *event); void mouseDoubleClickEvent(QMouseEvent *); + void contextMenuEvent(QContextMenuEvent *event); void resizeEvent(QResizeEvent *); private: -- cgit v1.2.1