fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kde3support / tests / itemcontainertest.cpp
blob9d15180502893b41dfbbb12540ae9bbe04d6c2e5
1 /*
2 * Tests the item container widgets K3IconView, K3ListView, KListWidget
4 * Copyright 2000 by Michael Reiher <michael.reiher@gmx.de>
6 * Licensed under the GNU General Public License version 2
7 */
9 #include <QtGui/QLayout>
10 #include <QtGui/QRadioButton>
11 #include <QtGui/QCheckBox>
12 #include <QtGui/QLabel>
13 #include <QtGui/QGroupBox>
14 #include <QtGui/QButtonGroup>
16 #include <kapplication.h>
17 #include <kcmdlineargs.h>
18 #include <kglobal.h>
19 #include <kconfig.h>
20 #include <k3iconview.h>
21 #include <k3listview.h>
22 #include <klistwidget.h>
24 #include "itemcontainertest.h"
26 static const char * item_xpm[] = {
27 "22 22 3 1",
28 " c None",
29 ". c #000000",
30 "+ c #FF0000",
31 " ...... ",
32 " ....++++.... ",
33 " ..++++..++++.. ",
34 " ..++++++++++++.. ",
35 " ..++++++..++++++.. ",
36 " ..++++++++++++++++.. ",
37 " .++++++++..++++++++. ",
38 " .++++++++++++++++++. ",
39 "..++++++++..++++++++..",
40 ".++++++++++++++++++++.",
41 ".+.+.+.+.+..+.+.+.+.+.",
42 ".+.+.+.+.+..+.+.+.+.+.",
43 ".++++++++++++++++++++.",
44 "..++++++++..++++++++..",
45 " .++++++++++++++++++. ",
46 " .++++++++..++++++++. ",
47 " ..++++++++++++++++.. ",
48 " ..++++++..++++++.. ",
49 " ..++++++++++++.. ",
50 " ..++++..++++.. ",
51 " ....++++.... ",
52 " ...... "};
55 TopLevel::TopLevel(QWidget *parent)
56 : QWidget(parent)
58 setWindowTitle("Item container test application");
60 QHBoxLayout* hBox = new QHBoxLayout( this );
61 QVBoxLayout* vBox = new QVBoxLayout;
62 hBox->addSpacing( 5 );
63 hBox->addItem( vBox );
64 vBox->setParent( hBox );
67 //Selection mode selection
68 QGroupBox* selectionModeBox = new QGroupBox("Selection Mode",this);
69 m_pbgMode = new QButtonGroup(this);
70 m_pbgMode->addButton(new QRadioButton("NoSlection", selectionModeBox), TopLevel::NoSelection );
71 m_pbgMode->addButton(new QRadioButton("Single", selectionModeBox), TopLevel::Single );
72 m_pbgMode->addButton(new QRadioButton("Multi", selectionModeBox), TopLevel::Multi );
73 m_pbgMode->addButton(new QRadioButton("Extended", selectionModeBox), TopLevel::Extended );
74 m_pbgMode->setExclusive( true );
75 vBox->addWidget( selectionModeBox );
77 connect( m_pbgMode, SIGNAL( buttonClicked( int ) ),
78 this, SLOT( slotSwitchMode( int ) ) );
80 //Signal labels
81 QGroupBox* gbWiget = new QGroupBox( "Widget", this);
82 m_plblWidget = new QLabel( gbWiget );
83 vBox->addWidget( gbWiget );
84 QGroupBox* gbSignal = new QGroupBox( "emitted Signal", this);
85 m_plblSignal = new QLabel( gbSignal );
86 vBox->addWidget( gbSignal );
87 QGroupBox* gbItem = new QGroupBox( "on Item", this);
88 m_plblItem = new QLabel( gbItem );
89 vBox->addWidget( gbItem );
91 QGroupBox* bgListView = new QGroupBox( "K3ListView", this);
92 QCheckBox* cbListView = new QCheckBox("Single Column", bgListView);
93 vBox->addWidget( bgListView );
94 connect( cbListView, SIGNAL( toggled( bool ) ),
95 this, SLOT( slotToggleSingleColumn( bool ) ) );
97 KGlobal::config()->reparseConfiguration();
99 //Create IconView
100 QGroupBox* gbIconView = new QGroupBox( "K3IconView", this);
101 m_pIconView = new K3IconView( gbIconView );
102 hBox->addWidget( gbIconView );
103 hBox->addSpacing( 5 );
104 connect( m_pIconView, SIGNAL( executed( Q3IconViewItem* ) ),
105 this, SLOT( slotIconViewExec( Q3IconViewItem* ) ) );
107 //Create ListView
108 QGroupBox* gbListView = new QGroupBox( "K3ListView", this);
109 m_pListView = new K3ListView( gbListView );
110 m_pListView->addColumn("Item");
111 m_pListView->addColumn("Text");
112 hBox->addWidget( gbListView );
113 hBox->addSpacing( 5 );
114 connect( m_pListView, SIGNAL( executed( Q3ListViewItem* ) ),
115 this, SLOT( slotListViewExec( Q3ListViewItem* ) ) );
117 //Create ListBox
118 QGroupBox* gbListBox = new QGroupBox( "KListWidget", this);
119 m_pListBox = new KListWidget( gbListBox );
120 hBox->addWidget( gbListBox );
121 connect( m_pListBox, SIGNAL( executed( QListWidgetItem* ) ),
122 this, SLOT( slotListBoxExec( QListWidgetItem* ) ) );
124 //Initialize buttons
125 cbListView->setChecked( !m_pListView->allColumnsShowFocus() );
126 m_pbgMode->button( TopLevel::Extended )->setChecked(true);
127 slotSwitchMode( TopLevel::Extended );
129 //Fill container widgets
130 for( int i = 0; i < 10; i++ ) {
131 new Q3IconViewItem( m_pIconView, QString("Item%1").arg(i), QPixmap(item_xpm) );
133 Q3ListViewItem* lv = new Q3ListViewItem( m_pListView, QString("Item%1").arg(i), QString("Text%1").arg(i) );
134 lv->setPixmap( 0, QPixmap(item_xpm));
135 lv->setPixmap( 1, QPixmap(item_xpm));
137 QListWidgetItem* listWidgetItem = new QListWidgetItem(m_pListBox);
138 listWidgetItem->setIcon( QPixmap(item_xpm) );
139 listWidgetItem->setText( QString("Item%1").arg(i) );
142 connect( m_pIconView, SIGNAL( clicked( Q3IconViewItem* ) ),
143 this, SLOT( slotClicked( Q3IconViewItem* ) ) );
144 connect( m_pIconView, SIGNAL( doubleClicked( Q3IconViewItem* ) ),
145 this, SLOT( slotDoubleClicked( Q3IconViewItem* ) ) );
148 void TopLevel::slotSwitchMode( int id )
150 m_pIconView->clearSelection();
151 m_pListView->clearSelection();
152 m_pListBox->clearSelection();
154 switch( id ) {
155 case TopLevel::NoSelection:
156 m_pIconView->setSelectionMode( K3IconView::NoSelection );
157 m_pListView->setSelectionMode( Q3ListView::NoSelection );
158 m_pListBox->setSelectionMode( KListWidget::NoSelection );
159 break;
160 case TopLevel::Single:
161 m_pIconView->setSelectionMode( K3IconView::Single );
162 m_pListView->setSelectionMode( Q3ListView::Single );
163 m_pListBox->setSelectionMode( KListWidget::SingleSelection );
164 break;
165 case TopLevel::Multi:
166 m_pIconView->setSelectionMode( K3IconView::Multi );
167 m_pListView->setSelectionMode( Q3ListView::Multi );
168 m_pListBox->setSelectionMode( KListWidget::MultiSelection );
169 break;
170 case TopLevel::Extended:
171 m_pIconView->setSelectionMode( K3IconView::Extended );
172 m_pListView->setSelectionMode( Q3ListView::Extended );
173 m_pListBox->setSelectionMode( KListWidget::ExtendedSelection );
174 break;
175 default:
176 Q_ASSERT(0);
180 void TopLevel::slotIconViewExec( Q3IconViewItem* item )
182 m_plblWidget->setText("K3IconView");
183 m_plblSignal->setText("executed");
184 if( item )
185 m_plblItem->setText( item->text() );
186 else
187 m_plblItem->setText("Viewport");
190 void TopLevel::slotListViewExec( Q3ListViewItem* item )
192 m_plblWidget->setText("K3ListView");
193 m_plblSignal->setText("executed");
194 if( item )
195 m_plblItem->setText( item->text(0) );
196 else
197 m_plblItem->setText("Viewport");
200 void TopLevel::slotListBoxExec( QListWidgetItem* item )
202 m_plblWidget->setText("KListWidget");
203 m_plblSignal->setText("executed");
204 if( item )
205 m_plblItem->setText( item->text() );
206 else
207 m_plblItem->setText("Viewport");
210 void TopLevel::slotToggleSingleColumn( bool b )
212 m_pListView->setAllColumnsShowFocus( !b );
215 int main( int argc, char ** argv )
217 KCmdLineArgs::init( argc, argv, "test", 0, ki18n("Test"), "1.0", ki18n("test app"));
218 KApplication app;
220 TopLevel *toplevel = new TopLevel(0);
222 toplevel->show();
223 toplevel->resize( 600, 300 );
224 app.exec();
227 #include "itemcontainertest.moc"