Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poprawki frmListSubtitles #57

Merged
merged 3 commits into from
Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 26 additions & 48 deletions src/forms/frmlistsubtitles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "frmlistsubtitles.h"
#include "qnapi.h"

#include "subdatawidget.h"

#include <QMessageBox>
#include <QtWidgets/QHeaderView>
#include <QDesktopWidget>
Expand All @@ -32,83 +34,59 @@ frmListSubtitles::frmListSubtitles(QWidget *parent, Qt::WindowFlags f)
void frmListSubtitles::setFileName(const QString & name)
{
ui.lbSelectSubtitles->setText(QString( "Z poniższej listy wybierz napisy, które"
" chcesz dopasować do pliku <b>%1</b>:")
" chcesz dopasować do pliku<br><br><b>%1</b>")
.arg(name));
}

void frmListSubtitles::setSubtitlesList(const QList<QNapiSubtitleInfo> & list)
void frmListSubtitles::setSubtitlesList(QList<QNapiSubtitleInfo> list)
{
QNapi n;
n.addEngines(n.enumerateEngines());

ui.twSubtitles->clear();
ui.twSubtitles->setColumnCount(4);
ui.twSubtitles->setRowCount(list.size());

ui.twSubtitles->horizontalHeader()->hide();
ui.twSubtitles->verticalHeader()->hide();
ui.twSubtitles->verticalHeader()->setDefaultSectionSize(20);
ui.twSubtitles->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);

int i = 0, good = 0, bad = 0;
int i = 0, goodCount = 0, badCount = 0;
foreach(QNapiSubtitleInfo s, list)
{
QTableWidgetItem *item;

bool highlight = (s.resolution != SUBTITLE_UNKNOWN);

QBrush brush((s.resolution == SUBTITLE_GOOD) ? QColor(qRgb(200, 255, 200)) : QColor(qRgb(255, 200, 200)));
QBrush brush((s.resolution == SUBTITLE_GOOD) ? QColor(qRgb(200, 255, 200)) : QColor(qRgb(255, 200, 200)));

QNapiAbstractEngine *e = n.engineByName(s.engine);
QListWidgetItem *listItem = new QListWidgetItem();

ui.twSubtitles->addItem(listItem);

if(highlight && (s.resolution == SUBTITLE_GOOD))
++good;
else if(highlight && (s.resolution == SUBTITLE_BAD))
++bad;
subDataWidget *subData = new subDataWidget();

if(highlight) listItem->setBackground(brush);

QString lang_path = QString(":/languages/") + s.lang + ".png";
if(QFile::exists(lang_path))
{
item = new QTableWidgetItem(QIcon(lang_path), "");
}
else
{
item = new QTableWidgetItem(s.lang);

if(highlight && (s.resolution == SUBTITLE_GOOD)){
++goodCount;
} else if(highlight && (s.resolution == SUBTITLE_BAD)){
++badCount;
}

if(highlight) item->setBackground(brush);
item->setToolTip(s.comment);
ui.twSubtitles->setItem(i, 1, item);

item = new QTableWidgetItem(s.name);
if(highlight) item->setBackground(brush);
item->setToolTip(s.comment);
ui.twSubtitles->setItem(i, 2, item);
subData->setSubData(s.name, s.format, QIcon(lang_path), e->engineIcon());

item = new QTableWidgetItem(s.format);
if(highlight) item->setBackground(brush);
item->setToolTip(s.comment);
ui.twSubtitles->setItem(i, 3, item);

QNapiAbstractEngine *e = n.engineByName(s.engine);
if(e)
{
item = new QTableWidgetItem(e->engineIcon(), "");
if(highlight) item->setBackground(brush);
item->setToolTip(s.comment);
ui.twSubtitles->setItem(i, 0, item);
}
ui.twSubtitles->setItemWidget(listItem, subData);
listItem->setSizeHint(subData->sizeHint());

++i;
}

ui.twSubtitles->resizeColumnsToContents();

if(good == 0) ui.lbGreenHint->hide();
if(bad == 0) ui.lbRedHint->hide();
if(goodCount == 0) ui.lbGreenHint->hide();
if(badCount == 0) ui.lbRedHint->hide();
}

int frmListSubtitles::getSelectedIndex()
{
return ui.twSubtitles->currentRow();
QModelIndexList selected = ui.twSubtitles->selectionModel()->selectedIndexes();
return selected.first().row();
}

void frmListSubtitles::accept()
Expand Down
2 changes: 1 addition & 1 deletion src/forms/frmlistsubtitles.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Q_OBJECT
public slots:

void setFileName(const QString & name);
void setSubtitlesList(const QList<QNapiSubtitleInfo> & list);
void setSubtitlesList(QList<QNapiSubtitleInfo> list);
int getSelectedIndex();
void accept();

Expand Down
24 changes: 18 additions & 6 deletions src/forms/subdatawidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ subDataWidget::~subDataWidget()
delete ui;
}

void subDataWidget::setSubData(const QIcon &stateIcon, QString name, const QIcon &langIcon, const QIcon &engineIcon){

void subDataWidget::clearAll(){
ui->place1->clear();
ui->place2->clear();
ui->place3->clear();
ui->place4->clear();
}

void subDataWidget::setSubData(const QIcon &stateIcon, QString name, const QIcon &langIcon, const QIcon &engineIcon){

ui->place1->setPixmap(stateIcon.pixmap(16));
ui->place2->setText(name);
Expand All @@ -27,14 +29,24 @@ void subDataWidget::setSubData(const QIcon &stateIcon, QString name, const QIcon

void subDataWidget::setSubData(const QIcon &stateIcon, QString name){

ui->place1->clear();
ui->place2->clear();
ui->place3->clear();
ui->place4->clear();
this->clearAll();

ui->place3->hide();
ui->place4->hide();

ui->place1->setPixmap(stateIcon.pixmap(16));
ui->place2->setText(name);
}

void subDataWidget::setSubData(QString name, QString ext, const QIcon &langIcon, const QIcon &engineIcon){

this->clearAll();

ui->place1->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
ui->place2->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);

ui->place1->setText(name);
ui->place2->setText(ext);
ui->place3->setPixmap(langIcon.pixmap(16));
ui->place4->setPixmap(engineIcon.pixmap(16));
}
6 changes: 4 additions & 2 deletions src/forms/subdatawidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class subDataWidget : public QWidget

public:
explicit subDataWidget(QWidget *parent = 0);
void setSubData(const QIcon &_stateIcon, QString _name, const QIcon &_langIcon, const QIcon &_engineIcon);
void setSubData(const QIcon &_stateIcon, QString _name);
void setSubData(const QIcon &stateIcon, QString name, const QIcon &langIcon, const QIcon &engineIcon);
void setSubData(const QIcon &stateIcon, QString name);
void setSubData(QString name, QString ext, const QIcon &langIcon, const QIcon &engineIcon);
void clearAll();
~subDataWidget();

private:
Expand Down
63 changes: 30 additions & 33 deletions ui/frmlistsubtitles.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,13 @@
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="lbSelectSubtitles">
<property name="text">
<string>Z poniższej listy wybierz napisy, które chcesz dopasować do pliku &lt;b&gt;film.avi&lt;/b&gt;:</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Z poniższej listy wybierz napisy, które chcesz dopasować do pliku&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;film.avi&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QTableWidget" name="twSubtitles">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="pbDownload">
<property name="text">
Expand Down Expand Up @@ -106,6 +78,31 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QListWidget" name="twSubtitles">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
Expand Down Expand Up @@ -151,12 +148,12 @@
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>166</x>
<y>109</y>
<x>286</x>
<y>146</y>
</hint>
<hint type="destinationlabel">
<x>480</x>
<y>320</y>
<x>525</x>
<y>321</y>
</hint>
</hints>
</connection>
Expand Down
6 changes: 0 additions & 6 deletions ui/subDataWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
</property>
<item>
<widget class="QLabel" name="place1">
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>[]</string>
</property>
Expand Down