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())
49 BranchPropertyWindow::~BranchPropertyWindow ()
51 settings.setValue( "/satellite/propertywindow/geometry/size", size() );
52 settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
53 settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
56 void BranchPropertyWindow::setBranch (BranchObj *bo)
62 ui.tabWidget->setEnabled (true);
65 FrameObj::FrameType t=branch->getFrameType();
66 if (t==FrameObj::NoFrame)
68 ui.frameTypeCombo->setCurrentIndex (0);
71 ui.colorGroupBox->setEnabled (false);
72 ui.framePaddingSpinBox->setEnabled (false);
73 ui.frameWidthSpinBox->setEnabled (false);
74 ui.framePaddingLabel->setEnabled (false);
75 ui.frameBorderLabel->setEnabled (false);
78 penColor=bo->getFramePenColor();
79 brushColor=bo->getFrameBrushColor();
82 ui.framePenColorButton->setPixmap (pix);
83 pix.fill (brushColor);
84 ui.frameBrushColorButton->setPixmap (pix);
85 ui.colorGroupBox->setEnabled (true);
86 ui.framePaddingSpinBox->setEnabled (true);
87 ui.framePaddingSpinBox->setValue (bo->getFramePadding());
88 ui.frameWidthSpinBox->setEnabled (true);
89 ui.frameWidthSpinBox->setValue (bo->getFrameBorderWidth());
90 ui.framePaddingLabel->setEnabled (true);
91 ui.frameBorderLabel->setEnabled (true);
95 case FrameObj::Rectangle:
96 ui.frameTypeCombo->setCurrentIndex (1);
98 case FrameObj::Ellipse:
99 ui.frameTypeCombo->setCurrentIndex (2);
107 if (branch->getHideLinkUnselected())
108 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
110 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
113 if (branch->getIncludeImagesVer())
114 ui.incImgVer->setCheckState (Qt::Checked);
116 ui.incImgVer->setCheckState (Qt::Unchecked);
117 if (branch->getIncludeImagesHor())
118 ui.incImgHor->setCheckState (Qt::Checked);
120 ui.incImgHor->setCheckState (Qt::Unchecked);
123 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
125 // FIXME some samples for testing
126 QStringList attrTypes=mapEditor->attributeTable()->getTypes();
127 for (int i=0; i<attrTypes.count()-1;i++)
129 attributeModel->insertRow (i,QModelIndex ());
130 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
131 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
132 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
136 ui.attributeTableView->resizeColumnsToContents();
138 // Initialize Delegate
139 delegate.setAttributeTable (mapEditor->attributeTable());
140 ui.attributeTableView->setItemDelegate (&delegate);
143 // Finally activate signals
147 ui.tabWidget->setEnabled (false);
151 void BranchPropertyWindow::setMapEditor (MapEditor *me)
155 setBranch (mapEditor->getSelectedBranch() );
157 ui.tabWidget->setEnabled (false);
161 void BranchPropertyWindow::frameTypeChanged (int i)
167 case 0: mapEditor->setFrameType (FrameObj::NoFrame); break;
169 mapEditor->setFrameType (FrameObj::Rectangle);
172 mapEditor->setFrameType (FrameObj::Ellipse);
173 mapEditor->setFramePadding (5);
180 void BranchPropertyWindow::framePenColorClicked()
184 QColor col = QColorDialog::getColor( penColor, this );
188 mapEditor->setFramePenColor (penColor);
193 void BranchPropertyWindow::frameBrushColorClicked()
197 QColor col = QColorDialog::getColor( brushColor, this );
201 mapEditor->setFrameBrushColor (brushColor);
206 void BranchPropertyWindow::framePaddingChanged(int i)
208 if (mapEditor) mapEditor->setFramePadding (i);
211 void BranchPropertyWindow::frameBorderWidthChanged(int i)
213 if (mapEditor) mapEditor->setFrameBorderWidth(i);
216 void BranchPropertyWindow::linkHideUnselectedChanged (int i)
219 mapEditor->setHideLinkUnselected(i);
222 void BranchPropertyWindow::incImgVerChanged (int i)
224 if (mapEditor) mapEditor->setIncludeImagesVer (i);
227 void BranchPropertyWindow::incImgHorChanged (int i)
229 if (mapEditor) mapEditor->setIncludeImagesHor (i);
232 void BranchPropertyWindow::closeEvent( QCloseEvent* ce )
234 ce->accept(); // can be reopened with show()
236 emit (windowClosed() );
240 void BranchPropertyWindow::addAttributeClicked()
242 // Add empty line for adding attributes
243 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
244 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()), "Add new");
245 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), "Undefined");
247 // Select attribute from list
248 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
249 ui.attributeTableView->resizeColumnsToContents();
251 // QString attname=attributeModel->in
252 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()), );
256 ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
260 void BranchPropertyWindow::deleteAttributeClicked()
262 cout << "BPW::delete\n";
265 void BranchPropertyWindow::connectSignals()
269 ui.framePenColorButton, SIGNAL (clicked()),
270 this, SLOT (framePenColorClicked()));
272 ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
273 this, SLOT (framePaddingChanged (int)));
275 ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
276 this, SLOT (frameBorderWidthChanged (int)));
278 ui.frameBrushColorButton, SIGNAL (clicked()),
279 this, SLOT (frameBrushColorClicked()));
281 ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
282 this, SLOT (frameTypeChanged (int)));
287 ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
288 this, SLOT (linkHideUnselectedChanged (int)));
292 ui.incImgVer, SIGNAL (stateChanged( int)),
293 this, SLOT (incImgVerChanged (int)));
295 ui.incImgHor, SIGNAL (stateChanged( int)),
296 this, SLOT (incImgHorChanged (int)));
300 ui.addAttributeButton, SIGNAL (clicked()),
301 this, SLOT (addAttributeClicked()));
303 ui.deleteAttributeButton, SIGNAL (clicked()),
304 this, SLOT (deleteAttributeClicked()));
308 void BranchPropertyWindow::disconnectSignals()
311 disconnect ( ui.frameTypeCombo, 0,0,0);
312 disconnect ( ui.framePenColorButton, 0,0,0);
313 disconnect ( ui.framePaddingSpinBox, 0,0,0);
314 disconnect ( ui.frameWidthSpinBox, 0,0,0);
315 disconnect ( ui.frameBrushColorButton, 0,0,0);
318 disconnect ( ui.hideLinkIfUnselected, 0,0,0);
321 disconnect ( ui.incImgVer, 0,0,0);
322 disconnect ( ui.incImgHor, 0,0,0);
325 disconnect ( ui.addAttributeButton, 0,0,0);
326 disconnect ( ui.deleteAttributeButton, 0,0,0);