Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 5143cd25 authored by Albert Astals Cid's avatar Albert Astals Cid

Report page size

It's only reported in case it makes sense for the format
Only implemented for pdf atm
If all pages have the same size it's reported on document properties
else there's a label shown in the new bottom bar with the size of the current page

svn path=/trunk/playground/graphics/okular/; revision=595822
parent 7cd16e9d
......@@ -77,6 +77,7 @@ set(okularpart_SRCS
ui/minibar.cpp
ui/newstuff.cpp
ui/pagepainter.cpp
ui/pagesizelabel.cpp
ui/pageviewannotator.cpp
ui/pageview.cpp
ui/pageviewutils.cpp
......
......@@ -500,7 +500,17 @@ bool Document::canConfigurePrinter( ) const
const DocumentInfo * Document::documentInfo() const
{
return generator ? generator->generateDocumentInfo() : NULL;
if (generator)
{
DocumentInfo *info = const_cast<DocumentInfo *>(generator->generateDocumentInfo());
QString pagesSize = pagesSizeString();
if (!pagesSize.isEmpty())
{
info->set( "pagesSize", pagesSize, i18n("Pages Size") );
}
return info;
}
else return NULL;
}
const DocumentSynopsis * Document::documentSynopsis() const
......@@ -627,6 +637,36 @@ int Document::rotation() const
return d->rotation;
}
QSizeF Document::allPagesSize() const
{
bool allPagesSameSize = true;
QSizeF size;
for (int i = 0; allPagesSameSize && i < pages_vector.count(); ++i)
{
Page *p = pages_vector[i];
if (i == 0) size = QSizeF(p->width(), p->height());
else
{
allPagesSameSize = (size == QSizeF(p->width(), p->height()));
}
}
if (allPagesSameSize) return size;
else return QSizeF();
}
QString Document::pageSizeString(int page) const
{
if (generator)
{
if (generator->pagesSizeMetric() != Generator::None)
{
Page *p = pages_vector[page];
return localizedSize(QSizeF(p->width(), p->height()));
}
}
return QString();
}
void Document::requestPixmaps( const QLinkedList< PixmapRequest * > & requests )
{
if ( !generator )
......@@ -1451,6 +1491,44 @@ void Document::sendGeneratorRequest()
QTimer::singleShot( 30, this, SLOT(sendGeneratorRequest()) );
}
QString Document::pagesSizeString() const
{
if (generator)
{
if (generator->pagesSizeMetric() != Generator::None)
{
QSizeF size = allPagesSize();
if (size.isValid()) return localizedSize(size);
else return QString();
}
else return QString();
}
else return QString();
}
QString Document::localizedSize(const QSizeF &size) const
{
double inchesWidth, inchesHeight;
switch (generator->pagesSizeMetric())
{
case Generator::Points:
inchesWidth = size.width() / 72.0;
inchesHeight = size.height() / 72.0;
break;
case Generator::None:
break;
}
if (KGlobal::locale()->measureSystem() == KLocale::Imperial)
{
return i18n("%1 x %2 in", inchesWidth, inchesHeight);
}
else
{
return i18n("%1 x %2 mm", inchesWidth * 25.4, inchesHeight * 25.4);
}
}
void Document::cleanupPixmapMemory( int /*sure? bytesOffset*/ )
{
// [MEM] choose memory parameters based on configuration profile
......
......@@ -119,6 +119,8 @@ class OKULAR_EXPORT Document : public QObject
bool historyAtEnd() const;
QString getMetaData( const QString & key, const QString & option = QString() ) const;
int rotation() const;
QSizeF allPagesSize() const;
QString pageSizeString(int page) const;
// gui altering stuff
QString getXMLFile();
......@@ -171,6 +173,8 @@ class OKULAR_EXPORT Document : public QObject
void notice(const QString & string, int duration);
private:
QString pagesSizeString() const;
QString localizedSize(const QSizeF &size) const;
// memory management related functions
void cleanupPixmapMemory( int bytesOffset = 0 );
int getTotalMemory();
......
......@@ -86,6 +86,10 @@ class OKULAR_EXPORT Generator : public QObject
virtual const DocumentSynopsis * generateDocumentSynopsis() { return 0L; }
virtual const DocumentFonts * generateDocumentFonts() { return 0L; }
virtual const QList<EmbeddedFile*> * embeddedFiles() { return 0L; }
// None = page size is not defined in a physical metric
// Points = page size is given in 1/72 inches
enum PageSizeMetric { None, Points };
virtual PageSizeMetric pagesSizeMetric() { return None; }
// DRM handling
virtual bool isAllowed( int /*Document::Permisison(s)*/ ) { return true; }
......
......@@ -25,9 +25,10 @@ namespace Okular {
#define MINIBAR_ID 6
#define REVIEWS_ID 7
#define PROGRESSWIDGET_ID 8
#define PAGESIZELABEL_ID 9
// the biggest ide, useful for ignoring wrong id request
#define MAX_OBSERVER_ID 9
// the biggest id, useful for ignoring wrong id request
#define MAX_OBSERVER_ID 10
/** PRIORITIES for requests. Globally defined here. **/
#define PAGEVIEW_PRIO 1
#define PAGEVIEW_PRELOAD_PRIO 3
......
......@@ -60,6 +60,7 @@ class PDFGenerator : public Okular::Generator
const Okular::DocumentSynopsis * generateDocumentSynopsis();
const Okular::DocumentFonts * generateDocumentFonts();
const QList<Okular::EmbeddedFile*> * embeddedFiles();
PageSizeMetric pagesSizeMetric() { return Points; }
// [INHERITED] document information
bool isAllowed( int permissions );
......
......@@ -67,6 +67,7 @@
#include "ui/embeddedfilesdialog.h"
#include "ui/propertiesdialog.h"
#include "ui/presentationwidget.h"
#include "ui/pagesizelabel.h"
#include "conf/preferencesdialog.h"
#include "settings.h"
#include "core/document.h"
......@@ -197,12 +198,15 @@ Part::Part(QWidget *parentWidget,
rightLayout->addWidget( m_pageView );
QWidget * bottomBar = new QWidget( rightContainer );
QHBoxLayout * bottomBarLayout = new QHBoxLayout( bottomBar );
m_pageSizeLabel = new PageSizeLabel( bottomBar, m_document );
bottomBarLayout->setMargin( 0 );
bottomBarLayout->setSpacing( 0 );
bottomBarLayout->addWidget( m_pageSizeLabel->antiWidget() );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
m_miniBar = new MiniBar( bottomBar, m_document );
bottomBarLayout->addWidget( m_miniBar );
bottomBarLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
bottomBarLayout->addWidget( m_pageSizeLabel );
rightLayout->addWidget( bottomBar );
// add document observers
......@@ -213,6 +217,7 @@ Part::Part(QWidget *parentWidget,
m_document->addObserver( m_miniBar );
m_document->addObserver( m_progressWidget );
m_document->addObserver( reviewsWidget );
m_document->addObserver( m_pageSizeLabel );
// ACTIONS
KActionCollection * ac = actionCollection();
......@@ -363,6 +368,7 @@ Part::~Part()
delete m_thumbnailList;
delete m_miniBar;
delete m_progressWidget;
delete m_pageSizeLabel;
delete m_document;
}
......
......@@ -42,6 +42,7 @@ class KPrinter;
class ThumbnailList;
class ThumbnailController;
class PageSizeLabel;
class PageView;
class PageViewTopMessage;
class PresentationWidget;
......@@ -165,6 +166,7 @@ private:
QPointer<MiniBar> m_miniBar;
QPointer<PresentationWidget> m_presentationWidget;
QPointer<ProgressWidget> m_progressWidget;
QPointer<PageSizeLabel> m_pageSizeLabel;
// document watcher (and reloader) variables
KDirWatch *m_watcher;
......
/***************************************************************************
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org> *
* *
* 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 "core/document.h"
#include "pagesizelabel.h"
PageSizeLabel::PageSizeLabel( QWidget * parent, Okular::Document * document )
: QLabel( parent ), m_document( document ),
m_currentPage( -1 ), m_antiWidget( NULL )
{
}
PageSizeLabel::~PageSizeLabel()
{
m_document->removeObserver( this );
}
QWidget *PageSizeLabel::antiWidget()
{
if (!m_antiWidget)
{
m_antiWidget = new QWidget(qobject_cast<QWidget*>(parent()));
m_antiWidget->resize(0, 0);
}
return m_antiWidget;
}
void PageSizeLabel::notifySetup( const QVector< Okular::Page * > & pageVector, bool changed )
{
// only process data when document changes
if ( !changed )
return;
// if document is closed or all pages have size hide widget
int pages = pageVector.count();
if ( pages < 1 || m_document->allPagesSize().isValid() )
{
hide();
return;
}
else show();
}
void PageSizeLabel::notifyViewportChanged( bool /*smoothMove*/ )
{
if (isVisible())
{
// get current page number
int page = m_document->viewport().pageNumber;
int pages = m_document->pages();
// if the document is opened and page is changed
if ( page != m_currentPage && pages > 0 )
{
m_currentPage = page;
setText( m_document->pageSizeString(page) );
m_antiWidget->setFixedSize(sizeHint());
}
}
}
/***************************************************************************
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org> *
* *
* 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_PAGESIZELABEL_H_
#define _OKULAR_PAGESIZELABEL_H_
#include <qlabel.h>
#include "core/observer.h"
namespace Okular {
class Document;
}
/**
* @short A widget to display page size.
*/
class PageSizeLabel : public QLabel, public Okular::DocumentObserver
{
public:
PageSizeLabel( QWidget *parent, Okular::Document * document );
~PageSizeLabel();
QWidget *antiWidget();
// [INHERITED] from DocumentObserver
uint observerId() const { return PAGESIZELABEL_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool );
void notifyViewportChanged( bool smoothMove );
private:
Okular::Document * m_document;
int m_currentPage;
QWidget *m_antiWidget;
};
#endif
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