home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / widgets / widgets.cpp < prev    next >
C/C++ Source or Header  |  2001-10-11  |  23KB  |  751 lines

  1. /****************************************************************************
  2. ** $Id:  qt/widgets.cpp   3.0.0   edited Aug 3 13:20 $
  3. **
  4. ** Copyright (C) 1992-2000 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 <qtextview.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.  
  69. class MyWhatsThis : public QWhatsThis
  70. {
  71. public:
  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.  
  87. private:
  88.     QListBox* listbox;
  89. };
  90.  
  91.  
  92. class MyMenuItem : public QCustomMenuItem
  93. {
  94. public:
  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.     }
  113. private:
  114.     QString string;
  115.     QFont font;
  116. };
  117.  
  118. //
  119. // Construct the WidgetView with children
  120. //
  121.  
  122. WidgetView::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.  
  188.     textStylePopup = popup = new QPopupMenu( this );
  189.     menuBar()->insertItem( "&Edit", popup );
  190.  
  191.     plainStyleID = id = popup->insertItem( "&Plain" );
  192.     popup->setAccel( CTRL+Key_T, id );
  193.  
  194.     popup->insertSeparator();
  195.     QFont f = font();
  196.     f.setBold( TRUE );
  197.     id = popup->insertItem( new MyMenuItem( "&Bold", f ) );
  198.     popup->setAccel( CTRL+Key_B, id );
  199.     f = font();
  200.     f.setItalic( TRUE );
  201.     id = popup->insertItem( new MyMenuItem( "&Italic", f ) );
  202.     popup->setItemChecked( id, TRUE );
  203.     popup->setAccel( CTRL+Key_I, id );
  204.     f = font();
  205.     f.setUnderline( TRUE );
  206.     id = popup->insertItem( new MyMenuItem( "&Underline", f ) );
  207.     popup->setAccel( CTRL+Key_U, id );
  208.     f = font();
  209.     f.setStrikeOut( TRUE );
  210.     id = popup->insertItem( new MyMenuItem( "&Strike", f ) );
  211.     connect( textStylePopup, SIGNAL(activated(int)),
  212.          this, SLOT(popupSelected(int)) );
  213.  
  214.     // Create an analog and a digital clock
  215.     AnalogClock  *aclock = new AnalogClock( central );
  216.     aclock->setAutoMask( TRUE );
  217.     DigitalClock *dclock = new DigitalClock( central );
  218.     dclock->setMaximumWidth(200);
  219.     grid->addWidget( aclock, 0, 2 );
  220.     grid->addWidget( dclock, 1, 2 );
  221.  
  222.     // Give the dclock widget a blue palette
  223.     col.setRgb( 0xaa, 0xbe, 0xff );
  224.     dclock->setPalette( QPalette( col ) );
  225.  
  226.     // make tool tips for both of them
  227.     QToolTip::add( aclock, "custom widget: analog clock" );
  228.     QToolTip::add( dclock, "custom widget: digital clock" );
  229.  
  230.     // Create a push button.
  231.     QPushButton *pb;
  232.     pb = new QPushButton( "&Push button 1", central, "button1" );
  233.     grid->addWidget( pb, 0, 0, AlignVCenter );
  234.     connect( pb, SIGNAL(clicked()), SLOT(button1Clicked()) );
  235.     QToolTip::add( pb, "push button 1" );
  236.     QWhatsThis::add( pb, "This is a <b>QPushButton</b>.<br>"
  237.              "Click it and watch...<br>"
  238.              "The wonders of modern technology.");
  239.  
  240.     QPixmap pm;
  241.     bool pix = pm.load("qt.png");
  242.     if ( !pix ) {
  243.     QMessageBox::information( 0, "Qt Widgets Example",
  244.                   "Could not load the file \"qt.png\", which\n"
  245.                   "contains an icon used...\n\n"
  246.                   "The text \"line 42\" will be substituted.",
  247.                   QMessageBox::Ok + QMessageBox::Default );
  248.     }
  249.  
  250.     // Create a label containing a QMovie
  251.     movie = QMovie( MOVIEFILENAME );
  252.     movielabel = new QLabel( central, "label0" );
  253.     movie.connectStatus(this, SLOT(movieStatus(int)));
  254.     movie.connectUpdate(this, SLOT(movieUpdate(const QRect&)));
  255.     movielabel->setFrameStyle( QFrame::Box | QFrame::Plain );
  256.     movielabel->setMovie( movie );
  257.     movielabel->setFixedSize( 128+movielabel->frameWidth()*2,
  258.                   64+movielabel->frameWidth()*2 );
  259.     grid->addWidget( movielabel, 0, 1, AlignCenter );
  260.     QToolTip::add( movielabel, "movie" );
  261.     QWhatsThis::add( movielabel, "This is a <b>QLabel</b> "
  262.              "that contains a QMovie." );
  263.  
  264.     // Create a group of check boxes
  265.     bg = new QButtonGroup( central, "checkGroup" );
  266.     bg->setTitle( "Check Boxes" );
  267.     grid->addWidget( bg, 1, 0 );
  268.  
  269.     // Create a layout for the check boxes
  270.     QVBoxLayout *vbox = new QVBoxLayout(bg, 10);
  271.  
  272.     vbox->addSpacing( bg->fontMetrics().height() );
  273.  
  274.     cb[0] = new QCheckBox( bg );
  275.     cb[0]->setText( "&Read" );
  276.     vbox->addWidget( cb[0] );
  277.     cb[1] = new QCheckBox( bg );
  278.     cb[1]->setText( "&Write" );
  279.     vbox->addWidget( cb[1] );
  280.     cb[2] = new QCheckBox( bg );
  281.     cb[2]->setText( "&Execute" );
  282.     vbox->addWidget( cb[2] );
  283.  
  284.     connect( bg, SIGNAL(clicked(int)), SLOT(checkBoxClicked(int)) );
  285.  
  286.     QToolTip::add( cb[0], "check box 1" );
  287.     QToolTip::add( cb[1], "check box 2" );
  288.     QToolTip::add( cb[2], "check box 3" );
  289.  
  290.     // Create a group of radio buttons
  291.     QRadioButton *rb;
  292.     bg = new QButtonGroup( central, "radioGroup" );
  293.     bg->setTitle( "Radio buttons" );
  294.  
  295.     grid->addWidget( bg, 1, 1 );
  296.  
  297.     // Create a layout for the radio buttons
  298.     vbox = new QVBoxLayout(bg, 10);
  299.  
  300.     vbox->addSpacing( bg->fontMetrics().height() );
  301.     rb = new QRadioButton( bg );
  302.     rb->setText( "&AM" );
  303.     rb->setChecked( TRUE );
  304.     vbox->addWidget(rb);
  305.     QToolTip::add( rb, "radio button 1" );
  306.     rb = new QRadioButton( bg );
  307.     rb->setText( "F&M" );
  308.     vbox->addWidget(rb);
  309.     QToolTip::add( rb, "radio button 2" );
  310.     rb = new QRadioButton( bg );
  311.     rb->setText( "&Short Wave" );
  312.     vbox->addWidget(rb);
  313.  
  314.     connect( bg, SIGNAL(clicked(int)), SLOT(radioButtonClicked(int)) );
  315.     QToolTip::add( rb, "radio button 3" );
  316.  
  317.     // Create a list box
  318.     QListBox *lb = new QListBox( central, "listBox" );
  319.     for ( int i=0; i<100; i++ ) {        // fill list box
  320.     QString str;
  321.     str.sprintf( "line %d", i );
  322.     if ( i == 42 && pix )
  323.         lb->insertItem( pm );
  324.     else
  325.         lb->insertItem( str );
  326.     }
  327.     grid->addMultiCellWidget( lb, 2, 4, 0, 0 );
  328.     connect( lb, SIGNAL(selected(int)), SLOT(listBoxItemSelected(int)) );
  329.     QToolTip::add( lb, "list box" );
  330.     (void)new MyWhatsThis( lb );
  331.  
  332.     vbox = new QVBoxLayout(8);
  333.     grid->addLayout( vbox, 2, 1 );
  334.  
  335.     // Create a slider
  336.     QSlider *sb = new QSlider( 0, 300, 30, 100, QSlider::Horizontal,
  337.                    central, "Slider" );
  338.     sb->setTickmarks( QSlider::Below );
  339.     sb->setTickInterval( 10 );
  340.     sb->setFocusPolicy( QWidget::TabFocus );
  341.     vbox->addWidget( sb );
  342.  
  343.     connect( sb, SIGNAL(valueChanged(int)), SLOT(sliderValueChanged(int)) );
  344.     QToolTip::add( sb, "slider" );
  345.     QWhatsThis::add( sb, "This is a <b>QSlider</b>. "
  346.              "The tick marks are optional."
  347.              " This slider controls the speed of the movie." );
  348.     // Create a combo box
  349.     QComboBox *combo = new QComboBox( FALSE, central, "comboBox" );
  350.     combo->insertItem( "darkBlue" );
  351.     combo->insertItem( "darkRed" );
  352.     combo->insertItem( "darkGreen" );
  353.     combo->insertItem( "blue" );
  354.     combo->insertItem( "red" );
  355.     vbox->addWidget( combo );
  356.     connect( combo, SIGNAL(activated(int)),
  357.          this, SLOT(comboBoxItemActivated(int)) );
  358.     QToolTip::add( combo, "read-only combo box" );
  359.  
  360.     // Create an editable combo box
  361.     QComboBox *edCombo = new QComboBox( TRUE, central, "edComboBox" );
  362.     edCombo->insertItem( "Permutable" );
  363.     edCombo->insertItem( "Malleable" );
  364.     edCombo->insertItem( "Adaptable" );
  365.     edCombo->insertItem( "Alterable" );
  366.     edCombo->insertItem( "Inconstant" );
  367.     vbox->addWidget( edCombo );
  368.     connect( edCombo, SIGNAL(activated(const QString&)),
  369.          this, SLOT(edComboBoxItemActivated(const QString&)) );
  370.     QToolTip::add( edCombo, "editable combo box" );
  371.  
  372.     edCombo->setAutoCompletion( TRUE );
  373.  
  374.     vbox = new QVBoxLayout(8);
  375.     grid->addLayout( vbox, 2, 2 );
  376.  
  377.     // Create a spin box
  378.     QSpinBox *spin = new QSpinBox( 0, 10, 1, central, "spin" );
  379.     spin->setSuffix(" mm");
  380.     spin->setSpecialValueText( "Auto" );
  381.     connect( spin, SIGNAL( valueChanged(const QString&) ),
  382.          SLOT( spinBoxValueChanged(const QString&) ) );
  383.     QToolTip::add( spin, "spin box" );
  384.     QWhatsThis::add( spin, "This is a <b>QSpinBox</b>. "
  385.              "You can chose values in a given range "
  386.              "either by using the arrow buttons "
  387.              "or by typing them in." );
  388.     vbox->addWidget( spin );
  389.  
  390.     vbox->addStretch( 1 );
  391.  
  392.     // Create a tabwidget that switches between multi line edits
  393.     tabs = new QTabWidget( central );
  394.     //tabs->setTabPosition( QTabWidget::Bottom );
  395.     tabs->setMargin( 4 );
  396.     grid->addMultiCellWidget( tabs, 3, 3, 1, 2 );
  397.     QMultiLineEdit *mle = new QMultiLineEdit( tabs, "multiLineEdit" );
  398.     edit = mle;
  399.     mle->setWordWrap( QMultiLineEdit::WidgetWidth );
  400.     mle->setText("This is a QMultiLineEdit widget, "
  401.              "useful for small multi-line "
  402.          "input fields.");
  403.     QToolTip::add( mle, "multi line editor" );
  404.  
  405.     tabs->addTab( mle, "F&irst");
  406.  
  407.     mle = new QMultiLineEdit( tabs, "multiLineEdit" );
  408.     QString mleText = "This is another QMultiLineEdit widget.";
  409. #if 1
  410.     mleText += "\n";
  411.     mleText += "Japanese: ";
  412.     mleText += QChar((ushort)0x6a38); // Kanji
  413.     mleText += "\n";
  414.     mleText += "Russian:";
  415.     mleText += QChar((ushort)0x042e); // Cyrillic
  416.     mleText += "\n";
  417.     mleText += "Norwegian:";
  418.     mleText += QChar((ushort)0x00d8); // Norwegian
  419.     mleText += "\n";
  420.     mleText += "Unicode (black square):";
  421.     mleText += QChar((ushort)0x25A0); // BLACK SQUARE
  422.     mleText += "\n";
  423. #endif
  424.     mle->setText( mleText );
  425.     QToolTip::add( mle, "second multi line editor" );
  426.     tabs->addTab( mle, "Se&cond");
  427.  
  428.  
  429.     // Create a single line edit
  430.     QLineEdit *le = new QLineEdit( central, "lineEdit" );
  431.  
  432.  
  433.     grid->addMultiCellWidget( le, 4, 4, 1, 2 );
  434.     connect( le, SIGNAL(textChanged(const QString&)),
  435.          SLOT(lineEditTextChanged(const QString&)) );
  436.     QToolTip::add( le, "single line editor" );
  437.     QWhatsThis::add( le, "This is a <b>QLineEdit</b>, you can enter a "
  438.              "single line of text in it. "
  439.               "It also it accepts text drops." );
  440.  
  441.     grid->setRowStretch(0,0);
  442.     grid->setRowStretch(1,0);
  443.     grid->setRowStretch(2,0);
  444.     grid->setRowStretch(3,1);
  445.     grid->setRowStretch(4,0);
  446.  
  447.     grid->setColStretch(0,1);
  448.     grid->setColStretch(1,1);
  449.     grid->setColStretch(2,1);
  450.  
  451.  
  452.     QSplitter *split = new QSplitter( Vertical, central, "splitter" );
  453.     split->setOpaqueResize( TRUE );
  454.     topLayout->addWidget( split, 1 );
  455.     QListView *lv = new MyListView( split );
  456.     connect(lv, SIGNAL(selectionChanged() ),
  457.         this, SLOT( selectionChanged() ) );
  458.     connect(lv, SIGNAL(selectionChanged(QListViewItem*) ),
  459.         this, SLOT( selectionChanged(QListViewItem*) ) );
  460.     connect(lv, SIGNAL(clicked(QListViewItem*) ),
  461.         this, SLOT( clicked(QListViewItem*) ) );
  462.     connect(lv, SIGNAL(mySelectionChanged(QListViewItem*) ),
  463.         this, SLOT( mySelectionChanged(QListViewItem*) ) );
  464.     lv->addColumn( "One" );
  465.     lv->addColumn( "Two" );
  466.     lv->setAllColumnsShowFocus( TRUE );
  467.  
  468.     QListViewItem *lvi=  new QListViewItem( lv, "Text", "Text" );
  469.     lvi=  new QListViewItem( lv, "Text", "Other Text" );
  470.     lvi=  new QListViewItem( lv, "Text", "More Text" );
  471.     lvi=  new QListViewItem( lv, "Text", "Extra Text" );
  472.     lvi->setOpen(TRUE);
  473.     (void)new QListViewItem( lvi, "SubText", "Additional Text" );
  474.     lvi=  new QListViewItem( lvi, "SubText", "Side Text" );
  475.     lvi=  new QListViewItem( lvi, "SubSubText", "Complimentary Text" );
  476.  
  477.     QToolTip::add( lv, "list view" );
  478.     QWhatsThis::add( lv, "This is a <b>QListView</b>, you can display lists "
  479.              "(or outline lists) of multiple-column data in it." );
  480.  
  481.     lv = new QListView( split );
  482.     lv->addColumn( "Choices" );
  483.     (void) new QCheckListItem( lv, "Onion", QCheckListItem::CheckBox );
  484.     (void) new QCheckListItem( lv, "Artichoke", QCheckListItem::CheckBox );
  485.     (void) new QCheckListItem( lv, "Pepper", QCheckListItem::CheckBox );
  486.     (void) new QCheckListItem( lv, "Habaneros", QCheckListItem::CheckBox );
  487.     (void) new QCheckListItem( lv, "Pineapple", QCheckListItem::CheckBox );
  488.     (void) new QCheckListItem( lv, "Ham", QCheckListItem::CheckBox );
  489.     (void) new QCheckListItem( lv, "Pepperoni", QCheckListItem::CheckBox );
  490.     (void) new QCheckListItem( lv, "Garlic", QCheckListItem::CheckBox );
  491.  
  492.  
  493.     QCheckListItem *lit = new QCheckListItem( lv, "Cheese" );
  494.     lit->setOpen( TRUE );
  495.     (void) new QCheckListItem( lit, "Cheddar", QCheckListItem::RadioButton );
  496.     (void) new QCheckListItem( lit, "Mozarella", QCheckListItem::RadioButton );
  497.     (void) new QCheckListItem( lit, "Jarlsberg", QCheckListItem::RadioButton );
  498.  
  499.     QToolTip::add( lv, "list view" );
  500.     QWhatsThis::add( lv, "This is also a <b>QListView</b>, with "
  501.              "interactive items." );
  502.  
  503.      QTextView *qmlv =  new QTextView( "<hr><h1>QTextView</h1>"
  504.               "<p>Qt supports formatted rich text, such "
  505.               "as the heading above, <em>emphasized</em> and "
  506.               "<b>bold</b> text, via an XML subset.</p> "
  507.               "<p>Style sheets are supported.</p>",
  508.                    "", split );
  509.     qmlv->setFont(QFont("Charter",11));
  510.     qmlv->setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
  511.  
  512.     // Create an label and a message in the status bar
  513.     // The message is updated when buttons are clicked etc.
  514.     msg = new QLabel( statusBar(), "message" );
  515.     msg->setAlignment( AlignCenter );
  516.     QFont boldfont; boldfont.setWeight(QFont::Bold);
  517.     msg->setFont( boldfont );
  518.     statusBar()->addWidget( msg, 4 );
  519.     QToolTip::add( msg, "Message area" );
  520.  
  521.     QAccel* a = new QAccel( this );
  522.     a->connectItem(  a->insertItem( Key_F9 ),
  523.              this, SLOT( showProperties() ) );
  524.  
  525.     prog = new QProgressBar( statusBar(), "progress" );
  526.     prog->setTotalSteps( 100 );
  527.     progress = 64;
  528.     prog->setProgress( progress );
  529.     statusBar()->addWidget( prog , 1 );
  530.     QWhatsThis::add( prog, "This is a <b>QProgressBar</b> "
  531.              "You can use it to show that a lengthy "
  532.              " process is progressing. "
  533.              "In this program, nothing much seems to happen." );
  534.     statusBar()->message( "Welcome to Qt", 2000 );
  535. }
  536.  
  537. void WidgetView::setStatus(const QString& text)
  538. {
  539.     msg->setText(text);
  540. }
  541.  
  542. void WidgetView::button1Clicked()
  543. {
  544.     msg->setText( "The push button was clicked" );
  545.     prog->setProgress( ++progress );
  546. }
  547.  
  548.  
  549. void WidgetView::movieUpdate( const QRect& )
  550. {
  551.     // Uncomment this to test animated icons on your window manager
  552.     //setIcon( movie.framePixmap() );
  553. }
  554.  
  555. void WidgetView::movieStatus( int s )
  556. {
  557.     switch ( s ) {
  558.       case QMovie::SourceEmpty:
  559.       case QMovie::UnrecognizedFormat:
  560.     {
  561.         QPixmap pm("tt-logo.png");
  562.         movielabel->setPixmap(pm);
  563.         movielabel->setFixedSize(pm.size());
  564.     }
  565.       break;
  566.       default:
  567.     if ( movielabel->movie() )         // for flicker-free animation:
  568.         movielabel->setBackgroundMode( NoBackground );
  569.     }
  570. }
  571.  
  572.  
  573. void WidgetView::popupSelected( int selectedId )
  574. {
  575.     if ( selectedId == plainStyleID ) {
  576.     for ( int i = 0; i < int(textStylePopup->count()); i++ ) {
  577.         int id = textStylePopup->idAt( i );
  578.         textStylePopup->setItemChecked( id, FALSE);
  579.     }
  580.     } else {
  581.     textStylePopup->setItemChecked( selectedId, TRUE );
  582.     }
  583. }
  584.  
  585. void WidgetView::checkBoxClicked( int id )
  586. {
  587.     QString str;
  588.     str = tr("Check box %1 clicked : ").arg(id);
  589.     QString chk = "---";
  590.     if ( cb[0]->isChecked() )
  591.     chk[0] = 'r';
  592.     if ( cb[1]->isChecked() )
  593.     chk[1] = 'w';
  594.     if ( cb[2]->isChecked() )
  595.     chk[2] = 'x';
  596.     str += chk;
  597.     msg->setText( str );
  598. }
  599.  
  600.  
  601. void WidgetView::edComboBoxItemActivated( const QString& text)
  602. {
  603.     QString str = tr("Editable Combo Box set to ");
  604.     str += text;
  605.     msg->setText( str );
  606. }
  607.  
  608.  
  609. void WidgetView::radioButtonClicked( int id )
  610. {
  611.     msg->setText( tr("Radio button #%1 clicked").arg(id) );
  612. }
  613.  
  614.  
  615. void WidgetView::listBoxItemSelected( int index )
  616. {
  617.     msg->setText( tr("List box item %1 selected").arg(index) );
  618. }
  619.  
  620.  
  621. void WidgetView::sliderValueChanged( int value )
  622. {
  623.     msg->setText( tr("Movie set to %1% of normal speed").arg(value) );
  624.     movie.setSpeed( value );
  625. }
  626.  
  627.  
  628. void WidgetView::comboBoxItemActivated( int index )
  629. {
  630.     msg->setText( tr("Combo box item %1 activated").arg(index) );
  631.     switch ( index ) {
  632.     default:
  633.     case 0:
  634.     QApplication::setWinStyleHighlightColor( darkBlue );
  635.     break;
  636.     case 1:
  637.     QApplication::setWinStyleHighlightColor( darkRed );
  638.     break;
  639.     case 2:
  640.     QApplication::setWinStyleHighlightColor( darkGreen );
  641.     break;
  642.     case 3:
  643.     QApplication::setWinStyleHighlightColor( blue );
  644.     break;
  645.     case 4:
  646.     QApplication::setWinStyleHighlightColor( red );
  647.     break;
  648.     }
  649. }
  650.  
  651.  
  652.  
  653. void WidgetView::lineEditTextChanged( const QString& newText )
  654. {
  655.     QString str( "Line edit text: ");
  656.     str += newText;
  657.     if ( newText.length() == 1 ) {
  658.     QString u;
  659.     u.sprintf(" (U%02x%02x)", newText[0].row(), newText[0].cell() );
  660.     str += u;
  661.     }
  662.     msg->setText( str );
  663. }
  664.  
  665.  
  666. void WidgetView::spinBoxValueChanged( const QString& valueText )
  667. {
  668.     QString str( "Spin box value: " );
  669.     str += valueText;
  670.     msg->setText( str );
  671. }
  672.  
  673. //
  674. // All application events are passed through this event filter.
  675. // We're using it to display some information about a clicked
  676. // widget (right mouse button + CTRL).
  677. //
  678.  
  679. bool WidgetView::eventFilter( QObject *obj, QEvent *event )
  680. {
  681.     static bool identify_now = TRUE;
  682.     if ( event->type() == QEvent::MouseButtonPress && identify_now ) {
  683.     QMouseEvent *e = (QMouseEvent*)event;
  684.     if ( e->button() == QMouseEvent::RightButton &&
  685.          (e->state() & QMouseEvent::ControlButton) != 0 ){
  686.         QString str = "The clicked widget is a\n";
  687.         str += obj->className();
  688.         str += "\nThe widget's name is\n";
  689.         if ( obj->name() )
  690.         str += obj->name();
  691.         else
  692.         str += "<no name>";
  693.         identify_now = FALSE;        // don't do it in message box
  694.         QMessageBox::information( (QWidget*)obj, "Identify Widget", str );
  695.         identify_now = TRUE;        // allow it again
  696.     }
  697.     }
  698.     return QMainWindow::eventFilter( obj, event ); // don't eat event
  699. }
  700.  
  701.  
  702. void WidgetView::open()
  703. {
  704.     QFileDialog::getOpenFileName( QString::null, "Textfiles (*.txt)", this );
  705. }
  706.  
  707.  
  708. void WidgetView::dummy()
  709. {
  710.     QMessageBox::information( this, "Sorry",
  711.                   "This function is not implemented" );
  712. }
  713.  
  714. void WidgetView::selectionChanged()
  715. {
  716.     //qDebug("selectionChanged");
  717. }
  718. void WidgetView::selectionChanged( QListViewItem* /*item*/)
  719. {
  720.     //qDebug("selectionChanged %p", item );
  721. }
  722.  
  723. void WidgetView::clicked( QListViewItem* /*item*/ )
  724. {
  725.     //qDebug("clicked %p", item );
  726. }
  727.  
  728. void WidgetView::mySelectionChanged( QListViewItem* /*item*/ )
  729. {
  730.     //qDebug("mySelectionChanged %p", item );
  731. }
  732.  
  733. void WidgetView::showProperties()
  734. {
  735.     if ( !qApp->focusWidget() )
  736.     return;
  737.     QCString output;
  738.     output.sprintf( "Properties for class '%s'",
  739.             qApp->focusWidget()->className() );
  740.     int i = 0;
  741.     while( i < (int) qApp->focusWidget()->metaObject()->numProperties( TRUE ) ) {
  742.     const QMetaProperty* p
  743.         = qApp->focusWidget()->metaObject()->property( i, TRUE );
  744.     QCString tmp;
  745.     tmp.sprintf( "\n %2d: %s (read-%s, %s)", ++i, p->name(),
  746.              p->writable() ? "write" : "only", p->type() );
  747.     output += tmp;
  748.     }
  749.     qDebug( output );
  750. }
  751.