Skip to content

Commit 208014c

Browse files
committed
Add feature to skip to specified time
Fix #56
1 parent 133a0b5 commit 208014c

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

PenguinSubtitlePlayer.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ INCLUDEPATH += $$PWD/src/libcharsetdetect \
1717

1818
SOURCES += src/configdialog.cpp \
1919
src/main.cpp \
20+
src/clickablelabel.cpp \
2021
src/mainwindow.cpp \
2122
src/pages.cpp \
2223
src/prefpage.cpp \
@@ -61,6 +62,7 @@ SOURCES += src/configdialog.cpp \
6162
src/engine.cpp
6263

6364
HEADERS += src/configdialog.h \
65+
src/clickablelabel.h \
6466
src/mainwindow.h \
6567
src/pages.h \
6668
src/prefpage.h \

resource/ui/mainwindow.ui

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@
293293
</property>
294294
</widget>
295295
</item>
296-
297296
<item>
298297
<widget class="QPushButton" name="backwardButton">
299298
<property name="sizePolicy">
@@ -407,8 +406,7 @@
407406
</property>
408407
</widget>
409408
</item>
410-
411-
<item>
409+
<item>
412410
<widget class="QSlider" name="horizontalSlider">
413411
<property name="enabled">
414412
<bool>false</bool>
@@ -428,7 +426,7 @@
428426
</widget>
429427
</item>
430428
<item>
431-
<widget class="QLabel" name="timeLabel">
429+
<widget class="ClickableLabel" name="timeLabel">
432430
<property name="font">
433431
<font>
434432
<pointsize>11</pointsize>
@@ -514,6 +512,11 @@ open-source, cross-platform</string>
514512
<header location="global">QSizeGrip</header>
515513
<container>1</container>
516514
</customwidget>
515+
<customwidget>
516+
<class>ClickableLabel</class>
517+
<extends>QLabel</extends>
518+
<header>src/clickablelabel.h</header>
519+
</customwidget>
517520
</customwidgets>
518521
<resources>
519522
<include location="../resource.qrc"/>

src/clickablelabel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "clickablelabel.h"
2+
3+
ClickableLabel::ClickableLabel(QWidget* parent, Qt::WindowFlags f)
4+
: QLabel(parent) {
5+
6+
}
7+
8+
ClickableLabel::~ClickableLabel() {}
9+
10+
void ClickableLabel::mousePressEvent(QMouseEvent* event) {
11+
emit clicked();
12+
}

src/clickablelabel.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef CLICKABLELABEL_H
2+
#define CLICKABLELABEL_H
3+
4+
#include <QLabel>
5+
#include <QWidget>
6+
#include <Qt>
7+
8+
class ClickableLabel : public QLabel {
9+
Q_OBJECT
10+
11+
public:
12+
explicit ClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
13+
~ClickableLabel();
14+
15+
signals:
16+
void clicked();
17+
18+
protected:
19+
void mousePressEvent(QMouseEvent* event);
20+
21+
};
22+
23+
#endif // CLICKABLELABEL_H

src/mainwindow.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "QStyle"
2323
#include "QTextCodec"
2424
#include "QTimer"
25+
#include "QLineEdit"
2526
#include "cmath"
2627
#include "chardet.h"
2728
#include "configdialog.h"
@@ -64,6 +65,8 @@ MainWindow::MainWindow(QWidget *parent)
6465
connect(ui->horizontalSlider, SIGNAL(sliderMoved(int)), this,
6566
SLOT(sliderMoved(int)));
6667

68+
connect(ui->timeLabel, SIGNAL(clicked()), this, SLOT(openSkipToTimeDialog()));
69+
6770
if (QSystemTrayIcon::isSystemTrayAvailable()) {
6871
QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
6972
trayIcon->setIcon(QIcon(":/icon.png"));
@@ -251,6 +254,30 @@ void MainWindow::openFileDialog() {
251254
this->show();
252255
}
253256

257+
void MainWindow::openSkipToTimeDialog() {
258+
if (!engine)
259+
return;
260+
261+
this->hide();
262+
263+
bool ok;
264+
QString timeStr = QInputDialog::getText(0, tr("Skip to Time"), tr("Skip to Time"),
265+
QLineEdit::Normal, Engine::millisToTimeString(currentTime), &ok);
266+
if (ok) {
267+
QRegularExpression timeRegex(
268+
"^(\\d+):(\\d+):(\\d+)$");
269+
QRegularExpressionMatchIterator it = timeRegex.globalMatch(timeStr);
270+
if (it.hasNext()) {
271+
QRegularExpressionMatch match = it.next();
272+
QString h = match.captured(1), m = match.captured(2), s = match.captured(3);
273+
long long time = Engine::calculateTime(h, m, s, "0");
274+
currentTime = qMin(engine->getFinishTime(), qMax(0LL, time));
275+
update();
276+
}
277+
}
278+
this->show();
279+
}
280+
254281
/*
255282
* Protected methods
256283
*/

src/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MainWindow : public QMainWindow {
2929
void iconActivated(QSystemTrayIcon::ActivationReason reason);
3030
void openSettingsWindow();
3131
void openFileDialog();
32+
void openSkipToTimeDialog();
3233

3334
protected:
3435
void paintEvent(QPaintEvent *event);

0 commit comments

Comments
 (0)