void TestSplitter::SplitVertical()
{
Split( sender(), Qt::Vertical );
}
void TestSplitter::SplitHorizontal()
{
Split( sender(), Qt::Horizontal);
}
void TestSplitter
::Split( QObject* sender, Qt
::Orientation splitOrientation
) {
// Get sender's parent(QSplitter object).
QSplitter* splitter
= qobject_cast<QSplitter
*>
( sender
->parent
() );
if ( splitter )
{
// Check if splitter has already been splitted.
QVariant splitted
= splitter
->property
( "Splitted" );
if ( !splitted.toBool() )
{
// Set orientation.
splitter->setOrientation( splitOrientation );
// Add widget splitter object.
WidgetSplitter* widgetSplitter = new WidgetSplitter( splitter );
splitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
splitter->setProperty( "Splitted", true );
}
else if ( splitOrientation == splitter->orientation() )
{
// Add widget splitter object.
WidgetSplitter* widgetSplitter = new WidgetSplitter( splitter );
splitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
}
else
{
// We must destroy the current widget splitter and add replace it
// with a QSplitter containing 2 widget splitter following
// specified orientation.
QWidget* widget
= static_cast<QWidget
*>
(sender
);
// Get index of widget splitter.
int index = splitter->indexOf( widget );
widget->setParent( NULL );
widget->deleteLater();
newSplitter->setOrientation( splitOrientation );
newSplitter->setChildrenCollapsible( false );
WidgetSplitter* widgetSplitter = new WidgetSplitter( newSplitter );
newSplitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
widgetSplitter = new WidgetSplitter( newSplitter );
newSplitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
splitter->insertWidget( index, newSplitter );
newSplitter->show();
}
}
}
void TestSplitter::SplitVertical()
{
Split( sender(), Qt::Vertical );
}
void TestSplitter::SplitHorizontal()
{
Split( sender(), Qt::Horizontal);
}
void TestSplitter::Split( QObject* sender, Qt::Orientation splitOrientation )
{
// Get sender's parent(QSplitter object).
QSplitter* splitter = qobject_cast<QSplitter*>( sender->parent() );
if ( splitter )
{
// Check if splitter has already been splitted.
QVariant splitted = splitter->property( "Splitted" );
if ( !splitted.toBool() )
{
// Set orientation.
splitter->setOrientation( splitOrientation );
// Add widget splitter object.
WidgetSplitter* widgetSplitter = new WidgetSplitter( splitter );
splitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
splitter->setProperty( "Splitted", true );
}
else if ( splitOrientation == splitter->orientation() )
{
// Add widget splitter object.
WidgetSplitter* widgetSplitter = new WidgetSplitter( splitter );
splitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
}
else
{
// We must destroy the current widget splitter and add replace it
// with a QSplitter containing 2 widget splitter following
// specified orientation.
QWidget* widget = static_cast<QWidget*>(sender);
// Get index of widget splitter.
int index = splitter->indexOf( widget );
widget->setParent( NULL );
widget->deleteLater();
QSplitter* newSplitter = new QSplitter();
newSplitter->setOrientation( splitOrientation );
newSplitter->setChildrenCollapsible( false );
WidgetSplitter* widgetSplitter = new WidgetSplitter( newSplitter );
newSplitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
widgetSplitter = new WidgetSplitter( newSplitter );
newSplitter->addWidget( widgetSplitter );
widgetSplitter->show();
connect( widgetSplitter, SIGNAL(SplitVertical()), this, SLOT(SplitVertical()) );
connect( widgetSplitter, SIGNAL(SplitHorizontal()), this, SLOT(SplitHorizontal()) );
connect( widgetSplitter, SIGNAL(Unsplit()), this, SLOT(Unsplit()) );
splitter->insertWidget( index, newSplitter );
newSplitter->show();
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks