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.
367 lines
13 KiB
367 lines
13 KiB
15 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqlayout.h>
|
||
|
#include <tqdragobject.h>
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
|
#include <kcmdlineargs.h>
|
||
|
#include <kinputdialog.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include "ktabwidgettest.h"
|
||
|
|
||
15 years ago
|
Test::Test( TQWidget* parent, const char *name )
|
||
|
:TQVBox( parent, name ), mChange(0), mLeftWidget(0), mRightWidget(0),
|
||
15 years ago
|
mLeftPopup( false ), mRightPopup( false ), mTabbarContextPopup( false ), mContextPopup( false )
|
||
|
|
||
|
{
|
||
|
resize( 600,300 );
|
||
|
|
||
|
mWidget = new KTabWidget( this );
|
||
15 years ago
|
mWidget->addTab( new TQLabel( "Testlabel 1", mWidget ), "One" );
|
||
|
mWidget->addTab( new TQLabel( "Testlabel 2", mWidget ), "Two" );
|
||
|
mWidget->addTab( new TQWidget( mWidget), SmallIcon( "konsole" ), "Three" );
|
||
|
mWidget->addTab( new TQWidget( mWidget), "Four" );
|
||
15 years ago
|
mWidget->setTabColor( mWidget->page(0), Qt::red );
|
||
|
mWidget->setTabColor( mWidget->page(1), Qt::blue );
|
||
|
|
||
15 years ago
|
connect( mWidget, TQT_SIGNAL( currentChanged( TQWidget * ) ), TQT_SLOT( currentChanged( TQWidget * ) ) );
|
||
|
connect( mWidget, TQT_SIGNAL( contextMenu( TQWidget *, const TQPoint & )), TQT_SLOT(contextMenu( TQWidget *, const TQPoint & )));
|
||
|
connect( mWidget, TQT_SIGNAL( contextMenu( const TQPoint & )), TQT_SLOT(tabbarContextMenu( const TQPoint & )));
|
||
|
connect( mWidget, TQT_SIGNAL( mouseDoubleClick( TQWidget * )), TQT_SLOT(mouseDoubleClick( TQWidget * )));
|
||
|
connect( mWidget, TQT_SIGNAL( mouseMiddleClick() ), TQT_SLOT(addTab() ));
|
||
|
connect( mWidget, TQT_SIGNAL( mouseMiddleClick( TQWidget * )), TQT_SLOT(mouseMiddleClick( TQWidget * )));
|
||
|
connect( mWidget, TQT_SIGNAL( closeRequest( TQWidget * )), TQT_SLOT(mouseMiddleClick( TQWidget * )));
|
||
|
connect( mWidget, TQT_SIGNAL( testCanDecode(const TQDragMoveEvent *, bool & )), TQT_SLOT(testCanDecode(const TQDragMoveEvent *, bool & )));
|
||
|
connect( mWidget, TQT_SIGNAL( receivedDropEvent( TQDropEvent * )), TQT_SLOT(receivedDropEvent( TQDropEvent * )));
|
||
|
connect( mWidget, TQT_SIGNAL( receivedDropEvent( TQWidget *, TQDropEvent * )), TQT_SLOT(receivedDropEvent( TQWidget *, TQDropEvent * )));
|
||
|
connect( mWidget, TQT_SIGNAL( initiateDrag( TQWidget * )), TQT_SLOT(initiateDrag( TQWidget * )));
|
||
|
connect( mWidget, TQT_SIGNAL( movedTab( int, int )), TQT_SLOT(movedTab( int, int )));
|
||
15 years ago
|
mWidget->setTabReorderingEnabled( true );
|
||
|
|
||
15 years ago
|
TQWidget * grid = new TQWidget(this);
|
||
14 years ago
|
TQGridLayout * gridlayout = new TQGridLayout( grid, 5, 2 );
|
||
15 years ago
|
|
||
15 years ago
|
TQPushButton * addTab = new TQPushButton( "Add Tab", grid );
|
||
14 years ago
|
gridlayout->addWidget( addTab, 0, 0 );
|
||
15 years ago
|
connect( addTab, TQT_SIGNAL( clicked() ), TQT_SLOT( addTab() ) );
|
||
15 years ago
|
|
||
15 years ago
|
TQPushButton * removeTab = new TQPushButton( "Remove Current Tab", grid );
|
||
14 years ago
|
gridlayout->addWidget( removeTab, 0, 1 );
|
||
15 years ago
|
connect( removeTab, TQT_SIGNAL( clicked() ), TQT_SLOT( removeCurrentTab() ) );
|
||
15 years ago
|
|
||
15 years ago
|
mLeftButton = new TQCheckBox( "Show left button", grid );
|
||
14 years ago
|
gridlayout->addWidget( mLeftButton, 1, 0 );
|
||
15 years ago
|
connect( mLeftButton, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleLeftButton(bool) ) );
|
||
15 years ago
|
mLeftButton->setChecked(true);
|
||
|
|
||
15 years ago
|
TQCheckBox * leftPopup = new TQCheckBox( "Enable left popup", grid );
|
||
14 years ago
|
gridlayout->addWidget( leftPopup, 2, 0 );
|
||
15 years ago
|
connect( leftPopup, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleLeftPopup(bool) ) );
|
||
15 years ago
|
leftPopup->setChecked(true);
|
||
|
|
||
15 years ago
|
mRightButton = new TQCheckBox( "Show right button", grid );
|
||
14 years ago
|
gridlayout->addWidget( mRightButton, 1, 1 );
|
||
15 years ago
|
connect( mRightButton, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleRightButton(bool) ) );
|
||
15 years ago
|
mRightButton->setChecked(true);
|
||
|
|
||
15 years ago
|
TQCheckBox * rightPopup = new TQCheckBox( "Enable right popup", grid );
|
||
14 years ago
|
gridlayout->addWidget( rightPopup, 2, 1 );
|
||
15 years ago
|
connect( rightPopup, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleRightPopup(bool) ) );
|
||
15 years ago
|
rightPopup->setChecked(true);
|
||
|
|
||
15 years ago
|
mTabsBottom = new TQCheckBox( "Show tabs at bottom", grid );
|
||
14 years ago
|
gridlayout->addWidget( mTabsBottom, 3, 0 );
|
||
15 years ago
|
connect( mTabsBottom, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleTabPosition(bool) ) );
|
||
15 years ago
|
|
||
14 years ago
|
TQCheckBox * tabtqshape = new TQCheckBox( "Triangular tab tqshape", grid );
|
||
|
gridlayout->addWidget( tabtqshape, 3, 1 );
|
||
|
connect( tabtqshape, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleTabShape(bool) ) );
|
||
15 years ago
|
|
||
15 years ago
|
TQCheckBox *tabClose = new TQCheckBox( "Close button on icon hover", grid );
|
||
14 years ago
|
gridlayout->addWidget( tabClose, 4, 0 );
|
||
15 years ago
|
connect( tabClose, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( toggleCloseButtons(bool) ) );
|
||
15 years ago
|
tabClose->setChecked(true);
|
||
|
|
||
15 years ago
|
TQCheckBox * showlabels = new TQCheckBox( "Show labels", grid );
|
||
14 years ago
|
gridlayout->addWidget( showlabels, 4, 1 );
|
||
15 years ago
|
connect( showlabels, TQT_SIGNAL( toggled(bool) ), this, TQT_SLOT( toggleLabels(bool) ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void Test::currentChanged(TQWidget* w)
|
||
15 years ago
|
{
|
||
|
mWidget->setTabColor( w, Qt::black );
|
||
|
}
|
||
|
|
||
|
void Test::addTab()
|
||
|
{
|
||
15 years ago
|
mWidget->addTab( new TQWidget( mWidget ), SmallIcon( "konsole" ), TQString("Tab %1").arg( mWidget->count()+1 ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void Test::testCanDecode(const TQDragMoveEvent *e, bool &accept /* result */)
|
||
15 years ago
|
{
|
||
15 years ago
|
if ( TQTextDrag::canDecode(e) ) // don't accept=false if it cannot be decoded!
|
||
15 years ago
|
accept = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::receivedDropEvent( TQDropEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString dropText;
|
||
|
if (TQTextDrag::decode(e, dropText)) {
|
||
|
mWidget->addTab( new TQWidget( mWidget), dropText );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::receivedDropEvent( TQWidget *w, TQDropEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString dropText;
|
||
|
if (TQTextDrag::decode(e, dropText)) {
|
||
15 years ago
|
mWidget->changeTab( w, dropText );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::initiateDrag( TQWidget *w )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDragObject *d = new TQTextDrag( mWidget->label( mWidget->indexOf( w ) ), this );
|
||
15 years ago
|
d->dragCopy(); // do NOT delete d.
|
||
|
}
|
||
|
|
||
|
void Test::removeCurrentTab()
|
||
|
{
|
||
|
if ( mWidget->count()==1 ) return;
|
||
|
|
||
|
mWidget->removePage( mWidget->currentPage() );
|
||
|
}
|
||
|
|
||
|
void Test::toggleLeftButton(bool state)
|
||
|
{
|
||
|
if (state) {
|
||
|
if (!mLeftWidget) {
|
||
15 years ago
|
mLeftWidget = new TQToolButton( mWidget );
|
||
|
connect( mLeftWidget, TQT_SIGNAL( clicked() ), TQT_SLOT( addTab() ) );
|
||
15 years ago
|
mLeftWidget->setIconSet( SmallIcon( "tab_new" ) );
|
||
|
mLeftWidget->setTextLabel("New");
|
||
15 years ago
|
mLeftWidget->setTextPosition(TQToolButton::Right);
|
||
15 years ago
|
mLeftWidget->adjustSize();
|
||
|
//mLeftWidget->setGeometry( 0, 0, h, h );
|
||
|
mLeftWidget->setPopup(mLeftPopup);
|
||
|
mWidget->setCornerWidget( mLeftWidget, TopLeft );
|
||
|
}
|
||
|
mLeftWidget->show();
|
||
|
}
|
||
|
else
|
||
|
mLeftWidget->hide();
|
||
|
}
|
||
|
|
||
|
void Test::toggleLeftPopup(bool state)
|
||
|
{
|
||
|
if (state) {
|
||
|
if (!mLeftPopup) {
|
||
15 years ago
|
mLeftPopup = new TQPopupMenu(this);
|
||
15 years ago
|
mLeftPopup->insertItem(SmallIcon( "tab_new" ), "Empty Tab", 0);
|
||
|
mLeftPopup->insertItem(SmallIcon( "tab_new" ), "Empty Tab After First", 3);
|
||
|
mLeftPopup->insertSeparator();
|
||
|
mLeftPopup->insertItem(SmallIcon( "tab_new" ), "Button Tab", 1);
|
||
|
mLeftPopup->insertItem(SmallIcon( "tab_new" ), "Label Tab", 2);
|
||
15 years ago
|
connect(mLeftPopup, TQT_SIGNAL(activated(int)), TQT_SLOT(leftPopupActivated(int)));
|
||
15 years ago
|
}
|
||
|
mLeftWidget->setPopup(mLeftPopup);
|
||
|
}
|
||
|
else
|
||
|
mLeftWidget->setPopup(0);
|
||
|
}
|
||
|
|
||
|
void Test::leftPopupActivated(int item)
|
||
|
{
|
||
|
switch (item) {
|
||
15 years ago
|
case 0: mWidget->addTab( new TQWidget( mWidget), TQString("Tab %1").arg( mWidget->count()+1 ) );
|
||
15 years ago
|
break;
|
||
15 years ago
|
case 1: mWidget->addTab( new TQPushButton( "Testbutton", mWidget ), TQString("Tab %1").arg( mWidget->count()+1 ) );
|
||
15 years ago
|
break;
|
||
15 years ago
|
case 2: mWidget->addTab( new TQLabel( "Testlabel", mWidget ), TQString("Tab %1").arg( mWidget->count()+1 ) );
|
||
15 years ago
|
break;
|
||
15 years ago
|
case 3: mWidget->insertTab( new TQWidget( mWidget), TQString("Tab %1").arg( mWidget->count()+1 ), 1 );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void Test::toggleRightButton(bool state)
|
||
|
{
|
||
|
if (state) {
|
||
|
if ( !mRightWidget) {
|
||
15 years ago
|
mRightWidget = new TQToolButton( mWidget );
|
||
|
TQObject::connect( mRightWidget, TQT_SIGNAL( clicked() ), TQT_SLOT( removeCurrentTab() ) );
|
||
15 years ago
|
mRightWidget->setIconSet( SmallIcon( "tab_remove" ) );
|
||
|
mRightWidget->setTextLabel("Close");
|
||
15 years ago
|
mRightWidget->setTextPosition(TQToolButton::Right);
|
||
15 years ago
|
mRightWidget->adjustSize();
|
||
|
//mRightButton->setGeometry( 0, 0, h, h );
|
||
|
mRightWidget->setPopup(mRightPopup);
|
||
|
mWidget->setCornerWidget( mRightWidget, TopRight );
|
||
|
}
|
||
|
mRightWidget->show();
|
||
|
}
|
||
|
else
|
||
|
mRightWidget->hide();
|
||
|
}
|
||
|
|
||
|
void Test::toggleRightPopup(bool state)
|
||
|
{
|
||
|
if (state) {
|
||
|
if (!mRightPopup) {
|
||
15 years ago
|
mRightPopup = new TQPopupMenu(this);
|
||
15 years ago
|
mRightPopup->insertItem(SmallIcon( "tab_remove" ), "Current Tab", 1);
|
||
|
mRightPopup->insertSeparator();
|
||
|
mRightPopup->insertItem(SmallIcon( "tab_remove" ), "Most Left Tab", 0);
|
||
|
mRightPopup->insertItem(SmallIcon( "tab_remove" ), "Most Right Tab", 2);
|
||
15 years ago
|
connect(mRightPopup, TQT_SIGNAL(activated(int)), TQT_SLOT(rightPopupActivated(int)));
|
||
15 years ago
|
}
|
||
|
mRightWidget->setPopup(mRightPopup);
|
||
|
}
|
||
|
else
|
||
|
mRightWidget->setPopup(0);
|
||
|
}
|
||
|
|
||
|
void Test::rightPopupActivated(int item)
|
||
|
{
|
||
|
switch (item) {
|
||
|
case 0: if ( mWidget->count() >1) {
|
||
|
mWidget->removePage( mWidget->page(0) );
|
||
|
}
|
||
|
break;
|
||
|
case 1: removeCurrentTab();
|
||
|
break;
|
||
|
case 2: int count = mWidget->count();
|
||
|
if (count>1) {
|
||
|
mWidget->removePage( mWidget->page(count-1) );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Test::toggleTabPosition(bool state)
|
||
|
{
|
||
15 years ago
|
mWidget->setTabPosition(state ? TQTabWidget::Bottom : TQTabWidget::Top);
|
||
15 years ago
|
}
|
||
|
|
||
|
void Test::toggleTabShape(bool state)
|
||
|
{
|
||
15 years ago
|
mWidget->setTabShape(state ? TQTabWidget::Triangular : TQTabWidget::Rounded);
|
||
15 years ago
|
}
|
||
|
|
||
|
void Test::toggleCloseButtons(bool state)
|
||
|
{
|
||
|
mWidget->setHoverCloseButton( state );
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::contextMenu(TQWidget *w, const TQPoint &p)
|
||
15 years ago
|
{
|
||
|
if (mContextPopup)
|
||
|
delete mContextPopup;
|
||
|
|
||
15 years ago
|
mContextPopup = new TQPopupMenu(this);
|
||
15 years ago
|
mContextPopup->insertItem( "Activate Tab", 4);
|
||
|
mContextPopup->insertSeparator();
|
||
|
mContextPopup->insertItem(SmallIcon( "konsole" ), "Set This Icon", 0);
|
||
|
mContextPopup->insertItem(SmallIcon( "konqueror" ), "Set This Icon", 1);
|
||
|
mContextPopup->insertSeparator();
|
||
|
mContextPopup->insertItem( mWidget->isTabEnabled(w) ? "Disable Tab" : "Enable Tab", 2);
|
||
|
mContextPopup->insertItem( mWidget->tabToolTip(w).isEmpty() ? "Set Tooltip" : "Remove Tooltip", 3);
|
||
15 years ago
|
connect(mContextPopup, TQT_SIGNAL(activated(int)), TQT_SLOT(contextMenuActivated(int)));
|
||
15 years ago
|
|
||
|
mContextWidget = w;
|
||
|
mContextPopup->popup(p);
|
||
|
}
|
||
|
|
||
|
void Test::contextMenuActivated(int item)
|
||
|
{
|
||
|
switch (item) {
|
||
|
case 0: mWidget->changeTab( mContextWidget, SmallIcon( "konsole" ), mWidget->label( mWidget->indexOf( mContextWidget ) ) );
|
||
|
break;
|
||
|
case 1: mWidget->changeTab( mContextWidget, SmallIcon( "konqueror" ), mWidget->label( mWidget->indexOf( mContextWidget ) ) );
|
||
|
break;
|
||
|
case 2: mWidget->setTabEnabled( mContextWidget, !(mWidget->isTabEnabled(mContextWidget)) );
|
||
|
break;
|
||
|
case 3: if ( mWidget->tabToolTip(mContextWidget).isEmpty() )
|
||
|
mWidget->setTabToolTip( mContextWidget, "This is a tool tip.");
|
||
|
else
|
||
|
mWidget->removeTabToolTip( mContextWidget );
|
||
|
break;
|
||
|
case 4: mWidget->showPage( mContextWidget );
|
||
|
}
|
||
|
delete mContextPopup;
|
||
|
mContextPopup = 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::tabbarContextMenu(const TQPoint &p)
|
||
15 years ago
|
{
|
||
|
if (mTabbarContextPopup)
|
||
|
delete mTabbarContextPopup;
|
||
|
|
||
15 years ago
|
mTabbarContextPopup = new TQPopupMenu(this);
|
||
15 years ago
|
mTabbarContextPopup->insertItem(SmallIcon( "tab_new" ), mLeftWidget->isVisible() ? "Hide \"Add\" Button" : "Show \"Add\" Button", 0);
|
||
|
mTabbarContextPopup->insertItem(SmallIcon( "tab_remove" ), mRightWidget->isVisible() ? "Hide \"Remove\" Button" : "Show \"Remove\" Button", 1);
|
||
|
mTabbarContextPopup->insertSeparator();
|
||
15 years ago
|
mTabbarContextPopup->insertItem(mWidget->tabPosition()==TQTabWidget::Top ? "Put Tabbar to Bottom" : "Put Tabbar to Top", 2);
|
||
|
connect(mTabbarContextPopup, TQT_SIGNAL(activated(int)), TQT_SLOT(tabbarContextMenuActivated(int)));
|
||
15 years ago
|
|
||
|
mTabbarContextPopup->popup(p);
|
||
|
}
|
||
|
|
||
|
void Test::tabbarContextMenuActivated(int item)
|
||
|
{
|
||
|
switch (item) {
|
||
|
case 0: mLeftButton->toggle();
|
||
|
break;
|
||
|
case 1: mRightButton->toggle();
|
||
|
break;
|
||
|
case 2: mTabsBottom->toggle();
|
||
|
}
|
||
|
delete mTabbarContextPopup;
|
||
|
mTabbarContextPopup = 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::mouseDoubleClick(TQWidget *w)
|
||
15 years ago
|
{
|
||
|
bool ok;
|
||
15 years ago
|
TQString text = KInputDialog::getText(
|
||
15 years ago
|
"Rename Tab", "Enter new name:",
|
||
|
mWidget->label( mWidget->indexOf( w ) ), &ok, this );
|
||
|
if ( ok && !text.isEmpty() ) {
|
||
|
mWidget->changeTab( w, text );
|
||
|
mWidget->setTabColor( w, Qt::green );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void Test::mouseMiddleClick(TQWidget *w)
|
||
15 years ago
|
{
|
||
|
if ( mWidget->count()==1 ) return;
|
||
|
|
||
|
mWidget->removePage( w );
|
||
|
}
|
||
|
|
||
|
void Test::movedTab(int from, int to)
|
||
|
{
|
||
|
kdDebug() << "Moved tab from index " << from << " to " << to << endl;
|
||
|
}
|
||
|
|
||
|
void Test::toggleLabels(bool state)
|
||
|
{
|
||
|
mLeftWidget->setUsesTextLabel(state);
|
||
|
mLeftWidget->adjustSize();
|
||
|
mRightWidget->setUsesTextLabel(state);
|
||
|
mRightWidget->adjustSize();
|
||
|
mWidget->hide(); // trigger update
|
||
|
mWidget->show();
|
||
|
}
|
||
|
|
||
|
int main(int argc, char** argv )
|
||
|
{
|
||
|
KCmdLineArgs::init(argc, argv, "ktabwidgettest", "ktabwidget test app", "1.0");
|
||
|
KApplication app(argc, argv);
|
||
|
Test *t = new Test();
|
||
|
|
||
|
app.setMainWidget( t );
|
||
|
t->show();
|
||
|
app.exec();
|
||
|
}
|
||
|
|
||
|
#include "ktabwidgettest.moc"
|