Change DialogSubWindowSelector in order to use check boxes

This commit is contained in:
2015-03-25 01:19:05 +00:00
parent 1423599894
commit c0e1dcd460
8 changed files with 114 additions and 190 deletions
+76 -123
View File
@@ -22,6 +22,8 @@
* \brief Dialog box to select sub windows
*/
#include <QCheckBox>
#include <QGroupBox>
#include "PlaYUVerSubWindowHandle.h"
#include "DialogSubWindowSelector.h"
#include "VideoSubWindow.h"
@@ -29,83 +31,58 @@
namespace plaYUVer
{
DialogSubWindowSelector::DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected, Int maxWindowsSelected ) :
DialogSubWindowSelector::DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected,
Int maxWindowsSelected ) :
QDialog( parent ),
m_uiCategory( uiCategory ),
m_iMinSelectedWindows( minWindowsSelected ),
m_iMaxSlectedWindows( maxWindowsSelected ),
m_pcMainWindowManager( windowManager )
{
QFont titleFont, menusFont;
titleFont.setPointSize( 14 );
titleFont.setBold( true );
titleFont.setWeight( 75 );
menusFont.setBold( true );
menusFont.setWeight( 75 );
QSize windowSize( 350, 80 );
resize( windowSize );
setWindowTitle( "Sub Windows Selection" );
setWindowTitle( "Select desired Sub-Windows" );
QHBoxLayout* MainLayout = new QHBoxLayout( this );
QVBoxLayout* mainLayout = new QVBoxLayout( this );
// Window list and add button
m_comboBoxWindowList = new QComboBox();
QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
sizePolicy.setHeightForWidth( m_comboBoxWindowList->sizePolicy().hasHeightForWidth() );
m_comboBoxWindowList->setSizePolicy( sizePolicy );
m_comboBoxWindowList->setAcceptDrops( true );
minWindowsSelected = minWindowsSelected == 0 ? 1 : minWindowsSelected;
m_pcGroupCheckBox = new QGroupBox( tr( "Exclusive Radio Buttons" ) );
m_pcGroupCheckBox->setLayout( new QVBoxLayout() );
mainLayout->addWidget( m_pcGroupCheckBox );
m_pushButtonAdd = new QPushButton( "Add", this );
m_pushButtonAddAll = new QPushButton( "Add all", this );
m_pushButtonRemove = new QPushButton( "Remove", this );
m_pushButtonRemoveAll = new QPushButton( "Remove All", this );
m_pushButtonRemove->setEnabled( false );
m_pushButtonRemoveAll->setEnabled( false );
// Selected Sub Window List
m_listSelectedWindows = new QListWidget( this );
// Confirmation buttons
m_pushButtonOkCancel = new QDialogButtonBox();
m_pushButtonOkCancel->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
m_pushButtonOkCancel->setOrientation( Qt::Vertical );
m_pushButtonOkCancel->setOrientation( Qt::Horizontal );
m_pushButtonOkCancel->setCenterButtons( false );
m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( false );
// Create Layouts
QVBoxLayout* LeftVLayout = new QVBoxLayout();
LeftVLayout->addWidget( m_comboBoxWindowList );
//LeftVLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
LeftVLayout->addWidget( m_listSelectedWindows );
QVBoxLayout* RightVLayout = new QVBoxLayout();
RightVLayout->addWidget( m_pushButtonAdd );
RightVLayout->addWidget( m_pushButtonAddAll );
RightVLayout->addWidget( m_pushButtonRemove );
RightVLayout->addWidget( m_pushButtonRemoveAll );
RightVLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
RightVLayout->addWidget( m_pushButtonOkCancel );
QHBoxLayout* BottomHLayout = new QHBoxLayout();
BottomHLayout->addWidget( m_pushButtonAddAll );
BottomHLayout->addWidget( m_pushButtonRemoveAll );
BottomHLayout->addWidget( m_pushButtonOkCancel );
// Add components
//MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Expanding, QSizePolicy::Fixed ) );
MainLayout->addLayout( LeftVLayout );
MainLayout->addLayout( RightVLayout );
mainLayout->addLayout( BottomHLayout );
setLayout( MainLayout );
setLayout( mainLayout );
// Create actions
connect( m_pushButtonOkCancel, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( m_pushButtonOkCancel, SIGNAL( rejected() ), this, SLOT( reject() ) );
connect( m_pushButtonAdd, SIGNAL( clicked() ), this, SLOT( addSubWindow() ) );
connect( m_pushButtonAddAll, SIGNAL( clicked() ), this, SLOT( addAllSubWindow() ) );
connect( m_pushButtonRemove, SIGNAL( clicked() ), this, SLOT( removeSubWindow() ) );
connect( m_pushButtonRemoveAll, SIGNAL( clicked() ), this, SLOT( removeAllSubWindow() ) );
QMetaObject::connectSlotsByName( this );
m_mapperWindowsList = new QSignalMapper( this );
connect( m_mapperWindowsList, SIGNAL( mapped(int) ), this, SLOT( toggleSubWindow(int) ) );
updateSubWindowList();
}
@@ -115,49 +92,58 @@ Void DialogSubWindowSelector::updateSubWindowList()
SubWindowHandle *subWindow;
QString currSubWindowName;
m_pcWindowListNames.clear();
QList<SubWindowHandle*> subWindowList = m_pcMainWindowManager->findSubWindow( m_uiCategory );
for( Int i = 0; i < subWindowList.size(); i++ )
m_apcSubWindowList = m_pcMainWindowManager->findSubWindow( m_uiCategory );
QCheckBox* windowCheckBox;
for( Int i = 0; i < m_apcSubWindowList.size(); i++ )
{
subWindow = subWindowList.at( i );
subWindow = m_apcSubWindowList.at( i );
currSubWindowName = subWindow->getWindowName();
if( !m_pcSelectedWindowListNames.contains( currSubWindowName ) )
m_pcWindowListNames.append( currSubWindowName );
windowCheckBox = new QCheckBox( currSubWindowName, this );
connect( windowCheckBox, SIGNAL( stateChanged(int) ), m_mapperWindowsList, SLOT( map() ) );
m_mapperWindowsList->setMapping( windowCheckBox, i );
m_pcGroupCheckBox->layout()->addWidget( windowCheckBox );
m_apcWindowsListCheckBox.append( windowCheckBox );
}
m_comboBoxWindowList->clear();
m_comboBoxWindowList->insertItems( 0, m_pcWindowListNames );
m_comboBoxWindowList->setCurrentIndex( -1 );
Bool enableAddAll = true;
}
if( m_iMaxSlectedWindows >= 0 )
Void DialogSubWindowSelector::selectSubWindow( SubWindowHandle* subWindow )
{
Int iIdx = m_apcSubWindowList.indexOf( subWindow );
if( iIdx >= 0 )
{
if( m_pcSelectedWindowListNames.size() >= m_iMaxSlectedWindows )
{
m_pushButtonAdd->setEnabled( false );
}
else
{
m_pushButtonAdd->setEnabled( true );
}
if( m_pcWindowListNames.size() > m_iMaxSlectedWindows )
{
enableAddAll = false;
}
m_apcWindowsListCheckBox.at( iIdx )->setChecked( true );
m_apcSelectedSubWindowList.append( m_apcSubWindowList.at( iIdx ) );
}
m_pushButtonAddAll->setEnabled( enableAddAll );
}
if( m_pcSelectedWindowListNames.size() > 0 )
// ----------------------- Slot Functions -----------------------
Void DialogSubWindowSelector::toggleSubWindow( Int idx )
{
Bool isChecked = m_apcWindowsListCheckBox.at( idx )->isChecked();
if( isChecked )
{
m_apcSelectedSubWindowList.append( m_apcSubWindowList.at( idx ) );
}
else
{
m_apcSelectedSubWindowList.removeOne( m_apcSubWindowList.at( idx ) );
}
if( m_apcSelectedSubWindowList.size() > 0 )
{
m_pushButtonRemove->setEnabled( true );
m_pushButtonRemoveAll->setEnabled( true );
}
else
{
m_pushButtonRemove->setEnabled( false );
m_pushButtonRemoveAll->setEnabled( false );
}
if( m_pcSelectedWindowListNames.size() >= m_iMinSelectedWindows )
if( m_apcSelectedSubWindowList.size() >= m_iMinSelectedWindows )
{
m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( true );
}
@@ -166,68 +152,35 @@ Void DialogSubWindowSelector::updateSubWindowList()
m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( false );
}
}
Void DialogSubWindowSelector::setSubWindowList( QStringList cWindowListNames )
{
m_pcSelectedWindowListNames = cWindowListNames;
m_listSelectedWindows->clear();
m_listSelectedWindows->insertItems( 0, cWindowListNames );
updateSubWindowList();
}
// ----------------------- Slot Functions -----------------------
Void DialogSubWindowSelector::addSubWindow()
{
Int iSelectedIdx = m_comboBoxWindowList->currentIndex();
if( iSelectedIdx >= 0 )
if( m_iMaxSlectedWindows > 0 )
{
m_pcSelectedWindowListNames.append( m_pcWindowListNames.at( iSelectedIdx ) );
m_listSelectedWindows->clear();
m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames );
updateSubWindowList();
if( m_apcSelectedSubWindowList.size() >= m_iMaxSlectedWindows )
{
m_pcGroupCheckBox->setEnabled( false );
}
else
{
m_pcGroupCheckBox->setEnabled( true );
}
}
}
Void DialogSubWindowSelector::addAllSubWindow()
{
if( m_iMaxSlectedWindows <= 0 || m_pcWindowListNames.size() <= m_iMaxSlectedWindows )
for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ )
{
for( Int i = 0; i < m_pcWindowListNames.size(); i++ )
{
m_pcSelectedWindowListNames.append( m_pcWindowListNames.at( i ) );
}
m_listSelectedWindows->clear();
m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames );
updateSubWindowList();
}
}
Void DialogSubWindowSelector::removeSubWindow()
{
QList<QListWidgetItem*> selectedWindows = m_listSelectedWindows->selectedItems();
if( selectedWindows.size() )
{
for( Int i = 0; i < selectedWindows.size(); i++ )
{
QString currName = selectedWindows.at( i )->text();
Int indexCurrName = m_pcSelectedWindowListNames.indexOf( currName );
m_pcSelectedWindowListNames.removeAt( indexCurrName );
m_listSelectedWindows->removeItemWidget( selectedWindows[i] );
}
m_listSelectedWindows->clear();
m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames );
updateSubWindowList();
m_apcWindowsListCheckBox.at( i )->setChecked( true );
m_apcSelectedSubWindowList.append( m_apcSubWindowList.at( i ) );
}
}
Void DialogSubWindowSelector::removeAllSubWindow()
{
QList<QListWidgetItem*> selectedWindows = m_listSelectedWindows->selectedItems();
m_listSelectedWindows->clear();
m_pcSelectedWindowListNames.clear();
updateSubWindowList();
for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ )
{
m_apcWindowsListCheckBox.at( i )->setChecked( false );
}
m_apcSelectedSubWindowList.clear();
}
} // Namespace SCode