Back to index

scribus-ng  1.3.4.dfsg+svn20071115
fontreplacedialog.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "fontreplacedialog.h"
00008 
00009 #include "fontreplacedialog.moc"
00010 #include <qvariant.h>
00011 #include <qlabel.h>
00012 #include <qtable.h>
00013 #include <qcheckbox.h>
00014 #include <qpushbutton.h>
00015 #include <qlayout.h>
00016 #include <qtooltip.h>
00017 #include <qwhatsthis.h>
00018 #include <qcombobox.h>
00019 
00020 #include "fontcombo.h"
00021 #include "commonstrings.h"
00022 
00023 extern QPixmap loadIcon(QString nam);
00024 
00025 FontReplaceDialog::FontReplaceDialog( QWidget* parent, QMap<QString, QString> *RList) : QDialog( parent, "FontReplaceDialog", true, 0 )
00026 {
00027        setCaption( tr( "Font Substitution" ) );
00028        setIcon(loadIcon("AppIcon.png"));
00029        ReplaceList = RList;
00030        FontReplaceDialogLayout = new QVBoxLayout( this, 10, 5, "FontReplaceDialogLayout");
00031 
00032        textLabel1 = new QLabel( this, "textLabel1" );
00033        textLabel1->setAlignment( int( QLabel::AlignVCenter ) );
00034        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>" );
00035        FontReplaceDialogLayout->addWidget( textLabel1 );
00036 
00037        replacementTable = new QTable( this, "replacementTable" );
00038        replacementTable->setNumCols( 2 );
00039        replacementTable->horizontalHeader()->setLabel( 0, tr( "Original Font" ) );
00040        replacementTable->horizontalHeader()->setLabel( 1, tr( "Substitution Font" ) );
00041        replacementTable->setSorting(false);
00042        replacementTable->setSelectionMode(QTable::NoSelection);
00043        replacementTable->setLeftMargin(0);
00044        replacementTable->verticalHeader()->hide();
00045        replacementTable->setNumRows(RList->count());
00046        int a = 0;
00047        QMap<QString,QString>::Iterator itfsu;
00048        for (itfsu = RList->begin(); itfsu != RList->end(); ++itfsu)
00049        {
00050               replacementTable->setText(a, 0, itfsu.key());
00051               FontCombo* item = new FontCombo(this);
00052               item->setCurrentText(itfsu.data());
00053               replacementTable->setCellWidget(a, 1, item);
00054               a++;
00055        }
00056        replacementTable->setColumnStretchable(0, true);
00057        replacementTable->setColumnStretchable(1, true);
00058        FontReplaceDialogLayout->addWidget( replacementTable );
00059 
00060        layout1 = new QHBoxLayout( 0, 0, 5, "layout1");
00061        stickyReplacements = new QCheckBox( this, "stickyReplacements" );
00062        stickyReplacements->setText( tr( "Make these substitutions permanent" ) );
00063        layout1->addWidget( stickyReplacements );
00064        spacer1 = new QSpacerItem( 71, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00065        layout1->addItem( spacer1 );
00066        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00067        layout1->addWidget( okButton );
00068        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00069        layout1->addWidget( cancelButton );
00070        FontReplaceDialogLayout->addLayout( layout1 );
00071        resize( QSize(474, 247).expandedTo(minimumSizeHint()) );
00072        clearWState( WState_Polished );
00073        QToolTip::add( cancelButton, "<qt>" + tr( "Cancels these font substitutions and stops loading the document.") + "</qt>" );
00074        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>" );
00075        QToolTip::add( okButton, "<qt>" + tr( "If you select OK, then save, these substitutions are made permanent in the document.") + "</qt>" );
00076        connect(okButton, SIGNAL(clicked()), this, SLOT(leaveOK()));
00077        connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
00078 }
00079 
00080 void FontReplaceDialog::closeEvent(QCloseEvent *closeEvent)
00081 {
00082        leaveOK();
00083        closeEvent->accept();
00084 }
00085 
00086 void FontReplaceDialog::leaveOK()
00087 {
00088        for (int a = 0; a < replacementTable->numRows(); ++a)
00089        {
00090               FontCombo* item = (FontCombo*)replacementTable->cellWidget(a, 1);
00091               ReplaceList->replace(replacementTable->text(a, 0), item->currentText());
00092        }
00093        if (okButton == sender())
00094               accept();
00095 }