Polish the videowidget example.
- Add command line parsing and file argument. - Port to Qt 5 connection syntax. - Adapt size to available geometry (for High DPI). Task-number: QTBUG-53114 Change-Id: I1c1c547ddb14210ef5900f99f4870d6d91b67088 Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
This commit is contained in:
@@ -41,13 +41,36 @@
|
||||
#include "videoplayer.h"
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QDesktopWidget>
|
||||
#include <QtCore/QCommandLineParser>
|
||||
#include <QtCore/QCommandLineOption>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QCoreApplication::setApplicationName("Video Widget Example");
|
||||
QCoreApplication::setOrganizationName("QtProject");
|
||||
QGuiApplication::setApplicationDisplayName(QCoreApplication::applicationName());
|
||||
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Qt Video Widget Example");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("url", "The URL to open.");
|
||||
parser.process(app);
|
||||
|
||||
VideoPlayer player;
|
||||
player.resize(320, 240);
|
||||
if (!parser.positionalArguments().isEmpty()) {
|
||||
const QUrl url =
|
||||
QUrl::fromUserInput(parser.positionalArguments().constFirst(),
|
||||
QDir::currentPath(), QUrl::AssumeLocalFile);
|
||||
player.setUrl(url);
|
||||
}
|
||||
|
||||
const QRect availableGeometry = QApplication::desktop()->availableGeometry(&player);
|
||||
player.resize(availableGeometry.width() / 6, availableGeometry.height() / 4);
|
||||
player.show();
|
||||
|
||||
return app.exec();
|
||||
|
||||
Reference in New Issue
Block a user