2009-02-05 14:21:47 +00:00
|
|
|
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
2009-02-01 00:08:08 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "groupcombobox.hh"
|
|
|
|
|
|
|
|
GroupComboBox::GroupComboBox( QWidget * parent ): QComboBox( parent )
|
|
|
|
{
|
|
|
|
setSizeAdjustPolicy( AdjustToContents );
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupComboBox::fill( Instances::Groups const & groups )
|
|
|
|
{
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned prevId = 0;
|
|
|
|
|
|
|
|
if ( count() )
|
|
|
|
prevId = itemData( currentIndex() ).toUInt();
|
2009-02-01 00:08:08 +00:00
|
|
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
for( unsigned x = 0; x < groups.size(); ++x )
|
|
|
|
{
|
|
|
|
QIcon icon = groups[ x ].icon.size() ?
|
|
|
|
QIcon( ":/flags/" + groups[ x ].icon ) : QIcon();
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
addItem( icon, groups[ x ].name, groups[ x ].id );
|
2009-02-01 00:08:08 +00:00
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
if ( prevId == groups[ x ].id )
|
2009-02-01 00:08:08 +00:00
|
|
|
setCurrentIndex( x );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
void GroupComboBox::setCurrentGroup( unsigned id )
|
2009-02-06 17:04:11 +00:00
|
|
|
{
|
|
|
|
for( int x = 0; x < count(); ++x )
|
|
|
|
{
|
2009-04-10 12:48:40 +00:00
|
|
|
if ( itemData( x ).toUInt() == id )
|
2009-02-06 17:04:11 +00:00
|
|
|
{
|
|
|
|
setCurrentIndex( x );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-10 12:48:40 +00:00
|
|
|
unsigned GroupComboBox::getCurrentGroup() const
|
|
|
|
{
|
|
|
|
if ( !count() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return itemData( currentIndex() ).toUInt();
|
|
|
|
}
|
|
|
|
|