2
This file is part of Rocs,
3
Copyright 2008-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4
Copyright 2008 Ugo Sangiori <ugorox@gmail.com>
5
Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
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.
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.
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/>.
21
#include "DocumentTypesWidget.h"
27
#include "PointerType.h"
28
#include "Scene/DataItem.h"
29
#include "Scene/PointerItem.h"
30
#include "DocumentManager.h"
31
#include "Actions/PropertiesDialogAction.h"
36
#include <KColorCombo>
37
#include <KPushButton>
40
DocumentTypesWidget::DocumentTypesWidget(QWidget* parent)
44
ui = new Ui::DocumentTypesWidget;
47
connect(&DocumentManager::self(), SIGNAL(documentRemoved(Document*)),
48
this, SLOT(removeDocument()));
49
connect(&DocumentManager::self(), SIGNAL(activateDocument()),
50
this, SLOT(updateDocument()));
53
DocumentTypesWidget::~DocumentTypesWidget()
57
void DocumentTypesWidget::updateDocument()
61
_document = DocumentManager::self().activeDocument();
62
// create default data element setups
63
Document* document = DocumentManager::self().activeDocument();
64
foreach (int type, document->dataTypeList()) {
65
createDataTypeInformationWidget(type, _document);
67
foreach (int type, document->pointerTypeList()) {
68
createPointerTypeInformationWidget(type, _document);
71
// react on new data types and pointer types
72
connect(_document, SIGNAL(dataTypeCreated(int)), this, SLOT(registerDataType(int)));
73
connect(_document, SIGNAL(dataTypeRemoved(int)), this, SLOT(unregisterDataType(int)));
74
connect(_document, SIGNAL(pointerTypeCreated(int)), this, SLOT(registerPointerType(int)));
75
connect(_document, SIGNAL(pointerTypeRemoved(int)), this, SLOT(unregisterPointerType(int)));
78
void DocumentTypesWidget::registerDataType(int identifier)
80
createDataTypeInformationWidget(identifier, _document);
83
void DocumentTypesWidget::removeDocument()
89
_document->disconnect(this);
91
// cleanup before filling again
92
QList<int> identifiers;
93
identifiers = _dataTypeWidgets.keys();
94
foreach (int identifier, identifiers) {
95
delete _dataTypeWidgets[identifier];
96
_dataTypeWidgets.remove(identifier);
97
_dataTypeButtons.remove(identifier);
99
identifiers = _pointerTypeWidgets.keys();
100
foreach (int identifier, identifiers) {
101
delete _pointerTypeWidgets[identifier];
102
_pointerTypeWidgets.remove(identifier);
103
_pointerTypeButtons.remove(identifier);
108
void DocumentTypesWidget::unregisterDataType(int identifier)
110
if (!_dataTypeWidgets.contains(identifier)) {
113
delete _dataTypeWidgets[identifier];
114
_dataTypeWidgets.remove(identifier);
115
_dataTypeButtons.remove(identifier);
118
void DocumentTypesWidget::registerPointerType(int identifier)
120
Document* document = DocumentManager::self().activeDocument();
121
createPointerTypeInformationWidget(identifier, document);
124
void DocumentTypesWidget::unregisterPointerType(int identifier)
126
if (!_pointerTypeWidgets.contains(identifier)) {
129
delete _pointerTypeWidgets[identifier];
130
_pointerTypeWidgets.remove(identifier);
131
_pointerTypeButtons.remove(identifier);
134
bool DocumentTypesWidget::createDataTypeInformationWidget(int typeIdentifier, Document* document)
136
if (!document->dataTypeList().contains(typeIdentifier)) {
140
DataTypePtr dataType = document->dataType(typeIdentifier);
142
// create default data element setups
143
QWidget* dataPropertyWidget = new QWidget(this);
144
QGridLayout* dataPropertyLayout = new QGridLayout(dataPropertyWidget);
145
KPushButton* dataTypeButton = new KPushButton(this);
146
dataTypeButton->setFlat(true);
147
dataTypeButton->setStyleSheet("text-align: left");
148
KAction* dataAction = new PropertiesDialogAction(i18nc("@action:inmenu", "Properties"), dataType, dataPropertyWidget);
149
dataTypeButton->addAction(dataAction);
150
dataTypeButton->setIcon(dataType->icon());
151
dataTypeButton->setText(dataType->name());
152
connect(dataTypeButton, SIGNAL(pressed()), dataAction, SLOT(trigger()));
155
KPushButton* dataTypeVisible = new KPushButton(this);
156
dataTypeVisible->setIcon(KIcon("rocseyeblack"));
157
dataTypeVisible->setCheckable(true);
158
dataTypeVisible->setChecked(true);
159
dataTypeVisible->setFixedWidth(24);
161
dataPropertyWidget->setLayout(dataPropertyLayout);
162
dataPropertyLayout->addWidget(dataTypeButton, 1, 1);
163
dataPropertyLayout->addWidget(dataTypeVisible, 1, 2);
164
ui->_dataTypes->addWidget(dataPropertyWidget);
166
connect(dataTypeVisible, SIGNAL(toggled(bool)), dataType.get(), SLOT(setVisible(bool)));
167
connect(dataType.get(), SIGNAL(iconChanged(QString)), this, SLOT(updateDataTypeButtons()));
168
connect(dataType.get(), SIGNAL(nameChanged(QString)), this, SLOT(updateDataTypeButtons()));
170
_dataTypeWidgets.insert(typeIdentifier, dataPropertyWidget);
171
_dataTypeButtons.insert(typeIdentifier, dataTypeButton);
176
bool DocumentTypesWidget::createPointerTypeInformationWidget(int typeIdentifier, Document* document)
178
if (!document->pointerTypeList().contains(typeIdentifier)) {
182
PointerTypePtr pointerType = document->pointerType(typeIdentifier);
184
// create default data element setups
185
QWidget* pointerPropertyWidget = new QWidget(this);
186
QGridLayout* pointerPropertyLayout = new QGridLayout(pointerPropertyWidget);
188
KPushButton* pointerTypeButton = new KPushButton(this);
189
pointerTypeButton->setText(pointerType->name());
190
pointerTypeButton->setFlat(true);
191
pointerTypeButton->setStyleSheet("text-align: left");
192
KAction* pointerAction = new PropertiesDialogAction(i18nc("@action:inmenu", "Properties"), pointerType, pointerPropertyWidget);
193
connect(pointerTypeButton, SIGNAL(pressed()), pointerAction, SLOT(trigger()));
195
KPushButton* pointerTypeVisible = new KPushButton(this);
196
pointerTypeVisible->setIcon(KIcon("rocseyeblack"));
197
pointerTypeVisible->setCheckable(true);
198
pointerTypeVisible->setChecked(true);
199
pointerTypeVisible->setToolTip(i18nc("@info:tooltip", "Set visibility of pointers"));
200
pointerTypeVisible->setFixedWidth(24);
202
pointerPropertyWidget->setLayout(pointerPropertyLayout);
203
pointerPropertyLayout->addWidget(pointerTypeButton, 1, 1);
204
pointerPropertyLayout->addWidget(pointerTypeVisible, 1, 2);
205
ui->_pointerTypes->addWidget(pointerPropertyWidget);
207
connect(pointerTypeVisible, SIGNAL(toggled(bool)), pointerType.get(), SLOT(setVisible(bool)));
208
connect(pointerType.get(), SIGNAL(nameChanged(QString)), this, SLOT(updatePointerTypeButtons()));
210
_pointerTypeWidgets.insert(typeIdentifier, pointerPropertyWidget);
211
_pointerTypeButtons.insert(typeIdentifier, pointerTypeButton);
216
void DocumentTypesWidget::updateDataTypeButtons()
218
QMap<int, KPushButton*>::const_iterator dataTypeWidget = _dataTypeButtons.constBegin();
219
while (dataTypeWidget != _dataTypeButtons.constEnd()) {
220
Document* activeDocument = DocumentManager::self().activeDocument();
221
DataTypePtr dataType = activeDocument->dataType(dataTypeWidget.key());
222
dataTypeWidget.value()->setIcon(dataType->icon());
223
dataTypeWidget.value()->setText(dataType->name());
228
void DocumentTypesWidget::updatePointerTypeButtons()
230
QMap<int, KPushButton*>::const_iterator pointerTypeWidget = _pointerTypeButtons.constBegin();
231
while (pointerTypeWidget != _pointerTypeButtons.constEnd()) {
232
Document* activeDocument = DocumentManager::self().activeDocument();
233
PointerTypePtr pointerType = activeDocument->pointerType(pointerTypeWidget.key());
234
pointerTypeWidget.value()->setText(pointerType->name());