okular/part/layers.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.5 KiB
C++
Raw Normal View History

2021-05-24 07:25:56 +00:00
/*
SPDX-FileCopyrightText: 2015 Saheb Preet Singh <saheb.preet@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
2015-05-29 04:24:06 +00:00
2015-05-27 13:56:56 +00:00
#include "layers.h"
#include "settings.h"
// qt/kde includes
2020-07-08 11:54:37 +00:00
#include <KLocalizedString>
2015-05-27 13:56:56 +00:00
#include <KTitleWidget>
2020-07-08 11:54:37 +00:00
#include <QHeaderView>
#include <QTreeView>
2015-05-27 13:56:56 +00:00
#include <QVBoxLayout>
Improve the sidebar's navigation and UX Okular's sidebar vertical view chooser toolbar suffers from a few issues: * It's a nonstandard UI not used for category choosers in other pieces of KDE software, and not used in other FOSS document readers * What is shown and what is hidden is simultaneously too configurable while still not offering the desirable UI common to other programs (i.e. no visible category chooser, but a sidebar capable of displaying thumbnails, table of contents, search results, etc.) * With labels on it takes up quite a bit of horizontal space, while with labels off, the categories are less than clear * UX is kind of clunky with nonstandard behaviors (e.g. clicking on the current category to hide that category's view while keeping the view chooser visible, showing mostly disabled items) * It's made with custom painting code, which reduces maintainability and introduces bugs (e.g. https://bugs.kde.org/show_bug.cgi?id=408190) This patch removes the vertical category chooser entirely and replaces it with a tabbed view on the top of the sidebar itself. The tabs are icons-only and have large icons. A button is added on the left side of the default toolbar to quickly hide or show the sidebar. In order to make room for the new button, the Previous and Next buttons on the toolbar are removed, as previous/next buttons are already present on the Page Bar on the bottom of the window so there's no need to duplicate this functionality. This improves the UX, fixes a variety of bugs, and deletes a lot of custom code of dubious long-term maintainability. ![vokoscreenNG-2020-04-16_13-29-24](https://invent.kde.org/graphics/okular/uploads/a1f96a315b69282df51de9993b1befaf/vokoscreenNG-2020-04-16_13-29-24.webm) BUG: 213508 BUG: 334441 BUG: 344599 BUG: 408190 CCBUG: 335189 FIXED-IN: 1.11.0 CHANGELOG: The sidebar can now be easily shown or hidden with a toolbar button, and the category chooser no longer takes up so much space
2020-05-27 13:37:42 +00:00
#include <kwidgetsaddons_version.h>
2015-05-27 13:56:56 +00:00
// local includes
#include "core/document.h"
#include "ktreeviewsearchline.h"
#include "pageview.h"
2015-05-27 13:56:56 +00:00
Layers::Layers(QWidget *parent, Okular::Document *document)
: QWidget(parent)
, m_document(document)
{
QVBoxLayout *const mainlay = new QVBoxLayout(this);
mainlay->setSpacing(6);
m_document->addObserver(this);
Improve the sidebar's navigation and UX Okular's sidebar vertical view chooser toolbar suffers from a few issues: * It's a nonstandard UI not used for category choosers in other pieces of KDE software, and not used in other FOSS document readers * What is shown and what is hidden is simultaneously too configurable while still not offering the desirable UI common to other programs (i.e. no visible category chooser, but a sidebar capable of displaying thumbnails, table of contents, search results, etc.) * With labels on it takes up quite a bit of horizontal space, while with labels off, the categories are less than clear * UX is kind of clunky with nonstandard behaviors (e.g. clicking on the current category to hide that category's view while keeping the view chooser visible, showing mostly disabled items) * It's made with custom painting code, which reduces maintainability and introduces bugs (e.g. https://bugs.kde.org/show_bug.cgi?id=408190) This patch removes the vertical category chooser entirely and replaces it with a tabbed view on the top of the sidebar itself. The tabs are icons-only and have large icons. A button is added on the left side of the default toolbar to quickly hide or show the sidebar. In order to make room for the new button, the Previous and Next buttons on the toolbar are removed, as previous/next buttons are already present on the Page Bar on the bottom of the window so there's no need to duplicate this functionality. This improves the UX, fixes a variety of bugs, and deletes a lot of custom code of dubious long-term maintainability. ![vokoscreenNG-2020-04-16_13-29-24](https://invent.kde.org/graphics/okular/uploads/a1f96a315b69282df51de9993b1befaf/vokoscreenNG-2020-04-16_13-29-24.webm) BUG: 213508 BUG: 334441 BUG: 344599 BUG: 408190 CCBUG: 335189 FIXED-IN: 1.11.0 CHANGELOG: The sidebar can now be easily shown or hidden with a toolbar button, and the category chooser no longer takes up so much space
2020-05-27 13:37:42 +00:00
KTitleWidget *titleWidget = new KTitleWidget(this);
titleWidget->setLevel(4);
Improve the sidebar's navigation and UX Okular's sidebar vertical view chooser toolbar suffers from a few issues: * It's a nonstandard UI not used for category choosers in other pieces of KDE software, and not used in other FOSS document readers * What is shown and what is hidden is simultaneously too configurable while still not offering the desirable UI common to other programs (i.e. no visible category chooser, but a sidebar capable of displaying thumbnails, table of contents, search results, etc.) * With labels on it takes up quite a bit of horizontal space, while with labels off, the categories are less than clear * UX is kind of clunky with nonstandard behaviors (e.g. clicking on the current category to hide that category's view while keeping the view chooser visible, showing mostly disabled items) * It's made with custom painting code, which reduces maintainability and introduces bugs (e.g. https://bugs.kde.org/show_bug.cgi?id=408190) This patch removes the vertical category chooser entirely and replaces it with a tabbed view on the top of the sidebar itself. The tabs are icons-only and have large icons. A button is added on the left side of the default toolbar to quickly hide or show the sidebar. In order to make room for the new button, the Previous and Next buttons on the toolbar are removed, as previous/next buttons are already present on the Page Bar on the bottom of the window so there's no need to duplicate this functionality. This improves the UX, fixes a variety of bugs, and deletes a lot of custom code of dubious long-term maintainability. ![vokoscreenNG-2020-04-16_13-29-24](https://invent.kde.org/graphics/okular/uploads/a1f96a315b69282df51de9993b1befaf/vokoscreenNG-2020-04-16_13-29-24.webm) BUG: 213508 BUG: 334441 BUG: 344599 BUG: 408190 CCBUG: 335189 FIXED-IN: 1.11.0 CHANGELOG: The sidebar can now be easily shown or hidden with a toolbar button, and the category chooser no longer takes up so much space
2020-05-27 13:37:42 +00:00
titleWidget->setText(i18n("Layers"));
mainlay->addWidget(titleWidget);
mainlay->setAlignment(titleWidget, Qt::AlignHCenter);
2015-05-27 13:56:56 +00:00
m_searchLine = new KTreeViewSearchLine(this);
mainlay->addWidget(m_searchLine);
m_searchLine->setCaseSensitivity(Okular::Settings::self()->layersSearchCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_searchLine->setRegularExpression(Okular::Settings::self()->layersSearchRegularExpression());
2015-10-29 12:37:11 +00:00
connect(m_searchLine, &KTreeViewSearchLine::searchOptionsChanged, this, &Layers::saveSearchOptions);
2015-05-27 13:56:56 +00:00
m_treeView = new QTreeView(this);
mainlay->addWidget(m_treeView);
m_treeView->setSortingEnabled(false);
m_treeView->setRootIsDecorated(true);
m_treeView->setAlternatingRowColors(true);
m_treeView->header()->hide();
}
Layers::~Layers()
{
m_document->removeObserver(this);
}
void Layers::notifySetup(const QVector<Okular::Page *> & /*pages*/, int /*setupFlags*/)
{
QAbstractItemModel *layersModel = m_document->layersModel();
2015-05-27 13:56:56 +00:00
if (layersModel) {
m_treeView->setModel(layersModel);
m_searchLine->setTreeView(m_treeView);
Q_EMIT hasLayers(true);
2015-10-29 12:37:11 +00:00
connect(layersModel, &QAbstractItemModel::dataChanged, m_document, &Okular::Document::reloadDocument);
connect(layersModel, &QAbstractItemModel::dataChanged, m_pageView, &PageView::reloadForms);
2015-05-27 13:56:56 +00:00
} else {
Q_EMIT hasLayers(false);
2015-05-27 13:56:56 +00:00
}
}
void Layers::setPageView(PageView *pageView)
{
m_pageView = pageView;
}
2015-05-27 13:56:56 +00:00
void Layers::saveSearchOptions()
{
Okular::Settings::setLayersSearchRegularExpression(m_searchLine->regularExpression());
Okular::Settings::setLayersSearchCaseSensitive(m_searchLine->caseSensitivity() == Qt::CaseSensitive ? true : false);
2016-07-24 20:43:41 +00:00
Okular::Settings::self()->save();
2015-05-27 13:56:56 +00:00
}