Commit 288d3e4c authored by Saheb Preet Singh's avatar Saheb Preet Singh
Browse files

added layer-visible-on and layer-visible-off icon instead of checkboxes

parent 455a381f
......@@ -205,6 +205,7 @@ set(okularpart_SRCS
ui/tts.cpp
ui/videowidget.cpp
ui/layers.cpp
ui/layersitemdelegate.cpp
)
kde4_add_ui_files(okularpart_SRCS
......
......@@ -18,6 +18,7 @@
// local includes
#include "core/document.h"
#include "ktreeviewsearchline.h"
#include "layersitemdelegate.h"
Layers::Layers(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document)
{
......@@ -38,12 +39,16 @@ Layers::Layers(QWidget *parent, Okular::Document *document) : QWidget(parent), m
QAbstractItemModel * layersModel = m_document->layersModel();
QAbstractItemDelegate * delegate = new LayersItemDelegate( this );
m_treeView->setItemDelegate( delegate );
if( layersModel )
{
m_treeView->setModel( layersModel );
m_searchLine->addTreeView( m_treeView );
emit hasLayers( true );
connect( layersModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), m_document, SLOT(reloadDocument()) );
connect( layersModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(repaintItems(QModelIndex,QModelIndex)) );
}
else
{
......@@ -69,6 +74,7 @@ void Layers::notifySetup( const QVector< Okular::Page * > & /*pages*/, int /*set
m_searchLine->addTreeView( m_treeView );
emit hasLayers( true );
connect( layersModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), m_document, SLOT(reloadDocument()) );
connect( layersModel, SIGNAL(dataChanged(const QModelIndex,const QModelIndex)), this, SLOT(repaintItems(const QModelIndex,const QModelIndex)) );
}
else
{
......@@ -83,4 +89,10 @@ void Layers::saveSearchOptions()
Okular::Settings::self()->writeConfig();
}
void Layers::repaintItems(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
if( topLeft == bottomRight )
m_treeView->update( topLeft );
}
#include "layers.moc"
......@@ -41,6 +41,7 @@ Q_OBJECT
private slots:
void saveSearchOptions();
void repaintItems( const QModelIndex &topLeft, const QModelIndex &bottomRight );
private:
......
/***************************************************************************
* 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. *
***************************************************************************/
#include "layersitemdelegate.h"
#include <kicon.h>
#include <QPainter>
#include <QDebug>
Q_DECLARE_METATYPE( Qt::CheckState );
LayersItemDelegate::LayersItemDelegate( QWidget * parent )
: QStyledItemDelegate( parent )
{
}
void LayersItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Qt::CheckState state = (Qt::CheckState ) qvariant_cast<int>( index.data( Qt::CheckStateRole ) );
if( option.state & QStyle::State_Selected )
painter->fillRect( option.rect, option.palette.highlight() );
KIcon icon = state == Qt::Checked ? KIcon( "layer-visible-on" ) : KIcon( "layer-visible-off" );
QRect iconRect = option.rect;
iconRect.setWidth( iconRect.height() );
painter->drawPixmap( iconRect, icon.pixmap( iconRect.size() ) );
QString text = qvariant_cast<QString>( index.data( Qt::DisplayRole ) );
QRect textRect = QRect( iconRect.topRight() + QPoint( 5, 0 ), QSize( option.rect.width() - iconRect.width(), option.rect.height() ) );
painter->drawText( textRect, Qt::AlignVCenter, text );
}
\ No newline at end of file
/***************************************************************************
* 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. *
***************************************************************************/
#ifndef _OKULAR_LAYERSITEMDELEGATE_H_
#define _OKULAR_LAYERSITEMDELEGATE_H_
#include <QStyledItemDelegate>
#include "okular_part_export.h"
class OKULAR_PART_EXPORT LayersItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
LayersItemDelegate( QWidget * parent);
virtual void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
};
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment