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 */
7 #include "fontreplacedialog.h"
8
9 #include <QPixmap>
10 #include <QHBoxLayout>
11 #include <QVBoxLayout>
12 #include <QLabel>
13 #include <QTableWidget>
14 #include <QCheckBox>
15 #include <QPushButton>
16 #include <QHeaderView>
17 #include <QSpacerItem>
18 #include <QToolTip>
19 #include <QCloseEvent>
20
21 #include "commonstrings.h"
22 #include "fontcombo.h"
23 #include "iconmanager.h"
24 #include "scribusstructs.h"
25 #include "util.h"
26
FontReplaceDialog(QWidget * parent,QMap<QString,QString> * RList)27 FontReplaceDialog::FontReplaceDialog( QWidget* parent, QMap<QString, QString> *RList) : QDialog( parent )
28 {
29 setModal(true);
30 setWindowTitle( tr( "Font Substitution" ) );
31 setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
32 ReplaceList = RList;
33 FontReplaceDialogLayout = new QVBoxLayout( this );
34 FontReplaceDialogLayout->setContentsMargins(9, 9, 9, 9);
35 FontReplaceDialogLayout->setSpacing(6);
36
37 textLabel1 = new QLabel(this);
38 textLabel1->setAlignment(Qt::AlignVCenter);
39 textLabel1->setWordWrap(true);
40 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>" );
41 FontReplaceDialogLayout->addWidget(textLabel1);
42
43 replacementTable = new QTableWidget(0, 2, this);
44 replacementTable->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Original Font")));
45 replacementTable->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Substitution Font")));
46 replacementTable->setSortingEnabled(false);
47 replacementTable->setSelectionBehavior(QAbstractItemView::SelectRows);
48 QHeaderView *header = replacementTable->horizontalHeader();
49 header->setSectionsClickable(false);
50 header->setSectionsMovable(false);
51 header->setSectionResizeMode(0, QHeaderView::Stretch);
52 header->setSectionResizeMode(1, QHeaderView::ResizeToContents);
53 replacementTable->verticalHeader()->hide();
54 replacementTable->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
55 replacementTable->setRowCount(RList->count());
56
57 int i = 0;
58 for (auto itfsu = RList->begin(); itfsu != RList->end(); ++itfsu)
59 {
60 replacementTable->setItem(i, 0, new QTableWidgetItem(itfsu.key()));
61 FontCombo* item = new FontCombo(this);
62 setCurrentComboItem(item, itfsu.value());
63 replacementTable->setCellWidget(i, 1, item);
64 i++;
65 }
66 FontReplaceDialogLayout->addWidget( replacementTable );
67
68 layout1 = new QHBoxLayout;
69 layout1->setContentsMargins(0, 0, 0, 0);
70 layout1->setSpacing(6);
71 stickyReplacements = new QCheckBox( this );
72 stickyReplacements->setText( tr( "Make these substitutions permanent" ) );
73 layout1->addWidget(stickyReplacements);
74 QSpacerItem* spacer1 = new QSpacerItem(2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum);
75 layout1->addItem(spacer1);
76 okButton = new QPushButton(CommonStrings::tr_OK, this);
77 layout1->addWidget(okButton);
78 cancelButton = new QPushButton(CommonStrings::tr_Cancel, this);
79 layout1->addWidget(cancelButton);
80 FontReplaceDialogLayout->addLayout(layout1);
81 resize( QSize(450, 250) );
82
83 cancelButton->setToolTip( "<qt>" + tr( "Cancels these font substitutions and stops loading the document") + "</qt>" );
84 stickyReplacements->setToolTip( "<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 File > Preferences > Fonts.") + "</qt>" );
85 okButton->setToolTip( "<qt>" + tr( "If you select OK, then save, these substitutions are made permanent in the document") + "</qt>" );
86 connect(okButton, SIGNAL(clicked()), this, SLOT(leaveOK()));
87 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
88 }
89
closeEvent(QCloseEvent * closeEvent)90 void FontReplaceDialog::closeEvent(QCloseEvent *closeEvent)
91 {
92 leaveOK();
93 closeEvent->accept();
94 }
95
leaveOK()96 void FontReplaceDialog::leaveOK()
97 {
98 for (int i = 0; i < replacementTable->rowCount(); ++i)
99 {
100 FontCombo* item = (FontCombo*)replacementTable->cellWidget(i, 1);
101 ReplaceList->remove(replacementTable->item(i, 0)->text());
102 ReplaceList->insert(replacementTable->item(i, 0)->text(), item->currentText());
103 }
104 if (okButton == sender())
105 accept();
106 }
107