okular/ui/layers.cpp

80 lines
2.8 KiB
C++
Raw Normal View History

2015-05-29 04:24:06 +00:00
/***************************************************************************
* Copyright (C) 2015 by Saheb Preet Singh <saheb.preet@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
2015-05-27 13:56:56 +00:00
#include "layers.h"
#include "settings.h"
// qt/kde includes
#include <QVBoxLayout>
#include <QTreeView>
#include <qheaderview.h>
// local includes
#include "core/document.h"
#include "ktreeviewsearchline.h"
#include "ui/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 );
2019-09-18 11:35:04 +00:00
mainlay->setContentsMargins( 0, 0, 0, 0 );
2015-05-27 13:56:56 +00:00
mainlay->setSpacing( 6 );
m_document->addObserver( this );
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 );
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
{
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
}