]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QGraphics.C
add graphics dialog - not quite working
[features.git] / src / frontends / qt2 / QGraphics.C
1 /**
2  * \file QGraphics.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "QGraphicsDialog.h"
16 #include "ControlGraphics.h"
17 #include "QGraphics.h"
18 #include "Qt2BC.h"
19 #include "gettext.h"
20 #include "debug.h" 
21
22 #include "support/lstrings.h"
23  
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qcheckbox.h>
27 #include <qradiobutton.h>
28 #include <qcombobox.h>
29
30 typedef Qt2CB<ControlGraphics, Qt2DB<QGraphicsDialog> > base_class;
31
32 QGraphics::QGraphics(ControlGraphics & c)
33         : base_class(c, _("Graphics"))
34 {
35 }
36
37
38 void QGraphics::build_dialog()
39 {
40         dialog_.reset(new QGraphicsDialog(this));
41
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);
58 }
59
60
61 namespace {
62         string const numtostr(double val) {
63                 string a(tostr(val));
64                 if (a == "0")
65                         a = "";
66                 return a;
67         }
68 } // namespace anon
69  
70 void QGraphics::update_contents()
71 {
72         InsetGraphicsParams & igp = controller().params();
73
74         dialog_->filenameED->setText(igp.filename.c_str());
75  
76         QRadioButton * button;
77  
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;
83         }
84         button->setChecked(true);
85
86         int item = 0;
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;
91                 default: break;
92         }
93  
94         dialog_->widthCO->setCurrentItem(item);
95  
96         item = 0;
97         switch (igp.heightResize) {
98                 case InsetGraphicsParams::INCH: item = 1; break;
99                 case InsetGraphicsParams::PERCENT_PAGE: item = 2; break;
100                 default: break;
101         }
102  
103         dialog_->heightCO->setCurrentItem(item);
104  
105         // FIXME: scale ???
106  
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());
110  
111         dialog_->subcaptionED->setText(igp.subcaptionText.c_str());
112 }
113
114
115 void QGraphics::apply()
116 {
117         InsetGraphicsParams & igp = controller().params();
118  
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;
125         else
126                 igp.display = InsetGraphicsParams::NONE;
127          
128         igp.subcaptionText = dialog_->subcaptionED->text().latin1();
129         igp.subcaption = !igp.subcaptionText.empty();
130
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;
136                 default:;
137         }
138         if (string(dialog_->widthED->text().latin1()).empty()) {
139                 igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
140                 igp.widthSize = 0.0; 
141         } else {
142                 igp.widthSize = strToDbl(dialog_->widthED->text().latin1());
143         }
144  
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;
149                 default:;
150         }
151         if (string(dialog_->heightED->text().latin1()).empty()) {
152                 igp.heightResize = InsetGraphicsParams::DEFAULT_SIZE;
153                 igp.heightSize = 0.0; 
154         } else {
155                 igp.heightSize = strToDbl(dialog_->heightED->text().latin1());
156         } 
157
158         // FIXME: scale ??? 
159
160         igp.rotateAngle = strToDbl(dialog_->rotateED->text().latin1());
161
162         igp.filename = dialog_->filenameED->text().latin1();
163 }
164
165
166 void QGraphics::browse()
167 {
168         string const & name = controller().Browse(dialog_->filenameED->text().latin1());
169         if (!name.empty())
170                 dialog_->filenameED->setText(name.c_str()); 
171 }
172
173
174 bool QGraphics::isValid()
175 {
176         return !string(dialog_->filenameED->text().latin1()).empty();
177 }