Rev 2533 | Rev 2877 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | #include "muster.h" |
2 | #include "muster.moc" |
||
3 | #include "newtemp.h" |
||
118 | Franz | 4 | #include "mergedoc.h" |
923 | cbradney | 5 | #include <qlayout.h> |
6 | #include <qlistbox.h> |
||
7 | #include <qpushbutton.h> |
||
3 | paul | 8 | #include <qmessagebox.h> |
118 | Franz | 9 | #include <qcursor.h> |
923 | cbradney | 10 | #include <qstring.h> |
1414 | fschmid | 11 | #include <qtooltip.h> |
923 | cbradney | 12 | #include "scribusdoc.h" |
13 | #include "scribusview.h" |
||
2533 | craig | 14 | #include "util.h" |
3 | paul | 15 | |
2093 | cbradney | 16 | MasterPagesPalette::MasterPagesPalette( QWidget* parent, ScribusDoc *pCurrentDoc, ScribusView *pCurrentView, QString masterPageName) |
225 | Franz | 17 | : QDialog( parent, "Muster", false, WDestructiveClose) |
3 | paul | 18 | { |
2093 | cbradney | 19 | setCaption( tr( "Edit Master Pages" ) ); |
225 | Franz | 20 | setIcon(loadIcon("AppIcon.png")); |
923 | cbradney | 21 | currentDoc = pCurrentDoc; |
22 | currentView = pCurrentView; |
||
2093 | cbradney | 23 | masterPagesLayout = new QVBoxLayout( this, 5, 5 ); |
1414 | fschmid | 24 | buttonLayout = new QHBoxLayout; |
25 | buttonLayout->setSpacing( 5 ); |
||
923 | cbradney | 26 | buttonLayout->setMargin( 0 ); |
2439 | cbradney | 27 | importButton = new QToolButton(this, "importButton" ); |
2093 | cbradney | 28 | importButton->setPixmap(loadIcon("fileopen.png")); |
2439 | cbradney | 29 | newButton = new QToolButton(this, "newButton" ); |
1414 | fschmid | 30 | newButton->setPixmap(loadIcon("filenew.png")); |
2439 | cbradney | 31 | duplicateButton = new QToolButton(this, "DublicateB" ); |
1414 | fschmid | 32 | duplicateButton->setPixmap(loadIcon("editcopy22.png")); |
2439 | cbradney | 33 | deleteButton = new QToolButton(this, "deleteButton" ); |
1414 | fschmid | 34 | deleteButton->setPixmap(loadIcon("edittrash.png")); |
923 | cbradney | 35 | buttonLayout->addWidget( newButton ); |
36 | buttonLayout->addWidget( duplicateButton ); |
||
2093 | cbradney | 37 | buttonLayout->addWidget( importButton ); |
923 | cbradney | 38 | buttonLayout->addWidget( deleteButton ); |
2093 | cbradney | 39 | masterPagesLayout->addLayout( buttonLayout ); |
40 | masterPageData = new QListBox( this, "masterPageData" ); |
||
41 | masterPageData->setMinimumSize( QSize( 100, 240 ) ); |
||
42 | masterPagesLayout->addWidget( masterPageData ); |
||
3 | paul | 43 | |
1414 | fschmid | 44 | |
2093 | cbradney | 45 | if (masterPageName == "") |
161 | Franz | 46 | { |
225 | Franz | 47 | sMuster = "Normal"; |
2093 | cbradney | 48 | updateMasterPageList(sMuster); |
49 | currentView->showMasterPage(0); |
||
161 | Franz | 50 | } |
51 | else |
||
52 | { |
||
2093 | cbradney | 53 | sMuster = masterPageName; |
54 | updateMasterPageList(sMuster); |
||
55 | currentView->showMasterPage(currentDoc->MasterNames[sMuster]); |
||
161 | Franz | 56 | } |
923 | cbradney | 57 | |
225 | Franz | 58 | setMaximumSize(sizeHint()); |
3 | paul | 59 | |
1414 | fschmid | 60 | QToolTip::add( duplicateButton, tr( "Duplicates the selected master page" ) ); |
61 | QToolTip::add( deleteButton, tr( "Deletes the selected master page" ) ); |
||
62 | QToolTip::add( newButton, tr( "Adds a new master page" ) ); |
||
2093 | cbradney | 63 | QToolTip::add( importButton, tr( "Imports master pages from another document" ) ); |
225 | Franz | 64 | // signals and slots connections |
2093 | cbradney | 65 | connect(duplicateButton, SIGNAL(clicked()), this, SLOT(duplicateMasterPage())); |
66 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteMasterPage())); |
||
67 | connect(newButton, SIGNAL(clicked()), this, SLOT(newMasterPage())); |
||
68 | connect(importButton, SIGNAL(clicked()), this, SLOT(appendPage())); |
||
69 | connect(masterPageData, SIGNAL(highlighted(QListBoxItem*)), this, SLOT(selectMasterPage(QListBoxItem*))); |
||
3 | paul | 70 | } |
71 | |||
2093 | cbradney | 72 | void MasterPagesPalette::reject() |
1830 | fschmid | 73 | { |
74 | emit finished(); |
||
75 | QDialog::reject(); |
||
76 | } |
||
77 | |||
2093 | cbradney | 78 | void MasterPagesPalette::closeEvent(QCloseEvent *closeEvent) |
3 | paul | 79 | { |
923 | cbradney | 80 | emit finished(); |
81 | closeEvent->accept(); |
||
3 | paul | 82 | } |
83 | |||
2093 | cbradney | 84 | void MasterPagesPalette::deleteMasterPage() |
3 | paul | 85 | { |
86 | if (sMuster == "Normal") |
||
87 | return; |
||
161 | Franz | 88 | int exit=QMessageBox::warning(this, |
225 | Franz | 89 | tr("Warning"), |
2093 | cbradney | 90 | tr("Do you really want to delete this master page?"), |
348 | Franz | 91 | tr("&No"), |
92 | tr("&Yes"), |
||
225 | Franz | 93 | 0, QMessageBox::No, QMessageBox::Yes); |
161 | Franz | 94 | if (exit == 1) |
225 | Franz | 95 | { |
2142 | cbradney | 96 | currentDoc->pageCount = currentDoc->Pages.count(); |
2776 | fschmid | 97 | emit removePage(currentDoc->MasterNames[sMuster]); |
923 | cbradney | 98 | currentDoc->MasterNames.clear(); |
99 | for (uint a = 0; a < currentDoc->Pages.count(); ++a) |
||
100 | currentDoc->MasterNames[currentDoc->Pages.at(a)->PageNam] = currentDoc->Pages.at(a)->PageNr; |
||
101 | for (uint b = 0; b < currentDoc->DocPages.count(); ++b) |
||
161 | Franz | 102 | { |
923 | cbradney | 103 | if (currentDoc->DocPages.at(b)->MPageNam == sMuster) |
104 | currentDoc->DocPages.at(b)->MPageNam = "Normal"; |
||
161 | Franz | 105 | } |
2142 | cbradney | 106 | currentDoc->pageCount = 1; |
3 | paul | 107 | sMuster = "Normal"; |
2093 | cbradney | 108 | updateMasterPageList(sMuster); |
1507 | fschmid | 109 | currentDoc->MasterPages = currentDoc->Pages; |
2055 | craig | 110 | emit docAltered(currentDoc); |
161 | Franz | 111 | } |
3 | paul | 112 | } |
113 | |||
2093 | cbradney | 114 | void MasterPagesPalette::duplicateMasterPage() |
3 | paul | 115 | { |
2093 | cbradney | 116 | QString MasterPageName; |
225 | Franz | 117 | int nr; |
118 | bool atf; |
||
1065 | cbradney | 119 | struct CopyPasteBuffer Buffer; |
2093 | cbradney | 120 | NewTm *dia = new NewTm(this, tr("&Name:"), tr("New Master Page"), currentDoc); |
225 | Franz | 121 | dia->Answer->setText( tr("Copy of %1").arg(sMuster)); |
122 | dia->Answer->selectAll(); |
||
123 | if (dia->exec()) |
||
124 | { |
||
2093 | cbradney | 125 | MasterPageName = dia->Answer->text(); |
126 | while (currentDoc->MasterNames.contains(MasterPageName) || (MasterPageName == "Normal")) |
||
225 | Franz | 127 | { |
128 | if (!dia->exec()) |
||
129 | { |
||
130 | delete dia; |
||
131 | return; |
||
132 | } |
||
2093 | cbradney | 133 | MasterPageName = dia->Answer->text(); |
225 | Franz | 134 | } |
923 | cbradney | 135 | nr = currentDoc->Pages.count(); |
2093 | cbradney | 136 | currentDoc->MasterNames.insert(MasterPageName, nr); |
2142 | cbradney | 137 | currentDoc->pageCount = 0; |
923 | cbradney | 138 | atf = currentDoc->PageAT; |
139 | currentDoc->PageAT = false; |
||
140 | emit createNew(nr); |
||
1756 | fschmid | 141 | currentDoc->loading = true; |
923 | cbradney | 142 | if (currentDoc->PageFP) |
143 | currentDoc->Pages.at(nr)->LeftPg = dia->Links->currentItem() == 0 ? true : false; |
||
144 | int inde = currentDoc->MasterNames[sMuster]; |
||
457 | fschmid | 145 | QMap<int,int> TableID; |
234 | Franz | 146 | QPtrList<PageItem> TableItems; |
147 | TableID.clear(); |
||
148 | TableItems.clear(); |
||
923 | cbradney | 149 | if (currentDoc->Pages.at(inde)->YGuides.count() != 0) |
449 | fschmid | 150 | { |
1065 | cbradney | 151 | currentDoc->currentPage->YGuides.clear(); |
923 | cbradney | 152 | for (uint y = 0; y < currentDoc->Pages.at(inde)->YGuides.count(); ++y) |
449 | fschmid | 153 | { |
1065 | cbradney | 154 | currentDoc->currentPage->YGuides.append(currentDoc->Pages.at(inde)->YGuides[y]); |
449 | fschmid | 155 | } |
1065 | cbradney | 156 | qHeapSort(currentDoc->currentPage->YGuides); |
449 | fschmid | 157 | } |
923 | cbradney | 158 | if (currentDoc->Pages.at(inde)->XGuides.count() != 0) |
449 | fschmid | 159 | { |
923 | cbradney | 160 | for (uint x = 0; x < currentDoc->Pages.at(inde)->XGuides.count(); ++x) |
449 | fschmid | 161 | { |
1065 | cbradney | 162 | currentDoc->currentPage->XGuides.append(currentDoc->Pages.at(inde)->XGuides[x]); |
449 | fschmid | 163 | } |
1065 | cbradney | 164 | qHeapSort(currentDoc->currentPage->XGuides); |
449 | fschmid | 165 | } |
923 | cbradney | 166 | uint end = currentDoc->Items.count(); |
457 | fschmid | 167 | for (uint a = 0; a < end; ++a) |
161 | Franz | 168 | { |
923 | cbradney | 169 | if (currentDoc->Items.at(a)->OwnPage == inde) |
234 | Franz | 170 | { |
923 | cbradney | 171 | CopyPageItem(&Buffer, currentDoc->Items.at(a)); |
172 | currentView->PasteItem(&Buffer, true, true); |
||
173 | PageItem* Neu = currentDoc->Items.at(currentDoc->Items.count()-1); |
||
457 | fschmid | 174 | if (Neu->isTableItem) |
175 | { |
||
176 | TableItems.append(Neu); |
||
177 | TableID.insert(a, Neu->ItemNr); |
||
178 | } |
||
234 | Franz | 179 | } |
161 | Franz | 180 | } |
234 | Franz | 181 | if (TableItems.count() != 0) |
182 | { |
||
183 | for (uint ttc = 0; ttc < TableItems.count(); ++ttc) |
||
184 | { |
||
185 | PageItem* ta = TableItems.at(ttc); |
||
186 | if (ta->TopLinkID != -1) |
||
923 | cbradney | 187 | ta->TopLink = currentDoc->Items.at(TableID[ta->TopLinkID]); |
234 | Franz | 188 | else |
189 | ta->TopLink = 0; |
||
190 | if (ta->LeftLinkID != -1) |
||
923 | cbradney | 191 | ta->LeftLink = currentDoc->Items.at(TableID[ta->LeftLinkID]); |
234 | Franz | 192 | else |
193 | ta->LeftLink = 0; |
||
194 | if (ta->RightLinkID != -1) |
||
923 | cbradney | 195 | ta->RightLink = currentDoc->Items.at(TableID[ta->RightLinkID]); |
234 | Franz | 196 | else |
197 | ta->RightLink = 0; |
||
198 | if (ta->BottomLinkID != -1) |
||
923 | cbradney | 199 | ta->BottomLink = currentDoc->Items.at(TableID[ta->BottomLinkID]); |
234 | Franz | 200 | else |
201 | ta->BottomLink = 0; |
||
202 | } |
||
203 | } |
||
923 | cbradney | 204 | currentView->Deselect(true); |
205 | currentView->DrawNew(); |
||
2093 | cbradney | 206 | currentDoc->Pages.at(nr)->setPageName(MasterPageName); |
923 | cbradney | 207 | currentDoc->Pages.at(nr)->MPageNam = ""; |
2093 | cbradney | 208 | updateMasterPageList(MasterPageName); |
923 | cbradney | 209 | currentDoc->PageAT = atf; |
1507 | fschmid | 210 | currentDoc->MasterPages = currentDoc->Pages; |
1756 | fschmid | 211 | currentDoc->loading = false; |
212 | currentView->DrawNew(); |
||
2055 | craig | 213 | emit docAltered(currentDoc); |
225 | Franz | 214 | } |
215 | delete dia; |
||
3 | paul | 216 | } |
217 | |||
2093 | cbradney | 218 | void MasterPagesPalette::newMasterPage() |
3 | paul | 219 | { |
2093 | cbradney | 220 | QString MasterPageName; |
225 | Franz | 221 | int nr; |
222 | bool atf; |
||
2093 | cbradney | 223 | NewTm *dia = new NewTm(this, tr("Name:"), tr("New MasterPage"), currentDoc); |
224 | dia->Answer->setText( tr("New Master Page")); |
||
225 | Franz | 225 | dia->Answer->selectAll(); |
226 | if (dia->exec()) |
||
227 | { |
||
2093 | cbradney | 228 | MasterPageName = dia->Answer->text(); |
229 | while (currentDoc->MasterNames.contains(MasterPageName) || (MasterPageName == "Normal")) |
||
225 | Franz | 230 | { |
231 | if (!dia->exec()) |
||
232 | { |
||
233 | delete dia; |
||
234 | return; |
||
235 | } |
||
2093 | cbradney | 236 | MasterPageName = dia->Answer->text(); |
225 | Franz | 237 | } |
923 | cbradney | 238 | nr = currentDoc->Pages.count(); |
2093 | cbradney | 239 | currentDoc->MasterNames.insert(MasterPageName, nr); |
2142 | cbradney | 240 | currentDoc->pageCount = 0; |
923 | cbradney | 241 | atf = currentDoc->PageAT; |
242 | currentDoc->PageAT = false; |
||
243 | emit createNew(nr); |
||
244 | if (currentDoc->PageFP) |
||
245 | currentDoc->Pages.at(nr)->LeftPg = dia->Links->currentItem() == 0 ? true : false; |
||
2093 | cbradney | 246 | currentDoc->Pages.at(nr)->setPageName(MasterPageName); |
923 | cbradney | 247 | currentDoc->Pages.at(nr)->MPageNam = ""; |
2093 | cbradney | 248 | updateMasterPageList(MasterPageName); |
923 | cbradney | 249 | currentDoc->PageAT = atf; |
2093 | cbradney | 250 | currentView->showMasterPage(currentDoc->MasterNames[MasterPageName]); |
1507 | fschmid | 251 | currentDoc->MasterPages = currentDoc->Pages; |
2055 | craig | 252 | emit docAltered(currentDoc); |
225 | Franz | 253 | } |
254 | delete dia; |
||
3 | paul | 255 | } |
256 | |||
2093 | cbradney | 257 | void MasterPagesPalette::appendPage() |
118 | Franz | 258 | { |
2093 | cbradney | 259 | QString MasterPageName, MasterPageName2; |
161 | Franz | 260 | int nr; |
261 | bool atf; |
||
118 | Franz | 262 | MergeDoc *dia = new MergeDoc(this, true); |
263 | if (dia->exec()) |
||
161 | Franz | 264 | { |
118 | Franz | 265 | qApp->setOverrideCursor(QCursor(waitCursor), true); |
923 | cbradney | 266 | nr = currentDoc->Pages.count(); |
2142 | cbradney | 267 | currentDoc->pageCount = 0; |
923 | cbradney | 268 | atf = currentDoc->PageAT; |
269 | currentDoc->PageAT = false; |
||
270 | emit createNew(nr); |
||
118 | Franz | 271 | qApp->processEvents(); |
923 | cbradney | 272 | emit loadPage(dia->getFromDoc(), dia->getMasterPageNameItem(), true); |
118 | Franz | 273 | qApp->processEvents(); |
2093 | cbradney | 274 | MasterPageName = currentDoc->Pages.at(nr)->PageNam; |
275 | MasterPageName2 = MasterPageName; |
||
118 | Franz | 276 | int copyC = 1; |
2093 | cbradney | 277 | while (currentDoc->MasterNames.contains(MasterPageName2)) |
161 | Franz | 278 | { |
2093 | cbradney | 279 | MasterPageName2 = tr("Copy #%1 of ").arg(copyC)+MasterPageName; |
118 | Franz | 280 | copyC++; |
161 | Franz | 281 | } |
2093 | cbradney | 282 | currentDoc->MasterNames.insert(MasterPageName2, nr); |
283 | currentDoc->Pages.at(nr)->setPageName(MasterPageName2); |
||
923 | cbradney | 284 | currentDoc->Pages.at(nr)->MPageNam = ""; |
2093 | cbradney | 285 | updateMasterPageList(MasterPageName2); |
923 | cbradney | 286 | currentDoc->PageAT = atf; |
2093 | cbradney | 287 | currentView->showMasterPage(currentDoc->MasterNames[MasterPageName2]); |
118 | Franz | 288 | qApp->setOverrideCursor(QCursor(arrowCursor), true); |
1507 | fschmid | 289 | currentDoc->MasterPages = currentDoc->Pages; |
2055 | craig | 290 | emit docAltered(currentDoc); |
161 | Franz | 291 | } |
118 | Franz | 292 | delete dia; |
293 | } |
||
294 | |||
2093 | cbradney | 295 | void MasterPagesPalette::selectMasterPage(QListBoxItem *item) |
3 | paul | 296 | { |
923 | cbradney | 297 | sMuster = item->text(); |
298 | deleteButton->setEnabled(currentDoc->MasterNames.count() == 1 ? false : true); |
||
225 | Franz | 299 | if (sMuster == tr("Normal")) |
300 | { |
||
301 | sMuster = "Normal"; |
||
923 | cbradney | 302 | deleteButton->setEnabled(false); |
225 | Franz | 303 | } |
161 | Franz | 304 | else |
923 | cbradney | 305 | deleteButton->setEnabled(true); |
2093 | cbradney | 306 | currentView->showMasterPage(currentDoc->MasterNames[sMuster]); |
3 | paul | 307 | } |
308 | |||
2093 | cbradney | 309 | void MasterPagesPalette::selectMasterPage(QString name) |
1268 | fschmid | 310 | { |
311 | sMuster = name; |
||
312 | deleteButton->setEnabled(currentDoc->MasterNames.count() == 1 ? false : true); |
||
313 | if (sMuster == tr("Normal")) |
||
314 | { |
||
315 | sMuster = "Normal"; |
||
316 | deleteButton->setEnabled(false); |
||
317 | } |
||
318 | else |
||
319 | deleteButton->setEnabled(true); |
||
2093 | cbradney | 320 | currentView->showMasterPage(currentDoc->MasterNames[sMuster]); |
1268 | fschmid | 321 | } |
322 | |||
2093 | cbradney | 323 | void MasterPagesPalette::updateMasterPageList(QString MasterPageName) |
3 | paul | 324 | { |
2093 | cbradney | 325 | masterPageData->clear(); |
923 | cbradney | 326 | for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) |
2093 | cbradney | 327 | masterPageData->insertItem(it.key() == "Normal" ? tr("Normal") : it.key()); |
923 | cbradney | 328 | deleteButton->setEnabled(currentDoc->MasterNames.count() == 1 ? false : true); |
2093 | cbradney | 329 | if (MasterPageName == "Normal") |
225 | Franz | 330 | { |
2093 | cbradney | 331 | MasterPageName = tr("Normal"); |
923 | cbradney | 332 | deleteButton->setEnabled(false); |
225 | Franz | 333 | } |
2093 | cbradney | 334 | masterPageData->setSelected(masterPageData->index(masterPageData->findItem(MasterPageName)), true); |
3 | paul | 335 | } |
336 |