Subversion Repositories Scribus

Rev

Rev 3582 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1428 fschmid 7
#include "fontreplacedialog.h"
8
 
9
#include "fontreplacedialog.moc"
10
#include <qvariant.h>
11
#include <qlabel.h>
12
#include <qtable.h>
13
#include <qcheckbox.h>
14
#include <qpushbutton.h>
15
#include <qlayout.h>
16
#include <qtooltip.h>
17
#include <qwhatsthis.h>
18
#include <qcombobox.h>
2952 cbradney 19
 
1428 fschmid 20
#include "fontcombo.h"
2952 cbradney 21
#include "commonstrings.h"
22
 
1428 fschmid 23
extern QPixmap loadIcon(QString nam);
24
 
2834 cbradney 25
FontReplaceDialog::FontReplaceDialog( QWidget* parent, QMap<QString, QString> *RList) : QDialog( parent, "FontReplaceDialog", true, 0 )
1428 fschmid 26
{
27
        setCaption( tr( "Font Substitution" ) );
28
        setIcon(loadIcon("AppIcon.png"));
29
        ReplaceList = RList;
30
        FontReplaceDialogLayout = new QVBoxLayout( this, 10, 5, "FontReplaceDialogLayout");
31
 
32
        textLabel1 = new QLabel( this, "textLabel1" );
33
        textLabel1->setAlignment( int( QLabel::AlignVCenter ) );
3188 mrdocs 34
        textLabel1->setText( "<qt>" + tr("This document contains some fonts that are not installed on your system, please choose a suitable replacement for them. Cancel will stop the document from loading.") + "</qt>" );
1428 fschmid 35
        FontReplaceDialogLayout->addWidget( textLabel1 );
36
 
37
        replacementTable = new QTable( this, "replacementTable" );
38
        replacementTable->setNumCols( 2 );
39
        replacementTable->horizontalHeader()->setLabel( 0, tr( "Original Font" ) );
40
        replacementTable->horizontalHeader()->setLabel( 1, tr( "Substitution Font" ) );
41
        replacementTable->setSorting(false);
42
        replacementTable->setSelectionMode(QTable::NoSelection);
43
        replacementTable->setLeftMargin(0);
44
        replacementTable->verticalHeader()->hide();
45
        replacementTable->setNumRows(RList->count());
46
        int a = 0;
47
        QMap<QString,QString>::Iterator itfsu;
48
        for (itfsu = RList->begin(); itfsu != RList->end(); ++itfsu)
49
        {
50
                replacementTable->setText(a, 0, itfsu.key());
2834 cbradney 51
                FontCombo* item = new FontCombo(this);
1428 fschmid 52
                item->setCurrentText(itfsu.data());
53
                replacementTable->setCellWidget(a, 1, item);
54
                a++;
55
        }
56
        replacementTable->setColumnStretchable(0, true);
57
        replacementTable->setColumnStretchable(1, true);
58
        FontReplaceDialogLayout->addWidget( replacementTable );
59
 
60
        layout1 = new QHBoxLayout( 0, 0, 5, "layout1");
61
        stickyReplacements = new QCheckBox( this, "stickyReplacements" );
62
        stickyReplacements->setText( tr( "Make these substitutions permanent" ) );
63
        layout1->addWidget( stickyReplacements );
64
        spacer1 = new QSpacerItem( 71, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
65
        layout1->addItem( spacer1 );
2952 cbradney 66
        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
1428 fschmid 67
        layout1->addWidget( okButton );
3150 fschmid 68
        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
69
        layout1->addWidget( cancelButton );
1428 fschmid 70
        FontReplaceDialogLayout->addLayout( layout1 );
71
        resize( QSize(474, 247).expandedTo(minimumSizeHint()) );
72
        clearWState( WState_Polished );
3184 mrdocs 73
        QToolTip::add( cancelButton, "<qt>" + tr( "Cancels these font substitutions and stops loading the document.") + "</qt>" );
3358 cbradney 74
        QToolTip::add( stickyReplacements, "<qt>" + tr( "Enabling this tells Scribus to use these replacements for missing fonts permanently in all future layouts. This can be reverted or changed in Edit > Preferences > Fonts.") + "</qt>" );
75
        QToolTip::add( okButton, "<qt>" + tr( "If you select OK, then save, these substitutions are made permanent in the document.") + "</qt>" );
3582 fschmid 76
        connect(okButton, SIGNAL(clicked()), this, SLOT(leaveOK()));
3150 fschmid 77
        connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
1428 fschmid 78
}
79
 
80
void FontReplaceDialog::closeEvent(QCloseEvent *closeEvent)
81
{
3582 fschmid 82
        leaveOK();
83
        closeEvent->accept();
84
}
85
 
86
void FontReplaceDialog::leaveOK()
87
{
1428 fschmid 88
        for (int a = 0; a < replacementTable->numRows(); ++a)
89
        {
90
                FontCombo* item = (FontCombo*)replacementTable->cellWidget(a, 1);
91
                ReplaceList->replace(replacementTable->text(a, 0), item->currentText());
92
        }
3582 fschmid 93
        if (okButton == sender())
94
                accept();
1428 fschmid 95
}