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()
45 : base_class(_("Graphics"))
50 void QGraphics::build_dialog()
52 dialog_.reset(new QGraphicsDialog(this));
54 bc().setOK(dialog_->okPB);
55 bc().setApply(dialog_->applyPB);
56 bc().setRestore(dialog_->restorePB);
57 bc().setCancel(dialog_->closePB);
59 bc().addReadOnly(dialog_->rotateGB);
60 bc().addReadOnly(dialog_->latexoptions);
61 bc().addReadOnly(dialog_->subfigure);
62 bc().addReadOnly(dialog_->subcaption);
63 bc().addReadOnly(dialog_->filenameL);
64 bc().addReadOnly(dialog_->filename);
65 bc().addReadOnly(dialog_->browsePB);
66 bc().addReadOnly(dialog_->unzipCB);
67 bc().addReadOnly(dialog_->filename);
68 bc().addReadOnly(dialog_->lbX);
69 bc().addReadOnly(dialog_->lbY);
70 bc().addReadOnly(dialog_->rtX);
71 bc().addReadOnly(dialog_->rtY);
72 bc().addReadOnly(dialog_->lbXunit);
73 bc().addReadOnly(dialog_->lbYunit);
74 bc().addReadOnly(dialog_->rtXunit);
75 bc().addReadOnly(dialog_->rtYunit);
76 bc().addReadOnly(dialog_->draftCB);
77 bc().addReadOnly(dialog_->clip);
78 bc().addReadOnly(dialog_->unzipCB);
79 bc().addReadOnly(dialog_->subfigure);
80 bc().addReadOnly(dialog_->subcaption);
81 bc().addReadOnly(dialog_->showCB);
82 bc().addReadOnly(dialog_->width);
83 bc().addReadOnly(dialog_->height);
84 bc().addReadOnly(dialog_->displayCB);
85 bc().addReadOnly(dialog_->displayscale);
86 bc().addReadOnly(dialog_->widthUnit);
87 bc().addReadOnly(dialog_->heightUnit);
88 bc().addReadOnly(dialog_->aspectratio);
89 bc().addReadOnly(dialog_->angle);
90 bc().addReadOnly(dialog_->origin);
91 bc().addReadOnly(dialog_->latexoptions);
92 bc().addReadOnly(dialog_->getPB);
96 void QGraphics::update_contents()
98 InsetGraphicsParams & igp = controller().params();
100 // set the right default unit
102 switch (lyxrc.default_papersize) {
103 case BufferParams::PAPER_DEFAULT: break;
105 case BufferParams::PAPER_USLETTER:
106 case BufferParams::PAPER_LEGALPAPER:
107 case BufferParams::PAPER_EXECUTIVEPAPER: unit = "in"; break;
109 case BufferParams::PAPER_A3PAPER:
110 case BufferParams::PAPER_A4PAPER:
111 case BufferParams::PAPER_A5PAPER:
112 case BufferParams::PAPER_B5PAPER: unit = "cm"; break;
115 dialog_->filename->setText(igp.filename.c_str());
117 // set the bounding box values, if exists. First we need the whole
118 // path, because the controller knows nothing about the doc-dir
119 controller().bbChanged = false;
120 if (igp.bb.empty()) {
121 string const fileWithAbsPath(MakeAbsPath(igp.filename, OnlyPath(igp.filename)));
122 string const bb(controller().readBB(fileWithAbsPath));
124 // get the values from the file
125 // in this case we always have the point-unit
126 dialog_->lbX->setText(token(bb, ' ', 0).c_str());
127 dialog_->lbY->setText(token(bb, ' ', 1).c_str());
128 dialog_->rtX->setText(token(bb, ' ', 2).c_str());
129 dialog_->rtY->setText(token(bb, ' ', 3).c_str());
132 // get the values from the inset
133 controller().bbChanged = true;
134 dialog_->lbX->setText(token(igp.bb, ' ', 0).c_str());
135 dialog_->lbY->setText(token(igp.bb, ' ', 1).c_str());
136 dialog_->rtX->setText(token(igp.bb, ' ', 2).c_str());
137 dialog_->rtY->setText(token(igp.bb, ' ', 3).c_str());
140 // Update the draft and clip mode
141 dialog_->draftCB->setChecked(igp.draft);
142 dialog_->clip->setChecked(igp.clip);
143 dialog_->unzipCB->setChecked(igp.noUnzip);
145 // Update the subcaption check button and input field
146 dialog_->subfigure->setChecked(igp.subcaption);
147 dialog_->subcaption->setText(igp.subcaptionText.c_str());
150 switch (igp.display) {
151 case grfx::DefaultDisplay: item = 0; break;
152 case grfx::MonochromeDisplay: item = 1; break;
153 case grfx::GrayscaleDisplay: item = 2; break;
154 case grfx::ColorDisplay: item = 3; break;
155 case grfx::NoDisplay: item = 0; break;
157 dialog_->showCB->setCurrentItem(item);
158 dialog_->showCB->setEnabled(igp.display != grfx::NoDisplay && !readOnly());
159 dialog_->displayCB->setChecked(igp.display != grfx::NoDisplay);
160 dialog_->displayscale->setEnabled(igp.display != grfx::NoDisplay && !readOnly());
161 dialog_->displayscale->setText(tostr(igp.lyxscale).c_str());
163 dialog_->widthUnit->setCurrentItem(igp.width.unit());
164 dialog_->heightUnit->setCurrentItem(igp.height.unit());
165 dialog_->aspectratio->setChecked(igp.keepAspectRatio);
167 // Update the rotate angle
168 dialog_->angle->setText(tostr(igp.rotateAngle).c_str());
170 if (igp.rotateOrigin.empty()) {
171 dialog_->origin->setCurrentItem(0);
173 // FIXME fl_set_choice_text(special_->choice_origin,igp.rotateOrigin.c_str());
177 dialog_->latexoptions->setText(igp.special.c_str());
181 void QGraphics::apply()
183 InsetGraphicsParams & igp = controller().params();
185 igp.filename = dialog_->filename->text();
187 if (!controller().bbChanged) {
191 string lbX(dialog_->lbX->text());
192 string lbY(dialog_->lbY->text());
193 string rtX(dialog_->rtX->text());
194 string rtY(dialog_->rtY->text());
216 igp.draft = dialog_->draftCB->isChecked();
217 igp.clip = dialog_->clip->isChecked();
218 igp.subcaption = dialog_->subfigure->isChecked();
219 igp.subcaptionText = dialog_->subcaption->text();
221 switch (dialog_->showCB->currentItem()) {
222 case 0: igp.display = grfx::DefaultDisplay; break;
223 case 1: igp.display = grfx::MonochromeDisplay; break;
224 case 2: igp.display = grfx::GrayscaleDisplay; break;
225 case 3: igp.display = grfx::ColorDisplay; break;
229 if (!dialog_->displayCB->isChecked())
230 igp.display = grfx::NoDisplay;
232 string value(dialog_->width->text());
233 igp.width = LyXLength(strToDbl(value), dialog_->widthUnit->currentLengthItem());
234 value = string(dialog_->height->text());
235 igp.height = LyXLength(strToDbl(value), dialog_->heightUnit->currentLengthItem());
237 igp.keepAspectRatio = dialog_->aspectratio->isChecked();
239 igp.noUnzip = dialog_->unzipCB->isChecked();
241 igp.lyxscale = strToInt(string(dialog_->displayscale->text()));
243 igp.rotateAngle = strToDbl(string(dialog_->angle->text()));
244 while (igp.rotateAngle < -360.0)
245 igp.rotateAngle += 360.0;
246 while (igp.rotateAngle > 360.0)
247 igp.rotateAngle -= 360.0;
249 if ((dialog_->origin->currentItem()) > 0)
250 igp.rotateOrigin = dialog_->origin->currentText();
252 igp.rotateOrigin = string();
254 igp.special = dialog_->latexoptions->text();
258 void QGraphics::browse()
260 string const & name = controller().Browse(dialog_->filename->text().latin1());
262 dialog_->filename->setText(name.c_str());
266 void QGraphics::get()
268 string const filename(dialog_->filename->text());
269 if (!filename.empty()) {
270 string const fileWithAbsPath(MakeAbsPath(filename, OnlyPath(filename)));
271 string const bb(controller().readBB(fileWithAbsPath));
273 dialog_->lbX->setText(token(bb, ' ', 0).c_str());
274 dialog_->lbY->setText(token(bb, ' ', 1).c_str());
275 dialog_->rtX->setText(token(bb, ' ', 2).c_str());
276 dialog_->rtY->setText(token(bb, ' ', 3).c_str());
278 controller().bbChanged = false;
283 bool QGraphics::isValid()
285 // FIXME: we need more here.
286 return !string(dialog_->filename->text().latin1()).empty();