~ubuntu-branches/ubuntu/saucy/rocs/saucy-proposed

« back to all changes in this revision

Viewing changes to App/Ui/DocumentTypesWidget.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg, Rohan Garg, Philip Muškovac
  • Date: 2013-06-21 02:04:20 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20130621020420-lzlui9y7qc6w3xog
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release

[ Philip Muškovac ]
* Build-depend on libgrantlee-dev and libx11-dev
* Update rocs.install and not-installed 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
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 "DocumentTypesWidget.h"
 
22
 
 
23
#include "Document.h"
 
24
#include "Data.h"
 
25
#include "DataType.h"
 
26
#include "Pointer.h"
 
27
#include "PointerType.h"
 
28
#include "Scene/DataItem.h"
 
29
#include "Scene/PointerItem.h"
 
30
#include "DocumentManager.h"
 
31
#include "Actions/PropertiesDialogAction.h"
 
32
 
 
33
#include <KLocale>
 
34
#include <KDebug>
 
35
#include <KAction>
 
36
#include <KColorCombo>
 
37
#include <KPushButton>
 
38
#include <QWidget>
 
39
 
 
40
DocumentTypesWidget::DocumentTypesWidget(QWidget* parent)
 
41
    : QWidget(parent)
 
42
    , _document(0)
 
43
{
 
44
    ui = new Ui::DocumentTypesWidget;
 
45
    ui->setupUi(this);
 
46
 
 
47
    connect(&DocumentManager::self(), SIGNAL(documentRemoved(Document*)),
 
48
            this, SLOT(removeDocument()));
 
49
    connect(&DocumentManager::self(), SIGNAL(activateDocument()),
 
50
            this, SLOT(updateDocument()));
 
51
}
 
52
 
 
53
DocumentTypesWidget::~DocumentTypesWidget()
 
54
{
 
55
}
 
56
 
 
57
void DocumentTypesWidget::updateDocument()
 
58
{
 
59
    removeDocument();
 
60
 
 
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);
 
66
    }
 
67
    foreach (int type, document->pointerTypeList()) {
 
68
        createPointerTypeInformationWidget(type, _document);
 
69
    }
 
70
 
 
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)));
 
76
}
 
77
 
 
78
void DocumentTypesWidget::registerDataType(int identifier)
 
79
{
 
80
    createDataTypeInformationWidget(identifier, _document);
 
81
}
 
82
 
 
83
void DocumentTypesWidget::removeDocument()
 
84
{
 
85
    if (_document == 0) {
 
86
        return;
 
87
    }
 
88
 
 
89
    _document->disconnect(this);
 
90
 
 
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);
 
98
    }
 
99
    identifiers = _pointerTypeWidgets.keys();
 
100
    foreach (int identifier, identifiers) {
 
101
        delete _pointerTypeWidgets[identifier];
 
102
        _pointerTypeWidgets.remove(identifier);
 
103
        _pointerTypeButtons.remove(identifier);
 
104
    }
 
105
    _document = 0;
 
106
}
 
107
 
 
108
void DocumentTypesWidget::unregisterDataType(int identifier)
 
109
{
 
110
    if (!_dataTypeWidgets.contains(identifier)) {
 
111
        return;
 
112
    }
 
113
    delete _dataTypeWidgets[identifier];
 
114
    _dataTypeWidgets.remove(identifier);
 
115
    _dataTypeButtons.remove(identifier);
 
116
}
 
117
 
 
118
void DocumentTypesWidget::registerPointerType(int identifier)
 
119
{
 
120
    Document* document = DocumentManager::self().activeDocument();
 
121
    createPointerTypeInformationWidget(identifier, document);
 
122
}
 
123
 
 
124
void DocumentTypesWidget::unregisterPointerType(int identifier)
 
125
{
 
126
    if (!_pointerTypeWidgets.contains(identifier)) {
 
127
        return;
 
128
    }
 
129
    delete _pointerTypeWidgets[identifier];
 
130
    _pointerTypeWidgets.remove(identifier);
 
131
    _pointerTypeButtons.remove(identifier);
 
132
}
 
133
 
 
134
bool DocumentTypesWidget::createDataTypeInformationWidget(int typeIdentifier, Document* document)
 
135
{
 
136
    if (!document->dataTypeList().contains(typeIdentifier)) {
 
137
        return false;
 
138
    }
 
139
 
 
140
    DataTypePtr dataType = document->dataType(typeIdentifier);
 
141
 
 
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()));
 
153
 
 
154
 
 
155
    KPushButton* dataTypeVisible = new KPushButton(this);
 
156
    dataTypeVisible->setIcon(KIcon("rocseyeblack"));
 
157
    dataTypeVisible->setCheckable(true);
 
158
    dataTypeVisible->setChecked(true);
 
159
    dataTypeVisible->setFixedWidth(24);
 
160
 
 
161
    dataPropertyWidget->setLayout(dataPropertyLayout);
 
162
    dataPropertyLayout->addWidget(dataTypeButton, 1, 1);
 
163
    dataPropertyLayout->addWidget(dataTypeVisible, 1, 2);
 
164
    ui->_dataTypes->addWidget(dataPropertyWidget);
 
165
 
 
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()));
 
169
 
 
170
    _dataTypeWidgets.insert(typeIdentifier, dataPropertyWidget);
 
171
    _dataTypeButtons.insert(typeIdentifier, dataTypeButton);
 
172
 
 
173
    return true;
 
174
}
 
175
 
 
176
bool DocumentTypesWidget::createPointerTypeInformationWidget(int typeIdentifier, Document* document)
 
177
{
 
178
    if (!document->pointerTypeList().contains(typeIdentifier)) {
 
179
        return false;
 
180
    }
 
181
 
 
182
    PointerTypePtr pointerType = document->pointerType(typeIdentifier);
 
183
 
 
184
    // create default data element setups
 
185
    QWidget* pointerPropertyWidget = new QWidget(this);
 
186
    QGridLayout* pointerPropertyLayout = new QGridLayout(pointerPropertyWidget);
 
187
 
 
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()));
 
194
 
 
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);
 
201
 
 
202
    pointerPropertyWidget->setLayout(pointerPropertyLayout);
 
203
    pointerPropertyLayout->addWidget(pointerTypeButton, 1, 1);
 
204
    pointerPropertyLayout->addWidget(pointerTypeVisible, 1, 2);
 
205
    ui->_pointerTypes->addWidget(pointerPropertyWidget);
 
206
 
 
207
    connect(pointerTypeVisible, SIGNAL(toggled(bool)), pointerType.get(), SLOT(setVisible(bool)));
 
208
    connect(pointerType.get(), SIGNAL(nameChanged(QString)), this, SLOT(updatePointerTypeButtons()));
 
209
 
 
210
    _pointerTypeWidgets.insert(typeIdentifier, pointerPropertyWidget);
 
211
    _pointerTypeButtons.insert(typeIdentifier, pointerTypeButton);
 
212
 
 
213
    return true;
 
214
}
 
215
 
 
216
void DocumentTypesWidget::updateDataTypeButtons()
 
217
{
 
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());
 
224
        ++dataTypeWidget;
 
225
    }
 
226
}
 
227
 
 
228
void DocumentTypesWidget::updatePointerTypeButtons()
 
229
{
 
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());
 
235
        ++pointerTypeWidget;
 
236
    }
 
237
}