mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Sidebar widget refactoring
This commit is contained in:
@ -67,6 +67,48 @@ PDFCatalog PDFCatalog::parse(const PDFObject& catalog, const PDFDocument* docume
|
||||
catalogObject.m_outlineRoot = PDFOutlineItem::parse(document, catalogDictionary->get("Outlines"));
|
||||
}
|
||||
|
||||
if (catalogDictionary->hasKey("OpenAction"))
|
||||
{
|
||||
PDFObject openAction = document->getObject(catalogDictionary->get("OpenAction"));
|
||||
if (openAction.isArray())
|
||||
{
|
||||
catalogObject.m_openAction.reset(new PDFActionGoTo(PDFDestination::parse(document, openAction)));
|
||||
}
|
||||
if (openAction.isDictionary())
|
||||
{
|
||||
catalogObject.m_openAction = PDFAction::parse(document, openAction);
|
||||
}
|
||||
}
|
||||
|
||||
PDFDocumentDataLoaderDecorator loader(document);
|
||||
if (catalogDictionary->hasKey("PageLayout"))
|
||||
{
|
||||
constexpr const std::array<std::pair<const char*, PageLayout>, 6> pageLayouts = {
|
||||
std::pair<const char*, PageLayout>{ "SinglePage", PageLayout::SinglePage },
|
||||
std::pair<const char*, PageLayout>{ "OneColumn", PageLayout::OneColumn },
|
||||
std::pair<const char*, PageLayout>{ "TwoColumnLeft", PageLayout::TwoColumnLeft },
|
||||
std::pair<const char*, PageLayout>{ "TwoColumnRight", PageLayout::TwoColumnRight },
|
||||
std::pair<const char*, PageLayout>{ "TwoPageLeft", PageLayout::TwoPagesLeft },
|
||||
std::pair<const char*, PageLayout>{ "TwoPageRight", PageLayout::TwoPagesRight }
|
||||
};
|
||||
|
||||
catalogObject.m_pageLayout = loader.readEnumByName(catalogDictionary->get("PageLayout"), pageLayouts.begin(), pageLayouts.end(), PageLayout::SinglePage);
|
||||
}
|
||||
|
||||
if (catalogDictionary->hasKey("PageMode"))
|
||||
{
|
||||
constexpr const std::array<std::pair<const char*, PageMode>, 6> pageModes = {
|
||||
std::pair<const char*, PageMode>{ "UseNone", PageMode::UseNone },
|
||||
std::pair<const char*, PageMode>{ "UseOutlines", PageMode::UseOutlines },
|
||||
std::pair<const char*, PageMode>{ "UseThumbs", PageMode::UseThumbnails },
|
||||
std::pair<const char*, PageMode>{ "FullScreen", PageMode::Fullscreen },
|
||||
std::pair<const char*, PageMode>{ "UseOC", PageMode::UseOptionalContent },
|
||||
std::pair<const char*, PageMode>{ "UseAttachments", PageMode::UseAttachments }
|
||||
};
|
||||
|
||||
catalogObject.m_pageMode = loader.readEnumByName(catalogDictionary->get("PageMode"), pageModes.begin(), pageModes.end(), PageMode::UseNone);
|
||||
}
|
||||
|
||||
return catalogObject;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "pdfpage.h"
|
||||
#include "pdfoptionalcontent.h"
|
||||
#include "pdfoutline.h"
|
||||
#include "pdfaction.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
@ -219,6 +220,12 @@ public:
|
||||
/// Returns root pointer for outline items
|
||||
QSharedPointer<PDFOutlineItem> getOutlineRootPtr() const { return m_outlineRoot; }
|
||||
|
||||
/// Returns action, which should be performed
|
||||
const PDFAction* getOpenAction() const { return m_openAction.data(); }
|
||||
|
||||
PageLayout getPageLayout() const { return m_pageLayout; }
|
||||
PageMode getPageMode() const { return m_pageMode; }
|
||||
|
||||
/// Parses catalog from catalog dictionary. If object cannot be parsed, or error occurs,
|
||||
/// then exception is thrown.
|
||||
static PDFCatalog parse(const PDFObject& catalog, const PDFDocument* document);
|
||||
@ -229,6 +236,9 @@ private:
|
||||
std::vector<PDFPageLabel> m_pageLabels;
|
||||
PDFOptionalContentProperties m_optionalContentProperties;
|
||||
QSharedPointer<PDFOutlineItem> m_outlineRoot;
|
||||
PDFActionPtr m_openAction;
|
||||
PageLayout m_pageLayout = PageLayout::SinglePage;
|
||||
PageMode m_pageMode = PageMode::UseNone;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -364,16 +364,26 @@ QVariant PDFOutlineTreeItemModel::data(const QModelIndex& index, int role) const
|
||||
case Qt::FontRole:
|
||||
{
|
||||
QFont font = QApplication::font();
|
||||
font.setPointSize(10);
|
||||
font.setBold(outlineItem->isFontBold());
|
||||
font.setItalic(outlineItem->isFontItalics());
|
||||
return font;
|
||||
}
|
||||
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
if (!m_icon.isNull())
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QString();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void PDFOutlineTreeItemModel::update()
|
||||
@ -415,4 +425,16 @@ Qt::ItemFlags PDFOutlineTreeItemModel::flags(const QModelIndex& index) const
|
||||
return flags;
|
||||
}
|
||||
|
||||
const PDFAction* PDFOutlineTreeItemModel::getAction(const QModelIndex& index) const
|
||||
{
|
||||
if (index.isValid())
|
||||
{
|
||||
const PDFOutlineTreeItem* item = static_cast<const PDFOutlineTreeItem*>(index.internalPointer());
|
||||
const PDFOutlineItem* outlineItem = item->getOutlineItem();
|
||||
return outlineItem->getAction();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -21,10 +21,12 @@
|
||||
#include "pdfglobal.h"
|
||||
#include "pdfobject.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
class PDFAction;
|
||||
class PDFDocument;
|
||||
class PDFOutlineItem;
|
||||
class PDFOptionalContentActivity;
|
||||
@ -107,6 +109,7 @@ private:
|
||||
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFOptionalContentTreeItemModel : public PDFTreeItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
inline explicit PDFOptionalContentTreeItemModel(QObject* parent) :
|
||||
PDFTreeItemModel(parent),
|
||||
@ -140,13 +143,27 @@ private:
|
||||
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFOutlineTreeItemModel : public PDFTreeItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using PDFTreeItemModel::PDFTreeItemModel;
|
||||
PDFOutlineTreeItemModel(QIcon icon, QObject* parent) :
|
||||
PDFTreeItemModel(parent),
|
||||
m_icon(qMove(icon))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual int columnCount(const QModelIndex& parent) const override;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const override;
|
||||
virtual void update() override;
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
/// Returns action assigned to the index. If index is invalid, or
|
||||
/// points to the invalid item, nullptr is returned.
|
||||
/// \param index Index of the outline item
|
||||
const PDFAction* getAction(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
Reference in New Issue
Block a user