insilmaril@421
|
1 |
#include "branchpropwindow.h"
|
insilmaril@421
|
2 |
|
insilmaril@440
|
3 |
#include <QColorDialog>
|
insilmaril@440
|
4 |
|
insilmaril@421
|
5 |
#include "frameobj.h"
|
insilmaril@462
|
6 |
#include "settings.h"
|
insilmaril@421
|
7 |
|
insilmaril@462
|
8 |
extern Settings settings;
|
insilmaril@487
|
9 |
extern QString vymName;
|
insilmaril@487
|
10 |
|
insilmaril@421
|
11 |
|
insilmaril@480
|
12 |
BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent)
|
insilmaril@421
|
13 |
{
|
insilmaril@421
|
14 |
ui.setupUi (this);
|
insilmaril@421
|
15 |
|
insilmaril@487
|
16 |
setCaption(vymName +" - " +tr ("Property Editor","Window caption"));
|
insilmaril@487
|
17 |
|
insilmaril@421
|
18 |
branch=NULL;
|
insilmaril@721
|
19 |
model=NULL;
|
insilmaril@421
|
20 |
|
insilmaril@440
|
21 |
ui.tabWidget->setEnabled(false);
|
insilmaril@440
|
22 |
|
insilmaril@440
|
23 |
penColor=QColor (Qt::black);
|
insilmaril@440
|
24 |
brushColor=QColor (Qt::black);
|
insilmaril@440
|
25 |
QPixmap pix( 16,16);
|
insilmaril@440
|
26 |
pix.fill (penColor);
|
insilmaril@440
|
27 |
ui.framePenColorButton->setPixmap (pix);
|
insilmaril@440
|
28 |
ui.frameBrushColorButton->setPixmap (pix);
|
insilmaril@480
|
29 |
|
insilmaril@672
|
30 |
// Create Model and View to hold attributes
|
insilmaril@672
|
31 |
attributeModel = new QStandardItemModel (1,3,this);
|
insilmaril@672
|
32 |
attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
|
insilmaril@672
|
33 |
attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
|
insilmaril@672
|
34 |
attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
|
insilmaril@672
|
35 |
ui.attributeTableView->setModel (attributeModel);
|
insilmaril@672
|
36 |
|
insilmaril@480
|
37 |
|
insilmaril@480
|
38 |
// Load Settings
|
insilmaril@480
|
39 |
resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
|
insilmaril@480
|
40 |
move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
|
insilmaril@480
|
41 |
|
insilmaril@480
|
42 |
if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
|
insilmaril@480
|
43 |
show();
|
insilmaril@480
|
44 |
else
|
insilmaril@480
|
45 |
hide();
|
insilmaril@480
|
46 |
|
insilmaril@746
|
47 |
// FIXME-2 for now remove attribute tab
|
insilmaril@686
|
48 |
ui.tabWidget->removeTab (3);
|
insilmaril@686
|
49 |
|
insilmaril@462
|
50 |
}
|
insilmaril@440
|
51 |
|
insilmaril@462
|
52 |
BranchPropertyWindow::~BranchPropertyWindow ()
|
insilmaril@462
|
53 |
{
|
insilmaril@480
|
54 |
settings.setValue( "/satellite/propertywindow/geometry/size", size() );
|
insilmaril@480
|
55 |
settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
|
insilmaril@530
|
56 |
settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
|
insilmaril@421
|
57 |
}
|
insilmaril@421
|
58 |
|
insilmaril@421
|
59 |
void BranchPropertyWindow::setBranch (BranchObj *bo)
|
insilmaril@421
|
60 |
{
|
insilmaril@462
|
61 |
disconnectSignals();
|
insilmaril@421
|
62 |
branch=bo;
|
insilmaril@440
|
63 |
if (bo)
|
insilmaril@440
|
64 |
{
|
insilmaril@440
|
65 |
ui.tabWidget->setEnabled (true);
|
insilmaril@421
|
66 |
|
insilmaril@440
|
67 |
// Frame
|
insilmaril@462
|
68 |
FrameObj::FrameType t=branch->getFrameType();
|
insilmaril@462
|
69 |
if (t==FrameObj::NoFrame)
|
insilmaril@440
|
70 |
{
|
insilmaril@440
|
71 |
ui.frameTypeCombo->setCurrentIndex (0);
|
insilmaril@440
|
72 |
penColor=Qt::white;
|
insilmaril@440
|
73 |
brushColor=Qt::white;
|
insilmaril@440
|
74 |
ui.colorGroupBox->setEnabled (false);
|
insilmaril@462
|
75 |
ui.framePaddingSpinBox->setEnabled (false);
|
insilmaril@462
|
76 |
ui.frameWidthSpinBox->setEnabled (false);
|
insilmaril@480
|
77 |
ui.framePaddingLabel->setEnabled (false);
|
insilmaril@480
|
78 |
ui.frameBorderLabel->setEnabled (false);
|
insilmaril@440
|
79 |
} else
|
insilmaril@440
|
80 |
{
|
insilmaril@440
|
81 |
penColor=bo->getFramePenColor();
|
insilmaril@440
|
82 |
brushColor=bo->getFrameBrushColor();
|
insilmaril@440
|
83 |
QPixmap pix( 16,16);
|
insilmaril@440
|
84 |
pix.fill (penColor);
|
insilmaril@480
|
85 |
ui.framePenColorButton->setPixmap (pix);
|
insilmaril@440
|
86 |
pix.fill (brushColor);
|
insilmaril@440
|
87 |
ui.frameBrushColorButton->setPixmap (pix);
|
insilmaril@440
|
88 |
ui.colorGroupBox->setEnabled (true);
|
insilmaril@462
|
89 |
ui.framePaddingSpinBox->setEnabled (true);
|
insilmaril@462
|
90 |
ui.framePaddingSpinBox->setValue (bo->getFramePadding());
|
insilmaril@462
|
91 |
ui.frameWidthSpinBox->setEnabled (true);
|
insilmaril@462
|
92 |
ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
|
insilmaril@480
|
93 |
ui.framePaddingLabel->setEnabled (true);
|
insilmaril@480
|
94 |
ui.frameBorderLabel->setEnabled (true);
|
insilmaril@440
|
95 |
|
insilmaril@440
|
96 |
switch (t)
|
insilmaril@440
|
97 |
{
|
insilmaril@462
|
98 |
case FrameObj::Rectangle:
|
insilmaril@440
|
99 |
ui.frameTypeCombo->setCurrentIndex (1);
|
insilmaril@440
|
100 |
break;
|
insilmaril@462
|
101 |
case FrameObj::Ellipse:
|
insilmaril@440
|
102 |
ui.frameTypeCombo->setCurrentIndex (2);
|
insilmaril@440
|
103 |
break;
|
insilmaril@440
|
104 |
default:
|
insilmaril@440
|
105 |
break;
|
insilmaril@440
|
106 |
}
|
insilmaril@440
|
107 |
}
|
insilmaril@440
|
108 |
|
insilmaril@440
|
109 |
// Link
|
insilmaril@440
|
110 |
if (branch->getHideLinkUnselected())
|
insilmaril@440
|
111 |
ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
|
insilmaril@440
|
112 |
else
|
insilmaril@440
|
113 |
ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
|
insilmaril@462
|
114 |
|
insilmaril@462
|
115 |
// Layout
|
insilmaril@462
|
116 |
if (branch->getIncludeImagesVer())
|
insilmaril@462
|
117 |
ui.incImgVer->setCheckState (Qt::Checked);
|
insilmaril@462
|
118 |
else
|
insilmaril@462
|
119 |
ui.incImgVer->setCheckState (Qt::Unchecked);
|
insilmaril@462
|
120 |
if (branch->getIncludeImagesHor())
|
insilmaril@462
|
121 |
ui.incImgHor->setCheckState (Qt::Checked);
|
insilmaril@462
|
122 |
else
|
insilmaril@462
|
123 |
ui.incImgHor->setCheckState (Qt::Unchecked);
|
insilmaril@462
|
124 |
|
insilmaril@672
|
125 |
// Attributes
|
insilmaril@672
|
126 |
attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
|
insilmaril@672
|
127 |
|
insilmaril@721
|
128 |
/*
|
insilmaril@746
|
129 |
// FIXME-3 some samples for attribute testing
|
insilmaril@672
|
130 |
QStringList attrTypes=mapEditor->attributeTable()->getTypes();
|
insilmaril@672
|
131 |
for (int i=0; i<attrTypes.count()-1;i++)
|
insilmaril@672
|
132 |
{
|
insilmaril@672
|
133 |
attributeModel->insertRow (i,QModelIndex ());
|
insilmaril@672
|
134 |
attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
|
insilmaril@672
|
135 |
attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
|
insilmaril@672
|
136 |
attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
|
insilmaril@672
|
137 |
}
|
insilmaril@672
|
138 |
|
insilmaril@672
|
139 |
|
insilmaril@672
|
140 |
ui.attributeTableView->resizeColumnsToContents();
|
insilmaril@672
|
141 |
|
insilmaril@672
|
142 |
// Initialize Delegate
|
insilmaril@672
|
143 |
delegate.setAttributeTable (mapEditor->attributeTable());
|
insilmaril@672
|
144 |
ui.attributeTableView->setItemDelegate (&delegate);
|
insilmaril@721
|
145 |
*/
|
insilmaril@672
|
146 |
|
insilmaril@462
|
147 |
// Finally activate signals
|
insilmaril@462
|
148 |
connectSignals();
|
insilmaril@440
|
149 |
} else
|
insilmaril@421
|
150 |
{
|
insilmaril@440
|
151 |
ui.tabWidget->setEnabled (false);
|
insilmaril@421
|
152 |
}
|
insilmaril@421
|
153 |
}
|
insilmaril@421
|
154 |
|
insilmaril@721
|
155 |
void BranchPropertyWindow::setModel (VymModel *m)
|
insilmaril@421
|
156 |
{
|
insilmaril@721
|
157 |
model=m;
|
insilmaril@721
|
158 |
if (model)
|
insilmaril@753
|
159 |
setBranch (model->getSelectedBranchObj() );
|
insilmaril@440
|
160 |
else
|
insilmaril@440
|
161 |
ui.tabWidget->setEnabled (false);
|
insilmaril@440
|
162 |
|
insilmaril@421
|
163 |
}
|
insilmaril@421
|
164 |
|
insilmaril@421
|
165 |
void BranchPropertyWindow::frameTypeChanged (int i)
|
insilmaril@421
|
166 |
{
|
insilmaril@721
|
167 |
if (model)
|
insilmaril@480
|
168 |
{
|
insilmaril@421
|
169 |
switch (i)
|
insilmaril@421
|
170 |
{
|
insilmaril@721
|
171 |
case 0: model->setFrameType (FrameObj::NoFrame); break;
|
insilmaril@672
|
172 |
case 1:
|
insilmaril@721
|
173 |
model->setFrameType (FrameObj::Rectangle);
|
insilmaril@672
|
174 |
break;
|
insilmaril@672
|
175 |
case 2:
|
insilmaril@721
|
176 |
model->setFrameType (FrameObj::Ellipse);
|
insilmaril@721
|
177 |
model->setFramePadding (5);
|
insilmaril@672
|
178 |
break;
|
insilmaril@421
|
179 |
}
|
insilmaril@480
|
180 |
setBranch (branch);
|
insilmaril@480
|
181 |
}
|
insilmaril@421
|
182 |
}
|
insilmaril@421
|
183 |
|
insilmaril@440
|
184 |
void BranchPropertyWindow::framePenColorClicked()
|
insilmaril@440
|
185 |
{
|
insilmaril@721
|
186 |
if (model)
|
insilmaril@440
|
187 |
{
|
insilmaril@440
|
188 |
QColor col = QColorDialog::getColor( penColor, this );
|
insilmaril@440
|
189 |
if ( col.isValid() )
|
insilmaril@440
|
190 |
{
|
insilmaril@440
|
191 |
penColor=col;
|
insilmaril@721
|
192 |
model->setFramePenColor (penColor);
|
insilmaril@440
|
193 |
}
|
insilmaril@440
|
194 |
}
|
insilmaril@440
|
195 |
}
|
insilmaril@440
|
196 |
|
insilmaril@440
|
197 |
void BranchPropertyWindow::frameBrushColorClicked()
|
insilmaril@440
|
198 |
{
|
insilmaril@721
|
199 |
if (model)
|
insilmaril@440
|
200 |
{
|
insilmaril@440
|
201 |
QColor col = QColorDialog::getColor( brushColor, this );
|
insilmaril@440
|
202 |
if ( col.isValid() )
|
insilmaril@440
|
203 |
{
|
insilmaril@440
|
204 |
brushColor=col;
|
insilmaril@721
|
205 |
model->setFrameBrushColor (brushColor);
|
insilmaril@440
|
206 |
}
|
insilmaril@440
|
207 |
}
|
insilmaril@440
|
208 |
}
|
insilmaril@440
|
209 |
|
insilmaril@462
|
210 |
void BranchPropertyWindow::framePaddingChanged(int i)
|
insilmaril@462
|
211 |
{
|
insilmaril@721
|
212 |
if (model) model->setFramePadding (i);
|
insilmaril@462
|
213 |
}
|
insilmaril@462
|
214 |
|
insilmaril@462
|
215 |
void BranchPropertyWindow::frameBorderWidthChanged(int i)
|
insilmaril@462
|
216 |
{
|
insilmaril@721
|
217 |
if (model) model->setFrameBorderWidth(i);
|
insilmaril@462
|
218 |
}
|
insilmaril@462
|
219 |
|
insilmaril@421
|
220 |
void BranchPropertyWindow::linkHideUnselectedChanged (int i)
|
insilmaril@421
|
221 |
{
|
insilmaril@421
|
222 |
if (!branch) return;
|
insilmaril@721
|
223 |
model->setHideLinkUnselected(i);
|
insilmaril@421
|
224 |
}
|
insilmaril@421
|
225 |
|
insilmaril@462
|
226 |
void BranchPropertyWindow::incImgVerChanged (int i)
|
insilmaril@462
|
227 |
{
|
insilmaril@721
|
228 |
if (model) model->setIncludeImagesVer (i);
|
insilmaril@462
|
229 |
}
|
insilmaril@462
|
230 |
|
insilmaril@462
|
231 |
void BranchPropertyWindow::incImgHorChanged (int i)
|
insilmaril@462
|
232 |
{
|
insilmaril@721
|
233 |
if (model) model->setIncludeImagesHor (i);
|
insilmaril@462
|
234 |
}
|
insilmaril@462
|
235 |
|
insilmaril@480
|
236 |
void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
|
insilmaril@480
|
237 |
{
|
insilmaril@480
|
238 |
ce->accept(); // can be reopened with show()
|
insilmaril@480
|
239 |
hide();
|
insilmaril@480
|
240 |
emit (windowClosed() );
|
insilmaril@480
|
241 |
return;
|
insilmaril@480
|
242 |
}
|
insilmaril@480
|
243 |
|
insilmaril@672
|
244 |
void BranchPropertyWindow::addAttributeClicked()
|
insilmaril@672
|
245 |
{
|
insilmaril@672
|
246 |
// Add empty line for adding attributes
|
insilmaril@672
|
247 |
attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
|
insilmaril@672
|
248 |
attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
|
insilmaril@672
|
249 |
attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
|
insilmaril@672
|
250 |
|
insilmaril@672
|
251 |
// Select attribute from list
|
insilmaril@672
|
252 |
ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
|
insilmaril@672
|
253 |
ui.attributeTableView->resizeColumnsToContents();
|
insilmaril@672
|
254 |
|
insilmaril@672
|
255 |
// QString attname=attributeModel->in
|
insilmaril@672
|
256 |
// attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
|
insilmaril@672
|
257 |
|
insilmaril@672
|
258 |
|
insilmaril@672
|
259 |
|
insilmaril@672
|
260 |
ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
|
insilmaril@672
|
261 |
|
insilmaril@672
|
262 |
}
|
insilmaril@672
|
263 |
|
insilmaril@672
|
264 |
void BranchPropertyWindow::deleteAttributeClicked()
|
insilmaril@672
|
265 |
{
|
insilmaril@746
|
266 |
//FIXME-3 cout << "BPW::delete\n";
|
insilmaril@672
|
267 |
}
|
insilmaril@480
|
268 |
|
insilmaril@462
|
269 |
void BranchPropertyWindow::connectSignals()
|
insilmaril@462
|
270 |
{
|
insilmaril@462
|
271 |
// Frame
|
insilmaril@462
|
272 |
connect (
|
insilmaril@462
|
273 |
ui.framePenColorButton, SIGNAL (clicked()),
|
insilmaril@462
|
274 |
this, SLOT (framePenColorClicked()));
|
insilmaril@462
|
275 |
connect (
|
insilmaril@462
|
276 |
ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
|
insilmaril@462
|
277 |
this, SLOT (framePaddingChanged (int)));
|
insilmaril@462
|
278 |
connect (
|
insilmaril@462
|
279 |
ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
|
insilmaril@462
|
280 |
this, SLOT (frameBorderWidthChanged (int)));
|
insilmaril@462
|
281 |
connect (
|
insilmaril@462
|
282 |
ui.frameBrushColorButton, SIGNAL (clicked()),
|
insilmaril@462
|
283 |
this, SLOT (frameBrushColorClicked()));
|
insilmaril@462
|
284 |
connect (
|
insilmaril@462
|
285 |
ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
|
insilmaril@462
|
286 |
this, SLOT (frameTypeChanged (int)));
|
insilmaril@462
|
287 |
|
insilmaril@462
|
288 |
|
insilmaril@462
|
289 |
// Link
|
insilmaril@462
|
290 |
connect (
|
insilmaril@462
|
291 |
ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
|
insilmaril@462
|
292 |
this, SLOT (linkHideUnselectedChanged (int)));
|
insilmaril@462
|
293 |
|
insilmaril@462
|
294 |
// Layout
|
insilmaril@462
|
295 |
connect (
|
insilmaril@462
|
296 |
ui.incImgVer, SIGNAL (stateChanged( int)),
|
insilmaril@462
|
297 |
this, SLOT (incImgVerChanged (int)));
|
insilmaril@462
|
298 |
connect (
|
insilmaril@462
|
299 |
ui.incImgHor, SIGNAL (stateChanged( int)),
|
insilmaril@462
|
300 |
this, SLOT (incImgHorChanged (int)));
|
insilmaril@672
|
301 |
|
insilmaril@672
|
302 |
// Attributes
|
insilmaril@672
|
303 |
connect (
|
insilmaril@672
|
304 |
ui.addAttributeButton, SIGNAL (clicked()),
|
insilmaril@672
|
305 |
this, SLOT (addAttributeClicked()));
|
insilmaril@672
|
306 |
connect (
|
insilmaril@672
|
307 |
ui.deleteAttributeButton, SIGNAL (clicked()),
|
insilmaril@672
|
308 |
this, SLOT (deleteAttributeClicked()));
|
insilmaril@462
|
309 |
}
|
insilmaril@462
|
310 |
|
insilmaril@462
|
311 |
|
insilmaril@462
|
312 |
void BranchPropertyWindow::disconnectSignals()
|
insilmaril@462
|
313 |
{
|
insilmaril@480
|
314 |
// Frame
|
insilmaril@462
|
315 |
disconnect ( ui.frameTypeCombo, 0,0,0);
|
insilmaril@462
|
316 |
disconnect ( ui.framePenColorButton, 0,0,0);
|
insilmaril@462
|
317 |
disconnect ( ui.framePaddingSpinBox, 0,0,0);
|
insilmaril@462
|
318 |
disconnect ( ui.frameWidthSpinBox, 0,0,0);
|
insilmaril@462
|
319 |
disconnect ( ui.frameBrushColorButton, 0,0,0);
|
insilmaril@462
|
320 |
|
insilmaril@462
|
321 |
// Link
|
insilmaril@462
|
322 |
disconnect ( ui.hideLinkIfUnselected, 0,0,0);
|
insilmaril@462
|
323 |
|
insilmaril@462
|
324 |
// Layout
|
insilmaril@462
|
325 |
disconnect ( ui.incImgVer, 0,0,0);
|
insilmaril@462
|
326 |
disconnect ( ui.incImgHor, 0,0,0);
|
insilmaril@672
|
327 |
|
insilmaril@672
|
328 |
// Attributes
|
insilmaril@672
|
329 |
disconnect ( ui.addAttributeButton, 0,0,0);
|
insilmaril@672
|
330 |
disconnect ( ui.deleteAttributeButton, 0,0,0);
|
insilmaril@462
|
331 |
}
|
insilmaril@462
|
332 |
|
insilmaril@462
|
333 |
|