1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "mycombobox.h"
|
---|
20 | #include <QDir>
|
---|
21 | #include <QStringListModel>
|
---|
22 | #include <QDebug>
|
---|
23 |
|
---|
24 | MyComboBox::MyComboBox( QWidget * parent ) : QComboBox(parent)
|
---|
25 | {
|
---|
26 | }
|
---|
27 |
|
---|
28 | MyComboBox::~MyComboBox()
|
---|
29 | {
|
---|
30 | }
|
---|
31 |
|
---|
32 | void MyComboBox::setCurrentText( const QString & text ) {
|
---|
33 | int i = findText(text);
|
---|
34 | if (i != -1)
|
---|
35 | setCurrentIndex(i);
|
---|
36 | else if (isEditable())
|
---|
37 | setEditText(text);
|
---|
38 | else
|
---|
39 | setItemText(currentIndex(), text);
|
---|
40 | }
|
---|
41 |
|
---|
42 | void MyComboBox::insertStringList( const QStringList & list, int index ) {
|
---|
43 | insertItems((index < 0 ? count() : index), list);
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | MyFontComboBox::MyFontComboBox( QWidget * parent ) : QFontComboBox(parent)
|
---|
49 | {
|
---|
50 | }
|
---|
51 |
|
---|
52 | MyFontComboBox::~MyFontComboBox()
|
---|
53 | {
|
---|
54 | }
|
---|
55 |
|
---|
56 | void MyFontComboBox::setCurrentText( const QString & text ) {
|
---|
57 | int i = findText(text);
|
---|
58 | if (i != -1)
|
---|
59 | setCurrentIndex(i);
|
---|
60 | else if (isEditable())
|
---|
61 | setEditText(text);
|
---|
62 | else
|
---|
63 | setItemText(currentIndex(), text);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void MyFontComboBox::setFontsFromDir(const QString & fontdir) {
|
---|
67 | QString current_text = currentText();
|
---|
68 |
|
---|
69 | if (fontdir.isEmpty()) {
|
---|
70 | QFontDatabase::removeAllApplicationFonts();
|
---|
71 | clear();
|
---|
72 | setWritingSystem(QFontDatabase::Any);
|
---|
73 | } else {
|
---|
74 | QFontDatabase fdb;
|
---|
75 | QStringList fontnames;
|
---|
76 | QStringList fontfiles = QDir(fontdir).entryList(QStringList() << "*.ttf" << "*.otf", QDir::Files);
|
---|
77 | for (int n=0; n < fontfiles.count(); n++) {
|
---|
78 | qDebug() << "MyFontComboBox::setFontsFromDir: adding font:" << fontfiles[n];
|
---|
79 | int id = fdb.addApplicationFont(fontdir +"/"+ fontfiles[n]);
|
---|
80 | fontnames << fdb.applicationFontFamilies(id);
|
---|
81 | }
|
---|
82 | //fdb.removeAllApplicationFonts();
|
---|
83 | fontnames.removeDuplicates();
|
---|
84 | qDebug() << "MyFontComboBox::setFontsFromDir: fontnames:" << fontnames;
|
---|
85 | clear();
|
---|
86 | QStringListModel *m = qobject_cast<QStringListModel *>(model());
|
---|
87 | if (m) m->setStringList(fontnames);
|
---|
88 | }
|
---|
89 |
|
---|
90 | setCurrentText(current_text);
|
---|
91 | }
|
---|
92 |
|
---|