/* ============================================================ * The rekonq project * ============================================================ * SPDX-License-Identifier: GPL-3.0-only * Copyright (C) 2022 aqua * ============================================================ */ #include "bookmarkspanel.hpp" #include "bookmarks/bookmarkstreemodel.hpp" #include BookmarksPanel::BookmarksPanel(QWidget *parent) : QTreeView(parent) { setEditTriggers(QAbstractItemView::NoEditTriggers); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &QTreeView::activated, this, [this](const QModelIndex &index) { open(index); }); connect(this, &QTreeView::customContextMenuRequested, this, &BookmarksPanel::customContextMenu); } BookmarksTreeModel *BookmarksPanel::model() const { auto *m = qobject_cast(QTreeView::model()); Q_CHECK_PTR(m); return m; } void BookmarksPanel::customContextMenu(const QPoint &pos) { const auto index = indexAt(pos); auto *item = model()->item(indexAt(pos)); Q_CHECK_PTR(item); auto *menu = new QMenu(this); menu->addAction(tr("Open in current tab"), this, [this, index]() { open(index); }); menu->addAction(tr("Open in new tab"), this, [this, index]() { open(index, rekonq::NewTab); }); menu->addAction(tr("Edit")); menu->addAction(tr("Remove"), this, [this, index]() { remove(index); }); menu->popup(mapToGlobal(pos)); } void BookmarksPanel::open(const QModelIndex &index, rekonq::OpenType type) { auto *item = model()->item(index); const auto url = item->data(BookmarksTreeItem::Href).toUrl(); emit loadUrl(url, type); } void BookmarksPanel::remove(const QModelIndex &index) { model()->removeRow(index.row(), index.parent()); }