1 #include "branchpropeditor.h"
3 #include <QColorDialog>
5 #include "attributeitem.h"
6 #include "branchitem.h"
11 extern Settings settings;
12 extern QString vymName;
14 BranchPropertyEditor::BranchPropertyEditor(QWidget *parent)
15 : QDialog(parent) // FIXME-4 not updating when data is set elsewhere
16 // (connect to dataCHanged)
21 setWindowTitle(vymName + " - " + tr("Property Editor", "Window caption"));
27 ui.tabWidget->setEnabled(false);
29 penColor = QColor(Qt::black);
30 brushColor = QColor(Qt::black);
33 ui.framePenColorButton->setIcon(pix);
34 ui.frameBrushColorButton->setIcon(pix);
36 if (!settings.value("/mainwindow/showTestMenu", false).toBool())
37 ui.tabWidget->widget(3)->hide();
39 //Create Model and View to hold attributes
40 attributeModel = new QStandardItemModel (1, 3, this);
41 attributeModel->setHeaderData(0,
43 tr("Name","Branchprop window: Attribute name"));
44 attributeModel->setHeaderData(1,
46 tr("Value","Branchprop window: Attribute value"));
47 attributeModel->setHeaderData(2,
49 tr("Type","Branchprop window: Attribute type"));
50 ui.attributeTableView->setModel (attributeModel);
55 .value("/satellite/propertywindow/geometry/size", QSize(450, 600))
58 .value("/satellite/propertywindow/geometry/pos", QPoint(250, 50))
61 if (settings.value("/satellite/propertywindow/showWithMain", true).toBool())
69 BranchPropertyEditor::~BranchPropertyEditor()
71 settings.setValue("/satellite/propertywindow/geometry/size", size());
72 settings.setValue("/satellite/propertywindow/geometry/pos", pos());
73 settings.setValue("/satellite/propertywindow/showWithMain", isVisible());
75 delete (attributeModel);
78 void BranchPropertyEditor::setItem(TreeItem *ti)
82 ui.tabWidget->setEnabled(false);
83 else if (ti->isBranchLikeType()) {
84 branchItem = (BranchItem *)ti;
86 branchObj = (BranchObj *)(branchItem->getLMO());
87 if (branchObj) // FIXME-4 replace by branchItem later, when Frame is
90 ui.tabWidget->setEnabled(true);
91 for (int i = 0; i < 4; ++i)
92 ui.tabWidget->setTabEnabled(i, true);
93 ui.tabWidget->setTabEnabled(4, false);
96 FrameObj::FrameType t = branchObj->getFrameType();
97 if (t == FrameObj::NoFrame) // FIXME-3 Check if all below depends on
100 ui.frameTypeCombo->setCurrentIndex(0);
101 penColor = Qt::white;
102 brushColor = Qt::white;
103 ui.colorGroupBox->setEnabled(false);
104 ui.framePaddingSpinBox->setEnabled(false);
105 ui.frameWidthSpinBox->setEnabled(false);
106 ui.framePaddingLabel->setEnabled(false);
107 ui.frameBorderLabel->setEnabled(false);
108 ui.includeChildrenCheckBox->setEnabled(false);
109 ui.includeChildrenCheckBox->setEnabled(false);
112 penColor = branchObj->getFramePenColor();
113 brushColor = branchObj->getFrameBrushColor();
116 ui.framePenColorButton->setIcon(pix);
117 pix.fill(brushColor);
118 ui.frameBrushColorButton->setIcon(pix);
119 ui.colorGroupBox->setEnabled(true);
120 ui.framePaddingSpinBox->setEnabled(true);
121 ui.framePaddingSpinBox->setValue(branchObj->getFramePadding());
122 ui.frameWidthSpinBox->setEnabled(true);
123 ui.frameWidthSpinBox->setValue(
124 branchObj->getFrameBorderWidth());
125 ui.framePaddingLabel->setEnabled(true);
126 ui.frameBorderLabel->setEnabled(true);
127 ui.includeChildrenCheckBox->setEnabled(true);
130 case FrameObj::Rectangle:
131 ui.frameTypeCombo->setCurrentIndex(1);
133 case FrameObj::RoundedRectangle:
134 ui.frameTypeCombo->setCurrentIndex(2);
136 case FrameObj::Ellipse:
137 ui.frameTypeCombo->setCurrentIndex(3);
139 case FrameObj::Cloud:
140 ui.frameTypeCombo->setCurrentIndex(4);
145 if (branchItem->getFrameIncludeChildren())
146 ui.includeChildrenCheckBox->setCheckState(Qt::Checked);
148 ui.includeChildrenCheckBox->setCheckState(Qt::Unchecked);
151 if (branchItem->getHideLinkUnselected())
152 ui.hideLinkIfUnselected->setCheckState(Qt::Checked);
154 ui.hideLinkIfUnselected->setCheckState(Qt::Unchecked);
157 if (branchItem->getIncludeImagesVer())
158 ui.incImgVer->setCheckState(Qt::Checked);
160 ui.incImgVer->setCheckState(Qt::Unchecked);
161 if (branchItem->getIncludeImagesHor())
162 ui.incImgHor->setCheckState(Qt::Checked);
164 ui.incImgHor->setCheckState(Qt::Unchecked);
165 if (branchItem->getChildrenLayout() == BranchItem::FreePositioning)
166 ui.childrenFreePositioning->setCheckState(Qt::Checked);
168 ui.childrenFreePositioning->setCheckState(Qt::Unchecked);
171 Task *task = branchItem->getTask();
173 ui.taskPrioDelta->setEnabled(true);
174 ui.taskPrioDelta->setValue(task->getPriorityDelta());
175 ui.lineEditDateCreation->setText(
176 task->getDateCreation().toString() + " - " +
177 QString(tr("%1 days ago", "task related times"))
178 .arg(task->getAgeCreation()));
179 QDateTime dt = task->getDateModification();
181 ui.lineEditDateModification->setText(
182 dt.toString() + " - " +
183 QString(tr("%1 days ago", "task related times"))
184 .arg(task->getAgeModification()));
187 ui.lineEditDateModification->setText("");
190 dt = task->getSleep();
193 qint64 daysSleep = task->getDaysSleep();
194 daysSleep >= 0 ? s = QString(dt.toString() + " - " +
195 tr("sleeping %1 days",
196 "task related times"))
198 : s = QString(tr("Task is awake",
199 "task related times"));
200 ui.lineEditSleep->setText(s);
203 ui.lineEditSleep->setText("");
207 ui.taskPrioDelta->setEnabled(false);
208 ui.taskPrioDelta->setValue(0);
209 ui.lineEditDateCreation->setText("");
210 ui.lineEditDateModification->setText("");
211 ui.lineEditSleep->setText("");
215 attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
217 for (int i = 0; i < branchItem->attributeCount(); i++)
219 AttributeItem *ai = branchItem->getAttributeNum(i);
221 attributeModel->insertRow (i, QModelIndex ());
222 attributeModel->setData(attributeModel->index(i, 0, QModelIndex()),
224 attributeModel->setData(attributeModel->index(i, 1, QModelIndex()),
225 ai->getValue().toString());
226 attributeModel->setData(attributeModel->index(i, 2, QModelIndex()),
227 ai->getAttributeTypeString());
231 ui.attributeTableView->resizeColumnsToContents();
233 // Initialize Delegate
234 //attributeDelegate.setAttributeTable (mapEditor->attributeTable());
235 //ui.attributeTableView->setItemDelegate (&attributeDelegate);
239 else if (ti->getType() == TreeItem::Image) {
240 ui.tabWidget->setEnabled(true);
241 for (int i = 0; i < ui.tabWidget->count(); ++i)
242 ui.tabWidget->setTabEnabled(i, false);
243 ui.tabWidget->setTabEnabled(3, true);
244 ui.tabWidget->setCurrentIndex(3);
246 else if (ti->getType() == TreeItem::Attribute) {
247 ui.tabWidget->setEnabled(true);
248 for (int i = 0; i < 3; ++i)
249 ui.tabWidget->setTabEnabled(i, false);
250 ui.tabWidget->setTabEnabled(3, true);
253 ui.tabWidget->setEnabled(false);
258 void BranchPropertyEditor::setModel(VymModel *m)
262 setItem(model->getSelectedItem());
264 ui.tabWidget->setEnabled(false);
267 void BranchPropertyEditor::frameTypeChanged(int i)
272 model->setFrameType(FrameObj::NoFrame);
275 model->setFrameType(FrameObj::Rectangle);
278 model->setFrameType(FrameObj::RoundedRectangle);
281 model->setFrameType(FrameObj::Ellipse);
284 model->setFrameType(FrameObj::Cloud);
291 void BranchPropertyEditor::framePenColorClicked()
294 QColor col = QColorDialog::getColor(penColor, this);
297 model->setFramePenColor(penColor);
302 void BranchPropertyEditor::frameBrushColorClicked()
305 QColor col = QColorDialog::getColor(brushColor, this);
308 model->setFrameBrushColor(brushColor);
313 void BranchPropertyEditor::framePaddingChanged(int i)
316 model->setFramePadding(i);
319 void BranchPropertyEditor::frameBorderWidthChanged(int i)
322 model->setFrameBorderWidth(i);
325 void BranchPropertyEditor::frameIncludeChildrenChanged(int i)
328 model->setFrameIncludeChildren(i);
331 void BranchPropertyEditor::linkHideUnselectedChanged(int i)
333 model->setHideLinkUnselected(i);
336 void BranchPropertyEditor::incImgVerChanged(int i)
339 model->setIncludeImagesVer(i);
342 void BranchPropertyEditor::incImgHorChanged(int i)
345 model->setIncludeImagesHor(i);
348 void BranchPropertyEditor::childrenFreePositioningChanged(int i)
352 model->setChildrenLayout(BranchItem::FreePositioning);
354 model->setChildrenLayout(BranchItem::AutoPositioning);
358 void BranchPropertyEditor::taskPriorityDeltaChanged(int n)
361 model->setTaskPriorityDelta(n);
364 void BranchPropertyEditor::closeEvent(QCloseEvent *ce)
366 ce->accept(); // can be reopened with show()
368 emit(windowClosed());
372 void BranchPropertyEditor::addAttributeClicked()
374 qDebug() << "BranchPropEditor::addAttribute";
377 // Add empty line for adding attributes
378 attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
379 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1,
380 0, QModelIndex()), "Add new");
381 attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1,
382 2, QModelIndex()), "Undefined");
384 // Select attribute from list
385 ui.attributeTableView->edit
386 (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
387 ui.attributeTableView->resizeColumnsToContents();
389 // QString attname=attributeModel->in
390 // attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1,
391 2, QModelIndex()), );
395 ui.attributeTableView->edit
396 (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
401 void BranchPropertyEditor::deleteAttributeClicked()
403 qDebug() << "BranchPropEditor::deleteAttribute";
406 void BranchPropertyEditor::connectSignals()
409 connect(ui.framePenColorButton, SIGNAL(clicked()), this,
410 SLOT(framePenColorClicked()));
411 connect(ui.framePaddingSpinBox, SIGNAL(valueChanged(int)), this,
412 SLOT(framePaddingChanged(int)));
413 connect(ui.frameWidthSpinBox, SIGNAL(valueChanged(int)), this,
414 SLOT(frameBorderWidthChanged(int)));
415 connect(ui.frameBrushColorButton, SIGNAL(clicked()), this,
416 SLOT(frameBrushColorClicked()));
417 connect(ui.frameTypeCombo, SIGNAL(currentIndexChanged(int)), this,
418 SLOT(frameTypeChanged(int)));
419 connect(ui.includeChildrenCheckBox, SIGNAL(stateChanged(int)), this,
420 SLOT(frameIncludeChildrenChanged(int)));
423 connect(ui.hideLinkIfUnselected, SIGNAL(stateChanged(int)), this,
424 SLOT(linkHideUnselectedChanged(int)));
427 connect(ui.incImgVer, SIGNAL(stateChanged(int)), this,
428 SLOT(incImgVerChanged(int)));
429 connect(ui.incImgHor, SIGNAL(stateChanged(int)), this,
430 SLOT(incImgHorChanged(int)));
431 connect(ui.childrenFreePositioning, SIGNAL(stateChanged(int)), this,
432 SLOT(childrenFreePositioningChanged(int)));
435 connect(ui.taskPrioDelta, SIGNAL(valueChanged(int)), this,
436 SLOT(taskPriorityDeltaChanged(int)));
439 // For the time being hide above buttons, not used
442 ui.addAttributeButton, SIGNAL (clicked()),
443 this, SLOT (addAttributeClicked()));
445 ui.deleteAttributeButton, SIGNAL (clicked()),
446 this, SLOT (deleteAttributeClicked()));
449 ui.addAttributeButton->hide();
450 ui.deleteAttributeButton->hide();
453 void BranchPropertyEditor::disconnectSignals()
456 disconnect(ui.framePenColorButton, 0, 0, 0);
457 disconnect(ui.framePaddingSpinBox, 0, 0, 0);
458 disconnect(ui.frameWidthSpinBox, 0, 0, 0);
459 disconnect(ui.frameBrushColorButton, 0, 0, 0);
460 disconnect(ui.frameTypeCombo, 0, 0, 0);
461 disconnect(ui.includeChildrenCheckBox, 0, 0, 0);
464 disconnect(ui.hideLinkIfUnselected, 0, 0, 0);
467 disconnect(ui.incImgVer, 0, 0, 0);
468 disconnect(ui.incImgHor, 0, 0, 0);
469 disconnect(ui.childrenFreePositioning, 0, 0, 0);
472 disconnect(ui.taskPrioDelta, 0, 0, 0);
475 disconnect (ui.addAttributeButton, 0, 0, 0);
476 disconnect (ui.deleteAttributeButton, 0, 0, 0);