1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/examples/qqtliveplayer/qqtwindow.cpp

171 lines
4.6 KiB
C++
Raw Normal View History

2017-09-05 18:07:05 +08:00
#include "qqtwindow.h"
#include "ui_qqtwindow.h"
#include "qqtobjectfactory.h"
2017-10-22 12:21:19 +08:00
#include "qqt-qt.h"
2017-09-05 18:07:05 +08:00
#include "qqtcore.h"
#include "qqtgui.h"
#include "animationmanager.h"
#include <VLCQtCore/Common.h>
#include <VLCQtCore/Instance.h>
#include <VLCQtCore/Media.h>
#include <VLCQtCore/MediaPlayer.h>
#include <VLCQtWidgets/WidgetVideo.h>
#include "qqtwidgets.h"
#include "qqttreewidget.h"
#include "qqtsqltreemodel.h"
QQTWindow::QQTWindow(QWidget *parent) :
QStackedWidget(parent),
ui(new Ui::QQTWindow)
{
ui->setupUi(this);
QQTObjectFactory::registerObject(this);
#ifdef __EMBEDDED_LINUX__
2017-09-05 18:07:05 +08:00
/*
* frameless足够
*/
setWindowFlags(Qt::FramelessWindowHint);
/*
*
*/
setAttribute(Qt::WA_TranslucentBackground, true);
#endif
setFixedSize(1024, 600);
moveCenter(this);
setAcceptDrops(true);
ui->treeView->setModel(QQTTreeWidget::SQLTREE);
((QQTSqlTreeModel*)ui->treeView->model())
->setFilePath("LiveStream.db");
((QQTSqlTreeModel*)ui->treeView->model())
->query("");
for(int i = 1; i < 11; i++)
ui->treeView->setColumnHidden(i, true);
((QQTSqlTreeModel*)ui->treeView->model())
->setHeaderData(0, Qt::Horizontal, tr("pindao liebiao"));
connect(ui->treeView, SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(doubleClicked(const QModelIndex&)));
#if 1
QPixmap pixmap("./skin/default/splash.png");
QSplashScreen splash(pixmap);
splash.showMessage(tr("Loading..."), Qt::AlignBottom);
splash.setFixedSize(600, 400);
splash.show();
QQTSleep(400);
splash.finish(this);
#elif 0
/**
* set movie in label0
* label0 will dispear in this function
*/
QMovie mov("./skin/default/splash.gif");
QLabel label;
label.setMovie(&mov);
label.setFixedSize(400, 300);
moveCenter(&label);
mov.start();
label.show();
QQTSleep(3000);
#endif
#if 1
//QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
//VlcCommon::setPluginPath(QCoreApplication::applicationDirPath() + "/plugins");
_instance = new VlcInstance(VlcCommon::args(), this);
_player = new VlcMediaPlayer(_instance);
_player->setVideoWidget(ui->widget);
ui->widget->setMediaPlayer(_player);
ui->widget->setWindowFlags(ui->widget->windowFlags()|Qt::WindowTransparentForInput);
ui->horizontalSlider->setMediaPlayer(_player);
ui->horizontalSlider->setVolume(100);
_media = NULL;
//VlcMediaPlayer *_player2;
//_player2 = new VlcMediaPlayer(_instance);
//_player2->setVideoWidget(ui->widget_2);
//QString url2 = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
//VlcMedia *_media2;
//_media2 = new VlcMedia(url2, _instance);
//ui->widget_2->setMediaPlayer(_player2);
//_player2->open(_media2);
#endif
/**
* decorate all windows
* nobody use animation to mainwindow
* so this animation use to child window
*/
AnimationManager::Instance(this);
}
QQTWindow::~QQTWindow()
{
delete ui;
}
void QQTWindow::doubleClicked(const QModelIndex &index)
{
if(!index.parent().isValid())
return;
QString uri = index.model()->index(index.row(), 1, index.parent()).data().toString();
pline() << uri;
if(_player->hasVout())
_player->stop();
if(_media)
delete _media;
//QString url = "http://ivi.bupt.edu.cn/hls/cctv1.m3u8";
_media = new VlcMedia(uri, _instance);
_player->open(_media);
}
/**
* @brief QQTWindow::dragEnterEvent
* dragEnterEvent事件
*/
void QQTWindow::dragEnterEvent(QDragEnterEvent *event)
{
//如果为文件,则支持拖放
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
}
/**
* @brief QQTWindow::dropEvent
* dropEvent事件
*/
void QQTWindow::dropEvent(QDropEvent *event)
{
/**
*
*
*/
QList<QUrl> urls = event->mimeData()->urls();
if(urls.isEmpty())
return;
/**
*
*/
foreach(QUrl url, urls) {
QString file_name = url.toLocalFile();
pline() << file_name;
if(_player->hasVout())
_player->stop();
if(_media)
delete _media;
_media = new VlcMedia(file_name, true, _instance);
_player->open(_media);
break;
}
}