summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-04-22 11:14:14 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-04-22 11:14:14 +0200
commitcb782fdc66376041e775f7566c2ab097c246bb53 (patch)
tree462c87d8e9e66701cc4427bb5a343a81aa620141
parentClean up headers && fix compilation with (the upcoming) qt 4.8.2 (diff)
downloadrekonq-cb782fdc66376041e775f7566c2ab097c246bb53.tar.xz
Add fixed favorite icon in the toolbar to let add favorites easier
Also clean up urlbar code, using 2 slots instead of 5(!) to manage bookmarks & favorites
-rw-r--r--src/urlbar/urlbar.cpp143
-rw-r--r--src/urlbar/urlbar.h10
2 files changed, 62 insertions, 91 deletions
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 5e1df8c5..b796224b 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -70,6 +70,8 @@ IconButton::IconButton(QWidget *parent)
setToolButtonStyle(Qt::ToolButtonIconOnly);
setStyleSheet("IconButton { background-color:transparent; border: none; padding: 0px}");
setCursor(Qt::ArrowCursor);
+
+ setContextMenuPolicy(Qt::PreventContextMenu);
}
@@ -363,16 +365,13 @@ void UrlBar::loadFinished()
// Make sure icons aren't duplicated
clearRightIcons();
- // show Favorite Icon
- if (ReKonfig::previewUrls().contains(_tab->url().url()))
- {
- IconButton *bt = addRightIcon(UrlBar::Favorite);
- connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(showFavoriteDialog(QPoint)));
- }
-
// show bookmark info
IconButton *bt = addRightIcon(UrlBar::BK);
- connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(showBookmarkInfo(QPoint)));
+ connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(manageBookmarks(QPoint)));
+
+ // show favorite icon
+ IconButton *fbt = addRightIcon(UrlBar::Favorite);
+ connect(fbt, SIGNAL(clicked(QPoint)), this, SLOT(manageFavorites(QPoint)));
// show KGet downloads??
if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetList())
@@ -417,32 +416,6 @@ void UrlBar::loadFinished()
}
-void UrlBar::showBookmarkDialog()
-{
- showBookmarkInfo(QCursor::pos());
-}
-
-
-void UrlBar::showBookmarkInfo(QPoint pos)
-{
- if (_tab->url().scheme() == QL1S("about"))
- return;
-
- KBookmark bookmark = rApp->bookmarkManager()->bookmarkForUrl(_tab->url());
-
- if (bookmark.isNull())
- {
- bookmark = rApp->bookmarkManager()->owner()->bookmarkCurrentPage();
- }
- else
- {
- BookmarkWidget *widget = new BookmarkWidget(bookmark, window());
-// connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons()));
- widget->showAt(pos);
- }
-}
-
-
void UrlBar::updateRightIcons()
{
if (!_tab->isPageLoading())
@@ -588,8 +561,6 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic)
rightIcon->setIcon(KIcon("bookmarks"));
rightIcon->setToolTip(i18n("Edit this bookmark"));
}
- rightIcon->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(rightIcon, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(bookmarkContextMenu(QPoint)));
break;
case UrlBar::SearchEngine:
{
@@ -603,8 +574,16 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic)
break;
}
case UrlBar::Favorite:
- rightIcon->setIcon(KIcon("emblem-favorite"));
- rightIcon->setToolTip(i18n("Remove from favorite"));
+ if (ReKonfig::previewUrls().contains(_tab->url().url()))
+ {
+ rightIcon->setIcon(KIcon("emblem-favorite"));
+ rightIcon->setToolTip(i18n("Remove from favorite"));
+ }
+ else
+ {
+ rightIcon->setIcon(KIcon("emblem-favorite").pixmap(32, 32, QIcon::Disabled));
+ rightIcon->setToolTip(i18n("Add to favorites"));
+ }
break;
case UrlBar::AdBlock:
rightIcon->setIcon(KIcon("preferences-web-browser-adblock"));
@@ -689,52 +668,68 @@ void UrlBar::refreshFavicon()
}
-void UrlBar::showFavoriteDialog(QPoint pos)
+void UrlBar::pasteAndGo()
{
- if (_tab->url().scheme() == QL1S("about"))
- return;
+ loadRequestedUrl(rApp->clipboard()->text());
+}
- IconButton *bt = qobject_cast<IconButton *>(this->sender());
- if (!bt)
- return;
- FavoriteWidget *widget = new FavoriteWidget(_tab, window());
- connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons()));
- widget->showAt(pos);
+void UrlBar::pasteAndSearch()
+{
+ KService::Ptr defaultEngine = SearchEngine::defaultEngine();
+ if (defaultEngine)
+ loadRequestedUrl(KUrl(SearchEngine::buildQuery(defaultEngine, rApp->clipboard()->text())));
}
-void UrlBar::bookmarkContextMenu(QPoint pos)
+void UrlBar::delSlot()
{
- Q_UNUSED(pos);
+ del();
+}
- KMenu menu(this);
- QAction *qa;
- if (!rApp->bookmarkManager()->bookmarkForUrl(_tab->url()).isNull())
+void UrlBar::manageBookmarks(QPoint pos)
+{
+ IconButton *bt = qobject_cast<IconButton *>(this->sender());
+ if (!bt)
+ return;
+
+ if (_tab->url().scheme() == QL1S("about"))
+ return;
+
+ KBookmark bookmark = rApp->bookmarkManager()->bookmarkForUrl(_tab->url());
+
+ if (bookmark.isNull())
{
- qa = new KAction(KIcon("bookmarks"), i18n("Edit Bookmark"), this);
- connect(qa, SIGNAL(triggered(bool)), this, SLOT(showBookmarkDialog()));
- menu.addAction(qa);
+ bookmark = rApp->bookmarkManager()->owner()->bookmarkCurrentPage();
}
-
- if (!ReKonfig::previewUrls().contains(_tab->url().url()))
+ else
{
- qa = new KAction(KIcon("emblem-favorite"), i18n("Add to favorite"), this);
- connect(qa, SIGNAL(triggered(bool)), this, SLOT(addFavorite()));
- menu.addAction(qa);
+ BookmarkWidget *widget = new BookmarkWidget(bookmark, window());
+ widget->showAt(pos);
}
-
- menu.exec(QCursor::pos());
}
-
-void UrlBar::addFavorite()
+void UrlBar::manageFavorites(QPoint pos)
{
+ IconButton *bt = qobject_cast<IconButton *>(this->sender());
+ if (!bt)
+ return;
+
+ if (_tab->url().scheme() == QL1S("about"))
+ return;
+
if (ReKonfig::previewUrls().contains(_tab->url().url()))
+ {
+ // remove site from favorites
+ FavoriteWidget *widget = new FavoriteWidget(_tab, window());
+ connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons()));
+ widget->showAt(pos);
return;
+ }
+ // else, add as favorite
QStringList urls = ReKonfig::previewUrls();
urls << _tab->url().url();
ReKonfig::setPreviewUrls(urls);
@@ -745,23 +740,3 @@ void UrlBar::addFavorite()
updateRightIcons();
}
-
-
-void UrlBar::pasteAndGo()
-{
- loadRequestedUrl(rApp->clipboard()->text());
-}
-
-
-void UrlBar::pasteAndSearch()
-{
- KService::Ptr defaultEngine = SearchEngine::defaultEngine();
- if (defaultEngine)
- loadRequestedUrl(KUrl(SearchEngine::buildQuery(defaultEngine, rApp->clipboard()->text())));
-}
-
-
-void UrlBar::delSlot()
-{
- del();
-}
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index 7cd79853..6460dae3 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -106,13 +106,9 @@ private Q_SLOTS:
void detectTypedString(const QString &);
void suggest();
- void showBookmarkInfo(QPoint);
- void showBookmarkDialog();
-
- void showFavoriteDialog(QPoint);
- void bookmarkContextMenu(QPoint);
- void addFavorite();
-
+ void manageBookmarks(QPoint);
+ void manageFavorites(QPoint);
+
void refreshFavicon();
void pasteAndGo();