1 #include "branchpropwindow.h"
3 #include <QColorDialog>
8 extern Settings settings;
9 extern QString vymName;
12 BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent)
16 setCaption(vymName +" - " +tr ("Property Editor","Window caption"));
21 ui.tabWidget->setEnabled(false);
23 penColor=QColor (Qt::black);
24 brushColor=QColor (Qt::black);
27 ui.framePenColorButton->setPixmap (pix);
28 ui.frameBrushColorButton->setPixmap (pix);
30 // Create Model and View to hold attributes
32 attributeModel = new QStandardItemModel (1,3,this);
33 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
34 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
35 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
36 ui.attributeTableView->setModel (attributeModel);
40 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
41 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
43 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
48 // FIXME-2 for now remove attribute tab
49 ui.tabWidget->removeTab (3);
53 BranchPropertyWindow::~BranchPropertyWindow ()
55 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
56 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
57 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
60 void BranchPropertyWindow::setBranch (BranchObj *bo) //FIXME-2 maybe do this via signals emitted anyway from model?
66 ui.tabWidget->setEnabled (true);
69 FrameObj::FrameType t=branch->getFrameType();
70 if (t==FrameObj::NoFrame)
72 ui.frameTypeCombo->setCurrentIndex (0);
75 ui.colorGroupBox->setEnabled (false);
76 ui.framePaddingSpinBox->setEnabled (false);
77 ui.frameWidthSpinBox->setEnabled (false);
78 ui.framePaddingLabel->setEnabled (false);
79 ui.frameBorderLabel->setEnabled (false);
82 penColor=bo->getFramePenColor();
83 brushColor=bo->getFrameBrushColor();
86 ui.framePenColorButton->setPixmap (pix);
87 pix.fill (brushColor);
88 ui.frameBrushColorButton->setPixmap (pix);
89 ui.colorGroupBox->setEnabled (true);
90 ui.framePaddingSpinBox->setEnabled (true);
91 ui.framePaddingSpinBox->setValue (bo->getFramePadding());
92 ui.frameWidthSpinBox->setEnabled (true);
93 ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
94 ui.framePaddingLabel->setEnabled (true);
95 ui.frameBorderLabel->setEnabled (true);
99 case FrameObj::Rectangle:
100 ui.frameTypeCombo->setCurrentIndex (1);
102 case FrameObj::Ellipse:
103 ui.frameTypeCombo->setCurrentIndex (2);
111 if (branch->getHideLinkUnselected())
112 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
114 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
117 if (branch->getIncludeImagesVer())
118 ui.incImgVer->setCheckState (Qt::Checked);
120 ui.incImgVer->setCheckState (Qt::Unchecked);
121 if (branch->getIncludeImagesHor())
122 ui.incImgHor->setCheckState (Qt::Checked);
124 ui.incImgHor->setCheckState (Qt::Unchecked);
128 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
130 // FIXME-3 some samples for attribute testing
131 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
132 for (int i=0; i<attrTypes.count()-1;i++)
134 attributeModel->insertRow (i,QModelIndex ());
135 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
136 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
137 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
141 ui.attributeTableView->resizeColumnsToContents();
143 // Initialize Delegate
144 delegate.setAttributeTable (mapEditor->attributeTable());
145 ui.attributeTableView->setItemDelegate (&delegate);
148 // Finally activate signals
152 ui.tabWidget->setEnabled (false);
156 void BranchPropertyWindow::setModel (VymModel *m)
160 setBranch (model->getSelectedBranchObj() );
162 ui.tabWidget->setEnabled (false);
166 void BranchPropertyWindow::frameTypeChanged (int i)
172 case 0: model->setFrameType (FrameObj::NoFrame); break;
174 model->setFrameType (FrameObj::Rectangle);
177 model->setFrameType (FrameObj::Ellipse);
178 model->setFramePadding (5);
185 void BranchPropertyWindow::framePenColorClicked()
189 QColor col = QColorDialog::getColor( penColor, this );
193 model->setFramePenColor (penColor);
198 void BranchPropertyWindow::frameBrushColorClicked()
202 QColor col = QColorDialog::getColor( brushColor, this );
206 model->setFrameBrushColor (brushColor);
211 void BranchPropertyWindow::framePaddingChanged(int i)
213 if (model) model->setFramePadding (i);
216 void BranchPropertyWindow::frameBorderWidthChanged(int i)
218 if (model) model->setFrameBorderWidth(i);
221 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
224 model->setHideLinkUnselected(i);
227 void BranchPropertyWindow::incImgVerChanged (int i)
229 if (model) model->setIncludeImagesVer (i);
232 void BranchPropertyWindow::incImgHorChanged (int i)
234 if (model) model->setIncludeImagesHor (i);
237 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
239 ce->accept(); // can be reopened with show()
241 emit (windowClosed() );
246 void BranchPropertyWindow::addAttributeClicked()
248 // Add empty line for adding attributes
249 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
250 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
251 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
253 // Select attribute from list
254 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
255 ui.attributeTableView->resizeColumnsToContents();
257 // QString attname=attributeModel->in
258 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
262 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
266 void BranchPropertyWindow::deleteAttributeClicked()
268 //FIXME-3 cout << "BPW::delete\n";
272 void BranchPropertyWindow::connectSignals()
276 ui.framePenColorButton, SIGNAL (clicked()),
277 this, SLOT (framePenColorClicked()));
279 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
280 this, SLOT (framePaddingChanged (int)));
282 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
283 this, SLOT (frameBorderWidthChanged (int)));
285 ui.frameBrushColorButton, SIGNAL (clicked()),
286 this, SLOT (frameBrushColorClicked()));
288 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
289 this, SLOT (frameTypeChanged (int)));
294 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
295 this, SLOT (linkHideUnselectedChanged (int)));
299 ui.incImgVer, SIGNAL (stateChanged( int)),
300 this, SLOT (incImgVerChanged (int)));
302 ui.incImgHor, SIGNAL (stateChanged( int)),
303 this, SLOT (incImgHorChanged (int)));
308 ui.addAttributeButton, SIGNAL (clicked()),
309 this, SLOT (addAttributeClicked()));
311 ui.deleteAttributeButton, SIGNAL (clicked()),
312 this, SLOT (deleteAttributeClicked()));
317 void BranchPropertyWindow::disconnectSignals()
320 disconnect ( ui.frameTypeCombo, 0,0,0);
321 disconnect ( ui.framePenColorButton, 0,0,0);
322 disconnect ( ui.framePaddingSpinBox, 0,0,0);
323 disconnect ( ui.frameWidthSpinBox, 0,0,0);
324 disconnect ( ui.frameBrushColorButton, 0,0,0);
327 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
330 disconnect ( ui.incImgVer, 0,0,0);
331 disconnect ( ui.incImgHor, 0,0,0);
335 disconnect ( ui.addAttributeButton, 0,0,0);
336 disconnect ( ui.deleteAttributeButton, 0,0,0);