20 #include "tdehtmlimage.h"
21 #include "tdehtmlview.h"
22 #include "tdehtml_ext.h"
23 #include "xml/dom_docimpl.h"
24 #include "html/html_documentimpl.h"
25 #include "html/html_elementimpl.h"
26 #include "rendering/render_image.h"
27 #include "misc/loader.h"
32 #include <tdeio/job.h>
33 #include <kinstance.h>
34 #include <kmimetype.h>
37 K_EXPORT_COMPONENT_FACTORY( tdehtmlimagefactory , TDEHTMLImageFactory )
41 TDEHTMLImageFactory::TDEHTMLImageFactory()
46 TDEHTMLImageFactory::~TDEHTMLImageFactory()
51 KParts::Part *TDEHTMLImageFactory::createPartObject( TQWidget *parentWidget,
const char *widgetName,
52 TQObject *parent,
const char *name,
53 const char *className,
const TQStringList & )
55 TDEHTMLPart::GUIProfile prof = TDEHTMLPart::DefaultGUI;
56 if ( strcmp( className,
"Browser/View" ) == 0 )
57 prof = TDEHTMLPart::BrowserViewGUI;
58 return new TDEHTMLImage( parentWidget, widgetName, parent, name, prof );
61 TDEHTMLImage::TDEHTMLImage( TQWidget *parentWidget,
const char *widgetName,
62 TQObject *parent,
const char *name, TDEHTMLPart::GUIProfile prof )
65 TDEHTMLPart* parentPart = ::tqt_cast<TDEHTMLPart *>( parent );
66 setInstance( TDEHTMLImageFactory::instance(), prof == TDEHTMLPart::BrowserViewGUI && !parentPart );
68 TQVBox *box =
new TQVBox( parentWidget, widgetName );
70 m_tdehtml =
new TDEHTMLPart( box, widgetName,
this,
"htmlimagepart", prof );
71 m_tdehtml->setAutoloadImages(
true );
72 m_tdehtml->widget()->installEventFilter(
this);
73 connect( m_tdehtml->view(), TQ_SIGNAL( finishedLayout() ),
this, TQ_SLOT( restoreScrollPosition() ) );
78 box->setFocusProxy( m_tdehtml->widget() );
80 m_ext =
new TDEHTMLImageBrowserExtension(
this,
"be" );
83 TDEAction *encodingAction = actionCollection()->action(
"setEncoding" );
86 encodingAction->unplugAll();
87 delete encodingAction;
89 TDEAction *viewSourceAction= actionCollection()->action(
"viewDocumentSource" );
90 if ( viewSourceAction )
92 viewSourceAction->unplugAll();
93 delete viewSourceAction;
96 TDEAction *selectAllAction= actionCollection()->action(
"selectAll" );
97 if ( selectAllAction )
99 selectAllAction->unplugAll();
100 delete selectAllAction;
106 TDEHTMLPart *p = ::tqt_cast<TDEHTMLPart *>(parent);
108 connect(m_tdehtml->browserExtension(), TQ_SIGNAL(openURLRequestDelayed(
const KURL &,
const KParts::URLArgs &)),
111 connect( m_tdehtml->browserExtension(), TQ_SIGNAL( popupMenu(
KXMLGUIClient *,
const TQPoint &,
const KURL &,
113 const KParts::URLArgs &, KParts::BrowserExtension::PopupFlags, mode_t) ) );
115 connect( m_tdehtml->browserExtension(), TQ_SIGNAL( enableAction(
const char *,
bool ) ),
116 m_ext, TQ_SIGNAL( enableAction(
const char *,
bool ) ) );
118 m_ext->setURLDropHandlingEnabled(
true );
121 TDEHTMLImage::~TDEHTMLImage()
136 bool TDEHTMLImage::openURL(
const KURL &url )
149 emit setWindowCaption( url.
prettyURL() );
155 m_tdehtml->begin( m_url );
156 m_tdehtml->setAutoloadImages(
true );
158 DOM::DocumentImpl *impl =
dynamic_cast<DOM::DocumentImpl *
>( m_tdehtml->document().handle() );
159 if (!impl)
return false;
160 if ( m_ext->urlArgs().reload )
161 impl->docLoader()->setCachePolicy( TDEIO::CC_Reload );
163 tdehtml::DocLoader *dl = impl->docLoader();
164 m_image = dl->requestImage( m_url.url() );
166 m_image->ref(
this );
168 m_tdehtml->write( html.arg( m_url.url() ) );
178 bool TDEHTMLImage::closeURL()
181 return m_tdehtml->closeURL();
185 void TDEHTMLImage::notifyFinished( tdehtml::CachedObject *o )
187 if ( !m_image || o != m_image )
190 const TQPixmap &pix = m_image->pixmap();
193 KMimeType::Ptr mimeType;
194 if ( !m_mimeType.isEmpty() )
195 mimeType = KMimeType::mimeType( m_mimeType );
198 if (m_image && !m_image->suggestedTitle().isEmpty()) {
199 caption = i18n(
"%1 (%2 - %3x%4 Pixels)" ).arg( m_image->suggestedTitle(), mimeType->comment() ).arg( pix.width() ).arg( pix.height() );
201 caption = i18n(
"%1 - %2x%3 Pixels" ).arg( mimeType->comment() )
202 .arg( pix.width() ).arg( pix.height() );
205 if (m_image && !m_image->suggestedTitle().isEmpty()) {
206 caption = i18n(
"%1 (%2x%3 Pixels)" ).arg(m_image->suggestedTitle()).arg( pix.width() ).arg( pix.height() );
208 caption = i18n(
"Image - %1x%2 Pixels" ).arg( pix.width() ).arg( pix.height() );
212 emit setWindowCaption( caption );
214 emit setStatusBarText(i18n(
"Done."));
217 void TDEHTMLImage::restoreScrollPosition()
219 if ( m_tdehtml->view()->contentsY() == 0 ) {
220 m_tdehtml->view()->setContentsPos( m_xOffset, m_yOffset );
229 if ( e->activated() )
290 void TDEHTMLImage::disposeImage()
295 m_image->deref(
this );
299 bool TDEHTMLImage::eventFilter(TQObject *, TQEvent *e) {
301 case TQEvent::DragEnter:
302 case TQEvent::DragMove:
303 case TQEvent::DragLeave:
304 case TQEvent::Drop: {
307 TDEHTMLPart *p = ::tqt_cast<TDEHTMLPart *>(parent());
309 return TQApplication::sendEvent(p->
widget(), e);
312 return TQApplication::sendEvent(widget(), e);
319 TDEHTMLImageBrowserExtension::TDEHTMLImageBrowserExtension( TDEHTMLImage *parent,
const char *name )
325 int TDEHTMLImageBrowserExtension::xOffset()
327 return m_imgPart->doc()->view()->contentsX();
330 int TDEHTMLImageBrowserExtension::yOffset()
332 return m_imgPart->doc()->view()->contentsY();
335 void TDEHTMLImageBrowserExtension::print()
340 void TDEHTMLImageBrowserExtension::reparseConfiguration()
343 m_imgPart->doc()->setAutoloadImages(
true );
347 void TDEHTMLImageBrowserExtension::disableScrolling()
352 using namespace KParts;
354 #include "tdehtmlimage.moc"
virtual TQWidget * widget()
virtual void guiActivateEvent(GUIActivateEvent *event)
TQString prettyURL(int _trailing=0) const
static const TQString & staticQString(const char *str)
This is the BrowserExtension for a TDEHTMLPart document.
This class is tdehtml's main class.
KParts::BrowserExtension * browserExtension() const
Returns a pointer to the KParts::BrowserExtension.
TQString name(StdAccel id)
const TDEShortcut & print()