2004-12-05 22:47:32 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "propertiesdialog.h"
|
|
|
|
|
2005-01-02 14:37:49 +00:00
|
|
|
// qt/kde includes
|
2005-01-02 22:37:52 +00:00
|
|
|
#include <qlayout.h>
|
2004-12-05 22:47:32 +00:00
|
|
|
#include <qlabel.h>
|
2006-03-30 23:15:30 +00:00
|
|
|
#include <qheaderview.h>
|
2007-07-07 20:35:01 +00:00
|
|
|
#include <qprogressbar.h>
|
2006-03-30 23:15:30 +00:00
|
|
|
#include <qsortfilterproxymodel.h>
|
|
|
|
#include <qtreeview.h>
|
2007-07-07 20:35:01 +00:00
|
|
|
#include <qtimer.h>
|
2006-07-17 11:52:41 +00:00
|
|
|
#include <kicon.h>
|
2005-03-25 08:32:27 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <ksqueezedtextlabel.h>
|
|
|
|
#include <kglobalsettings.h>
|
2004-12-05 22:47:32 +00:00
|
|
|
|
2005-01-02 14:37:49 +00:00
|
|
|
// local includes
|
|
|
|
#include "core/document.h"
|
2007-07-07 20:35:01 +00:00
|
|
|
#include "core/fontinfo.h"
|
2004-12-05 22:47:32 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc)
|
2007-07-09 12:34:08 +00:00
|
|
|
: KPageDialog( parent ), m_document( doc ), m_fontPage( 0 ),
|
|
|
|
m_fontModel( 0 ), m_fontInfo( 0 ), m_fontProgressBar( 0 ),
|
|
|
|
m_fontScanStarted( false )
|
2004-12-05 22:47:32 +00:00
|
|
|
{
|
2006-06-13 08:44:08 +00:00
|
|
|
setFaceType( Tabbed );
|
|
|
|
setCaption( i18n( "Unknown File" ) );
|
|
|
|
setButtons( Ok );
|
|
|
|
|
2005-06-13 15:46:23 +00:00
|
|
|
// PROPERTIES
|
2006-06-13 17:40:31 +00:00
|
|
|
QFrame *page = new QFrame();
|
2006-07-17 11:52:41 +00:00
|
|
|
KPageWidgetItem *item = addPage( page, i18n( "&Properties" ) );
|
2007-03-08 21:41:46 +00:00
|
|
|
item->setIcon( KIcon( "document-properties" ) );
|
2006-04-03 20:48:26 +00:00
|
|
|
QGridLayout *layout = new QGridLayout( page );
|
|
|
|
layout->setMargin( marginHint() );
|
|
|
|
layout->setSpacing( spacingHint() );
|
2005-01-02 22:37:52 +00:00
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// get document info, if not present display blank data and a warning
|
2006-09-21 08:45:36 +00:00
|
|
|
const Okular::DocumentInfo * info = doc->documentInfo();
|
2005-01-02 22:37:52 +00:00
|
|
|
if ( !info ) {
|
2005-01-17 14:57:18 +00:00
|
|
|
layout->addWidget( new QLabel( i18n( "No document opened." ), page ), 0, 0 );
|
2004-12-11 17:25:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-01-02 22:37:52 +00:00
|
|
|
|
2004-12-21 12:38:52 +00:00
|
|
|
// mime name based on mimetype id
|
2006-03-29 13:52:17 +00:00
|
|
|
QString mimeName = info->get( "mimeType" ).section( '/', -1 ).toUpper();
|
2006-04-10 19:50:00 +00:00
|
|
|
setCaption( i18n( "%1 Properties", mimeName ) );
|
2005-01-02 22:37:52 +00:00
|
|
|
|
|
|
|
QDomElement docElement = info->documentElement();
|
|
|
|
|
|
|
|
int row = 0;
|
2005-03-25 08:32:27 +00:00
|
|
|
int valMaxWidth = 100;
|
2005-01-02 22:37:52 +00:00
|
|
|
for ( QDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
|
|
|
|
QDomElement element = node.toElement();
|
|
|
|
|
2005-03-25 08:32:27 +00:00
|
|
|
QString titleString = element.attribute( "title" );
|
|
|
|
QString valueString = element.attribute( "value" );
|
|
|
|
if ( titleString.isEmpty() || valueString.isEmpty() )
|
|
|
|
continue;
|
2005-01-02 22:37:52 +00:00
|
|
|
|
2005-03-25 08:32:27 +00:00
|
|
|
// create labels and layout them
|
2006-04-10 19:50:00 +00:00
|
|
|
QLabel *key = new QLabel( i18n( "%1:", titleString ), page );
|
2005-03-25 08:32:27 +00:00
|
|
|
QLabel *value = new KSqueezedTextLabel( valueString, page );
|
2007-10-10 18:41:10 +00:00
|
|
|
value->setTextInteractionFlags( Qt::TextSelectableByMouse );
|
2006-03-23 20:43:38 +00:00
|
|
|
layout->addWidget( key, row, 0, Qt::AlignRight );
|
2005-03-25 08:32:27 +00:00
|
|
|
layout->addWidget( value, row, 1 );
|
|
|
|
row++;
|
2005-01-02 22:37:52 +00:00
|
|
|
|
2005-03-25 08:32:27 +00:00
|
|
|
// refine maximum width of 'value' labels
|
2006-03-29 17:16:46 +00:00
|
|
|
valMaxWidth = qMax( valMaxWidth, fontMetrics().width( valueString ) );
|
2005-01-02 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add the number of pages if the generator hasn't done it already
|
|
|
|
QDomNodeList list = docElement.elementsByTagName( "pages" );
|
|
|
|
if ( list.count() == 0 ) {
|
|
|
|
QLabel *key = new QLabel( i18n( "Pages:" ), page );
|
|
|
|
QLabel *value = new QLabel( QString::number( doc->pages() ), page );
|
2007-10-10 18:41:10 +00:00
|
|
|
value->setTextInteractionFlags( Qt::TextSelectableByMouse );
|
2005-01-02 22:37:52 +00:00
|
|
|
|
2006-06-11 13:39:28 +00:00
|
|
|
layout->addWidget( key, row, 0, Qt::AlignRight );
|
2005-01-02 22:37:52 +00:00
|
|
|
layout->addWidget( value, row, 1 );
|
|
|
|
}
|
2005-03-25 08:32:27 +00:00
|
|
|
|
2005-06-13 15:46:23 +00:00
|
|
|
// FONTS
|
|
|
|
QVBoxLayout *page2Layout = 0;
|
2007-07-07 20:35:01 +00:00
|
|
|
if ( doc->canProvideFontInformation() ) {
|
2005-06-13 15:46:23 +00:00
|
|
|
// create fonts tab and layout it
|
2006-06-13 17:40:31 +00:00
|
|
|
QFrame *page2 = new QFrame();
|
2007-07-07 20:35:01 +00:00
|
|
|
m_fontPage = addPage(page2, i18n("&Fonts"));
|
2007-12-09 12:15:03 +00:00
|
|
|
m_fontPage->setIcon( KIcon( "preferences-desktop-font" ) );
|
2006-03-29 17:16:46 +00:00
|
|
|
page2Layout = new QVBoxLayout(page2);
|
2006-05-13 17:04:59 +00:00
|
|
|
page2Layout->setMargin(marginHint());
|
|
|
|
page2Layout->setSpacing(spacingHint());
|
2006-03-30 23:15:30 +00:00
|
|
|
// add a tree view
|
|
|
|
QTreeView *view = new QTreeView(page2);
|
|
|
|
page2Layout->addWidget(view);
|
|
|
|
view->setRootIsDecorated(false);
|
|
|
|
view->setAlternatingRowColors(true);
|
2007-07-08 18:40:37 +00:00
|
|
|
view->setSortingEnabled( true );
|
2006-03-30 23:15:30 +00:00
|
|
|
// creating a proxy model so we can sort the data
|
|
|
|
QSortFilterProxyModel *proxymodel = new QSortFilterProxyModel(view);
|
2007-07-08 18:40:37 +00:00
|
|
|
proxymodel->setDynamicSortFilter( true );
|
|
|
|
proxymodel->setSortCaseSensitivity( Qt::CaseInsensitive );
|
2007-07-07 20:35:01 +00:00
|
|
|
m_fontModel = new FontsListModel(view);
|
|
|
|
proxymodel->setSourceModel(m_fontModel);
|
2006-03-30 23:15:30 +00:00
|
|
|
view->setModel(proxymodel);
|
2007-07-08 18:40:37 +00:00
|
|
|
view->sortByColumn( 0, Qt::AscendingOrder );
|
2007-07-07 20:35:01 +00:00
|
|
|
m_fontInfo = new QLabel( this );
|
|
|
|
page2Layout->addWidget( m_fontInfo );
|
|
|
|
m_fontInfo->setText( i18n( "Reading font information..." ) );
|
|
|
|
m_fontInfo->hide();
|
|
|
|
m_fontProgressBar = new QProgressBar( this );
|
|
|
|
page2Layout->addWidget( m_fontProgressBar );
|
|
|
|
m_fontProgressBar->setRange( 0, 100 );
|
|
|
|
m_fontProgressBar->setValue( 0 );
|
|
|
|
m_fontProgressBar->hide();
|
2005-06-13 15:46:23 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 08:32:27 +00:00
|
|
|
// current width: left columnt + right column + dialog borders
|
2005-06-13 15:46:23 +00:00
|
|
|
int width = layout->minimumSize().width() + valMaxWidth + 2 * marginHint() + spacingHint() + 30;
|
|
|
|
if ( page2Layout )
|
2006-03-24 21:31:46 +00:00
|
|
|
width = qMax( width, page2Layout->sizeHint().width() + marginHint() + spacingHint() + 31 );
|
2005-03-25 08:32:27 +00:00
|
|
|
// stay inside the 2/3 of the screen width
|
|
|
|
QRect screenContainer = KGlobalSettings::desktopGeometry( this );
|
2006-03-24 21:31:46 +00:00
|
|
|
width = qMin( width, 2*screenContainer.width()/3 );
|
2005-06-13 15:46:23 +00:00
|
|
|
resize(width, 1);
|
2006-09-27 15:57:15 +00:00
|
|
|
// TODO ?
|
|
|
|
setMinimumSize(sizeHint());
|
2007-07-07 20:35:01 +00:00
|
|
|
|
|
|
|
connect( pageWidget(), SIGNAL( currentPageChanged( KPageWidgetItem *, KPageWidgetItem * ) ),
|
|
|
|
this, SLOT( pageChanged( KPageWidgetItem *, KPageWidgetItem * ) ) );
|
|
|
|
}
|
|
|
|
|
2007-07-08 21:22:37 +00:00
|
|
|
PropertiesDialog::~PropertiesDialog()
|
|
|
|
{
|
|
|
|
m_document->stopFontReading();
|
|
|
|
}
|
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
void PropertiesDialog::pageChanged( KPageWidgetItem *current, KPageWidgetItem * )
|
|
|
|
{
|
|
|
|
if ( current == m_fontPage && !m_fontScanStarted )
|
|
|
|
{
|
|
|
|
connect( m_document, SIGNAL( gotFont( const Okular::FontInfo& ) ), m_fontModel, SLOT( addFont( const Okular::FontInfo& ) ) );
|
|
|
|
connect( m_document, SIGNAL( fontReadingProgress( int ) ), this, SLOT( slotFontReadingProgress( int ) ) );
|
|
|
|
connect( m_document, SIGNAL( fontReadingEnded() ), this, SLOT( slotFontReadingEnded() ) );
|
|
|
|
QTimer::singleShot( 0, this, SLOT( reallyStartFontReading() ) );
|
|
|
|
|
|
|
|
m_fontScanStarted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesDialog::slotFontReadingProgress( int page )
|
|
|
|
{
|
|
|
|
m_fontProgressBar->setValue( m_fontProgressBar->maximum() * page / m_document->pages() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertiesDialog::slotFontReadingEnded()
|
|
|
|
{
|
|
|
|
m_fontInfo->hide();
|
|
|
|
m_fontProgressBar->hide();
|
2004-12-05 22:47:32 +00:00
|
|
|
}
|
2006-03-30 23:15:30 +00:00
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
void PropertiesDialog::reallyStartFontReading()
|
2006-03-30 23:15:30 +00:00
|
|
|
{
|
2007-07-07 20:35:01 +00:00
|
|
|
m_fontInfo->show();
|
|
|
|
m_fontProgressBar->show();
|
|
|
|
m_document->startFontReading();
|
|
|
|
}
|
2006-03-30 23:15:30 +00:00
|
|
|
|
|
|
|
FontsListModel::FontsListModel( QObject * parent )
|
|
|
|
: QAbstractTableModel( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FontsListModel::~FontsListModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
void FontsListModel::addFont( const Okular::FontInfo &fi )
|
2006-03-30 23:15:30 +00:00
|
|
|
{
|
2006-09-28 12:21:04 +00:00
|
|
|
beginInsertRows( QModelIndex(), m_fonts.size(), m_fonts.size() );
|
2006-03-30 23:15:30 +00:00
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
m_fonts << fi;
|
2006-03-30 23:15:30 +00:00
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2007-07-08 18:40:37 +00:00
|
|
|
int FontsListModel::columnCount( const QModelIndex &parent ) const
|
2006-03-30 23:15:30 +00:00
|
|
|
{
|
2007-07-08 18:40:37 +00:00
|
|
|
return parent.isValid() ? 0 : 4;
|
2006-03-30 23:15:30 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 20:35:01 +00:00
|
|
|
static QString descriptionForFontType( Okular::FontInfo::FontType type )
|
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case Okular::FontInfo::Type1:
|
|
|
|
return i18n("Type 1");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::Type1C:
|
|
|
|
return i18n("Type 1C");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::Type1COT:
|
|
|
|
return i18nc("OT means OpenType", "Type 1C (OT)");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::Type3:
|
|
|
|
return i18n("Type 3");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::TrueType:
|
|
|
|
return i18n("TrueType");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::TrueTypeOT:
|
|
|
|
return i18nc("OT means OpenType", "TrueType (OT)");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::CIDType0:
|
|
|
|
return i18n("CID Type 0");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::CIDType0C:
|
|
|
|
return i18n("CID Type 0C");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::CIDType0COT:
|
|
|
|
return i18nc("OT means OpenType", "CID Type 0C (OT)");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::CIDTrueType:
|
|
|
|
return i18n("CID TrueType");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::CIDTrueTypeOT:
|
|
|
|
return i18nc("OT means OpenType", "CID TrueType (OT)");
|
|
|
|
break;
|
|
|
|
case Okular::FontInfo::Unknown:
|
|
|
|
return i18nc("Unknown font type", "Unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-08 16:07:37 +00:00
|
|
|
static QString descriptionForEmbedType( Okular::FontInfo::EmbedType type )
|
|
|
|
{
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case Okular::FontInfo::NotEmbedded:
|
|
|
|
return i18n("No");
|
|
|
|
break;
|
2007-07-08 16:23:07 +00:00
|
|
|
case Okular::FontInfo::EmbeddedSubset:
|
2007-07-08 16:07:37 +00:00
|
|
|
return i18n("Yes (subset)");
|
|
|
|
break;
|
2007-07-08 16:23:07 +00:00
|
|
|
case Okular::FontInfo::FullyEmbedded:
|
2007-07-08 16:07:37 +00:00
|
|
|
return i18n("Yes");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2006-03-30 23:15:30 +00:00
|
|
|
QVariant FontsListModel::data( const QModelIndex &index, int role ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( ( index.row() < 0 ) || ( index.row() >= m_fonts.size() ) )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role != Qt::DisplayRole )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch ( index.column() )
|
|
|
|
{
|
2007-12-24 23:31:52 +00:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
QString fontname = m_fonts.at( index.row() ).name();
|
|
|
|
return fontname.isEmpty() ? QString::fromLatin1( "-" ) : fontname; // TODO i18n
|
|
|
|
break;
|
|
|
|
}
|
2007-07-07 20:35:01 +00:00
|
|
|
case 1: return descriptionForFontType( m_fonts.at( index.row() ).type() ); break;
|
2007-07-08 16:07:37 +00:00
|
|
|
case 2: return descriptionForEmbedType( m_fonts.at( index.row() ).embedType() ); break;
|
2007-07-07 20:35:01 +00:00
|
|
|
case 3: return m_fonts.at( index.row() ).file(); break;
|
2006-03-30 23:15:30 +00:00
|
|
|
}
|
2007-12-24 23:31:52 +00:00
|
|
|
return QVariant();
|
2006-03-30 23:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant FontsListModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
|
|
|
{
|
|
|
|
if ( orientation != Qt::Horizontal )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( role == Qt::TextAlignmentRole )
|
|
|
|
return QVariant( Qt::AlignLeft );
|
|
|
|
|
|
|
|
if ( role != Qt::DisplayRole )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
switch ( section )
|
|
|
|
{
|
|
|
|
case 0: return i18n( "Name" ); break;
|
|
|
|
case 1: return i18n( "Type" ); break;
|
|
|
|
case 2: return i18n( "Embedded" ); break;
|
|
|
|
case 3: return i18n( "File" ); break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-08 18:40:37 +00:00
|
|
|
int FontsListModel::rowCount( const QModelIndex &parent ) const
|
2006-03-30 23:15:30 +00:00
|
|
|
{
|
2007-07-08 18:40:37 +00:00
|
|
|
return parent.isValid() ? 0 : m_fonts.size();
|
2006-03-30 23:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "propertiesdialog.moc"
|