• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/VisualEditor

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • VisualEditor
  • Interface
PointerPropertiesWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2009-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
5  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "PointerPropertiesWidget.h"
22 #include "Pointer.h"
23 #include "model_GraphProperties.h"
24 #include "DataStructure.h"
25 #include "Actions/PropertiesDialogAction.h"
26 #include <DataStructureBackendManager.h>
27 
28 PointerPropertiesWidget::PointerPropertiesWidget(PointerPtr pointer, QWidget* parent)
29  : KDialog(parent)
30 {
31  ui = new Ui::PointerPropertiesWidget;
32  ui->setupUi(mainWidget());
33 
34  // edit data types by separate dialog
35  QPointer<PropertiesDialogAction> dataTypePropertiesAction = new PropertiesDialogAction(
36  i18n("Edit Pointer Types"), pointer->dataStructure()->document()->pointerType(pointer->pointerType()), this);
37  ui->_editType->setDefaultAction(dataTypePropertiesAction);
38  ui->_editType->setIcon(KIcon("document-properties"));
39  connect(pointer->dataStructure()->document(), SIGNAL(dataTypeCreated(int)), this, SLOT(updatePointerTypes()));
40  connect(pointer->dataStructure()->document(), SIGNAL(dataTypeRemoved(int)), this, SLOT(updatePointerTypes()));
41 
42  setCaption(i18nc("@title:window", "Pointer Properties"));
43  setButtons(Close);
44  setAttribute(Qt::WA_DeleteOnClose);
45  setPointer(pointer);
46 }
47 
48 
49 void PointerPropertiesWidget::setPointer(PointerPtr pointer)
50 {
51  PointerTypePtr pointerType;
52  if (_pointer == pointer) {
53  return;
54  }
55  if (_pointer) {
56  pointerType = _pointer->dataStructure()->document()->pointerType(_pointer->pointerType());
57  pointerType->disconnect(this);
58  _pointer->disconnect(this);
59  ui->_pointerType->clear();
60  }
61  _pointer = pointer;
62 
63  updatePointerTypes();
64 
65  // listen to pointer changes
66  connect(_pointer.get(), SIGNAL(changed()), this, SLOT(reflectAttributes()));
67 
68  // connect ui
69  connect(ui->_pointerType, SIGNAL(currentIndexChanged(int)),
70  this, SLOT(setPointerType(int)));
71  connect(ui->_width, SIGNAL(valueChanged(double)), this, SLOT(setWidth(double)));
72  connect(ui->_color, SIGNAL(activated(QColor)), this, SLOT(setColor(QColor)));
73 
74  // listen to pointer type changes
75  pointerType = _pointer->dataStructure()->document()->pointerType(_pointer->pointerType());
76  connect(pointerType.get(), SIGNAL(propertyAdded(QString,QVariant)), this, SLOT(updateProperties()));
77  connect(pointerType.get(), SIGNAL(propertyRemoved(QString)), this, SLOT(updateProperties()));
78  connect(pointerType.get(), SIGNAL(propertyRenamed(QString,QString)), this, SLOT(updateProperties()));
79 
80  reflectAttributes();
81 
82  GraphPropertiesModel *model = new GraphPropertiesModel();
83  model->setDataSource(_pointer.get());
84 
85  ui->_propertiesTable->setModel(model);
86  ui->_propertiesTable->horizontalHeader()->setProperty("stretchLastSection", true);
87 }
88 
89 void PointerPropertiesWidget::setPosition(QPointF screenPosition)
90 {
91  move(screenPosition.x() + 10, screenPosition.y() + 10);
92 }
93 
94 void PointerPropertiesWidget::reflectAttributes()
95 {
96  if (!ui->extraItems->layout()) {
97  ui->extraItems->setLayout(DataStructureBackendManager::self().pointerExtraProperties(_pointer, this));
98  }
99 
100  ui->_color->setColor(_pointer->color());
101  ui->_width->setValue(_pointer->width());
102 
103  PointerTypePtr pointerType = _pointer->dataStructure()->document()->pointerType(_pointer->pointerType());
104  ui->_pointerType->setCurrentIndex(ui->_pointerType->findData(QVariant(_pointer->pointerType())));
105 }
106 
107 void PointerPropertiesWidget::setWidth(double v)
108 {
109  _pointer->setWidth(static_cast<qreal>(v));
110 }
111 
112 
113 void PointerPropertiesWidget::setColor(const QColor& c)
114 {
115  _pointer->setColor(c.name());
116 }
117 
118 void PointerPropertiesWidget::setPointerType(int pointerTypeIndex)
119 {
120  _pointer->setPointerType(ui->_pointerType->itemData(pointerTypeIndex).toInt());
121 }
122 
123 void PointerPropertiesWidget::updatePointerTypes()
124 {
125  ui->_pointerType->clear();
126  // setup data types combobox
127  foreach (int type, _pointer->dataStructure()->document()->pointerTypeList()) {
128  QString typeString = _pointer->dataStructure()->document()->pointerType(type)->name();
129  ui->_pointerType->addItem(typeString, QVariant(type));
130  }
131  if (_pointer) {
132  ui->_pointerType->setCurrentIndex(ui->_pointerType->findData(QVariant(_pointer->pointerType())));
133  }
134 }
135 
136 void PointerPropertiesWidget::updateProperties()
137 {
138  // TODO the following can be solved much nicer by updating the model
139  GraphPropertiesModel *model = new GraphPropertiesModel();
140  model->setDataSource(_pointer.get());
141  ui->_propertiesTable->model()->deleteLater();
142  ui->_propertiesTable->setModel(model);
143 }
PointerPropertiesWidget::setPosition
void setPosition(QPointF screenPosition)
Definition: PointerPropertiesWidget.cpp:89
QWidget
PropertiesDialogAction
Definition: PropertiesDialogAction.h:31
QColor::name
QString name() const
PointerPropertiesWidget::reflectAttributes
void reflectAttributes()
Definition: PointerPropertiesWidget.cpp:94
QPointer
KDialog
PointerPropertiesWidget::setPointer
void setPointer(PointerPtr e)
Definition: PointerPropertiesWidget.cpp:49
PointerPropertiesWidget.h
QPointF
PropertiesDialogAction.h
QPointF::x
qreal x() const
QPointF::y
qreal y() const
GraphPropertiesModel
Definition: model_GraphProperties.h:29
PointerPropertiesWidget::setPointerType
void setPointerType(int pointerTypeIndex)
Definition: PointerPropertiesWidget.cpp:118
QString
QColor
model_GraphProperties.h
PointerPropertiesWidget::setWidth
void setWidth(double v)
Definition: PointerPropertiesWidget.cpp:107
PointerPropertiesWidget::updateProperties
void updateProperties()
Definition: PointerPropertiesWidget.cpp:136
GraphPropertiesModel::setDataSource
void setDataSource(QObject *dataSource)
Definition: model_GraphProperties.cpp:95
PointerPropertiesWidget::updatePointerTypes
void updatePointerTypes()
Definition: PointerPropertiesWidget.cpp:123
PointerPropertiesWidget::PointerPropertiesWidget
PointerPropertiesWidget(PointerPtr pointer, QWidget *parent=0)
Definition: PointerPropertiesWidget.cpp:28
PointerPropertiesWidget::setColor
void setColor(const QColor &c)
Definition: PointerPropertiesWidget.cpp:113
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/VisualEditor

Skip menu "rocs/VisualEditor"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal