00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "webpage.h"
00015
00016 #include <stdlib.h>
00017
00018 #include <qdragobject.h>
00019 #include <qpainter.h>
00020 #include <qpaintdevicemetrics.h>
00021 #include <qlayout.h>
00022 #include <qhbox.h>
00023 #include <qlabel.h>
00024 #include <qcursor.h>
00025 #include <qtimer.h>
00026
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029 #include <kkeydialog.h>
00030 #include <kaccel.h>
00031 #include <kio/netaccess.h>
00032 #include <kconfig.h>
00033 #include <kurl.h>
00034 #include <kurlrequesterdlg.h>
00035
00036 #include <kstdaccel.h>
00037 #include <kaction.h>
00038 #include <kstdaction.h>
00039
00040 #include <khtml_part.h>
00041 #include <khtmlview.h>
00042 #include <kio/jobclasses.h>
00043
00044 using namespace std;
00045
00046 WebPage::WebPage (const char *location, int zoom, WFlags flags)
00047 : QWidget(NULL, NULL, flags)
00048 {
00049 setPaletteBackgroundColor(Qt::white);
00050
00051 QHBoxLayout *hbox = new QHBoxLayout(this);
00052 browser = new KHTMLPart(this);
00053 hbox->addWidget(browser->view());
00054
00055
00056 connect(browser->browserExtension(),
00057 SIGNAL(openURLRequest(const KURL &, const KParts::URLArgs &)),
00058 this,
00059 SLOT(openURLRequest(const KURL &, const KParts::URLArgs &)));
00060
00061 connect(browser->browserExtension(),
00062 SIGNAL( createNewWindow(const KURL &, const KParts::URLArgs &,
00063 const KParts::WindowArgs &, KParts::ReadOnlyPart *&)),
00064 this,
00065 SLOT( createNewWindow(const KURL &, const KParts::URLArgs &,
00066 const KParts::WindowArgs &, KParts::ReadOnlyPart *&)));
00067
00068
00069 connect(browser, SIGNAL(started(KIO::Job*)),
00070 this, SLOT(started(KIO::Job*)));
00071 connect(browser, SIGNAL(completed()),
00072 this, SLOT(completed()));
00073 connect(browser, SIGNAL(completed(bool)),
00074 this, SLOT(completed()));
00075
00076 browser->setStandardFont("Arial");
00077
00078 zoom = zoom<20 ? 20:zoom;
00079 zoom = zoom>300 ? 300:zoom;
00080 browser->setZoomFactor(zoom);
00081 zoomFactor=zoom;
00082
00083 browser->setPluginsEnabled(true);
00084 browser->enableMetaRefresh(true);
00085 browser->setJavaEnabled(true);
00086 browser->enableJScript(true);
00087
00088 openURL(QString(location));
00089 }
00090
00091 WebPage::WebPage (const char *location, const KParts::URLArgs &args,
00092 int zoom, WFlags flags)
00093 : QWidget(NULL,NULL,flags)
00094 {
00095 setPaletteBackgroundColor(Qt::white);
00096
00097 QHBoxLayout *hbox = new QHBoxLayout(this);
00098 browser = new KHTMLPart(this);
00099 hbox->addWidget(browser->view());
00100
00101
00102 connect(browser->browserExtension(),
00103 SIGNAL(openURLRequest(const KURL &, const KParts::URLArgs &)),
00104 this,
00105 SLOT(openURLRequest(const KURL &, const KParts::URLArgs &)));
00106
00107 connect(browser->browserExtension(),
00108 SIGNAL(createNewWindow( const KURL &, const KParts::URLArgs &,
00109 const KParts::WindowArgs &, KParts::ReadOnlyPart *&)),
00110 this,
00111 SLOT(createNewWindow(const KURL &, const KParts::URLArgs &,
00112 const KParts::WindowArgs &, KParts::ReadOnlyPart *&)));
00113
00114
00115 connect(browser,SIGNAL(started(KIO::Job*)),
00116 this,SLOT(started(KIO::Job*)));
00117 connect(browser,SIGNAL(completed()),
00118 this,SLOT(completed()));
00119 connect(browser,SIGNAL(completed(bool)),
00120 this,SLOT(completed()));
00121
00122 browser->setStandardFont("Arial");
00123 browser->browserExtension()->setURLArgs(args);
00124
00125 zoom = zoom<20 ? 20:zoom;
00126 zoom = zoom>300 ? 300:zoom;
00127 browser->setZoomFactor(zoom);
00128 zoomFactor=zoom;
00129
00130 browser->setPluginsEnabled(true);
00131 browser->enableMetaRefresh(true);
00132 browser->setJavaEnabled(true);
00133 browser->enableJScript(true);
00134
00135 openURL(QString(location));
00136 }
00137
00138 WebPage::~WebPage()
00139 {
00140 }
00141
00142 void WebPage::openURL(const QString &url)
00143 {
00144 sUrl = url;
00145 if (url != "")
00146 browser->openURL(url);
00147 }
00148
00149 void WebPage::openURLRequest(const KURL &url, const KParts::URLArgs &args)
00150 {
00151 emit newUrlRequested(url,args);
00152 }
00153
00154 void WebPage::createNewWindow( const KURL &url, const KParts::URLArgs &args,
00155 const KParts::WindowArgs &windowArgs,
00156 KParts::ReadOnlyPart *&part)
00157 {
00158 emit newWindowRequested(url, args, windowArgs, part);
00159 }
00160
00161 void WebPage::zoomOut()
00162 {
00163 zoomFactor -= 20;
00164 zoomFactor = zoomFactor<20 ? 20:zoomFactor;
00165 browser->setZoomFactor(zoomFactor);
00166 }
00167
00168 void WebPage::zoomIn()
00169 {
00170 zoomFactor += 20;
00171 zoomFactor = zoomFactor>300 ? 300:zoomFactor;
00172 browser->setZoomFactor(zoomFactor);
00173 }
00174
00175 bool WebPage::eventFilter(QObject* object, QEvent* event)
00176 {
00177 object = object;
00178
00179 switch(event->type())
00180 {
00181 case QEvent::KeyPress:
00182 printf("Key press event\n");
00183 break;
00184 case QEvent::MouseButtonPress:
00185 printf("MouseButtonPress Event\n");
00186 break;
00187 case QEvent::MouseButtonRelease:
00188 printf("MouseButtonRelease Event\n");
00189 break;
00190 case QEvent::MouseButtonDblClick:
00191 printf("MouseButtonDblClick Event\n");
00192 break;
00193 default:
00194 printf("An other event was detected %d\n",event->type());
00195 break;
00196 }
00197 return false;
00198 }
00199
00200 void WebPage::started(KIO::Job *job)
00201 {
00202 job = job;
00203 setCursor(QCursor(Qt::BusyCursor));
00204 }
00205
00206 void WebPage::completed()
00207 {
00208 setCursor(QCursor(Qt::ArrowCursor));
00209
00210
00211
00212 KURL url(sUrl);
00213 if (url.hasRef())
00214 {
00215 QTimer::singleShot(1, this, SLOT(timerTimeout()));
00216 }
00217
00218 setFocus();
00219
00220 emit pageCompleted( this );
00221 }
00222
00223 void WebPage::timerTimeout()
00224 {
00225
00226 KURL url(sUrl);
00227 if (url.hasRef())
00228 {
00229 if (!browser->gotoAnchor(url.encodedHtmlRef()))
00230 browser->gotoAnchor(url.htmlRef());
00231 }
00232 }