⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qt_gui.cpp

📁 彩信浏览器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA/* qt_gui.cpp - Qt GUI for Ambulant *               */#include <pthread.h>#include <libgen.h>#include <stdlib.h>#include <fcntl.h>#include "qt_gui.h"#include "qt_mainloop.h"#include "qt_logger.h"#include "qt_renderer.h"#include <qthread.h>#include "ambulant/config/config.h"#include "ambulant/lib/logger.h"#include "ambulant/version.h"#include "ambulant/gui/qt/qt_includes.h"#include "ambulant/gui/qt/qt_factory.h"//#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endif#define	WITH_QT_LOGGERconst QString about_text1 = 	"Ambulant SMIL 2.1 player.\nVersion: ";const QString about_text2 = 	"\nCopyright Stichting CWI, 2003-2007.\n\n"	"License: LGPL";// Places where to look for the Welcome documentconst char *welcome_locations[] = {	"Welcome/Welcome.smil",	"../Welcome/Welcome.smil",	"Extras/Welcome/Welcome.smil",	"../Extras/Welcome/Welcome.smil",#ifdef AMBULANT_DATADIR	AMBULANT_DATADIR "/Welcome/Welcome.smil",#else	"/usr/local/share/ambulant/Welcome/Welcome.smil",#endif#ifdef	QT_NO_FILEDIALOG	/* Assume embedded Qt */	"/home/zaurus/Documents/Ambulant/Extras/Welcome/Welcome.smil",#endif/*QT_NO_FILEDIALOG*/	NULL};// Places where to look for the helpfileconst char *helpfile_locations[] = {	"Documentation/user/index.html",	"../Documentation/user/index.html",#ifdef AMBULANT_DATADIR	AMBULANT_DATADIR "/AmbulantPlayerHelp/index.html",#else	"/usr/local/share/ambulant/AmbulantPlayerHelp/index.html",#endif	NULL};static const char * find_datafile(const char **locations){	const char **p;	for(p = locations; *p; p++) {		if (access(*p, 0) >= 0) return *p;	}	return NULL;}qt_gui::qt_gui(const char* title,	       const char* initfile) :#ifdef	WITH_QT_HTML_WIDGET  KMainWindow(0L, title),#else /*WITH_QT_HTML_WIDGET*/	QWidget(),  #endif/*WITH_QT_HTML_WIDGET*/#ifndef QT_NO_FILEDIALOG	/* Assume plain Qt */	m_cursor_shape(Qt::ArrowCursor),#else /*QT_NO_FILEDIALOG*/	/* Assume embedded Qt */	//m_cursor_shape(arrowCursor);	m_fileselector(NULL),	m_settings_selector(NULL),#endif/*QT_NO_FILEDIALOG*/	m_mainloop(NULL),#ifdef	TRY_LOCKING	m_gui_thread(0),#endif/*TRY_LOCKING*/	m_smilfilename(NULL){	m_programfilename = title;#ifdef	TRY_LOCKING	pthread_cond_init(&m_cond_message, NULL);	pthread_mutex_init(&m_lock_message, NULL);	m_gui_thread = pthread_self();#endif/*TRY_LOCKING*/	if (initfile != NULL && initfile != "")		m_smilfilename = QString(initfile);#ifdef  QT_NO_FILEDIALOG	else		m_smilfilename = QString(			"/home/zaurus/Documents/example.smil");#endif/*QT_NO_FILEDIALOG*/	setCaption(initfile);	/* Menu bar */	m_menubar = new QMenuBar(this,"MainMenu");	{		int id;		/* File */		m_filemenu = new QPopupMenu (this);		assert(m_filemenu);		int open_id = m_filemenu->insertItem(gettext("&Open..."), this, SLOT(slot_open()));		m_filemenu->setAccel(CTRL+Key_O, open_id);		int url_id = m_filemenu->insertItem(gettext("Open &URL..."), this, SLOT(slot_open_url()));		m_filemenu->setAccel(CTRL+Key_L, url_id);		m_reload_id = m_filemenu->insertItem(gettext("&Reload..."), this, SLOT(slot_reload()));#ifdef QT_NO_FILEDIALOG	/* Assume embedded Qt */		// Disable unavailable menu entries		m_filemenu->setItemEnabled(open_id, true);		m_filemenu->setItemEnabled(url_id, false);#endif/*QT_NO_FILEDIALOG*/		m_filemenu->insertSeparator();				m_filemenu->insertItem(gettext("&Preferences..."), this, SLOT(slot_settings_select()));		m_filemenu->insertItem(gettext("&Document Settings..."), this, SLOT(slot_load_settings()));		m_filemenu->insertSeparator();				int quit_id = m_filemenu->insertItem(gettext("&Quit"), this, SLOT(slot_quit()));		m_filemenu->setAccel(CTRL+Key_Q, quit_id);		m_menubar->insertItem(gettext("&File"), m_filemenu);				/* Play */		m_playmenu = new QPopupMenu (this, "PlayA");		assert(m_playmenu);		m_play_id = m_playmenu->insertItem(gettext("Pla&y"), this, SLOT(slot_play()));		m_playmenu->setAccel(CTRL+Key_P, m_play_id);		m_playmenu->setItemEnabled(m_play_id, false);		m_pause_id = m_playmenu->insertItem(gettext("&Pause"), this, SLOT(slot_pause()));		m_playmenu->setAccel(CTRL+Key_Space, m_pause_id);		m_playmenu->setItemEnabled(m_pause_id, false);		m_stop_id = m_playmenu->insertItem(gettext("&Stop"), this, SLOT(slot_stop()));		m_playmenu->setAccel(CTRL+Key_S, m_stop_id);		m_menubar->insertItem(gettext("Pla&y"), m_playmenu);				/* View */		m_viewmenu = new QPopupMenu(this, "View");		int fullscreen_id = m_viewmenu->insertItem(gettext("&Full Screen"), this, SLOT(showFullScreen()));		m_viewmenu->setAccel(CTRL+Key_F, fullscreen_id);		int window_id = m_viewmenu->insertItem(gettext("&Window"), this, SLOT(showNormal()));		m_viewmenu->setAccel(CTRL+SHIFT+Key_F, window_id);		m_viewmenu->insertSeparator();#ifdef	WITH_QT_LOGGER		m_viewmenu->insertItem(gettext("&Log Window..."), this, SLOT(slot_logger_window()));#endif/*WITH_QT_LOGGER*/		m_menubar->insertItem(gettext("&View"), m_viewmenu);				/* Help */		m_helpmenu = new QPopupMenu (this, "HelpA");		assert(m_helpmenu);		m_helpmenu->insertItem(gettext("&About AmbulantPlayer"), this, SLOT(slot_about()));		int help_id = m_helpmenu->insertItem(gettext("AmbulantPlayer &Help..."), this, SLOT(slot_help()));		m_helpmenu->setAccel(CTRL+Key_Question, help_id);		m_helpmenu->insertSeparator();		m_helpmenu->insertItem(gettext("AmbulantPlayer &Website..."), this, SLOT(slot_homepage()));		m_helpmenu->insertItem(gettext("&Play Welcome Document"), this, SLOT(slot_welcome()));		m_menubar->insertItem(gettext("&Help"), m_helpmenu);		m_menubar->setGeometry(0,0,320,20);#ifndef QT_NO_FILEDIALOG	/* Assume plain Qt */		m_menubar_height = 27;#else /*QT_NO_FILEDIALOG*/	/* Assume embedded Qt */		m_menubar_height = 20;#endif/*QT_NO_FILEDIALOG*/	}	QObject::connect(this, SIGNAL(signal_player_done()),			    this, SLOT(slot_player_done()));	_update_menus();}qt_gui::~qt_gui() {#define DELETE(X) if (X) { delete X; X = NULL; }	AM_DBG printf("%s0x%X\n", "qt_gui::~qt_gui(), m_mainloop=",m_mainloop);	setCaption(QString::null);#ifdef  QT_NO_FILEDIALOG	/* Assume embedded Qt */	DELETE(m_fileselector)	DELETE(m_settings_selector)#endif/*QT_NO_FILEDIALOG*/	DELETE(m_mainloop) 	DELETE(m_filemenu)	DELETE(m_helpmenu)	DELETE(m_playmenu)	DELETE(m_viewmenu)	DELETE(m_menubar)	m_smilfilename = (char *)NULL;}void qt_gui::slot_about() {	int but = QMessageBox::information(this, gettext("About AmbulantPlayer"),					   about_text1+get_version()+about_text2,					   gettext("OK"));}void qt_gui::slot_homepage() {	open_web_browser("http://www.ambulantplayer.org");}void qt_gui::slot_welcome() {	const char *welcome_doc = find_datafile(welcome_locations);		if (welcome_doc) {		if( openSMILfile(welcome_doc, IO_ReadOnly)) {			slot_play();		}	} else {		QMessageBox::information(this, m_programfilename, 			gettext("Cannot find Welcome.smil document"));	}}void qt_gui::slot_help() {	const char *help_doc = find_datafile(helpfile_locations);		if (help_doc) {		open_web_browser(help_doc);	} else {		QMessageBox::information(this, m_programfilename, 			gettext("Cannot find Ambulant Player Help"));	}}voidqt_gui::slot_logger_window() {	AM_DBG printf("slot_logger_window()\n");#ifndef QT_NO_FILEDIALOG	 /* Assume plain Qt */	QTextEdit* logger_window =		qt_logger::get_qt_logger()->get_logger_window();	if (logger_window->isHidden())		logger_window->show();	else		logger_window->hide();#endif/*QT_NO_FILEDIALOG*/}bool checkFilename(QString filename, int mode) {	QFile* file = new QFile(filename);	return file->open(mode);}voidqt_gui::fileError(QString smilfilename) { 	char buf[1024];	sprintf(buf, gettext("%s: Cannot open file: %s"),		(const char*) smilfilename, strerror(errno));	QMessageBox::information(this, m_programfilename, buf);}bool qt_gui::openSMILfile(QString smilfilename, int mode) {	if (smilfilename.isNull())		return false;#if 0	if (! checkFilename(smilfilename, mode)) {		fileError(smilfilename);		return false;	}#endif	char* filename = strdup(smilfilename);	setCaption(basename(filename));	free(filename);	m_playmenu->setItemEnabled(m_pause_id, false);	m_playmenu->setItemEnabled(m_play_id, true);	m_smilfilename = smilfilename;	if (m_mainloop != NULL)		delete m_mainloop; 	m_mainloop = new qt_mainloop(this, m_menubar_height);	return m_mainloop->is_open();}void qt_gui::slot_open() {#ifndef QT_NO_FILEDIALOG	QString smilfilename =		QFileDialog::getOpenFileName(				 ".", // Initial dir				 gettext("SMIL files (*.smil *.smi);; All files (*.smil *.smi *.mms *.grins);; Any file (*)"), // file types				 this,				 gettext("open file dialog"),				 gettext("Double Click a file to open")				 );	if (openSMILfile(smilfilename, IO_ReadOnly))		slot_play();#else	/*QT_NO_FILEDIALOG*/		if (m_fileselector == NULL) {		QString mimeTypes("application/smil;");		m_fileselector = new FileSelector(mimeTypes, NULL,						  "slot_open", false);		m_fileselector->resize(240, 280);	} else {		m_fileselector->reread();	}	QObject::connect(m_fileselector, SIGNAL(fileSelected(const DocLnk&)),			 this, SLOT(slot_file_selected(const DocLnk&)));	QObject::connect(m_fileselector, SIGNAL(closeMe()), 			 this, SLOT(slot_close_fileselector()));	m_fileselector->show();#endif	/*QT_NO_FILEDIALOG*/}voidqt_gui::setDocument(const QString& smilfilename) {#ifdef	QT_NO_FILEDIALOG	/* Assume embedded Qt */	if (openSMILfile(smilfilename, IO_ReadOnly))		slot_play();#endif/*QT_NO_FILEDIALOG*/}voidqt_gui::slot_file_selected(const DocLnk& selected_file) {#ifdef	QT_NO_FILEDIALOG	/* Assume embedded Qt */	QString* smilfilepointer = new QString(selected_file.file());	QString smilfilename = *smilfilepointer;	delete smilfilepointer;	m_fileselector->hide();	if (openSMILfile(smilfilename, IO_ReadOnly))		slot_play();#endif/*QT_NO_FILEDIALOG*/}voidqt_gui::slot_close_fileselector()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -