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

174 lines
4.9 KiB
C++
Raw Normal View History

2017-09-05 18:07:05 +08:00
#include "qqtwindow.h"
#include "ui_qqtwindow.h"
2018-04-22 16:17:15 +08:00
#include "qqtobjectmanager.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"
2018-05-29 09:15:15 +08:00
QQTWindow::QQTWindow ( QWidget* parent ) :
QStackedWidget ( parent ),
ui ( new Ui::QQTWindow )
2017-09-05 18:07:05 +08:00
{
2018-05-29 09:15:15 +08:00
ui->setupUi ( this );
2017-09-05 18:07:05 +08:00
2018-05-29 09:15:15 +08:00
QQtObjectManager::registerObject ( this );
2017-09-05 18:07:05 +08:00
#ifdef __EMBEDDED_LINUX__
2017-09-05 18:07:05 +08:00
/*
* frameless足够
*/
2018-05-29 09:15:15 +08:00
setWindowFlags ( Qt::FramelessWindowHint );
2017-09-05 18:07:05 +08:00
/*
*
*/
2018-05-29 09:15:15 +08:00
setAttribute ( Qt::WA_TranslucentBackground, true );
2017-09-05 18:07:05 +08:00
#endif
2018-05-29 09:15:15 +08:00
setFixedSize ( 1024, 600 );
moveCenter ( this );
setAcceptDrops ( true );
QQtSqlTreeModel* model = new QQtSqlTreeModel ( this );
ui->treeView->setModel ( model );
( ( QQtSqlTreeModel* ) ui->treeView->model() )
->setAbsoluteFilePath ( "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 0
QPixmap pixmap ( "./skin/default/splash.png" );
QSplashScreen splash ( pixmap );
splash.showMessage ( tr ( "Loading..." ), Qt::AlignBottom );
splash.setFixedSize ( 600, 400 );
2017-09-05 18:07:05 +08:00
splash.show();
2018-05-29 09:15:15 +08:00
QQtSleep ( 400 );
splash.finish ( this );
2017-09-05 18:07:05 +08:00
#elif 0
/**
* set movie in label0
* label0 will dispear in this function
*/
2018-05-29 09:15:15 +08:00
QMovie mov ( "./skin/default/splash.gif" );
2017-09-05 18:07:05 +08:00
QLabel label;
2018-05-29 09:15:15 +08:00
label.setMovie ( &mov );
label.setFixedSize ( 400, 300 );
moveCenter ( &label );
2017-09-05 18:07:05 +08:00
mov.start();
label.show();
2018-05-29 09:15:15 +08:00
QQtSleep ( 3000 );
2017-09-05 18:07:05 +08:00
#endif
#if 1
//QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
//VlcCommon::setPluginPath(QCoreApplication::applicationDirPath() + "/plugins");
2018-05-29 09:15:15 +08:00
_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 );
2017-09-05 18:07:05 +08:00
_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
*/
2018-05-29 09:15:15 +08:00
AnimationManager::Instance ( this );
2017-09-05 18:07:05 +08:00
}
QQTWindow::~QQTWindow()
{
delete ui;
}
2018-05-29 09:15:15 +08:00
void QQTWindow::doubleClicked ( const QModelIndex& index )
2017-09-05 18:07:05 +08:00
{
2018-05-29 09:15:15 +08:00
if ( !index.parent().isValid() )
2017-09-05 18:07:05 +08:00
return;
2018-05-29 09:15:15 +08:00
QString uri = index.model()->index ( index.row(), 1, index.parent() ).data().toString();
2017-09-05 18:07:05 +08:00
pline() << uri;
2018-05-29 09:15:15 +08:00
if ( _player->hasVout() )
2017-09-05 18:07:05 +08:00
_player->stop();
2018-05-29 09:15:15 +08:00
if ( _media )
2017-09-05 18:07:05 +08:00
delete _media;
//QString url = "http://ivi.bupt.edu.cn/hls/cctv1.m3u8";
2018-05-29 09:15:15 +08:00
_media = new VlcMedia ( uri, _instance );
_player->open ( _media );
2017-09-05 18:07:05 +08:00
}
/**
* @brief QQTWindow::dragEnterEvent
* dragEnterEvent事件
*/
2018-05-29 09:15:15 +08:00
void QQTWindow::dragEnterEvent ( QDragEnterEvent* event )
2017-09-05 18:07:05 +08:00
{
//如果为文件,则支持拖放
2018-05-29 09:15:15 +08:00
if ( event->mimeData()->hasFormat ( "text/uri-list" ) )
2017-09-05 18:07:05 +08:00
event->acceptProposedAction();
}
/**
* @brief QQTWindow::dropEvent
* dropEvent事件
*/
2018-05-29 09:15:15 +08:00
void QQTWindow::dropEvent ( QDropEvent* event )
2017-09-05 18:07:05 +08:00
{
/**
*
*
*/
QList<QUrl> urls = event->mimeData()->urls();
2018-05-29 09:15:15 +08:00
if ( urls.isEmpty() )
2017-09-05 18:07:05 +08:00
return;
/**
*
*/
2018-05-29 09:15:15 +08:00
foreach ( QUrl url, urls )
{
2017-09-05 18:07:05 +08:00
QString file_name = url.toLocalFile();
pline() << file_name;
2018-05-29 09:15:15 +08:00
if ( _player->hasVout() )
2017-09-05 18:07:05 +08:00
_player->stop();
2018-05-29 09:15:15 +08:00
if ( _media )
2017-09-05 18:07:05 +08:00
delete _media;
2018-05-29 09:15:15 +08:00
_media = new VlcMedia ( file_name, true, _instance );
_player->open ( _media );
2017-09-05 18:07:05 +08:00
break;
}
}