1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of TQt Designer.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid TQt Enterprise Edition or TQt Professional Edition
** licenses may use this file in accordance with the TQt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
** See http://www.trolltech.com/pricing.html or email [email protected] for
** information about TQt Commercial License Agreements.
**
** Contact [email protected] if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "mainwindow.h"
#include "widgetaction.h"
#include "listviewdnd.h"
#include <tqlistview.h>
void ConfigToolboxDialog::init()
{
listViewTools->setSorting( -1 );
listViewCommon->setSorting( -1 );
ListViewDnd *toolsDnd = new ListViewDnd( listViewTools );
toolsDnd->setDragMode( ListViewDnd::External | ListViewDnd::NullDrop | ListViewDnd::Flat );
ListViewDnd *commonDnd = new ListViewDnd( listViewCommon );
commonDnd->setDragMode( ListViewDnd::Both | ListViewDnd::Move | ListViewDnd::Flat );
TQObject::connect( toolsDnd, TQT_SIGNAL( dropped( TQListViewItem * ) ),
commonDnd, TQT_SLOT( confirmDrop( TQListViewItem * ) ) );
TQObject::connect( commonDnd, TQT_SIGNAL( dropped( TQListViewItem * ) ),
commonDnd, TQT_SLOT( confirmDrop( TQListViewItem * ) ) );
TQDict<TQListViewItem> groups;
TQAction *a;
for ( a = MainWindow::self->toolActions.last();
a;
a = MainWindow::self->toolActions.prev() ) {
TQString grp = ( (WidgetAction*)a )->group();
TQListViewItem *parent = groups.find( grp );
if ( !parent ) {
parent = new TQListViewItem( listViewTools );
parent->setText( 0, grp );
parent->setOpen( TRUE );
groups.insert( grp, parent );
}
TQListViewItem *i = new TQListViewItem( parent );
i->setText( 0, a->text() );
i->setPixmap( 0, a->iconSet().pixmap() );
}
for ( a = MainWindow::self->commonWidgetsPage.last(); a;
a = MainWindow::self->commonWidgetsPage.prev() ) {
TQListViewItem *i = new TQListViewItem( listViewCommon );
i->setText( 0, a->text() );
i->setPixmap( 0, a->iconSet().pixmap() );
}
}
void ConfigToolboxDialog::addTool()
{
TQListView *src = listViewTools;
bool addKids = FALSE;
TQListViewItem *nextSibling = 0;
TQListViewItem *nextParent = 0;
TQListViewItemIterator it = src->firstChild();
for ( ; *it; it++ ) {
// Hit the nextSibling, turn of child processing
if ( (*it) == nextSibling )
addKids = FALSE;
if ( (*it)->isSelected() ) {
if ( (*it)->childCount() == 0 ) {
// Selected, no children
TQListViewItem *i = new TQListViewItem( listViewCommon, listViewCommon->lastItem() );
i->setText( 0, (*it)->text(0) );
i->setPixmap( 0, *((*it)->pixmap(0)) );
listViewCommon->setCurrentItem( i );
listViewCommon->ensureItemVisible( i );
} else if ( !addKids ) {
// Children processing not set, so set it
// Also find the item were we shall quit
// processing children...if any such item
addKids = TRUE;
nextSibling = (*it)->nextSibling();
nextParent = (*it)->parent();
while ( nextParent && !nextSibling ) {
nextSibling = nextParent->nextSibling();
nextParent = nextParent->parent();
}
}
} else if ( ((*it)->childCount() == 0) && addKids ) {
// Leaf node, and we _do_ process children
TQListViewItem *i = new TQListViewItem( listViewCommon, listViewCommon->lastItem() );
i->setText( 0, (*it)->text(0) );
i->setPixmap( 0, *((*it)->pixmap(0)) );
listViewCommon->setCurrentItem( i );
listViewCommon->ensureItemVisible( i );
}
}
}
void ConfigToolboxDialog::removeTool()
{
TQListViewItemIterator it = listViewCommon->firstChild();
while ( *it ) {
if ( (*it)->isSelected() )
delete (*it);
else
it++;
}
}
void ConfigToolboxDialog::moveToolUp()
{
TQListViewItem *next = 0;
TQListViewItem *item = listViewCommon->firstChild();
for ( int i = 0; i < listViewCommon->childCount(); ++i ) {
next = item->itemBelow();
if ( item->isSelected() && (i > 0) && !item->itemAbove()->isSelected() )
item->itemAbove()->moveItem( item );
item = next;
}
}
void ConfigToolboxDialog::moveToolDown()
{
int count = listViewCommon->childCount();
TQListViewItem *next = 0;
TQListViewItem *item = listViewCommon->lastItem();
for ( int i = 0; i < count; ++i ) {
next = item->itemAbove();
if ( item->isSelected() && (i > 0) && !item->itemBelow()->isSelected() )
item->moveItem( item->itemBelow() );
item = next;
}
// TQListViewItem *item = listViewCommon->firstChild();
// for ( int i = 0; i < listViewCommon->childCount(); ++i ) {
//if ( item == listViewCommon->currentItem() ) {
// item->moveItem( item->itemBelow() );
// currentCommonToolChanged( item );
// break;
//}
//item = item->itemBelow();
// }
}
void ConfigToolboxDialog::currentToolChanged( TQListViewItem *i )
{
bool canAdd = FALSE;
TQListViewItemIterator it = listViewTools->firstChild();
for ( ; *it; it++ ) {
if ( (*it)->isSelected() ) {
canAdd = TRUE;
break;
}
}
buttonAdd->setEnabled( canAdd || ( i && i->isSelected() ) );
}
void ConfigToolboxDialog::currentCommonToolChanged( TQListViewItem *i )
{
buttonUp->setEnabled( (bool) (i && i->itemAbove()) );
buttonDown->setEnabled( (bool) (i && i->itemBelow()) );
bool canRemove = FALSE;
TQListViewItemIterator it = listViewCommon->firstChild();
for ( ; *it; it++ ) {
if ( (*it)->isSelected() ) {
canRemove = TRUE;
break;
}
}
buttonRemove->setEnabled( canRemove || ( i && i->isSelected() ) );
}
void ConfigToolboxDialog::ok()
{
MainWindow::self->commonWidgetsPage.clear();
TQListViewItem *item = listViewCommon->firstChild();
for ( int j = 0; j < listViewCommon->childCount(); item = item->itemBelow(), ++j ) {
TQAction *a = 0;
for ( a = MainWindow::self->toolActions.last();
a;
a = MainWindow::self->toolActions.prev() ) {
if ( a->text() == item->text( 0 ) )
break;
}
if ( a )
MainWindow::self->commonWidgetsPage.insert( j, a );
}
}
|