mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 14:14:10 +00:00
fix and port the Table of Contents browser
This commit is contained in:
parent
c8db597052
commit
bb5c4291e2
|
@ -21,16 +21,22 @@ import QtQuick 2.1
|
|||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
||||
import org.kde.plasma.mobilecomponents 2.0 as MobileComponents
|
||||
import org.kde.plasma.mobilecomponents 0.2 as MobileComponents
|
||||
|
||||
PlasmaComponents.Page {
|
||||
id: root
|
||||
property alias contentY: flickable.contentY
|
||||
property alias contentHeight: flickable.contentHeight
|
||||
|
||||
tools: MobileComponents.ViewSearch {
|
||||
id: searchField
|
||||
anchors.centerIn: parent
|
||||
busy: documentItem.searchInProgress
|
||||
tools: Item {
|
||||
id: toolBarContent
|
||||
width: root.width
|
||||
height: searchField.height
|
||||
PlasmaComponents.TextField {
|
||||
id: searchField
|
||||
clearButtonShown: true
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
}
|
||||
PlasmaExtras.ScrollArea {
|
||||
anchors.fill: parent
|
||||
|
|
|
@ -33,6 +33,7 @@ ThumbnailsBase {
|
|||
height: searchField.height
|
||||
PlasmaComponents.TextField {
|
||||
id: searchField
|
||||
clearButtonShown: true
|
||||
enabled: documentItem.supportsSearch
|
||||
anchors.centerIn: parent
|
||||
onTextChanged: {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
import QtQuick 2.1
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.qtextracomponents 2.0
|
||||
import org.kde.kquickcontrolsaddons 2.0
|
||||
|
||||
Column {
|
||||
id: treeDelegate
|
||||
|
@ -28,13 +28,13 @@ Column {
|
|||
property int rowIndex: index
|
||||
width: parent.width
|
||||
|
||||
property bool matches: searchField.searchQuery.length < 3 || display.toLowerCase().indexOf(searchField.searchQuery.toLowerCase()) !== -1
|
||||
property bool matches: display.toLowerCase().indexOf(searchField.text.toLowerCase()) !== -1
|
||||
|
||||
|
||||
MouseArea {
|
||||
id: delegateArea
|
||||
width: parent.width
|
||||
height: label.height
|
||||
height: matches ? label.height : 0
|
||||
opacity: matches ? 1 : 0
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
|
@ -56,6 +56,7 @@ Column {
|
|||
width: theme.smallIconSize
|
||||
height: width
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
x: units.largeSpacing
|
||||
}
|
||||
PlasmaComponents.Label {
|
||||
id: label
|
||||
|
@ -63,10 +64,10 @@ Column {
|
|||
verticalAlignment: Text.AlignBottom
|
||||
anchors.left: icon.right
|
||||
}
|
||||
//there isn't a sane way to do a dotted line in QML1
|
||||
//there isn't a sane way to do a dotted line in QML
|
||||
Rectangle {
|
||||
color: theme.textColor
|
||||
opacity: 2.0
|
||||
opacity: 0.3
|
||||
height: 1
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
|
@ -79,7 +80,7 @@ Column {
|
|||
text: pageLabel ? pageLabel : page
|
||||
anchors.right: parent.right
|
||||
verticalAlignment: Text.AlignBottom
|
||||
anchors.rightMargin: 40
|
||||
anchors.rightMargin: units.largeSpacing
|
||||
}
|
||||
}
|
||||
Column {
|
||||
|
|
|
@ -60,9 +60,10 @@ void DocumentItem::setPath(const QString &path)
|
|||
QMimeDatabase db;
|
||||
m_document->openDocument(path, QUrl::fromLocalFile(path), db.mimeTypeForUrl(QUrl::fromLocalFile(path)));
|
||||
|
||||
m_tocModel->clear();
|
||||
m_tocModel->fill(m_document->documentSynopsis());
|
||||
m_tocModel->setCurrentViewport(m_document->viewport());
|
||||
|
||||
qWarning()<<"LLL"<<m_tocModel->count();
|
||||
m_matchingPages.clear();
|
||||
for (uint i = 0; i < m_document->pages(); ++i) {
|
||||
m_matchingPages << (int)i;
|
||||
|
|
|
@ -132,6 +132,7 @@ void TOCModelPrivate::addChildren( const QDomNode & parentNode, TOCItem * parent
|
|||
itemsToOpen.append( currentItem );
|
||||
|
||||
n = n.nextSibling();
|
||||
emit q->countChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +170,14 @@ TOCModel::~TOCModel()
|
|||
delete d;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> TOCModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||
roles[(int)PageItemDelegate::PageRole] = "page";
|
||||
roles[(int)PageItemDelegate::PageLabelRole] = "pageLabel";
|
||||
return roles;
|
||||
}
|
||||
|
||||
int TOCModel::columnCount( const QModelIndex &parent ) const
|
||||
{
|
||||
Q_UNUSED( parent )
|
||||
|
|
|
@ -24,12 +24,17 @@ class TOCModelPrivate;
|
|||
class TOCModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
/**
|
||||
* How many items are in this model, useful for QML
|
||||
*/
|
||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||
|
||||
public:
|
||||
explicit TOCModel( Okular::Document *document, QObject *parent = Q_NULLPTR );
|
||||
virtual ~TOCModel();
|
||||
|
||||
// reimplementations from QAbstractItemModel
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
|
||||
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
|
||||
bool hasChildren( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
|
||||
|
@ -52,6 +57,14 @@ class TOCModel : public QAbstractItemModel
|
|||
Okular::DocumentViewport viewportForIndex( const QModelIndex &index ) const;
|
||||
QString urlForIndex( const QModelIndex &index ) const;
|
||||
|
||||
int count() const
|
||||
{
|
||||
return rowCount();
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void countChanged();
|
||||
|
||||
private:
|
||||
// storage
|
||||
friend class TOCModelPrivate;
|
||||
|
|
Loading…
Reference in a new issue