khtml Library API Documentation

khtml_ext.cpp

00001 
00002 #include <assert.h>
00003 #include "khtml_ext.h"
00004 #include "khtmlview.h"
00005 #include "khtml_pagecache.h"
00006 #include "rendering/render_form.h"
00007 #include "dom/html_form.h"
00008 #include "dom/html_image.h"
00009 #include <qclipboard.h>
00010 #include <qfileinfo.h>
00011 #include <qpopupmenu.h>
00012 #include <qmetaobject.h>
00013 #include <private/qucomextra_p.h>
00014 
00015 #include <kdebug.h>
00016 #include <klocale.h>
00017 #include <kfiledialog.h>
00018 #include <kio/job.h>
00019 #include <kprocess.h>
00020 #include <ktoolbarbutton.h>
00021 #include <ktoolbar.h>
00022 #include <ksavefile.h>
00023 #include <kurldrag.h>
00024 #include <kstringhandler.h>
00025 #include <kapplication.h>
00026 #include <kmessagebox.h>
00027 #include <kstandarddirs.h>
00028 #include <krun.h>
00029 
00030 #include "dom/dom_element.h"
00031 #include "misc/htmltags.h"
00032 
00033 KHTMLPartBrowserExtension::KHTMLPartBrowserExtension( KHTMLPart *parent, const char *name )
00034 : KParts::BrowserExtension( parent, name )
00035 {
00036     m_part = parent;
00037     setURLDropHandlingEnabled( true );
00038 
00039     enableAction( "cut", false );
00040     enableAction( "copy", false );
00041     enableAction( "paste", false );
00042 
00043     m_connectedToClipboard = false;
00044 }
00045 
00046 int KHTMLPartBrowserExtension::xOffset()
00047 {
00048     return m_part->view()->contentsX();
00049 }
00050 
00051 int KHTMLPartBrowserExtension::yOffset()
00052 {
00053   return m_part->view()->contentsY();
00054 }
00055 
00056 void KHTMLPartBrowserExtension::saveState( QDataStream &stream )
00057 {
00058   kdDebug( 6050 ) << "saveState!" << endl;
00059   m_part->saveState( stream );
00060 }
00061 
00062 void KHTMLPartBrowserExtension::restoreState( QDataStream &stream )
00063 {
00064   kdDebug( 6050 ) << "restoreState!" << endl;
00065   m_part->restoreState( stream );
00066 }
00067 
00068 void KHTMLPartBrowserExtension::editableWidgetFocused( QWidget *widget )
00069 {
00070     m_editableFormWidget = widget;
00071     updateEditActions();
00072 
00073     if ( !m_connectedToClipboard && m_editableFormWidget )
00074     {
00075         connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00076                  this, SLOT( updateEditActions() ) );
00077 
00078         if ( m_editableFormWidget->inherits( "QLineEdit" ) || m_editableFormWidget->inherits( "QTextEdit" ) )
00079             connect( m_editableFormWidget, SIGNAL( selectionChanged() ),
00080                      this, SLOT( updateEditActions() ) );
00081 
00082         m_connectedToClipboard = true;
00083     }
00084 }
00085 
00086 void KHTMLPartBrowserExtension::editableWidgetBlurred( QWidget *widget )
00087 {
00088     QWidget *oldWidget = m_editableFormWidget;
00089 
00090     m_editableFormWidget = widget;
00091     enableAction( "cut", false );
00092     enableAction( "paste", false );
00093     m_part->emitSelectionChanged();
00094 
00095     if ( m_connectedToClipboard )
00096     {
00097         disconnect( QApplication::clipboard(), SIGNAL( dataChanged() ),
00098                     this, SLOT( updateEditActions() ) );
00099 
00100         if ( oldWidget )
00101         {
00102             if ( oldWidget->inherits( "QLineEdit" ) || oldWidget->inherits( "QTextEdit" ) )
00103                 disconnect( oldWidget, SIGNAL( selectionChanged() ),
00104                             this, SLOT( updateEditActions() ) );
00105         }
00106 
00107         m_connectedToClipboard = false;
00108     }
00109 }
00110 
00111 void KHTMLPartBrowserExtension::setExtensionProxy( KParts::BrowserExtension *proxy )
00112 {
00113     if ( m_extensionProxy )
00114         disconnect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ),
00115                     this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) );
00116 
00117     m_extensionProxy = proxy;
00118 
00119     if ( m_extensionProxy )
00120     {
00121         connect( m_extensionProxy, SIGNAL( enableAction( const char *, bool ) ),
00122                  this, SLOT( extensionProxyActionEnabled( const char *, bool ) ) );
00123 
00124         enableAction( "cut", m_extensionProxy->isActionEnabled( "cut" ) );
00125         enableAction( "copy", m_extensionProxy->isActionEnabled( "copy" ) );
00126         enableAction( "paste", m_extensionProxy->isActionEnabled( "paste" ) );
00127     }
00128     else
00129     {
00130         updateEditActions();
00131         enableAction( "copy", false ); // ### re-check this
00132     }
00133 }
00134 
00135 void KHTMLPartBrowserExtension::cut()
00136 {
00137     if ( m_extensionProxy )
00138     {
00139         callExtensionProxyMethod( "cut()" );
00140         return;
00141     }
00142 
00143     if ( !m_editableFormWidget )
00144         return; // shouldn't happen
00145 
00146     if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00147         static_cast<QLineEdit *>( &(*m_editableFormWidget) )->cut();
00148     else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00149         static_cast<QTextEdit *>( &(*m_editableFormWidget) )->cut();
00150 }
00151 
00152 void KHTMLPartBrowserExtension::copy()
00153 {
00154     if ( m_extensionProxy )
00155     {
00156         callExtensionProxyMethod( "copy()" );
00157         return;
00158     }
00159 
00160     kdDebug( 6050 ) << "************! KHTMLPartBrowserExtension::copy()" << endl;
00161     if ( !m_editableFormWidget )
00162     {
00163         // get selected text and paste to the clipboard
00164         QString text = m_part->selectedText();
00165         QClipboard *cb = QApplication::clipboard();
00166         disconnect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) );
00167         cb->setText(text);
00168         connect( cb, SIGNAL( selectionChanged() ), m_part, SLOT( slotClearSelection() ) );
00169     }
00170     else
00171     {
00172         if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00173             static_cast<QLineEdit *>( &(*m_editableFormWidget) )->copy();
00174         else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00175             static_cast<QTextEdit *>( &(*m_editableFormWidget) )->copy();
00176     }
00177 }
00178 
00179 void KHTMLPartBrowserExtension::paste()
00180 {
00181     if ( m_extensionProxy )
00182     {
00183         callExtensionProxyMethod( "paste()" );
00184         return;
00185     }
00186 
00187     if ( !m_editableFormWidget )
00188         return; // shouldn't happen
00189 
00190     if ( m_editableFormWidget->inherits( "QLineEdit" ) )
00191         static_cast<QLineEdit *>( &(*m_editableFormWidget) )->paste();
00192     else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00193         static_cast<QTextEdit *>( &(*m_editableFormWidget) )->paste();
00194 }
00195 
00196 void KHTMLPartBrowserExtension::callExtensionProxyMethod( const char *method )
00197 {
00198     if ( !m_extensionProxy )
00199         return;
00200 
00201     int slot = m_extensionProxy->metaObject()->findSlot( method );
00202     if ( slot == -1 )
00203         return;
00204 
00205     QUObject o[ 1 ];
00206     m_extensionProxy->qt_invoke( slot, o );
00207 }
00208 
00209 void KHTMLPartBrowserExtension::updateEditActions()
00210 {
00211     if ( !m_editableFormWidget )
00212     {
00213         enableAction( "cut", false );
00214         enableAction( "paste", false );
00215         return;
00216     }
00217 
00218     // ### duplicated from KonqMainWindow::slotClipboardDataChanged
00219 #ifndef QT_NO_MIMECLIPBOARD // Handle minimalized versions of Qt Embedded
00220     QMimeSource *data = QApplication::clipboard()->data();
00221     enableAction( "paste", data->provides( "text/plain" ) );
00222 #else
00223     QString data=QApplication::clipboard()->text();
00224     enableAction( "paste", data.contains("://"));
00225 #endif
00226 
00227     bool hasSelection = false;
00228 
00229     if ( m_editableFormWidget->inherits( "QLineEdit" ) ) {
00230         hasSelection = static_cast<QLineEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
00231     }
00232     else if ( m_editableFormWidget->inherits( "QTextEdit" ) )
00233     {
00234         hasSelection = static_cast<QTextEdit *>( &(*m_editableFormWidget) )->hasSelectedText();
00235     }
00236 
00237     enableAction( "copy", hasSelection );
00238     enableAction( "cut", hasSelection );
00239 }
00240 
00241 void KHTMLPartBrowserExtension::extensionProxyActionEnabled( const char *action, bool enable )
00242 {
00243     // only forward enableAction calls for actions we actually do foward
00244     if ( strcmp( action, "cut" ) == 0 ||
00245          strcmp( action, "copy" ) == 0 ||
00246          strcmp( action, "paste" ) == 0 ) {
00247         enableAction( action, enable );
00248     }
00249 }
00250 
00251 void KHTMLPartBrowserExtension::reparseConfiguration()
00252 {
00253   m_part->reparseConfiguration();
00254 }
00255 
00256 void KHTMLPartBrowserExtension::print()
00257 {
00258   m_part->view()->print();
00259 }
00260 
00261 class KHTMLPopupGUIClient::KHTMLPopupGUIClientPrivate
00262 {
00263 public:
00264   KHTMLPart *m_khtml;
00265   KURL m_url;
00266   KURL m_imageURL;
00267   KAction *m_paPrintFrame;
00268   KAction *m_paSaveLinkAs;
00269   KAction *m_paSaveImageAs;
00270   KAction *m_paCopyLinkLocation;
00271   KAction *m_paStopAnimations;
00272   KAction *m_paCopyImageLocation;
00273   KAction *m_paViewImage;
00274   KAction *m_paReloadFrame;
00275   KAction *m_paViewFrameSource;
00276   KAction *m_paViewFrameInfo;
00277   KAction *m_paSendImage;
00278 };
00279 
00280 
00281 KHTMLPopupGUIClient::KHTMLPopupGUIClient( KHTMLPart *khtml, const QString &doc, const KURL &url )
00282 {
00283   d = new KHTMLPopupGUIClientPrivate;
00284   d->m_khtml = khtml;
00285   d->m_url = url;
00286 
00287   setInstance( khtml->instance() );
00288 
00289   actionCollection()->insert( khtml->actionCollection()->action( "selectAll" ) );
00290   actionCollection()->insert( khtml->actionCollection()->action( "security" ) );
00291   actionCollection()->insert( khtml->actionCollection()->action( "viewDocumentSource" ) );
00292 
00293   // frameset? -> add "Reload Frame" etc.
00294   if ( khtml->parentPart() )
00295   {
00296     d->m_paReloadFrame = new KAction( i18n( "Reload Frame" ), 0, this, SLOT( slotReloadFrame() ),
00297                                       actionCollection(), "reloadframe" );
00298     d->m_paViewFrameSource = new KAction( i18n( "View Frame Source" ), 0, d->m_khtml, SLOT( slotViewDocumentSource() ),
00299                                           actionCollection(), "viewFrameSource" );
00300     d->m_paViewFrameInfo = new KAction( i18n( "View Frame Information" ), 0, d->m_khtml, SLOT( slotViewPageInfo() ), actionCollection(), "viewPageInfo" );
00301     // This one isn't in khtml_popupmenu.rc anymore, because Print isn't either,
00302     // and because print frame is already in the toolbar and the menu.
00303     // But leave this here, so that it's easy to readd it.
00304     d->m_paPrintFrame = new KAction( i18n( "Print Frame..." ), "fileprint", 0, d->m_khtml->browserExtension(), SLOT( print() ), actionCollection(), "printFrame" );
00305   } else {
00306     actionCollection()->insert( khtml->actionCollection()->action( "viewPageInfo" ) );
00307   }
00308 
00309   actionCollection()->insert( khtml->actionCollection()->action( "setEncoding" ) );
00310 
00311   if ( !url.isEmpty() )
00312   {
00313     d->m_paSaveLinkAs = new KAction( i18n( "&Save Link As..." ), 0, this, SLOT( slotSaveLinkAs() ),
00314                                      actionCollection(), "savelinkas" );
00315     d->m_paCopyLinkLocation = new KAction( i18n( "Copy Link Location" ), 0, this, SLOT( slotCopyLinkLocation() ),
00316                                            actionCollection(), "copylinklocation" );
00317   }
00318 
00319   d->m_paStopAnimations = new KAction( i18n( "Stop Animations" ), 0, this, SLOT( slotStopAnimations() ),
00320                                        actionCollection(), "stopanimations" );
00321 
00322   DOM::Element e;
00323   e = khtml->nodeUnderMouse();
00324 
00325   if ( !e.isNull() && (e.elementId() == ID_IMG ||
00326                        (e.elementId() == ID_INPUT && !static_cast<DOM::HTMLInputElement>(e).src().isEmpty())))
00327   {
00328       if ( e.elementId() == ID_IMG )
00329           d->m_imageURL = KURL( static_cast<DOM::HTMLImageElement>( e ).src().string() );
00330       else
00331           d->m_imageURL = KURL( static_cast<DOM::HTMLInputElement>( e ).src().string() );
00332     d->m_paSaveImageAs = new KAction( i18n( "Save Image As..." ), 0, this, SLOT( slotSaveImageAs() ),
00333                                       actionCollection(), "saveimageas" );
00334     d->m_paSendImage = new KAction( i18n( "Send Image" ), 0, this, SLOT( slotSendImage() ),
00335                                       actionCollection(), "sendimage" );
00336 
00337 
00338     d->m_paCopyImageLocation = new KAction( i18n( "Copy Image Location" ), 0, this, SLOT( slotCopyImageLocation() ),
00339                                             actionCollection(), "copyimagelocation" );
00340     QString name = KStringHandler::csqueeze(d->m_imageURL.fileName()+d->m_imageURL.query(), 25);
00341     d->m_paViewImage = new KAction( i18n( "View Image (%1)" ).arg(name.replace(QRegExp("&"), "&&")), 0, this, SLOT( slotViewImage() ),
00342                                             actionCollection(), "viewimage" );
00343   }
00344 
00345   setXML( doc );
00346   setDOMDocument( QDomDocument(), true ); // ### HACK
00347 
00348   QDomElement menu = domDocument().documentElement().namedItem( "Menu" ).toElement();
00349 
00350   if ( actionCollection()->count() > 0 )
00351     menu.insertBefore( domDocument().createElement( "separator" ), menu.firstChild() );
00352 }
00353 
00354 KHTMLPopupGUIClient::~KHTMLPopupGUIClient()
00355 {
00356   delete d;
00357 }
00358 
00359 void KHTMLPopupGUIClient::slotSaveLinkAs()
00360 {
00361   KIO::MetaData metaData;
00362   metaData["referrer"] = d->m_khtml->referrer();
00363   saveURL( d->m_khtml->widget(), i18n( "Save Link As" ), d->m_url, metaData );
00364 }
00365 
00366 void KHTMLPopupGUIClient::slotSendImage()
00367 {
00368     QStringList urls;
00369     urls.append( d->m_imageURL.url());
00370     QString subject = d->m_imageURL.url();
00371     kapp->invokeMailer(QString::null, QString::null, QString::null, subject,
00372                        QString::null, //body
00373                        QString::null,
00374                        urls); // attachments
00375 
00376 
00377 }
00378 
00379 void KHTMLPopupGUIClient::slotSaveImageAs()
00380 {
00381   KIO::MetaData metaData;
00382   metaData["referrer"] = d->m_khtml->referrer();
00383   saveURL( d->m_khtml->widget(), i18n( "Save Image As" ), d->m_imageURL, metaData );
00384 }
00385 
00386 void KHTMLPopupGUIClient::slotCopyLinkLocation()
00387 {
00388   KURL safeURL(d->m_url);
00389   safeURL.setPass(QString::null);
00390   KURL::List lst;
00391   lst.append( safeURL );
00392 #ifndef QT_NO_MIMECLIPBOARD
00393   // Set it in both the mouse selection and in the clipboard
00394   QApplication::clipboard()->setSelectionMode(true);
00395   QApplication::clipboard()->setData( KURLDrag::newDrag( lst ) );
00396   QApplication::clipboard()->setSelectionMode(false);
00397   QApplication::clipboard()->setData( KURLDrag::newDrag( lst ) );
00398 #else
00399   QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries
00400 #endif
00401 }
00402 
00403 void KHTMLPopupGUIClient::slotStopAnimations()
00404 {
00405   d->m_khtml->stopAnimations();
00406 }
00407 
00408 void KHTMLPopupGUIClient::slotCopyImageLocation()
00409 {
00410   KURL safeURL(d->m_url);
00411   safeURL.setPass(QString::null);
00412   KURL::List lst;
00413   lst.append( safeURL );
00414 #ifndef QT_NO_MIMECLIPBOARD
00415   // Set it in both the mouse selection and in the clipboard
00416   QApplication::clipboard()->setSelectionMode(true);
00417   QApplication::clipboard()->setData( KURLDrag::newDrag( lst ) );
00418   QApplication::clipboard()->setSelectionMode(false);
00419   QApplication::clipboard()->setData( KURLDrag::newDrag( lst ) );
00420 #else
00421   QApplication::clipboard()->setText( safeURL.url() ); //FIXME(E): Handle multiple entries
00422 #endif
00423 }
00424 
00425 void KHTMLPopupGUIClient::slotViewImage()
00426 {
00427   d->m_khtml->browserExtension()->createNewWindow(d->m_imageURL.url());
00428 }
00429 
00430 void KHTMLPopupGUIClient::slotReloadFrame()
00431 {
00432   KParts::URLArgs args( d->m_khtml->browserExtension()->urlArgs() );
00433   args.reload = true;
00434   // reload document
00435   d->m_khtml->closeURL();
00436   d->m_khtml->browserExtension()->setURLArgs( args );
00437   d->m_khtml->openURL( d->m_khtml->url() );
00438 }
00439 
00440 void KHTMLPopupGUIClient::saveURL( QWidget *parent, const QString &caption,
00441                                    const KURL &url,
00442                                    const QMap<QString, QString> &metadata,
00443                                    const QString &filter, long cacheId,
00444                                    const QString & suggestedFilename )
00445 {
00446   QString name = QString::fromLatin1( "index.html" );
00447   if ( !suggestedFilename.isEmpty() )
00448     name = suggestedFilename;
00449   else if ( !url.fileName().isEmpty() )
00450     name = url.fileName();
00451 
00452   KURL destURL;
00453   int query;
00454   do {
00455     query = KMessageBox::Yes;
00456     destURL = KFileDialog::getSaveURL( name, filter, parent, caption );
00457       if( destURL.isLocalFile() )
00458       {
00459         QFileInfo info( destURL.path() );
00460         if( info.exists() )
00461           query = KMessageBox::warningContinueCancel( parent, i18n( "A file named \"%1\" already exists. " "Are you sure you want to overwrite it?" ).arg( info.fileName() ), i18n( "Overwrite File?" ), i18n( "Overwrite" ) );
00462        }
00463    } while ( query == KMessageBox::Cancel );
00464 
00465   if ( !destURL.isMalformed() )
00466     saveURL(url, destURL, metadata, cacheId);
00467 }
00468 
00469 void KHTMLPopupGUIClient::saveURL( const KURL &url, const KURL &destURL,
00470                                    const QMap<QString, QString> &metadata,
00471                                    long cacheId )
00472 {
00473     if ( !destURL.isMalformed() )
00474     {
00475         bool saved = false;
00476         if (KHTMLPageCache::self()->isValid(cacheId))
00477         {
00478             if (destURL.isLocalFile())
00479             {
00480                 KSaveFile destFile(destURL.path());
00481                 if (destFile.status() == 0)
00482                 {
00483                     KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00484                     saved = true;
00485                 }
00486             }
00487             else
00488             {
00489                 // save to temp file, then move to final destination.
00490                 KTempFile destFile;
00491                 if (destFile.status() == 0)
00492                 {
00493                     KHTMLPageCache::self()->saveData(cacheId, destFile.dataStream());
00494                     destFile.close();
00495                     KURL url2 = KURL();
00496                     url2.setPath(destFile.name());
00497                     KIO::move(url2, destURL);
00498                     saved = true;
00499                 }
00500             }
00501         }
00502         if(!saved)
00503         {
00504             // DownloadManager <-> konqueror integration
00505             // find if the integration is enabled
00506             // the empty key  means no integration
00507             KConfig *cfg = new KConfig("konquerorrc", false, false);
00508             cfg->setGroup("HTML Settings");
00509             QString downloadManger=cfg->readPathEntry("DownloadManager");
00510             if (!downloadManger.isEmpty())
00511             {
00512                 // then find the download manager location
00513                 kdDebug(1000) << "Using: "<<downloadManger <<" as Download Manager" <<endl;
00514                 QString cmd=KStandardDirs::findExe(downloadManger);
00515                 if (cmd.isEmpty())
00516                 {
00517                     QString errMsg=i18n("The Download Manager (%1) could not be found in your $PATH ").arg(downloadManger);
00518                     QString errMsgEx= i18n("Try to reinstall it  \n\nThe integration with Konqueror will be disabled!");
00519                     KMessageBox::detailedSorry(0,errMsg,errMsgEx);
00520                     cfg->writeEntry("DownloadManager",QString::null);
00521                     cfg->sync ();
00522                 }
00523                 else
00524                 {
00525                     KURL cleanDest = destURL;
00526                     cleanDest.setPass( QString::null ); // don't put password into commandline
00527                     cmd += " " + KProcess::quote(url.url()) + " " +
00528                            KProcess::quote(cleanDest.url());
00529                     kdDebug(1000) << "Calling command  "<<cmd<<endl;
00530                     KRun::runCommand(cmd);
00531                 }
00532             }
00533             else
00534             {
00535                 KIO::Job *job = KIO::copy( url, destURL );
00536                 job->setMetaData(metadata);
00537                 job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache.
00538                 job->addMetaData("cache", "cache"); // Use entry from cache if available.
00539                 job->setAutoErrorHandlingEnabled( true );
00540             }
00541             delete cfg;
00542         } //end if(!saved)
00543     }
00544 }
00545 
00546 KHTMLPartBrowserHostExtension::KHTMLPartBrowserHostExtension( KHTMLPart *part )
00547 : KParts::BrowserHostExtension( part )
00548 {
00549   m_part = part;
00550 }
00551 
00552 KHTMLPartBrowserHostExtension::~KHTMLPartBrowserHostExtension()
00553 {
00554 }
00555 
00556 QStringList KHTMLPartBrowserHostExtension::frameNames() const
00557 {
00558   return m_part->frameNames();
00559 }
00560 
00561 const QPtrList<KParts::ReadOnlyPart> KHTMLPartBrowserHostExtension::frames() const
00562 {
00563   return m_part->frames();
00564 }
00565 
00566 bool KHTMLPartBrowserHostExtension::openURLInFrame( const KURL &url, const KParts::URLArgs &urlArgs )
00567 {
00568   return m_part->openURLInFrame( url, urlArgs );
00569 }
00570 
00571 void KHTMLPartBrowserHostExtension::virtual_hook( int id, void *data )
00572 { 
00573   if (id == VIRTUAL_FIND_FRAME_PARENT)
00574   {
00575     FindFrameParentParams *param = static_cast<FindFrameParentParams*>(data);
00576     KHTMLPart *parentPart = m_part->findFrameParent(param->callingPart, param->frame);
00577     if (parentPart)
00578        param->parent = parentPart->browserHostExtension();
00579     return;
00580   }
00581   BrowserHostExtension::virtual_hook( id, data );
00582 }
00583 
00584 KHTMLZoomFactorAction::KHTMLZoomFactorAction( KHTMLPart *part, bool direction, const QString &text, const QString &icon, const QObject *receiver, const char *slot, QObject *parent, const char *name )
00585     : KAction( text, icon, 0, receiver, slot, parent, name )
00586 {
00587     m_direction = direction;
00588     m_part = part;
00589 
00590     m_popup = new QPopupMenu;
00591     m_popup->insertItem( i18n( "Default Font Size" ) );
00592 
00593     int m = m_direction ? 1 : -1;
00594 
00595     for ( int i = 1; i < 5; ++i )
00596     {
00597         int num = i * m;
00598         QString numStr = QString::number( num );
00599         if ( num > 0 ) numStr.prepend( '+' );
00600 
00601         m_popup->insertItem( i18n( "Font Size %1" ).arg( numStr ) );
00602     }
00603 
00604     connect( m_popup, SIGNAL( activated( int ) ), this, SLOT( slotActivated( int ) ) );
00605 }
00606 
00607 KHTMLZoomFactorAction::~KHTMLZoomFactorAction()
00608 {
00609     delete m_popup;
00610 }
00611 
00612 int KHTMLZoomFactorAction::plug( QWidget *w, int index )
00613 {
00614     int containerId = KAction::plug( w, index );
00615     if ( containerId == -1 || !w->inherits( "KToolBar" ) )
00616         return containerId;
00617 
00618     KToolBarButton *button = static_cast<KToolBar *>( w )->getButton( menuId( containerId ) );
00619     if ( !button )
00620         return containerId;
00621 
00622     button->setDelayedPopup( m_popup );
00623     return containerId;
00624 }
00625 
00626 void KHTMLZoomFactorAction::slotActivated( int id )
00627 {
00628     int idx = m_popup->indexOf( id );
00629 
00630     if (idx == 0)
00631         m_part->setZoomFactor(100);
00632     else
00633         m_part->setZoomFactor(m_part->zoomFactor() + (m_direction ? 10 : -10) * idx);
00634 }
00635 
00636 #include "khtml_ext.moc"
00637 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Mar 16 18:45:36 2005 by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-2001