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)
66 qWarning ("BPW::setBranch");
67 ui.tabWidget->setEnabled (true);
70 FrameObj::FrameType t=branch->getFrameType();
71 if (t==FrameObj::NoFrame)
73 ui.frameTypeCombo->setCurrentIndex (0);
76 ui.colorGroupBox->setEnabled (false);
77 ui.framePaddingSpinBox->setEnabled (false);
78 ui.frameWidthSpinBox->setEnabled (false);
79 ui.framePaddingLabel->setEnabled (false);
80 ui.frameBorderLabel->setEnabled (false);
83 penColor=bo->getFramePenColor();
84 brushColor=bo->getFrameBrushColor();
87 ui.framePenColorButton->setPixmap (pix);
88 pix.fill (brushColor);
89 ui.frameBrushColorButton->setPixmap (pix);
90 ui.colorGroupBox->setEnabled (true);
91 ui.framePaddingSpinBox->setEnabled (true);
92 ui.framePaddingSpinBox->setValue (bo->getFramePadding());
93 ui.frameWidthSpinBox->setEnabled (true);
94 ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
95 ui.framePaddingLabel->setEnabled (true);
96 ui.frameBorderLabel->setEnabled (true);
100 case FrameObj::Rectangle:
101 ui.frameTypeCombo->setCurrentIndex (1);
103 case FrameObj::Ellipse:
104 ui.frameTypeCombo->setCurrentIndex (2);
112 if (branch->getHideLinkUnselected())
113 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
115 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
118 if (branch->getIncludeImagesVer())
119 ui.incImgVer->setCheckState (Qt::Checked);
121 ui.incImgVer->setCheckState (Qt::Unchecked);
122 if (branch->getIncludeImagesHor())
123 ui.incImgHor->setCheckState (Qt::Checked);
125 ui.incImgHor->setCheckState (Qt::Unchecked);
129 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
131 // FIXME-3 some samples for attribute testing
132 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
133 for (int i=0; i<attrTypes.count()-1;i++)
135 attributeModel->insertRow (i,QModelIndex ());
136 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
137 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
138 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
142 ui.attributeTableView->resizeColumnsToContents();
144 // Initialize Delegate
145 delegate.setAttributeTable (mapEditor->attributeTable());
146 ui.attributeTableView->setItemDelegate (&delegate);
149 // Finally activate signals
153 ui.tabWidget->setEnabled (false);
157 void BranchPropertyWindow::setModel (VymModel *m)
161 setBranch (model->getSelectedBranchObj() );
163 ui.tabWidget->setEnabled (false);
167 void BranchPropertyWindow::frameTypeChanged (int i)
173 case 0: model->setFrameType (FrameObj::NoFrame); break;
175 model->setFrameType (FrameObj::Rectangle);
178 model->setFrameType (FrameObj::Ellipse);
179 model->setFramePadding (5);
186 void BranchPropertyWindow::framePenColorClicked()
190 QColor col = QColorDialog::getColor( penColor, this );
194 model->setFramePenColor (penColor);
199 void BranchPropertyWindow::frameBrushColorClicked()
203 QColor col = QColorDialog::getColor( brushColor, this );
207 model->setFrameBrushColor (brushColor);
212 void BranchPropertyWindow::framePaddingChanged(int i)
214 if (model) model->setFramePadding (i);
217 void BranchPropertyWindow::frameBorderWidthChanged(int i)
219 if (model) model->setFrameBorderWidth(i);
222 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
225 model->setHideLinkUnselected(i);
228 void BranchPropertyWindow::incImgVerChanged (int i)
230 if (model) model->setIncludeImagesVer (i);
233 void BranchPropertyWindow::incImgHorChanged (int i)
235 if (model) model->setIncludeImagesHor (i);
238 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
240 ce->accept(); // can be reopened with show()
242 emit (windowClosed() );
247 void BranchPropertyWindow::addAttributeClicked()
249 // Add empty line for adding attributes
250 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
251 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
252 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
254 // Select attribute from list
255 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
256 ui.attributeTableView->resizeColumnsToContents();
258 // QString attname=attributeModel->in
259 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
263 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
267 void BranchPropertyWindow::deleteAttributeClicked()
269 //FIXME-3 cout << "BPW::delete\n";
273 void BranchPropertyWindow::connectSignals()
277 ui.framePenColorButton, SIGNAL (clicked()),
278 this, SLOT (framePenColorClicked()));
280 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
281 this, SLOT (framePaddingChanged (int)));
283 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
284 this, SLOT (frameBorderWidthChanged (int)));
286 ui.frameBrushColorButton, SIGNAL (clicked()),
287 this, SLOT (frameBrushColorClicked()));
289 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
290 this, SLOT (frameTypeChanged (int)));
295 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
296 this, SLOT (linkHideUnselectedChanged (int)));
300 ui.incImgVer, SIGNAL (stateChanged( int)),
301 this, SLOT (incImgVerChanged (int)));
303 ui.incImgHor, SIGNAL (stateChanged( int)),
304 this, SLOT (incImgHorChanged (int)));
309 ui.addAttributeButton, SIGNAL (clicked()),
310 this, SLOT (addAttributeClicked()));
312 ui.deleteAttributeButton, SIGNAL (clicked()),
313 this, SLOT (deleteAttributeClicked()));
318 void BranchPropertyWindow::disconnectSignals()
321 disconnect ( ui.frameTypeCombo, 0,0,0);
322 disconnect ( ui.framePenColorButton, 0,0,0);
323 disconnect ( ui.framePaddingSpinBox, 0,0,0);
324 disconnect ( ui.frameWidthSpinBox, 0,0,0);
325 disconnect ( ui.frameBrushColorButton, 0,0,0);
328 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
331 disconnect ( ui.incImgVer, 0,0,0);
332 disconnect ( ui.incImgHor, 0,0,0);
336 disconnect ( ui.addAttributeButton, 0,0,0);
337 disconnect ( ui.deleteAttributeButton, 0,0,0);