1 #include "branchpropeditor.h"
3 #include <QColorDialog>
5 #include "branchitem.h"
10 extern Settings settings;
11 extern QString vymName;
14 BranchPropertyEditor::BranchPropertyEditor (QWidget *parent): QDialog (parent) // FIXME-4 not updating when data is set elsewhere (connect to dataCHanged)
19 setWindowTitle (vymName +" - " +tr ("Property Editor","Window caption"));
25 ui.tabWidget->setEnabled(false);
27 penColor=QColor (Qt::black);
28 brushColor=QColor (Qt::black);
31 ui.framePenColorButton->setIcon (pix);
32 ui.frameBrushColorButton->setIcon (pix);
34 if (!settings.value( "/mainwindow/showTestMenu",false).toBool() )
35 ui.tabWidget->widget (3)->hide();
38 /* Create Model and View to hold attributes
39 attributeModel = new QStandardItemModel (1,3,this);
40 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
41 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
42 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
43 ui.attributeTableView->setModel (attributeModel);
47 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
48 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
50 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
56 BranchPropertyEditor::~BranchPropertyEditor ()
58 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
59 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
60 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
63 void BranchPropertyEditor::setItem (TreeItem *ti)
67 ui.tabWidget->setEnabled (false);
68 else if (ti->isBranchLikeType() )
70 branchItem=(BranchItem*)ti;
72 branchObj=(BranchObj*)(branchItem->getLMO());
73 if (branchObj) // FIXME-4 replace by branchItem later, when Frame is ported...
75 ui.tabWidget->setEnabled (true);
76 for (int i=0; i<3;++i)
77 ui.tabWidget->setTabEnabled (i,true);
78 ui.tabWidget->setTabEnabled (3,false);
81 FrameObj::FrameType t=branchObj->getFrameType();
82 if (t==FrameObj::NoFrame) // FIXME-3 Check if all below depends on frame type???
84 ui.frameTypeCombo->setCurrentIndex (0);
87 ui.colorGroupBox->setEnabled (false);
88 ui.framePaddingSpinBox->setEnabled (false);
89 ui.frameWidthSpinBox->setEnabled (false);
90 ui.framePaddingLabel->setEnabled (false);
91 ui.frameBorderLabel->setEnabled (false);
92 ui.includeChildrenCheckBox->setEnabled (false);
93 ui.includeChildrenCheckBox->setEnabled (false);
96 penColor=branchObj->getFramePenColor();
97 brushColor=branchObj->getFrameBrushColor();
100 ui.framePenColorButton->setIcon (pix);
101 pix.fill (brushColor);
102 ui.frameBrushColorButton->setIcon (pix);
103 ui.colorGroupBox->setEnabled (true);
104 ui.framePaddingSpinBox->setEnabled (true);
105 ui.framePaddingSpinBox->setValue (branchObj->getFramePadding());
106 ui.frameWidthSpinBox->setEnabled (true);
107 ui.frameWidthSpinBox->setValue (branchObj->getFrameBorderWidth());
108 ui.framePaddingLabel->setEnabled (true);
109 ui.frameBorderLabel->setEnabled (true);
110 ui.includeChildrenCheckBox->setEnabled (true);
114 case FrameObj::Rectangle:
115 ui.frameTypeCombo->setCurrentIndex (1);
117 case FrameObj::RoundedRectangle:
118 ui.frameTypeCombo->setCurrentIndex (2);
120 case FrameObj::Ellipse:
121 ui.frameTypeCombo->setCurrentIndex (3);
123 case FrameObj::Cloud:
124 ui.frameTypeCombo->setCurrentIndex (4);
129 if (branchItem->getFrameIncludeChildren())
130 ui.includeChildrenCheckBox->setCheckState (Qt::Checked);
132 ui.includeChildrenCheckBox->setCheckState (Qt::Unchecked);
135 if (branchItem->getHideLinkUnselected())
136 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
138 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
141 if (branchItem->getIncludeImagesVer())
142 ui.incImgVer->setCheckState (Qt::Checked);
144 ui.incImgVer->setCheckState (Qt::Unchecked);
145 if (branchItem->getIncludeImagesHor())
146 ui.incImgHor->setCheckState (Qt::Checked);
148 ui.incImgHor->setCheckState (Qt::Unchecked);
149 if (branchItem->getChildrenLayout() == BranchItem::FreePositioning)
150 ui.childrenFreePositioning->setCheckState( Qt::Checked);
152 ui.childrenFreePositioning->setCheckState( Qt::Unchecked);
157 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
159 // some samples for attribute testing
160 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
161 for (int i=0; i<attrTypes.count()-1;i++)
163 attributeModel->insertRow (i,QModelIndex ());
164 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
165 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
166 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
170 ui.attributeTableView->resizeColumnsToContents();
172 // Initialize Delegate
173 delegate.setAttributeTable (mapEditor->attributeTable());
174 ui.attributeTableView->setItemDelegate (&delegate);
177 // Finally activate signals
180 } else if (ti->getType()==TreeItem::Attribute)
182 ui.tabWidget->setEnabled (true);
183 for (int i=0; i<3;++i)
184 ui.tabWidget->setTabEnabled (i,false);
185 ui.tabWidget->setTabEnabled (3,true);
188 ui.tabWidget->setEnabled (false);
192 void BranchPropertyEditor::setModel (VymModel *m)
196 setItem (model->getSelectedItem() );
198 ui.tabWidget->setEnabled (false);
202 void BranchPropertyEditor::frameTypeChanged (int i)
208 case 0: model->setFrameType (FrameObj::NoFrame); break;
210 model->setFrameType (FrameObj::Rectangle);
213 model->setFrameType (FrameObj::RoundedRectangle);
216 model->setFrameType (FrameObj::Ellipse);
219 model->setFrameType (FrameObj::Cloud);
222 setItem (branchItem);
226 void BranchPropertyEditor::framePenColorClicked()
230 QColor col = QColorDialog::getColor( penColor, this );
234 model->setFramePenColor (penColor);
239 void BranchPropertyEditor::frameBrushColorClicked()
243 QColor col = QColorDialog::getColor( brushColor, this );
247 model->setFrameBrushColor (brushColor);
252 void BranchPropertyEditor::framePaddingChanged(int i)
254 if (model) model->setFramePadding (i);
257 void BranchPropertyEditor::frameBorderWidthChanged(int i)
259 if (model) model->setFrameBorderWidth(i);
262 void BranchPropertyEditor::frameIncludeChildrenChanged(int i)
264 if (model) model->setFrameIncludeChildren(i);
267 void BranchPropertyEditor::linkHideUnselectedChanged (int i)
269 if (!branchItem) return;
270 model->setHideLinkUnselected(i);
273 void BranchPropertyEditor::incImgVerChanged (int i)
275 if (model) model->setIncludeImagesVer (i);
278 void BranchPropertyEditor::incImgHorChanged (int i)
280 if (model) model->setIncludeImagesHor (i);
283 void BranchPropertyEditor::childrenFreePositioningChanged (int i)
288 model->setChildrenLayout( BranchItem::FreePositioning);
290 model->setChildrenLayout( BranchItem::AutoPositioning);
294 void BranchPropertyEditor::closeEvent( QCloseEvent* ce )
296 ce->accept(); // can be reopened with show()
298 emit (windowClosed() );
303 void BranchPropertyEditor::addAttributeClicked()
305 // Add empty line for adding attributes
306 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
307 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
308 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
310 // Select attribute from list
311 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
312 ui.attributeTableView->resizeColumnsToContents();
314 // QString attname=attributeModel->in
315 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
319 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
323 void BranchPropertyEditor::deleteAttributeClicked()
325 //qDebug() << "BPW::delete";
329 void BranchPropertyEditor::connectSignals()
333 ui.framePenColorButton, SIGNAL (clicked()),
334 this, SLOT (framePenColorClicked()));
336 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
337 this, SLOT (framePaddingChanged (int)));
339 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
340 this, SLOT (frameBorderWidthChanged (int)));
342 ui.frameBrushColorButton, SIGNAL (clicked()),
343 this, SLOT (frameBrushColorClicked()));
345 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
346 this, SLOT (frameTypeChanged (int)));
348 ui.includeChildrenCheckBox, SIGNAL (stateChanged( int)),
349 this, SLOT (frameIncludeChildrenChanged (int)));
353 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
354 this, SLOT (linkHideUnselectedChanged (int)));
358 ui.incImgVer, SIGNAL (stateChanged( int)),
359 this, SLOT (incImgVerChanged (int)));
361 ui.incImgHor, SIGNAL (stateChanged( int)),
362 this, SLOT (incImgHorChanged (int)));
364 ui.childrenFreePositioning, SIGNAL (stateChanged( int)),
365 this, SLOT (childrenFreePositioningChanged (int)));
370 ui.addAttributeButton, SIGNAL (clicked()),
371 this, SLOT (addAttributeClicked()));
373 ui.deleteAttributeButton, SIGNAL (clicked()),
374 this, SLOT (deleteAttributeClicked()));
379 void BranchPropertyEditor::disconnectSignals()
382 disconnect ( ui.frameTypeCombo, 0,0,0);
383 disconnect ( ui.framePenColorButton, 0,0,0);
384 disconnect ( ui.framePaddingSpinBox, 0,0,0);
385 disconnect ( ui.frameWidthSpinBox, 0,0,0);
386 disconnect ( ui.frameBrushColorButton, 0,0,0);
387 disconnect ( ui.includeChildrenCheckBox, 0,0,0);
390 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
393 disconnect ( ui.incImgVer, 0,0,0);
394 disconnect ( ui.incImgHor, 0,0,0);
395 disconnect ( ui.childrenFreePositioning, 0,0,0);
399 disconnect ( ui.addAttributeButton, 0,0,0);
400 disconnect ( ui.deleteAttributeButton, 0,0,0);