summaryrefslogtreecommitdiffstats
path: root/kpdf/ui/propertiesdialog.cpp
blob: 02743ccbf0abead27bf0a12d6a1e7d77351875f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***************************************************************************
 *   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.                                   *
 ***************************************************************************/

// qt/kde includes
#include <tqlayout.h>
#include <tqlabel.h>
#include <klistview.h>
#include <klocale.h>
#include <ksqueezedtextlabel.h>
#include <kglobalsettings.h>

// local includes
#include "propertiesdialog.h"
#include "core/document.h"

PropertiesDialog::PropertiesDialog(TQWidget *tqparent, KPDFDocument *doc)
  : KDialogBase( Tabbed, i18n( "Unknown File" ), Ok, Ok, tqparent, 0, true, true )
{
  // Properties
  TQFrame *page = addPage(i18n("Properties"));
  TQGridLayout *tqlayout = new TQGridLayout( page, 2, 2, marginHint(), spacingHint() );

  // get document info, if not present display blank data and a warning
  const DocumentInfo * info = doc->documentInfo();
  if ( !info ) {
    tqlayout->addWidget( new TQLabel( i18n( "No document opened." ), page ), 0, 0 );
    return;
  }

  // mime name based on mimetype id
  TQString mimeName = info->get( "mimeType" ).section( '/', -1 ).upper();
  setCaption( i18n("%1 Properties").tqarg( mimeName ) );

  TQDomElement docElement = info->documentElement();

  int row = 0;
  int valMaxWidth = 100;
  for ( TQDomNode node = docElement.firstChild(); !node.isNull(); node = node.nextSibling() ) {
    TQDomElement element = node.toElement();

    TQString titleString = element.attribute( "title" );
    TQString valueString = element.attribute( "value" );
    if ( titleString.isEmpty() || valueString.isEmpty() )
        continue;

    // create labels and tqlayout them
    TQLabel *key = new TQLabel( i18n( "%1:" ).tqarg( titleString ), page );
    TQLabel *value = new KSqueezedTextLabel( valueString, page );
    tqlayout->addWidget( key, row, 0, AlignRight );
    tqlayout->addWidget( value, row, 1 );
    row++;

    // refine maximum width of 'value' labels
    valMaxWidth = TQMAX( valMaxWidth, fontMetrics().width( valueString ) );
  }

  // add the number of pages if the generator hasn't done it already
  TQDomNodeList list = docElement.elementsByTagName( "pages" );
  if ( list.count() == 0 ) {
    TQLabel *key = new TQLabel( i18n( "Pages:" ), page );
    TQLabel *value = new TQLabel( TQString::number( doc->pages() ), page );

    tqlayout->addWidget( key, row, 0 );
    tqlayout->addWidget( value, row, 1 );
  }

  // Fonts
  TQVBoxLayout *page2Layout = 0;
  if (doc->hasFonts())
  {
    TQFrame *page2 = addPage(i18n("Fonts"));
    page2Layout = new TQVBoxLayout(page2, 0, KDialog::spacingHint());
    KListView *lv = new KListView(page2);
    page2Layout->add(lv);
    doc->putFontInfo(lv);
  }

  // current width: left column + right column + dialog borders
  int width = tqlayout->tqminimumSize().width() + valMaxWidth + marginHint() + spacingHint() + marginHint() + 30;
  if (page2Layout)
  {
    width = TQMAX( width, page2Layout->tqsizeHint().width() + marginHint() + spacingHint() + 31 );
  }
  // stay inside the 2/3 of the screen width
  TQRect screenContainer = KGlobalSettings::desktopGeometry( this );
  width = TQMIN( width, 2*screenContainer.width()/3 );
  resize(width, 1);
}