source: trunk/examples/widgets/widgets.cpp@ 203

Last change on this file since 203 was 160, checked in by dmik, 19 years ago

Imported table and iconview modules and a bunch of dependent examples from the official release 3.3.1 from Trolltech.

  • Property svn:keywords set to Id
File size: 23.3 KB
Line 
1/****************************************************************************
2** $Id: widgets.cpp 160 2006-12-11 20:15:57Z dmik $
3**
4** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include <qmessagebox.h>
12#include <qpixmap.h>
13#include <qlayout.h>
14#include <qapplication.h>
15
16// Standard Qt widgets
17
18#include <qtoolbar.h>
19#include <qmenubar.h>
20#include <qpopupmenu.h>
21#include <qbuttongroup.h>
22#include <qcheckbox.h>
23#include <qcombobox.h>
24#include <qframe.h>
25#include <qgroupbox.h>
26#include <qlabel.h>
27#include <qlcdnumber.h>
28#include <qmultilineedit.h>
29#include <qlineedit.h>
30#include <qlistbox.h>
31#include <qpushbutton.h>
32#include <qradiobutton.h>
33#include <qslider.h>
34#include <qtooltip.h>
35#include <qspinbox.h>
36#include <qstatusbar.h>
37#include <qwhatsthis.h>
38#include <qtoolbutton.h>
39#include <qvbox.h>
40#include <qtabbar.h>
41#include <qtabwidget.h>
42#include <qwidgetstack.h>
43#include <qprogressbar.h>
44#include <qsplitter.h>
45#include <qlistview.h>
46#include <qheader.h>
47#include <qtextbrowser.h>
48#include <qfiledialog.h>
49#include <qaccel.h>
50#include <qmetaobject.h>
51#include <qpainter.h>
52
53#include "widgets.h"
54
55
56// Some sample widgets
57
58#include "../aclock/aclock.h"
59#include "../dclock/dclock.h"
60
61
62#define MOVIEFILENAME "trolltech.gif"
63
64#include "../application/fileopen.xpm"
65#include "../application/filesave.xpm"
66#include "../application/fileprint.xpm"
67
68
69class MyWhatsThis : public QWhatsThis
70{
71public:
72 MyWhatsThis( QListBox* lb)
73 : QWhatsThis( lb ) { listbox = lb; };
74 ~MyWhatsThis(){};
75
76
77 QString text( const QPoint & p) {
78 QListBoxItem* i = listbox->itemAt( p );
79 if ( i && i->pixmap() ) {
80 return "Isn't that a <em>wonderful</em> pixmap? <br>" \
81 "Imagine, you could even decorate a" \
82 " <b>red</b> pushbutton with it! :-)";
83 }
84 return "This is a QListBox.";
85 }
86
87private:
88 QListBox* listbox;
89};
90
91
92class MyMenuItem : public QCustomMenuItem
93{
94public:
95 MyMenuItem( const QString& s, const QFont& f )
96 : string( s ), font( f ){};
97 ~MyMenuItem(){}
98
99 void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/,
100 bool /*enabled*/, int x, int y, int w, int h )
101 {
102 p->setFont ( font );
103 p->drawText( x, y, w, h,
104 AlignAuto | AlignVCenter | ShowPrefix | DontClip,
105 string );
106 }
107
108 QSize sizeHint()
109 {
110 return QFontMetrics( font ).size( AlignAuto | AlignVCenter |
111 ShowPrefix | DontClip, string );
112 }
113private:
114 QString string;
115 QFont font;
116};
117
118//
119// Construct the WidgetView with children
120//
121
122WidgetView::WidgetView( QWidget *parent, const char *name )
123 : QMainWindow( parent, name )
124{
125 QColor col;
126
127 // Set the window caption/title
128 setCaption( "Qt Example - Widgets Demo Application" );
129
130 // create a toolbar
131 QToolBar *tools = new QToolBar( this, "toolbar" );
132
133 // put something in it
134 QPixmap openIcon( fileopen );
135 QToolButton * toolb = new QToolButton( openIcon, "toolbutton 1",
136 QString::null, this, SLOT(open()),
137 tools, "open file" );
138 QWhatsThis::add( toolb, "This is a <b>QToolButton</b>. It lives in a "
139 "QToolBar. This particular button doesn't do anything "
140 "useful." );
141
142 QPixmap saveIcon( filesave );
143 toolb = new QToolButton( saveIcon, "toolbutton 2", QString::null,
144 this, SLOT(dummy()),
145 tools, "save file" );
146 QWhatsThis::add( toolb, "This is also a <b>QToolButton</b>." );
147
148 QPixmap printIcon( fileprint );
149 toolb = new QToolButton( printIcon, "toolbutton 3", QString::null,
150 this, SLOT(dummy()),
151 tools, "print file" );
152 QWhatsThis::add( toolb, "This is the third <b>QToolButton</b>.");
153
154 toolb = QWhatsThis::whatsThisButton( tools );
155 QWhatsThis::add( toolb, "This is a <b>What's This</b> button "
156 "It enables the user to ask for help "
157 "about widgets on the screen.");
158
159 // Install an application-global event filter to catch control+leftbutton
160 qApp->installEventFilter( this );
161
162 //make a central widget to contain the other widgets
163 central = new QWidget( this );
164 setCentralWidget( central );
165
166 // Create a layout to position the widgets
167 QHBoxLayout *topLayout = new QHBoxLayout( central, 10 );
168
169 // Create a grid layout to hold most of the widgets
170 QGridLayout *grid = new QGridLayout( 0, 3 ); //3 wide and autodetect number of rows
171 topLayout->addLayout( grid, 1 );
172
173 // Create an easter egg
174 QToolTip::add( menuBar(), QRect( 0, 0, 2, 2 ), "easter egg" );
175
176 QPopupMenu* popup;
177 popup = new QPopupMenu( this );
178 menuBar()->insertItem( "&File", popup );
179 int id;
180 id = popup->insertItem( "&New" );
181 popup->setItemEnabled( id, FALSE );
182 id = popup->insertItem( openIcon, "&Open...", this, SLOT( open() ) );
183
184 popup->insertSeparator();
185 popup->insertItem( "Quit", qApp, SLOT(quit()), CTRL+Key_Q );
186
187 textStylePopup = popup = new QPopupMenu( this );
188 menuBar()->insertItem( "&Edit", popup );
189
190 plainStyleID = id = popup->insertItem( "&Plain" );
191 popup->setAccel( CTRL+Key_T, id );
192
193 popup->insertSeparator();
194 QFont f = font();
195 f.setBold( TRUE );
196 id = popup->insertItem( new MyMenuItem( "&Bold", f ) );
197 popup->setAccel( CTRL+Key_B, id );
198 f = font();
199 f.setItalic( TRUE );
200 id = popup->insertItem( new MyMenuItem( "&Italic", f ) );
201 popup->setItemChecked( id, TRUE );
202 popup->setAccel( CTRL+Key_I, id );
203 f = font();
204 f.setUnderline( TRUE );
205 id = popup->insertItem( new MyMenuItem( "&Underline", f ) );
206 popup->setAccel( CTRL+Key_U, id );
207 f = font();
208 f.setStrikeOut( TRUE );
209 id = popup->insertItem( new MyMenuItem( "&Strike", f ) );
210 connect( textStylePopup, SIGNAL(activated(int)),
211 this, SLOT(popupSelected(int)) );
212
213 // Create an analog and a digital clock
214 AnalogClock *aclock = new AnalogClock( central );
215 aclock->setAutoMask( TRUE );
216 DigitalClock *dclock = new DigitalClock( central );
217 dclock->setMaximumWidth(200);
218 grid->addWidget( aclock, 0, 2 );
219 grid->addWidget( dclock, 1, 2 );
220
221 // Give the dclock widget a blue palette
222 col.setRgb( 0xaa, 0xbe, 0xff );
223 dclock->setPalette( QPalette( col ) );
224
225 // make tool tips for both of them
226 QToolTip::add( aclock, "custom widget: analog clock" );
227 QToolTip::add( dclock, "custom widget: digital clock" );
228
229 // Create a push button.
230 QPushButton *pb;
231 pb = new QPushButton( "&Push button 1", central, "button1" );
232 grid->addWidget( pb, 0, 0, AlignVCenter );
233 connect( pb, SIGNAL(clicked()), SLOT(button1Clicked()) );
234 QToolTip::add( pb, "push button 1" );
235 QWhatsThis::add( pb, "This is a <b>QPushButton</b>.<br>"
236 "Click it and watch...<br>"
237 "The wonders of modern technology.");
238
239 QPixmap pm;
240 bool pix = pm.load("qt.png");
241 if ( !pix ) {
242 QMessageBox::information( 0, "Qt Widgets Example",
243 "Could not load the file \"qt.png\", which\n"
244 "contains an icon used...\n\n"
245 "The text \"line 42\" will be substituted.",
246 QMessageBox::Ok + QMessageBox::Default );
247 }
248
249 // Create a label containing a QMovie
250 movie = QMovie( MOVIEFILENAME );
251 movielabel = new QLabel( central, "label0" );
252 movie.connectStatus(this, SLOT(movieStatus(int)));
253 movie.connectUpdate(this, SLOT(movieUpdate(const QRect&)));
254 movielabel->setFrameStyle( QFrame::Box | QFrame::Plain );
255 movielabel->setMovie( movie );
256 movielabel->setFixedSize( 128+movielabel->frameWidth()*2,
257 64+movielabel->frameWidth()*2 );
258 grid->addWidget( movielabel, 0, 1, AlignCenter );
259 QToolTip::add( movielabel, "movie" );
260 QWhatsThis::add( movielabel, "This is a <b>QLabel</b> "
261 "that contains a QMovie." );
262
263 // Create a group of check boxes
264 bg = new QButtonGroup( central, "checkGroup" );
265 bg->setTitle( "Check Boxes" );
266 grid->addWidget( bg, 1, 0 );
267
268 // Create a layout for the check boxes
269 QVBoxLayout *vbox = new QVBoxLayout(bg, 10);
270
271 vbox->addSpacing( bg->fontMetrics().height() );
272
273 cb[0] = new QCheckBox( bg );
274 cb[0]->setText( "&Read" );
275 vbox->addWidget( cb[0] );
276 cb[1] = new QCheckBox( bg );
277 cb[1]->setText( "&Write" );
278 vbox->addWidget( cb[1] );
279 cb[2] = new QCheckBox( bg );
280 cb[2]->setText( "&Execute" );
281 vbox->addWidget( cb[2] );
282
283 connect( bg, SIGNAL(clicked(int)), SLOT(checkBoxClicked(int)) );
284
285 QToolTip::add( cb[0], "check box 1" );
286 QToolTip::add( cb[1], "check box 2" );
287 QToolTip::add( cb[2], "check box 3" );
288
289 // Create a group of radio buttons
290 QRadioButton *rb;
291 bg = new QButtonGroup( central, "radioGroup" );
292 bg->setTitle( "Radio buttons" );
293
294 grid->addWidget( bg, 1, 1 );
295
296 // Create a layout for the radio buttons
297 vbox = new QVBoxLayout(bg, 10);
298
299 vbox->addSpacing( bg->fontMetrics().height() );
300 rb = new QRadioButton( bg );
301 rb->setText( "&AM" );
302 rb->setChecked( TRUE );
303 vbox->addWidget(rb);
304 QToolTip::add( rb, "radio button 1" );
305 rb = new QRadioButton( bg );
306 rb->setText( "F&M" );
307 vbox->addWidget(rb);
308 QToolTip::add( rb, "radio button 2" );
309 rb = new QRadioButton( bg );
310 rb->setText( "&Short Wave" );
311 vbox->addWidget(rb);
312
313 connect( bg, SIGNAL(clicked(int)), SLOT(radioButtonClicked(int)) );
314 QToolTip::add( rb, "radio button 3" );
315
316 // Create a list box
317 QListBox *lb = new QListBox( central, "listBox" );
318 for ( int i=0; i<100; i++ ) { // fill list box
319 QString str;
320 str.sprintf( "line %d", i );
321 if ( i == 42 && pix )
322 lb->insertItem( pm );
323 else
324 lb->insertItem( str );
325 }
326 grid->addMultiCellWidget( lb, 2, 4, 0, 0 );
327 connect( lb, SIGNAL(selected(int)), SLOT(listBoxItemSelected(int)) );
328 QToolTip::add( lb, "list box" );
329 (void)new MyWhatsThis( lb );
330
331 vbox = new QVBoxLayout(8);
332 grid->addLayout( vbox, 2, 1 );
333
334 // Create a slider
335 QSlider *sb = new QSlider( 0, 300, 30, 100, QSlider::Horizontal,
336 central, "Slider" );
337 sb->setTickmarks( QSlider::Below );
338 sb->setTickInterval( 10 );
339 sb->setFocusPolicy( QWidget::TabFocus );
340 vbox->addWidget( sb );
341
342 connect( sb, SIGNAL(valueChanged(int)), SLOT(sliderValueChanged(int)) );
343 QToolTip::add( sb, "slider" );
344 QWhatsThis::add( sb, "This is a <b>QSlider</b>. "
345 "The tick marks are optional."
346 " This slider controls the speed of the movie." );
347 // Create a combo box
348 QComboBox *combo = new QComboBox( FALSE, central, "comboBox" );
349 combo->insertItem( "darkBlue" );
350 combo->insertItem( "darkRed" );
351 combo->insertItem( "darkGreen" );
352 combo->insertItem( "blue" );
353 combo->insertItem( "red" );
354 vbox->addWidget( combo );
355 connect( combo, SIGNAL(activated(int)),
356 this, SLOT(comboBoxItemActivated(int)) );
357 QToolTip::add( combo, "read-only combo box" );
358
359 // Create an editable combo box
360 QComboBox *edCombo = new QComboBox( TRUE, central, "edComboBox" );
361 QListBox *edComboLst = new QListBox(this);
362 edCombo->setListBox(edComboLst);
363 edComboLst->insertItem( "Permutable" );
364 edComboLst->insertItem( "Malleable" );
365 edComboLst->insertItem( "Adaptable" );
366 edComboLst->insertItem( "Alterable" );
367 edComboLst->insertItem( "Inconstant" );
368 vbox->addWidget( edCombo );
369 connect( edCombo, SIGNAL(activated(const QString&)),
370 this, SLOT(edComboBoxItemActivated(const QString&)) );
371 QToolTip::add( edCombo, "editable combo box" );
372
373 edCombo->setAutoCompletion( TRUE );
374
375 vbox = new QVBoxLayout(8);
376 grid->addLayout( vbox, 2, 2 );
377
378 // Create a spin box
379 QSpinBox *spin = new QSpinBox( 0, 10, 1, central, "spin" );
380 spin->setSuffix(" mm");
381 spin->setSpecialValueText( "Auto" );
382 connect( spin, SIGNAL( valueChanged(const QString&) ),
383 SLOT( spinBoxValueChanged(const QString&) ) );
384 QToolTip::add( spin, "spin box" );
385 QWhatsThis::add( spin, "This is a <b>QSpinBox</b>. "
386 "You can chose values in a given range "
387 "either by using the arrow buttons "
388 "or by typing them in." );
389 vbox->addWidget( spin );
390
391 vbox->addStretch( 1 );
392
393 // Create a tabwidget that switches between multi line edits
394 tabs = new QTabWidget( central );
395 //tabs->setTabPosition( QTabWidget::Bottom );
396 tabs->setMargin( 4 );
397 grid->addMultiCellWidget( tabs, 3, 3, 1, 2 );
398 QMultiLineEdit *mle = new QMultiLineEdit( tabs, "multiLineEdit" );
399 edit = mle;
400 mle->setWordWrap( QMultiLineEdit::WidgetWidth );
401 mle->setText("This is a QMultiLineEdit widget, "
402 "useful for small multi-line "
403 "input fields.");
404 QToolTip::add( mle, "multi line editor" );
405
406 tabs->addTab( mle, "F&irst");
407
408 mle = new QMultiLineEdit( tabs, "multiLineEdit" );
409 QString mleText = "This is another QMultiLineEdit widget.";
410#if 1
411 mleText += "\n";
412 mleText += "Japanese: ";
413 mleText += QChar((ushort)0x6a38); // Kanji
414 mleText += "\n";
415 mleText += "Russian: ";
416 mleText += QChar((ushort)0x042e); // Cyrillic
417 mleText += "\n";
418 mleText += "Norwegian: ";
419 mleText += QChar((ushort)0x00d8); // Norwegian
420 mleText += "\n";
421 mleText += "Unicode (black square): ";
422 mleText += QChar((ushort)0x25A0); // BLACK SQUARE
423 mleText += "\n";
424#endif
425 mle->setText( mleText );
426 QToolTip::add( mle, "second multi line editor" );
427 tabs->addTab( mle, "Se&cond");
428
429
430 // Create a single line edit
431 QLineEdit *le = new QLineEdit( central, "lineEdit" );
432
433
434 grid->addMultiCellWidget( le, 4, 4, 1, 2 );
435 connect( le, SIGNAL(textChanged(const QString&)),
436 SLOT(lineEditTextChanged(const QString&)) );
437 QToolTip::add( le, "single line editor" );
438 QWhatsThis::add( le, "This is a <b>QLineEdit</b>, you can enter a "
439 "single line of text in it. "
440 "It also it accepts text drops." );
441
442 grid->setRowStretch(0,0);
443 grid->setRowStretch(1,0);
444 grid->setRowStretch(2,0);
445 grid->setRowStretch(3,1);
446 grid->setRowStretch(4,0);
447
448 grid->setColStretch(0,1);
449 grid->setColStretch(1,1);
450 grid->setColStretch(2,1);
451
452
453 QSplitter *split = new QSplitter( Vertical, central, "splitter" );
454 split->setOpaqueResize( TRUE );
455 topLayout->addWidget( split, 1 );
456 QListView *lv = new MyListView( split );
457 connect(lv, SIGNAL(selectionChanged() ),
458 this, SLOT( selectionChanged() ) );
459 connect(lv, SIGNAL(selectionChanged(QListViewItem*) ),
460 this, SLOT( selectionChanged(QListViewItem*) ) );
461 connect(lv, SIGNAL(clicked(QListViewItem*) ),
462 this, SLOT( clicked(QListViewItem*) ) );
463 connect(lv, SIGNAL(mySelectionChanged(QListViewItem*) ),
464 this, SLOT( mySelectionChanged(QListViewItem*) ) );
465 lv->addColumn( "One" );
466 lv->addColumn( "Two" );
467 lv->setAllColumnsShowFocus( TRUE );
468
469 QListViewItem *lvi= new QListViewItem( lv, "Text", "Text" );
470 lvi= new QListViewItem( lv, "Text", "Other Text" );
471 lvi= new QListViewItem( lv, "Text", "More Text" );
472 lvi= new QListViewItem( lv, "Text", "Extra Text" );
473 lvi->setOpen(TRUE);
474 (void)new QListViewItem( lvi, "SubText", "Additional Text" );
475 lvi= new QListViewItem( lvi, "SubText", "Side Text" );
476 lvi= new QListViewItem( lvi, "SubSubText", "Complimentary Text" );
477
478 QToolTip::add( lv, "list view" );
479 QWhatsThis::add( lv, "This is a <b>QListView</b>, you can display lists "
480 "(or outline lists) of multiple-column data in it." );
481
482 lv = new QListView( split );
483 lv->addColumn( "Choices" );
484 (void) new QCheckListItem( lv, "Onion", QCheckListItem::CheckBox );
485 (void) new QCheckListItem( lv, "Artichoke", QCheckListItem::CheckBox );
486 (void) new QCheckListItem( lv, "Pepper", QCheckListItem::CheckBox );
487 (void) new QCheckListItem( lv, "Habaneros", QCheckListItem::CheckBox );
488 (void) new QCheckListItem( lv, "Pineapple", QCheckListItem::CheckBox );
489 (void) new QCheckListItem( lv, "Ham", QCheckListItem::CheckBox );
490 (void) new QCheckListItem( lv, "Pepperoni", QCheckListItem::CheckBox );
491 (void) new QCheckListItem( lv, "Garlic", QCheckListItem::CheckBox );
492
493
494 QCheckListItem *lit = new QCheckListItem( lv, "Cheese" );
495 lit->setOpen( TRUE );
496 (void) new QCheckListItem( lit, "Cheddar", QCheckListItem::RadioButton );
497 (void) new QCheckListItem( lit, "Mozarella", QCheckListItem::RadioButton );
498 (void) new QCheckListItem( lit, "Jarlsberg", QCheckListItem::RadioButton );
499
500 QToolTip::add( lv, "list view" );
501 QWhatsThis::add( lv, "This is also a <b>QListView</b>, with "
502 "interactive items." );
503
504 QTextBrowser *browser = new QTextBrowser( split );
505 browser->setText( "<h1>QTextBrowser</h1>"
506 "<p>Qt supports formatted rich text, such "
507 "as the heading above, <em>emphasized</em> and "
508 "<b>bold</b> text, via an XML subset.</p> "
509 "<p><a href=\"nogo://some.where.com\">Hypertext navigation</a> and style sheets are supported.</p>", "" );
510 browser->setFont(QFont("Charter",11));
511 browser->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
512 connect( browser, SIGNAL(linkClicked(const QString&)), browser, SLOT(setText(const QString&)) );
513
514 // Create an label and a message in the status bar
515 // The message is updated when buttons are clicked etc.
516 msg = new QLabel( statusBar(), "message" );
517 msg->setAlignment( AlignCenter );
518 QFont boldfont; boldfont.setWeight(QFont::Bold);
519 msg->setFont( boldfont );
520 statusBar()->addWidget( msg, 4 );
521 QToolTip::add( msg, "Message area" );
522
523 QAccel* a = new QAccel( this );
524 a->connectItem( a->insertItem( Key_F9 ),
525 this, SLOT( showProperties() ) );
526
527 prog = new QProgressBar( statusBar(), "progress" );
528 prog->setTotalSteps( 100 );
529 progress = 64;
530 prog->setProgress( progress );
531 statusBar()->addWidget( prog , 1 );
532 QWhatsThis::add( prog, "This is a <b>QProgressBar</b> "
533 "You can use it to show that a lengthy "
534 " process is progressing. "
535 "In this program, nothing much seems to happen." );
536 statusBar()->message( "Welcome to Qt", 2000 );
537}
538
539void WidgetView::setStatus(const QString& text)
540{
541 msg->setText(text);
542}
543
544void WidgetView::button1Clicked()
545{
546 msg->setText( "The push button was clicked" );
547 prog->setProgress( ++progress );
548}
549
550
551void WidgetView::movieUpdate( const QRect& )
552{
553 // Uncomment this to test animated icons on your window manager
554 //setIcon( movie.framePixmap() );
555}
556
557void WidgetView::movieStatus( int s )
558{
559 switch ( s ) {
560 case QMovie::SourceEmpty:
561 case QMovie::UnrecognizedFormat:
562 {
563 QPixmap pm("tt-logo.png");
564 movielabel->setPixmap(pm);
565 movielabel->setFixedSize(pm.size());
566 }
567 break;
568 default:
569 if ( movielabel->movie() ) // for flicker-free animation:
570 movielabel->setBackgroundMode( NoBackground );
571 }
572}
573
574
575void WidgetView::popupSelected( int selectedId )
576{
577 if ( selectedId == plainStyleID ) {
578 for ( int i = 0; i < int(textStylePopup->count()); i++ ) {
579 int id = textStylePopup->idAt( i );
580 textStylePopup->setItemChecked( id, FALSE);
581 }
582 } else {
583 textStylePopup->setItemChecked( selectedId, TRUE );
584 }
585}
586
587void WidgetView::checkBoxClicked( int id )
588{
589 QString str;
590 str = tr("Check box %1 clicked : ").arg(id);
591 QString chk = "---";
592 if ( cb[0]->isChecked() )
593 chk[0] = 'r';
594 if ( cb[1]->isChecked() )
595 chk[1] = 'w';
596 if ( cb[2]->isChecked() )
597 chk[2] = 'x';
598 str += chk;
599 msg->setText( str );
600}
601
602
603void WidgetView::edComboBoxItemActivated( const QString& text)
604{
605 QString str = tr("Editable Combo Box set to ");
606 str += text;
607 msg->setText( str );
608}
609
610
611void WidgetView::radioButtonClicked( int id )
612{
613 msg->setText( tr("Radio button #%1 clicked").arg(id) );
614}
615
616
617void WidgetView::listBoxItemSelected( int index )
618{
619 msg->setText( tr("List box item %1 selected").arg(index) );
620}
621
622
623void WidgetView::sliderValueChanged( int value )
624{
625 msg->setText( tr("Movie set to %1% of normal speed").arg(value) );
626 movie.setSpeed( value );
627}
628
629
630void WidgetView::comboBoxItemActivated( int index )
631{
632 msg->setText( tr("Combo box item %1 activated").arg(index) );
633 switch ( index ) {
634 default:
635 case 0:
636 QApplication::setWinStyleHighlightColor( darkBlue );
637 break;
638 case 1:
639 QApplication::setWinStyleHighlightColor( darkRed );
640 break;
641 case 2:
642 QApplication::setWinStyleHighlightColor( darkGreen );
643 break;
644 case 3:
645 QApplication::setWinStyleHighlightColor( blue );
646 break;
647 case 4:
648 QApplication::setWinStyleHighlightColor( red );
649 break;
650 }
651}
652
653
654
655void WidgetView::lineEditTextChanged( const QString& newText )
656{
657 QString str( "Line edit text: ");
658 str += newText;
659 if ( newText.length() == 1 ) {
660 QString u;
661 u.sprintf(" (U%02x%02x)", newText[0].row(), newText[0].cell() );
662 str += u;
663 }
664 msg->setText( str );
665}
666
667
668void WidgetView::spinBoxValueChanged( const QString& valueText )
669{
670 QString str( "Spin box value: " );
671 str += valueText;
672 msg->setText( str );
673}
674
675//
676// All application events are passed through this event filter.
677// We're using it to display some information about a clicked
678// widget (right mouse button + CTRL).
679//
680
681bool WidgetView::eventFilter( QObject *obj, QEvent *event )
682{
683 static bool identify_now = TRUE;
684 if ( event->type() == QEvent::MouseButtonPress && identify_now ) {
685 QMouseEvent *e = (QMouseEvent*)event;
686 if ( e->button() == QMouseEvent::RightButton &&
687 (e->state() & QMouseEvent::ControlButton) != 0 ){
688 QString str = "The clicked widget is a\n";
689 str += obj->className();
690 str += "\nThe widget's name is\n";
691 if ( obj->name() )
692 str += obj->name();
693 else
694 str += "<no name>";
695 identify_now = FALSE; // don't do it in message box
696 QMessageBox::information( (QWidget*)obj, "Identify Widget", str );
697 identify_now = TRUE; // allow it again
698 }
699 }
700 return QMainWindow::eventFilter( obj, event ); // don't eat event
701}
702
703
704void WidgetView::open()
705{
706 QFileDialog::getOpenFileName( QString::null, "Textfiles (*.txt)", this );
707}
708
709
710void WidgetView::dummy()
711{
712 QMessageBox::information( this, "Sorry",
713 "This function is not implemented" );
714}
715
716void WidgetView::selectionChanged()
717{
718 //qDebug("selectionChanged");
719}
720void WidgetView::selectionChanged( QListViewItem* /*item*/)
721{
722 //qDebug("selectionChanged %p", item );
723}
724
725void WidgetView::clicked( QListViewItem* /*item*/ )
726{
727 //qDebug("clicked %p", item );
728}
729
730void WidgetView::mySelectionChanged( QListViewItem* /*item*/ )
731{
732 //qDebug("mySelectionChanged %p", item );
733}
734
735void WidgetView::showProperties()
736{
737 if ( !qApp->focusWidget() )
738 return;
739 QCString output;
740 output.sprintf( "Properties for class '%s'",
741 qApp->focusWidget()->className() );
742 int i = 0;
743 while( i < (int) qApp->focusWidget()->metaObject()->numProperties( TRUE ) ) {
744 const QMetaProperty* p
745 = qApp->focusWidget()->metaObject()->property( i, TRUE );
746 QCString tmp;
747 tmp.sprintf( "\n %2d: %s (read-%s, %s)", ++i, p->name(),
748 p->writable() ? "write" : "only", p->type() );
749 output += tmp;
750 }
751 qDebug( output );
752}
Note: See TracBrowser for help on using the repository browser.