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