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.
228 lines
7.2 KiB
228 lines
7.2 KiB
15 years ago
|
#define protected public // for delegate()
|
||
|
#include <kcombobox.h>
|
||
|
#undef protected
|
||
|
|
||
|
#include "kcomboboxtest.h"
|
||
|
|
||
|
#include <assert.h>
|
||
|
|
||
|
#include <kapplication.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kdialog.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <ksimpleconfig.h>
|
||
|
|
||
15 years ago
|
#include <tqpushbutton.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqhbox.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
|
|
||
15 years ago
|
KComboBoxTest::KComboBoxTest(TQWidget* widget, const char* name )
|
||
|
:TQWidget(widget, name)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQVBoxLayout *vbox = new TQVBoxLayout (this, KDialog::marginHint(), KDialog::spacingHint());
|
||
15 years ago
|
|
||
|
// Test for KCombo's KLineEdit destruction
|
||
|
KComboBox *testCombo = new KComboBox( true, this ); // rw, with KLineEdit
|
||
|
testCombo->setEditable( false ); // destroys our KLineEdit
|
||
|
assert( testCombo->delegate() == 0L );
|
||
|
delete testCombo; // not needed anymore
|
||
|
|
||
|
// Qt combobox
|
||
15 years ago
|
TQHBox* hbox = new TQHBox(this);
|
||
15 years ago
|
hbox->setSpacing (KDialog::spacingHint());
|
||
15 years ago
|
TQLabel* lbl = new TQLabel("&QCombobox:", hbox);
|
||
14 years ago
|
lbl->tqsetSizePolicy (TQSizePolicy::Maximum, TQSizePolicy::Preferred);
|
||
15 years ago
|
|
||
15 years ago
|
m_qc = new TQComboBox(hbox, "QtReadOnlyCombo" );
|
||
15 years ago
|
lbl->setBuddy (m_qc);
|
||
15 years ago
|
TQObject::connect (m_qc, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
|
||
|
TQObject::connect (m_qc, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT (slotActivated(const TQString&)));
|
||
15 years ago
|
vbox->addWidget (hbox);
|
||
|
|
||
|
// Read-only combobox
|
||
15 years ago
|
hbox = new TQHBox(this);
|
||
15 years ago
|
hbox->setSpacing (KDialog::spacingHint());
|
||
15 years ago
|
lbl = new TQLabel("&Read-Only Combo:", hbox);
|
||
14 years ago
|
lbl->tqsetSizePolicy (TQSizePolicy::Maximum, TQSizePolicy::Preferred);
|
||
15 years ago
|
|
||
|
m_ro = new KComboBox(hbox, "ReadOnlyCombo" );
|
||
|
lbl->setBuddy (m_ro);
|
||
|
m_ro->setCompletionMode( KGlobalSettings::CompletionAuto );
|
||
15 years ago
|
TQObject::connect (m_ro, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
|
||
|
TQObject::connect (m_ro, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT (slotActivated(const TQString&)));
|
||
15 years ago
|
vbox->addWidget (hbox);
|
||
|
|
||
|
// Read-write combobox
|
||
15 years ago
|
hbox = new TQHBox(this);
|
||
15 years ago
|
hbox->setSpacing (KDialog::spacingHint());
|
||
15 years ago
|
lbl = new TQLabel("&Editable Combo:", hbox);
|
||
14 years ago
|
lbl->tqsetSizePolicy (TQSizePolicy::Maximum, TQSizePolicy::Preferred);
|
||
15 years ago
|
|
||
|
m_rw = new KComboBox( true, hbox, "ReadWriteCombo" );
|
||
|
lbl->setBuddy (m_rw);
|
||
|
m_rw->setDuplicatesEnabled( true );
|
||
15 years ago
|
m_rw->setInsertionPolicy( TQComboBox::NoInsertion );
|
||
15 years ago
|
m_rw->setTrapReturnKey( true );
|
||
15 years ago
|
TQObject::connect (m_rw, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
|
||
|
TQObject::connect (m_rw, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT(slotActivated(const TQString&)));
|
||
|
TQObject::connect (m_rw, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotReturnPressed()));
|
||
|
TQObject::connect (m_rw, TQT_SIGNAL(returnPressed(const TQString&)), TQT_SLOT(slotReturnPressed(const TQString&)));
|
||
15 years ago
|
vbox->addWidget (hbox);
|
||
|
|
||
|
// History combobox...
|
||
15 years ago
|
hbox = new TQHBox(this);
|
||
15 years ago
|
hbox->setSpacing (KDialog::spacingHint());
|
||
15 years ago
|
lbl = new TQLabel("&History Combo:", hbox);
|
||
14 years ago
|
lbl->tqsetSizePolicy (TQSizePolicy::Maximum, TQSizePolicy::Preferred);
|
||
15 years ago
|
|
||
|
m_hc = new KHistoryCombo( true, hbox, "HistoryCombo" );
|
||
|
lbl->setBuddy (m_hc);
|
||
|
m_hc->setDuplicatesEnabled( true );
|
||
15 years ago
|
m_hc->setInsertionPolicy( TQComboBox::NoInsertion );
|
||
|
TQObject::connect (m_hc, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
|
||
|
TQObject::connect (m_hc, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT(slotActivated(const TQString&)));
|
||
|
TQObject::connect (m_hc, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotReturnPressed()));
|
||
15 years ago
|
vbox->addWidget (hbox);
|
||
|
m_hc->setTrapReturnKey(true);
|
||
|
|
||
|
// Read-write combobox that is a replica of code in konqueror...
|
||
15 years ago
|
hbox = new TQHBox(this);
|
||
15 years ago
|
hbox->setSpacing (KDialog::spacingHint());
|
||
15 years ago
|
lbl = new TQLabel( "&Konq's Combo:", hbox);
|
||
14 years ago
|
lbl->tqsetSizePolicy (TQSizePolicy::Maximum, TQSizePolicy::Preferred);
|
||
15 years ago
|
|
||
|
m_konqc = new KComboBox( true, hbox, "KonqyCombo" );
|
||
|
lbl->setBuddy (m_konqc);
|
||
|
m_konqc->setMaxCount( 10 );
|
||
15 years ago
|
TQObject::connect (m_konqc, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivated(int)));
|
||
|
TQObject::connect (m_konqc, TQT_SIGNAL(activated(const TQString&)), TQT_SLOT (slotActivated(const TQString&)));
|
||
|
TQObject::connect (m_konqc, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotReturnPressed()));
|
||
15 years ago
|
vbox->addWidget (hbox);
|
||
|
|
||
|
// Create an exit button
|
||
15 years ago
|
hbox = new TQHBox (this);
|
||
|
m_btnExit = new TQPushButton( "E&xit", hbox );
|
||
|
TQObject::connect( m_btnExit, TQT_SIGNAL(clicked()), TQT_SLOT(quitApp()) );
|
||
15 years ago
|
|
||
|
// Create a disable button...
|
||
15 years ago
|
m_btnEnable = new TQPushButton( "Disa&ble", hbox );
|
||
|
TQObject::connect (m_btnEnable, TQT_SIGNAL(clicked()), TQT_SLOT(slotDisable()));
|
||
15 years ago
|
|
||
|
vbox->addWidget (hbox);
|
||
|
|
||
|
// Popuplate the select-only list box
|
||
15 years ago
|
TQStringList list;
|
||
15 years ago
|
list << "Stone" << "Tree" << "Peables" << "Ocean" << "Sand" << "Chips"
|
||
|
<< "Computer" << "Mankind";
|
||
|
list.sort();
|
||
|
|
||
|
// Setup the qcombobox
|
||
|
m_qc->insertStringList (list);
|
||
|
|
||
|
// Setup read-only combo
|
||
|
m_ro->insertStringList( list );
|
||
|
m_ro->completionObject()->setItems( list );
|
||
|
|
||
|
// Setup read-write combo
|
||
|
m_rw->insertStringList( list );
|
||
|
m_rw->completionObject()->setItems( list );
|
||
|
|
||
|
// Setup read-write combo
|
||
|
m_hc->insertStringList( list );
|
||
|
m_hc->completionObject()->setItems( list );
|
||
|
|
||
|
// Setup konq's combobox
|
||
|
KSimpleConfig historyConfig( "konq_history" );
|
||
|
historyConfig.setGroup( "Location Bar" );
|
||
|
KCompletion * s_pCompletion = new KCompletion;
|
||
|
s_pCompletion->setOrder( KCompletion::Weighted );
|
||
|
s_pCompletion->setItems( historyConfig.readListEntry( "ComboContents" ) );
|
||
|
s_pCompletion->setCompletionMode( KGlobalSettings::completionMode() );
|
||
|
m_konqc->setCompletionObject( s_pCompletion );
|
||
|
|
||
15 years ago
|
TQPixmap pix = SmallIcon("www");
|
||
15 years ago
|
m_konqc->insertItem( pix, "http://www.kde.org" );
|
||
|
m_konqc->setCurrentItem( m_konqc->count()-1 );
|
||
|
|
||
15 years ago
|
m_timer = new TQTimer (this);
|
||
|
connect (m_timer, TQT_SIGNAL (timeout()), TQT_SLOT (slotTimeout()));
|
||
15 years ago
|
}
|
||
|
|
||
|
KComboBoxTest::~KComboBoxTest()
|
||
|
{
|
||
|
if (m_timer)
|
||
|
{
|
||
|
delete m_timer;
|
||
|
m_timer = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KComboBoxTest::slotDisable ()
|
||
|
{
|
||
|
if (m_timer->isActive())
|
||
|
return;
|
||
|
|
||
|
m_btnEnable->setEnabled (!m_btnEnable->isEnabled());
|
||
|
|
||
|
m_timer->start (5000, true);
|
||
|
}
|
||
|
|
||
|
void KComboBoxTest::slotTimeout ()
|
||
|
{
|
||
|
bool enabled = m_ro->isEnabled();
|
||
|
|
||
|
if (enabled)
|
||
|
m_btnEnable->setText ("Ena&ble");
|
||
|
else
|
||
|
m_btnEnable->setText ("Disa&ble");
|
||
|
|
||
|
m_qc->setEnabled (!enabled);
|
||
|
m_ro->setEnabled (!enabled);
|
||
|
m_rw->setEnabled (!enabled);
|
||
|
m_hc->setEnabled (!enabled);
|
||
|
m_konqc->setEnabled (!enabled);
|
||
|
|
||
|
m_btnEnable->setEnabled (!m_btnEnable->isEnabled());
|
||
|
}
|
||
|
|
||
|
void KComboBoxTest::slotActivated( int index )
|
||
|
{
|
||
|
kdDebug() << "Activated Combo: " << sender()->name() << ", index:" << index << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KComboBoxTest::slotActivated (const TQString& item)
|
||
15 years ago
|
{
|
||
|
kdDebug() << "Activated Combo: " << sender()->name() << ", item: " << item << endl;
|
||
|
}
|
||
|
|
||
|
void KComboBoxTest::slotReturnPressed ()
|
||
|
{
|
||
|
kdDebug() << "Return Pressed: " << sender()->name() << endl;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KComboBoxTest::slotReturnPressed(const TQString& item)
|
||
15 years ago
|
{
|
||
|
kdDebug() << "Return Pressed, value = " << item << endl;
|
||
|
}
|
||
|
|
||
|
void KComboBoxTest::quitApp()
|
||
|
{
|
||
|
kapp->closeAllWindows();
|
||
|
}
|
||
|
|
||
|
int main ( int argc, char **argv)
|
||
|
{
|
||
|
KApplication a(argc, argv, "kcomboboxtest");
|
||
|
KComboBoxTest* t= new KComboBoxTest;
|
||
|
a.setMainWidget (t);
|
||
|
t->show ();
|
||
|
return a.exec();
|
||
|
}
|
||
|
|
||
|
#include "kcomboboxtest.moc"
|