You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
5.0 KiB
194 lines
5.0 KiB
13 years ago
|
/****************************************************************************
|
||
|
**
|
||
|
** 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 "listbox.h"
|
||
|
|
||
|
#include <qlabel.h>
|
||
|
#include <qradiobutton.h>
|
||
|
#include <qcheckbox.h>
|
||
|
#include <qspinbox.h>
|
||
|
#include <qlistbox.h>
|
||
|
#include <qbuttongroup.h>
|
||
|
#include <qlayout.h>
|
||
|
#include <qpushbutton.h>
|
||
|
|
||
|
|
||
|
ListBoxDemo::ListBoxDemo()
|
||
|
: TQWidget( 0, 0 )
|
||
|
{
|
||
|
TQGridLayout * g = new TQGridLayout( this, 2, 2, 6 );
|
||
|
|
||
|
g->addWidget( new TQLabel( "<b>Configuration:</b>", this ), 0, 0 );
|
||
|
g->addWidget( new TQLabel( "<b>Result:</b>", this ), 0, 1 );
|
||
|
|
||
|
l = new TQListBox( this );
|
||
|
g->addWidget( l, 1, 1 );
|
||
|
l->setFocusPolicy( TQWidget::StrongFocus );
|
||
|
|
||
|
TQVBoxLayout * v = new TQVBoxLayout;
|
||
|
g->addLayout( v, 1, 0 );
|
||
|
|
||
|
TQRadioButton * b;
|
||
|
bg = new TQButtonGroup( 0 );
|
||
|
|
||
|
b = new TQRadioButton( "Fixed number of columns,\n"
|
||
|
"as many rows as needed.",
|
||
|
this );
|
||
|
bg->insert( b );
|
||
|
v->addWidget( b );
|
||
|
b->setChecked( TRUE );
|
||
|
connect( b, SIGNAL(clicked()), this, SLOT(setNumCols()) );
|
||
|
TQHBoxLayout * h = new TQHBoxLayout;
|
||
|
v->addLayout( h );
|
||
|
h->addSpacing( 30 );
|
||
|
h->addSpacing( 100 );
|
||
|
h->addWidget( new TQLabel( "Columns:", this ) );
|
||
|
columns = new TQSpinBox( this );
|
||
|
h->addWidget( columns );
|
||
|
|
||
|
v->addSpacing( 12 );
|
||
|
|
||
|
b = new TQRadioButton( "As many columns as fit on-screen,\n"
|
||
|
"as many rows as needed.",
|
||
|
this );
|
||
|
bg->insert( b );
|
||
|
v->addWidget( b );
|
||
|
connect( b, SIGNAL(clicked()), this, SLOT(setColsByWidth()) );
|
||
|
|
||
|
v->addSpacing( 12 );
|
||
|
|
||
|
b = new TQRadioButton( "Fixed number of rows,\n"
|
||
|
"as many columns as needed.",
|
||
|
this );
|
||
|
bg->insert( b );
|
||
|
v->addWidget( b );
|
||
|
connect( b, SIGNAL(clicked()), this, SLOT(setNumRows()) );
|
||
|
h = new TQHBoxLayout;
|
||
|
v->addLayout( h );
|
||
|
h->addSpacing( 30 );
|
||
|
h->addSpacing( 100 );
|
||
|
h->addWidget( new TQLabel( "Rows:", this ) );
|
||
|
rows = new TQSpinBox( this );
|
||
|
rows->setEnabled( FALSE );
|
||
|
h->addWidget( rows );
|
||
|
|
||
|
v->addSpacing( 12 );
|
||
|
|
||
|
b = new TQRadioButton( "As many rows as fit on-screen,\n"
|
||
|
"as many columns as needed.",
|
||
|
this );
|
||
|
bg->insert( b );
|
||
|
v->addWidget( b );
|
||
|
connect( b, SIGNAL(clicked()), this, SLOT(setRowsByHeight()) );
|
||
|
|
||
|
v->addSpacing( 12 );
|
||
|
|
||
|
TQCheckBox * cb = new TQCheckBox( "Variable-height rows", this );
|
||
|
cb->setChecked( TRUE );
|
||
|
connect( cb, SIGNAL(toggled(bool)), this, SLOT(setVariableHeight(bool)) );
|
||
|
v->addWidget( cb );
|
||
|
v->addSpacing( 6 );
|
||
|
|
||
|
cb = new TQCheckBox( "Variable-width columns", this );
|
||
|
connect( cb, SIGNAL(toggled(bool)), this, SLOT(setVariableWidth(bool)) );
|
||
|
v->addWidget( cb );
|
||
|
|
||
|
cb = new TQCheckBox( "Extended-Selection", this );
|
||
|
connect( cb, SIGNAL(toggled(bool)), this, SLOT(setMultiSelection(bool)) );
|
||
|
v->addWidget( cb );
|
||
|
|
||
|
TQPushButton *pb = new TQPushButton( "Sort ascending", this );
|
||
|
connect( pb, SIGNAL( clicked() ), this, SLOT( sortAscending() ) );
|
||
|
v->addWidget( pb );
|
||
|
|
||
|
pb = new TQPushButton( "Sort descending", this );
|
||
|
connect( pb, SIGNAL( clicked() ), this, SLOT( sortDescending() ) );
|
||
|
v->addWidget( pb );
|
||
|
|
||
|
v->addStretch( 100 );
|
||
|
|
||
|
int i = 0;
|
||
|
while( ++i <= 2560 )
|
||
|
l->insertItem( TQString::fromLatin1( "Item " ) + TQString::number( i ),
|
||
|
i );
|
||
|
columns->setRange( 1, 256 );
|
||
|
columns->setValue( 1 );
|
||
|
rows->setRange( 1, 256 );
|
||
|
rows->setValue( 256 );
|
||
|
|
||
|
connect( columns, SIGNAL(valueChanged(int)), this, SLOT(setNumCols()) );
|
||
|
connect( rows, SIGNAL(valueChanged(int)), this, SLOT(setNumRows()) );
|
||
|
}
|
||
|
|
||
|
|
||
|
ListBoxDemo::~ListBoxDemo()
|
||
|
{
|
||
|
delete bg;
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setNumRows()
|
||
|
{
|
||
|
columns->setEnabled( FALSE );
|
||
|
rows->setEnabled( TRUE );
|
||
|
l->setRowMode( rows->value() );
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setNumCols()
|
||
|
{
|
||
|
columns->setEnabled( TRUE );
|
||
|
rows->setEnabled( FALSE );
|
||
|
l->setColumnMode( columns->value() );
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setRowsByHeight()
|
||
|
{
|
||
|
columns->setEnabled( FALSE );
|
||
|
rows->setEnabled( FALSE );
|
||
|
l->setRowMode( TQListBox::FitToHeight );
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setColsByWidth()
|
||
|
{
|
||
|
columns->setEnabled( FALSE );
|
||
|
rows->setEnabled( FALSE );
|
||
|
l->setColumnMode( TQListBox::FitToWidth );
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setVariableWidth( bool b )
|
||
|
{
|
||
|
l->setVariableWidth( b );
|
||
|
}
|
||
|
|
||
|
|
||
|
void ListBoxDemo::setVariableHeight( bool b )
|
||
|
{
|
||
|
l->setVariableHeight( b );
|
||
|
}
|
||
|
|
||
|
void ListBoxDemo::setMultiSelection( bool b )
|
||
|
{
|
||
|
l->clearSelection();
|
||
|
l->setSelectionMode( b ? TQListBox::Extended : TQListBox::Single );
|
||
|
}
|
||
|
|
||
|
void ListBoxDemo::sortAscending()
|
||
|
{
|
||
|
l->sort( TRUE );
|
||
|
}
|
||
|
|
||
|
void ListBoxDemo::sortDescending()
|
||
|
{
|
||
|
l->sort( FALSE );
|
||
|
}
|