📄 qt_factory.cpp
字号:
// 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 //#define AM_DBG if(1)#ifndef AM_DBG#define AM_DBG if(0)#endif #include "ambulant/gui/qt/qt_includes.h"#include "ambulant/gui/qt/qt_factory_impl.h"#include "ambulant/gui/qt/qt_image_renderer.h"#ifdef WITH_QT_HTML_WIDGET#include "ambulant/gui/qt/qt_html_renderer.h"#endif/*WITH_QT_HTML_WIDGET*/#include "ambulant/gui/qt/qt_text_renderer.h"#include "ambulant/gui/qt/qt_video_renderer.h"#include "qcursor.h"using namespace ambulant;using namespace gui::qt;using namespace net;//---------------------------------------------------------------------------// External interfacescommon::window_factory *ambulant::gui::qt::create_qt_window_factory(QWidget *parent_widget, int top_offset, gui_player *gpl){ return new qt_window_factory(parent_widget, top_offset, gpl);}common::window_factory *ambulant::gui::qt::create_qt_window_factory_unsafe(void *parent_widget, int top_offset, gui_player *gpl){ QWidget *qw = reinterpret_cast<QWidget*>(parent_widget); if (qw == NULL) { lib::logger::get_logger()->fatal("create_qt_window_factory: Not a QWidget!"); return NULL; } return new qt_window_factory(qw, top_offset, gpl);}common::playable_factory *ambulant::gui::qt::create_qt_playable_factory(common::factories *factory){ return new qt_renderer_factory(factory);}common::playable_factory *ambulant::gui::qt::create_qt_video_factory(common::factories *factory){ return new qt_video_factory(factory);}//---------------------------------------------------------------------------// Internal implementations//// Auxiliary/debug code to dump pixmaps at various stages of transitions and// such. Enable by defining WITH_DUMPPIXMAP//#ifndef WITH_DUMPPIXMAP#define DUMPPIXMAP(qpm, filename) /* nothing */#else#define DUMPPIXMAP(qpm, filename) dumpPixmap(qpm, filename)static QImage* oldImageP;static bool isEqualToPrevious(QPixmap* qpmP) { return false; QImage img = qpmP->convertToImage(); if (oldImageP != NULL && img == *oldImageP) { AM_DBG lib::logger::get_logger()->debug("isEqualToPrevious: new image not different from old one"); return true; } else { if (oldImageP != NULL) delete oldImageP; oldImageP = new QImage(img); return false; }}void gui::qt::dumpPixmap(QPixmap* qpm, std::string filename) { if ( ! qpm) return; QImage img = qpm->convertToImage(); if ( ! isEqualToPrevious(qpm)) { static int i; char buf[5]; sprintf(buf,"%04d",i++); std::string newfile = buf + std::string(filename) +".png"; qpm->save(newfile, "PNG"); AM_DBG lib::logger::get_logger()->debug("dumpPixmap(%s)", newfile.c_str()); }}#endif /* WITH_DUMPPIXMAP *///// qt_renderer_factory//qt_renderer_factory::qt_renderer_factory(common::factories *factory): m_factory(factory){ AM_DBG lib::logger::get_logger()->debug("qt_renderer factory (0x%x)", (void*) this);}common::playable *qt_renderer_factory::new_playable( common::playable_notification *context, common::playable_notification::cookie_type cookie, const lib::node *node, lib::event_processor *const evp) { lib::xml_string tag = node->get_qname().second; common::playable* rv; if (tag == "img") { rv = new qt_image_renderer(context, cookie, node, evp, m_factory); AM_DBG lib::logger::get_logger()->debug("qt_renderer_factory: node 0x%x: returning qt_image_renderer 0x%x", (void*) node, (void*) rv); return rv; } if (tag == "brush") { rv = new qt_fill_renderer(context, cookie, node, evp, m_factory); AM_DBG lib::logger::get_logger()->debug("qt_renderer_factory: node 0x%x: returning qt_fill_renderer 0x%x", (void*) node, (void*) rv); return rv; } if ( tag == "text") {#ifdef WITH_QT_HTML_WIDGET net::url url = net::url(node->get_url("src")); if (url.guesstype() == "text/html") { rv = new qt_html_renderer(context, cookie, node, evp, m_factory); AM_DBG lib::logger::get_logger()->debug("qt_renderer_factory: node 0x%x: returning qt_html_renderer 0x%x", (void*) node, (void*) rv); return rv; }#endif /*WITH_QT_HTML_WIDGET*/ rv = new qt_text_renderer(context, cookie, node, evp, m_factory); AM_DBG lib::logger::get_logger()->debug("qt_renderer_factory: node 0x%x: returning qt_text_renderer 0x%x", (void*) node, (void*) rv); return rv; } return NULL;}common::playable *qt_renderer_factory::new_aux_audio_playable( common::playable_notification *context, common::playable_notification::cookie_type cookie, const lib::node *node, lib::event_processor *evp, net::audio_datasource *src){ return NULL;} //// qt_window_factory//qt_window_factory::qt_window_factory( QWidget* parent_widget, int top_offset, gui_player *gpl): m_parent_widget(parent_widget), m_top_offset(top_offset), m_gui_player(gpl){ AM_DBG lib::logger::get_logger()->debug("qt_window_factory (0x%x)", (void*) this);} common::gui_window *qt_window_factory::new_window (const std::string &name, lib::size bounds, common::gui_events *region){ lib::rect* r = new lib::rect(lib::point(0, m_top_offset), bounds); AM_DBG lib::logger::get_logger()->debug("qt_window_factory::new_window (0x%x): name=%s %d,%d,%d,%d", (void*) this, name.c_str(), r->left(),r->top(),r->right(),r->bottom()); ambulant_qt_window * aqw = new ambulant_qt_window(name, r, region); qt_ambulant_widget * qaw = new qt_ambulant_widget(name, r, m_parent_widget);#ifndef QT_NO_FILEDIALOG /* Assume plain Qt */ qaw->setBackgroundMode(Qt::NoBackground); assert(qApp); assert(qApp->mainWidget()); qApp->mainWidget()->resize(bounds.w, bounds.h+m_top_offset);#else /*QT_NO_FILEDIALOG*/ /* Assume embedded Qt */ qaw->setBackgroundMode(QWidget::NoBackground); /* No resize implemented for embedded Qt */#endif /*QT_NO_FILEDIALOG*/ aqw->set_ambulant_widget(qaw); qaw->set_qt_window(aqw); qaw->set_gui_player(m_gui_player); AM_DBG lib::logger::get_logger()->debug("qt_window_factory::new_window(0x%x): ambulant_widget=0x%x qt_window=0x%x", (void*) this, (void*) qaw, (void*) aqw); qaw->show(); return aqw;}common::bgrenderer *qt_window_factory::new_background_renderer(const common::region_info *src){ AM_DBG lib::logger::get_logger()->debug("qt_window_factory::new_background_renderer(0x%x): src=0x%x", (void*) this, src); return new qt_background_renderer(src);}//// qt_video_factory//qt_video_factory::~qt_video_factory(){}common::playable *qt_video_factory::new_playable( common::playable_notification *context, common::playable_notification::cookie_type cookie, const lib::node *node, lib::event_processor *evp){ common::playable *rv; lib::xml_string tag = node->get_qname().second; AM_DBG lib::logger::get_logger()->debug("qt_video_factory: node 0x%x: inspecting %s\n", (void *)node, tag.c_str()); if ( tag == "video") { rv = new qt_video_renderer(context, cookie, node, evp, m_factory); AM_DBG lib::logger::get_logger()->debug("qt_video_factory: node 0x%x: returning qt_video_renderer 0x%x", (void *)node, (void *)rv); } else { AM_DBG lib::logger::get_logger()->debug("qt_video_factory: no renderer for tag \"%s\"", tag.c_str()); return NULL; } return rv;}common::playable *qt_video_factory::new_aux_audio_playable( common::playable_notification *context, common::playable_notification::cookie_type cookie, const lib::node *node, lib::event_processor *evp, net::audio_datasource *src){ return NULL;}//// ambulant_qt_window//ambulant_qt_window::ambulant_qt_window(const std::string &name, lib::rect* bounds, common::gui_events *region): common::gui_window(region), m_ambulant_widget(NULL), m_pixmap(NULL), m_oldpixmap(NULL), m_tmppixmap(NULL), m_fullscreen_count(0), m_fullscreen_prev_pixmap(NULL), m_fullscreen_old_pixmap(NULL), m_fullscreen_engine(NULL), m_fullscreen_now(0), m_surface(NULL){ AM_DBG lib::logger::get_logger()->debug("ambulant_qt_window::ambulant_qt_window(0x%x)",(void *)this);}ambulant_qt_window::~ambulant_qt_window(){ AM_DBG lib::logger::get_logger()->debug("ambulant_qt_window::~ambulant_qt_window(0x%x): m_ambulant_widget=0x%x, m_pixmap=0x%x",this,m_ambulant_widget, m_pixmap); // Note that we don't destroy the widget, only sver the connection. // the widget itself is destroyed independently. if (m_ambulant_widget ) { m_ambulant_widget->set_qt_window(NULL); delete m_ambulant_widget; m_ambulant_widget = NULL; delete m_pixmap; m_pixmap = NULL; if (m_tmppixmap != NULL) { delete m_tmppixmap; m_tmppixmap = NULL; } }} voidambulant_qt_window::need_redraw(const lib::rect &r){ AM_DBG lib::logger::get_logger()->debug("ambulant_qt_window::need_redraw(0x%x): ltrb=(%d,%d,%d,%d)", (void *)this, r.left(), r.top(), r.right(), r.bottom()); if (m_ambulant_widget == NULL) { lib::logger::get_logger()->error("ambulant_qt_window::need_redraw(0x%x): m_ambulant_widget == NULL !!!", (void*) this); return; }#ifdef QT_NO_FILEDIALOG /* Assume embedded Qt */ m_ambulant_widget->repaint(r.left(), r.top(), r.width(), r.height(), false); qApp->wakeUpGuiThread();// qApp->processEvents();#else /*QT_NO_FILEDIALOG*/ /* Assume plain Qt */ m_ambulant_widget->update(r.left(), r.top(), r.width(), r.height()); qApp->wakeUpGuiThread();#endif /*QT_NO_FILEDIALOG*/}voidambulant_qt_window::redraw_now(){ AM_DBG lib::logger::get_logger()->debug("ambulant_qt_window::redraw_now()"); m_ambulant_widget->repaint(false);}voidambulant_qt_window::need_events(bool want) { AM_DBG lib::logger::get_logger()->debug("ambulant_qt_window::need_events(0x%x): want=%d", this, want);}#if 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -