forked from KDE/okular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers.cpp
83 lines (68 loc) · 2.51 KB
/
layers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
SPDX-FileCopyrightText: 2015 Saheb Preet Singh <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "layers.h"
#include "settings.h"
// qt/kde includes
#include <KLocalizedString>
#include <KTitleWidget>
#include <QHeaderView>
#include <QTreeView>
#include <QVBoxLayout>
#include <kwidgetsaddons_version.h>
// local includes
#include "core/document.h"
#include "ktreeviewsearchline.h"
#include "pageview.h"
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);
KTitleWidget *titleWidget = new KTitleWidget(this);
titleWidget->setLevel(4);
titleWidget->setText(i18n("Layers"));
mainlay->addWidget(titleWidget);
mainlay->setAlignment(titleWidget, Qt::AlignHCenter);
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());
connect(m_searchLine, &KTreeViewSearchLine::searchOptionsChanged, this, &Layers::saveSearchOptions);
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();
if (layersModel) {
m_treeView->setModel(layersModel);
m_searchLine->setTreeView(m_treeView);
Q_EMIT hasLayers(true);
connect(layersModel, &QAbstractItemModel::dataChanged, m_document, &Okular::Document::reloadDocument);
connect(layersModel, &QAbstractItemModel::dataChanged, m_pageView, &PageView::reloadForms);
} else {
Q_EMIT hasLayers(false);
}
}
void Layers::setPageView(PageView *pageView)
{
m_pageView = pageView;
}
void Layers::saveSearchOptions()
{
Okular::Settings::setLayersSearchRegularExpression(m_searchLine->regularExpression());
Okular::Settings::setLayersSearchCaseSensitive(m_searchLine->caseSensitivity() == Qt::CaseSensitive ? true : false);
Okular::Settings::self()->save();
}