文件查看器示例支持 文件预览,编辑和视频播放
以下为文件查看器示例,支持 文件预览,和视频播放:
import QtQuick 2.2
import QtQuick.Window 2.1
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1
import QtMultimedia 5.0
ApplicationWindow {
visible: true
width: 480
height: 360;
color: "black";
title: "文件查看器";
id: root;
property var aboutDlg: null;
property var colorDlg: null;
property color textColor: "green";
property color textBackgroundColor: "black";
menuBar: MenuBar{
Menu {
title: "文件";
MenuItem{
iconSource: "res/txtFile.png";
action: Action{
id: textAction;
iconSource: "res/txtFile.png";
text: "文本文件";
onTriggered: {
fileDialog.selectedNameFilter = fileDialog.nameFilters[0];
fileDialog.open();
}
tooltip: "打开txt等文本文件";
}
}
MenuItem{
action: Action {
id: imageAction;
text: "图片";
iconSource: "res/imageFile.png";
onTriggered: {
fileDialog.selectedNameFilter = fileDialog.nameFilters[1];
fileDialog.open();
}
tooltip: "打开jpg等格式的图片";
}
}
MenuItem{
action: Action {
id: videoAction;
iconSource: "res/videoFile.png";
text: "视频";
onTriggered: {
fileDialog.selectedNameFilter = fileDialog.nameFilters[2];
fileDialog.open();
}
tooltip: "打开TS、MKV、MP4等格式的文件";
}
}
MenuItem{
action: Action {
id: audioAction;
iconSource: "res/audioFile.png";
text: "音乐";
onTriggered: {
fileDialog.selectedNameFilter = fileDialog.nameFilters[3];
fileDialog.open();
}
tooltip: "打开mp3、wma等格式的文件";
}
}
MenuItem{
text: "退出";
onTriggered: Qt.quit();
}
}
Menu {
title: "设置";
MenuItem {
action: Action {
id: textColorAction;
iconSource: "res/ic_textcolor.png";
text: "文字颜色";
onTriggered: root.selectColor(root.onTextColorSelected);
}
}
MenuItem {
action: Action{
id: backgroundColorAction;
iconSource: "res/ic_bkgndcolor.png";
text: "文字背景色";
onTriggered: root.selectColor(root.onTextBackgroundColorSelected);
}
}
MenuItem {
action: Action{
id: fontSizeAddAction;
iconSource: "res/ic_fontsize2.png";
text: "增大字体";
onTriggered: textView.font.pointSize += 1;
}
}
MenuItem {
action: Action{
id: fontSizeMinusAction;
iconSource: "res/ic_fontsize1.png";
text: "减小字体";
onTriggered: textView.font.pointSize -= 1;
}
}
}
Menu {
title: "帮助";
MenuItem{
text: "关于";
onTriggered: root.showAbout();
}
MenuItem{
text: "访问作者博客";
onTriggered: Qt.openUrlExternally("https://blog.csdn.net/lvmengzou");
}
}
}
toolBar: ToolBar{
RowLayout {
ToolButton{
action: textAction;
}
ToolButton{
action: imageAction;
}
ToolButton{
action: videoAction;
}
ToolButton{
action: audioAction;
}
ToolButton{
action: textColorAction;
}
ToolButton {
action: backgroundColorAction;
}
ToolButton {
action: fontSizeAddAction;
}
ToolButton {
action: fontSizeMinusAction;
}
}
}
statusBar: Rectangle {
color: "lightgray";
implicitHeight: 30;
width: parent.width;
property alias text: status.text;
Text {
id: status;
anchors.fill: parent;
anchors.margins: 4;
font.pointSize: 12;
}
}
Item {
id: centralView;
anchors.fill: parent;
visible: true;
property var current: null;
BusyIndicator {
id: busy;
anchors.centerIn: parent;
running: false;
z: 3;
}
Image {
id: imageViewer;
anchors.fill: parent;
visible: false;
asynchronous: true;
fillMode: Image.PreserveAspectFit;
onStatusChanged: {
if (status === Image.Loading) {
centralView.busy.running = true;
}
else if(status === Image.Ready){
centralView.busy.running = false;
}
else if(status === Image.Error){
centralView.busy.running = false;
centralView.statusBar.text = "图片无法显示";
}
}
}
TextArea {
id: textView;
anchors.fill: parent;
readOnly: true;
visible: false;
wrapMode: TextEdit.WordWrap;
font.pointSize: 12;
style: TextAreaStyle{
backgroundColor: root.textBackgroundColor;
textColor: root.textColor;
selectionColor: "steelblue";
selectedTextColor: "#a00000";
}
property var xmlhttp: null;
function onReadyStateChanged(){
if(xmlhttp.readyState == 4){
text = xmlhttp.responseText;
xmlhttp.abort();
}
}
function loadText(fileUrl){
if(xmlhttp == null){
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = onReadyStateChanged;
}
if(xmlhttp.readyState == 0){
xmlhttp.open("GET", fileUrl);
xmlhttp.send(null);
}
}
}
VideoOutput {
id: videoOutput;
anchors.fill: parent;
visible: false;
source: player;
onVisibleChanged: {
playerState.visible = visible;
if(visible == false){
player.stop();
}
}
MouseArea {
anchors.fill: parent;
onClicked: {
switch(player.playbackState){
case MediaPlayer.PausedState:
case MediaPlayer.StoppedState:
player.play();
break;
case MediaPlayer.PlayingState:
player.pause();
break;
}
}
}
}
Rectangle {
id: playerState;
color: "gray";
radius: 16;
opacity: 0.8;
visible: false;
z: 2;
implicitHeight: 80;
implicitWidth: 200;
anchors.horizontalCenter: parent.horizontalCenter;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 16;
Column {
anchors.fill: parent;
anchors.leftMargin: 12;
anchors.rightMargin: 12;
anchors.topMargin: 6;
anchors.bottomMargin: 6;
spacing: 4;
Text {
id: state;
font.pointSize: 14;
color: "blue";
}
Text {
id: progress;
font.pointSize: 12;
color: "white";
}
}
}
MediaPlayer {
id: player;
property var utilDate: new Date();
function msecs2String(msecs){
utilDate.setTime(msecs);
return Qt.formatTime(utilDate, "mm:ss");
}
property var sDuration;
onPositionChanged: {
progress.text = msecs2String(position) + sDuration;
}
onDurationChanged: {
sDuration = " / " + msecs2String(duration);
}
onPlaybackStateChanged: {
switch(playbackState){
case MediaPlayer.PlayingState:
state.text = "播放中";
break;
case MediaPlayer.PausedState:
state.text = "已暂停";
break;
case MediaPlayer.StoppedState:
state.text = "停止";
break;
}
}
onStatusChanged: {
switch(status){
case MediaPlayer.Loading:
case MediaPlayer.Buffering:
busy.running = true;
break;
case MediaPlayer.InvalidMedia:
root.statusBar.text = "无法播放";
case MediaPlayer.Buffered:
case MediaPlayer.Loaded:
busy.running = false;
break;
}
}
}
}
function processFile(fileUrl, ext){
var i = 0;
for(; i < fileDialog.nameFilters.length; i++){
if(fileDialog.nameFilters[i].search(ext) != -1) break;
}
switch(i){
case 0:
//text file
if(centralView.current != textView){
if(centralView.current != null){
centralView.current.visible = false;
}
textView.visible = true;
centralView.current = textView;
}
textView.loadText(fileUrl);
break;
case 1:
if(centralView.current != imageViewer){
if(centralView.current != null){
centralView.current.visible = false;
}
imageViewer.visible = true;
centralView.current = imageViewer;
}
imageViewer.source = fileUrl;
break;
case 2:
case 3:
if(centralView.current != videoOutput){
if(centralView.current != null){
centralView.current.visible = false;
}
videoOutput.visible = true;
centralView.current = videoOutput;
}
player.source = fileUrl;
player.play();
break;
default:
statusBar.text = "抱歉,处理不了";
break;
}
}
function showAbout(){
if(aboutDlg == null){
aboutDlg = Qt.createQmlObject(
'import QtQuick 2.2;import QtQuick.Dialogs 1.1;MessageDialog{icon: StandardIcon.Information;title: "关于";\ntext: "仅仅是个示例撒";\nstandardButtons:StandardButton.Ok;}'
, root, "aboutDlg");
aboutDlg.accepted.connect(onAboutDlgClosed);
aboutDlg.rejected.connect(onAboutDlgClosed);
aboutDlg.visible = true;
}
}
function selectColor(func){
if(colorDlg == null){
colorDlg = Qt.createQmlObject(
'import QtQuick 2.2;import QtQuick.Dialogs 1.1;ColorDialog{}',
root, "colorDlg");
colorDlg.accepted.connect(func);
colorDlg.accepted.connect(onColorDlgClosed);
colorDlg.rejected.connect(onColorDlgClosed);
colorDlg.visible = true;
}
}
function onAboutDlgClosed(){
aboutDlg.destroy();
aboutDlg = null;
}
function onColorDlgClosed(){
colorDlg.destroy();
colorDlg = null;
}
function onTextColorSelected(){
root.textColor = colorDlg.color;
}
function onTextBackgroundColorSelected(){
root.textBackgroundColor = colorDlg.color;
}
FileDialog {
id: fileDialog;
title: qsTr("Please choose an image file");
nameFilters: [
"Text Files (*.txt *.ini *.log *.c *.h *.java *.cpp *.html *.xml)",
"Image Files (*.jpg *.png *.gif *.bmp *.ico)",
"Video Files (*.ts *.mp4 *.avi *.flv *.mkv *.3gp)",
"Audio Files (*.mp3 *.ogg *.wav *.wma *.ape *.ra)",
"*.*"
];
onAccepted: {
var filepath = new String(fileUrl);
//remove file:///
if(Qt.platform.os == "windows"){
root.statusBar.text = filepath.slice(8);
}else{
root.statusBar.text = filepath.slice(7);
}
var dot = filepath.lastIndexOf(".");
var sep = filepath.lastIndexOf("/");
if(dot > sep){
var ext = filepath.substring(dot);
root.processFile(fileUrl, ext.toLowerCase());
}else{
root.statusBar.text = "Not Supported!";
}
}
}
}
文件查看器示例支持 文件预览,编辑和视频播放相关推荐
- 【实用软件】Json文件查看器(支持查看超大JSON文件)
内容信息 软件类型:绿色 软件平台:电脑 软件版本:v1.0 软件大小:3.4MB 软件特点 Json文件查看器是一个用来查看Json文件的的绿色软件
- 【iOS_GitHub】文档/文件查看器(支持本地或者其他app分享过来的word、excel、pdf、rtf等格式文件)
DocViewer(文档/文件查看器) Function Description 文档查看器(Word && Excel && PDF && Rft | ...
- 基于Web的文件管理系统,支持Office、WPS预览/编辑、在线解压缩、文件分享、文件加密、远程存储、远程文件推送、秒传、断点
基于Web的文件管理系统,支持权限管理.历史版本管理.Office预览/编辑.WPS预览/编辑.在线解压缩.文件分享.文件加密.远程存储.远程文件推送.秒传.断点续传.智能搜索.文件备注.本地自动备份 ...
- 利用第三方API实现文件在线预览/编辑/上传/下载等功能
个人的需求是想做一些在线预览编辑之类的事情,这里我使用了第三方(永中软件)的云编辑API接口,其支持doc/docx,ppt/pptx,xls/xlsx文件,需要先进行注册. 具体步骤如下: 一.先需 ...
- mhtml文件查看器MHT Viewer Mac版
MHT Viewer 是一个轻量级的 MHT (MHTML/MIME HTML) 文档查看器/阅读器. 点击获得MHT Viewer for Mac(mhtml文件查看器) MHT Viewer fo ...
- SpringBoot+MongoDB GridFS文件上传、下载、预览实战
SpringBoot + MongoDB GridFS 随着web 3.0的兴起,数据的形式不局限于文字,还有语音.视频.图片等.高效存储与检索二进制数据也成为web 3.0必须要考虑的问题.然而这种 ...
- 文件上传,下载,预览,删除(File),分页接口
文件上传,下载,预览,删除(File) 1.公共参数方法 1.1公共返回类型定义 1.2 分页接口 1.3公共实体类 1.4 公共的 mapper.java/xml(都放在一起) 1.4.1 File ...
- Springboot + layui + FTP文件上传删除 + HTTP文件下载预览 + pdf.js文件预览(项目实战总结)
文件管理 0.需求及前言 1.前端,上传按钮嵌入数据表格中 2.利用IIS部署FTP文件服务器 3.后台FTP连接和文件操作 4.FTP遇到的问题和解决方案 5.预览PDF文件V1.0:FTP+临时文 ...
- 【玩转.Net MF – 03】远程文件查看器
虽说目前.Net Micro Framework已经支持文件系统(FAT16/FAT32),但在远程还无法直接访问,从某种意义上讲,无法和PC交互的存储介质显得有些鸡肋.我做SideShow相关开发的 ...
最新文章
- ios bug 分析
- javascript之iframe
- 电路非门_【连载】电路和维修基础之门电路、转换器
- Kafka设计解析(二):Kafka High Availability (上)
- 16.编译错误Unknown CMake command “check_symbol_exists“解决
- 51CTO学院四周年-成长之路
- python数据可视化代码_python数据可视化
- plsql数据库异常---plsql 登录后,提示数据库字符集(AL32UTF8)和客户端字符集(ZHS16GBK)不一致
- mysql查询的是问号_MySQL客户端查询中文显示为问号(linux) | 学步园
- 助力南京打造创新名城 第三届未来网络发展大会将召开
- eclipse中配置heritrix1.14.3
- C语言———不定参数标准库 stdarg.h
- 阿里—最新iOS面试题总结
- js 跨域下载链接 下载文件 实现重命名,文件名称 兼容处理
- bootice.exe linux 启动盘,BOOTICE(无损)制作启动盘-适用于移动硬盘与U盘(支持BIOS及EFI启动)...
- 机器学习算法(三十):强化学习(Reinforcement Learning)
- Q3中国网游业观察:腾讯网易春风得意
- 60级高阶督军套装属性_魔兽世界60年代法师套装大解析,最经典实用的果然是灵风套装...
- java题兔子第三个月生_JAVA编程之古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子...
- 华米Amazfit GTS 2e用续航和高性价比征服外媒
热门文章
- Source Insight3.5主题设置
- Typora个人主题设置
- STM32使用ADC+电位器测电压
- linux 安卓打印服务器,我无法在打印机服务器的打印机上打印客服端计算机的数据。(Linux)...
- SAP销售返利(回扣)实现方法
- 【jQuery案例】手风琴
- 独立硬盘冗余阵列-RAID
- C语言-入门-必备基础知识(九)
- 润生集团2021年度业绩内部汇报 | 探索·前行·创造
- 海南大学-数据库课程设计-企业人事档案管理系统