diff options
Diffstat (limited to 'examples/listboxcombo')
-rw-r--r-- | examples/listboxcombo/fileopen.xpm | 22 | ||||
-rw-r--r-- | examples/listboxcombo/listboxcombo.cpp | 187 | ||||
-rw-r--r-- | examples/listboxcombo/listboxcombo.doc | 29 | ||||
-rw-r--r-- | examples/listboxcombo/listboxcombo.h | 36 | ||||
-rw-r--r-- | examples/listboxcombo/listboxcombo.pro | 10 | ||||
-rw-r--r-- | examples/listboxcombo/main.cpp | 24 | ||||
-rw-r--r-- | examples/listboxcombo/qtlogo.png | bin | 0 -> 12615 bytes |
7 files changed, 308 insertions, 0 deletions
diff --git a/examples/listboxcombo/fileopen.xpm b/examples/listboxcombo/fileopen.xpm new file mode 100644 index 000000000..880417eee --- /dev/null +++ b/examples/listboxcombo/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/examples/listboxcombo/listboxcombo.cpp b/examples/listboxcombo/listboxcombo.cpp new file mode 100644 index 000000000..ceb06995b --- /dev/null +++ b/examples/listboxcombo/listboxcombo.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "listboxcombo.h" + +#include <qcombobox.h> +#include <qlistbox.h> +#include <qhbox.h> +#include <qpushbutton.h> +#include <qstring.h> +#include <qpixmap.h> +#include <qlabel.h> +#include <qimage.h> +#include <qpainter.h> +#include <qstyle.h> + + +class MyListBoxItem : public TQListBoxItem +{ +public: + MyListBoxItem() + : TQListBoxItem() + { + setCustomHighlighting( TRUE ); + } + +protected: + virtual void paint( TQPainter * ); + virtual int width( const TQListBox* ) const { return 100; } + virtual int height( const TQListBox* ) const { return 16; } + +}; + +void MyListBoxItem::paint( TQPainter *painter ) +{ + // evil trick: find out whether we are painted onto our listbox + bool in_list_box = listBox() && listBox()->viewport() == painter->device(); + + TQRect r ( 0, 0, width( listBox() ), height( listBox() ) ); + if ( in_list_box && isSelected() ) + painter->eraseRect( r ); + painter->fillRect( 5, 5, width( listBox() ) - 10, height( listBox() ) - 10, TQt::red ); + if ( in_list_box && isCurrent() ) + listBox()->style().drawPrimitive( TQStyle::PE_FocusRect, painter, r, listBox()->colorGroup() ); +} + +/* + * Constructor + * + * Creates child widgets of the ListBoxCombo widget + */ + +ListBoxCombo::ListBoxCombo( TQWidget *parent, const char *name ) + : TQVBox( parent, name ) +{ + setMargin( 5 ); + setSpacing( 5 ); + + unsigned int i; + TQString str; + + TQHBox *row1 = new TQHBox( this ); + row1->setSpacing( 5 ); + + // Create a multi-selection ListBox... + lb1 = new TQListBox( row1 ); + lb1->setSelectionMode( TQListBox::Multi ); + + // ...insert a pixmap item... + lb1->insertItem( TQPixmap( "qtlogo.png" ) ); + // ...and 100 text items + for ( i = 0; i < 100; i++ ) { + str = TQString( "Listbox Item %1" ).arg( i ); + if ( !( i % 4 ) ) + lb1->insertItem( TQPixmap( "fileopen.xpm" ), str ); + else + lb1->insertItem( str ); + } + + // Create a pushbutton... + TQPushButton *arrow1 = new TQPushButton( " -> ", row1 ); + // ...and connect the clicked SIGNAL with the SLOT slotLeft2Right + connect( arrow1, SIGNAL( clicked() ), this, SLOT( slotLeft2Right() ) ); + + // create an empty single-selection ListBox + lb2 = new TQListBox( row1 ); + + TQHBox *row2 = new TQHBox( this ); + row2->setSpacing( 5 ); + + TQVBox *box1 = new TQVBox( row2 ); + box1->setSpacing( 5 ); + + // Create a non-editable Combobox and a label below... + TQComboBox *cb1 = new TQComboBox( FALSE, box1 ); + label1 = new TQLabel( "Current Item: Combobox Item 0", box1 ); + label1->setMaximumHeight( label1->sizeHint().height() * 2 ); + label1->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + + //...and insert 50 items into the Combobox + for ( i = 0; i < 50; i++ ) { + str = TQString( "Combobox Item %1" ).arg( i ); + if ( i % 9 ) + cb1->insertItem( str ); + else + cb1->listBox()->insertItem( new MyListBoxItem ); + } + + TQVBox *box2 = new TQVBox( row2 ); + box2->setSpacing( 5 ); + + // Create an editable Combobox and a label below... + TQComboBox *cb2 = new TQComboBox( TRUE, box2 ); + label2 = new TQLabel( "Current Item: Combobox Item 0", box2 ); + label2->setMaximumHeight( label2->sizeHint().height() * 2 ); + label2->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + + // ... and insert 50 items into the Combobox + for ( i = 0; i < 50; i++ ) { + str = TQString( "Combobox Item %1" ).arg( i ); + if ( !( i % 4 ) ) + cb2->insertItem( TQPixmap( "fileopen.xpm" ), str ); + else + cb2->insertItem( str ); + } + + // Connect the activated SIGNALs of the Comboboxes with SLOTs + connect( cb1, SIGNAL( activated( const TQString & ) ), this, SLOT( slotCombo1Activated( const TQString & ) ) ); + connect( cb2, SIGNAL( activated( const TQString & ) ), this, SLOT( slotCombo2Activated( const TQString & ) ) ); +} + +/* + * SLOT slotLeft2Right + * + * Copies all selected items of the first ListBox into the + * second ListBox + */ + +void ListBoxCombo::slotLeft2Right() +{ + // Go through all items of the first ListBox + for ( unsigned int i = 0; i < lb1->count(); i++ ) { + TQListBoxItem *item = lb1->item( i ); + // if the item is selected... + if ( item->isSelected() ) { + // ...and it is a text item... + if ( item->pixmap() && !item->text().isEmpty() ) + lb2->insertItem( *item->pixmap(), item->text() ); + else if ( !item->pixmap() ) + lb2->insertItem( item->text() ); + else if ( item->text().isEmpty() ) + lb2->insertItem( *item->pixmap() ); + } + } +} + +/* + * SLOT slotCombo1Activated( const TQString &s ) + * + * Sets the text of the item which the user just selected + * in the first Combobox (and is now the value of s) to + * the first Label. + */ + +void ListBoxCombo::slotCombo1Activated( const TQString &s ) +{ + label1->setText( TQString( "Current Item: %1" ).arg( s ) ); +} + +/* + * SLOT slotCombo2Activated( const TQString &s ) + * + * Sets the text of the item which the user just selected + * in the second Combobox (and is now the value of s) to + * the second Label. + */ + +void ListBoxCombo::slotCombo2Activated( const TQString &s ) +{ + label2->setText( TQString( "Current Item: %1" ).arg( s ) ); +} diff --git a/examples/listboxcombo/listboxcombo.doc b/examples/listboxcombo/listboxcombo.doc new file mode 100644 index 000000000..f2d768ad7 --- /dev/null +++ b/examples/listboxcombo/listboxcombo.doc @@ -0,0 +1,29 @@ +/* +*/ +/*! \page listboxcombo-example.html + + \ingroup examples + \title Listboxes and Comboboxes + + This example program demonstrates how to use listboxes (with single selection + and multi selection) and comboboxes (editable and non-editable). + + <hr> + + Header file: + + \include listboxcombo/listboxcombo.h + + <hr> + + Implementation: + + \include listboxcombo/listboxcombo.cpp + + <hr> + + Main: + + \include listboxcombo/main.cpp +*/ + diff --git a/examples/listboxcombo/listboxcombo.h b/examples/listboxcombo/listboxcombo.h new file mode 100644 index 000000000..b614fbd2a --- /dev/null +++ b/examples/listboxcombo/listboxcombo.h @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef LISTBOX_COMBO_H +#define LISTBOX_COMBO_H + +#include <qvbox.h> + +class TQListBox; +class TQLabel; + +class ListBoxCombo : public TQVBox +{ + Q_OBJECT + +public: + ListBoxCombo( TQWidget *parent = 0, const char *name = 0 ); + +protected: + TQListBox *lb1, *lb2; + TQLabel *label1, *label2; + +protected slots: + void slotLeft2Right(); + void slotCombo1Activated( const TQString &s ); + void slotCombo2Activated( const TQString &s ); + +}; + +#endif diff --git a/examples/listboxcombo/listboxcombo.pro b/examples/listboxcombo/listboxcombo.pro new file mode 100644 index 000000000..a75e30864 --- /dev/null +++ b/examples/listboxcombo/listboxcombo.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = listboxcombo + +CONFIG += qt warn_on release + +REQUIRES = large-config + +HEADERS = listboxcombo.h +SOURCES = listboxcombo.cpp \ + main.cpp diff --git a/examples/listboxcombo/main.cpp b/examples/listboxcombo/main.cpp new file mode 100644 index 000000000..dcfc0a8b7 --- /dev/null +++ b/examples/listboxcombo/main.cpp @@ -0,0 +1,24 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "listboxcombo.h" +#include <qapplication.h> + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); + + ListBoxCombo listboxcombo; + listboxcombo.resize( 400, 270 ); + listboxcombo.setCaption( "TQt Example - Listboxes and Comboboxes" ); + a.setMainWidget( &listboxcombo ); + listboxcombo.show(); + + return a.exec(); +} diff --git a/examples/listboxcombo/qtlogo.png b/examples/listboxcombo/qtlogo.png Binary files differnew file mode 100644 index 000000000..4e1a14726 --- /dev/null +++ b/examples/listboxcombo/qtlogo.png |