Rev 2093 | Rev 2397 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
691 | cbradney | 1 | #include <qdialog.h> |
2 | #include <qpushbutton.h> |
||
3 | #include <qlabel.h> |
||
4 | #include <qlineedit.h> |
||
5 | #include <qspinbox.h> |
||
6 | #include <qstring.h> |
||
7 | #include <qlayout.h> |
||
8 | #include <qtooltip.h> |
||
9 | #include <qcombobox.h> |
||
10 | #include <qcheckbox.h> |
||
11 | #include <qtooltip.h> |
||
12 | |||
13 | |||
3 | paul | 14 | #include "mergedoc.h" |
15 | #include "mergedoc.moc" |
||
16 | #include "customfdialog.h" |
||
17 | #include "scribusXml.h" |
||
415 | Franz | 18 | #include "prefsfile.h" |
128 | Franz | 19 | |
617 | cbradney | 20 | #ifdef _MSC_VER |
21 | #if (_MSC_VER >= 1200) |
||
22 | #include "win-config.h" |
||
23 | #endif |
||
128 | Franz | 24 | #else |
25 | #include "config.h" |
||
26 | #endif |
||
27 | |||
3 | paul | 28 | #include <qcursor.h> |
29 | |||
30 | extern QPixmap loadIcon(QString nam); |
||
415 | Franz | 31 | extern PrefsFile* prefsFile; |
3 | paul | 32 | |
691 | cbradney | 33 | MergeDoc::MergeDoc( QWidget* parent, bool importMasterPages, int targetDocPageCount, int currentPage ) : |
326 | Franz | 34 | QDialog( parent, "merge", true, 0 ) |
3 | paul | 35 | { |
691 | cbradney | 36 | masterPages = importMasterPages; |
2093 | cbradney | 37 | setCaption( (masterPages) ? tr("Import Master Page") : tr( "Import Page(s)" ) ); |
83 | Franz | 38 | setIcon(loadIcon("AppIcon.png")); |
691 | cbradney | 39 | |
40 | count = 0; |
||
41 | dialogLayout = new QVBoxLayout( this, 10, 10, "dialogLayout"); |
||
42 | fromInfoLayout = new QGridLayout(1, 1, 5, "layout"); |
||
43 | fromDocData = new QLineEdit( this, "fromDocData" ); |
||
44 | fromDocLabel = new QLabel( fromDocData, tr( "&From Document:"), this, "fromDocLabel" ); |
||
45 | fromInfoLayout->addWidget( fromDocLabel, 0, 0 ); |
||
46 | fromInfoLayout->addWidget( fromDocData, 0, 1 ); |
||
47 | changeButton = new QPushButton( tr( "Chan&ge..." ), this, "changeButton" ); |
||
48 | changeButton->setAutoDefault( false ); |
||
49 | fromInfoLayout->addWidget( changeButton, 0, 2 ); |
||
50 | importPageLabel = new QLabel( tr( "&Import Page(s):" ), this, "importPageLabel" ); |
||
51 | fromInfoLayout->addWidget( importPageLabel, 1, 0 ); |
||
52 | if (masterPages) |
||
240 | Franz | 53 | { |
2093 | cbradney | 54 | importPageLabel->setText( tr("&Import Master Page") ); |
691 | cbradney | 55 | masterPageNameData = new QComboBox( false, this, "masterPageNameData" ); |
56 | masterPageNameData->setEnabled(false); |
||
57 | importPageLabel->setBuddy( masterPageNameData ); |
||
58 | fromInfoLayout->addWidget( masterPageNameData, 1, 1 ); |
||
240 | Franz | 59 | } |
118 | Franz | 60 | else |
240 | Franz | 61 | { |
691 | cbradney | 62 | pageNumberData = new QLineEdit( this, "pageNumberData" ); |
63 | pageNumberData->setEnabled(false); |
||
64 | importPageLabel->setBuddy( pageNumberData ); |
||
2217 | cbradney | 65 | QToolTip::add( pageNumberData, "<qt>" + tr( "Insert a comma separated list of tokens import where " |
66 | "a token can be * for all the pages, 1-5 for " |
||
67 | "a range of pages or a single page number.") + "</qt>"); |
||
691 | cbradney | 68 | fromInfoLayout->addWidget( pageNumberData, 1, 1 ); |
326 | Franz | 69 | fromLabel = new QLabel(this, "fromLabel"); |
70 | fromLabel->setText(tr(" from 0")); |
||
691 | cbradney | 71 | fromInfoLayout->addWidget( fromLabel, 1, 2 ); |
72 | createPageData = new QCheckBox( this, "createPageData" ); |
||
73 | createPageData->setText(tr("Create Page(s)")); |
||
74 | fromInfoLayout->addWidget( createPageData, 2, 0 ); |
||
75 | importWhereData = new QComboBox( false, this, "positionCombo" ); |
||
76 | importWhereData->setEnabled(false); |
||
77 | importWhereData->insertItem(tr("Before Page")); |
||
78 | importWhereData->insertItem(tr("After Page")); |
||
79 | importWhereData->insertItem(tr("At End")); |
||
80 | importWhereData->setCurrentItem( 2 ); |
||
81 | fromInfoLayout->addWidget( importWhereData, 2, 1 ); |
||
82 | importWherePageData = new QSpinBox( 1, targetDocPageCount, 1, this, "pageSpin" ); |
||
83 | importWherePageData->setValue( currentPage ); |
||
84 | importWherePageData->setEnabled(false); |
||
85 | fromInfoLayout->addWidget( importWherePageData, 2, 2 ); |
||
326 | Franz | 86 | } |
691 | cbradney | 87 | |
88 | dialogLayout->addLayout( fromInfoLayout ); |
||
89 | importCancelLayout = new QHBoxLayout( 0, 0, 2, "importCancelLayout"); |
||
3 | paul | 90 | QSpacerItem* spacer = new QSpacerItem( 41, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
691 | cbradney | 91 | importCancelLayout->addItem( spacer ); |
92 | importButton = new QPushButton( tr( "&Import" ), this, "importButton" ); |
||
93 | importButton->setEnabled(false); |
||
94 | importCancelLayout->addWidget( importButton ); |
||
95 | cancelButton = new QPushButton( tr( "&Cancel" ), this, "cancelButton" ); |
||
96 | cancelButton->setDefault( TRUE ); |
||
97 | importCancelLayout->addWidget( cancelButton ); |
||
98 | dialogLayout->addLayout( importCancelLayout ); |
||
3 | paul | 99 | resize( QSize(350, 134).expandedTo(minimumSizeHint()) ); |
100 | clearWState( WState_Polished ); |
||
691 | cbradney | 101 | connect( importButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
102 | connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
||
103 | connect( changeButton, SIGNAL( clicked() ), this, SLOT( changeFile() ) ); |
||
104 | if (!masterPages) |
||
338 | Franz | 105 | { |
691 | cbradney | 106 | connect( importWhereData, SIGNAL( activated(int) ), this, SLOT( checkDestPageStatus(int) ) ); |
107 | connect( createPageData, SIGNAL( clicked() ), this, SLOT( enableCreateWidgets() ) ); |
||
338 | Franz | 108 | } |
3 | paul | 109 | } |
110 | |||
111 | /* |
||
112 | * Destroys the object and frees any allocated resources |
||
113 | */ |
||
114 | MergeDoc::~MergeDoc() |
||
115 | { |
||
116 | // no need to delete child widgets, Qt does it all for us |
||
117 | } |
||
118 | |||
691 | cbradney | 119 | void MergeDoc::changeFile() |
3 | paul | 120 | { |
121 | QString fn; |
||
118 | Franz | 122 | int dummy; |
123 | bool ret = false; |
||
691 | cbradney | 124 | count = 0; |
415 | Franz | 125 | PrefsContext* dirs = prefsFile->getContext("dirs"); |
126 | QString wdir = dirs->get("merge", "."); |
||
3 | paul | 127 | #ifdef HAVE_LIBZ |
1756 | fschmid | 128 | CustomFDialog *dia = new CustomFDialog(this, wdir, tr("Open"), tr("Documents (*.sla *.sla.gz *.scd *.scd.gz);;All Files (*)")); |
3 | paul | 129 | #else |
1756 | fschmid | 130 | CustomFDialog *dia = new CustomFDialog(this, wdir, tr("Open"), tr("Documents (*.sla *.scd);;All Files (*)")); |
3 | paul | 131 | #endif |
691 | cbradney | 132 | if (fromDocData->text() != "") |
1756 | fschmid | 133 | dia->setSelection(fromDocData->text()); |
134 | if (dia->exec() == QDialog::Accepted) |
||
240 | Franz | 135 | { |
1756 | fschmid | 136 | fn = dia->selectedFile(); |
3 | paul | 137 | if (!fn.isEmpty()) |
240 | Franz | 138 | { |
415 | Franz | 139 | dirs->set("merge", fn.left(fn.findRev("/"))); |
3 | paul | 140 | qApp->setOverrideCursor(QCursor(waitCursor), true); |
141 | ScriXmlDoc *ss = new ScriXmlDoc(); |
||
691 | cbradney | 142 | if (masterPages) |
143 | ret = ss->ReadPageCount(fn, &dummy, &count); |
||
118 | Franz | 144 | else |
691 | cbradney | 145 | ret = ss->ReadPageCount(fn, &count, &dummy); |
3 | paul | 146 | qApp->setOverrideCursor(QCursor(arrowCursor), true); |
691 | cbradney | 147 | if ((ret) && (count != 0)) |
240 | Franz | 148 | { |
691 | cbradney | 149 | fromDocData->setText(fn); |
150 | importButton->setEnabled(true); |
||
151 | if (masterPages) |
||
240 | Franz | 152 | { |
691 | cbradney | 153 | masterPageNameData->clear(); |
154 | masterPageNameData->setEnabled(true); |
||
155 | masterPageNameData->insertStringList(ss->MNames); |
||
240 | Franz | 156 | } |
118 | Franz | 157 | else |
240 | Franz | 158 | { |
691 | cbradney | 159 | pageNumberData->setEnabled(true); |
240 | Franz | 160 | } |
691 | cbradney | 161 | if (!masterPages) |
162 | fromLabel->setText( tr(" from %1").arg(count)); |
||
240 | Franz | 163 | } |
3 | paul | 164 | delete ss; |
165 | } |
||
240 | Franz | 166 | } |
3 | paul | 167 | else |
240 | Franz | 168 | { |
691 | cbradney | 169 | fromDocData->setText(""); |
170 | count = 0; |
||
171 | importButton->setEnabled(false); |
||
172 | if (masterPages) |
||
240 | Franz | 173 | { |
691 | cbradney | 174 | masterPageNameData->clear(); |
175 | masterPageNameData->setEnabled(false); |
||
240 | Franz | 176 | } |
118 | Franz | 177 | else |
240 | Franz | 178 | { |
691 | cbradney | 179 | pageNumberData->setEnabled(false); |
240 | Franz | 180 | } |
691 | cbradney | 181 | if (!masterPages) |
182 | fromLabel->setText( tr(" from %1").arg(count)); |
||
240 | Franz | 183 | } |
1756 | fschmid | 184 | delete dia; |
3 | paul | 185 | } |
186 | |||
691 | cbradney | 187 | void MergeDoc::checkDestPageStatus(int positionComboSelection) |
326 | Franz | 188 | { |
691 | cbradney | 189 | importWherePageData->setDisabled( positionComboSelection == 2 ); |
326 | Franz | 190 | } |
191 | |||
192 | void MergeDoc::enableCreateWidgets() |
||
193 | { |
||
691 | cbradney | 194 | if (createPageData->isChecked()) |
326 | Franz | 195 | { |
691 | cbradney | 196 | importWhereData->setEnabled(true); |
197 | if (importWhereData->currentItem() != 2) |
||
198 | importWherePageData->setEnabled(true); |
||
326 | Franz | 199 | } |
200 | else |
||
201 | { |
||
691 | cbradney | 202 | importWhereData->setEnabled(false); |
203 | importWherePageData->setEnabled(false); |
||
326 | Franz | 204 | } |
205 | } |
||
691 | cbradney | 206 | |
207 | const QString MergeDoc::getFromDoc() |
||
208 | { |
||
209 | return fromDocData->text(); |
||
210 | } |
||
211 | |||
212 | const int MergeDoc::getMasterPageNameItem() |
||
213 | { |
||
214 | return masterPageNameData->currentItem(); |
||
215 | } |
||
216 | |||
217 | const int MergeDoc::getImportWhere() |
||
218 | { |
||
219 | return importWhereData->currentItem(); |
||
220 | } |
||
221 | |||
222 | const int MergeDoc::getImportWherePage() |
||
223 | { |
||
224 | return importWherePageData->value(); |
||
225 | } |
||
226 | |||
227 | const bool MergeDoc::getCreatePageChecked() |
||
228 | { |
||
229 | return createPageData->isChecked(); |
||
230 | } |
||
231 | |||
232 | const QString MergeDoc::getPageNumbers() |
||
233 | { |
||
234 | return pageNumberData->text(); |
||
235 | } |
||
236 | |||
237 | const int MergeDoc::getPageCounter() |
||
238 | { |
||
239 | return count; |
||
240 | } |