Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
BookmarksMenu: Load icons only when action is shown
Browse files Browse the repository at this point in the history
See #1679
  • Loading branch information
nowrep committed Dec 11, 2016
1 parent ca3d29d commit d6ff977
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/lib/bookmarks/bookmarksmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "browserwindow.h"
#include "qzsettings.h"
#include "tabwidget.h"
#include "iconprovider.h"

BookmarksMenu::BookmarksMenu(QWidget* parent)
: Menu(parent)
Expand Down Expand Up @@ -78,6 +79,21 @@ void BookmarksMenu::aboutToShow()
}
}

void BookmarksMenu::menuAboutToShow()
{
Q_ASSERT(qobject_cast<Menu*>(sender()));
Menu *menu = static_cast<Menu*>(sender());

foreach (QAction *action, menu->actions()) {
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
IconProvider::imageForUrlAsync(item->url(), action, [=](const QImage &img) {
action->setIcon(QIcon(QPixmap::fromImage(img)));
});
}
}
}

void BookmarksMenu::menuMiddleClicked(Menu* menu)
{
BookmarkItem* item = static_cast<BookmarkItem*>(menu->menuAction()->data().value<void*>());
Expand Down Expand Up @@ -156,6 +172,7 @@ void BookmarksMenu::init()
addSeparator();

connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
connect(this, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
connect(this, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(menuMiddleClicked(Menu*)));
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/bookmarks/bookmarksmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:

void bookmarksChanged();
void aboutToShow();
void menuAboutToShow();
void menuMiddleClicked(Menu* menu);

void bookmarkActivated();
Expand Down
4 changes: 1 addition & 3 deletions src/lib/bookmarks/bookmarkstools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ void BookmarksTools::addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem
QString title = QFontMetrics(m->font()).elidedText(folder->title(), Qt::ElideRight, 250);
m->setTitle(title);
m->setIcon(folder->icon());
QObject::connect(m, SIGNAL(aboutToShow()), receiver, SLOT(menuAboutToShow()));
QObject::connect(m, SIGNAL(menuMiddleClicked(Menu*)), receiver, SLOT(menuMiddleClicked(Menu*)));

QAction* act = menu->addMenu(m);
Expand All @@ -389,9 +390,6 @@ void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* b
Action* act = new Action(menu);
QString title = QFontMetrics(act->font()).elidedText(bookmark->title(), Qt::ElideRight, 250);
act->setText(title);
IconProvider::imageForUrlAsync(bookmark->url(), act, [=](const QImage &img) {
act->setIcon(QIcon(QPixmap::fromImage(img)));
});

act->setData(QVariant::fromValue<void*>(static_cast<void*>(bookmark)));
act->setIconVisibleInMenu(true);
Expand Down

0 comments on commit d6ff977

Please sign in to comment.