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

Upgrade to Qt6 #335

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion src/configeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with Subtivals. If not, see <http://www.gnu.org/licenses/>
**/
#include <QColorDialog>
#include <QDesktopWidget>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPainter>
Expand Down
40 changes: 17 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <QFile>
#include <QIODevice>
#include <QSettings>
#include <QSslCertificate>
#include <QSslSocket>
#include <QStyleFactory>
#include <QTranslator>
#include <QtCore/QFileInfo>
#include <QByteArray>
#include <QIODevice>
#include <QLocale>

#include "configeditor.h"
#include "mainwindow.h"
Expand All @@ -31,13 +32,6 @@
#include "weblive.h"

int main(int argc, char *argv[]) {
// Load Let's Encrypts issuer certificate (WebLive feature).
QFile file(":/ssl/lets-encrypt-r3.pem");
file.open(QIODevice::ReadOnly);
const QByteArray bytes = file.readAll();
const QSslCertificate certificate(bytes);
QSslSocket::addDefaultCaCertificate(certificate);

// Load settings from profile.
QSettings::setDefaultFormat(QSettings::IniFormat);
QCoreApplication::setOrganizationName("Subtivals");
Expand All @@ -63,40 +57,40 @@ int main(int argc, char *argv[]) {
WebLive live;

// Live
QObject::connect(w.player(), SIGNAL(on(Subtitle *)), &live,
SLOT(addSubtitle(Subtitle *)));
QObject::connect(w.player(), SIGNAL(off(Subtitle *)), &live,
SLOT(remSubtitle(Subtitle *)));
QObject::connect(w.player(), SIGNAL(on(Subtitle*)), &live,
SLOT(addSubtitle(Subtitle*)));
QObject::connect(w.player(), SIGNAL(off(Subtitle*)), &live,
SLOT(remSubtitle(Subtitle*)));
QObject::connect(w.player(), SIGNAL(clear()), &live, SLOT(clearSubtitles()),
Qt::DirectConnection);
QObject::connect(w.configEditor(), SIGNAL(webliveEnabled(bool)), &live,
SLOT(enable(bool)));
QObject::connect(&live, SIGNAL(connected(bool, QString)), w.configEditor(),
SLOT(webliveConnected(bool, QString)));
QObject::connect(&live, SIGNAL(connected(bool,QString)), w.configEditor(),
SLOT(webliveConnected(bool,QString)));
w.configEditor()->enableWeblive(live.configured());

// Projection screen
QObject::connect(w.player(), SIGNAL(on(Subtitle *)), &f,
SLOT(addSubtitle(Subtitle *)));
QObject::connect(w.player(), SIGNAL(off(Subtitle *)), &f,
SLOT(remSubtitle(Subtitle *)));
QObject::connect(w.player(), SIGNAL(on(Subtitle*)), &f,
SLOT(addSubtitle(Subtitle*)));
QObject::connect(w.player(), SIGNAL(off(Subtitle*)), &f,
SLOT(remSubtitle(Subtitle*)));
QObject::connect(w.player(), SIGNAL(clear()), &f, SLOT(clearSubtitles()),
Qt::DirectConnection);
QObject::connect(&w, SIGNAL(toggleHide(bool)), &f, SLOT(toggleHide(bool)));
QObject::connect(&w, SIGNAL(screenResizable(bool)), &f,
SLOT(screenResizable(bool)));
QObject::connect(&f, SIGNAL(geometryChanged(QRect)), w.configEditor(),
SLOT(screenChanged(QRect)));
QObject::connect(w.configEditor(), SIGNAL(changeScreen(int, QRect)), &f,
SLOT(changeGeometry(int, QRect)));
QObject::connect(w.configEditor(), SIGNAL(changeScreen(int,QRect)), &f,
SLOT(changeGeometry(int,QRect)));
QObject::connect(w.configEditor(), SIGNAL(hideDesktop(bool)), &f,
SLOT(toggleHideDesktop(bool)));
QObject::connect(w.configEditor(), SIGNAL(rotate(double)), &f,
SLOT(rotate(double)));
QObject::connect(w.configEditor(), SIGNAL(color(QColor)), &f,
SLOT(color(QColor)));
QObject::connect(w.configEditor(), SIGNAL(outline(QColor, int)), &f,
SLOT(outline(QColor, int)));
QObject::connect(w.configEditor(), SIGNAL(outline(QColor,int)), &f,
SLOT(outline(QColor,int)));
QObject::connect(w.configEditor(), SIGNAL(styleChanged()), &f,
SLOT(repaint()));

Expand Down
33 changes: 19 additions & 14 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
* You should have received a copy of the GNU General Public License
* along with Subtivals. If not, see <http://www.gnu.org/licenses/>
**/
#include <QtCore/QByteArray>
#include <QtCore/QFile>
#include <QtCore/QSettings>
#include <QtCore/QTextCodec>
#include <QtCore/QTextStream>
#include <QtCore/QThread>
#include <QtCore/QUrl>
#include <QtCore/QtGlobal>

#include <QDesktopServices>
#include <QDesktopWidget>
#include <QFile>
#include <QFileDialog>
#include <QFileSystemWatcher>
#include <QKeyEvent>
#include <QMessageBox>
#include <QMimeData>
#include <QPainter>
#include <QScrollBar>
#include <QSettings>
#include <QStyle>
#include <QStyledItemDelegate>
#include <QTextCodec>
#include <QThread>
#include <QWidget>


#include "configeditor.h"
#include "mainwindow.h"
Expand All @@ -41,6 +43,7 @@
#include "ui_mainwindow.h"
#include "wizard.h"

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
/**
* A small delegate class to allow rich text rendering in main table cells.
*/
Expand Down Expand Up @@ -102,6 +105,7 @@ class SubtitleDurationDelegate : public QStyledItemDelegate {
painter->restore();
}
};
#endif

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), m_script(nullptr),
Expand All @@ -113,12 +117,14 @@ MainWindow::MainWindow(QWidget *parent)
m_scriptProperties(new QLabel(this)), m_countDown(new QLabel(this)) {
ui->setupUi(this);
m_defaultPalette = qApp->palette();
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
ui->tableWidget->setItemDelegateForColumn(COLUMN_START,
new SubtitleDurationDelegate());
ui->tableWidget->setItemDelegateForColumn(COLUMN_END,
new SubtitleDurationDelegate());
ui->tableWidget->setItemDelegateForColumn(COLUMN_TEXT,
new SubtitleTextDelegate());
#endif
ui->tableWidget->hideColumn(COLUMN_COMMENTS);

ui->tableWidget->installEventFilter(this);
Expand Down Expand Up @@ -306,7 +312,7 @@ void MainWindow::showEvent(QShowEvent *) {
resize(settings.value("size", size()).toSize());

// Place window at center, below black screen by default.
QRect screenGeom = qApp->desktop()->screenGeometry();
QRect screenGeom = qApp->primaryScreen()->geometry();
int center = (screenGeom.width() - geometry().width()) / 2;
int decorationHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
QPoint pos(center, DEFAULT_HEIGHT + decorationHeight);
Expand Down Expand Up @@ -382,7 +388,6 @@ void MainWindow::actionOperatorPrintout() {
}

QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
out << m_script->exportList(Script::CSV);
file.close();
Expand Down Expand Up @@ -951,15 +956,15 @@ void MainWindow::subtitleChanged(QList<Subtitle *> p_currentSubtitles) {
}

void MainWindow::highlightSubtitles(qlonglong elapsed) {
QColor off = qApp->palette().color(QPalette::Base);
QColor on = qApp->palette().color(QPalette::Highlight).lighter(130);
QColor next = qApp->palette().color(QPalette::Highlight).lighter(170);
QBrush off = QBrush(qApp->palette().color(QPalette::Base));
QBrush on = QBrush(qApp->palette().color(QPalette::Highlight).lighter(130));
QBrush next = QBrush(qApp->palette().color(QPalette::Highlight).lighter(170));

// First reset all
for (int row = 0; row < ui->tableWidget->rowCount(); row++) {
for (int col = 0; col < ui->tableWidget->columnCount(); col++) {
QTableWidgetItem *item = ui->tableWidget->item(row, col);
item->setBackgroundColor(off);
item->setBackground(off);
QFont f = item->font();
f.setBold(false);
item->setFont(f);
Expand All @@ -974,7 +979,7 @@ void MainWindow::highlightSubtitles(qlonglong elapsed) {
int row = m_tableMapping[e];
for (int col = 0; col < ui->tableWidget->columnCount(); col++) {
QTableWidgetItem *item = ui->tableWidget->item(row, col);
item->setBackgroundColor(next);
item->setBackground(next);
}
}
// Finally highlight current subtitles
Expand All @@ -987,7 +992,7 @@ void MainWindow::highlightSubtitles(qlonglong elapsed) {
f.setBold(true);
item->setFont(f);
}
item->setBackgroundColor(on);
item->setBackground(on);
if (col == COLUMN_TEXT)
item->setData(Qt::UserRole, !ui->actionHide->isChecked());
}
Expand Down Expand Up @@ -1154,7 +1159,7 @@ void MainWindow::enableKnownFactors(bool p_state) {
ui->knownFactors->setSizeAdjustPolicy(QComboBox::AdjustToContents);
} else {
ui->knownFactors->setSizeAdjustPolicy(
QComboBox::AdjustToMinimumContentsLength);
QComboBox::AdjustToMinimumContentsLengthWithIcon);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<string>Common framerates conversions</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1204,6 +1204,7 @@
<slot>actionShowWizard()</slot>
<slot>actionOperatorPrintout()</slot>
<slot>actionJumpLongest()</slot>
<slot>actionAdvancedSettings()</slot>
<slot>speedFactorChanged(double)</slot>
<slot>knownFactorChosen(int)</slot>
<slot>actionToggleDarkMode(bool)</slot>
Expand Down
45 changes: 23 additions & 22 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
**/
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QRegExp>
#include <QtCore/QSettings>
#include <QtCore/QStringList>
#include <QtCore/QTime>
#include <QtXml/QDomDocument>
#include <QtXml/QDomNodeList>
#include <QRegularExpression>

#include "script.h"

Expand All @@ -40,7 +40,7 @@ bool compareSubtitleStartTime(const Subtitle *s1, const Subtitle *s2) {

QString sp2nbsp(const QString s) {
// Replace multiple spaces between words by non breakable spaces
if (QRegExp("\\S\\s{2,}\\S").exactMatch(s)) {
if (QRegularExpression("\\S\\s{2,}\\S").match(s).hasMatch()) {
return QString(s).replace(" ", "&nbsp;");
}
return s;
Expand Down Expand Up @@ -88,7 +88,7 @@ Script::Script(const QString &p_fileName, int p_charsRate,
m_format = XML;
loadFromXml(content.join(""));
}
qSort(m_subtitles.begin(), m_subtitles.end(), compareSubtitleStartTime);
std::sort(m_subtitles.begin(), m_subtitles.end(), compareSubtitleStartTime);
}

Script::ScriptFormat Script::format() const { return m_format; }
Expand Down Expand Up @@ -283,7 +283,7 @@ void Script::loadFromAss(QStringList content) {
QString text = value.mid(p + 1);
text = text.trimmed();
// New-lines : ignore at start
text = text.replace(QRegExp("^(\\\\[nN])+"), "");
text = text.replace(QRegularExpression("^(\\\\[nN])+"), "");

// Transform the hints in the text into HTML:
// Italic HTML-ification
Expand All @@ -295,17 +295,18 @@ void Script::loadFromAss(QStringList content) {
text = sp2nbsp(text);

QList<SubtitleLine> lines;
foreach (QString line, text.split(QRegExp("\\\\[nN]"))) {
foreach (QString line, text.split(QRegularExpression("\\\\[nN]"))) {
// Absolute positioning
int x = -1;
int y = -1;
//{\pos(x,y)} or {\pos(x)} in the beginning of the line
QRegExp rx("\\{\\\\pos\\((\\d+)(,(\\d+))?\\)\\}");
if (rx.indexIn(line) >= 0) {
QStringList strpos = rx.capturedTexts();
x = strpos[1].toInt();
if (!strpos[3].isEmpty())
y = strpos[3].toInt();
QRegularExpression rx("\\{\\\\pos\\((\\d+)(,(\\d+))?\\)\\}");
QRegularExpressionMatch match = rx.match(line);
if (match.hasMatch()) {
x = match.captured(1).toInt(); // Group 1: The first number (x)
if (!match.captured(3).isEmpty()) {
y = match.captured(3).toInt(); // Group 3: The second number (y)
}
}

// Color HTML-ification
Expand All @@ -326,7 +327,7 @@ void Script::loadFromAss(QStringList content) {
}

// Drop others hints that cannot be translated in HTML
lines.append(SubtitleLine(line.replace(QRegExp("\\{.*\\}"), ""),
lines.append(SubtitleLine(line.replace(QRegularExpression("\\{.*\\}"), ""),
QPoint(x, y)));
}

Expand Down Expand Up @@ -381,10 +382,10 @@ void Script::loadFromSrt(QStringList content) {
int start = 0;
int end = 0;
foreach (QString line, content) {
if (section == SECTION_NONE && QRegExp("^[0-9]+$").exactMatch(line)) {
if (section == SECTION_NONE && QRegularExpression("^[0-9]+$").match(line).hasMatch()) {
section = SECTION_INFOS;
} else if (section == SECTION_INFOS) {
QStringList subparts = line.split(QRegExp("\\s+\\-\\->\\s+"));
QStringList subparts = line.split(QRegularExpression("\\s+\\-\\->\\s+"));
start =
QTime(0, 0, 0).msecsTo(QTime::fromString(subparts[0], "h:mm:ss,z"));
end = QTime(0, 0, 0).msecsTo(QTime::fromString(subparts[1], "h:mm:ss,z"));
Expand Down Expand Up @@ -434,13 +435,13 @@ void Script::loadFromTxt(QStringList content) {
if (section == SECTION_NONE) {
section = SECTION_EVENTS;

QRegExp times("^([0-9:]+) ([0-9:]+)");
if (times.indexIn(line) >= 0) {
QStringList subparts = times.capturedTexts();
QRegularExpression times("^([0-9:]+) ([0-9:]+)");
QRegularExpressionMatch match = times.match(line);
if (match.hasMatch()) {
start =
QTime(0, 0, 0).msecsTo(QTime::fromString(subparts[1], "h:mm:ss:z"));
QTime(0, 0, 0).msecsTo(QTime::fromString(match.captured(1), "h:mm:ss:z"));
end =
QTime(0, 0, 0).msecsTo(QTime::fromString(subparts[2], "h:mm:ss:z"));
QTime(0, 0, 0).msecsTo(QTime::fromString(match.captured(2), "h:mm:ss:z"));
continue;
}
}
Expand All @@ -460,9 +461,9 @@ void Script::loadFromTxt(QStringList content) {
comments = line.replace("#", "");
} else {
// In TXT format : <word> is equivalent to <i>word</i>
line = line.replace(QRegExp("<([^i/][^>]+)>"), "<i>\\1</i>");
line = line.replace(QRegularExpression("<([^i/][^>]+)>"), "<i>\\1</i>");
// and *word* is equivalent to <b>word</b>
line = line.replace(QRegExp("\\*([^\\*]+)\\*"), "<b>\\1</b>");
line = line.replace(QRegularExpression("\\*([^\\*]+)\\*"), "<b>\\1</b>");
line = sp2nbsp(line);
text.append(line);
}
Expand Down Expand Up @@ -516,7 +517,7 @@ void Script::loadFromXml(QString content) {
fontNode.toElement().attribute("Size", "DEFAULT_FONT_SIZE").toInt());
defaultFont.setUnderline(
(fontNode.toElement().attribute("Underlined", "no") != "no"));
defaultColor.setNamedColor(QString("#%1").arg(
defaultColor = QColor::fromString(QString("#%1").arg(
fontNode.toElement().attribute("Color", "FFFFFFFF")));
}

Expand Down
12 changes: 6 additions & 6 deletions src/shortcuteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ ShortcutEditor::ShortcutEditor(QWidget *parent)
ui->tableActions->horizontalHeader()->setResizeMode(COLUMN_DESCRIPTION,
QHeaderView::Stretch);
#endif
connect(ui->tableActions, SIGNAL(itemPressed(QTableWidgetItem *)), this,
SLOT(recordAction(QTableWidgetItem *)));
connect(ui->tableActions, SIGNAL(itemChanged(QTableWidgetItem *)), this,
SLOT(validateAction(QTableWidgetItem *)));
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this,
SLOT(onClicked(QAbstractButton *)));
connect(ui->tableActions, SIGNAL(itemPressed(QTableWidgetItem*)), this,
SLOT(recordAction(QTableWidgetItem*)));
connect(ui->tableActions, SIGNAL(itemChanged(QTableWidgetItem*)), this,
SLOT(validateAction(QTableWidgetItem*)));
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this,
SLOT(onClicked(QAbstractButton*)));
}

ShortcutEditor::~ShortcutEditor() { delete ui; }
Expand Down
Loading