diff options
author | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-04-21 11:53:35 +0200 |
---|---|---|
committer | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-04-21 11:53:35 +0200 |
commit | 2a117cc570574099839da41a5ae9fbb2a5ca9e55 (patch) | |
tree | 6107da409f9c7f07c0ffa0869a26a161b097aea7 /src/mycombobox.cpp | |
parent | aa68b7bd585a157e8952881e87e2c09de6ec742f (diff) |
Imported Upstream version 14.3.0
Diffstat (limited to 'src/mycombobox.cpp')
-rw-r--r-- | src/mycombobox.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/mycombobox.cpp b/src/mycombobox.cpp index c0e8fcd..8541557 100644 --- a/src/mycombobox.cpp +++ b/src/mycombobox.cpp @@ -1,5 +1,5 @@ /* smplayer, GUI front-end for mplayer. - Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net> + Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,9 @@ */ #include "mycombobox.h" +#include <QDir> +#include <QStringListModel> +#include <QDebug> MyComboBox::MyComboBox( QWidget * parent ) : QComboBox(parent) { @@ -59,3 +62,31 @@ void MyFontComboBox::setCurrentText( const QString & text ) { else setItemText(currentIndex(), text); } + +void MyFontComboBox::setFontsFromDir(const QString & fontdir) { + QString current_text = currentText(); + + if (fontdir.isEmpty()) { + QFontDatabase::removeAllApplicationFonts(); + clear(); + setWritingSystem(QFontDatabase::Any); + } else { + QFontDatabase fdb; + QStringList fontnames; + QStringList fontfiles = QDir(fontdir).entryList(QStringList() << "*.ttf" << "*.otf", QDir::Files); + for (int n=0; n < fontfiles.count(); n++) { + qDebug() << "MyFontComboBox::setFontsFromDir: adding font:" << fontfiles[n]; + int id = fdb.addApplicationFont(fontdir +"/"+ fontfiles[n]); + fontnames << fdb.applicationFontFamilies(id); + } + //fdb.removeAllApplicationFonts(); + fontnames.removeDuplicates(); + qDebug() << "MyFontComboBox::setFontsFromDir: fontnames:" << fontnames; + clear(); + QStringListModel *m = qobject_cast<QStringListModel *>(model()); + if (m) m->setStringList(fontnames); + } + + setCurrentText(current_text); +} + |