3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
7 * \author Edwin Leuven <leuven@fee.uva.nl>
13 #pragma implementation
16 #include "QtLyXView.h"
17 #include "ControlGraphics.h"
19 #include "support/lstrings.h"
20 #include "support/FileInfo.h"
21 #include "support/filetools.h"
22 #include "insets/insetgraphicsParams.h"
24 #include "lengthcombo.h"
28 #include <qlineedit.h>
29 #include <qpushbutton.h>
30 #include <qcheckbox.h>
31 #include <qradiobutton.h>
32 #include <qcombobox.h>
33 #include <qgroupbox.h>
34 #include <qbuttongroup.h>
37 #include "QGraphicsDialog.h"
38 #include "QGraphics.h"
42 typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
44 QGraphics::QGraphics(ControlGraphics & c)
45 : base_class(c, _("Graphics"))
50 void QGraphics::build_dialog()
52 dialog_.reset(new QGraphicsDialog(this));
54 bc().setOK(dialog_->okPB);
55 bc().setApply(dialog_->applyPB);
56 bc().setCancel(dialog_->closePB);
57 bc().setRestore(dialog_->restorePB);
59 bc().addReadOnly(dialog_->rotateGB);
60 bc().addReadOnly(dialog_->latexoptionsGB);
61 bc().addReadOnly(dialog_->bbGB);
62 bc().addReadOnly(dialog_->sizeBG);
63 bc().addReadOnly(dialog_->displayGB);
64 bc().addReadOnly(dialog_->subfigure);
65 bc().addReadOnly(dialog_->subcaption);
66 bc().addReadOnly(dialog_->filenameL);
67 bc().addReadOnly(dialog_->filename);
68 bc().addReadOnly(dialog_->browsePB);
71 void QGraphics::update_contents()
73 InsetGraphicsParams & igp = controller().params();
76 if (lyxrc.default_papersize < 3)
78 string const defaultUnit = string(unit);
80 // Update dialog with details from inset
81 dialog_->filename->setText(igp.filename.c_str());
83 // set the bounding box values, if exists. First we need the whole
84 // path, because the controller knows nothing about the doc-dir
85 controller().bbChanged = false;
87 string const fileWithAbsPath = MakeAbsPath(igp.filename, OnlyPath(igp.filename));
88 string bb = controller().readBB(fileWithAbsPath);
90 // get the values from the file
91 // in this case we always have the point-unit
92 dialog_->lbX->setText(token(bb,' ',0).c_str());
93 dialog_->lbY->setText(token(bb,' ',1).c_str());
94 dialog_->rtX->setText(token(bb,' ',2).c_str());
95 dialog_->rtY->setText(token(bb,' ',3).c_str());
98 // get the values from the inset
99 controller().bbChanged = true;
100 dialog_->lbX->setText(token(igp.bb,' ',0).c_str());
101 dialog_->lbY->setText(token(igp.bb,' ',1).c_str());
102 dialog_->rtX->setText(token(igp.bb,' ',2).c_str());
103 dialog_->rtY->setText(token(igp.bb,' ',3).c_str());
106 // Update the draft and clip mode
107 dialog_->draft->setChecked(igp.draft);
108 dialog_->clip->setChecked(igp.clip);
110 // Update the subcaption check button and input field
111 dialog_->subfigure->setChecked(igp.subcaption);
112 dialog_->subcaption->setText(igp.subcaptionText.c_str());
114 switch (igp.display) {
115 case InsetGraphicsParams::MONOCHROME: {
116 dialog_->show->setCurrentItem(0);
119 case InsetGraphicsParams::GRAYSCALE: {
120 dialog_->show->setCurrentItem(1);
123 case InsetGraphicsParams::COLOR: {
124 dialog_->show->setCurrentItem(2);
127 case InsetGraphicsParams::NONE: {
128 dialog_->show->setCurrentItem(3);
133 dialog_->widthUnit->setCurrentItem(igp.width.unit());
134 dialog_->heightUnit->setCurrentItem(igp.height.unit());
136 switch (igp.size_type) {
137 case InsetGraphicsParams::DEFAULT_SIZE: {
138 dialog_->defaultRB->setChecked(TRUE);
141 case InsetGraphicsParams::WH: {
142 dialog_->customRB->setChecked(TRUE);
145 case InsetGraphicsParams::SCALE: {
146 dialog_->scaleRB->setChecked(TRUE);
147 dialog_->scale->setText(tostr(igp.scale).c_str());
153 dialog_->aspectratio->setChecked(igp.keepAspectRatio);
155 // now the lyx-internally viewsize
156 dialog_->displaywidthUnit->setCurrentItem(igp.lyxwidth.unit());
157 dialog_->displayheightUnit->setCurrentItem(igp.lyxheight.unit());
159 // Update the rotate angle
160 dialog_->angle->setText(tostr(igp.rotateAngle).c_str());
162 if (igp.rotateOrigin.empty()) {
163 dialog_->origin->setCurrentItem(0);
165 //fl_set_choice_text(special_->choice_origin,igp.rotateOrigin.c_str());
170 dialog_->latexoptions->setText(igp.special.c_str());
174 void QGraphics::apply()
176 // Create the parameters structure and fill the data from the dialog.
177 InsetGraphicsParams & igp = controller().params();
179 igp.filename = dialog_->filename->text();
181 if (!controller().bbChanged) // different to the original one?
182 igp.bb = string(); // don't write anything
185 string lbX(dialog_->lbX->text());
186 string lbY(dialog_->lbY->text());
187 string rtX(dialog_->rtX->text());
188 string rtY(dialog_->rtY->text());
210 igp.draft = dialog_->draft->isChecked();
212 igp.clip = dialog_->clip->isChecked();
214 igp.subcaption = dialog_->subfigure->isChecked();
216 igp.subcaptionText = dialog_->subcaption->text();
218 switch(dialog_->show->currentItem()) {
219 case 0: igp.display = InsetGraphicsParams::MONOCHROME; break;
220 case 1: igp.display = InsetGraphicsParams::GRAYSCALE; break;
221 case 2: igp.display = InsetGraphicsParams::COLOR; break;
222 case 3: igp.display = InsetGraphicsParams::NONE; break;
226 if (dialog_->defaultRB->isChecked())
227 igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
228 else if (dialog_->customRB->isChecked())
229 igp.size_type = InsetGraphicsParams::WH;
231 igp.size_type = InsetGraphicsParams::SCALE;
233 string value(dialog_->width->text());
234 igp.width = LyXLength(strToDbl(value), dialog_->widthUnit->currentLengthItem());
236 value = string(dialog_->height->text());
237 igp.height = LyXLength(strToDbl(value), dialog_->heightUnit->currentLengthItem());
239 value = string(dialog_->displaywidth->text());
240 igp.lyxwidth = LyXLength(strToDbl(value), dialog_->displaywidthUnit->currentLengthItem());
242 value = string(dialog_->displayheight->text());
243 igp.lyxheight = LyXLength(strToDbl(value), dialog_->displayheightUnit->currentLengthItem());
245 igp.scale = strToInt(string(dialog_->scale->text()));
247 igp.keepAspectRatio = dialog_->aspectratio->isChecked();
249 igp.rotateAngle = strToDbl(string(dialog_->angle->text()));
251 while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
252 if (igp.rotateAngle < 0.0) {
253 igp.rotateAngle += 360.0;
254 } else if (igp.rotateAngle > 360.0) {
255 igp.rotateAngle -= 360.0;
259 if ((dialog_->origin->currentItem()) > 0)
260 igp.rotateOrigin = dialog_->origin->currentText();
262 igp.rotateOrigin = string();
264 igp.special = dialog_->latexoptions->text();
269 void QGraphics::browse()
271 string const & name = controller().Browse(dialog_->filename->text().latin1());
273 dialog_->filename->setText(name.c_str());
276 void QGraphics::get()
278 string const filename(dialog_->filename->text());
279 if (!filename.empty()) {
280 string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
281 string bb = controller().readBB(fileWithAbsPath);
283 dialog_->lbX->setText(token(bb,' ',0).c_str());
284 dialog_->lbY->setText(token(bb,' ',1).c_str());
285 dialog_->rtX->setText(token(bb,' ',2).c_str());
286 dialog_->rtY->setText(token(bb,' ',3).c_str());
288 controller().bbChanged = false;
293 bool QGraphics::isValid()
295 return !string(dialog_->filename->text().latin1()).empty();