1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwPlaylistPaged.cpp
22 * @brief A plain paged playlist item.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwPlaylistPaged.h"
27 #include "KwPlaylistPagedNode.h"
33 * Constructors + destructor.
36 /// Default constructor.
37 KwPlaylistPaged::KwPlaylistPaged()
45 KwPlaylistPaged::~KwPlaylistPaged()
53 /// Get the number of text blocks.
54 unsigned int KwPlaylistPaged::getBlockCount() const
56 return m_blockStarts
.size();
59 /// Get the number of pages.
60 unsigned int KwPlaylistPaged::getPageCount() const
62 return m_pageContents
.size();
65 /// Get a block's first page number.
66 unsigned int KwPlaylistPaged::getBlockPageIndex(unsigned int blockIndex
) const
68 assert(blockIndex
< getBlockCount());
69 return m_blockStarts
[blockIndex
];
72 /// Get the number of pages in a block.
73 unsigned int KwPlaylistPaged::getBlockPageCount(unsigned int blockIndex
) const
75 assert(blockIndex
< getBlockCount());
76 if (likely(blockIndex
< getBlockCount()-1))
78 return getBlockPageIndex(blockIndex
+1) - getBlockPageIndex(blockIndex
);
82 return getPageCount() - getBlockPageIndex(blockIndex
);
86 /// Get a page's block index.
87 unsigned int KwPlaylistPaged::getPageBlockIndex(unsigned int pageIndex
) const
89 assert(pageIndex
< getPageCount());
90 for (unsigned int block
= 1; block
< getBlockCount(); ++block
)
92 if (getBlockPageIndex(block
) >= pageIndex
)
97 return getBlockCount() - 1;
100 /// Get the content of a page.
101 QString
KwPlaylistPaged::getPageText(unsigned int pageIndex
) const
103 return m_pageContents
[pageIndex
];
106 /// Get the list of blocks.
107 QStringList
KwPlaylistPaged::blocks() const
110 for (int block
= 0; block
< m_blockStarts
.size(); ++block
)
112 int first
= m_blockStarts
[block
];
113 int count
= (block
== m_blockStarts
.size()-1 ? -1 : m_blockStarts
[block
+1]-first
);
114 result
+= QStringList(m_pageContents
.mid(first
, count
)).join("\n");
119 KwPlaylistNode
* KwPlaylistPaged::getNode(KwPlaylistNode
* parent
)
121 return new KwPlaylistPagedNode(parent
, this);
125 * Derived class block control interface
128 /// Set the text blocks.
129 void KwPlaylistPaged::setTextBlocks(const QStringList
& blocks
)
131 m_pageContents
= blocks
;
132 m_blockStarts
.resize(blocks
.size());
133 for (int block
= 0; block
< blocks
.size(); ++block
)
135 m_blockStarts
[block
] = block
;