]> git.sven.stormbind.net Git - sven/vym.git/blob - branchpropeditor.cpp
Import Upstream version 2.6.11
[sven/vym.git] / branchpropeditor.cpp
1 #include "branchpropeditor.h"
2
3 #include <QColorDialog>
4
5 #include "branchitem.h"
6 #include "frameobj.h"
7 #include "settings.h"
8 #include "vymmodel.h"
9
10 extern Settings settings;
11 extern QString vymName;
12
13
14 BranchPropertyEditor::BranchPropertyEditor (QWidget *parent): QDialog (parent)  // FIXME-4 not updating when data is set elsewhere (connect to dataCHanged)
15
16 {
17     ui.setupUi (this);
18
19     setWindowTitle (vymName +" - " +tr ("Property Editor","Window caption"));
20
21     branchObj=NULL;
22     branchItem=NULL;
23     model=NULL;
24
25     ui.tabWidget->setEnabled(false);
26
27     penColor=QColor (Qt::black);
28     brushColor=QColor (Qt::black);
29     QPixmap pix( 16,16);
30     pix.fill (penColor);
31     ui.framePenColorButton->setIcon (pix);
32     ui.frameBrushColorButton->setIcon (pix);
33
34     if (!settings.value( "/mainwindow/showTestMenu",false).toBool() )
35         ui.tabWidget->widget (3)->hide();
36
37
38     /* Create Model and View to hold attributes
39     attributeModel = new QStandardItemModel (1,3,this);
40     attributeModel->setHeaderData(0, Qt::Horizontal, tr("Name","Branchprop window: Attribute name"));
41     attributeModel->setHeaderData(1, Qt::Horizontal, tr("Value","Branchprop window: Attribute value"));
42     attributeModel->setHeaderData(2, Qt::Horizontal, tr("Type","Branchprop window: Attribute type"));
43     ui.attributeTableView->setModel (attributeModel);
44     */
45
46     // Load Settings
47     resize (settings.value ( "/satellite/propertywindow/geometry/size", QSize(450,600)).toSize());
48     move   (settings.value ( "/satellite/propertywindow/geometry/pos", QPoint (250,50)).toPoint());
49     
50     if (settings.value ( "/satellite/propertywindow/showWithMain",true).toBool())
51         show();
52     else
53         hide();
54 }
55
56 BranchPropertyEditor::~BranchPropertyEditor ()
57 {
58     settings.setValue( "/satellite/propertywindow/geometry/size", size() );
59     settings.setValue( "/satellite/propertywindow/geometry/pos", pos() );
60     settings.setValue( "/satellite/propertywindow/showWithMain",isVisible() );
61 }
62
63 void BranchPropertyEditor::setItem (TreeItem *ti)   
64 {
65     disconnectSignals();
66     if (!ti)
67         ui.tabWidget->setEnabled (false);
68     else if (ti->isBranchLikeType() )
69     {
70         branchItem=(BranchItem*)ti;
71
72         branchObj=(BranchObj*)(branchItem->getLMO());
73         if (branchObj)      // FIXME-4 replace by branchItem later, when Frame is ported...
74         {
75             ui.tabWidget->setEnabled (true);
76             for (int i=0; i<3;++i)
77                 ui.tabWidget->setTabEnabled (i,true);
78             ui.tabWidget->setTabEnabled (3,false);
79
80             // Frame
81             FrameObj::FrameType t=branchObj->getFrameType();
82             if (t==FrameObj::NoFrame)   // FIXME-3 Check if all below depends on frame type???
83             {
84                 ui.frameTypeCombo->setCurrentIndex (0);
85                 penColor=Qt::white;
86                 brushColor=Qt::white;
87                 ui.colorGroupBox->setEnabled (false);
88                 ui.framePaddingSpinBox->setEnabled (false);
89                 ui.frameWidthSpinBox->setEnabled (false);
90                 ui.framePaddingLabel->setEnabled (false);
91                 ui.frameBorderLabel->setEnabled (false);
92                 ui.includeChildrenCheckBox->setEnabled (false);
93                 ui.includeChildrenCheckBox->setEnabled (false);
94             } else
95             {
96                 penColor=branchObj->getFramePenColor();
97                 brushColor=branchObj->getFrameBrushColor();
98                 QPixmap pix( 16,16);
99                 pix.fill (penColor);
100                 ui.framePenColorButton->setIcon (pix);
101                 pix.fill (brushColor);
102                 ui.frameBrushColorButton->setIcon (pix);
103                 ui.colorGroupBox->setEnabled (true);
104                 ui.framePaddingSpinBox->setEnabled (true);
105                 ui.framePaddingSpinBox->setValue (branchObj->getFramePadding());
106                 ui.frameWidthSpinBox->setEnabled (true);
107                 ui.frameWidthSpinBox->setValue (branchObj->getFrameBorderWidth());
108                 ui.framePaddingLabel->setEnabled (true);
109                 ui.frameBorderLabel->setEnabled (true);
110                 ui.includeChildrenCheckBox->setEnabled (true);
111
112                 switch (t)
113                 {
114                 case FrameObj::Rectangle:
115                     ui.frameTypeCombo->setCurrentIndex (1);
116                     break;
117                 case FrameObj::RoundedRectangle:
118                     ui.frameTypeCombo->setCurrentIndex (2);
119                     break;
120                 case FrameObj::Ellipse:
121                     ui.frameTypeCombo->setCurrentIndex (3);
122                     break;
123                 case FrameObj::Cloud:
124                     ui.frameTypeCombo->setCurrentIndex (4);
125                     break;
126                 default:
127                     break;
128                 }
129                 if (branchItem->getFrameIncludeChildren())
130                     ui.includeChildrenCheckBox->setCheckState (Qt::Checked);
131                 else
132                     ui.includeChildrenCheckBox->setCheckState (Qt::Unchecked);
133             }
134             // Link
135             if (branchItem->getHideLinkUnselected())
136                 ui.hideLinkIfUnselected->setCheckState (Qt::Checked);
137             else
138                 ui.hideLinkIfUnselected->setCheckState (Qt::Unchecked);
139
140             // Layout
141             if (branchItem->getIncludeImagesVer())
142                 ui.incImgVer->setCheckState (Qt::Checked);
143             else
144                 ui.incImgVer->setCheckState (Qt::Unchecked);
145             if (branchItem->getIncludeImagesHor())
146                 ui.incImgHor->setCheckState (Qt::Checked);
147             else
148                 ui.incImgHor->setCheckState (Qt::Unchecked);
149             if (branchItem->getChildrenLayout() == BranchItem::FreePositioning)
150                 ui.childrenFreePositioning->setCheckState( Qt::Checked);
151             else
152                 ui.childrenFreePositioning->setCheckState( Qt::Unchecked);
153
154
155             /*
156         // Attributes
157         attributeModel->removeRows(0, attributeModel->rowCount(), QModelIndex());
158
159         // some samples for attribute testing
160         QStringList attrTypes=mapEditor->attributeTable()->getTypes();
161         for (int i=0; i<attrTypes.count()-1;i++)
162         {
163         attributeModel->insertRow (i,QModelIndex ());
164         attributeModel->setData(attributeModel->index(i, 0, QModelIndex()), QString ("Name %1").arg(i));
165         attributeModel->setData(attributeModel->index(i, 1, QModelIndex()), i);
166         attributeModel->setData(attributeModel->index(i, 2, QModelIndex()), attrTypes.at(i));
167         }
168
169
170         ui.attributeTableView->resizeColumnsToContents();
171
172         // Initialize Delegate
173         delegate.setAttributeTable (mapEditor->attributeTable());
174         ui.attributeTableView->setItemDelegate (&delegate);
175     */
176
177             // Finally activate signals
178             connectSignals();
179         } // BranchItem
180     } else if (ti->getType()==TreeItem::Attribute)
181     {
182         ui.tabWidget->setEnabled (true);
183         for (int i=0; i<3;++i)
184             ui.tabWidget->setTabEnabled (i,false);
185         ui.tabWidget->setTabEnabled (3,true);
186     } else
187     {
188         ui.tabWidget->setEnabled (false);
189     }
190 }
191
192 void BranchPropertyEditor::setModel (VymModel *m)
193 {
194     model=m;
195     if (model) 
196         setItem (model->getSelectedItem() );
197     else
198         ui.tabWidget->setEnabled (false);
199         
200 }
201
202 void BranchPropertyEditor::frameTypeChanged (int i)
203 {
204     if (model)
205     {
206         switch (i)
207         {
208             case 0: model->setFrameType (FrameObj::NoFrame); break;
209             case 1: 
210                 model->setFrameType (FrameObj::Rectangle); 
211                 break;
212             case 2: 
213                 model->setFrameType (FrameObj::RoundedRectangle); 
214                 break;
215             case 3: 
216                 model->setFrameType (FrameObj::Ellipse); 
217                 break;
218             case 4: 
219                 model->setFrameType (FrameObj::Cloud); 
220                 break;
221         }
222         setItem (branchItem);
223     }   
224 }
225
226 void BranchPropertyEditor::framePenColorClicked()
227 {
228     if (model) 
229     {   
230         QColor col = QColorDialog::getColor( penColor, this );
231         if ( col.isValid() ) 
232         {
233             penColor=col;
234             model->setFramePenColor (penColor);
235         }   
236     }
237 }
238
239 void BranchPropertyEditor::frameBrushColorClicked()
240 {
241     if (model) 
242     {
243         QColor col = QColorDialog::getColor( brushColor, this );
244         if ( col.isValid() ) 
245         {
246             brushColor=col;
247             model->setFrameBrushColor (brushColor);
248         }   
249     }   
250 }
251
252 void BranchPropertyEditor::framePaddingChanged(int i)
253 {
254     if (model) model->setFramePadding (i);
255 }
256
257 void BranchPropertyEditor::frameBorderWidthChanged(int i)
258 {
259     if (model) model->setFrameBorderWidth(i);
260 }
261
262 void BranchPropertyEditor::frameIncludeChildrenChanged(int i)
263 {
264     if (model) model->setFrameIncludeChildren(i);
265 }
266
267 void BranchPropertyEditor::linkHideUnselectedChanged (int i)
268 {
269     if (!branchItem) return;
270     model->setHideLinkUnselected(i);
271 }
272
273 void BranchPropertyEditor::incImgVerChanged (int  i)
274 {
275     if (model) model->setIncludeImagesVer (i);
276 }
277
278 void BranchPropertyEditor::incImgHorChanged (int  i)
279 {
280     if (model) model->setIncludeImagesHor (i);
281 }
282
283 void BranchPropertyEditor::childrenFreePositioningChanged (int  i)
284 {
285     if (model)
286     {
287         if (i>0)
288             model->setChildrenLayout( BranchItem::FreePositioning);
289         else
290             model->setChildrenLayout( BranchItem::AutoPositioning);
291     }
292 }
293
294 void BranchPropertyEditor::closeEvent( QCloseEvent* ce )
295 {
296     ce->accept();   // can be reopened with show()
297     hide();
298     emit (windowClosed() );
299     return;
300 }
301
302 /*
303 void BranchPropertyEditor::addAttributeClicked()
304 {
305     // Add empty line for adding attributes
306     attributeModel->insertRow (attributeModel->rowCount (),QModelIndex ());
307     attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 0, QModelIndex()),  "Add new");
308     attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  "Undefined");
309
310     // Select attribute from list
311     ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,0, QModelIndex() ));
312     ui.attributeTableView->resizeColumnsToContents();
313
314 //  QString attname=attributeModel->in
315 //  attributeModel->setData(attributeModel->index(attributeModel->rowCount()-1, 2, QModelIndex()),  );
316
317
318
319     ui.attributeTableView->edit (attributeModel->index(attributeModel->rowCount()-1,1, QModelIndex() ));
320
321 }
322
323 void BranchPropertyEditor::deleteAttributeClicked()
324 {
325     //qDebug() << "BPW::delete";
326 }
327 */
328
329 void BranchPropertyEditor::connectSignals()
330 {
331     // Frame
332     connect ( 
333         ui.framePenColorButton, SIGNAL (clicked()),
334         this, SLOT (framePenColorClicked()));
335     connect ( 
336         ui.framePaddingSpinBox, SIGNAL (valueChanged( int)),
337         this, SLOT (framePaddingChanged (int)));
338     connect ( 
339         ui.frameWidthSpinBox, SIGNAL (valueChanged( int)),
340         this, SLOT (frameBorderWidthChanged (int)));
341     connect ( 
342         ui.frameBrushColorButton, SIGNAL (clicked()),
343         this, SLOT (frameBrushColorClicked()));
344     connect ( 
345         ui.frameTypeCombo, SIGNAL (currentIndexChanged( int)),
346         this, SLOT (frameTypeChanged (int)));
347     connect ( 
348         ui.includeChildrenCheckBox, SIGNAL (stateChanged( int)),
349         this, SLOT (frameIncludeChildrenChanged (int)));
350
351     // Link 
352     connect ( 
353         ui.hideLinkIfUnselected, SIGNAL (stateChanged( int)),
354         this, SLOT (linkHideUnselectedChanged (int)));
355
356     // Layout   
357     connect ( 
358         ui.incImgVer, SIGNAL (stateChanged( int)),
359         this, SLOT (incImgVerChanged (int)));
360     connect ( 
361         ui.incImgHor, SIGNAL (stateChanged( int)),
362         this, SLOT (incImgHorChanged (int)));
363     connect (
364         ui.childrenFreePositioning, SIGNAL (stateChanged( int)),
365         this, SLOT (childrenFreePositioningChanged (int)));
366
367 /*
368     // Attributes   
369     connect ( 
370         ui.addAttributeButton, SIGNAL (clicked()), 
371         this, SLOT (addAttributeClicked()));
372     connect ( 
373         ui.deleteAttributeButton, SIGNAL (clicked()), 
374         this, SLOT (deleteAttributeClicked()));
375 */      
376 }
377
378
379 void BranchPropertyEditor::disconnectSignals()
380 {
381     // Frame 
382     disconnect ( ui.frameTypeCombo, 0,0,0);
383     disconnect ( ui.framePenColorButton, 0,0,0);
384     disconnect ( ui.framePaddingSpinBox, 0,0,0);
385     disconnect ( ui.frameWidthSpinBox, 0,0,0);
386     disconnect ( ui.frameBrushColorButton, 0,0,0);
387     disconnect ( ui.includeChildrenCheckBox, 0,0,0);
388
389     // Link 
390     disconnect ( ui.hideLinkIfUnselected, 0,0,0);
391
392     // Layout   
393     disconnect ( ui.incImgVer, 0,0,0);
394     disconnect ( ui.incImgHor, 0,0,0);
395     disconnect ( ui.childrenFreePositioning, 0,0,0);
396
397     // Attributes
398     /*
399     disconnect ( ui.addAttributeButton, 0,0,0);
400     disconnect ( ui.deleteAttributeButton, 0,0,0);
401     */
402 }
403
404