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"));
23 ui.tabWidget->setEnabled(false);
25 penColor=QColor (Qt::black);
26 brushColor=QColor (Qt::black);
29 ui.framePenColorButton->setPixmap (pix);
30 ui.frameBrushColorButton->setPixmap (pix);
32 // Create Model and View to hold attributes // FIXME-3
34 attributeModel = new QStandardItemModel (1,3,this);
35 attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
36 attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
37 attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
38 ui.attributeTableView->setModel (attributeModel);
42 resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
43 move (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
45 if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
51 BranchPropertyWindow::~BranchPropertyWindow ()
53 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
54 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
55 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
58 void BranchPropertyWindow::setItem (TreeItem *ti)
62 ui.tabWidget->setEnabled (false);
63 else if (ti->isBranchLikeType() )
65 branchItem=(BranchItem*)ti;
67 branch=(BranchObj*)(branchItem->getLMO());
68 if (branch) // FIXME-3 replace by branchItem later, when Frame is ported...
70 ui.tabWidget->setEnabled (true);
71 for (int i=0; i<3;++i)
72 ui.tabWidget->setTabEnabled (i,true);
73 ui.tabWidget->setTabEnabled (3,false);
76 FrameObj::FrameType t=branch->getFrameType();
77 if (t==FrameObj::NoFrame)
79 ui.frameTypeCombo->setCurrentIndex (0);
82 ui.colorGroupBox->setEnabled (false);
83 ui.framePaddingSpinBox->setEnabled (false);
84 ui.frameWidthSpinBox->setEnabled (false);
85 ui.framePaddingLabel->setEnabled (false);
86 ui.frameBorderLabel->setEnabled (false);
89 penColor=branch->getFramePenColor();
90 brushColor=branch->getFrameBrushColor();
93 ui.framePenColorButton->setPixmap (pix);
94 pix.fill (brushColor);
95 ui.frameBrushColorButton->setPixmap (pix);
96 ui.colorGroupBox->setEnabled (true);
97 ui.framePaddingSpinBox->setEnabled (true);
98 ui.framePaddingSpinBox->setValue (branch->getFramePadding());
99 ui.frameWidthSpinBox->setEnabled (true);
100 ui.frameWidthSpinBox->setValue (branch->getFrameBorderWidth());
101 ui.framePaddingLabel->setEnabled (true);
102 ui.frameBorderLabel->setEnabled (true);
106 case FrameObj::Rectangle:
107 ui.frameTypeCombo->setCurrentIndex (1);
109 case FrameObj::Ellipse:
110 ui.frameTypeCombo->setCurrentIndex (2);
118 if (branchItem->getHideLinkUnselected())
119 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
121 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
124 if (branchItem->getIncludeImagesVer())
125 ui.incImgVer->setCheckState (Qt::Checked);
127 ui.incImgVer->setCheckState (Qt::Unchecked);
128 if (branchItem->getIncludeImagesHor())
129 ui.incImgHor->setCheckState (Qt::Checked);
131 ui.incImgHor->setCheckState (Qt::Unchecked);
135 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
137 // FIXME-3 some samples for attribute testing
138 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
139 for (int i=0; i<attrTypes.count()-1;i++)
141 attributeModel->insertRow (i,QModelIndex ());
142 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
143 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
144 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
148 ui.attributeTableView->resizeColumnsToContents();
150 // Initialize Delegate
151 delegate.setAttributeTable (mapEditor->attributeTable());
152 ui.attributeTableView->setItemDelegate (&delegate);
155 // Finally activate signals
158 } else if (ti->getType()==TreeItem::Attribute)
160 ui.tabWidget->setEnabled (true);
161 for (int i=0; i<3;++i)
162 ui.tabWidget->setTabEnabled (i,false);
163 ui.tabWidget->setTabEnabled (3,true);
166 ui.tabWidget->setEnabled (false);
170 void BranchPropertyWindow::setModel (VymModel *m)
175 setItem (model->getSelectedItem() );
177 ui.tabWidget->setEnabled (false);
181 void BranchPropertyWindow::frameTypeChanged (int i)
187 case 0: model->setFrameType (FrameObj::NoFrame); break;
189 model->setFrameType (FrameObj::Rectangle);
192 model->setFrameType (FrameObj::Ellipse);
193 model->setFramePadding (5);
196 setItem (branchItem);
200 void BranchPropertyWindow::framePenColorClicked()
204 QColor col = QColorDialog::getColor( penColor, this );
208 model->setFramePenColor (penColor);
213 void BranchPropertyWindow::frameBrushColorClicked()
217 QColor col = QColorDialog::getColor( brushColor, this );
221 model->setFrameBrushColor (brushColor);
226 void BranchPropertyWindow::framePaddingChanged(int i)
228 if (model) model->setFramePadding (i);
231 void BranchPropertyWindow::frameBorderWidthChanged(int i)
233 if (model) model->setFrameBorderWidth(i);
236 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
238 if (!branchItem) return;
239 model->setHideLinkUnselected(i);
242 void BranchPropertyWindow::incImgVerChanged (int i)
244 if (model) model->setIncludeImagesVer (i);
247 void BranchPropertyWindow::incImgHorChanged (int i)
249 if (model) model->setIncludeImagesHor (i);
252 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
254 ce->accept(); // can be reopened with show()
256 emit (windowClosed() );
261 void BranchPropertyWindow::addAttributeClicked()
263 // Add empty line for adding attributes
264 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
265 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
266 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
268 // Select attribute from list
269 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
270 ui.attributeTableView->resizeColumnsToContents();
272 // QString attname=attributeModel->in
273 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
277 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
281 void BranchPropertyWindow::deleteAttributeClicked()
283 //FIXME-3 cout << "BPW::delete\n";
287 void BranchPropertyWindow::connectSignals()
291 ui.framePenColorButton, SIGNAL (clicked()),
292 this, SLOT (framePenColorClicked()));
294 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
295 this, SLOT (framePaddingChanged (int)));
297 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
298 this, SLOT (frameBorderWidthChanged (int)));
300 ui.frameBrushColorButton, SIGNAL (clicked()),
301 this, SLOT (frameBrushColorClicked()));
303 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
304 this, SLOT (frameTypeChanged (int)));
309 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
310 this, SLOT (linkHideUnselectedChanged (int)));
314 ui.incImgVer, SIGNAL (stateChanged( int)),
315 this, SLOT (incImgVerChanged (int)));
317 ui.incImgHor, SIGNAL (stateChanged( int)),
318 this, SLOT (incImgHorChanged (int)));
323 ui.addAttributeButton, SIGNAL (clicked()),
324 this, SLOT (addAttributeClicked()));
326 ui.deleteAttributeButton, SIGNAL (clicked()),
327 this, SLOT (deleteAttributeClicked()));
332 void BranchPropertyWindow::disconnectSignals()
335 disconnect ( ui.frameTypeCombo, 0,0,0);
336 disconnect ( ui.framePenColorButton, 0,0,0);
337 disconnect ( ui.framePaddingSpinBox, 0,0,0);
338 disconnect ( ui.frameWidthSpinBox, 0,0,0);
339 disconnect ( ui.frameBrushColorButton, 0,0,0);
342 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
345 disconnect ( ui.incImgVer, 0,0,0);
346 disconnect ( ui.incImgHor, 0,0,0);
350 disconnect ( ui.addAttributeButton, 0,0,0);
351 disconnect ( ui.deleteAttributeButton, 0,0,0);