1 /***************************************************************************
2 * copyright : (C) 2003-2007 by Pascal Brachet *
3 * http://www.xm1math.net/texmaker/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 ***************************************************************************/
11
12 #include "quickdocumentdialog.h"
13 #include "universalinputdialog.h"
14 #include "configmanagerinterface.h"
15 #include "utilsUI.h"
16
convertLatexLengthToMetre(const qreal & length,const QString & unit)17 qreal convertLatexLengthToMetre(const qreal &length, const QString &unit)
18 {
19 static const qreal inchInMetre = 0.0254;
20 static const qreal pointInMetre = inchInMetre / 72.27;
21 static const qreal bigPointInMetre = inchInMetre / 72;
22 QString lunit = unit.toLower();
23 if (lunit == "pt") return length * pointInMetre;
24 if (lunit == "bp") return length * bigPointInMetre;
25 if (lunit == "cm") return length * 0.01;
26 if (lunit == "dm") return length * 0.1;
27 if (lunit == "in") return length * inchInMetre;
28 /*if (unit == "mm")*/ return length * 0.001;
29 }
30
31 //options for the configmanager
32 QStringList QuickDocumentDialog::otherClassList, QuickDocumentDialog::otherPaperList, QuickDocumentDialog::otherInputEncodingList, QuickDocumentDialog::otherFontEncodingList, QuickDocumentDialog::otherBabelOptionsList, QuickDocumentDialog::otherOptionsList;
33 QString QuickDocumentDialog::document_class, QuickDocumentDialog::typeface_size, QuickDocumentDialog::paper_size, QuickDocumentDialog::document_encoding, QuickDocumentDialog::font_encoding, QuickDocumentDialog::babel_language, QuickDocumentDialog::author;
34 bool QuickDocumentDialog::ams_packages, QuickDocumentDialog::makeidx_package, QuickDocumentDialog::graphicx_package;
35 double geometryPageWidth, geometryPageHeight, geometryMarginLeft, geometryMarginRight, geometryMarginTop, geometryMarginBottom;
36 QString geometryPageWidthUnit, geometryPageHeightUnit, geometryMarginLeftUnit, geometryMarginRightUnit, geometryMarginTopUnit, geometryMarginBottomUnit;
37 bool geometryPageWidthEnabled, geometryPageHeightEnabled, geometryMarginLeftEnabled, geometryMarginRightEnabled, geometryMarginTopEnabled, geometryMarginBottomEnabled;
38
39 ConfigManagerInterface *QuickDocumentDialog::configManagerInterface;
40
41
QuickDocumentDialog(QWidget * parent,const QString & name)42 QuickDocumentDialog::QuickDocumentDialog(QWidget *parent, const QString &name)
43 : QDialog(parent)
44 {
45 setWindowTitle(name);
46 setModal(true);
47 ui.setupUi(this);
48 UtilsUi::resizeInFontHeight(this, 39, 37);
49
50 connect(ui.pushButtonClass , SIGNAL(clicked()), SLOT(addUserClass()));
51 ui.comboBoxSize->addItem("10pt");
52 ui.comboBoxSize->addItem("11pt");
53 ui.comboBoxSize->addItem("12pt");
54 connect(ui.pushButtonPaper , SIGNAL(clicked()), SLOT(addUserPaper()));
55 connect(ui.pushButtonInputEncoding , SIGNAL(clicked()), SLOT(addUserInputEncoding()));
56 connect(ui.pushButtonFontEncoding , SIGNAL(clicked()), SLOT(addUserFontEncoding()));
57 connect(ui.pushButtonBabel, SIGNAL(clicked()), SLOT(addBabelOption()));
58 connect(ui.pushButtonOptions , SIGNAL(clicked()), SLOT(addUserOptions()));
59 ui.listWidgetOptions->setSelectionMode(QAbstractItemView::ExtendedSelection);
60 setWindowTitle(tr("Quick Start"));
61
62 //Geometry package
63 connect(ui.spinBoxUnitGeometryPageWidth, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
64 connect(ui.spinBoxUnitGeometryPageHeight, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
65 connect(ui.spinBoxUnitGeometryMarginLeft, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
66 connect(ui.spinBoxUnitGeometryMarginRight, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
67 connect(ui.spinBoxUnitGeometryMarginTop, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
68 connect(ui.spinBoxUnitGeometryMarginBottom, SIGNAL(editTextChanged(QString)), SLOT(geometryUnitsChanged()));
69
70 connect(ui.spinBoxGeometryPageWidth, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
71 connect(ui.spinBoxGeometryPageHeight, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
72 connect(ui.spinBoxGeometryMarginLeft, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
73 connect(ui.spinBoxGeometryMarginRight, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
74 connect(ui.spinBoxGeometryMarginTop, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
75 connect(ui.spinBoxGeometryMarginBottom, SIGNAL(valueChanged(double)), SLOT(geometryValuesChanged()));
76
77 connect(ui.checkBoxGeometryPageWidth, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
78 connect(ui.checkBoxGeometryPageHeight, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
79 connect(ui.checkBoxGeometryMarginLeft, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
80 connect(ui.checkBoxGeometryMarginRight, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
81 connect(ui.checkBoxGeometryMarginTop, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
82 connect(ui.checkBoxGeometryMarginBottom, SIGNAL(toggled(bool)), SLOT(geometryValuesChanged()));
83
84 connect(ui.tabWidget, SIGNAL(currentChanged(int)), SLOT(geometryValuesChanged()));
85 }
86
~QuickDocumentDialog()87 QuickDocumentDialog::~QuickDocumentDialog()
88 {
89 }
90
getNewDocumentText()91 QString QuickDocumentDialog::getNewDocumentText()
92 {
93 QString opt = "";
94 QString tag = QString("\\documentclass[");
95 tag += ui.comboBoxSize->currentText() + QString(",");
96 tag += ui.comboBoxPaper->currentText();
97 QList<QListWidgetItem *> selectedItems = ui.listWidgetOptions->selectedItems();
98 for (int i = 0; i < selectedItems.size(); ++i) {
99 if (selectedItems.at(i)) opt += QString(",") + selectedItems.at(i)->text();
100 }
101 tag += opt + QString("]{");
102 tag += ui.comboBoxClass->currentText() + QString("}");
103 tag += QString("\n");
104 if (ui.comboBoxInputEncoding->currentText() != "NONE") {
105 tag += QString("\\usepackage[") + ui.comboBoxInputEncoding->currentText() + QString("]{inputenc}");
106 tag += QString("\n");
107 }
108 if (ui.comboBoxFontEncoding->currentText() != "NONE") {
109 tag += QString("\\usepackage[") + ui.comboBoxFontEncoding->currentText() + QString("]{fontenc}");
110 tag += QString("\n");
111 }
112 if (ui.comboBoxInputEncoding->currentText().startsWith("utf8x"))
113 tag += QString("\\usepackage{ucs}\n");
114 if (ui.checkBoxAMS->isChecked())
115 tag += QString("\\usepackage{amsmath}\n\\usepackage{amssymb}\n");
116 if (ui.checkBoxIDX->isChecked())
117 tag += QString("\\usepackage{makeidx}\n");
118 if (ui.checkBoxGraphicx->isChecked())
119 tag += QString("\\usepackage{graphicx}\n");
120
121 if (ui.checkBoxGeometryPageWidth->isChecked() ||
122 ui.checkBoxGeometryPageHeight->isChecked() ||
123 ui.checkBoxGeometryMarginLeft->isChecked() ||
124 ui.checkBoxGeometryMarginRight->isChecked() ||
125 ui.checkBoxGeometryMarginBottom->isChecked() ||
126 ui.checkBoxGeometryMarginTop->isChecked()) {
127 QString geometryOptions;
128 if (ui.checkBoxGeometryPageWidth->isChecked()) geometryOptions += ", width=" + ui.spinBoxGeometryPageWidth->text();
129 if (ui.checkBoxGeometryPageHeight->isChecked()) geometryOptions += ", height=" + ui.spinBoxGeometryPageHeight->text();
130 if (ui.checkBoxGeometryMarginLeft->isChecked()) geometryOptions += ", left=" + ui.spinBoxGeometryMarginLeft->text();
131 if (ui.checkBoxGeometryMarginRight->isChecked()) geometryOptions += ", right=" + ui.spinBoxGeometryMarginRight->text();
132 if (ui.checkBoxGeometryMarginTop->isChecked()) geometryOptions += ", top=" + ui.spinBoxGeometryMarginTop->text();
133 if (ui.checkBoxGeometryMarginBottom->isChecked()) geometryOptions += ", bottom=" + ui.spinBoxGeometryMarginBottom->text();
134 geometryOptions.remove(0, 2);
135 tag += "\\usepackage[" + geometryOptions + "]{geometry}\n";
136 }
137 if (ui.comboBoxBabel->currentText() != "NONE")
138 tag += QString("\\usepackage[%1]{babel}\n").arg(ui.comboBoxBabel->currentText());
139
140 if (ui.lineEditTitle->text() != "")
141 tag += "\\title{" + ui.lineEditTitle->text() + "}\n";
142 if (ui.lineEditAuthor->text() != "")
143 tag += "\\author{" + ui.lineEditAuthor->text() + "}\n";
144
145 tag += QString("\\begin{document}\n%|\n\\end{document}");
146 return tag;
147 }
148
registerOptions(ConfigManagerInterface & configManager)149 void QuickDocumentDialog::registerOptions(ConfigManagerInterface &configManager)
150 {
151 configManager.registerOption("Tools/User Class", &otherClassList);
152 configManager.registerOption("Tools/User Paper", &otherPaperList);
153 configManager.registerOption("Tools/User Encoding", &otherInputEncodingList);
154 configManager.registerOption("Tools/User Font Encoding", &otherFontEncodingList);
155 configManager.registerOption("Tools/User Babel Options", &otherBabelOptionsList);
156 configManager.registerOption("Tools/User Options", &otherOptionsList);
157 configManager.registerOption("Quick/Class", &document_class, "article");
158 configManager.registerOption("Quick/Typeface", &typeface_size, "10pt");
159 configManager.registerOption("Quick/Papersize", &paper_size, "a4paper");
160 configManager.registerOption("Quick/Encoding", &document_encoding, "utf8");
161 configManager.registerOption("Quick/FontEncoding", &font_encoding, "T1");
162 configManager.registerOption("Quick/Babel", &babel_language, "NONE");
163 configManager.registerOption("Quick/AMS", &ams_packages, true);
164 configManager.registerOption("Quick/MakeIndex", &makeidx_package, false);
165 configManager.registerOption("Quick/graphicx", &graphicx_package, true);
166 configManager.registerOption("Quick/Author", &author, "");
167
168 configManager.registerOption("Quick/Geometry Page Width", &geometryPageWidth, 0.0f);
169 configManager.registerOption("Quick/Geometry Page Height", &geometryPageHeight, 0.0f);
170 configManager.registerOption("Quick/Geometry Margin Left", &geometryMarginLeft, 0.0f);
171 configManager.registerOption("Quick/Geometry Margin Right", &geometryMarginRight, 0.0f);
172 configManager.registerOption("Quick/Geometry Margin Top", &geometryMarginTop, 0.0f);
173 configManager.registerOption("Quick/Geometry Margin Bottom", &geometryMarginBottom, 0.0f);
174
175 configManager.registerOption("Quick/Geometry Page Width Unit", &geometryPageWidthUnit, "cm");
176 configManager.registerOption("Quick/Geometry Page Height Unit", &geometryPageHeightUnit, "cm");
177 configManager.registerOption("Quick/Geometry Margin Left Unit", &geometryMarginLeftUnit, "cm");
178 configManager.registerOption("Quick/Geometry Margin Right Unit", &geometryMarginRightUnit, "cm");
179 configManager.registerOption("Quick/Geometry Margin Top Unit", &geometryMarginTopUnit, "cm");
180 configManager.registerOption("Quick/Geometry Margin Bottom Unit", &geometryMarginBottomUnit, "cm");
181
182 configManager.registerOption("Quick/Geometry Page Width Enabled", &geometryPageWidthEnabled, false);
183 configManager.registerOption("Quick/Geometry Page Height Enabled", &geometryPageHeightEnabled, false);
184 configManager.registerOption("Quick/Geometry Margin Left Enabled", &geometryMarginLeftEnabled, false);
185 configManager.registerOption("Quick/Geometry Margin Right Enabled", &geometryMarginRightEnabled, false);
186 configManager.registerOption("Quick/Geometry Margin Top Enabled", &geometryMarginTopEnabled, false);
187 configManager.registerOption("Quick/Geometry Margin Bottom Enabled", &geometryMarginBottomEnabled, false);
188
189 configManagerInterface = &configManager;
190 }
191
192 QStringList babelLanguages = QStringList()
193 << "arabic"
194 << "czech"
195 << "dutch"
196 << "english"
197 << "farsi"
198 << "finnish"
199 << "french"
200 << "ngerman"
201 << "greek"
202 << "icelandic"
203 << "italian"
204 << "magyar"
205 << "polish"
206 << "portuguese"
207 << "russian"
208 << "slovak"
209 << "spanish" ;
210
Init()211 void QuickDocumentDialog::Init()
212 {
213 ui.comboBoxClass->clear();
214 ui.comboBoxClass->addItem("article");
215 ui.comboBoxClass->addItem("report");
216 ui.comboBoxClass->addItem("letter");
217 ui.comboBoxClass->addItem("book");
218 ui.comboBoxClass->addItem("beamer");
219 if (!otherClassList.isEmpty()) ui.comboBoxClass->addItems(otherClassList);
220
221 ui.comboBoxPaper->clear();
222 ui.comboBoxPaper->addItem("a4paper");
223 ui.comboBoxPaper->addItem("a5paper");
224 ui.comboBoxPaper->addItem("b5paper");
225 ui.comboBoxPaper->addItem("letterpaper");
226 ui.comboBoxPaper->addItem("legalpaper");
227 ui.comboBoxPaper->addItem("executivepaper");
228 if (!otherPaperList.isEmpty()) ui.comboBoxPaper->addItems(otherPaperList);
229
230 ui.comboBoxInputEncoding->clear();
231 ui.comboBoxInputEncoding->addItem("latin1");
232 ui.comboBoxInputEncoding->addItem("latin2");
233 ui.comboBoxInputEncoding->addItem("latin3");
234 ui.comboBoxInputEncoding->addItem("latin5");
235 ui.comboBoxInputEncoding->addItem("utf8");
236 ui.comboBoxInputEncoding->addItem("utf8x");
237 ui.comboBoxInputEncoding->addItem("ascii");
238 ui.comboBoxInputEncoding->addItem("decmulti");
239 ui.comboBoxInputEncoding->addItem("cp850");
240 ui.comboBoxInputEncoding->addItem("cp852");
241 ui.comboBoxInputEncoding->addItem("cp437");
242 ui.comboBoxInputEncoding->addItem("cp437de");
243 ui.comboBoxInputEncoding->addItem("cp865");
244 ui.comboBoxInputEncoding->addItem("applemac");
245 ui.comboBoxInputEncoding->addItem("next");
246 ui.comboBoxInputEncoding->addItem("ansinew");
247 ui.comboBoxInputEncoding->addItem("cp1252");
248 ui.comboBoxInputEncoding->addItem("cp1250");
249 ui.comboBoxInputEncoding->addItem("NONE");
250 if (!otherInputEncodingList.isEmpty()) ui.comboBoxInputEncoding->addItems(otherInputEncodingList);
251
252 ui.comboBoxFontEncoding->clear();
253 ui.comboBoxFontEncoding->addItem("OT1");
254 ui.comboBoxFontEncoding->addItem("OT2");
255 ui.comboBoxFontEncoding->addItem("OT3");
256 ui.comboBoxFontEncoding->addItem("OT4");
257 ui.comboBoxFontEncoding->addItem("OT5");
258 ui.comboBoxFontEncoding->addItem("OT6");
259 ui.comboBoxFontEncoding->addItem("T1");
260 ui.comboBoxFontEncoding->addItem("T2A");
261 ui.comboBoxFontEncoding->addItem("T2B");
262 ui.comboBoxFontEncoding->addItem("T2C");
263 ui.comboBoxFontEncoding->addItem("T3");
264 ui.comboBoxFontEncoding->addItem("T4");
265 ui.comboBoxFontEncoding->addItem("T5");
266 ui.comboBoxFontEncoding->addItem("T6");
267 ui.comboBoxFontEncoding->addItem("T7");
268 ui.comboBoxFontEncoding->addItem("TS1");
269 ui.comboBoxFontEncoding->addItem("TS3");
270 ui.comboBoxFontEncoding->addItem("X2");
271 ui.comboBoxFontEncoding->addItem("OML");
272 ui.comboBoxFontEncoding->addItem("OMS");
273 ui.comboBoxFontEncoding->addItem("OMX");
274 ui.comboBoxFontEncoding->addItem("C..");
275 ui.comboBoxFontEncoding->addItem("E..");
276 ui.comboBoxFontEncoding->addItem("L..");
277 ui.comboBoxFontEncoding->addItem("LY1");
278 ui.comboBoxFontEncoding->addItem("LV1");
279 ui.comboBoxFontEncoding->addItem("LGR");
280 ui.comboBoxFontEncoding->addItem("PD1");
281 ui.comboBoxFontEncoding->addItem("PU");
282 ui.comboBoxFontEncoding->addItem("U");
283 ui.comboBoxFontEncoding->addItem("NONE");
284 if (!otherFontEncodingList.isEmpty()) ui.comboBoxFontEncoding->addItems(otherFontEncodingList);
285
286 ui.comboBoxBabel->clear();
287 ui.comboBoxBabel->addItem("NONE");
288 ui.comboBoxBabel->addItems(babelLanguages);
289 if (!otherBabelOptionsList.isEmpty()) ui.comboBoxBabel->addItems(otherBabelOptionsList);
290
291 ui.listWidgetOptions->clear();
292 ui.listWidgetOptions->addItem("landscape");
293 ui.listWidgetOptions->addItem("draft");
294 ui.listWidgetOptions->addItem("final");
295 ui.listWidgetOptions->addItem("oneside");
296 ui.listWidgetOptions->addItem("twoside");
297 ui.listWidgetOptions->addItem("openright");
298 ui.listWidgetOptions->addItem("openany");
299 ui.listWidgetOptions->addItem("onecolumn");
300 ui.listWidgetOptions->addItem("twocolumn");
301 ui.listWidgetOptions->addItem("titlepage");
302 ui.listWidgetOptions->addItem("notitlepage");
303 ui.listWidgetOptions->addItem("openbib");
304 ui.listWidgetOptions->addItem("leqno");
305 ui.listWidgetOptions->addItem("fleqn");
306 if (!otherOptionsList.isEmpty()) ui.listWidgetOptions->addItems(otherOptionsList);
307
308
309 configManagerInterface->linkOptionToDialogWidget(&document_class, ui.comboBoxClass);
310 configManagerInterface->linkOptionToDialogWidget(&typeface_size, ui.comboBoxSize);
311 configManagerInterface->linkOptionToDialogWidget(&paper_size, ui.comboBoxPaper);
312 configManagerInterface->linkOptionToDialogWidget(&document_encoding, ui.comboBoxInputEncoding);
313 configManagerInterface->linkOptionToDialogWidget(&font_encoding, ui.comboBoxFontEncoding);
314 configManagerInterface->linkOptionToDialogWidget(&babel_language, ui.comboBoxBabel);
315 configManagerInterface->linkOptionToDialogWidget(&ams_packages, ui.checkBoxAMS);
316 configManagerInterface->linkOptionToDialogWidget(&makeidx_package, ui.checkBoxIDX);
317 configManagerInterface->linkOptionToDialogWidget(&graphicx_package, ui.checkBoxGraphicx);
318 configManagerInterface->linkOptionToDialogWidget(&author, ui.lineEditAuthor);
319
320 configManagerInterface->linkOptionToDialogWidget(&geometryPageWidth, ui.spinBoxGeometryPageWidth);
321 configManagerInterface->linkOptionToDialogWidget(&geometryPageHeight, ui.spinBoxGeometryPageHeight);
322 configManagerInterface->linkOptionToDialogWidget(&geometryMarginLeft, ui.spinBoxGeometryMarginLeft);
323 configManagerInterface->linkOptionToDialogWidget(&geometryMarginRight, ui.spinBoxGeometryMarginRight);
324 configManagerInterface->linkOptionToDialogWidget(&geometryMarginTop, ui.spinBoxGeometryMarginTop);
325 configManagerInterface->linkOptionToDialogWidget(&geometryMarginBottom, ui.spinBoxGeometryMarginBottom);
326
327 configManagerInterface->linkOptionToDialogWidget(&geometryPageWidthUnit, ui.spinBoxUnitGeometryPageWidth);
328 configManagerInterface->linkOptionToDialogWidget(&geometryPageHeightUnit, ui.spinBoxUnitGeometryPageHeight);
329 configManagerInterface->linkOptionToDialogWidget(&geometryMarginLeftUnit, ui.spinBoxUnitGeometryMarginLeft);
330 configManagerInterface->linkOptionToDialogWidget(&geometryMarginRightUnit, ui.spinBoxUnitGeometryMarginRight);
331 configManagerInterface->linkOptionToDialogWidget(&geometryMarginTopUnit, ui.spinBoxUnitGeometryMarginTop);
332 configManagerInterface->linkOptionToDialogWidget(&geometryMarginBottomUnit, ui.spinBoxUnitGeometryMarginBottom);
333
334 configManagerInterface->linkOptionToDialogWidget(&geometryPageWidthEnabled, ui.checkBoxGeometryPageWidth);
335 configManagerInterface->linkOptionToDialogWidget(&geometryPageHeightEnabled, ui.checkBoxGeometryPageHeight);
336 configManagerInterface->linkOptionToDialogWidget(&geometryMarginLeftEnabled, ui.checkBoxGeometryMarginLeft);
337 configManagerInterface->linkOptionToDialogWidget(&geometryMarginRightEnabled, ui.checkBoxGeometryMarginRight);
338 configManagerInterface->linkOptionToDialogWidget(&geometryMarginTopEnabled, ui.checkBoxGeometryMarginTop);
339 configManagerInterface->linkOptionToDialogWidget(&geometryMarginBottomEnabled, ui.checkBoxGeometryMarginBottom);
340 }
341
accept()342 void QuickDocumentDialog::accept()
343 {
344 QDialog::accept();
345 }
346
geometryUnitsChanged()347 void QuickDocumentDialog::geometryUnitsChanged()
348 {
349 //update all units (easier than just the changed one, slower, but need probably less memory)
350 ui.spinBoxGeometryPageWidth->setSuffix(ui.spinBoxUnitGeometryPageWidth->currentText());
351 ui.spinBoxGeometryPageHeight->setSuffix(ui.spinBoxUnitGeometryPageHeight->currentText());
352 ui.spinBoxGeometryMarginLeft->setSuffix(ui.spinBoxUnitGeometryMarginLeft->currentText());
353 ui.spinBoxGeometryMarginRight->setSuffix(ui.spinBoxUnitGeometryMarginRight->currentText());
354 ui.spinBoxGeometryMarginTop->setSuffix(ui.spinBoxUnitGeometryMarginTop->currentText());
355 ui.spinBoxGeometryMarginBottom->setSuffix(ui.spinBoxUnitGeometryMarginBottom->currentText());
356
357 if (sender() == ui.spinBoxUnitGeometryPageWidth) ui.checkBoxGeometryPageWidth->setChecked(true);
358 else if (sender() == ui.spinBoxUnitGeometryPageHeight) ui.checkBoxGeometryPageHeight->setChecked(true);
359 else if (sender() == ui.spinBoxUnitGeometryMarginLeft) ui.checkBoxGeometryMarginLeft->setChecked(true);
360 else if (sender() == ui.spinBoxUnitGeometryMarginRight) ui.checkBoxGeometryMarginRight->setChecked(true);
361 else if (sender() == ui.spinBoxUnitGeometryMarginTop) ui.checkBoxGeometryMarginTop->setChecked(true);
362 else if (sender() == ui.spinBoxUnitGeometryMarginBottom) ui.checkBoxGeometryMarginBottom->setChecked(true);
363 }
364
calculatePaperLength(qreal paper,qreal & left,qreal & body,qreal & right,qreal defaultLeftRatio)365 void calculatePaperLength(qreal paper, qreal &left, qreal &body, qreal &right, qreal defaultLeftRatio)
366 {
367 //all can be unknown
368 if (body == -1 && (left == -1 || right == -1)) body = 0.7 * paper; //this is the behaviour of geometry package 5, in version 4 it would first set the other margin if one is given
369 //either body or both margins are known
370 if (left == -1 && right == -1) {
371 left = (paper - body) * defaultLeftRatio;
372 right = paper - body - left;
373 }
374 //only one value can be unknown
375 if (left == -1) left = paper - body - right;
376 if (right == -1) right = paper - left - body;
377
378 //forget body
379 body = paper - left - right;
380
381 }
382
geometryValuesChanged()383 void QuickDocumentDialog::geometryValuesChanged()
384 {
385 //if a value is changed, enable it (I just don't like to create 12 slots for this, where are you lambda?)
386 if (sender() == ui.spinBoxGeometryPageWidth) ui.checkBoxGeometryPageWidth->setChecked(true);
387 else if (sender() == ui.spinBoxGeometryPageHeight) ui.checkBoxGeometryPageHeight->setChecked(true);
388 else if (sender() == ui.spinBoxGeometryMarginLeft) ui.checkBoxGeometryMarginLeft->setChecked(true);
389 else if (sender() == ui.spinBoxGeometryMarginRight) ui.checkBoxGeometryMarginRight->setChecked(true);
390 else if (sender() == ui.spinBoxGeometryMarginTop) ui.checkBoxGeometryMarginTop->setChecked(true);
391 else if (sender() == ui.spinBoxGeometryMarginBottom) ui.checkBoxGeometryMarginBottom->setChecked(true);
392
393 static const QStringList paperFormats = QStringList()
394 << "a0paper" << "841" << "1189" << "mm"
395 << "a1paper" << "594" << "841" << "mm"
396 << "a2paper" << "420" << "594" << "mm"
397 << "a3paper" << "297" << "420" << "mm"
398 << "a4paper" << "210" << "297" << "mm"
399 << "a5paper" << "148" << "210" << "mm"
400 << "a6paper" << "105" << "148" << "mm"
401 << "b0paper" << "1000" << "1414" << "mm"
402 << "b1paper" << "707" << "1000" << "mm"
403 << "b2paper" << "500" << "707" << "mm"
404 << "b3paper" << "353" << "500" << "mm"
405 << "b4paper" << "250" << "353" << "mm"
406 << "b5paper" << "176" << "250" << "mm"
407 << "b6paper" << "125" << "176" << "mm"
408 << "b0j" << "1030" << "1456" << "mm"
409 << "b1j" << "728" << "1030" << "mm"
410 << "b2j" << "515" << "728" << "mm"
411 << "b3j" << "364" << "515" << "mm"
412 << "b4j" << "257" << "364" << "mm"
413 << "b5j" << "182" << "257" << "mm"
414 << "b6j" << "128" << "182" << "mm"
415 << "ansiapaper" << "8.5" << "11" << "in"
416 << "ansibpaper" << "11" << "17" << "in"
417 << "ansicpaper" << "17" << "22" << "in"
418 << "ansidpaper" << "22" << "34" << "in"
419 << "ansiepaper" << "34" << "44" << "in"
420 << "letterpaper" << "8.5" << "11" << "in"
421 << "legalpaper" << "8.5" << "14" << "in"
422 << "executivepaper" << "7.25" << "10.5" << "in"
423 << "screen" << "225" << "180" << "mm";
424
425 int paperFormat = paperFormats.indexOf(ui.comboBoxPaper->currentText().toLower());
426 if (paperFormat == -1) {
427 ui.geometryPreviewLabel->setText("unknown paper format");
428 return;
429 }
430 qreal physicalPaperWidth = convertLatexLengthToMetre(paperFormats[paperFormat + 1].toDouble(), paperFormats[paperFormat + 3]);
431 qreal physicalPaperHeight = convertLatexLengthToMetre(paperFormats[paperFormat + 2].toDouble(), paperFormats[paperFormat + 3]);
432
433 qreal textWidth = (ui.checkBoxGeometryPageWidth->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryPageWidth->value(), ui.spinBoxGeometryPageWidth->suffix()) : -1);
434 qreal textHeight = (ui.checkBoxGeometryPageWidth->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryPageHeight->value(), ui.spinBoxGeometryPageHeight->suffix()) : -1);
435
436 qreal marginLeft = (ui.checkBoxGeometryMarginLeft->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryMarginLeft->value(), ui.spinBoxGeometryMarginLeft->suffix()) : -1);
437 qreal marginRight = (ui.checkBoxGeometryMarginRight->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryMarginRight->value(), ui.spinBoxGeometryMarginRight->suffix()) : -1);
438 qreal marginTop = (ui.checkBoxGeometryMarginTop->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryMarginTop->value(), ui.spinBoxGeometryMarginTop->suffix()) : -1);
439 qreal marginBottom = (ui.checkBoxGeometryMarginBottom->isChecked() ? convertLatexLengthToMetre(ui.spinBoxGeometryMarginBottom->value(), ui.spinBoxGeometryMarginBottom->suffix()) : -1);
440
441 bool twoSide = ui.listWidgetOptions->findItems("twoside", Qt::MatchExactly).constFirst()->isSelected();
442 bool landscape = ui.listWidgetOptions->findItems("landscape", Qt::MatchExactly).constFirst()->isSelected();
443
444 if (landscape) qSwap(physicalPaperWidth, physicalPaperHeight);
445
446 //calculate missing parametres like the geometry package does it
447 calculatePaperLength(physicalPaperWidth, marginLeft, textWidth, marginRight, twoSide ? (2.0f / 5.0f) : (1 / 2.0f));
448 calculatePaperLength(physicalPaperHeight, marginTop, textHeight, marginBottom, 2.0f / 5.0f);
449
450 //draw paper
451 qreal resolution = qMin((ui.geometryPreviewLabel->width() - 5) / physicalPaperWidth, (ui.geometryPreviewLabel->height() - 5) / physicalPaperHeight);
452 QPixmap preview((int)(physicalPaperWidth * resolution + 6), (int)(physicalPaperHeight * resolution + 5));
453 preview.fill(QColor(0, 0, 0));
454
455 QPainter painter(&preview);
456 QBrush brush(QColor(255, 255, 255));
457 brush.setStyle(Qt::SolidPattern);
458 painter.setBrush(brush);
459 painter.drawRect(2, 2, qRound(physicalPaperWidth * resolution), qRound(physicalPaperHeight * resolution));
460
461 painter.setTransform(QTransform().scale(resolution, resolution)*QTransform().translate(2, 2));
462
463 QPen pen(QColor(128, 128, 128));
464 pen.setWidth(0);
465 painter.setPen(pen);
466
467 painter.drawLine(QPointF(marginLeft, 0), QPointF(marginLeft, physicalPaperHeight));
468 painter.drawLine(QPointF(0, marginTop), QPointF(physicalPaperWidth, marginTop));
469 painter.drawLine(QPointF(physicalPaperWidth - marginRight, 0), QPointF(physicalPaperWidth - marginRight, physicalPaperHeight));
470 painter.drawLine(QPointF(0, physicalPaperHeight - marginTop), QPointF(physicalPaperWidth, physicalPaperHeight - marginTop));
471
472 ui.geometryPreviewLabel->setPixmap(preview);
473 }
474
addUserClass()475 void QuickDocumentDialog::addUserClass()
476 {
477 QString newoption;
478 UniversalInputDialog dialog;
479 dialog.addVariable(&newoption, tr("New:"));
480 if (dialog.exec() && !newoption.isEmpty()) {
481 otherClassList.append(newoption);
482 Init();
483 }
484 }
485
addUserPaper()486 void QuickDocumentDialog::addUserPaper()
487 {
488 QString newoption;
489 UniversalInputDialog dialog;
490 dialog.addVariable(&newoption, tr("New:"));
491 if (dialog.exec() && !newoption.isEmpty()) {
492 otherPaperList.append(newoption);
493 Init();
494 }
495 }
496
addUserInputEncoding()497 void QuickDocumentDialog::addUserInputEncoding()
498 {
499 QString newoption;
500 UniversalInputDialog dialog;
501 dialog.addVariable(&newoption, tr("New:"));
502 if (dialog.exec() && !newoption.isEmpty()) {
503 otherInputEncodingList.append(newoption);
504 Init();
505 }
506 }
507
addUserFontEncoding()508 void QuickDocumentDialog::addUserFontEncoding()
509 {
510 QString newoption;
511 UniversalInputDialog dialog;
512 dialog.addVariable(&newoption, tr("New:"));
513 if (dialog.exec() && !newoption.isEmpty()) {
514 otherFontEncodingList.append(newoption);
515 Init();
516 }
517 }
518
addBabelOption()519 void QuickDocumentDialog::addBabelOption()
520 {
521 QString newoption;
522 UniversalInputDialog dialog;
523 dialog.addVariable(&newoption, tr("New:"));
524 if (dialog.exec() && !newoption.isEmpty()) {
525 otherBabelOptionsList.append(newoption);
526 Init();
527 }
528 }
529
addUserOptions()530 void QuickDocumentDialog::addUserOptions()
531 {
532 QString newoption;
533 UniversalInputDialog dialog;
534 dialog.addVariable(&newoption, tr("New:"));
535 if (dialog.exec() && !newoption.isEmpty()) {
536 otherOptionsList.append(newoption);
537 Init();
538 }
539 }
540