From a2c6fcecf195bb2016e86318689486827981cab1 Mon Sep 17 00:00:00 2001
From: unknown The QtBrowserPlugin solution makes it easy to write browser plugins that can be used in Netscape, Mozilla FireFox, Opera, and any other web browser supporting the "npruntime" API: http://www.mozilla.org/projects/plugins/ http://www.mozilla.org/projects/plugins/npruntime.html Current versions of Microsoft Internet Explorer do not support this API. However, you can use the ActiveQt framework to compile a single plugin library that works with all web browsers. Since any QWidget or QObject subclass can be turned into a plugin with little effort it is usually easiest to do the development as a stand-alone Qt application - debugging plugins is cumbersome. Make sure that the subclasses you want to export use the Q_OBJECT macro and provide a default constructor. Use the Q_CLASSINFO macro to specify a list of MIME types each of your classes supports, and export the classes through the QtNPFactory macros: Include the qtbrowserplugin.pri in your .pro file, and regenerate the makefile with qmake. The resulting makefile will generate a shared library with a file name starting with "np" - this is required by all browsers to recognize the library as a plugin. On Windows it is required to link a version resource into the plugin library. To do that, create an .rc file (a plain-text file) and add it to the RC_FILE variable of your project. The .rc file needs to contain a version description like here: To build a plugin project with ActiveX support, use ActiveQt's QAxServer module by adding the following line to your project: CONFIG += qaxserver Also, add the following line to your resource file 1 TYPELIB "thisfile.rc" In your plugin code, use Q_CLASSINFO and the QAxFactory macros as usual. When you build the plugin, then ActiveQt will perform the build steps required to turn the plugin library into an ActiveX control server which provides your plugin classes not only to browsers supporting the npruntime API, but also to browsers supporting ActiveX controls (i.e. Internet Explorer). However, not that calling QtNPBindable APIs will not do anything when the browser does not support the npruntime API. In some cases, QAxBindable provides equivalent APIs (i.e. for reading incoming data). On Unix/Linux, QtBrowserPlugin uses the XEmbed protocol. This is a fairly recent addition to the NPP plugin API. At the time of writing, it is not supported by the Opera and Konqueror browsers. Firefox and other Mozilla/Gecko-based browsers do support it. Update: Opera version 9.50 will support the XEmbed protocol. QtBrowserPlugin is tested successfully with the beta release of Opera 9.50. One known issue: Opera does not automatically register the extension part of the MIME description. If required, work around by adding it manually in the Preferences->Advanced->Download dialog. (e.g. add "g1n" to "application/x-graphable" to make the grapher example work). There are two known issues that may cause the plugin to crash on initialization, possibly taking the browser down with it: In addition, Firefox may emit this warning when initializing the plugin: _XEMBED_INFO property has wrong type. This is fixed in Qt 4.3.1 and later. To build a browser plugin on Mac, two plain-text resource files are needed: an Info.plist file and a .r file. To create these files, it is easiest to use the ones provided with the QtBrowserPlugin examples as templates, editing as necessary. Then add them to your project (.pro file) like this: Most browsers provide a UI to display all loaded plugins. Use this functionality to diagnose problems. The plugin will need to load the Qt libraries at runtime (unless they are statically linked into the plugin). Hence, the required Qt dynamic libraries (at least QtCore, QtGui, and QtNetwork) must be located in a directory which the system searches for DLLs. This may or may not include the directory where the plugin itself is located, depending on the OS and browser. Windows, Netscape-style browsers: To install the plugin, copy the plugin library in the "plugins" directory of the browser. See src/qtbrowserplugin.pri for some typical paths. Windows, Internet Explorer: The Makefile generated by qmake by default runs the necessary commands to register the plugin as an ActiveX server (if CONFIG includes qaxserver). To unregister, use the following command: Mac: The build will result in a directory called myplugin.plugin. To install, copy this directory with all contents to /Library/Internet Plugins. Unix: Copy the file myplugin.so to the browser or system plugin directory, typically /usr/lib/browser-plugins. The path to the Qt libraries may be set in the LD_LIBRARY_PATH environment variable of the browser process. Different browser support different embedding tags, but the following should work with Netscape, FireFox, Opera and Internet Explorer (if the plugin has been compiled as an ActiveX server as well). Objects can be initialized with a data file, which will be delivered to the plugin at some point after plugin creation to the plugin through the QtNPBindable::readData() virtual function. Note that some browsers will not display or immediately unload the plugin if the data file does not exist, while other browsers will display the plugin without ever calling readData(). For additional information, see http://devedge-temp.mozilla.org/library/manuals Plugins embedded into browsers that support the respecive NPAPI extensions as well as ActiveX controls can be accessed from JavaScript in the HTML page. Before the object can be accessed, some browsers require it to be located based on the id in the object tag. Object properties and public slots can then be accessed as usual. The QtBrowserPlugin implementation supports properties and slots that have parameters and types that QVariant can be convert to and from strings, or that are QObjects. Only public slots and scriptable properties are exposed. If the QObject class sets a "ToSuperClass" Q_CLASSINFO, then only slots and properties up to the specified superclass are exposed. See the QAxServer documentation provided with Qt for more information. JavaScript functions can be connected to Qt signals emitted by the Qt plugin object. Assign a function to a property of the object with the same name as the signal. Overloads (i.e. two signal with the same name, but different parameters) are not possible. Internet Explorer requires a special syntax that is not compatible with other browsers, but the IE-specific function can just call the other functions. Plugin objects can be embedded as form elements. To specify which property value the plugin should report to the form upon submission, specify the name of the property as the DefaultProperty using a Q_CLASSINFO entry: In the HTML page, embed the object as usual: Clicking the button will make the browser request a URL http://www.server.com/search.asp?text=[value from object] The property type needs to be convertible to a string. The QtBrowserPlugin solution is useful for implementing plugins for web browser. The project provides a framework that makes it simple to export widgets and objects as plugins for web browsers supporting the Netscape LiveConnect APIs. Supported web browsers are Netscape, Mozilla FireFox and Opera. Internet Explorer is supported when the plugin supports ActiveX via ActiveQt. This Qt Solutions component is for Qt 4. For Qt 3 Solutions, please visit the Qt 3 Solutions Catalog. Implementation: This example demonstrates the combination of Javascript and a trivial plugin, and the use of a plugin in combination with a form. If the browser supports scripting plugins, and everything is set up correctly, the plugin below should react to mouse clicks and drags by changing its text. The About... button should pop up an About Qt dialog. The second plugin instance, below the horizontal line, should display the word QtBrowserPlugin, and pressing the Go! button should navigate the browser to a search for this word at trolltech.com. Implementation: This example is trivial, and thus useful for investigating problems you might have installing plugins. If everything works correctly, the trivial plugin should appear below as a rectangular field below with some text in it: Implementation: ?w+0dvn+p8AtsuzczTim&ncwp*CeX
zkaY`9c57S=CYI%3N`Cj)xwB?F(0>%~Rv)s;+XzT#Ob`*K$Xl18Eo$_bZYt%ETKaS>
zO)6R=MS{_5lqQQTIZ|SVHB^sZ6Me=&MHOcd^ts!efOfYDF~@UJMrsbLHvy+Yc{l{m
ztUFQWBexYprs*;B006j2lzitLjCFS|YbXsZBql|0PZSkPAtAk68vCfF$7XSxK~U2S
zQ>WsX!8|bG1P3Q|7fY7YL}K*#{WMd&76vJ~r%6^34TuzoRpi= This is the complete list of members for QtNPBindable, including inherited members. The QtNPBindable class provides an interface between a widget and the web browser. More... The QtNPBindable class provides an interface between a widget and the web browser. Inherit your plugin widget class from both QWidget (or QObject) and QtNPBindable to be able to call the functions of this class, and to reimplement the virtual functions. The meta-object compiler requires you to inherit from the QObject subclass first. This enum specifies the different display modes of a plugin
+
+
+![]()
Home
+![]()
Developing Plugins
+
+
+
+Implementing plugins
+ QTNPFACTORY_BEGIN("Qt-based Graph Plugin", "A Qt-based LiveConnected plug-in that graphs numeric data");
+ QTNPCLASS(Graph)
+ QTNPFACTORY_END()
+Windows specific notes
+ 1 VERSIONINFO
+ FILEVERSION 1,0,0,1
+ PRODUCTVERSION 1,0,0,1
+ FILEFLAGSMASK 0x3fL
+ #ifdef _DEBUG
+ FILEFLAGS 0x1L
+ #else
+ FILEFLAGS 0x0L
+ #endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904e4"
+ BEGIN
+ VALUE "Comments", "\0"
+ VALUE "CompanyName", "Trolltech\0"
+ VALUE "FileDescription", "grapher\0"
+ VALUE "FileExtents", "g1n\0"
+ VALUE "FileOpenName", "Graphable data (*.g1n)\0"
+ VALUE "FileVersion", "1, 0, 0, 1\0"
+ VALUE "InternalName", "grapher\0"
+ VALUE "LegalCopyright", "Copyright 1997 Trolltech ASA\0"
+ VALUE "LegalTrademarks", "\0"
+ VALUE "MIMEType", "application/x-graphable\0"
+ VALUE "OriginalFilename", "grapher.dll\0"
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", "Trolltech grapher\0"
+ VALUE "ProductVersion", "1, 0, 0, 1\0"
+ VALUE "SpecialBuild", "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+ END
+
+Enabling ActiveX support
+Unix specific notes
+Known Issues on Unix/Linux
+
+
+Mac OSX specific notes
+ QMAKE_INFO_PLIST = Info.plist
+ REZ_FILES += grapher.r
+ rsrc_files.files = grapher.rsrc
+ rsrc_files.path = Contents/Resources
+ QMAKE_BUNDLE_DATA += rsrc_files
+
+Known Issues on Mac
+
+
+
+Installing and using Plugins
+ c:\Qt-x.y.z\bin\idc.exe path\to\myplugin.dll /unregserver
+Using the plugin in HTML
+Object with data:
+ <object type="application/x-graphable" data="graph.g1n" width=50% height=300>
+ Plugin not installed!
+ </object>
+ <object data="http://doc.trolltech.com/3.3/graph.g1n" width=50% height=300>
+ Plugin not installed!
+ </object>
+Objects without data:
+ <embed type="trivial/very" [property]=[value]>
+
+Not working with all browsers
+
+
+Scripting
+ <object id="ScriptableObject" TYPE=trivial/very WIDTH=200 HEIGHT=100 text="Very Scriptable!"> </object>
+
+ <script language=JavaScript>
+JavaScript calling slots and properties
+ var ScriptableObject = document.getElementById('ScriptableObject');
+The plugin calling JavaScript
+ ScriptableObject.text = 'This is some text'
+
+ var oldText
+ ScriptableObject.mouseDown = function()
+ {
+ oldText = ScriptableObject.text
+ ScriptableObject.text = 'Mouse Down'
+ }
+
+ ScriptableObject.mouseMove = function(x, y)
+ {
+ ScriptableObject.text = 'Mouse at ' + x + ',' + y
+ }
+
+ ScriptableObject.mouseUp = function()
+ {
+ ScriptableObject.text = oldText
+ }
+ </script>
+ <!-- Special hookup code required for Internet Explorer -->
+ <!--[if IE]>
+ <script language=JScript>
+ function ScriptableObject::mouseDown() { ScriptableObject.mouseDown() }
+ function ScriptableObject::mouseMove(x, y) { ScriptableObject.mouseMove(x, y) }
+ function ScriptableObject::mouseUp() { ScriptableObject.mouseUp() }
+ </script>
+Using plugins in forms
+ Q_OBJECT
+ Q_CLASSINFO("MIME", "trivial/very:xxx:Trivial and useless")
+ Q_CLASSINFO("DefaultProperty", "text")
+ <form method="get" action="http://www.server.com/search.asp">
+ <table>
+ <tr>
+ <td>Search:</td>
+ <td><object type="trivial/very" name="text" WIDTH=100 HEIGHT=20></object></td>
+ <td><input type="submit" value="Check"></td>
+ </tr>
+ </table>
+ </form>
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+
+
+
+![]()
Home
+![]()
Browser Plugin
+
+
+Description
+Guidelines
+
+
+Classes
+
+
+Examples
+
+
+
+Tested platforms
+
+
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+
+
+
+![]()
Home
+![]()
Grapher Plugin
+
+
+ /****************************************************************************
+ **
+ ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+ **
+ ** This file is part of a Qt Solutions component.
+ **
+ ** This file may be used under the terms of the GNU General Public
+ ** License version 2.0 as published by the Free Software Foundation
+ ** and appearing in the file LICENSE.GPL included in the packaging of
+ ** this file. Please review the following information to ensure GNU
+ ** General Public Licensing requirements will be met:
+ ** http://www.trolltech.com/products/qt/opensource.html
+ **
+ ** If you are unsure which license is appropriate for your use, please
+ ** review the following information:
+ ** http://www.trolltech.com/products/qt/licensing.html or contact the
+ ** Trolltech sales department at sales@trolltech.com.
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+ #include <QtGui>
+ #include <qtbrowserplugin.h>
+
+ #ifdef QAXSERVER
+ #include <ActiveQt/QAxBindable>
+ #endif
+
+ class Graph : public QWidget, public QtNPBindable
+ #ifdef QAXSERVER
+ , public QAxBindable
+ #endif
+ {
+ Q_OBJECT
+ Q_ENUMS(GraphStyle)
+ Q_PROPERTY(GraphStyle graphStyle READ graphStyle WRITE setGraphStyle)
+
+ Q_CLASSINFO("ClassID", "{2e5b2715-46b2-4831-ba9b-6a3b195d5ec8}")
+ Q_CLASSINFO("InterfaceID", "{94581136-3c0c-46cc-97a1-066061356d43}")
+ Q_CLASSINFO("EventsID", "{8c191b77-1894-45c7-9d6b-201dede95410}")
+
+ Q_CLASSINFO("MIME", "application/x-graphable:g1n:Graphable ASCII numeric data")
+ public:
+ Graph(QWidget *parent = 0);
+ ~Graph();
+
+ enum GraphStyle
+ {
+ Pie,
+ Bar
+ };
+ void setGraphStyle(GraphStyle style);
+ GraphStyle graphStyle() const;
+
+ bool readData(QIODevice *source, const QString &format);
+ bool writeData(QIODevice *sink);
+
+ void transferComplete(const QString &url, int id, Reason r);
+
+ protected:
+ void timerEvent(QTimerEvent*);
+ void enterEvent(QEvent *);
+ void leaveEvent(QEvent *);
+ void paintEvent(QPaintEvent*);
+ void mousePressEvent(QMouseEvent *me);
+
+ void paintWait();
+ void paintBar(QPaintEvent*);
+ void paintPie(QPaintEvent*);
+
+ private slots:
+ void stylePie();
+ void styleBar();
+ void aboutPlugin();
+ void aboutData();
+ void aboutQt();
+ void aboutTrolltech();
+
+ private:
+ struct Datum {
+ double value;
+ QString label;
+ };
+ QList<Datum> data;
+ void processData(QTextStream &in);
+
+ QMenu *menu;
+ QStatusBar *statusbar;
+ QAction *pie, *bar;
+
+ int pieRotation;
+ int pieTimer;
+ GraphStyle m_style;
+
+ int lastReqId, lastConfId;
+ QString lastConfUrl;
+ Reason lastConfReason;
+ };
+
+ Graph::Graph(QWidget *parent)
+ : QWidget(parent), pieRotation(0), pieTimer(0)
+ {
+ menu = new QMenu(this);
+ QMenu *styles = menu->addMenu("&Styles");
+
+ pie = styles->addAction("&Pie",this,SLOT(stylePie()));
+ pie->setShortcut(QString("Ctrl+P"));
+ pie->setCheckable(true);
+
+ bar = styles->addAction("&Bar", this, SLOT(styleBar()));
+ bar->setShortcut(QString("Ctrl+B"));
+ bar->setCheckable(true);
+
+ QActionGroup *group = new QActionGroup(this);
+ group->setExclusive(true);
+
+ group->addAction(pie);
+ group->addAction(bar);
+
+ QMenu* help = menu->addMenu("&Help");
+ help->addAction("About &plugin...", this, SLOT(aboutPlugin()))->setShortcut(QString("Ctrl+A"));
+ help->addAction("About &data...", this, SLOT(aboutData()));
+ help->addAction("About &Qt...", this, SLOT(aboutQt()));
+ help->addAction("About &Trolltech...", this, SLOT(aboutTrolltech()));
+
+ QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+F5"), this);
+ connect(shortcut, SIGNAL(activated()), this, SLOT(aboutQt()));
+
+ statusbar = new QStatusBar(this);
+
+ setFocusPolicy(Qt::StrongFocus);
+ setGraphStyle(Pie);
+
+ QPalette pal = palette();
+ pal.setColor(QPalette::Window,Qt::white);
+ setPalette(pal);
+
+ lastReqId = 0;
+ lastConfId = 0;
+ lastConfReason = ReasonUnknown;
+ }
+
+ Graph::~Graph()
+ {
+ }
+
+ void Graph::setGraphStyle(GraphStyle style)
+ {
+ if (style==m_style)
+ return;
+
+ if (pieTimer)
+ killTimer(pieTimer);
+
+ m_style = style;
+ switch(m_style) {
+ case Pie:
+ pieTimer = startTimer(50);
+ pie->setChecked(true);
+ break;
+ case Bar:
+ bar->setChecked(true);
+ break;
+ }
+
+ repaint();
+ }
+
+ Graph::GraphStyle Graph::graphStyle() const
+ {
+ return m_style;
+ }
+
+ void Graph::aboutPlugin()
+ {
+ openUrl("http://www.trolltech.com/products/solutions/catalog/4/Utilities/qtbrowserplugin/");
+ }
+
+ void Graph::aboutData()
+ {
+ QString page = parameters().value("datapage").toString();
+ if (!page.isEmpty()) {
+ openUrl(page);
+ } else {
+ QByteArray table("<b>This data has been loaded with streammode = '");
+ table += parameters().contains("streammode") ? parameters().value("streammode").toByteArray() : QByteArray("Default");
+ table += "'</b>\n";
+ table += "<table>\n";
+ for (int i = 0; i < data.count(); ++i) {
+ Datum datum = data.at(i);
+ table += "<tr><td>" + datum.label + "</td><td>" + QString::number(datum.value) + "</td></tr>\n";
+ }
+ table += "</table>\n";
+
+ table += "<p>Last OpenURL request id: " + QString::number(lastReqId);
+ table += "<br>Last confirmation id: " + QString::number(lastConfId);
+ table += " Reason: " + QString::number((int)lastConfReason);
+ table += "<br>URL: " + lastConfUrl;
+ QMessageBox::information(this, "Data information", QLatin1String(table));
+ }
+ }
+
+ void Graph::transferComplete(const QString &url, int id, Reason r)
+ {
+ lastConfId = id;
+ lastConfUrl = url;
+ lastConfReason = r;
+ }
+
+ void Graph::aboutQt()
+ {
+ QMessageBox::aboutQt(this);
+ }
+
+ void Graph::aboutTrolltech()
+ {
+ lastReqId = openUrl("http://www.trolltech.com");
+ }
+
+ void Graph::stylePie()
+ {
+ setGraphStyle(Pie);
+ }
+
+ void Graph::styleBar()
+ {
+ setGraphStyle(Bar);
+ }
+
+ bool Graph::readData(QIODevice *source, const QString &/*format*/)
+ {
+ if (!source->open(QIODevice::ReadOnly|QIODevice::Text))
+ return false;
+
+ QTextStream in(source);
+ processData(in);
+
+ update();
+ return true;
+ }
+
+ void Graph::processData(QTextStream &in)
+ {
+ while (!in.atEnd()) {
+ Datum datum;
+ QString value;
+ in >> value;
+ in >> datum.label;
+ bool ok;
+ datum.value = value.toDouble(&ok);
+ if (ok)
+ data += datum;
+ }
+ }
+
+ bool Graph::writeData(QIODevice *target)
+ {
+ if (!target->open(QIODevice::WriteOnly|QIODevice::Text))
+ return false;
+
+ QTextStream out(target);
+ foreach(Datum datum, data) {
+ out << datum.value << "\t" << datum.label << endl;
+ }
+
+ return true;
+ }
+
+ void Graph::timerEvent(QTimerEvent *e)
+ {
+ if (e->timerId() == pieTimer) {
+ pieRotation = (pieRotation + 1) % 360;
+ update();
+ }
+ QWidget::timerEvent(e);
+ }
+
+ void Graph::enterEvent(QEvent *)
+ {
+ statusbar->showMessage(QString("Qt Grapher plugin [%1]").arg(mimeType()));
+ }
+
+ void Graph::leaveEvent(QEvent *)
+ {
+ if (!QApplication::activePopupWidget()) {
+ statusbar->clearMessage();
+ }
+ }
+
+ void Graph::paintEvent(QPaintEvent* event)
+ {
+ if (!data.count()) {
+ paintWait();
+ } else {
+ switch (m_style) {
+ case Pie:
+ paintPie(event);
+ break;
+ default:
+ paintBar(event);
+ break;
+ }
+ }
+ }
+
+ void Graph::mousePressEvent(QMouseEvent *me)
+ {
+ menu->exec(me->globalPos());
+ }
+
+ void Graph::paintWait()
+ {
+ QPainter p(this);
+ p.drawText(rect(), Qt::AlignCenter, "Loading...");
+ }
+
+ void Graph::paintBar(QPaintEvent* event)
+ {
+ const int count = data.count();
+ double max = 0.0;
+ for (int i = 0; i < count; ++i) {
+ double value = data.at(i).value;
+ if (value > max)
+ max = value;
+ }
+
+ QPainter painter(this);
+ painter.setClipRect(event->rect());
+ painter.save();
+ painter.setWindow(0, qRound(max), count * 20, qRound(-max));
+ painter.setViewport(20, 5, width() - 40, height() - 40);
+
+ for (int i = 0; i < count; ++i) {
+ double value = data.at(i).value;
+ QColor c;
+ c.setHsv((i * 255)/count, 255, 255);// rainbow effect
+ painter.setBrush(c);
+
+ painter.drawRect(i * 20, 0, 20, qRound(value));
+ }
+ painter.restore();
+ painter.setClipRect(QRect());
+ }
+
+ void Graph::paintPie(QPaintEvent* event)
+ {
+ const int count = data.count();
+ double total = 0.0;
+
+ for (int i = 0; i < count; ++i) {
+ double value = data.at(i).value;
+ total += value;
+ }
+
+ int apos = (pieRotation-90)*16;
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setClipRect(event->rect());
+ QRect r(rect());
+ r.adjust(10, 10, -10, -10);
+
+ for (int i = 0; i < count; ++i) {
+ double value = data.at(i).value;
+ QColor c;
+ c.setHsv((i * 255)/count, 255, 255);// rainbow effect
+ painter.setBrush( c );
+
+ int a = int((value * 360.0) / total * 16.0 + 0.5);
+ painter.drawPie(r, -apos, -a);
+ apos += a;
+ }
+ }
+
+ #include "grapher.moc"
+
+ QTNPFACTORY_BEGIN("Qt-based Graph Plugin", "A Qt-based LiveConnected plug-in that graphs numeric data");
+ QTNPCLASS(Graph)
+ QTNPFACTORY_END()
+
+ #ifdef QAXSERVER
+ #include <ActiveQt/QAxFactory>
+ QAXFACTORY_BEGIN("{89ab08da-df8c-4bd0-8327-72f73741c1a6}", "{082bd921-0832-4ca7-ab5a-ec06ca7f3350}")
+ QAXCLASS(Graph)
+ QAXFACTORY_END()
+ #endif
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+
+
+
+![]()
Home
+![]()
Scripting Example
+
+
+
+ /****************************************************************************
+ **
+ ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+ **
+ ** This file is part of a Qt Solutions component.
+ **
+ ** This file may be used under the terms of the GNU General Public
+ ** License version 2.0 as published by the Free Software Foundation
+ ** and appearing in the file LICENSE.GPL included in the packaging of
+ ** this file. Please review the following information to ensure GNU
+ ** General Public Licensing requirements will be met:
+ ** http://www.trolltech.com/products/qt/opensource.html
+ **
+ ** If you are unsure which license is appropriate for your use, please
+ ** review the following information:
+ ** http://www.trolltech.com/products/qt/licensing.html or contact the
+ ** Trolltech sales department at sales@trolltech.com.
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+ #include <QtGui>
+ #include <qtbrowserplugin.h>
+
+ class Trivial : public QWidget
+ {
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText)
+
+ Q_CLASSINFO("ClassID", "{5a22176d-118f-4185-9653-9f98958a6df8}")
+ Q_CLASSINFO("InterfaceID", "{2df735ba-da4f-4fb7-8f35-b8dfbf8cfd9a}")
+ Q_CLASSINFO("EventsID", "{449de213-f8bd-4d2e-a2cf-eab407c03245}")
+
+ Q_CLASSINFO("MIME", "trivial/very:xxx:Trivial and useless")
+ Q_CLASSINFO("ToSuperClass", "Trivial")
+ Q_CLASSINFO("DefaultProperty", "text")
+
+ public:
+ Trivial(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ m_text = QString::fromLatin1("Empty");
+ }
+
+ void mousePressEvent(QMouseEvent *)
+ {
+ mouseDown();
+ }
+ void mouseMoveEvent(QMouseEvent *e)
+ {
+ mouseMove(e->x(), e->y());
+ }
+ void mouseReleaseEvent(QMouseEvent*)
+ {
+ mouseUp();
+ }
+ QString text() const
+ {
+ return m_text;
+ }
+
+ public slots:
+ void about()
+ {
+ QMessageBox::aboutQt(this);
+ }
+ void setText(const QString &text)
+ {
+ m_text = text;
+ update();
+ }
+
+ signals:
+ void mouseDown();
+ void mouseMove(int x, int y);
+ void mouseUp();
+
+ protected:
+ void paintEvent(QPaintEvent*)
+ {
+ QPainter p(this);
+ QRect r(rect());
+ r.adjust(0, 0, -1, -1);
+
+ p.drawRect(r);
+ p.drawText(r, Qt::AlignCenter, m_text);
+ }
+
+ private:
+ QString m_text;
+ };
+
+ #include "trivial.moc"
+
+ QTNPFACTORY_BEGIN("Trivial Qt-based Plugin", "A Qt-based LiveConnected plug-in that does nothing")
+ QTNPCLASS(Trivial)
+ QTNPFACTORY_END()
+
+ #ifdef QAXSERVER
+ #include <ActiveQt/QAxFactory>
+ QAXFACTORY_BEGIN("{aa3216bf-7e20-482c-84c6-06167bacb616}", "{08538ca5-eb7a-4f24-a3c4-a120c6e04dc4}")
+ QAXCLASS(Trivial)
+ QAXFACTORY_END()
+ #endif
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+
+
+
+![]()
Home
+![]()
Trivial Example
+
+ /****************************************************************************
+ **
+ ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
+ **
+ ** This file is part of a Qt Solutions component.
+ **
+ ** This file may be used under the terms of the GNU General Public
+ ** License version 2.0 as published by the Free Software Foundation
+ ** and appearing in the file LICENSE.GPL included in the packaging of
+ ** this file. Please review the following information to ensure GNU
+ ** General Public Licensing requirements will be met:
+ ** http://www.trolltech.com/products/qt/opensource.html
+ **
+ ** If you are unsure which license is appropriate for your use, please
+ ** review the following information:
+ ** http://www.trolltech.com/products/qt/licensing.html or contact the
+ ** Trolltech sales department at sales@trolltech.com.
+ **
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ **
+ ****************************************************************************/
+ #include <QtGui>
+ #include <qtbrowserplugin.h>
+
+ class Trivial : public QWidget
+ {
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText)
+
+ Q_CLASSINFO("ClassID", "{5a22176d-118f-4185-9653-9f98958a6df8}")
+ Q_CLASSINFO("InterfaceID", "{2df735ba-da4f-4fb7-8f35-b8dfbf8cfd9a}")
+ Q_CLASSINFO("EventsID", "{449de213-f8bd-4d2e-a2cf-eab407c03245}")
+
+ Q_CLASSINFO("MIME", "trivial/very:xxx:Trivial and useless")
+ Q_CLASSINFO("ToSuperClass", "Trivial")
+ Q_CLASSINFO("DefaultProperty", "text")
+
+ public:
+ Trivial(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ m_text = QString::fromLatin1("Empty");
+ }
+
+ void mousePressEvent(QMouseEvent *)
+ {
+ mouseDown();
+ }
+ void mouseMoveEvent(QMouseEvent *e)
+ {
+ mouseMove(e->x(), e->y());
+ }
+ void mouseReleaseEvent(QMouseEvent*)
+ {
+ mouseUp();
+ }
+ QString text() const
+ {
+ return m_text;
+ }
+
+ public slots:
+ void about()
+ {
+ QMessageBox::aboutQt(this);
+ }
+ void setText(const QString &text)
+ {
+ m_text = text;
+ update();
+ }
+
+ signals:
+ void mouseDown();
+ void mouseMove(int x, int y);
+ void mouseUp();
+
+ protected:
+ void paintEvent(QPaintEvent*)
+ {
+ QPainter p(this);
+ QRect r(rect());
+ r.adjust(0, 0, -1, -1);
+
+ p.drawRect(r);
+ p.drawText(r, Qt::AlignCenter, m_text);
+ }
+
+ private:
+ QString m_text;
+ };
+
+ #include "trivial.moc"
+
+ QTNPFACTORY_BEGIN("Trivial Qt-based Plugin", "A Qt-based LiveConnected plug-in that does nothing")
+ QTNPCLASS(Trivial)
+ QTNPFACTORY_END()
+
+ #ifdef QAXSERVER
+ #include <ActiveQt/QAxFactory>
+ QAXFACTORY_BEGIN("{aa3216bf-7e20-482c-84c6-06167bacb616}", "{08538ca5-eb7a-4f24-a3c4-a120c6e04dc4}")
+ QAXCLASS(Trivial)
+ QAXFACTORY_END()
+ #endif
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+;yL?$%p-AUG^KeB!$*feCkJjUfgXUm?hOHxedxjIl
zL_8)ro|e^|1s1Wp3A!8aA_Jc#*HAA6keVC$(h3I5Q}B26ll5OXyVMIZ%KmZ!<|FTQQIBsM7BTM
z!+WrA!{5MAz6U@gH(DdrlH`h%PQLg^8G;Z4(n}XQ*;JVWdr8Mdy=IwLkjsof#FnU@
zcMir@aC+<=Tpv^8a3f10TJE)rC>3Qj9nQ@L7J`N7CqxH5dJUl9gvXHWRC!)qoMs}g
zSWP&o8r4ZbR$pbm>;jZ?(CIGYvM^pfUhFO@Uaf*@gGS^^+14eXG;pkLF%cj|K#e0M
zW58&d5=xJ&3f?13C65YM&gs4^4e(EE+h1*yX|8>f&j;Td1zDSU{9$Xbcq+@6>Ubo7
z>Pq}_Xv1hL!LZfkc&%ilmFn?Cd1q31<9e(Q--W?`)$R4kcH{GEkCEVK?pIOz$MhH5
zo{Hr=GWmDlw+8b^PF+XHq5Ypwtd;_8yR945!+$c%%#`f(F|XmiFlLd2Q_cR&hpx5p
z6Wx-Eo3yB)enDQEj-!f&?bV8@!SU+a8($H4ao<;7xFXrWFBEjY7ypn2geU5YKpo02
zNFS!__|U>=mt^s?81(4ju?a1>yEEQ(82I!dkvLO9h)~Cf
zp?S}!d9QS9$Qh240?Ea^%wgBK{e*r>J%0A)rw7=oWr=LIAL{dy5>!gHNb?L`SYw8y
zPUnZ{V;{D*8rl&QoO!+6e&iB7{uIt5SH7Q81HoZQzPBN}Aa&!T;g;m*5t=1;P{FG<
z2I5yO;WrU#Nk(0J>@m~)bxtaM)cbQb*yc29(*1cyukalYbBssQOflXcu+oD^(9e!a
zzCNkk5K$uYZG!*gXM4VX{64C>sNWEyaSyeT-omG1?1QMma+5#+vXcHQ%2992EKuP@
zAYX&}aecnfdEi`i&V_KX&AczV>%a>u96i3|u_9tM`61y`1e1~-LumJ>W7EjJI{Pv+
zbBNKr6P(fOVKq`TY-InQYS60|eByEt=Rv`y)V6Vcc{fjOMkFn>?SqISn+Qlg==RNF
z+4IZOBm{EwQxsj#QLW{3%Fk8ds%s?Kc%cG&*kyfHJ0ilu=;ShBs+G&RG(Lw-fjIhy
zT+(5C?ZL~DEE~sjhT*D$%&dLSQ;Vdotl8J26A0whIpvZ_ICZIbL
zep|N-4>k{qu5m$^su}7VIywERuj95kGTHdgDOri%!apqP*G@ntiSV@;7LVNu5bf+?
zJ?1)DP|^@_u;w9Xwhhr?3nyV8E$||K5Lsi7sd-`Pa%ht~{^~ug9P>tvm9sbI2mH1M
zGg=hh87M+1Vw^yOh`n;`Pho8b@HCiB5;3m=KN{-dsyn$jAJW)%MiP22*Iyu0wK(nP
z@`o#hatzthTiBZ2?%0_$lQ
g%2H_s$`MCgokHQ}Br3i=d7D
zNM2^!5rzzI7_|OJA#T*87&{wr^i%lAKM1!!5kJm;6ogQAkPq&d>DD=8(L}9`hNw^y
z(#A|W
+
+
+![]()
Home
+![]()
List of All Members for QtNPBindable
+
+
+
+
+
+
+ Copyright © 2008 Trolltech
+Trademarks
+
+
+
+
+![]()
Home
+![]()
QtNPBindable Class Reference
+ #include <QtNPBindable>
+
+Public Types
+
+
+
+Public Functions
+
+
+
+Protected Functions
+
+
+
+
+Detailed Description
+ class PluginWidget : public QWidget, public QtNPBindable
+ {
+ Q_OBJECT
+ public:
+ PluginWidget(QWidget *parent = 0)
+ {
+ }
+
+ //...
+ };
+
+Member Type Documentation
+enum QtNPBindable::DisplayMode
+
+
+Constant Value Description
+QtNPBindable::Embedded 1 The plugin widget is embedded in a web page, usually with the <EMBED> or the <OBJECT> tag.
+QtNPBindable::Fullpage 2 The plugin widget is the primary content of the web browser, which is usually the case when the web browser displays a file the plugin supports.
This enum specifies how an URL operation was completed
+| Constant | Value |
|---|---|
| QtNPBindable::ReasonDone | 0 |
| QtNPBindable::ReasonBreak | 1 |
| QtNPBindable::ReasonError | 2 |
| QtNPBindable::ReasonUnknown | -1 |
Constructs a QtNPBindable object.
+This can only happen when the plugin object is created.
+Destroys the object.
+This can only happen when the plugin object is destroyed.
+Returns the display mode of the plugin.
+Extracts the version of the browser into major and minor.
+See http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/ for an explanation of those values.
+See also getNppVersion() and userAgent().
+Extracts the version of the plugin API used by this plugin into major and minor.
+See http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/ for an explanation of those values.
+See also getBrowserVersion() and userAgent().
+Returns the browser's plugin instance associated with this plugin object. The instance is required to call functions in the Netscape Plugin API, i.e. NPN_GetJavaPeer().
+The instance returned is only valid as long as this object is.
+See http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/ for documentation of the NPP type.
+Returns the mime type this plugin has been instantiated for.
+Requests that the url be retrieved and sent to the named window (or a new window if window is empty), and returns the ID of the request that is delivered to transferComplete() when the get-operation has finished. Returns 0 when the browser or the system doesn't support notification, or -1 when an error occured.
+ void MyPlugin::aboutTrolltech()
+ {
+ openUrl("http://www.trolltech.com");
+ }
+See Netscape's JavaScript documentation for an explanation of window names.
+See also transferComplete(), uploadData(), and uploadFile().
+Returns the parameters passed to the plugin instance.
+The framework sets the properties of the plugin to the corresponding parameters when the plugin object has been created, but you can use this function to process additional parameters.
+Note that the SGML specification does not permit multiple arguments with the same name.
+Reimplement this function to read data from source provided with mime type format. The data is the one specified in the src or data attribute of the <EMBED> or <OBJECT> tag of in HTML page. This function is called once for every stream the browser creates for the plugin.
+Return true to indicate successfull processing of the data, otherwise return false. The default implementation does nothing and returns false.
+Called as a result of a call to openUrl, uploadData or uploadFile. url corresponds to the respective parameter, and id to value returned by the call. reason indicates how the transfer was completed.
+Posts data to url, and displays the result in window. Returns the ID of the request that is delivered to transferComplete() when the post-operation has finished. Returns 0 when the browser or the system doesn't support notification, or -1 when an error occured.
+ void MyPlugin::sendMail()
+ {
+ uploadData("mailto:fred@somewhere.com", QString(), "There is a new file for you!");
+ }
+See Netscape's JavaScript documentation for an explanation of window names.
+See also transferComplete(), openUrl(), and uploadFile().
+Posts filename to url, and displays the result in window. Returns the ID of the request that is delivered to transferComplete() when the post-operation has finished. Returns 0 when the browser or the system doesn't support notification, or -1 when an error occured.
+ void MyPlugin::uploadFile()
+ {
+ uploadFile("ftp://ftp.somewhere.com/incoming", "response", "c:\\temp\\file.txt");
+ }
+See Netscape's JavaScript documentation for an explanation of window names.
+See also transferComplete(), uploadData(), and openUrl().
+Returns the user agent (browser name) containing this plugin.
+This is a wrapper around NPN_UserAgent.
+See also getBrowserVersion().
+| Copyright © 2008 Trolltech | +Trademarks | +Qt Solutions |
+
| Home | +
This is the complete list of members for QtNPFactory, including inherited members.
+| Copyright © 2008 Trolltech | +Trademarks | +Qt Solutions |
+
| Home | +
The QtNPFactory class provides the factory for plugin objects. More...
+#include <QtNPFactory>+ +
The QtNPFactory class provides the factory for plugin objects.
+Implement this factory once in your plugin project to provide information about the plugin and to create the plugin objects. Subclass QtNPFactory and implement the pure virtual functions, and export the factory using the QTNPFACTORY_EXPORT() macro.
+If you use the Q_CLASSINFO macro in your object classes you can use the QTNPFACTORY_BEGIN(), QTNPCLASS() and QTNPFACTORY_END() macros to generate a factory implementation:
+ class Widget : public QWidget
+ {
+ Q_OBJECT
+ Q_CLASSINFO("MIME", "application/x-graphable:g1n:Graphable data")
+ public:
+ ...
+ };
+
+ QTNPFACTORY_BEGIN("Plugin name", "Plugin description")
+ QTNPCLASS(WidgetClass)
+ QTNPFACTORY_END()
+The classes exposed must provide a constructor.
+If Qt is linked to the plugin as a dynamic library, only one instance of QApplication will exist across all plugins that have been made with Qt. So, your plugin should tread lightly on global settings. Do not, for example, use QApplication::setFont() - that will change the font in every widget of every Qt-based plugin currently loaded!
+Creates a QtNPFactory.
+Destroys the QtNPFactory.
+This is called by the plugin binding code just before the plugin is about to be unloaded from memory. If createObject() has been called, a QApplication will still exist at this time, but will be deleted shortly after, just before the plugin is deleted.
+Reimplement this function to return the QObject or QWidget subclass supporting the mime type type, or 0 if the factory doesn't support the type requested.
+type will be in the same form as the leftmost (mime) part of the string(s) returned by mimeTypes(), e.g. "image/png".
+Reimplement this function to return the MIME types of the data formats supported by your plugin. The format of each string is mime:extension(s):description:
+ QStringList mimeTypes() const
+ {
+ QStringList list;
+ list << "image/x-png:png:PNG Image"
+ << "image/png:png:PNG Image"
+ << "image/jpeg:jpg,jpeg:JPEG Image";
+ return list;
+ }
+Reimplement this function to return the description of the plugin.
+Reimplement this function to return the name of the plugin.
+| Copyright © 2008 Trolltech | +Trademarks | +Qt Solutions |
+