本文整理汇总了C++中KHTMLPart::browserExtension方法的典型用法代码示例。如果您正苦于以下问题:C++ KHTMLPart::browserExtension方法的具体用法?C++ KHTMLPart::browserExtension怎么用?C++ KHTMLPart::browserExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KHTMLPart
的用法示例。
在下文中一共展示了KHTMLPart::browserExtension方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void HTMLLinkElementImpl::process()
{
if (!inDocument())
return;
QString type = m_type.string().lower();
QString rel = m_rel.string().lower();
KHTMLPart* part = getDocument()->part();
// IE extension: location of small icon for locationbar / bookmarks
#if APPLE_CHANGES
if ( part && rel == "shortcut icon" && !m_url.isEmpty() && !part->parentPart())
part->browserExtension()->setIconURL( KURL(m_url.string()) );
// Mozilla extension to IE extension: icon specified with type
if ( part && rel == "icon" && !m_url.isEmpty() && !part->parentPart())
part->browserExtension()->setTypedIconURL( KURL(m_url.string()), type );
#else
// Uses both "shortcut icon" and "icon"
if ( part && rel.contains("icon") && !m_url.isEmpty() && !part->parentPart())
part->browserExtension()->setIconURL( KURL(m_url.string()) );
#endif
// Stylesheet
// This was buggy and would incorrectly match <link rel="alternate">, which has a different specified meaning. -dwh
if(m_disabledState != 2 && (type.contains("text/css") || rel == "stylesheet" || (rel.contains("alternate") && rel.contains("stylesheet"))) && getDocument()->part()) {
// no need to load style sheets which aren't for the screen output
// ### there may be in some situations e.g. for an editor or script to manipulate
// also, don't load style sheets for standalone documents
if( m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print") ) {
m_loading = true;
// Add ourselves as a pending sheet, but only if we aren't an alternate
// stylesheet. Alternate stylesheets don't hold up render tree construction.
m_alternate = rel.contains("alternate");
if (!isAlternate())
getDocument()->addPendingSheet();
QString chset = getAttribute( ATTR_CHARSET ).string();
if (m_cachedSheet)
m_cachedSheet->deref(this);
m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(m_url, chset);
if (m_cachedSheet)
m_cachedSheet->ref(this);
}
}
else if (m_sheet) {
// we no longer contain a stylesheet, e.g. perhaps rel or type was changed
m_sheet->deref();
m_sheet = 0;
getDocument()->updateStyleSelector();
}
}
示例2: tryCall
Value MozillaSidebarExtensionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
KJS_CHECK_THIS(KJS::MozillaSidebarExtension, thisObj);
MozillaSidebarExtension *mse = static_cast< MozillaSidebarExtension * >(thisObj.imp());
KHTMLPart *part = mse->part();
if(!part)
return Undefined();
// addPanel() id == 0
KParts::BrowserExtension *ext = part->browserExtension();
if(ext)
{
QString url, name;
if(args.size() == 1)
{ // I've seen this, don't know if it's legal.
name = QString::null;
url = args[0].toString(exec).qstring();
}
else if(args.size() == 2 || args.size() == 3)
{
name = args[0].toString(exec).qstring();
url = args[1].toString(exec).qstring();
// 2 is the "CURL" which I don't understand and don't think we need.
}
else
{
return Boolean(false);
}
emit ext->addWebSideBar(KURL(url), name);
return Boolean(true);
}
return Undefined();
}
示例3: GoHistory
void BrowserWindow::GoHistory( int nStep )
{
// if ( nStep != 0 ) {
// UpdateHistory();
// }
m_nCurHistoryPos += nStep;
HistoryEntry* pcCurrent = HistoryCurrent();
if ( pcCurrent != NULL ) {
GlobalMutex::PushLooper( this );
m_pcHTMLPart->browserExtension()->restoreState( pcCurrent->m_cState );
m_pcURLView->Set( pcCurrent->m_cURL.c_str(), false );
GlobalMutex::PopLooper();
}
if ( m_nCurHistoryPos == 0 ) {
m_pcToolBar->EnableButton( BI_BACK, false );
} else {
m_pcToolBar->EnableButton( BI_BACK, true );
}
if ( m_nCurHistoryPos >= int(m_cHistory.size()) - 1 ) {
m_pcToolBar->EnableButton( BI_FORWARD, false );
} else {
m_pcToolBar->EnableButton( BI_FORWARD, true );
}
}
示例4: process
void HTMLLinkElementImpl::process()
{
if(!inDocument())
return;
QString type = getAttribute(ATTR_TYPE).string().lower();
QString rel = getAttribute(ATTR_REL).string().lower();
KHTMLPart *part = getDocument()->view() ? getDocument()->view()->part() : 0;
// IE extension: location of small icon for locationbar / bookmarks
// Uses both "shortcut icon" and "icon"
if(part && rel.contains("icon") && !m_url.isEmpty() && !part->parentPart())
part->browserExtension()->setIconURL(KURL(m_url.string()));
// Stylesheet
else if(!m_isDisabled && (type.contains("text/css") || rel.contains("stylesheet")))
{
// no need to load style sheets which aren't for the screen output
// ### there may be in some situations e.g. for an editor or script to manipulate
if(m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print"))
{
m_loading = true;
// Add ourselves as a pending sheet, but only if we aren't an alternate
// stylesheet. Alternate stylesheets don't hold up render tree construction.
m_alternate = rel.contains("alternate");
if(!isAlternate())
getDocument()->addPendingSheet();
QString chset = getAttribute(ATTR_CHARSET).string();
// set chset to charset of referring document when attribute CHARSET is absent.
// http://www.w3.org/TR/CSS21/syndata.html(4.4)
if(chset.isEmpty() && part)
chset = part->encoding();
if(m_cachedSheet)
m_cachedSheet->deref(this);
m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(m_url, chset);
if(m_cachedSheet)
{
m_isCSSSheet = true;
m_cachedSheet->ref(this);
}
else if(!isAlternate())
{
// Error requesting sheet; decrement pending sheet count
getDocument()->styleSheetLoaded();
}
}
}
else if(m_sheet)
{
// we no longer contain a stylesheet, e.g. perhaps rel or type was changed
m_sheet->deref();
m_sheet = 0;
m_isCSSSheet = false;
getDocument()->updateStyleSelector();
}
}
示例5: setInstance
KHTMLImage::KHTMLImage(QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name, KHTMLPart::GUIProfile prof)
: KParts::ReadOnlyPart(parent, name), m_image(0)
{
KHTMLPart *parentPart = ::qt_cast< KHTMLPart * >(parent);
setInstance(KHTMLImageFactory::instance(), prof == KHTMLPart::BrowserViewGUI && !parentPart);
QVBox *box = new QVBox(parentWidget, widgetName);
m_khtml = new KHTMLPart(box, widgetName, this, "htmlimagepart", prof);
m_khtml->setAutoloadImages(true);
m_khtml->widget()->installEventFilter(this);
connect(m_khtml->view(), SIGNAL(finishedLayout()), this, SLOT(restoreScrollPosition()));
setWidget(box);
// VBox can't take focus, so pass it on to sub-widget
box->setFocusProxy(m_khtml->widget());
m_ext = new KHTMLImageBrowserExtension(this, "be");
// Remove unnecessary actions.
KAction *encodingAction = actionCollection()->action("setEncoding");
if(encodingAction)
{
encodingAction->unplugAll();
delete encodingAction;
}
KAction *viewSourceAction = actionCollection()->action("viewDocumentSource");
if(viewSourceAction)
{
viewSourceAction->unplugAll();
delete viewSourceAction;
}
KAction *selectAllAction = actionCollection()->action("selectAll");
if(selectAllAction)
{
selectAllAction->unplugAll();
delete selectAllAction;
}
// forward important signals from the khtml part
// forward opening requests to parent frame (if existing)
KHTMLPart *p = ::qt_cast< KHTMLPart * >(parent);
KParts::BrowserExtension *be = p ? p->browserExtension() : m_ext;
connect(m_khtml->browserExtension(), SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)), be,
SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)));
connect(m_khtml->browserExtension(),
SIGNAL(popupMenu(KXMLGUIClient *, const QPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t)),
m_ext,
SIGNAL(popupMenu(KXMLGUIClient *, const QPoint &, const KURL &, const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t)));
connect(m_khtml->browserExtension(), SIGNAL(enableAction(const char *, bool)), m_ext, SIGNAL(enableAction(const char *, bool)));
m_ext->setURLDropHandlingEnabled(true);
}
示例6: OpenURL
void BrowserWindow::OpenURL( const std::string& cURL, const KParts::URLArgs& cArgs )
{
// GlobalMutex::Lock();
// m_pcURLView->Set( cURL.c_str(), false );
m_pcURLView->SetText( cURL.c_str() );
m_pcHTMLPart->browserExtension()->setURLArgs( cArgs );
m_pcHTMLPart->openURL( cURL.c_str() );
// GlobalMutex::Unlock();
}
示例7: actionCollection
KHTMLImage::KHTMLImage( QWidget *parentWidget,
QObject *parent, KHTMLPart::GUIProfile prof )
: KParts::ReadOnlyPart( parent ), m_image( 0 )
{
KHTMLPart* parentPart = qobject_cast<KHTMLPart*>( parent );
setComponentData( KHTMLImageFactory::componentData(), prof == KHTMLPart::BrowserViewGUI && !parentPart );
KVBox *box = new KVBox( parentWidget );
box->setAcceptDrops( true );
m_khtml = new KHTMLPart( box, this, prof );
m_khtml->setAutoloadImages( true );
// We do not want our subpart to be destroyed when its widget is,
// since that may cause all KHTMLParts to die when we're dealing
// with
m_khtml->setAutoDeletePart( false );
connect( m_khtml->view(), SIGNAL(finishedLayout()), this, SLOT(restoreScrollPosition()) );
setWidget( box );
// VBox can't take focus, so pass it on to sub-widget
box->setFocusProxy( m_khtml->widget() );
m_ext = new KHTMLImageBrowserExtension( this );
m_ext->setObjectName( "be" );
m_sbExt = new KParts::StatusBarExtension( this );
m_sbExt->setObjectName( "sbe" );
// Remove unnecessary actions.
delete actionCollection()->action( "setEncoding" );
delete actionCollection()->action( "viewDocumentSource" );
delete actionCollection()->action( "selectAll" );
// forward important signals from the khtml part
// forward opening requests to parent frame (if existing)
KHTMLPart *p = qobject_cast<KHTMLPart*>(parent);
KParts::BrowserExtension *be = p ? p->browserExtension() : m_ext;
connect(m_khtml->browserExtension(), SIGNAL(openUrlRequestDelayed(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
be, SIGNAL(openUrlRequestDelayed(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)));
connect(m_khtml->browserExtension(), SIGNAL(popupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)),
this, SLOT(slotPopupMenu(QPoint,KUrl,mode_t,KParts::OpenUrlArguments,KParts::BrowserArguments,KParts::BrowserExtension::PopupFlags,KParts::BrowserExtension::ActionGroupMap)));
connect( m_khtml->browserExtension(), SIGNAL(enableAction(const char*,bool)),
m_ext, SIGNAL(enableAction(const char*,bool)) );
m_ext->setURLDropHandlingEnabled( true );
}
示例8: slotPartLoadingErrorNotify
void RenderPartObject::slotPartLoadingErrorNotify()
{
#if APPLE_CHANGES
// FIXME: What are we going to do for this case?
#else
// First we need to find out the servicetype - again - this code is too duplicated !
HTMLEmbedElementImpl *embed = 0;
QString serviceType;
if( element()->id()==ID_OBJECT ) {
// check for embed child object
HTMLObjectElementImpl *o = static_cast<HTMLObjectElementImpl *>(element());
serviceType = o->serviceType;
NodeImpl *child = o->firstChild();
while ( child ) {
if ( child->id() == ID_EMBED )
embed = static_cast<HTMLEmbedElementImpl *>( child );
child = child->nextSibling();
}
} else if( element()->id()==ID_EMBED ) {
embed = static_cast<HTMLEmbedElementImpl *>(element());
}
if ( embed )
serviceType = embed->serviceType;
KHTMLPart *part = static_cast<KHTMLView *>(m_view)->part();
KParts::BrowserExtension *ext = part->browserExtension();
if( embed && !embed->pluginPage.isEmpty() && ext ) {
// Prepare the mimetype to show in the question (comment if available, name as fallback)
QString mimeName = serviceType;
KMimeType::Ptr mime = KMimeType::mimeType(serviceType);
if ( mime->name() != KMimeType::defaultMimeType() )
mimeName = mime->comment();
// Prepare the URL to show in the question (host only if http, to make it short)
KURL pluginPageURL( embed->pluginPage );
QString shortURL = pluginPageURL.protocol() == "http" ? pluginPageURL.host() : pluginPageURL.prettyURL();
int res = KMessageBox::questionYesNo( m_view,
i18n("No plugin found for '%1'.\nDo you want to download one from %2?").arg(mimeName).arg(shortURL),
i18n("Missing plugin"), QString::null, QString::null, QString("plugin-")+serviceType);
if ( res == KMessageBox::Yes )
{
// Display vendor download page
ext->createNewWindow( pluginPageURL );
}
}
#endif // APPLE_CHANGES
}
示例9: UpdateHistory
void BrowserWindow::UpdateHistory()
{
HistoryEntry* pcCurrent = HistoryCurrent();
if ( pcCurrent == NULL ) {
pcCurrent = new HistoryEntry;
m_nCurHistoryPos = m_cHistory.size();
m_cHistory.push_back( pcCurrent );
} else {
pcCurrent->m_cState.MakeEmpty();
}
GlobalMutex::PushLooper( this );
m_pcHTMLPart->browserExtension()->saveState( &pcCurrent->m_cState );
pcCurrent->m_cURL = m_pcHTMLPart->url().prettyURL().utf8().data(); // m_pcURLView->GetBuffer()[0];
GlobalMutex::PopLooper();
}
示例10: MessageReceived
void BrowserWindow::MessageReceived( BMessage* pcMsg )
{
switch( pcMsg->what )
{
case ID_URL_CHANGED:
{
std::string cURL = m_pcURLView->Text();
for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
if ( i == cURL.size() || cURL[i] != ':' ) {
std::string cTmp = cURL;
cURL = "http://";
for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
if ( cTmp[j] != '/' ) {
cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
break;
}
}
}
break;
}
}
m_pcHTMLPart->view()->MakeFocus();
OpenURL( cURL, KParts::URLArgs() );
//----------------------------------------------
#if 0
uint32 nEvents = 0;
pcMsg->FindInt( "events", &nEvents );
if ( nEvents & os::TextView::EI_ESC_PRESSED ) {
m_pcURLView->Set( m_pcHTMLPart->url().prettyURL().utf8().data() );
m_pcHTMLPart->view()->MakeFocus();
break;
}
if ( nEvents & os::TextView::EI_ENTER_PRESSED ) {
std::string cURL = m_pcURLView->GetBuffer()[0];
for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
if ( i == cURL.size() || cURL[i] != ':' ) {
std::string cTmp = cURL;
cURL = "http://";
for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
if ( cTmp[j] != '/' ) {
cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
break;
}
}
}
break;
}
}
UpdateHistory();
AddHistoryEntry();
m_pcHTMLPart->view()->MakeFocus();
OpenURL( cURL, KParts::URLArgs() );
UpdateHistory();
}
#endif
break;
}
case ID_ACTIVATE_URLEDIT:
m_pcURLView->MakeFocus( true );
#if 0
m_pcURLView->SetCursor( -1, 0 );
#endif
m_pcURLView->TextView()->SelectAll();
break;
case ID_RELOAD:
{
KParts::URLArgs cArgs;
cArgs.reload = true;
cArgs.xOffset = m_pcHTMLPart->browserExtension()->xOffset();
cArgs.yOffset = m_pcHTMLPart->browserExtension()->yOffset();
#if 0
OpenURL( m_pcURLView->GetBuffer()[0], cArgs );
#endif
OpenURL( m_pcURLView->Text(), cArgs );
break;
}
case ID_NEW_WINDOW:
{
BrowserWindow* pcNewWindow = new BrowserWindow( Frame().OffsetByCopy( 30.0f, 30.0f ), false );
pcNewWindow->Show();
#if 0
UpdateHistory();
std::vector<HistoryEntry*> cHistory = m_cHistory;
cHistory.resize( m_nCurHistoryPos + 1 );
BrowserWindow* pcNewWindow = new BrowserWindow( GetFrame() + os::Point( 30.0f, 30.0f ), &cHistory, false );
pcNewWindow->GoHistory(0);
pcNewWindow->Show( true );
pcNewWindow->MakeFocus( true );
#endif
break;
}
case ID_OPEN_LINK:
{
BString cURL;
//.........这里部分代码省略.........
示例11: main
int main(int argc, char *argv[])
{
KCmdLineArgs::init(argc, argv, "Testkhtml", "a basic web browser using the KHTML library", "1.0");
KCmdLineArgs::addCmdLineOptions(options);
KApplication a;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs( );
if ( args->count() == 0 ) {
KCmdLineArgs::usage();
::exit( 1 );
}
KHTMLFactory *fac = new KHTMLFactory();
KMainWindow *toplevel = new KMainWindow();
KHTMLPart *doc = new KHTMLPart( toplevel, 0, toplevel, 0, KHTMLPart::BrowserViewGUI );
Dummy *dummy = new Dummy( doc );
QObject::connect( doc->browserExtension(), SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs & ) ),
dummy, SLOT( slotOpenURL( const KURL&, const KParts::URLArgs & ) ) );
if (args->url(0).url().right(4).find(".xml", 0, false) == 0) {
KParts::URLArgs ags(doc->browserExtension()->urlArgs());
ags.serviceType = "text/xml";
doc->browserExtension()->setURLArgs(ags);
}
doc->openURL( args->url(0) );
// DOMTreeView * dtv = new DOMTreeView(0, doc, "DomTreeView");
// dtv->show();
toplevel->setCentralWidget( doc->widget() );
toplevel->resize( 640, 800);
// dtv->resize(toplevel->width()/2, toplevel->height());
QDomDocument d = doc->domDocument();
QDomElement viewMenu = d.documentElement().firstChild().childNodes().item( 2 ).toElement();
QDomElement e = d.createElement( "action" );
e.setAttribute( "name", "debugRenderTree" );
viewMenu.appendChild( e );
e = d.createElement( "action" );
e.setAttribute( "name", "debugDOMTree" );
viewMenu.appendChild( e );
QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement();
e = d.createElement( "action" );
e.setAttribute( "name", "reload" );
toolBar.insertBefore( e, toolBar.firstChild() );
e = d.createElement( "action" );
e.setAttribute( "name", "print" );
toolBar.insertBefore( e, toolBar.firstChild() );
(void)new KAction( "Reload", "reload", Qt::Key_F5, dummy, SLOT( reload() ), doc->actionCollection(), "reload" );
KAction* kprint = new KAction( "Print", "print", 0, doc->browserExtension(), SLOT( print() ), doc->actionCollection(), "print" );
kprint->setEnabled(true);
toplevel->guiFactory()->addClient( doc );
doc->setJScriptEnabled(true);
doc->setJavaEnabled(true);
doc->setURLCursor(QCursor(Qt::PointingHandCursor));
a.setTopWidget(doc->widget());
QWidget::connect(doc, SIGNAL(setWindowCaption(const QString &)),
doc->widget(), SLOT(setCaption(const QString &)));
doc->widget()->show();
toplevel->show();
((QScrollView *)doc->widget())->viewport()->show();
int ret = a.exec();
//delete doc;
//delete dtv;
khtml::Cache::clear();
khtml::CSSStyleSelector::clear();
khtml::RenderStyle::cleanup();
delete fac;
return ret;
}
示例12: main
int main(int argc, char *argv[])
{
KCmdLineOptions options;
options.add("+file", ki18n("URL to open"));
KCmdLineArgs::init(argc, argv, "testkhtml", 0, ki18n("Testkhtml"),
"1.0", ki18n("a basic web browser using the KHTML library"));
KCmdLineArgs::addCmdLineOptions(options);
KApplication a;
KCmdLineArgs *args = KCmdLineArgs::parsedArgs( );
if ( args->count() == 0 ) {
KCmdLineArgs::usage();
::exit( 1 );
}
new KHTMLGlobal;
KXmlGuiWindow *toplevel = new KXmlGuiWindow();
KHTMLPart *doc = new KHTMLPart( toplevel, toplevel, KHTMLPart::BrowserViewGUI );
Dummy *dummy = new Dummy( doc );
QObject::connect( doc->browserExtension(), SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
dummy, SLOT(slotOpenURL(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) );
QObject::connect( doc, SIGNAL(completed()), dummy, SLOT(handleDone()) );
if (args->url(0).url().right(4).toLower() == ".xml") {
KParts::OpenUrlArguments args(doc->arguments());
args.setMimeType("text/xml");
doc->setArguments(args);
}
doc->openUrl( args->url(0) );
toplevel->setCentralWidget( doc->widget() );
toplevel->resize( 800, 600);
QDomDocument d = doc->domDocument();
QDomElement viewMenu = d.documentElement().firstChild().childNodes().item( 2 ).toElement();
QDomElement e = d.createElement( "action" );
e.setAttribute( "name", "debugRenderTree" );
viewMenu.appendChild( e );
e = d.createElement( "action" );
e.setAttribute( "name", "debugDOMTree" );
viewMenu.appendChild( e );
e = d.createElement( "action" );
e.setAttribute( "name", "debugDoBenchmark" );
viewMenu.appendChild( e );
QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement();
e = d.createElement( "action" );
e.setAttribute( "name", "editable" );
toolBar.insertBefore( e, toolBar.firstChild() );
e = d.createElement( "action" );
e.setAttribute( "name", "navigable" );
toolBar.insertBefore( e, toolBar.firstChild() );
e = d.createElement( "action" );
e.setAttribute( "name", "reload" );
toolBar.insertBefore( e, toolBar.firstChild() );
e = d.createElement( "action" );
e.setAttribute( "name", "print" );
toolBar.insertBefore( e, toolBar.firstChild() );
KAction *action = new KAction(KIcon("view-refresh"), "Reload", doc );
doc->actionCollection()->addAction( "reload", action );
QObject::connect(action, SIGNAL(triggered(bool)), dummy, SLOT(reload()));
action->setShortcut(Qt::Key_F5);
KAction *bench = new KAction( KIcon(), "Benchmark...", doc );
doc->actionCollection()->addAction( "debugDoBenchmark", bench );
QObject::connect(bench, SIGNAL(triggered(bool)), dummy, SLOT(doBenchmark()));
KAction *kprint = new KAction(KIcon("document-print"), "Print", doc );
doc->actionCollection()->addAction( "print", kprint );
QObject::connect(kprint, SIGNAL(triggered(bool)), doc->browserExtension(), SLOT(print()));
kprint->setEnabled(true);
KToggleAction *ta = new KToggleAction( KIcon("edit-rename"), "Navigable", doc );
doc->actionCollection()->addAction( "navigable", ta );
ta->setShortcuts( KShortcut() );
ta->setChecked(doc->isCaretMode());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleNavigable(bool)));
ta = new KToggleAction( KIcon("document-properties"), "Editable", doc );
doc->actionCollection()->addAction( "editable", ta );
ta->setShortcuts( KShortcut() );
ta->setChecked(doc->isEditable());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleEditable(bool)));
toplevel->guiFactory()->addClient( doc );
doc->setJScriptEnabled(true);
doc->setJavaEnabled(true);
doc->setPluginsEnabled( true );
doc->setURLCursor(QCursor(Qt::PointingHandCursor));
a.setTopWidget(doc->widget());
QWidget::connect(doc, SIGNAL(setWindowCaption(QString)),
doc->widget()->topLevelWidget(), SLOT(setCaption(QString)));
doc->widget()->show();
toplevel->show();
doc->view()->viewport()->show();
doc->view()->widget()->show();
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
if (a.arguments().count() <= 1) {
qWarning() << "Argument expected: url to open";
return 1;
}
new KHTMLGlobal;
KXmlGuiWindow *toplevel = new KXmlGuiWindow();
KHTMLPart *doc = new KHTMLPart(toplevel, toplevel, KHTMLPart::BrowserViewGUI);
Dummy *dummy = new Dummy(doc);
QObject::connect(doc->browserExtension(), SIGNAL(openUrlRequest(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
dummy, SLOT(slotOpenURL(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)));
QObject::connect(doc, SIGNAL(completed()), dummy, SLOT(handleDone()));
QUrl url = QUrl::fromUserInput(a.arguments().at(1)); // TODO support for relative paths
if (url.path().right(4).toLower() == ".xml") {
KParts::OpenUrlArguments args(doc->arguments());
args.setMimeType("text/xml");
doc->setArguments(args);
}
doc->openUrl(url);
toplevel->setCentralWidget(doc->widget());
toplevel->resize(800, 600);
QDomDocument d = doc->domDocument();
QDomElement viewMenu = d.documentElement().firstChild().childNodes().item(2).toElement();
QDomElement e = d.createElement("action");
e.setAttribute("name", "debugRenderTree");
viewMenu.appendChild(e);
e = d.createElement("action");
e.setAttribute("name", "debugDOMTree");
viewMenu.appendChild(e);
e = d.createElement("action");
e.setAttribute("name", "debugDoBenchmark");
viewMenu.appendChild(e);
QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement();
e = d.createElement("action");
e.setAttribute("name", "editable");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "navigable");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "reload");
toolBar.insertBefore(e, toolBar.firstChild());
e = d.createElement("action");
e.setAttribute("name", "print");
toolBar.insertBefore(e, toolBar.firstChild());
QAction *action = new QAction(QIcon::fromTheme("view-refresh"), "Reload", doc);
doc->actionCollection()->addAction("reload", action);
QObject::connect(action, SIGNAL(triggered(bool)), dummy, SLOT(reload()));
doc->actionCollection()->setDefaultShortcut(action, Qt::Key_F5);
QAction *bench = new QAction(QIcon(), "Benchmark...", doc);
doc->actionCollection()->addAction("debugDoBenchmark", bench);
QObject::connect(bench, SIGNAL(triggered(bool)), dummy, SLOT(doBenchmark()));
QAction *kprint = new QAction(QIcon::fromTheme("document-print"), "Print", doc);
doc->actionCollection()->addAction("print", kprint);
QObject::connect(kprint, SIGNAL(triggered(bool)), doc->browserExtension(), SLOT(print()));
kprint->setEnabled(true);
KToggleAction *ta = new KToggleAction(QIcon::fromTheme("edit-rename"), "Navigable", doc);
doc->actionCollection()->addAction("navigable", ta);
ta->setShortcuts(QList<QKeySequence>());
ta->setChecked(doc->isCaretMode());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleNavigable(bool)));
ta = new KToggleAction(QIcon::fromTheme("document-properties"), "Editable", doc);
doc->actionCollection()->addAction("editable", ta);
ta->setShortcuts(QList<QKeySequence>());
ta->setChecked(doc->isEditable());
QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleEditable(bool)));
toplevel->guiFactory()->addClient(doc);
doc->setJScriptEnabled(true);
doc->setJavaEnabled(true);
doc->setPluginsEnabled(true);
doc->setURLCursor(QCursor(Qt::PointingHandCursor));
a.setActiveWindow(doc->widget());
QWidget::connect(doc, SIGNAL(setWindowCaption(QString)),
doc->widget()->topLevelWidget(), SLOT(setCaption(QString)));
doc->widget()->show();
toplevel->show();
doc->view()->viewport()->show();
doc->view()->widget()->show();
int ret = a.exec();
return ret;
}