From 4dd3dc3f39f462e437447f4816abbae2bea2f359 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Thu, 23 Sep 2021 14:16:49 -0600 Subject: [PATCH] Improve UI for Bookmarks sidebar page buttons Currently there are two tiny icons-only buttons with very similar icons (which may even be identical in some icon themes). One of them is checkable, and the other one triggers an immediate action. And there is lots of unused space to the right of them. This commit overhauls them in the following way: - The toggle button becomes a checkbox with visible text, and is inverted; now when checked, it shows all bookmarks - The checkbox moves above the view and search field, to communicate that it affects everything below it - The button to add a bookmark gets some visible text This should make the UI much clearer, at the cost of one extra line of vertical space from the bookmarks list. --- part/bookmarklist.cpp | 47 ++++++++++++++++++++----------------------- part/bookmarklist.h | 7 ++++--- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/part/bookmarklist.cpp b/part/bookmarklist.cpp index a106c6f0f..1788c2e51 100644 --- a/part/bookmarklist.cpp +++ b/part/bookmarklist.cpp @@ -8,13 +8,14 @@ // qt/kde includes #include +#include #include #include #include #include #include #include -#include +#include #include #include @@ -128,6 +129,12 @@ BookmarkList::BookmarkList(Okular::Document *document, QAction *addBookmarkActio titleWidget->setText(i18n("Bookmarks")); mainlay->addWidget(titleWidget); mainlay->setAlignment(titleWidget, Qt::AlignHCenter); + + m_showForAllDocumentsCheckbox = new QCheckBox(i18n("Show for all documents"), this); + m_showForAllDocumentsCheckbox->setChecked(true); // this setting isn't saved + connect(m_showForAllDocumentsCheckbox, &QCheckBox::toggled, this, &BookmarkList::slotShowAllBookmarks); + mainlay->addWidget(m_showForAllDocumentsCheckbox); + m_searchLine = new KTreeWidgetSearchLine(this); mainlay->addWidget(m_searchLine); m_searchLine->setPlaceholderText(i18n("Search...")); @@ -149,25 +156,15 @@ BookmarkList::BookmarkList(Okular::Document *document, QAction *addBookmarkActio connect(m_tree, &QTreeWidget::customContextMenuRequested, this, &BookmarkList::slotContextMenu); m_searchLine->addTreeWidget(m_tree); - QToolBar *bookmarkController = new QToolBar(this); - mainlay->addWidget(bookmarkController); - bookmarkController->setObjectName(QStringLiteral("BookmarkControlBar")); - // change toolbar appearance - bookmarkController->setIconSize(QSize(16, 16)); - bookmarkController->setMovable(false); - QSizePolicy sp = bookmarkController->sizePolicy(); - sp.setVerticalPolicy(QSizePolicy::Minimum); - bookmarkController->setSizePolicy(sp); - // insert a togglebutton [show only bookmarks in the current document] - m_showBoomarkOnlyAction = bookmarkController->addAction(QIcon::fromTheme(QStringLiteral("bookmarks")), i18n("Current document only")); - m_showBoomarkOnlyAction->setCheckable(true); - connect(m_showBoomarkOnlyAction, &QAction::toggled, this, &BookmarkList::slotFilterBookmarks); - // insert a button to bookmark/un-bookmark the current page - bookmarkController->addAction(addBookmarkAction); - connect(m_document->bookmarkManager(), &Okular::BookmarkManager::bookmarksChanged, this, &BookmarkList::slotBookmarksChanged); - rebuildTree(m_showBoomarkOnlyAction->isChecked()); + rebuildTree(m_showForAllDocumentsCheckbox->isChecked()); + + QToolButton *showAllToolButton = new QToolButton(this); + showAllToolButton->setDefaultAction(addBookmarkAction); + showAllToolButton->setAutoRaise(true); + showAllToolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + mainlay->addWidget(showAllToolButton); } BookmarkList::~BookmarkList() @@ -184,8 +181,8 @@ void BookmarkList::notifySetup(const QVector &pages, int setupFl // clear contents m_searchLine->clear(); - if (m_showBoomarkOnlyAction->isChecked()) { - rebuildTree(m_showBoomarkOnlyAction->isChecked()); + if (!m_showForAllDocumentsCheckbox->isChecked()) { + rebuildTree(m_showForAllDocumentsCheckbox->isChecked()); } else { disconnect(m_tree, &QTreeWidget::itemChanged, this, &BookmarkList::slotChanged); if (m_currentDocumentItem && m_currentDocumentItem != m_tree->invisibleRootItem()) { @@ -200,9 +197,9 @@ void BookmarkList::notifySetup(const QVector &pages, int setupFl } } -void BookmarkList::slotFilterBookmarks(bool on) +void BookmarkList::slotShowAllBookmarks(bool showAll) { - rebuildTree(on); + rebuildTree(showAll); } void BookmarkList::slotExecuted(QTreeWidgetItem *item) @@ -305,7 +302,7 @@ void BookmarkList::slotBookmarksChanged(const QUrl &url) } // we are showing the bookmarks for the current document only - if (m_showBoomarkOnlyAction->isChecked()) + if (!m_showForAllDocumentsCheckbox->isChecked()) return; QTreeWidgetItem *item = itemForUrl(url); @@ -326,7 +323,7 @@ QList createItems(const QUrl &baseurl, const KBookmark::List return ret; } -void BookmarkList::rebuildTree(bool filter) +void BookmarkList::rebuildTree(bool showAll) { // disconnect and reconnect later, otherwise we'll get many itemChanged() // signals for all the current items @@ -336,7 +333,7 @@ void BookmarkList::rebuildTree(bool filter) m_tree->clear(); const QList urls = m_document->bookmarkManager()->files(); - if (filter) { + if (!showAll) { if (m_document->isOpened()) { for (const QUrl &url : urls) { if (url == m_document->currentDocument()) { diff --git a/part/bookmarklist.h b/part/bookmarklist.h index 027cb7f64..a4a7bc0d7 100644 --- a/part/bookmarklist.h +++ b/part/bookmarklist.h @@ -12,6 +12,7 @@ #include "core/observer.h" class QAction; +class QCheckBox; class QTreeWidget; class QTreeWidgetItem; class KTreeWidgetSearchLine; @@ -36,14 +37,14 @@ public: void notifySetup(const QVector &pages, int setupFlags) override; private Q_SLOTS: - void slotFilterBookmarks(bool); + void slotShowAllBookmarks(bool); void slotExecuted(QTreeWidgetItem *item); void slotChanged(QTreeWidgetItem *item); void slotContextMenu(const QPoint p); void slotBookmarksChanged(const QUrl &url); private: - void rebuildTree(bool filter); + void rebuildTree(bool showAll); void goTo(BookmarkItem *item); void selectiveUrlUpdate(const QUrl &url, QTreeWidgetItem *&item); QTreeWidgetItem *itemForUrl(const QUrl &url) const; @@ -53,7 +54,7 @@ private: Okular::Document *m_document; QTreeWidget *m_tree; KTreeWidgetSearchLine *m_searchLine; - QAction *m_showBoomarkOnlyAction; + QCheckBox *m_showForAllDocumentsCheckbox; QTreeWidgetItem *m_currentDocumentItem; };