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-2 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());
129 // FIXME-3 some samples for attribute testing
130 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
131 for (int i=0; i<attrTypes.count()-1;i++)
133 attributeModel->insertRow (i,QModelIndex ());
134 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
135 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
136 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
140 ui.attributeTableView->resizeColumnsToContents();
142 // Initialize Delegate
143 delegate.setAttributeTable (mapEditor->attributeTable());
144 ui.attributeTableView->setItemDelegate (&delegate);
147 // Finally activate signals
151 ui.tabWidget->setEnabled (false);
155 void BranchPropertyWindow::setModel (VymModel *m)
159 setBranch (model->getSelectedBranch() );
161 ui.tabWidget->setEnabled (false);
165 void BranchPropertyWindow::frameTypeChanged (int i)
171 case 0: model->setFrameType (FrameObj::NoFrame); break;
173 model->setFrameType (FrameObj::Rectangle);
176 model->setFrameType (FrameObj::Ellipse);
177 model->setFramePadding (5);
184 void BranchPropertyWindow::framePenColorClicked()
188 QColor col = QColorDialog::getColor( penColor, this );
192 model->setFramePenColor (penColor);
197 void BranchPropertyWindow::frameBrushColorClicked()
201 QColor col = QColorDialog::getColor( brushColor, this );
205 model->setFrameBrushColor (brushColor);
210 void BranchPropertyWindow::framePaddingChanged(int i)
212 if (model) model->setFramePadding (i);
215 void BranchPropertyWindow::frameBorderWidthChanged(int i)
217 if (model) model->setFrameBorderWidth(i);
220 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
223 model->setHideLinkUnselected(i);
226 void BranchPropertyWindow::incImgVerChanged (int i)
228 if (model) model->setIncludeImagesVer (i);
231 void BranchPropertyWindow::incImgHorChanged (int i)
233 if (model) model->setIncludeImagesHor (i);
236 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
238 ce->accept(); // can be reopened with show()
240 emit (windowClosed() );
244 void BranchPropertyWindow::addAttributeClicked()
246 // Add empty line for adding attributes
247 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
248 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
249 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
251 // Select attribute from list
252 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
253 ui.attributeTableView->resizeColumnsToContents();
255 // QString attname=attributeModel->in
256 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
260 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
264 void BranchPropertyWindow::deleteAttributeClicked()
266 //FIXME-3 cout << "BPW::delete\n";
269 void BranchPropertyWindow::connectSignals()
273 ui.framePenColorButton, SIGNAL (clicked()),
274 this, SLOT (framePenColorClicked()));
276 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
277 this, SLOT (framePaddingChanged (int)));
279 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
280 this, SLOT (frameBorderWidthChanged (int)));
282 ui.frameBrushColorButton, SIGNAL (clicked()),
283 this, SLOT (frameBrushColorClicked()));
285 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
286 this, SLOT (frameTypeChanged (int)));
291 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
292 this, SLOT (linkHideUnselectedChanged (int)));
296 ui.incImgVer, SIGNAL (stateChanged( int)),
297 this, SLOT (incImgVerChanged (int)));
299 ui.incImgHor, SIGNAL (stateChanged( int)),
300 this, SLOT (incImgHorChanged (int)));
304 ui.addAttributeButton, SIGNAL (clicked()),
305 this, SLOT (addAttributeClicked()));
307 ui.deleteAttributeButton, SIGNAL (clicked()),
308 this, SLOT (deleteAttributeClicked()));
312 void BranchPropertyWindow::disconnectSignals()
315 disconnect ( ui.frameTypeCombo, 0,0,0);
316 disconnect ( ui.framePenColorButton, 0,0,0);
317 disconnect ( ui.framePaddingSpinBox, 0,0,0);
318 disconnect ( ui.frameWidthSpinBox, 0,0,0);
319 disconnect ( ui.frameBrushColorButton, 0,0,0);
322 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
325 disconnect ( ui.incImgVer, 0,0,0);
326 disconnect ( ui.incImgHor, 0,0,0);
329 disconnect ( ui.addAttributeButton, 0,0,0);
330 disconnect ( ui.deleteAttributeButton, 0,0,0);