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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
|
/**********************************************************************
** Copyright (C) 2003 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 <tqapplication.h>
#include <tqcstring.h>
#include <tqdatastream.h>
#include <tqdragobject.h>
#include <tqlineedit.h>
#include <tqobjectlist.h>
#include <tqpainter.h>
#include <tqpopupmenu.h>
#include <tqrect.h>
#include <tqsize.h>
#include <tqstyle.h>
#include <tqtimer.h>
#include "actiondnd.h"
#include "actioneditorimpl.h"
#include "command.h"
#include "formfile.h"
#include "formwindow.h"
#include "mainwindow.h"
#include "metadatabase.h"
#include "pixmapchooser.h"
#include "popupmenueditor.h"
#include "menubareditor.h"
#include <klocale.h>
// Drag Object Declaration -------------------------------------------
class PopupMenuEditorItemPtrDrag : public TQStoredDrag
{
public:
PopupMenuEditorItemPtrDrag( PopupMenuEditorItem * item, TQWidget * tqparent = 0,
const char * name = 0 );
~PopupMenuEditorItemPtrDrag() {};
static bool canDecode( TQDragMoveEvent * e );
static bool decode( TQDropEvent * e, PopupMenuEditorItem ** i );
};
// Drag Object Implementation ---------------------------------------
PopupMenuEditorItemPtrDrag::PopupMenuEditorItemPtrDrag( PopupMenuEditorItem * item,
TQWidget * tqparent, const char * name )
: TQStoredDrag( "qt/popupmenueditoritemptr", tqparent, name )
{
TQByteArray data( sizeof( TQ_LONG ) );
TQDataStream stream( data, IO_WriteOnly );
stream << ( TQ_LONG ) item;
setEncodedData( data );
}
bool PopupMenuEditorItemPtrDrag::canDecode( TQDragMoveEvent * e )
{
return e->provides( "qt/popupmenueditoritemptr" );
}
bool PopupMenuEditorItemPtrDrag::decode( TQDropEvent * e, PopupMenuEditorItem ** i )
{
TQByteArray data = e->tqencodedData( "qt/popupmenueditoritemptr" );
TQDataStream stream( data, IO_ReadOnly );
if ( !data.size() )
return FALSE;
TQ_LONG p = 0;
stream >> p;
*i = ( PopupMenuEditorItem *) p;
return TRUE;
}
// PopupMenuEditorItem Implementation -----------------------------------
PopupMenuEditorItem::PopupMenuEditorItem( PopupMenuEditor * menu, TQObject * tqparent, const char * name )
: TQObject( tqparent, name ),
a( 0 ),
s( 0 ),
m( menu ),
separator( FALSE ),
removable( FALSE )
{
init();
a = new TQAction( this );
TQObject::connect( a, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( selfDestruct() ) );
}
PopupMenuEditorItem::PopupMenuEditorItem( TQAction * action, PopupMenuEditor * menu,
TQObject * tqparent, const char * name )
: TQObject( tqparent, name ),
a( action ),
s( 0 ),
m( menu ),
separator( FALSE ),
removable( TRUE )
{
init();
if ( /*a->name() == "qt_separator_action" ||*/ ::tqqt_cast<TQSeparatorAction*>(a) )
separator = TRUE;
if ( a && !a->childrenListObject().isEmpty() )
a->installEventFilter( this );
}
PopupMenuEditorItem::PopupMenuEditorItem( PopupMenuEditorItem * item, PopupMenuEditor * menu,
TQObject * tqparent, const char * name )
: TQObject( tqparent, name ),
a( item->a ),
s( 0 ),
m( menu ),
separator( item->separator ),
removable( item->removable )
{
init();
if ( ::tqqt_cast<TQActionGroup*>(a) )
a->installEventFilter( this );
}
PopupMenuEditorItem::~PopupMenuEditorItem()
{
}
void PopupMenuEditorItem::init()
{
if ( a ) {
TQObject::connect( a, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( selfDestruct() ) );
if ( m && !isSeparator() ) {
s = new PopupMenuEditor( m->formWindow(), m );
TQString n = "PopupMenuEditor";
m->formWindow()->unify( TQT_TQOBJECT(s), n, TRUE );
s->setName( n );
MetaDataBase::addEntry( TQT_TQOBJECT(s) );
}
}
}
PopupMenuEditorItem::ItemType PopupMenuEditorItem::type() const
{
if ( separator )
return Separator;
else if ( a )
return Action;
return Unknown;
}
void PopupMenuEditorItem::setVisible( bool enable )
{
if ( a )
a->tqsetVisible( enable );
}
bool PopupMenuEditorItem::isVisible() const
{
TQActionGroup *g = ::tqqt_cast<TQActionGroup*>(a);
if ( g )
return ( g->isVisible() && g->usesDropDown() );
else if ( a )
return a->isVisible();
return FALSE;
}
void PopupMenuEditorItem::showMenu( int x, int y )
{
if ( ( !separator ) && s ) {
s->move( x, y );
s->show();
s->raise();
}
}
void PopupMenuEditorItem::hideMenu()
{
if ( s ) {
s->hideSubMenu();
s->hide();
}
}
void PopupMenuEditorItem::focusOnMenu()
{
if ( s ) {
s->showSubMenu();
s->setFocus();
}
}
int PopupMenuEditorItem::count() const
{
if ( s ) {
return s->count();
} else if ( ::tqqt_cast<TQActionGroup*>(a) ) {
const TQObjectList l = a->childrenListObject();
if ( !l.isEmpty() )
return l.count();
}
return 0;
}
bool PopupMenuEditorItem::eventFilter( TQObject * o, TQEvent * event )
{
if ( ! ::tqqt_cast<TQActionGroup*>( o ) )
return FALSE;
if ( event->type() == TQEvent::ChildInserted ) {
TQChildEvent * ce = ( TQChildEvent * ) event;
TQObject * c = TQT_TQOBJECT(ce->child());
TQAction * action = ::tqqt_cast<TQAction*>( c );
if ( s->tqfind( action ) != -1 ) // avoid duplicates
return FALSE;
TQActionGroup * actionGroup = ::tqqt_cast<TQActionGroup*>( c );
if ( actionGroup )
s->insert( actionGroup );
else if ( action )
s->insert( action );
}
return FALSE;
}
void PopupMenuEditorItem::selfDestruct()
{
hideMenu();
int i = m->tqfind( s );
if ( i != -1 && i < m->count() )
m->remove( i ); // remove this item
a = 0; // the selfDestruct call was caused by the deletion of the action
delete this;
}
// PopupMenuEditor Implementation -----------------------------------
PopupMenuEditorItem * PopupMenuEditor::draggedItem = 0;
int PopupMenuEditor::clipboardOperation = 0;
PopupMenuEditorItem * PopupMenuEditor::clipboardItem = 0;
PopupMenuEditor::PopupMenuEditor( FormWindow * fw, TQWidget * tqparent, const char * name )
: TQWidget( 0, name, WStyle_Customize | WStyle_NoBorder | WRepaintNoErase | WResizeNoErase ),
formWnd( fw ),
tqparentMenu( tqparent ),
iconWidth( 0 ),
textWidth( 0 ),
accelWidth( 0 ),
arrowWidth( 30 ),
borderSize( 2 ),
currentField( 1 ),
currentIndex( 0 )
{
init();
}
PopupMenuEditor::PopupMenuEditor( FormWindow * fw, PopupMenuEditor * menu,
TQWidget * tqparent, const char * name )
: TQWidget( 0, name, WStyle_Customize | WStyle_NoBorder | WRepaintNoErase ),
formWnd( fw ),
tqparentMenu( tqparent ),
iconWidth( menu->iconWidth ),
textWidth( menu->textWidth ),
accelWidth( menu->accelWidth ),
arrowWidth( menu->arrowWidth ),
borderSize( menu->borderSize ),
currentField( menu->currentField ),
currentIndex( menu->currentIndex )
{
init();
PopupMenuEditorItem * i;
for ( i = menu->itemList.first(); i; i = menu->itemList.next() ) {
PopupMenuEditorItem * n = new PopupMenuEditorItem( i, this );
itemList.append( n );
}
}
PopupMenuEditor::~PopupMenuEditor()
{
itemList.setAutoDelete( TRUE );
}
void PopupMenuEditor::init()
{
reparent( ( TQMainWindow * ) formWnd->mainContainer(), pos() );
addItem.action()->setMenuText( i18n("new item") );
addSeparator.action()->setMenuText( i18n("new separator") );
setAcceptDrops( TRUE );
setFocusPolicy( TQ_StrongFocus );
lineEdit = new TQLineEdit( this );
lineEdit->hide();
lineEdit->setFrameStyle(TQFrame::Plain | TQFrame::NoFrame);
lineEdit->polish();
lineEdit->setBackgroundOrigin(ParentOrigin);
lineEdit->setBackgroundMode(PaletteButton);
lineEdit->installEventFilter( this );
dropLine = new TQWidget( this, 0, TQt::WStyle_NoBorder | WStyle_StaysOnTop );
dropLine->setBackgroundColor( TQt::red );
dropLine->hide();
hide();
}
void PopupMenuEditor::insert( PopupMenuEditorItem * item, int index )
{
if ( !item )
return;
if ( index == -1 ) {
itemList.append( item );
if ( isVisible() )
currentIndex = itemList.count() - 1;
} else {
itemList.insert( index, item );
if ( isVisible() )
currentIndex = index;
}
item->m = this;
item->s->tqparentMenu = this;
resizeToContents();
if ( isVisible() && tqparentMenu )
tqparentMenu->update(); // draw arrow in tqparent menu
emit inserted( item->action() );
}
void PopupMenuEditor::insert( TQAction * action, int index )
{
if ( !action )
return;
insert( new PopupMenuEditorItem( action, this, 0, action->name() ), index );
}
void PopupMenuEditor::insert( TQActionGroup * actionGroup, int index )
{
if ( !actionGroup )
return;
bool dropdown = actionGroup->usesDropDown();
PopupMenuEditorItem *i = new PopupMenuEditorItem( (TQAction *)actionGroup, this, 0,
TQString( actionGroup->name() ) + "Menu" );
TQActionGroup *g = 0;
TQObjectList *l = actionGroup->queryList( TQACTION_OBJECT_NAME_STRING, 0, FALSE, FALSE );
TQObjectListIterator it( *l );
insert( i, index );
for ( ; it.current(); ++it ) {
g = ::tqqt_cast<TQActionGroup*>(it.current());
if ( g ) {
if ( dropdown )
i->s->insert( g );
else
insert( g );
} else {
i->s->insert( (TQAction*)it.current() );
}
}
delete l;
}
int PopupMenuEditor::tqfind( const TQAction * action )
{
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
if ( i->action() == action )
return itemList.at();
i = itemList.next();
}
return -1;
}
int PopupMenuEditor::tqfind( PopupMenuEditor * menu )
{
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
if ( i->subMenu() == menu )
return itemList.at();
i = itemList.next();
}
return -1;
}
int PopupMenuEditor::count()
{
return itemList.count();
}
PopupMenuEditorItem * PopupMenuEditor::at( int index )
{
return itemList.at( index );
}
void PopupMenuEditor::exchange( int a, int b )
{
PopupMenuEditorItem * ia = itemList.at( a );
PopupMenuEditorItem * ib = itemList.at( b );
if ( !ia || !ib ||
ia == &addItem || ia == &addSeparator ||
ib == &addItem || ib == &addSeparator )
return; // do nothing
itemList.tqreplace( b, ia );
itemList.tqreplace( a, ib );
}
void PopupMenuEditor::cut( int index )
{
int idx = ( index == -1 ? currentIndex : index );
if ( clipboardItem && clipboardOperation == Cut )
delete clipboardItem;
clipboardOperation = Cut;
clipboardItem = itemList.at( idx );
if ( clipboardItem == &addItem || clipboardItem == &addSeparator ) {
clipboardOperation = None;
clipboardItem = 0;
return; // do nothing
}
RemoveActionFromPopupCommand * cmd =
new RemoveActionFromPopupCommand( i18n( "Cut Item" ), formWnd, this, idx );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
}
void PopupMenuEditor::copy( int index )
{
int idx = ( index == -1 ? currentIndex : index );
if ( clipboardItem && clipboardOperation == Cut )
delete clipboardItem;
clipboardOperation = Copy;
clipboardItem = itemList.at( idx );
if ( clipboardItem == &addItem || clipboardItem == &addSeparator ) {
clipboardOperation = None;
clipboardItem = 0;
}
}
void PopupMenuEditor::paste( int index )
{
int idx = ( index == -1 ? currentIndex : index );
if ( clipboardItem && clipboardOperation ) {
PopupMenuEditorItem * n = new PopupMenuEditorItem( clipboardItem, this );
AddActionToPopupCommand * cmd =
new AddActionToPopupCommand( i18n( "Paste Item" ), formWnd, this, n, idx );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
}
}
void PopupMenuEditor::insertedActions( TQPtrList<TQAction> & list )
{
TQAction * a = 0;
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
a = i->action();
if ( a )
list.append( a );
i = itemList.next();
}
}
void PopupMenuEditor::show()
{
resizeToContents();
TQWidget::show();
}
void PopupMenuEditor::choosePixmap( int index )
{
int idx = ( index == -1 ? currentIndex : index );
PopupMenuEditorItem * i = 0;
TQAction * a = 0;
if ( idx < (int)itemList.count() ) {
i = itemList.at( idx );
a = i->action();
} else {
createItem();
}
hide(); // qChoosePixmap hides the menu
TQIconSet icons( qChoosePixmap( 0, formWnd, 0, 0 ) );
SetActionIconsCommand * cmd =
new SetActionIconsCommand( i18n( "Set Icon" ), formWnd, a, this, icons );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
show();
setFocus();
}
void PopupMenuEditor::showLineEdit( int index )
{
int idx = ( index == -1 ? currentIndex : index );
PopupMenuEditorItem * i = 0;
if ( idx >= (int)itemList.count() )
i = &addItem;
else
i = itemList.at( idx );
// open edit currentField for item name
lineEdit->setText( i->action()->menuText() );
lineEdit->selectAll();
lineEdit->setGeometry( borderSize + iconWidth, borderSize + itemPos( i ),
textWidth, itemHeight( i ) );
lineEdit->show();
lineEdit->setFocus();
}
void PopupMenuEditor::setAccelerator( int key, TQt::ButtonState state, int index )
{
// FIXME: make this a command
int idx = ( index == -1 ? currentIndex : index );
if ( key == TQt::Key_Shift ||
key == TQt::Key_Control ||
key == TQt::Key_Alt ||
key == TQt::Key_Meta ||
key == TQt::Key_unknown )
return; // ignore these keys when they are pressed
PopupMenuEditorItem * i = 0;
if ( idx >= (int)itemList.count() )
i = createItem();
else
i = itemList.at( idx );
int shift = ( state & TQt::ShiftButton ? TQt::SHIFT : 0 );
int ctrl = ( state & TQt::ControlButton ? TQt::CTRL : 0 );
int alt = ( state & TQt::AltButton ? TQt::ALT : 0 );
int meta = ( state & TQt::MetaButton ? TQt::META : 0 );
TQAction * a = i->action();
TQKeySequence ks = a->accel();
int keys[4] = { ks[0], ks[1], ks[2], ks[3] };
int n = 0;
while ( n < 4 && ks[n++] );
n--;
if ( n < 4 )
keys[n] = key | shift | ctrl | alt | meta;
a->setAccel( TQKeySequence( keys[0], keys[1], keys[2], keys[3] ) );
MetaDataBase::setPropertyChanged( a, "accel", TRUE );
resizeToContents();
}
void PopupMenuEditor::resizeToContents()
{
TQSize s = contentsSize();
dropLine->resize( s.width(), 2 );
s.rwidth() += borderSize * 2;
s.rheight() += borderSize * 2;
resize( s );
}
void PopupMenuEditor::showSubMenu()
{
if ( currentIndex < (int)itemList.count() ) {
itemList.at( currentIndex )->showMenu( pos().x() + width() - borderSize * 3,
pos().y() + itemPos( at( currentIndex ) ) +
borderSize * 2 );
setFocus(); // Keep focus in this widget
}
}
void PopupMenuEditor::hideSubMenu()
{
if ( currentIndex < (int)itemList.count() )
itemList.at( currentIndex )->hideMenu();
}
void PopupMenuEditor::focusOnSubMenu()
{
if ( currentIndex < (int)itemList.count() )
itemList.at( currentIndex )->focusOnMenu();
}
// This function has no undo. It is only here to remove an item when its action was
// removed from the action editor.
// Use removeItem to put the command on the command stack.
void PopupMenuEditor::remove( int index )
{
int idx = ( index == -1 ? currentIndex : index );
PopupMenuEditorItem * i = itemList.at( idx );
if ( i && i->isRemovable() ) {
itemList.remove( idx );
int n = itemList.count() + 1;
if ( currentIndex >= n )
currentIndex = itemList.count() + 1;
emit removed( i->action() );
resizeToContents();
}
}
PopupMenuEditorItem * PopupMenuEditor::createItem( TQAction * a )
{
ActionEditor * ae = (ActionEditor *) formWindow()->mainWindow()->child( 0, "ActionEditor" );
if ( !a )
a = ae->newActionEx();
PopupMenuEditorItem * i = new PopupMenuEditorItem( a, this );
TQString n = TQString( a->name() ) + "Item";
formWindow()->unify( i, n, FALSE );
i->setName( n );
AddActionToPopupCommand * cmd =
new AddActionToPopupCommand( i18n( "Add Item" ), formWnd, this, i );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
return i;
}
void PopupMenuEditor::removeItem( int index )
{
int idx = ( index == -1 ? currentIndex : index );
if ( idx < (int)itemList.count() ) {
RemoveActionFromPopupCommand * cmd = new RemoveActionFromPopupCommand( i18n( "Remove Item" ),
formWnd,
this,
idx );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
if ( itemList.count() == 0 && tqparentMenu )
tqparentMenu->update();
resizeToContents();
}
}
PopupMenuEditorItem * PopupMenuEditor::currentItem()
{
int count = itemList.count();
if ( currentIndex < count )
return itemList.at( currentIndex );
else if ( currentIndex == count )
return &addItem;
return &addSeparator;
}
PopupMenuEditorItem * PopupMenuEditor::itemAt( int y )
{
PopupMenuEditorItem * i = itemList.first();
int iy = 0;
while ( i ) {
iy += itemHeight( i );
if ( iy > y )
return i;
i = itemList.next();
}
iy += itemHeight( &addItem );
if ( iy > y )
return &addItem;
return &addSeparator;
}
void PopupMenuEditor::setFocusAt( const TQPoint & pos )
{
hideSubMenu();
lineEdit->hide();
currentIndex = 0;
int iy = 0;
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
iy += itemHeight( i );
if ( iy > pos.y() )
break;
i = itemList.next();
currentIndex++;
}
iy += itemHeight( &addItem );
if ( iy <= pos.y() )
currentIndex++;
if ( currentIndex < (int)itemList.count() ) {
if ( pos.x() < iconWidth )
currentField = 0;
else if ( pos.x() < iconWidth + textWidth )
currentField = 1;
else
currentField = 2;
} else {
currentField = 1;
}
showSubMenu();
}
bool PopupMenuEditor::eventFilter( TQObject * o, TQEvent * e )
{
if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(lineEdit) && e->type() == TQEvent::FocusOut ) {
leaveEditMode( 0 );
update();
}
return TQWidget::eventFilter( o, e );
}
void PopupMenuEditor::paintEvent( TQPaintEvent * )
{
TQPainter p( this );
p.save();
TQRegion reg( rect() );
TQRegion mid( borderSize, borderSize,
rect().width() - borderSize * 2, rect().height() - borderSize * 2 );
reg -= mid;
p.setClipRegion( reg );
tqstyle().tqdrawPrimitive( TQStyle::PE_PanelPopup, &p, rect(), tqcolorGroup() );
p.restore();
drawItems( &p );
}
void PopupMenuEditor::mousePressEvent( TQMouseEvent * e )
{
mousePressPos = e->pos();
setFocusAt( mousePressPos );
e->accept();
update();
}
void PopupMenuEditor::mouseDoubleClickEvent( TQMouseEvent * )
{
setFocusAt( mousePressPos );
if ( currentItem() == &addSeparator ) {
PopupMenuEditorItem * i = createItem( new TQSeparatorAction( 0 ) );
i->setSeparator( TRUE );
return;
}
if ( currentField == 0 ) {
choosePixmap();
resizeToContents();
} else if ( currentField == 1 ) {
showLineEdit();
}
}
void PopupMenuEditor::mouseMoveEvent( TQMouseEvent * e )
{
if ( e->state() & Qt::LeftButton ) {
if ( ( e->pos() - mousePressPos ).manhattanLength() > 3 ) {
draggedItem = itemAt( mousePressPos.y() );
if ( draggedItem == &addItem ) {
draggedItem = createItem();
RenameActionCommand cmd( i18n( "Rename Item" ), formWnd, draggedItem->action(),
this, "Unnamed" );
cmd.execute();
// FIXME: start rename after drop
} else if ( draggedItem == &addSeparator ) {
draggedItem = createItem( new TQSeparatorAction( 0 ) );
draggedItem->setSeparator( TRUE );
}
PopupMenuEditorItemPtrDrag * d =
new PopupMenuEditorItemPtrDrag( draggedItem, this );
hideSubMenu();
draggedItem->setVisible( FALSE );
resizeToContents();
// If the item is dropped in the same list,
// we will have two instances of the same pointer
// in the list. We use node instead.
int idx = itemList.tqfind( draggedItem );
TQLNode * node = itemList.currentNode();
d->dragCopy(); // dragevents and stuff happens
if ( draggedItem ) { // item was not dropped
draggedItem->setVisible( TRUE );
draggedItem = 0;
if ( hasFocus() ) {
hideSubMenu();
resizeToContents();
showSubMenu();
}
} else { // item was dropped
itemList.takeNode( node )->setVisible( TRUE );
if ( currentIndex > 0 && currentIndex > idx )
--currentIndex;
// the drop might happen in another menu, so we'll resize
// and show the submenu there
}
}
}
}
void PopupMenuEditor::dragEnterEvent( TQDragEnterEvent * e )
{
if ( e->provides( "qt/popupmenueditoritemptr" ) ||
e->provides( "application/x-designer-actions" ) ||
e->provides( "application/x-designer-actiongroup" ) ) {
e->accept();
dropLine->show();
}
}
void PopupMenuEditor::dragLeaveEvent( TQDragLeaveEvent * )
{
dropLine->hide();
}
void PopupMenuEditor::dragMoveEvent( TQDragMoveEvent * e )
{
TQPoint pos = e->pos();
dropLine->move( borderSize, snapToItem( pos.y() ) );
if ( currentItem() != itemAt( pos.y() ) ) {
hideSubMenu();
setFocusAt( pos );
showSubMenu();
}
}
void PopupMenuEditor::dropEvent( TQDropEvent * e )
{
if ( !( e->provides( "qt/popupmenueditoritemptr" ) ||
e->provides( "application/x-designer-actions" ) ||
e->provides( "application/x-designer-actiongroup" ) ) )
return;
// Hide the sub menu of the current item, but do it later
if ( currentIndex < (int)itemList.count() ) {
PopupMenuEditor *s = itemList.at( currentIndex )->s;
TQTimer::singleShot( 0, s, TQT_SLOT( hide() ) );
}
draggedItem = 0;
PopupMenuEditorItem * i = 0;
if ( e->provides( "qt/popupmenueditoritemptr" ) ) {
PopupMenuEditorItemPtrDrag::decode( e, &i );
} else {
if ( e->provides( "application/x-designer-actiongroup" ) ) {
TQActionGroup * g = ::tqqt_cast<TQDesignerActionGroup*>(ActionDrag::action());
if ( g->usesDropDown() ) {
i = new PopupMenuEditorItem( g, this );
TQString n = TQString( g->name() ) + "Item";
formWindow()->unify( i, n, FALSE );
i->setName( n );
TQObjectList *l = g->queryList( TQACTION_OBJECT_NAME_STRING, 0, FALSE, FALSE );
TQObjectListIterator it( *l );
for ( ; it.current(); ++it ) {
g = ::tqqt_cast<TQActionGroup*>(it.current());
if ( g )
i->s->insert( g );
else
i->s->insert( (TQAction*)it.current() );
}
delete l;
} else {
dropInPlace( g, e->pos().y() );
}
} else if ( e->provides( "application/x-designer-actions" ) ) {
TQAction *a = ::tqqt_cast<TQDesignerAction*>(ActionDrag::action());
i = new PopupMenuEditorItem( a, this );
}
}
if ( i ) {
dropInPlace( i, e->pos().y() );
TQTimer::singleShot( 0, this, TQT_SLOT( resizeToContents() ) );
}
TQTimer::singleShot( 0, this, TQT_SLOT( showSubMenu() ) );
TQTimer::singleShot( 0, this, TQT_SLOT( setFocus() ) );
dropLine->hide();
e->accept();
}
void PopupMenuEditor::keyPressEvent( TQKeyEvent * e )
{
if ( lineEdit->isHidden() ) { // In navigation mode
switch ( e->key() ) {
case TQt::Key_Delete:
hideSubMenu();
removeItem();
showSubMenu();
break;
case TQt::Key_Backspace:
clearCurrentField();
break;
case TQt::Key_Up:
navigateUp( e->state() & TQt::ControlButton );
break;
case TQt::Key_Down:
navigateDown( e->state() & TQt::ControlButton );
break;
case TQt::Key_Left:
navigateLeft();
break;
case TQt::Key_Right:
navigateRight();
break;
case TQt::Key_PageUp:
currentIndex = 0;
break;
case TQt::Key_PageDown:
currentIndex = itemList.count();
break;
case TQt::Key_Enter:
case TQt::Key_Return:
case TQt::Key_F2:
enterEditMode( e );
// move on
case TQt::Key_Alt:
case TQt::Key_Shift:
case TQt::Key_Control:
// do nothing
return;
case TQt::Key_Escape:
currentField = 0;
navigateLeft();
break;
case TQt::Key_C:
if ( e->state() & TQt::ControlButton &&
currentIndex < (int)itemList.count() ) {
copy( currentIndex );
break;
}
case TQt::Key_X:
if ( e->state() & TQt::ControlButton &&
currentIndex < (int)itemList.count() ) {
hideSubMenu();
cut( currentIndex );
showSubMenu();
break;
}
case TQt::Key_V:
if ( e->state() & TQt::ControlButton ) {
hideSubMenu();
paste( currentIndex < (int)itemList.count() ? currentIndex + 1: itemList.count() );
showSubMenu();
break;
}
default:
if ( currentItem()->isSeparator() )
return;
if ( currentField == 1 ) {
showLineEdit();
TQApplication::sendEvent( lineEdit, e );
e->accept();
return;
} else if ( currentField == 2 ) {
setAccelerator( e->key(), e->state() );
showSubMenu();
}
break;
}
} else { // In edit mode
switch ( e->key() ) {
case TQt::Key_Enter:
case TQt::Key_Return:
case TQt::Key_Escape:
leaveEditMode( e );
e->accept();
return;
}
}
update();
}
void PopupMenuEditor::focusInEvent( TQFocusEvent * )
{
showSubMenu();
update();
tqparentMenu->update();
}
void PopupMenuEditor::focusOutEvent( TQFocusEvent * )
{
TQWidget * fw = tqApp->tqfocusWidget();
if ( !fw || ( !::tqqt_cast<PopupMenuEditor*>(fw) && fw != lineEdit ) ) {
hideSubMenu();
if ( fw && ::tqqt_cast<MenuBarEditor*>(fw) )
return;
TQWidget * w = this;
while ( w && w != fw && ::tqqt_cast<PopupMenuEditor*>(w) ) { // hide all popups
w->hide();
w = ((PopupMenuEditor *)w)->tqparentEditor();
}
}
}
void PopupMenuEditor::drawItem( TQPainter * p, PopupMenuEditorItem * i,
const TQRect & r, int f ) const
{
int x = r.x();
int y = r.y();
int h = r.height();
p->fillRect( r, tqcolorGroup().brush( TQColorGroup::Background ) );
if ( i->isSeparator() ) {
tqstyle().tqdrawPrimitive( TQStyle::PE_Separator, p,
TQRect( r.x(), r.y() + 2, r.width(), 1 ),
tqcolorGroup(), TQStyle::Style_Sunken | f );
return;
}
const TQAction * a = i->action();
if ( a->isToggleAction() && a->isOn() ) {
tqstyle().tqdrawPrimitive( TQStyle::PE_CheckMark, p,
TQRect( x , y, iconWidth, h ),
tqcolorGroup(), f );
} else {
TQPixmap icon = a->iconSet().pixmap( TQIconSet::Automatic, TQIconSet::Normal );
p->drawPixmap( x + ( iconWidth - icon.width() ) / 2,
y + ( h - icon.height() ) / 2,
icon );
}
x += iconWidth;
p->drawText( x, y, textWidth, h,
TQPainter::AlignLeft |
TQPainter::AlignVCenter |
TQt::ShowPrefix |
TQt::SingleLine,
a->menuText() );
x += textWidth + borderSize * 3;
p->drawText( x, y, accelWidth, h,
TQPainter::AlignLeft | TQPainter::AlignVCenter,
a->accel() );
if ( i->count() ) // Item has submenu
tqstyle().tqdrawPrimitive( TQStyle::PE_ArrowRight, p,
TQRect( r.width() - arrowWidth, r.y(), arrowWidth, r.height() ),
tqcolorGroup(), f );
}
void PopupMenuEditor::drawWinFocusRect( TQPainter * p, const TQRect & r ) const
{
if ( currentIndex < (int)itemList.count() &&
((PopupMenuEditor*)this)->itemList.at( currentIndex )->isSeparator() ) {
p->drawWinFocusRect( borderSize, r.y(), width() - borderSize * 2, r.height() );
return;
}
int y = r.y();
int h = r.height();
if ( currentField == 0 )
p->drawWinFocusRect( borderSize + 1, y, iconWidth - 2, h );
else if ( currentField == 1 )
p->drawWinFocusRect( borderSize + iconWidth, y, textWidth, h );
else if ( currentField == 2 )
p->drawWinFocusRect( borderSize + iconWidth + textWidth +
borderSize * 3, y, accelWidth, h );
}
void PopupMenuEditor::drawItems( TQPainter * p )
{
int flags = 0;
int idx = 0;
TQColorGroup enabled = tqcolorGroup();
TQColorGroup disabled = tqpalette().disabled();
TQRect focus;
TQRect rect( borderSize, borderSize, width() - borderSize * 2, 0 );
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
if ( i->isVisible() ) {
rect.setHeight( itemHeight( i ) );
if ( idx == currentIndex )
focus = rect;
if ( i->action()->isEnabled() ) {
flags = TQStyle::Style_Enabled;
p->setPen( enabled.buttonText() );
} else {
flags = TQStyle::Style_Default;
p->setPen( disabled.buttonText() );
}
drawItem( p, i, rect, flags );
rect.moveBy( 0, rect.height() );
}
i = itemList.next();
idx++;
}
// Draw the "add item" and "add separator" items
p->setPen( darkBlue );
rect.setHeight( itemHeight( &addItem ) );
if ( idx == currentIndex )
focus = rect;
drawItem( p, &addItem, rect, TQStyle::Style_Default );
rect.moveBy( 0, rect.height() );
idx++;
rect.setHeight( itemHeight( &addSeparator ) );
if ( idx == currentIndex )
focus = rect;
drawItem( p, &addSeparator, rect, TQStyle::Style_Default );
idx++;
if ( hasFocus() && !draggedItem )
drawWinFocusRect( p, focus );
}
TQSize PopupMenuEditor::contentsSize()
{
TQRect textRect = fontMetrics().boundingRect( addSeparator.action()->menuText() );
textWidth = textRect.width();
accelWidth = textRect.height(); // default size
iconWidth = textRect.height();
int w = 0;
int h = itemHeight( &addItem ) + itemHeight( &addSeparator );
PopupMenuEditorItem * i = itemList.first();
TQAction * a = 0;
while ( i ) {
if ( i->isVisible() ) {
if ( !i->isSeparator() ) {
a = i->action();
w = a->iconSet().pixmap( TQIconSet::Automatic, TQIconSet::Normal ).rect().width() +
borderSize; // padding
iconWidth = TQMAX( iconWidth, w );
w = fontMetrics().boundingRect( a->menuText() ).width();
textWidth = TQMAX( textWidth, w );
w = fontMetrics().boundingRect( a->accel() ).width() + 2; // added padding?
accelWidth = TQMAX( accelWidth, w );
}
h += itemHeight( i );
}
i = itemList.next();
}
int width = iconWidth + textWidth + borderSize * 3 + accelWidth + arrowWidth;
return TQSize( width, h );
}
int PopupMenuEditor::itemHeight( const PopupMenuEditorItem * item ) const
{
if ( !item || ( item && !item->isVisible() ) )
return 0;
if ( item->isSeparator() )
return 4; // FIXME: hardcoded ( get from styles )r
int padding = + borderSize * 6;
TQAction * a = item->action();
int h = a->iconSet().pixmap( TQIconSet::Automatic, TQIconSet::Normal ).rect().height();
h = TQMAX( h, fontMetrics().boundingRect( a->menuText() ).height() + padding );
h = TQMAX( h, fontMetrics().boundingRect( a->accel() ).height() + padding );
return h;
}
int PopupMenuEditor::itemPos( const PopupMenuEditorItem * item ) const
{
PopupMenuEditor * that = ( PopupMenuEditor * ) this;
int y = 0;
PopupMenuEditorItem * i = that->itemList.first();
while ( i ) {
if ( i == item )
return y;
y += itemHeight( i );
i = that->itemList.next();
}
return y;
}
int PopupMenuEditor::snapToItem( int y )
{
int iy = 0;
int dy = 0;
PopupMenuEditorItem * i = itemList.first();
while ( i ) {
dy = itemHeight( i );
if ( iy + dy / 2 > y )
return iy;
iy += dy;
i = itemList.next();
}
return iy;
}
void PopupMenuEditor::dropInPlace( PopupMenuEditorItem * i, int y )
{
int iy = 0;
int dy = 0;
int idx = 0;
PopupMenuEditorItem * n = itemList.first();
while ( n ) {
dy = itemHeight( n );
if ( iy + dy / 2 > y )
break;
iy += dy;
idx++;
n = itemList.next();
}
int same = itemList.tqfindRef( i );
AddActionToPopupCommand * cmd = new AddActionToPopupCommand( i18n( "Drop Item" ), formWnd, this, i, idx );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
currentIndex = ( same >= 0 && same < idx ) ? idx - 1 : idx;
currentField = 1;
}
void PopupMenuEditor::dropInPlace( TQActionGroup * g, int y )
{
TQObjectList l = g->childrenListObject();
if (l.isEmpty())
return;
for ( int i = 0; i < (int)l.count(); ++i ) {
TQAction *a = ::tqqt_cast<TQAction*>(l.at(i));
TQActionGroup *g = ::tqqt_cast<TQActionGroup*>(l.at(i));
if ( g )
dropInPlace( g, y );
else if ( a )
dropInPlace( new PopupMenuEditorItem( a, this ), y );
}
}
void PopupMenuEditor::safeDec()
{
do {
currentIndex--;
} while ( currentIndex > 0 && !currentItem()->isVisible() );
if ( currentIndex == 0 &&
!currentItem()->isVisible() &&
tqparentMenu ) {
tqparentMenu->setFocus();
}
}
void PopupMenuEditor::safeInc()
{
int max = itemList.count() + 1;
if ( currentIndex < max ) {
do {
currentIndex++;
} while ( currentIndex < max && !currentItem()->isVisible() ); // skip invisible items
}
}
void PopupMenuEditor::clearCurrentField()
{
if ( currentIndex >= (int)itemList.count() )
return; // currentIndex is addItem or addSeparator
PopupMenuEditorItem * i = currentItem();
hideSubMenu();
if ( i->isSeparator() )
return;
if ( currentField == 0 ) {
TQIconSet icons( 0 );
SetActionIconsCommand * cmd = new SetActionIconsCommand( i18n( "Remove Icon" ),
formWnd,
i->action(),
this,
icons );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
} else if ( currentField == 2 ) {
i->action()->setAccel( 0 );
}
resizeToContents();
showSubMenu();
return;
}
void PopupMenuEditor::navigateUp( bool ctrl )
{
if ( currentIndex > 0 ) {
hideSubMenu();
if ( ctrl ) {
ExchangeActionInPopupCommand * cmd =
new ExchangeActionInPopupCommand( i18n( "Move Item Up" ),
formWnd,
this,
currentIndex,
currentIndex - 1 );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
safeDec();
} else {
safeDec();
}
showSubMenu();
} else if ( tqparentMenu ) {
tqparentMenu->setFocus();
tqparentMenu->update();
}
}
void PopupMenuEditor::navigateDown( bool ctrl )
{
hideSubMenu();
if ( ctrl ) {
if ( currentIndex < ( (int)itemList.count() - 1 ) ) { // safe index
ExchangeActionInPopupCommand * cmd =
new ExchangeActionInPopupCommand( i18n( "Move Item Down" ),
formWnd,
this,
currentIndex,
currentIndex + 1 );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
safeInc();
}
} else { // ! Ctrl
safeInc();
}
if ( currentIndex >= (int)itemList.count() )
currentField = 1;
showSubMenu();
}
void PopupMenuEditor::navigateLeft()
{
if ( currentItem()->isSeparator() ||
currentIndex >= (int)itemList.count() ||
currentField == 0 ) {
if ( tqparentMenu ) {
hideSubMenu();
tqparentMenu->setFocus();
} else if ( !currentItem()->isSeparator() ) {
currentField = 2;
}
} else {
currentField--;
}
}
void PopupMenuEditor::navigateRight()
{
if ( !currentItem()->isSeparator() &&
currentIndex < (int)itemList.count() ) {
if ( currentField == 2 ) {
focusOnSubMenu();
} else {
currentField++;
currentField %= 3;
}
}
}
void PopupMenuEditor::enterEditMode( TQKeyEvent * e )
{
PopupMenuEditorItem * i = currentItem();
if ( i == &addSeparator ) {
i = createItem( new TQSeparatorAction( 0 ) );
} else if ( i->isSeparator() ) {
return;
} else if ( currentField == 0 ) {
choosePixmap();
} else if ( currentField == 1 ) {
showLineEdit();
return;
} else {// currentField == 2
setAccelerator( e->key(), e->state() );
}
showSubMenu();
return;
}
void PopupMenuEditor::leaveEditMode( TQKeyEvent * e )
{
setFocus();
lineEdit->hide();
PopupMenuEditorItem * i = 0;
if ( e && e->key() == TQt::Key_Escape ) {
update();
return;
}
if ( currentIndex >= (int)itemList.count() ) {
// new item was created
TQAction * a = formWnd->mainWindow()->actioneditor()->newActionEx();
TQString actionText = lineEdit->text();
actionText.tqreplace("&&", "&");
TQString menuText = lineEdit->text();
a->setText( actionText );
a->setMenuText( menuText );
i = createItem( a );
TQString n = constructName( i );
formWindow()->unify( a, n, TRUE );
a->setName( n );
MetaDataBase::addEntry( a );
MetaDataBase::setPropertyChanged( a, "menuText", TRUE );
ActionEditor *ae = (ActionEditor*)formWindow()->mainWindow()->child( 0, "ActionEditor" );
if ( ae )
ae->updateActionName( a );
} else {
i = itemList.at( currentIndex );
RenameActionCommand * cmd = new RenameActionCommand( i18n( "Rename Item" ),
formWnd,
i->action(),
this,
lineEdit->text() );
formWnd->commandHistory()->addCommand( cmd );
cmd->execute();
}
resizeToContents();
if ( !i )
return;
if ( i->isSeparator() )
hideSubMenu();
else
showSubMenu();
}
TQString PopupMenuEditor::constructName( PopupMenuEditorItem *item )
{
TQString s;
TQString name = item->action()->menuText();
TQWidget *e = tqparentEditor();
PopupMenuEditor *p = ::tqqt_cast<PopupMenuEditor*>(e);
if ( p ) {
int idx = p->tqfind( item->m );
PopupMenuEditorItem * i = ( idx > -1 ? p->at( idx ) : 0 );
s = ( i ? TQString( i->action()->name() ).remove( "Action" ) : TQString( "" ) );
} else {
MenuBarEditor *b = ::tqqt_cast<MenuBarEditor*>(e);
if ( b ) {
int idx = b->findItem( item->m );
MenuBarEditorItem * i = ( idx > -1 ? b->item( idx ) : 0 );
s = ( i ? i->menuText().lower() : TQString( "" ) );
}
}
// replace illegal characters
return ( RenameMenuCommand::makeLegal( s ) +
RenameMenuCommand::makeLegal( name ) + "Action" );
}
|