[114] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[114] | 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 |
|
---|
| 20 | #include "subchooserdialog.h"
|
---|
| 21 |
|
---|
| 22 | static Qt::CheckState CurItemCheckState = Qt::Unchecked;
|
---|
| 23 |
|
---|
| 24 | SubChooserDialog::SubChooserDialog(QWidget * parent, Qt::WindowFlags f)
|
---|
| 25 | : QDialog(parent, f )
|
---|
| 26 | {
|
---|
| 27 | setupUi(this);
|
---|
| 28 |
|
---|
| 29 | listWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
---|
| 30 |
|
---|
| 31 | connect(selectAll, SIGNAL(clicked(bool)), this, SLOT(selectAllClicked(bool)));
|
---|
| 32 | connect(selectNone, SIGNAL(clicked(bool)), this, SLOT(selectNoneClicked(bool)));
|
---|
| 33 | connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listItemClicked(QListWidgetItem*)));
|
---|
| 34 | connect(listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(listItemPressed(QListWidgetItem*)));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | SubChooserDialog::~SubChooserDialog()
|
---|
| 38 | {
|
---|
| 39 |
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | void SubChooserDialog::selectAllClicked(bool) {
|
---|
| 43 | for (int k = 0; k < listWidget->count(); k++)
|
---|
| 44 | listWidget->item(k)->setCheckState(Qt::Checked);
|
---|
| 45 |
|
---|
| 46 | listWidget->setFocus();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void SubChooserDialog::selectNoneClicked(bool) {
|
---|
| 50 | for (int k = 0; k < listWidget->count(); k++)
|
---|
| 51 | listWidget->item(k)->setCheckState(Qt::Unchecked);
|
---|
| 52 |
|
---|
| 53 | listWidget->setFocus();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void SubChooserDialog::listItemClicked(QListWidgetItem* item) {
|
---|
| 57 | if (item->checkState() == CurItemCheckState)
|
---|
| 58 | {
|
---|
| 59 | //Clicked on the list item (not checkbox)
|
---|
| 60 | if (item->checkState() == Qt::Checked)
|
---|
| 61 | {
|
---|
| 62 | item->setCheckState(Qt::Unchecked);
|
---|
| 63 | }
|
---|
| 64 | else
|
---|
| 65 | item->setCheckState(Qt::Checked);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | //else - clicked on the checkbox itself, do nothing
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void SubChooserDialog::listItemPressed(QListWidgetItem* item) {
|
---|
| 72 | CurItemCheckState = item->checkState();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void SubChooserDialog::addFile(QString filename) {
|
---|
| 76 | QListWidgetItem* item = new QListWidgetItem(listWidget);
|
---|
| 77 | item->setText(filename);
|
---|
| 78 | item->setCheckState(Qt::Unchecked);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | QStringList SubChooserDialog::selectedFiles() {
|
---|
| 82 | QStringList files;
|
---|
| 83 |
|
---|
| 84 | for (int n = 0; n < listWidget->count(); n++) {
|
---|
| 85 | QListWidgetItem * i = listWidget->item(n);
|
---|
| 86 | if (i && i->checkState() == Qt::Checked) {
|
---|
| 87 | files.append(i->text());
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return files;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | void SubChooserDialog::retranslateStrings() {
|
---|
| 95 | retranslateUi(this);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | // Language change stuff
|
---|
| 99 | void SubChooserDialog::changeEvent(QEvent *e) {
|
---|
| 100 | if (e->type() == QEvent::LanguageChange) {
|
---|
| 101 | retranslateStrings();
|
---|
| 102 | } else {
|
---|
| 103 | QDialog::changeEvent(e);
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | #include "moc_subchooserdialog.cpp"
|
---|
| 108 |
|
---|