3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author John Levon <moz@compsoc.man.ac.uk>
12 #pragma implementation
15 #include "QGraphicsDialog.h"
16 #include "ControlGraphics.h"
17 #include "QGraphics.h"
22 #include "support/lstrings.h"
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qcheckbox.h>
27 #include <qradiobutton.h>
28 #include <qcombobox.h>
30 typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
32 QGraphics::QGraphics(ControlGraphics & c)
33 : base_class(c, _("Graphics"))
38 void QGraphics::build_dialog()
40 dialog_.reset(new QGraphicsDialog(this));
42 bc().setOK(dialog_->okPB);
43 bc().setApply(dialog_->applyPB);
44 bc().setCancel(dialog_->closePB);
45 bc().addReadOnly(dialog_->filenameED);
46 bc().addReadOnly(dialog_->browsePB);
47 bc().addReadOnly(dialog_->widthED);
48 bc().addReadOnly(dialog_->widthCO);
49 bc().addReadOnly(dialog_->heightED);
50 bc().addReadOnly(dialog_->heightCO);
51 bc().addReadOnly(dialog_->scaleCB);
52 bc().addReadOnly(dialog_->rotateED);
53 bc().addReadOnly(dialog_->monochromeRB);
54 bc().addReadOnly(dialog_->grayscaleRB);
55 bc().addReadOnly(dialog_->colorRB);
56 bc().addReadOnly(dialog_->dontRB);
57 bc().addReadOnly(dialog_->subcaptionED);
62 string const numtostr(double val) {
70 void QGraphics::update_contents()
72 InsetGraphicsParams & igp = controller().params();
74 dialog_->filenameED->setText(igp.filename.c_str());
76 QRadioButton * button;
78 switch (igp.display) {
79 case InsetGraphicsParams::COLOR: button = dialog_->colorRB; break;
80 case InsetGraphicsParams::GRAYSCALE: button = dialog_->grayscaleRB; break;
81 case InsetGraphicsParams::MONOCHROME: button = dialog_->monochromeRB; break;
82 case InsetGraphicsParams::NONE: button = dialog_->dontRB; break;
84 button->setChecked(true);
87 switch (igp.widthResize) {
88 case InsetGraphicsParams::INCH: item = 1; break;
89 case InsetGraphicsParams::PERCENT_PAGE: item = 2; break;
90 case InsetGraphicsParams::PERCENT_COLUMN: item = 3; break;
94 dialog_->widthCO->setCurrentItem(item);
97 switch (igp.heightResize) {
98 case InsetGraphicsParams::INCH: item = 1; break;
99 case InsetGraphicsParams::PERCENT_PAGE: item = 2; break;
103 dialog_->heightCO->setCurrentItem(item);
107 dialog_->widthED->setText(numtostr(igp.widthSize).c_str());
108 dialog_->heightED->setText(numtostr(igp.heightSize).c_str());
109 dialog_->rotateED->setText(numtostr(igp.rotateAngle).c_str());
111 dialog_->subcaptionED->setText(igp.subcaptionText.c_str());
115 void QGraphics::apply()
117 InsetGraphicsParams & igp = controller().params();
119 if (dialog_->colorRB->isChecked())
120 igp.display = InsetGraphicsParams::COLOR;
121 else if (dialog_->grayscaleRB->isChecked())
122 igp.display = InsetGraphicsParams::GRAYSCALE;
123 else if (dialog_->monochromeRB->isChecked())
124 igp.display = InsetGraphicsParams::MONOCHROME;
126 igp.display = InsetGraphicsParams::NONE;
128 igp.subcaptionText = dialog_->subcaptionED->text().latin1();
129 igp.subcaption = !igp.subcaptionText.empty();
131 switch (dialog_->widthCO->currentItem()) {
132 case 0: igp.widthResize = InsetGraphicsParams::CM; break;
133 case 1: igp.widthResize = InsetGraphicsParams::INCH; break;
134 case 2: igp.widthResize = InsetGraphicsParams::PERCENT_PAGE; break;
135 case 3: igp.widthResize = InsetGraphicsParams::PERCENT_COLUMN; break;
138 if (string(dialog_->widthED->text().latin1()).empty()) {
139 igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
142 igp.widthSize = strToDbl(dialog_->widthED->text().latin1());
145 switch (dialog_->heightCO->currentItem()) {
146 case 0: igp.heightResize = InsetGraphicsParams::CM; break;
147 case 1: igp.heightResize = InsetGraphicsParams::INCH; break;
148 case 2: igp.heightResize = InsetGraphicsParams::PERCENT_PAGE; break;
151 if (string(dialog_->heightED->text().latin1()).empty()) {
152 igp.heightResize = InsetGraphicsParams::DEFAULT_SIZE;
153 igp.heightSize = 0.0;
155 igp.heightSize = strToDbl(dialog_->heightED->text().latin1());
160 igp.rotateAngle = strToDbl(dialog_->rotateED->text().latin1());
162 igp.filename = dialog_->filenameED->text().latin1();
166 void QGraphics::browse()
168 string const & name = controller().Browse(dialog_->filenameED->text().latin1());
170 dialog_->filenameED->setText(name.c_str());
174 bool QGraphics::isValid()
176 return !string(dialog_->filenameED->text().latin1()).empty();