Empty branches are always unscrolled after import, relinking to scrolled branch doesn't open branch, starting DBUS implementation
1 #include "branchpropwindow.h"
3 #include <QColorDialog>
5 #include "branchitem.h"
9 extern Settings settings;
10 extern QString vymName;
13 BranchPropertyWindow::BranchPropertyWindow (QWidget *parent): QDialog (parent)
17 setCaption(vymName +" - " +tr ("Property Editor","Window caption"));
22 ui.tabWidget->setEnabled(false);
24 penColor=QColor (Qt::black);
25 brushColor=QColor (Qt::black);
28 ui.framePenColorButton->setPixmap (pix);
29 ui.frameBrushColorButton->setPixmap (pix);
31 // Create Model and View to hold attributes
33 attributeModel = new QStandardItemModel (1,3,this);
34 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
35 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
36 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
37 ui.attributeTableView->setModel (attributeModel);
41 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
42 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
44 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
49 // FIXME-2 for now remove attribute tab
50 ui.tabWidget->removeTab (3);
54 BranchPropertyWindow::~BranchPropertyWindow ()
56 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
57 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
58 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
61 void BranchPropertyWindow::setBranch (BranchObj *bo)
67 BranchItem *bi=(BranchItem*)(bo->getTreeItem());
68 ui.tabWidget->setEnabled (true);
71 FrameObj::FrameType t=branch->getFrameType();
72 if (t==FrameObj::NoFrame)
74 ui.frameTypeCombo->setCurrentIndex (0);
77 ui.colorGroupBox->setEnabled (false);
78 ui.framePaddingSpinBox->setEnabled (false);
79 ui.frameWidthSpinBox->setEnabled (false);
80 ui.framePaddingLabel->setEnabled (false);
81 ui.frameBorderLabel->setEnabled (false);
84 penColor=bo->getFramePenColor();
85 brushColor=bo->getFrameBrushColor();
88 ui.framePenColorButton->setPixmap (pix);
89 pix.fill (brushColor);
90 ui.frameBrushColorButton->setPixmap (pix);
91 ui.colorGroupBox->setEnabled (true);
92 ui.framePaddingSpinBox->setEnabled (true);
93 ui.framePaddingSpinBox->setValue (bo->getFramePadding());
94 ui.frameWidthSpinBox->setEnabled (true);
95 ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
96 ui.framePaddingLabel->setEnabled (true);
97 ui.frameBorderLabel->setEnabled (true);
101 case FrameObj::Rectangle:
102 ui.frameTypeCombo->setCurrentIndex (1);
104 case FrameObj::Ellipse:
105 ui.frameTypeCombo->setCurrentIndex (2);
113 if (bi->getHideLinkUnselected())
114 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
116 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
119 if (branch->getIncludeImagesVer())
120 ui.incImgVer->setCheckState (Qt::Checked);
122 ui.incImgVer->setCheckState (Qt::Unchecked);
123 if (branch->getIncludeImagesHor())
124 ui.incImgHor->setCheckState (Qt::Checked);
126 ui.incImgHor->setCheckState (Qt::Unchecked);
130 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
132 // FIXME-3 some samples for attribute testing
133 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
134 for (int i=0; i<attrTypes.count()-1;i++)
136 attributeModel->insertRow (i,QModelIndex ());
137 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
138 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
139 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
143 ui.attributeTableView->resizeColumnsToContents();
145 // Initialize Delegate
146 delegate.setAttributeTable (mapEditor->attributeTable());
147 ui.attributeTableView->setItemDelegate (&delegate);
150 // Finally activate signals
154 ui.tabWidget->setEnabled (false);
158 void BranchPropertyWindow::setModel (VymModel *m)
162 setBranch (model->getSelectedBranchObj() );
164 ui.tabWidget->setEnabled (false);
168 void BranchPropertyWindow::frameTypeChanged (int i)
174 case 0: model->setFrameType (FrameObj::NoFrame); break;
176 model->setFrameType (FrameObj::Rectangle);
179 model->setFrameType (FrameObj::Ellipse);
180 model->setFramePadding (5);
187 void BranchPropertyWindow::framePenColorClicked()
191 QColor col = QColorDialog::getColor( penColor, this );
195 model->setFramePenColor (penColor);
200 void BranchPropertyWindow::frameBrushColorClicked()
204 QColor col = QColorDialog::getColor( brushColor, this );
208 model->setFrameBrushColor (brushColor);
213 void BranchPropertyWindow::framePaddingChanged(int i)
215 if (model) model->setFramePadding (i);
218 void BranchPropertyWindow::frameBorderWidthChanged(int i)
220 if (model) model->setFrameBorderWidth(i);
223 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
226 model->setHideLinkUnselected(i);
229 void BranchPropertyWindow::incImgVerChanged (int i)
231 if (model) model->setIncludeImagesVer (i);
234 void BranchPropertyWindow::incImgHorChanged (int i)
236 if (model) model->setIncludeImagesHor (i);
239 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
241 ce->accept(); // can be reopened with show()
243 emit (windowClosed() );
248 void BranchPropertyWindow::addAttributeClicked()
250 // Add empty line for adding attributes
251 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
252 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
253 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
255 // Select attribute from list
256 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
257 ui.attributeTableView->resizeColumnsToContents();
259 // QString attname=attributeModel->in
260 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
264 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
268 void BranchPropertyWindow::deleteAttributeClicked()
270 //FIXME-3 cout << "BPW::delete\n";
274 void BranchPropertyWindow::connectSignals()
278 ui.framePenColorButton, SIGNAL (clicked()),
279 this, SLOT (framePenColorClicked()));
281 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
282 this, SLOT (framePaddingChanged (int)));
284 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
285 this, SLOT (frameBorderWidthChanged (int)));
287 ui.frameBrushColorButton, SIGNAL (clicked()),
288 this, SLOT (frameBrushColorClicked()));
290 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
291 this, SLOT (frameTypeChanged (int)));
296 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
297 this, SLOT (linkHideUnselectedChanged (int)));
301 ui.incImgVer, SIGNAL (stateChanged( int)),
302 this, SLOT (incImgVerChanged (int)));
304 ui.incImgHor, SIGNAL (stateChanged( int)),
305 this, SLOT (incImgHorChanged (int)));
310 ui.addAttributeButton, SIGNAL (clicked()),
311 this, SLOT (addAttributeClicked()));
313 ui.deleteAttributeButton, SIGNAL (clicked()),
314 this, SLOT (deleteAttributeClicked()));
319 void BranchPropertyWindow::disconnectSignals()
322 disconnect ( ui.frameTypeCombo, 0,0,0);
323 disconnect ( ui.framePenColorButton, 0,0,0);
324 disconnect ( ui.framePaddingSpinBox, 0,0,0);
325 disconnect ( ui.frameWidthSpinBox, 0,0,0);
326 disconnect ( ui.frameBrushColorButton, 0,0,0);
329 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
332 disconnect ( ui.incImgVer, 0,0,0);
333 disconnect ( ui.incImgHor, 0,0,0);
337 disconnect ( ui.addAttributeButton, 0,0,0);
338 disconnect ( ui.deleteAttributeButton, 0,0,0);