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
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
|
/****************************************************************************
**
** Implementation of TQMenuData class
**
** Created : 941128
**
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial 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 WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#include "tqmenudata.h"
#ifndef TQT_NO_MENUDATA
#include "tqpopupmenu.h"
#include "tqmenubar.h"
#include "ntqapplication.h"
#include "tqguardedptr.h"
class TQMenuItemData {
public:
TQCustomMenuItem *custom_item; // custom menu item
};
class TQMenuDataData {
// attention: also defined in tqmenubar.cpp and tqpopupmenu.cpp
public:
TQMenuDataData();
TQGuardedPtr<TQWidget> aWidget;
int aInt;
};
TQMenuDataData::TQMenuDataData()
: aInt(-1)
{}
/*!
\class TQMenuData tqmenudata.h
\brief The TQMenuData class is a base class for TQMenuBar and TQPopupMenu.
\ingroup misc
TQMenuData has an internal list of menu items. A menu item can have
a text(), an \link accel() accelerator\endlink, a pixmap(), an
iconSet(), a whatsThis() text and a popup menu (unless it is a
separator). Menu items may optionally be \link setItemChecked()
checked\endlink (except for separators).
The menu item sends out an \link TQMenuBar::activated()
activated()\endlink signal when it is chosen and a \link
TQMenuBar::highlighted() highlighted()\endlink signal when it
receives the user input focus.
\keyword menu identifier
Menu items are assigned the menu identifier \e id that is passed
in insertItem() or an automatically generated identifier if \e id
is < 0 (the default). The generated identifiers (negative
integers) are guaranteed to be unique within the entire
application. The identifier is used to access the menu item in
other functions.
Menu items can be removed with removeItem() and removeItemAt(), or
changed with changeItem(). All menu items can be removed with
clear(). Accelerators can be changed or set with setAccel().
Checkable items can be checked or unchecked with setItemChecked().
Items can be enabled or disabled using setItemEnabled() and
connected and disconnected with connectItem() and disconnectItem()
respectively. By default, newly created menu items are visible.
They can be hidden (and shown again) with setItemVisible().
Menu items are stored in a list. Use findItem() to find an item by
its list position or by its menu identifier. (See also indexOf()
and idAt().)
\sa TQAccel TQPopupMenu TQAction
*/
/*****************************************************************************
TQMenuItem member functions
*****************************************************************************/
TQMenuItem::TQMenuItem()
:ident( -1 ), iconset_data( 0 ), pixmap_data( 0 ), popup_menu( 0 ),
widget_item( 0 ), signal_data( 0 ), is_separator( FALSE ), is_enabled( TRUE ),
is_checked( FALSE ), is_dirty( TRUE ), is_visible( TRUE ), d( 0)
{}
TQMenuItem::~TQMenuItem()
{
delete iconset_data;
delete pixmap_data;
delete signal_data;
delete widget_item;
if ( d )
delete d->custom_item;
delete d;
}
/*****************************************************************************
TQMenuData member functions
*****************************************************************************/
TQMenuItemData* TQMenuItem::extra()
{
if ( !d ) d = new TQMenuItemData;
return d;
}
TQCustomMenuItem *TQMenuItem::custom() const
{
if ( !d ) return 0;
return d->custom_item;
}
static int get_seq_id()
{
static int seq_no = -2;
return seq_no--;
}
/*!
Constructs an empty menu data list.
*/
TQMenuData::TQMenuData()
{
actItem = -1; // no active menu item
mitems = new TQMenuItemList; // create list of menu items
TQ_CHECK_PTR( mitems );
mitems->setAutoDelete( TRUE );
parentMenu = 0; // assume top level
isPopupMenu = FALSE;
isMenuBar = FALSE;
mouseBtDn = FALSE;
badSize = TRUE;
avoid_circularity = 0;
actItemDown = FALSE;
d = new TQMenuDataData;
}
/*!
Removes all menu items and disconnects any signals that have been
connected.
*/
TQMenuData::~TQMenuData()
{
delete mitems; // delete menu item list
delete d;
}
/*!
Virtual function; notifies subclasses about an item with \a id
that has been changed.
*/
void TQMenuData::updateItem( int /* id */ ) // reimplemented in subclass
{
}
/*!
Virtual function; notifies subclasses that one or more items have
been inserted or removed.
*/
void TQMenuData::menuContentsChanged() // reimplemented in subclass
{
}
/*!
Virtual function; notifies subclasses that one or more items have
changed state (enabled/disabled or checked/unchecked).
*/
void TQMenuData::menuStateChanged() // reimplemented in subclass
{
}
/*!
Virtual function; notifies subclasses that a popup menu item has
been inserted.
*/
void TQMenuData::menuInsPopup( TQPopupMenu * ) // reimplemented in subclass
{
}
/*!
Virtual function; notifies subclasses that a popup menu item has
been removed.
*/
void TQMenuData::menuDelPopup( TQPopupMenu * ) // reimplemented in subclass
{
}
/*!
Returns the number of items in the menu.
*/
uint TQMenuData::count() const
{
return mitems->count();
}
/*!
\internal
Internal function that insert a menu item. Called by all insert()
functions.
*/
int TQMenuData::insertAny( const TQString *text, const TQPixmap *pixmap,
TQPopupMenu *popup, const TQIconSet* iconset, int id, int index,
TQWidget* widget, TQCustomMenuItem* custom )
{
if ( index < 0 ) { // append, but not if the rightmost item is an mdi separator in the menubar
index = mitems->count();
if ( isMenuBar && mitems->last() && mitems->last()->widget() && mitems->last()->isSeparator() )
index--;
} else if ( index > (int) mitems->count() ) { // append
index = mitems->count();
}
if ( id < 0 ) // -2, -3 etc.
id = get_seq_id();
TQMenuItem *mi = new TQMenuItem;
TQ_CHECK_PTR( mi );
mi->ident = id;
if ( widget != 0 ) {
mi->widget_item = widget;
mi->is_separator = !widget->isFocusEnabled();
} else if ( custom != 0 ) {
mi->extra()->custom_item = custom;
mi->is_separator = custom->isSeparator();
if ( iconset && !iconset->isNull() )
mi->iconset_data = new TQIconSet( *iconset );
} else if ( text == 0 && pixmap == 0 && popup == 0 ) {
mi->is_separator = TRUE; // separator
} else {
#ifndef Q_OS_TEMP
mi->text_data = text?*text:TQString();
#else
TQString newText( *text );
newText.truncate( newText.findRev( '\t' ) );
mi->text_data = newText.isEmpty()?TQString():newText;
#endif
#ifndef TQT_NO_ACCEL
mi->accel_key = TQt::Key_unknown;
#endif
if ( pixmap && !pixmap->isNull() )
mi->pixmap_data = new TQPixmap( *pixmap );
if ( (mi->popup_menu = popup) )
menuInsPopup( popup );
if ( iconset && !iconset->isNull() )
mi->iconset_data = new TQIconSet( *iconset );
}
mitems->insert( index, mi );
TQPopupMenu* p = ::tqt_cast<TQPopupMenu*>(TQMenuData::d->aWidget);
if (p && p->isVisible() && p->mitems) {
p->mitems->clear();
for ( TQMenuItemListIt it( *mitems ); it.current(); ++it ) {
if ( it.current()->id() != TQMenuData::d->aInt && !it.current()->widget() )
p->mitems->append( it.current() );
}
}
menuContentsChanged(); // menu data changed
return mi->ident;
}
/*!
\internal
Internal function that finds the menu item where \a popup is located,
storing its index at \a index if \a index is not NULL.
*/
TQMenuItem *TQMenuData::findPopup( TQPopupMenu *popup, int *index )
{
int i = 0;
TQMenuItem *mi = mitems->first();
while ( mi ) {
if ( mi->popup_menu == popup ) // found popup
break;
i++;
mi = mitems->next();
}
if ( index && mi )
*index = i;
return mi;
}
void TQMenuData::removePopup( TQPopupMenu *popup )
{
int index = 0;
TQMenuItem *mi = findPopup( popup, &index );
if ( mi ) {
mi->popup_menu = 0;
removeItemAt( index );
}
}
/*!
The family of insertItem() functions inserts menu items into a
popup menu or a menu bar.
A menu item is usually either a text string or a pixmap, both with
an optional icon or keyboard accelerator. For special cases it is
also possible to insert custom items (see \l{TQCustomMenuItem}) or
even widgets into popup menus.
Some insertItem() members take a popup menu as an additional
argument. Use this to insert submenus into existing menus or
pulldown menus into a menu bar.
The number of insert functions may look confusing, but they are
actually quite simple to use.
This default version inserts a menu item with the text \a text,
the accelerator key \a accel, an id and an optional index and
connects it to the slot \a member in the object \a receiver.
Example:
\code
TQMenuBar *mainMenu = new TQMenuBar;
TQPopupMenu *fileMenu = new TQPopupMenu;
fileMenu->insertItem( "New", myView, TQ_SLOT(newFile()), CTRL+Key_N );
fileMenu->insertItem( "Open", myView, TQ_SLOT(open()), CTRL+Key_O );
mainMenu->insertItem( "File", fileMenu );
\endcode
Not all insert functions take an object/slot parameter or an
accelerator key. Use connectItem() and setAccel() on those items.
If you need to translate accelerators, use tr() with the text and
accelerator. (For translations use a string \link TQKeySequence key
sequence\endlink.):
\code
fileMenu->insertItem( tr("Open"), myView, TQ_SLOT(open()),
tr("Ctrl+O") );
\endcode
In the example above, pressing Ctrl+O or selecting "Open" from the
menu activates the myView->open() function.
Some insert functions take a TQIconSet parameter to specify the
little menu item icon. Note that you can always pass a TQPixmap
object instead.
The \a id specifies the identification number associated with the
menu item. Note that only positive values are valid, as a negative
value will make TQt select a unique id for the item.
The \a index specifies the position in the menu. The menu item is
appended at the end of the list if \a index is negative.
Note that keyboard accelerators in TQt are not application-global,
instead they are bound to a certain top-level window. For example,
accelerators in TQPopupMenu items only work for menus that are
associated with a certain window. This is true for popup menus
that live in a menu bar since their accelerators will then be
installed in the menu bar itself. This also applies to stand-alone
popup menus that have a top-level widget in their parentWidget()
chain. The menu will then install its accelerator object on that
top-level widget. For all other cases use an independent TQAccel
object.
\warning Be careful when passing a literal 0 to insertItem()
because some C++ compilers choose the wrong overloaded function.
Cast the 0 to what you mean, e.g. \c{(TQObject*)0}.
\warning On Mac OS X, items that connect to a slot that are inserted into a
menubar will not function as we use the native menubar that knows nothing
about signals or slots. Instead insert the items into a popup menu and
insert the popup menu into the menubar. This may be fixed in a future TQt
version.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem(), TQAccel,
ntqnamespace.h
*/
int TQMenuData::insertItem( const TQString &text,
const TQObject *receiver, const char* member,
const TQKeySequence& accel, int id, int index )
{
int actualID = insertAny( &text, 0, 0, 0, id, index );
connectItem( actualID, receiver, member );
#ifndef TQT_NO_ACCEL
if ( accel )
setAccel( accel, actualID );
#endif
return actualID;
}
/*!
\overload
Inserts a menu item with icon \a icon, text \a text, accelerator
\a accel, optional id \a id, and optional \a index position. The
menu item is connected it to the \a receiver's \a member slot. The
icon will be displayed to the left of the text in the item.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem(), TQAccel,
ntqnamespace.h
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQString &text,
const TQObject *receiver, const char* member,
const TQKeySequence& accel, int id, int index )
{
int actualID = insertAny( &text, 0, 0, &icon, id, index );
connectItem( actualID, receiver, member );
#ifndef TQT_NO_ACCEL
if ( accel )
setAccel( accel, actualID );
#endif
return actualID;
}
/*!
\overload
Inserts a menu item with pixmap \a pixmap, accelerator \a accel,
optional id \a id, and optional \a index position. The menu item
is connected it to the \a receiver's \a member slot. The icon will
be displayed to the left of the text in the item.
To look best when being highlighted as a menu item, the pixmap
should provide a mask (see TQPixmap::mask()).
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQPixmap &pixmap,
const TQObject *receiver, const char* member,
const TQKeySequence& accel, int id, int index )
{
int actualID = insertAny( 0, &pixmap, 0, 0, id, index );
connectItem( actualID, receiver, member );
#ifndef TQT_NO_ACCEL
if ( accel )
setAccel( accel, actualID );
#endif
return actualID;
}
/*!
\overload
Inserts a menu item with icon \a icon, pixmap \a pixmap,
accelerator \a accel, optional id \a id, and optional \a index
position. The icon will be displayed to the left of the pixmap in
the item. The item is connected to the \a member slot in the \a
receiver object.
To look best when being highlighted as a menu item, the pixmap
should provide a mask (see TQPixmap::mask()).
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem(), TQAccel,
ntqnamespace.h
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQPixmap &pixmap,
const TQObject *receiver, const char* member,
const TQKeySequence& accel, int id, int index )
{
int actualID = insertAny( 0, &pixmap, 0, &icon, id, index );
connectItem( actualID, receiver, member );
#ifndef TQT_NO_ACCEL
if ( accel )
setAccel( accel, actualID );
#endif
return actualID;
}
/*!
\overload
Inserts a menu item with text \a text, optional id \a id, and
optional \a index position.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQString &text, int id, int index )
{
return insertAny( &text, 0, 0, 0, id, index );
}
/*!
\overload
Inserts a menu item with icon \a icon, text \a text, optional id
\a id, and optional \a index position. The icon will be displayed
to the left of the text in the item.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQString &text, int id, int index )
{
return insertAny( &text, 0, 0, &icon, id, index );
}
/*!
\overload
Inserts a menu item with text \a text, submenu \a popup, optional
id \a id, and optional \a index position.
The \a popup must be deleted by the programmer or by its parent
widget. It is not deleted when this menu item is removed or when
the menu is deleted.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQString &text, TQPopupMenu *popup,
int id, int index )
{
return insertAny( &text, 0, popup, 0, id, index );
}
/*!
\overload
Inserts a menu item with icon \a icon, text \a text, submenu \a
popup, optional id \a id, and optional \a index position. The icon
will be displayed to the left of the text in the item.
The \a popup must be deleted by the programmer or by its parent
widget. It is not deleted when this menu item is removed or when
the menu is deleted.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQString &text, TQPopupMenu *popup,
int id, int index )
{
return insertAny( &text, 0, popup, &icon, id, index );
}
/*!
\overload
Inserts a menu item with pixmap \a pixmap, optional id \a id, and
optional \a index position.
To look best when being highlighted as a menu item, the pixmap
should provide a mask (see TQPixmap::mask()).
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQPixmap &pixmap, int id, int index )
{
return insertAny( 0, &pixmap, 0, 0, id, index );
}
/*!
\overload
Inserts a menu item with icon \a icon, pixmap \a pixmap, optional
id \a id, and optional \a index position. The icon will be
displayed to the left of the pixmap in the item.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQPixmap &pixmap, int id, int index )
{
return insertAny( 0, &pixmap, 0, &icon, id, index );
}
/*!
\overload
Inserts a menu item with pixmap \a pixmap, submenu \a popup,
optional id \a id, and optional \a index position.
The \a popup must be deleted by the programmer or by its parent
widget. It is not deleted when this menu item is removed or when
the menu is deleted.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQPixmap &pixmap, TQPopupMenu *popup,
int id, int index )
{
return insertAny( 0, &pixmap, popup, 0, id, index );
}
/*!
\overload
Inserts a menu item with icon \a icon, pixmap \a pixmap submenu \a
popup, optional id \a id, and optional \a index position. The icon
will be displayed to the left of the pixmap in the item.
The \a popup must be deleted by the programmer or by its parent
widget. It is not deleted when this menu item is removed or when
the menu is deleted.
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem(), changeItem(), setAccel(), connectItem()
*/
int TQMenuData::insertItem( const TQIconSet& icon,
const TQPixmap &pixmap, TQPopupMenu *popup,
int id, int index )
{
return insertAny( 0, &pixmap, popup, &icon, id, index );
}
/*!
\overload
Inserts a menu item that consists of the widget \a widget with
optional id \a id, and optional \a index position.
Ownership of \a widget is transferred to the popup menu or to the
menu bar.
Theoretically, any widget can be inserted into a popup menu. In
practice, this only makes sense with certain widgets.
If a widget is not focus-enabled (see
\l{TQWidget::isFocusEnabled()}), the menu treats it as a separator;
this means that the item is not selectable and will never get
focus. In this way you can, for example, simply insert a TQLabel if
you need a popup menu with a title.
If the widget is focus-enabled it will get focus when the user
traverses the popup menu with the arrow keys. If the widget does
not accept \c ArrowUp and \c ArrowDown in its key event handler,
the focus will move back to the menu when the respective arrow key
is hit one more time. This works with a TQLineEdit, for example. If
the widget accepts the arrow key itself, it must also provide the
possibility to put the focus back on the menu again by calling
TQWidget::focusNextPrevChild(). Futhermore, if the embedded widget
closes the menu when the user made a selection, this can be done
safely by calling:
\code
if ( isVisible() &&
parentWidget() &&
parentWidget()->inherits("TQPopupMenu") )
parentWidget()->close();
\endcode
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa removeItem()
*/
int TQMenuData::insertItem( TQWidget* widget, int id, int index )
{
return insertAny( 0, 0, 0, 0, id, index, widget );
}
/*!
\overload
Inserts a custom menu item \a custom with optional id \a id, and
optional \a index position.
This only works with popup menus. It is not supported for menu
bars. Ownership of \a custom is transferred to the popup menu.
If you want to connect a custom item to a slot, use connectItem().
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa connectItem(), removeItem(), TQCustomMenuItem
*/
int TQMenuData::insertItem( TQCustomMenuItem* custom, int id, int index )
{
return insertAny( 0, 0, 0, 0, id, index, 0, custom );
}
/*!
\overload
Inserts a custom menu item \a custom with an \a icon and with
optional id \a id, and optional \a index position.
This only works with popup menus. It is not supported for menu
bars. Ownership of \a custom is transferred to the popup menu.
If you want to connect a custom item to a slot, use connectItem().
Returns the allocated menu identifier number (\a id if \a id >= 0).
\sa connectItem(), removeItem(), TQCustomMenuItem
*/
int TQMenuData::insertItem( const TQIconSet& icon, TQCustomMenuItem* custom, int id, int index )
{
return insertAny( 0, 0, 0, &icon, id, index, 0, custom );
}
/*!
Inserts a separator at position \a index, and returns the menu identifier
number allocated to it. The separator becomes the last menu item if
\a index is negative.
In a popup menu a separator is rendered as a horizontal line. In a
Motif menu bar a separator is spacing, so the rest of the items
(normally just "Help") are drawn right-justified. In a Windows
menu bar separators are ignored (to comply with the Windows style
guidelines).
*/
int TQMenuData::insertSeparator( int index )
{
return insertAny( 0, 0, 0, 0, -1, index );
}
/*!
\fn void TQMenuData::removeItem( int id )
Removes the menu item that has the identifier \a id.
\sa removeItemAt(), clear()
*/
void TQMenuData::removeItem( int id )
{
TQMenuData *parent;
if ( findItem( id, &parent ) )
parent->removeItemAt(parent->indexOf(id));
}
/*!
Removes the menu item at position \a index.
\sa removeItem(), clear()
*/
void TQMenuData::removeItemAt( int index )
{
if ( index < 0 || index >= (int)mitems->count() ) {
#if defined(QT_CHECK_RANGE)
tqWarning( "TQMenuData::removeItem: Index %d out of range", index );
#endif
return;
}
TQMenuItem *mi = mitems->at( index );
if ( mi->popup_menu )
menuDelPopup( mi->popup_menu );
mitems->remove();
TQPopupMenu* p = ::tqt_cast<TQPopupMenu*>(TQMenuData::d->aWidget);
if (p && p->isVisible() && p->mitems) {
p->mitems->clear();
for ( TQMenuItemListIt it( *mitems ); it.current(); ++it ) {
if ( it.current()->id() != TQMenuData::d->aInt && !it.current()->widget() )
p->mitems->append( it.current() );
}
}
if ( !TQApplication::closingDown() ) // avoid trouble
menuContentsChanged();
}
/*!
Removes all menu items.
\sa removeItem(), removeItemAt()
*/
void TQMenuData::clear()
{
TQMenuItem *mi = mitems->first();
while ( mi ) {
if ( mi->popup_menu )
menuDelPopup( mi->popup_menu );
mitems->remove();
mi = mitems->current();
}
TQPopupMenu* p = ::tqt_cast<TQPopupMenu*>(TQMenuData::d->aWidget);
if (p && p->isVisible() && p->mitems) {
p->mitems->clear();
}
if ( !TQApplication::closingDown() ) // avoid trouble
menuContentsChanged();
}
#ifndef TQT_NO_ACCEL
/*!
Returns the accelerator key that has been defined for the menu
item \a id, or 0 if it has no accelerator key or if there is no
such menu item.
\sa setAccel(), TQAccel, ntqnamespace.h
*/
TQKeySequence TQMenuData::accel( int id ) const
{
TQMenuItem *mi = findItem( id );
if ( mi )
return mi->key();
return TQKeySequence();
}
/*!
Sets the accelerator key for the menu item \a id to \a key.
An accelerator key consists of a key code and a combination of the
modifiers \c SHIFT, \c CTRL, \c ALT or \c UNICODE_ACCEL (OR'ed or
added). The header file \c ntqnamespace.h contains a list of key
codes.
Defining an accelerator key produces a text that is added to the
menu item; for instance, \c CTRL + \c Key_O produces "Ctrl+O". The
text is formatted differently for different platforms.
Note that keyboard accelerators in TQt are not application-global,
instead they are bound to a certain top-level window. For example,
accelerators in TQPopupMenu items only work for menus that are
associated with a certain window. This is true for popup menus
that live in a menu bar since their accelerators will then be
installed in the menu bar itself. This also applies to stand-alone
popup menus that have a top-level widget in their parentWidget()
chain. The menu will then install its accelerator object on that
top-level widget. For all other cases use an independent TQAccel
object.
Example:
\code
TQMenuBar *mainMenu = new TQMenuBar;
TQPopupMenu *fileMenu = new TQPopupMenu; // file sub menu
fileMenu->insertItem( "Open Document", 67 ); // add "Open" item
fileMenu->setAccel( CTRL + Key_O, 67 ); // Ctrl+O to open
fileMenu->insertItem( "Quit", 69 ); // add "Quit" item
fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 ); // add Alt+Del to quit
mainMenu->insertItem( "File", fileMenu ); // add the file menu
\endcode
If you need to translate accelerators, use tr() with a string:
\code
fileMenu->setAccel( tr("Ctrl+O"), 67 );
\endcode
You can also specify the accelerator in the insertItem() function.
You may prefer to use TQAction to associate accelerators with menu
items.
\sa accel() insertItem() TQAccel TQAction
*/
void TQMenuData::setAccel( const TQKeySequence& key, int id )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi ) {
mi->accel_key = key;
parent->menuContentsChanged();
}
}
#endif // TQT_NO_ACCEL
/*!
Returns the icon set that has been set for menu item \a id, or 0
if no icon set has been set.
\sa changeItem(), text(), pixmap()
*/
TQIconSet* TQMenuData::iconSet( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->iconSet() : 0;
}
/*!
Returns the text that has been set for menu item \a id, or
TQString::null if no text has been set.
\sa changeItem(), pixmap(), iconSet()
*/
TQString TQMenuData::text( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->text() : TQString::null;
}
/*!
Returns the pixmap that has been set for menu item \a id, or 0 if
no pixmap has been set.
\sa changeItem(), text(), iconSet()
*/
TQPixmap *TQMenuData::pixmap( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->pixmap() : 0;
}
/*!
\fn void TQMenuData::changeItem( const TQString &, int )
\obsolete
Changes the text of the menu item \a id. If the item has an icon,
the icon remains unchanged.
\sa text()
*/
/*!
\fn void TQMenuData::changeItem( const TQPixmap &, int )
\obsolete
Changes the pixmap of the menu item \a id. If the item has an icon,
the icon remains unchanged.
\sa pixmap()
*/
/*!
\fn void TQMenuData::changeItem( const TQIconSet &, const TQString &, int )
\obsolete
Changes the icon and text of the menu item \a id.
\sa pixmap()
*/
/*!
Changes the text of the menu item \a id to \a text. If the item
has an icon, the icon remains unchanged.
\sa text()
*/
void TQMenuData::changeItem( int id, const TQString &text )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi ) { // item found
if ( mi->text_data == text ) // same string
return;
if ( mi->pixmap_data ) { // delete pixmap
delete mi->pixmap_data;
mi->pixmap_data = 0;
}
mi->text_data = text;
#ifndef TQT_NO_ACCEL
if ( !mi->accel_key && text.find( '\t' ) != -1 )
mi->accel_key = TQt::Key_unknown;
#endif
parent->menuContentsChanged();
}
}
/*!
\overload
Changes the pixmap of the menu item \a id to the pixmap \a pixmap.
If the item has an icon, the icon is unchanged.
\sa pixmap()
*/
void TQMenuData::changeItem( int id, const TQPixmap &pixmap )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi ) { // item found
TQPixmap *i = mi->pixmap_data;
bool fast_refresh = i != 0 &&
i->width() == pixmap.width() &&
i->height() == pixmap.height() &&
!mi->text();
if ( !mi->text_data.isNull() ) // delete text
mi->text_data = TQString::null;
if ( !pixmap.isNull() )
mi->pixmap_data = new TQPixmap( pixmap );
else
mi->pixmap_data = 0;
delete i; // old mi->pixmap_data, could be &pixmap
if ( fast_refresh )
parent->updateItem( id );
else
parent->menuContentsChanged();
}
}
/*!
\overload
Changes the iconset and text of the menu item \a id to the \a icon
and \a text respectively.
\sa pixmap()
*/
void TQMenuData::changeItem( int id, const TQIconSet &icon, const TQString &text )
{
changeItem( id, text );
changeItemIconSet( id, icon );
}
/*!
\overload
Changes the iconset and pixmap of the menu item \a id to \a icon
and \a pixmap respectively.
\sa pixmap()
*/
void TQMenuData::changeItem( int id, const TQIconSet &icon, const TQPixmap &pixmap )
{
changeItem( id, pixmap );
changeItemIconSet( id, icon );
}
/*!
Changes the icon of the menu item \a id to \a icon.
\sa pixmap()
*/
void TQMenuData::changeItemIconSet( int id, const TQIconSet &icon )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi ) { // item found
TQIconSet *i = mi->iconset_data;
bool fast_refresh = i != 0;
if ( !icon.isNull() )
mi->iconset_data = new TQIconSet( icon );
else
mi->iconset_data = 0;
delete i; // old mi->iconset_data, could be &icon
if ( fast_refresh )
parent->updateItem( id );
else
parent->menuContentsChanged();
}
}
/*!
Returns TRUE if the item with identifier \a id is enabled;
otherwise returns FALSE
\sa setItemEnabled(), isItemVisible()
*/
bool TQMenuData::isItemEnabled( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->isEnabled() : FALSE;
}
/*!
If \a enable is TRUE, enables the menu item with identifier \a id;
otherwise disables the menu item with identifier \a id.
\sa isItemEnabled()
*/
void TQMenuData::setItemEnabled( int id, bool enable )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi && (bool)mi->is_enabled != enable ) {
mi->is_enabled = enable;
#if !defined(TQT_NO_ACCEL) && !defined(TQT_NO_POPUPMENU)
if ( mi->popup() )
mi->popup()->enableAccel( enable );
#endif
parent->menuStateChanged();
}
}
/*!
Returns TRUE if the menu item with the id \a id is currently
active; otherwise returns FALSE.
*/
bool TQMenuData::isItemActive( int id ) const
{
if ( actItem == -1 )
return FALSE;
return indexOf( id ) == actItem;
}
/*!
Returns TRUE if the menu item with the id \a id has been checked;
otherwise returns FALSE.
\sa setItemChecked()
*/
bool TQMenuData::isItemChecked( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->isChecked() : FALSE;
}
/*!
If \a check is TRUE, checks the menu item with id \a id; otherwise
unchecks the menu item with id \a id. Calls
TQPopupMenu::setCheckable( TRUE ) if necessary.
\sa isItemChecked()
*/
void TQMenuData::setItemChecked( int id, bool check )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi && (bool)mi->is_checked != check ) {
mi->is_checked = check;
#ifndef TQT_NO_POPUPMENU
if ( parent->isPopupMenu && !((TQPopupMenu *)parent)->isCheckable() )
((TQPopupMenu *)parent)->setCheckable( TRUE );
#endif
parent->menuStateChanged();
}
}
/*!
Returns TRUE if the menu item with the id \a id is visible;
otherwise returns FALSE.
\sa setItemVisible()
*/
bool TQMenuData::isItemVisible( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi ? mi->isVisible() : FALSE;
}
/*!
If \a visible is TRUE, shows the menu item with id \a id; otherwise
hides the menu item with id \a id.
\sa isItemVisible(), isItemEnabled()
*/
void TQMenuData::setItemVisible( int id, bool visible )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi && (bool)mi->is_visible != visible ) {
mi->is_visible = visible;
parent->menuContentsChanged();
}
}
/*!
Returns the menu item with identifier \a id, or 0 if there is no
item with this identifier.
Note that TQMenuItem is an internal class, and that you should not
need to call this function. Use the higher level functions like
text(), pixmap() and changeItem() to get and modify menu item
attributes instead.
\sa indexOf()
*/
TQMenuItem *TQMenuData::findItem( int id ) const
{
return findItem( id, 0 );
}
/*!
\overload
Returns the menu item with identifier \a id, or 0 if there is no
item with this identifier. Changes \a *parent to point to the
parent of the return value.
Note that TQMenuItem is an internal class, and that you should not
need to call this function. Use the higher level functions like
text(), pixmap() and changeItem() to get and modify menu item
attributes instead.
\sa indexOf()
*/
TQMenuItem * TQMenuData::findItem( int id, TQMenuData ** parent ) const
{
if ( parent )
*parent = (TQMenuData *)this; // ###
if ( id == -1 ) // bad identifier
return 0;
TQMenuItemListIt it( *mitems );
TQMenuItem *mi;
while ( (mi=it.current()) ) { // search this menu
++it;
if ( mi->ident == id ) // found item
return mi;
}
it.toFirst();
while ( (mi=it.current()) ) { // search submenus
++it;
#ifndef TQT_NO_POPUPMENU
if ( mi->popup_menu ) {
TQPopupMenu *p = mi->popup_menu;
if (!p->avoid_circularity) {
p->avoid_circularity = 1;
mi = mi->popup_menu->findItem( id, parent );
p->avoid_circularity = 0;
if ( mi ) // found item
return mi;
}
}
#endif
}
return 0; // not found
}
/*!
Returns the index of the menu item with identifier \a id, or -1 if
there is no item with this identifier.
\sa idAt(), findItem()
*/
int TQMenuData::indexOf( int id ) const
{
if ( id == -1 ) // bad identifier
return -1;
TQMenuItemListIt it( *mitems );
TQMenuItem *mi;
int index = 0;
while ( (mi=it.current()) ) {
if ( mi->ident == id ) // this one?
return index;
++index;
++it;
}
return -1; // not found
}
/*!
Returns the identifier of the menu item at position \a index in
the internal list, or -1 if \a index is out of range.
\sa setId(), indexOf()
*/
int TQMenuData::idAt( int index ) const
{
return index < (int)mitems->count() && index >= 0 ?
mitems->at(index)->id() : -1;
}
/*!
Sets the menu identifier of the item at \a index to \a id.
If \a index is out of range, the operation is ignored.
\sa idAt()
*/
void TQMenuData::setId( int index, int id )
{
if ( index < (int)mitems->count() )
mitems->at(index)->ident = id;
}
/*!
Sets the parameter of the activation signal of item \a id to \a
param.
If any receiver takes an integer parameter, this value is passed.
\sa connectItem(), disconnectItem(), itemParameter()
*/
bool TQMenuData::setItemParameter( int id, int param ) {
TQMenuItem *mi = findItem( id );
if ( !mi ) // no such identifier
return FALSE;
if ( !mi->signal_data ) { // create new signal
mi->signal_data = new TQSignal;
TQ_CHECK_PTR( mi->signal_data );
}
mi->signal_data->setValue( param );
return TRUE;
}
/*!
Returns the parameter of the activation signal of item \a id.
If no parameter has been specified for this item with
setItemParameter(), the value defaults to \a id.
\sa connectItem(), disconnectItem(), setItemParameter()
*/
int TQMenuData::itemParameter( int id ) const
{
TQMenuItem *mi = findItem( id );
if ( !mi || !mi->signal_data )
return id;
return mi->signal_data->value().toInt();
}
/*!
Connects the menu item with identifier \a id to \a{receiver}'s \a
member slot or signal.
The receiver's slot (or signal) is activated when the menu item is
activated.
\sa disconnectItem(), setItemParameter()
*/
bool TQMenuData::connectItem( int id, const TQObject *receiver,
const char* member )
{
TQMenuItem *mi = findItem( id );
if ( !mi ) // no such identifier
return FALSE;
if ( !mi->signal_data ) { // create new signal
mi->signal_data = new TQSignal;
TQ_CHECK_PTR( mi->signal_data );
mi->signal_data->setValue( id );
}
return mi->signal_data->connect( receiver, member );
}
/*!
Disconnects the \a{receiver}'s \a member from the menu item with
identifier \a id.
All connections are removed when the menu data object is
destroyed.
\sa connectItem(), setItemParameter()
*/
bool TQMenuData::disconnectItem( int id, const TQObject *receiver,
const char* member )
{
TQMenuItem *mi = findItem( id );
if ( !mi || !mi->signal_data ) // no identifier or no signal
return FALSE;
return mi->signal_data->disconnect( receiver, member );
}
/*!
Sets \a text as What's This help for the menu item with identifier
\a id.
\sa whatsThis()
*/
void TQMenuData::setWhatsThis( int id, const TQString& text )
{
TQMenuData *parent;
TQMenuItem *mi = findItem( id, &parent );
if ( mi ) {
mi->setWhatsThis( text );
parent->menuContentsChanged();
}
}
/*!
Returns the What's This help text for the item with identifier \a
id or TQString::null if no text has yet been defined.
\sa setWhatsThis()
*/
TQString TQMenuData::whatsThis( int id ) const
{
TQMenuItem *mi = findItem( id );
return mi? mi->whatsThis() : TQString::null;
}
/*!
\class TQCustomMenuItem tqmenudata.h
\brief The TQCustomMenuItem class is an abstract base class for custom menu items in popup menus.
\ingroup misc
A custom menu item is a menu item that is defined by two pure
virtual functions, paint() and sizeHint(). The size hint tells the
menu how much space it needs to reserve for this item, and paint
is called whenever the item needs painting.
This simple mechanism allows you to create all kinds of
application specific menu items. Examples are items showing
different fonts in a word processor or menus that allow the
selection of drawing utilities in a vector drawing program.
A custom item is inserted into a popup menu with
TQPopupMenu::insertItem().
By default, a custom item can also have an icon and a keyboard
accelerator. You can reimplement fullSpan() to return TRUE if you
want the item to span the entire popup menu width. This is
particularly useful for labels.
If you want the custom item to be treated just as a separator,
reimplement isSeparator() to return TRUE.
Note that you can insert pixmaps or bitmaps as items into a popup
menu without needing to create a TQCustomMenuItem. However, custom
menu items offer more flexibility, and -- especially important
with Windows style -- provide the possibility of drawing the item
with a different color when it is highlighted.
\link menu-example.html menu/menu.cpp\endlink shows a simple
example how custom menu items can be used.
Note: the current implementation of TQCustomMenuItem will not
recognize shortcut keys that are from text with ampersands. Normal
accelerators work though.
<img src=qpopmenu-fancy.png>
\sa TQMenuData, TQPopupMenu
*/
/*!
Constructs a TQCustomMenuItem
*/
TQCustomMenuItem::TQCustomMenuItem()
{
}
/*!
Destroys a TQCustomMenuItem
*/
TQCustomMenuItem::~TQCustomMenuItem()
{
}
/*!
Sets the font of the custom menu item to \a font.
This function is called whenever the font in the popup menu
changes. For menu items that show their own individual font entry,
you want to ignore this.
*/
void TQCustomMenuItem::setFont( const TQFont& /* font */ )
{
}
/*!
Returns TRUE if this item wants to span the entire popup menu
width; otherwise returns FALSE. The default is FALSE, meaning that
the menu may show an icon and an accelerator key for this item as
well.
*/
bool TQCustomMenuItem::fullSpan() const
{
return FALSE;
}
/*!
Returns TRUE if this item is just a separator; otherwise returns
FALSE.
*/
bool TQCustomMenuItem::isSeparator() const
{
return FALSE;
}
/*!
\fn void TQCustomMenuItem::paint( TQPainter* p, const TQColorGroup& cg, bool act, bool enabled, int x, int y, int w, int h );
Paints this item. When this function is invoked, the painter \a p
is set to a font and foreground color suitable for a menu item
text using color group \a cg. The item is active if \a act is TRUE
and enabled if \a enabled is TRUE. The geometry values \a x, \a y,
\a w and \a h specify where to draw the item.
Do not draw any background, this has already been done by the
popup menu according to the current GUI style.
*/
/*!
\fn TQSize TQCustomMenuItem::sizeHint();
Returns the item's size hint.
*/
/*!
Activates the menu item at position \a index.
If the index is invalid (for example, -1), the object itself is
deactivated.
*/
void TQMenuData::activateItemAt( int index )
{
#ifndef TQT_NO_MENUBAR
if ( isMenuBar )
( (TQMenuBar*)this )->activateItemAt( index );
else
#endif
{
#ifndef TQT_NO_POPUPMENU
if ( isPopupMenu )
( (TQPopupMenu*)this )->activateItemAt( index );
#endif
}
}
#endif
|