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

New Release #331

Open
wants to merge 20 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
2 changes: 1 addition & 1 deletion src/Baka-MPlayer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = baka-mplayer
TEMPLATE = app

CONFIG += c++11 link_pkgconfig
CONFIG += c++1y link_pkgconfig

isEmpty(DESTDIR):DESTDIR=build
OBJECTS_DIR = $${DESTDIR}/obj
Expand Down
180 changes: 99 additions & 81 deletions src/bakacommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <QApplication>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QProcess>
#include <QDir>
#include <QClipboard>
#include <QMessageBox>
#include <QScreen>

#include "ui/mainwindow.h"
#include "ui_mainwindow.h"
Expand All @@ -20,7 +20,6 @@
#include "widgets/dimdialog.h"
#include "mpvhandler.h"
#include "overlayhandler.h"
#include "updatemanager.h"
#include "util.h"


Expand All @@ -32,6 +31,25 @@ void BakaEngine::BakaMpv(QStringList &args)
RequiresParameters("mpv");
}

void BakaEngine::BakaGet(QStringList &args)
{
if(!args.empty())
{
QString arg = args.front();
args.pop_front();
if(args.empty())
{
mpv->Command({"expand-properties", "print-text", QString("${%0}").arg(arg)});
}
else
{
InvalidParameter(args.join(' '));
}
}
else
RequiresParameters("get");
}

void BakaEngine::BakaSh(QStringList &args)
{
if(!args.empty())
Expand All @@ -41,7 +59,7 @@ void BakaEngine::BakaSh(QStringList &args)
QProcess *p = new QProcess(this);
p->start(arg, args);
connect(p, &QProcess::readyRead,
[=]
p, [=]
{
Print(p->readAll(), QString("%0(%1))").arg(p->program(), QString::number(quintptr(p))));
});
Expand All @@ -52,7 +70,7 @@ void BakaEngine::BakaSh(QStringList &args)
// });
}
else
RequiresParameters("mpv");
RequiresParameters("sh");
}

void BakaEngine::BakaNew(QStringList &args)
Expand Down Expand Up @@ -100,7 +118,7 @@ void BakaEngine::BakaAddSubtitles(QStringList &args)
{
trackFile = QFileDialog::getOpenFileName(window, tr("Open Subtitle File"), mpv->getPath(),
QString("%0 (%1)").arg(tr("Subtitle Files"), Mpv::subtitle_filetypes.join(" ")),
0, QFileDialog::DontUseSheet);
0);
}
else
trackFile = args.join(' ');
Expand All @@ -115,7 +133,7 @@ void BakaEngine::BakaAddAudio(QStringList &args)
{
trackFile = QFileDialog::getOpenFileName(window, tr("Open Audio File"), mpv->getPath(),
QString("%0 (%1)").arg(tr("Audio Files"), Mpv::audio_filetypes.join(" ")),
0, QFileDialog::DontUseSheet);
0);
}
else
trackFile = args.join(' ');
Expand Down Expand Up @@ -159,9 +177,9 @@ void BakaEngine::Screenshot(bool subs)
if(i != -1)
dir.remove(0, i+1);
if(subs)
mpv->ShowText(tr("Saved to \"%0\", with subs").arg(dir));
overlay->showStatusText(tr("Saved to \"%0\", with subs").arg(dir));
else
mpv->ShowText(tr("Saved to \"%0\", without subs").arg(dir));
overlay->showStatusText(tr("Saved to \"%0\", without subs").arg(dir));
}


Expand Down Expand Up @@ -287,7 +305,7 @@ void BakaEngine::BakaPlaylist(QStringList &args)
InvalidParameter(arg);
}
else
RequiresParameters("baka playlist");
RequiresParameters("playlist");
}

void BakaEngine::BakaJump(QStringList &args)
Expand Down Expand Up @@ -389,7 +407,7 @@ void BakaEngine::Open()
QString("%0 (%1);;").arg(tr("Video Files"), Mpv::video_filetypes.join(" "))+
QString("%0 (%1);;").arg(tr("Audio Files"), Mpv::audio_filetypes.join(" "))+
QString("%0 (*.*)").arg(tr("All Files")),
0, QFileDialog::DontUseSheet));
0));
}


Expand Down Expand Up @@ -427,87 +445,87 @@ void BakaEngine::FitWindow(int percent, bool msg)
if(window->isFullScreen() || window->isMaximized() || !window->ui->menuFit_Window->isEnabled())
return;

mpv->LoadVideoParams();
mpv->LoadVideoParams([=]() {
const Mpv::VideoParams &vG = mpv->getFileInfo().video_params; // video geometry
QRect mG = window->ui->mpvFrame->geometry(), // mpv geometry
wfG = window->frameGeometry(), // frame geometry of window (window geometry + window frame)
wG = window->geometry(), // window geometry
aG = qApp->screenAt(wfG.center())->availableGeometry(); // available geometry of the screen we're in--(geometry not including the taskbar)

const Mpv::VideoParams &vG = mpv->getFileInfo().video_params; // video geometry
QRect mG = window->ui->mpvFrame->geometry(), // mpv geometry
wfG = window->frameGeometry(), // frame geometry of window (window geometry + window frame)
wG = window->geometry(), // window geometry
aG = qApp->desktop()->availableGeometry(wfG.center()); // available geometry of the screen we're in--(geometry not including the taskbar)
double a, // aspect ratio
w, // width of vid we want
h; // height of vid we want

double a, // aspect ratio
w, // width of vid we want
h; // height of vid we want

// obtain natural video aspect ratio
if(vG.width == 0 || vG.height == 0) // width/height are 0 when there is no output
return;
if(vG.dwidth == 0 || vG.dheight == 0) // dwidth/height are 0 on load
a = double(vG.width)/vG.height; // use video width and height for aspect ratio
else
a = double(vG.dwidth)/vG.dheight; // use display width and height for aspect ratio
// obtain natural video aspect ratio
if(vG.width == 0 || vG.height == 0) // width/height are 0 when there is no output
return;
if(vG.dwidth == 0 || vG.dheight == 0) // dwidth/height are 0 on load
a = double(vG.width)/vG.height; // use video width and height for aspect ratio
else
a = double(vG.dwidth)/vG.dheight; // use display width and height for aspect ratio

// calculate resulting display:
if(percent == 0) // fit to window
{
// set our current mpv frame dimensions
w = mG.width();
h = mG.height();
// calculate resulting display:
if(percent == 0) // fit to window
{
// set our current mpv frame dimensions
w = mG.width();
h = mG.height();

double cmp = w/h - a, // comparison
eps = 0.01; // epsilon (deal with rounding errors) we consider -eps < 0 < eps ==> 0
double cmp = w/h - a, // comparison
eps = 0.01; // epsilon (deal with rounding errors) we consider -eps < 0 < eps ==> 0

if(cmp > eps) // too wide
w = h * a; // calculate width based on the correct height
else if(cmp < -eps) // too long
h = w / a; // calculate height based on the correct width
}
else // fit into desired dimensions
{
double scale = percent / 100.0; // get scale
if(cmp > eps) // too wide
w = h * a; // calculate width based on the correct height
else if(cmp < -eps) // too long
h = w / a; // calculate height based on the correct width
}
else // fit into desired dimensions
{
double scale = percent / 100.0; // get scale

w = vG.width * scale; // get scaled width
h = vG.height * scale; // get scaled height
}
w = vG.width * scale; // get scaled width
h = vG.height * scale; // get scaled height
}

double dW = w + (wfG.width() - mG.width()), // calculate display width of the window
dH = h + (wfG.height() - mG.height()); // calculate display height of the window
double dW = w + (wfG.width() - mG.width()), // calculate display width of the window
dH = h + (wfG.height() - mG.height()); // calculate display height of the window

if(dW > aG.width()) // if the width is bigger than the available area
{
dW = aG.width(); // set the width equal to the available area
w = dW - (wfG.width() - mG.width()); // calculate the width
h = w / a; // calculate height
dH = h + (wfG.height() - mG.height()); // calculate new display height
}
if(dH > aG.height()) // if the height is bigger than the available area
{
dH = aG.height(); // set the height equal to the available area
h = dH - (wfG.height() - mG.height()); // calculate the height
w = h * a; // calculate the width accordingly
dW = w + (wfG.width() - mG.width()); // calculate new display width
}
if(dW > aG.width()) // if the width is bigger than the available area
{
dW = aG.width(); // set the width equal to the available area
w = dW - (wfG.width() - mG.width()); // calculate the width
h = w / a; // calculate height
dH = h + (wfG.height() - mG.height()); // calculate new display height
}
if(dH > aG.height()) // if the height is bigger than the available area
{
dH = aG.height(); // set the height equal to the available area
h = dH - (wfG.height() - mG.height()); // calculate the height
w = h * a; // calculate the width accordingly
dW = w + (wfG.width() - mG.width()); // calculate new display width
}

// get the centered rectangle we want
QRect rect = QStyle::alignedRect(Qt::LeftToRight,
Qt::AlignCenter,
QSize(dW,
dH),
percent == 0 ? wfG : aG); // center in window (autofit) or on our screen
// get the centered rectangle we want
QRect rect = QStyle::alignedRect(Qt::LeftToRight,
Qt::AlignCenter,
QSize(dW,
dH),
percent == 0 ? wfG : aG); // center in window (autofit) or on our screen

// adjust the rect to compensate for the frame
rect.setLeft(rect.left() + (wG.left() - wfG.left()));
rect.setTop(rect.top() + (wG.top() - wfG.top()));
rect.setRight(rect.right() - (wfG.right() - wG.right()));
rect.setBottom(rect.bottom() - (wfG.bottom() - wG.bottom()));
// adjust the rect to compensate for the frame
rect.setLeft(rect.left() + (wG.left() - wfG.left()));
rect.setTop(rect.top() + (wG.top() - wfG.top()));
rect.setRight(rect.right() - (wfG.right() - wG.right()));
rect.setBottom(rect.bottom() - (wfG.bottom() - wG.bottom()));

// finally set the geometry of the window
window->setGeometry(rect);
// finally set the geometry of the window
window->setGeometry(rect);

// note: the above block is required because there is no setFrameGeometry function
// note: the above block is required because there is no setFrameGeometry function

if(msg)
mpv->ShowText(tr("Fit Window: %0").arg(percent == 0 ? tr("To Current Size") : (QString::number(percent)+"%")));
if(msg)
overlay->showStatusText(tr("Fit Window: %0").arg(percent == 0 ? tr("To Current Size") : (QString::number(percent)+"%")));
});
}

void BakaEngine::BakaDeinterlace(QStringList &args)
Expand Down Expand Up @@ -566,7 +584,7 @@ void BakaEngine::BakaSpeed(QStringList &args)
mpv->Speed(mpv->getSpeed()+arg.toDouble());
else
mpv->Speed(arg.toDouble());
mpv->ShowText(tr("Speed: %0x").arg(QString::number(mpv->getSpeed(), 'f', 2)));
overlay->showStatusText(tr("Speed: %0x").arg(QString::number(mpv->getSpeed(), 'f', 2)));
}
else
InvalidParameter(args.join(' '));
Expand All @@ -581,7 +599,7 @@ void BakaEngine::BakaFullScreen(QStringList &args)
{
window->FullScreen(!window->isFullScreen());
if(window->isFullScreen())
mpv->ShowText(tr("Press ESC or double-click to leave full screen"));
overlay->showStatusText(tr("Press ESC or double-click to leave full screen"));
}
else
InvalidParameter(args.join(' '));
Expand All @@ -601,7 +619,7 @@ void BakaEngine::BakaHideAllControls(QStringList &args)
{
if(i->first == "hide_all_controls")
{
mpv->ShowText(tr("Press %0 to show all controls again").arg(i.key()));
overlay->showStatusText(tr("Press %0 to show all controls again").arg(i.key()));
break;
}
}
Expand Down
27 changes: 8 additions & 19 deletions src/bakaengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
BakaEngine::BakaEngine(QObject *parent):
QObject(parent),
window(static_cast<MainWindow*>(parent)),
mpv(new MpvHandler(window->ui->mpvFrame->winId(), this)),
mpv(window->ui->mpvFrame),
settings(new Settings(Util::SettingsLocation(), this)),
gesture(new GestureHandler(this)),
overlay(new OverlayHandler(this)),
Expand All @@ -29,38 +29,27 @@ BakaEngine::BakaEngine(QObject *parent):
qtTranslator(nullptr)
{
if(Util::DimLightsSupported())
dimDialog = new DimDialog(window, nullptr);
dimDialog = new DimDialog(window);
else
{
dimDialog = nullptr;
window->ui->action_Dim_Lights->setEnabled(false);
}

connect(mpv, &MpvHandler::messageSignal,
[=](QString msg)
mpv, [=](QString msg)
{
Print(msg, "mpv");
});
connect(update, &UpdateManager::messageSignal,
[=](QString msg)
update, [=](QString msg)
{
Print(msg, "update");
});
}

BakaEngine::~BakaEngine()
{
if(translator != nullptr)
delete translator;
if(qtTranslator != nullptr)
delete qtTranslator;
if(dimDialog != nullptr)
delete dimDialog;
delete update;
delete overlay;
delete gesture;
delete settings;
delete mpv;
connect(mpv, &MpvHandler::showText,
overlay, [=](QString msg, int duration) {
overlay->showStatusText(msg, duration);
});
}

void BakaEngine::LoadSettings()
Expand Down
Loading