Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found
Sélectionner une révision Git
Loading items

Cible

Sélectionner le projet cible
  • Elliu/Vivy
1 résultat
Sélectionner une révision Git
Loading items
Afficher les modifications
Validations sur la source (16)
#include "AudioVisualizer.h"
#include "Timer.h"
#include <QLabel>
#include <QScrollArea>
......@@ -16,7 +15,7 @@ AudioVisualizer::AudioVisualizer(QWidget *parent) noexcept
void
AudioVisualizer::printSpectrum(QImage pixmap) noexcept
{
Timer *timer = new Timer(pixmap);
TimingView *timer = new TimingView(pixmap);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(timer);
......
#ifndef VIVY_AUDIOVISUALIZER_H
#define VIVY_AUDIOVISUALIZER_H
#include "Timer.h"
#include "TimingView.hpp"
#include <QWidget>
class AudioVisualizer final : public QWidget {
......
#include "Char.hpp"
Char::Char(const Char& old) :
char_(old.char_),
dur(old.dur),
line(old.line)
{
}
#ifndef VIVY_CHAR_H
#define VIVY_CHAR_H
#include "Style.hpp"
class Line;
class Char {
private:
QChar char_;
unsigned int dur;
Line *line;
public:
// Copy constructor
explicit Char(const Char&);
explicit Char(const QChar);
Char& operator=(const Char&) = delete;
~Char() noexcept = default;
};
#endif
#include "DialogHelp.h"
#include <cstdio>
#include <QWidget>
#include <QLabel>
#include <QDialog>
DialogHelp::DialogHelp(QWidget *parent) noexcept
: QMessageBox(parent)
{
setWindowTitle("Vivy - Help");
setWindowFlags(Qt::Dialog);
setWindowModality(Qt::WindowModal);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setSizePolicy(sizePolicy);
setTextFormat(Qt::RichText);
setText(aboutContent);
setTextInteractionFlags(Qt::NoTextInteraction);
adjustSize();
}
#ifndef VIVY_DIALOGHELP_H
#define VIVY_DIALOGHELP_H
#include <QMessageBox>
#include <QWidget>
class DialogHelp final : public QMessageBox {
Q_OBJECT
public:
DialogHelp(QWidget *parent = nullptr) noexcept;
~DialogHelp() noexcept = default;
private:
/* See https://doc.qt.io/qt-5/richtext-html-subset.html for the supported
* rich text subset. */
// clang-format off
static inline const char *aboutContent =
"<body>"
"<h1>About Vivy</h1>"
"<p>Vivy is a replacement for Aegisub, writen in Qt5+and with less segfaults - hopefully.</p>"
"<p>The following libraries where used:</p>"
"<ul>"
" <li>Qt5</li>"
" <li>libavutils</li>"
" <li>libavcodec</li>"
" <li>libavformat</li>"
"</ul>"
"</body>";
// clang-format on
};
#endif // VIVY_DIALOGHELP_H
#include "Line.hpp"
Line::Line(){
}
Line::Line(const Line& old) :
start(old.start),
end(old.end),
syls(old.syls)
{
}
#ifndef VIVY_LINE_H
#define VIVY_LINE_H
#include <QString>
#include "Style.hpp"
#include "Syl.hpp"
class Line {
private:
uint64_t start, end;
QVector<Syl> syls;
public:
explicit Line();
explicit Line(const Line&);
explicit Line(QString);
Line& operator=(const Line&) = delete;
~Line() noexcept = default;
};
#endif
#define VIVY_MAINWINDOW_CC
#include "MainWindow.h"
#include "AudioUtils.h"
#include "DialogHelp.h"
#include <iostream>
#include <cstring>
......@@ -12,23 +15,30 @@
#include <QStatusBar>
#include <QMenuBar>
#include <QImage>
#include <QToolBar>
MainWindow::MainWindow(QWidget *parent) noexcept
: QMainWindow(parent)
{
openAudioFileAct = new QAction(tr("&Open audio"), this);
openAudioFileAct->setStatusTip(tr("Open an audio file"));
openAudioFileAct->setShortcut(QKeySequence::Open);
connect(openAudioFileAct, &QAction::triggered, this, &MainWindow::openAudioFile);
#include "MainWindow.xdef"
statusBar()->showMessage("QSimulate has started");
}
fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction(openAudioFileAct);
editMenu = menuBar()->addMenu("&Edit");
viewMenu = menuBar()->addMenu("&View");
simulateMenu = menuBar()->addMenu("&Simulate");
helpMenu = menuBar()->addMenu("&Help");
void
MainWindow::openDialogHelp() noexcept
{
std::unique_ptr<DialogHelp> help_holder = std::make_unique<DialogHelp>(this);
help_holder->exec();
}
statusBar()->showMessage("QSimulate has started");
void
MainWindow::saveFile() noexcept
{
}
void
MainWindow::saveFileAs() noexcept
{
}
void
......@@ -42,7 +52,10 @@ MainWindow::openAudioFile() noexcept
double *data = nullptr;
int size = 0;
int rc = decodeAudioFile(filename.toStdString().c_str(), sample_rate, &data, &size);
auto data_deleter = [](double *ptr) -> void { av_free(ptr); };
auto data_deleter = [](double *ptr) -> void {
if (ptr != nullptr)
av_free(ptr);
};
std::unique_ptr<double, decltype(data_deleter)> data_holder(data, data_deleter);
if (rc != 0) {
......
......@@ -16,13 +16,8 @@ public:
private slots:
void openAudioFile() noexcept;
private:
QMenu *fileMenu = nullptr;
QMenu *editMenu = nullptr;
QMenu *viewMenu = nullptr;
QMenu *simulateMenu = nullptr;
QMenu *helpMenu = nullptr;
QAction *openAudioFileAct = nullptr;
void openDialogHelp() noexcept;
void saveFile() noexcept;
void saveFileAs() noexcept;
};
#endif // VIVY_MAINWINDOW_H
/* The main window actions, menus, toolbars, etc */
#ifndef VIVY_MAINWINDOW_CC
#error "This file should be included in the MainWindow constructor"
#endif
/* A list of all the possible icons with `QIcon::fromTheme(String)`:
* https://gist.github.com/peteristhegreat/c0ca6e1a57e5d4b9cd0bb1d7b3be1d6a */
/* Implement the menus for the main window */
#define MAIN_WINDOW_MENU(menu, name) QMenu *menu##Menu = menuBar()->addMenu(name);
/* Implement the actions for the main window */
#define MAIN_WINDOW_ACTION(method, name, tip, menu) \
QAction *method##Act = new QAction(tr(name), this); \
method##Act->setStatusTip(tr(tip)); \
menu##Menu->addAction(method##Act); \
connect(method##Act, &QAction::triggered, this, &MainWindow::method);
/* Implement the actions for the main window and add them an icon */
#define MAIN_WINDOW_ACTION_ICON(method, name, tip, menu, icon) \
MAIN_WINDOW_ACTION(method, name, tip, menu); \
method##Act->setIcon(QIcon::fromTheme(icon));
/* Implement the toolbar creations */
#define MAIN_WINDOW_TOOLBAR(method, name) \
QToolBar *method ## ToolBar = new QToolBar(tr(name), this); \
addToolBar(method ## ToolBar);
/* Add a shortcut to an action */
#define MAIN_WINDOW_ACTION_ADD_SHORTCUT(action, shortcut) \
action ## Act->setShortcut(shortcut);
/* Add an action to a toolbar */
#define MAIN_WINDOW_TOOLBAR_ADD_ACTION(toolbar, action) toolbar ## ToolBar->addAction(action ## Act);
/* List of things to add to the main window */
MAIN_WINDOW_MENU(file, "&File")
MAIN_WINDOW_MENU(edit, "&Edit")
MAIN_WINDOW_MENU(view, "&View")
MAIN_WINDOW_MENU(simulate, "&Simulate")
MAIN_WINDOW_MENU(help, "&Help")
MAIN_WINDOW_TOOLBAR(file, "File")
MAIN_WINDOW_TOOLBAR(other, "Other")
MAIN_WINDOW_ACTION_ICON(openAudioFile, "&Open audio", "Open an audio file", file, "document-open")
MAIN_WINDOW_ACTION_ICON(saveFile, "&Save file", "Save the current document", file, "document-save")
MAIN_WINDOW_ACTION_ICON(saveFileAs, "&Save file as", "Save the current document as", file, "document-save-as")
MAIN_WINDOW_ACTION_ICON(openDialogHelp, "&About", "Open the help dialog", help, "help-about")
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, openAudioFile)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFile)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(file, saveFileAs)
MAIN_WINDOW_TOOLBAR_ADD_ACTION(other, openDialogHelp)
MAIN_WINDOW_ACTION_ADD_SHORTCUT(openAudioFile, QKeySequence::Open)
MAIN_WINDOW_ACTION_ADD_SHORTCUT(saveFile, QKeySequence::Save)
// vim: ft=c
#include "Style.hpp"
Style::Style(const Style& old) :
styleName(old.styleName),
fontName(old.fontName),
fontSize(old.fontSize),
primaryColor(old.primaryColor),
secondaryColor(old.secondaryColor),
outlineColor(old.outlineColor),
backColor(old.backColor),
bold(old.bold),
italic(old.italic),
underline(old.underline),
strikeOut(old.strikeOut),
scaleX(old.scaleX),
scaleY(old.scaleY),
spacing(old.spacing),
angle(old.angle),
borderStyle(old.borderStyle),
alignment(old.alignment),
marginL(old.marginL),
marginR(old.marginR),
marginV(old.marginV),
encoding(old.encoding)
{
}
#ifndef VIVY_STYLE_H
#define VIVY_STYLE_H
#include <QString>
#include <QVector>
// class or struct, that is the question
struct Color {
uint8_t a, r, g, b;
Color();
Color(const QString);
};
class Style {
private:
QString styleName;
QString fontName;
int fontSize;
Color primaryColor, secondaryColor, outlineColor, backColor;
bool bold, italic, underline, strikeOut;
float scaleX, scaleY;
float spacing, angle, borderStyle;
int alignment, marginL, marginR, marginV;
int encoding;
public:
// Should grab and copy a user-changeable default style
explicit Style();
explicit Style(const Style&);
explicit Style(const QString&);
Style& operator=(const Style&) = delete;
~Style() noexcept = default;
};
#endif
#include "Syl.hpp"
Syl::Syl(const Syl& old) :
chars(old.chars),
dur(old.dur),
line(old.line)
{
}
#ifndef VIVY_SYL_H
#define VIVY_SYL_H
#include "Char.hpp"
#include "Style.hpp"
class Line;
class Syl {
private:
QVector<Char> chars;
unsigned int dur;
Line *line;
public:
explicit Syl(const Syl&);
explicit Syl(const QString);
Syl& operator=(const Syl&) = delete;
~Syl() noexcept = default;
};
#endif
#include "TimingScene.hpp"
#include <QLabel>
#include <QGraphicsLineItem>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QScrollBar>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
TimingScene::TimingScene(QWidget *parent) noexcept
: QGraphicsScene(parent)
{
}
TimingScene::TimingScene(QImage img, QWidget *parent) noexcept
: QGraphicsScene(parent)
, img(img)
{
QPixmap pixmap(QPixmap::fromImage(img));
backgroundImg = addPixmap(pixmap);
}
#ifndef VIVY_TIMING_SCENE_H
#define VIVY_TIMING_SCENE_H
#include "TimingBar.h"
#include <QWidget>
#include <QColor>
#include <QVector>
#include <QGraphicsView>
#include <QGraphicsScene>
class QGraphicsPixmapItem;
class TimingScene final : public QGraphicsScene {
Q_OBJECT
public:
static inline constexpr QColor startColour = QColor(127, 0, 127);
static inline constexpr QColor endColour = QColor(0, 127, 0);
explicit TimingScene(QWidget *parent = nullptr) noexcept;
TimingScene(QImage img, QWidget *parent = nullptr) noexcept;
~TimingScene() noexcept = default;
private:
QGraphicsPixmapItem *backgroundImg = nullptr;
QImage img;
QVector<QLine> lines;
public:
inline QGraphicsPixmapItem* bg() { return backgroundImg; };
public slots:
};
#endif // VIVY_TIMING_SCENE_H
#include "Timer.h"
#include "TimingView.hpp"
#include <QLabel>
#include <QGraphicsLineItem>
......@@ -10,30 +10,30 @@
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QAbstractScrollArea>
#define TO_ADD_TO_IMAGE_HEIGHT 2 /* Used for alignement */
Timer::Timer(QImage img, QWidget *parent) noexcept
TimingView::TimingView(QImage img, QWidget *parent) noexcept
: QGraphicsView(parent)
, img(img)
{
QPixmap pixmap(QPixmap::fromImage(img));
bg = scene->addPixmap(pixmap);
setFixedHeight(pixmap.height());
scene = new TimingScene(img);
setFixedHeight(img.height());
setMaximumHeight(img.height() + horizontalScrollBar()->height() - TO_ADD_TO_IMAGE_HEIGHT);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setScene(scene);
}
void
Timer::mousePressEvent(QMouseEvent *event) noexcept
TimingView::mousePressEvent(QMouseEvent *event) noexcept
{
QPoint pos = event->pos();
pos.rx() += horizontalScrollBar()->value();
int x = event->pos().x() + horizontalScrollBar()->value();
QGraphicsItem *got;
if ((got = scene->itemAt(pos, QTransform())) == nullptr || got == bg) {
scene->addItem(new TimingBar(QLine(x, 0, x, img.height() - TO_ADD_TO_IMAGE_HEIGHT),
if ((got = scene->itemAt(pos, QTransform())) == nullptr || got == scene->bg()) {
scene->addItem(new TimingBar(QLine(x, 0, x, scene->height()),
event->button() == Qt::LeftButton ? startColour : endColour));
}
......
#ifndef VIVY_TIMER_H
#define VIVY_TIMER_H
#ifndef VIVY_TIMING_VIEW_H
#define VIVY_TIMING_VIEW_H
#include "TimingBar.h"
#include "TimingScene.hpp"
#include <QWidget>
#include <QColor>
......@@ -10,25 +11,22 @@
class QGraphicsPixmapItem;
class Timer final : public QGraphicsView {
class TimingView final : public QGraphicsView {
Q_OBJECT
public:
static inline constexpr QColor startColour = QColor(127, 0, 127);
static inline constexpr QColor endColour = QColor(0, 127, 0);
Timer(QImage img, QWidget *parent = nullptr) noexcept;
~Timer() noexcept = default;
TimingView(QImage img, QWidget *parent = nullptr) noexcept;
~TimingView() noexcept = default;
private:
QGraphicsPixmapItem *bg = nullptr;
QGraphicsScene *scene = new QGraphicsScene;
QImage img;
QVector<QLine> lines;
TimingScene* scene;
void mousePressEvent(QMouseEvent *event) noexcept;
public slots:
};
#endif // VIVY_TIMER_H
#endif // VIVY_TIMING_VIEW_H