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
31 attributeModel = new QStandardItemModel (1,3,this);
32 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
33 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
34 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
35 ui.attributeTableView->setModel (attributeModel);
39 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
40 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
42 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
47 // FIXME for now remove attribute tab
48 ui.tabWidget->removeTab (3);
52 BranchPropertyWindow::~BranchPropertyWindow ()
54 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
55 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
56 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
59 void BranchPropertyWindow::setBranch (BranchObj *bo)
65 ui.tabWidget->setEnabled (true);
68 FrameObj::FrameType t=branch->getFrameType();
69 if (t==FrameObj::NoFrame)
71 ui.frameTypeCombo->setCurrentIndex (0);
74 ui.colorGroupBox->setEnabled (false);
75 ui.framePaddingSpinBox->setEnabled (false);
76 ui.frameWidthSpinBox->setEnabled (false);
77 ui.framePaddingLabel->setEnabled (false);
78 ui.frameBorderLabel->setEnabled (false);
81 penColor=bo->getFramePenColor();
82 brushColor=bo->getFrameBrushColor();
85 ui.framePenColorButton->setPixmap (pix);
86 pix.fill (brushColor);
87 ui.frameBrushColorButton->setPixmap (pix);
88 ui.colorGroupBox->setEnabled (true);
89 ui.framePaddingSpinBox->setEnabled (true);
90 ui.framePaddingSpinBox->setValue (bo->getFramePadding());
91 ui.frameWidthSpinBox->setEnabled (true);
92 ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
93 ui.framePaddingLabel->setEnabled (true);
94 ui.frameBorderLabel->setEnabled (true);
98 case FrameObj::Rectangle:
99 ui.frameTypeCombo->setCurrentIndex (1);
101 case FrameObj::Ellipse:
102 ui.frameTypeCombo->setCurrentIndex (2);
110 if (branch->getHideLinkUnselected())
111 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
113 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
116 if (branch->getIncludeImagesVer())
117 ui.incImgVer->setCheckState (Qt::Checked);
119 ui.incImgVer->setCheckState (Qt::Unchecked);
120 if (branch->getIncludeImagesHor())
121 ui.incImgHor->setCheckState (Qt::Checked);
123 ui.incImgHor->setCheckState (Qt::Unchecked);
126 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
128 // FIXME some samples for testing
129 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
130 for (int i=0; i<attrTypes.count()-1;i++)
132 attributeModel->insertRow (i,QModelIndex ());
133 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
134 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
135 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
139 ui.attributeTableView->resizeColumnsToContents();
141 // Initialize Delegate
142 delegate.setAttributeTable (mapEditor->attributeTable());
143 ui.attributeTableView->setItemDelegate (&delegate);
146 // Finally activate signals
150 ui.tabWidget->setEnabled (false);
154 void BranchPropertyWindow::setMapEditor (MapEditor *me)
158 setBranch (mapEditor->getSelectedBranch() );
160 ui.tabWidget->setEnabled (false);
164 void BranchPropertyWindow::frameTypeChanged (int i)
170 case 0: mapEditor->setFrameType (FrameObj::NoFrame); break;
172 mapEditor->setFrameType (FrameObj::Rectangle);
175 mapEditor->setFrameType (FrameObj::Ellipse);
176 mapEditor->setFramePadding (5);
183 void BranchPropertyWindow::framePenColorClicked()
187 QColor col = QColorDialog::getColor( penColor, this );
191 mapEditor->setFramePenColor (penColor);
196 void BranchPropertyWindow::frameBrushColorClicked()
200 QColor col = QColorDialog::getColor( brushColor, this );
204 mapEditor->setFrameBrushColor (brushColor);
209 void BranchPropertyWindow::framePaddingChanged(int i)
211 if (mapEditor) mapEditor->setFramePadding (i);
214 void BranchPropertyWindow::frameBorderWidthChanged(int i)
216 if (mapEditor) mapEditor->setFrameBorderWidth(i);
219 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
222 mapEditor->setHideLinkUnselected(i);
225 void BranchPropertyWindow::incImgVerChanged (int i)
227 if (mapEditor) mapEditor->setIncludeImagesVer (i);
230 void BranchPropertyWindow::incImgHorChanged (int i)
232 if (mapEditor) mapEditor->setIncludeImagesHor (i);
235 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
237 ce->accept(); // can be reopened with show()
239 emit (windowClosed() );
243 void BranchPropertyWindow::addAttributeClicked()
245 // Add empty line for adding attributes
246 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
247 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
248 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
250 // Select attribute from list
251 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
252 ui.attributeTableView->resizeColumnsToContents();
254 // QString attname=attributeModel->in
255 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
259 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
263 void BranchPropertyWindow::deleteAttributeClicked()
265 cout << "BPW::delete\n";
268 void BranchPropertyWindow::connectSignals()
272 ui.framePenColorButton, SIGNAL (clicked()),
273 this, SLOT (framePenColorClicked()));
275 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
276 this, SLOT (framePaddingChanged (int)));
278 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
279 this, SLOT (frameBorderWidthChanged (int)));
281 ui.frameBrushColorButton, SIGNAL (clicked()),
282 this, SLOT (frameBrushColorClicked()));
284 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
285 this, SLOT (frameTypeChanged (int)));
290 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
291 this, SLOT (linkHideUnselectedChanged (int)));
295 ui.incImgVer, SIGNAL (stateChanged( int)),
296 this, SLOT (incImgVerChanged (int)));
298 ui.incImgHor, SIGNAL (stateChanged( int)),
299 this, SLOT (incImgHorChanged (int)));
303 ui.addAttributeButton, SIGNAL (clicked()),
304 this, SLOT (addAttributeClicked()));
306 ui.deleteAttributeButton, SIGNAL (clicked()),
307 this, SLOT (deleteAttributeClicked()));
311 void BranchPropertyWindow::disconnectSignals()
314 disconnect ( ui.frameTypeCombo, 0,0,0);
315 disconnect ( ui.framePenColorButton, 0,0,0);
316 disconnect ( ui.framePaddingSpinBox, 0,0,0);
317 disconnect ( ui.frameWidthSpinBox, 0,0,0);
318 disconnect ( ui.frameBrushColorButton, 0,0,0);
321 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
324 disconnect ( ui.incImgVer, 0,0,0);
325 disconnect ( ui.incImgHor, 0,0,0);
328 disconnect ( ui.addAttributeButton, 0,0,0);
329 disconnect ( ui.deleteAttributeButton, 0,0,0);