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)
174 setItem (model->getSelectedItem() );
176 ui.tabWidget->setEnabled (false);
180 void BranchPropertyWindow::frameTypeChanged (int i)
186 case 0: model->setFrameType (FrameObj::NoFrame); break;
188 model->setFrameType (FrameObj::Rectangle);
191 model->setFrameType (FrameObj::Ellipse);
192 model->setFramePadding (5);
195 setItem (branchItem);
199 void BranchPropertyWindow::framePenColorClicked()
203 QColor col = QColorDialog::getColor( penColor, this );
207 model->setFramePenColor (penColor);
212 void BranchPropertyWindow::frameBrushColorClicked()
216 QColor col = QColorDialog::getColor( brushColor, this );
220 model->setFrameBrushColor (brushColor);
225 void BranchPropertyWindow::framePaddingChanged(int i)
227 if (model) model->setFramePadding (i);
230 void BranchPropertyWindow::frameBorderWidthChanged(int i)
232 if (model) model->setFrameBorderWidth(i);
235 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
237 if (!branchItem) return;
238 model->setHideLinkUnselected(i);
241 void BranchPropertyWindow::incImgVerChanged (int i)
243 if (model) model->setIncludeImagesVer (i);
246 void BranchPropertyWindow::incImgHorChanged (int i)
248 if (model) model->setIncludeImagesHor (i);
251 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
253 ce->accept(); // can be reopened with show()
255 emit (windowClosed() );
260 void BranchPropertyWindow::addAttributeClicked()
262 // Add empty line for adding attributes
263 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
264 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
265 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
267 // Select attribute from list
268 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
269 ui.attributeTableView->resizeColumnsToContents();
271 // QString attname=attributeModel->in
272 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
276 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
280 void BranchPropertyWindow::deleteAttributeClicked()
282 //FIXME-3 cout << "BPW::delete\n";
286 void BranchPropertyWindow::connectSignals()
290 ui.framePenColorButton, SIGNAL (clicked()),
291 this, SLOT (framePenColorClicked()));
293 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
294 this, SLOT (framePaddingChanged (int)));
296 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
297 this, SLOT (frameBorderWidthChanged (int)));
299 ui.frameBrushColorButton, SIGNAL (clicked()),
300 this, SLOT (frameBrushColorClicked()));
302 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
303 this, SLOT (frameTypeChanged (int)));
308 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
309 this, SLOT (linkHideUnselectedChanged (int)));
313 ui.incImgVer, SIGNAL (stateChanged( int)),
314 this, SLOT (incImgVerChanged (int)));
316 ui.incImgHor, SIGNAL (stateChanged( int)),
317 this, SLOT (incImgHorChanged (int)));
322 ui.addAttributeButton, SIGNAL (clicked()),
323 this, SLOT (addAttributeClicked()));
325 ui.deleteAttributeButton, SIGNAL (clicked()),
326 this, SLOT (deleteAttributeClicked()));
331 void BranchPropertyWindow::disconnectSignals()
334 disconnect ( ui.frameTypeCombo, 0,0,0);
335 disconnect ( ui.framePenColorButton, 0,0,0);
336 disconnect ( ui.framePaddingSpinBox, 0,0,0);
337 disconnect ( ui.frameWidthSpinBox, 0,0,0);
338 disconnect ( ui.frameBrushColorButton, 0,0,0);
341 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
344 disconnect ( ui.incImgVer, 0,0,0);
345 disconnect ( ui.incImgHor, 0,0,0);
349 disconnect ( ui.addAttributeButton, 0,0,0);
350 disconnect ( ui.deleteAttributeButton, 0,0,0);