-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.cpp
More file actions
132 lines (112 loc) · 3.93 KB
/
Window.cpp
File metadata and controls
132 lines (112 loc) · 3.93 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
#include "Window.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QFrame>
#include <QTimeEdit>
#include <QHeaderView>
Window::Window()
{
resize(680, -1);
QHBoxLayout *hlayout = new QHBoxLayout;
// Le tableau, à gauche
{
m_pTable = new QTableWidget;
m_pTable->setSelectionMode(QAbstractItemView::SingleSelection);
m_pTable->setColumnCount(3);
QStringList labels;
labels << tr("Position du sous-titre") << tr("Position voulue")
<< tr("Supprimer le point");
m_pTable->setHorizontalHeaderLabels(labels);
m_pTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
addPoint(); addPoint();
hlayout->addWidget(m_pTable);
}
// Le reste, à droite
{
QVBoxLayout *vlayout = new QVBoxLayout;
QPushButton *add = new QPushButton(tr("Ajouter un point"));
connect(add, SIGNAL(clicked()), this, SLOT(addPoint()));
vlayout->addWidget(add);
m_pSourceFile = new FileSelector(FileSelector::READ);
vlayout->addWidget(m_pSourceFile);
m_pTargetFile = new FileSelector(FileSelector::WRITE);
vlayout->addWidget(m_pTargetFile);
QPushButton *go = new QPushButton(tr("Appliquer"));
connect(go, SIGNAL(clicked()), this, SLOT(process()));
vlayout->addWidget(go);
hlayout->addLayout(vlayout);
}
setLayout(hlayout);
show();
}
void Window::addPoint()
{
// Agrandit le tableau
int row = m_pTable->rowCount();
m_pTable->setRowCount(row + 1);
// Remplit la nouvelle ligne
m_pTable->setCellWidget(row, 0, new QTimeEdit);
m_pTable->setCellWidget(row, 1, new QTimeEdit);
QPushButton *r = new RemoveButton(row);
connect(r, SIGNAL(removeRow(int)), this, SLOT(removePoint(int)));
m_pTable->setCellWidget(row, 2, r);
}
void Window::removePoint(int row)
{
m_pTable->removeRow(row);
for(; row < m_pTable->rowCount(); row++)
qobject_cast<RemoveButton*>(m_pTable->cellWidget(row, 2))->setRow(row);
}
RemoveButton::RemoveButton(int row)
: QPushButton::QPushButton(tr("Supprimer")), m_iRow(row)
{
connect(this, SIGNAL(clicked()), this, SLOT(onclick()));
}
void RemoveButton::setRow(int row)
{
m_iRow = row;
}
void RemoveButton::onclick()
{
emit removeRow(m_iRow);
}
FileSelector::FileSelector(EOpenType type, QString text, QWidget *parent)
: QFrame::QFrame(parent), m_eType(type)
{
QHBoxLayout *hlayout = new QHBoxLayout;
m_pLineEdit = new QLineEdit;
hlayout->addWidget(m_pLineEdit);
m_pLineEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
QPushButton *searchButton = new QPushButton(tr("Parcourir"));
connect(searchButton, SIGNAL(clicked()), this, SLOT(search()));
hlayout->addWidget(searchButton);
setLayout(hlayout);
}
void FileSelector::search()
{
QString ret;
if(m_eType == FileSelector::READ)
ret = QFileDialog::getOpenFileName(this, tr("Choisissez le fichier "
".srt de départ"), "",
tr("Sous-titre au format SubRip (*.srt);;Tous les fichiers (*.*)"));
else
ret = QFileDialog::getSaveFileName(this, tr("Choisissez le fichier "
".srt de départ"), "",
tr("Sous-titre au format SubRip (*.srt);;Tous les fichiers (*.*)"));
if(!ret.isNull())
m_pLineEdit->setText(ret);
}
QString FileSelector::path() const
{
return m_pLineEdit->text();
}
void FileSelector::setPath(QString text)
{
m_pLineEdit->setText(text);
}