forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstylescombobox.cc
47 lines (42 loc) · 980 Bytes
/
stylescombobox.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "stylescombobox.hh"
#include "config.hh"
#include <QDir>
StylesComboBox::StylesComboBox( QWidget * parent ):
QComboBox( parent )
{
fill();
setVisible( count() > 1 );
}
void StylesComboBox::fill()
{
clear();
addItem( tr( "None" ) );
QString stylesDir = Config::getStylesDir();
if( !stylesDir.isEmpty() )
{
QDir dir( stylesDir );
QStringList styles = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::LocaleAware );
addItems( styles );
}
}
void StylesComboBox::setCurrentStyle( QString const & style )
{
int nom = 0;
if( !style.isEmpty() )
{
for( int i = 1; i < count(); i++ )
if( style.compare( itemText( i ) ) == 0 )
{
nom = i;
break;
}
}
setCurrentIndex( nom );
}
QString StylesComboBox::getCurrentStyle() const
{
if( currentIndex() == 0 )
return QString();
return itemText( currentIndex() );
}