This commit is contained in:
pekka.aho 2008-04-19 19:04:32 +03:00
Родитель af19c7a530
Коммит 15f7389033
4 изменённых файлов: 87 добавлений и 9 удалений

Просмотреть файл

@ -77,6 +77,8 @@
#include "nsPIDOMEventTarget.h"
#include <nsCOMPtr.h>
#include <nsPIDOMWindow.h>
#include <nsIMarkupDocumentViewer.h>
#include <nsIContentViewer.h>
#include "prenv.h"
@ -731,3 +733,54 @@ void QGeckoEmbed::initialize(const char *aDir, const char *aName, const char *xp
QGeckoGlobals::setProfilePath(aDir, aName);
}
static nsresult
GetMarkupViewerByWindow(nsIDOMWindow *aDOMWindow,
nsIMarkupDocumentViewer * *aMarkupDocViewver)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aMarkupDocViewver);
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aDOMWindow, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsIDocShell *docShell = nsnull;
if (window)
docShell = window->GetDocShell();
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIContentViewer> contentViewer;
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(contentViewer, &rv));
NS_ENSURE_TRUE(markupViewer, NS_ERROR_FAILURE);
*aMarkupDocViewver = markupViewer;
NS_IF_ADDREF(*aMarkupDocViewver);
return rv;
}
bool QGeckoEmbed::zoom( const float &zoomFactor )
{
// get the web browser
nsCOMPtr<nsIWebBrowser> webBrowser = NULL;
d->window->GetWebBrowser(getter_AddRefs(webBrowser));
if( !webBrowser ){
return FALSE;
}
// get the content DOM window for that web browser
nsCOMPtr<nsIDOMWindow> domWindow = NULL;
webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow){
return FALSE;
}
nsCOMPtr<nsIMarkupDocumentViewer> markupViewer = NULL;
nsresult rv = NS_OK;
rv = GetMarkupViewerByWindow(domWindow, getter_AddRefs(markupViewer));
if (!markupViewer || !NS_SUCCEEDED(rv) ){
return FALSE;
}
rv = markupViewer->SetFullZoom(zoomFactor);
return NS_SUCCEEDED(rv);
}

Просмотреть файл

@ -105,6 +105,8 @@ public:
NS_VISIBILITY_DEFAULT QString url() const;
NS_VISIBILITY_DEFAULT QString resolvedUrl(const QString &relativepath) const;
NS_VISIBILITY_DEFAULT bool zoom( const float &zoomFactor );
public NS_SLOTS:
NS_VISIBILITY_DEFAULT void loadURL(const QString &url);
NS_VISIBILITY_DEFAULT void stopLoad();

Просмотреть файл

@ -14,7 +14,9 @@
const QString rsrcPath = ":/images/lin";
MyMainWindow::MyMainWindow()
: zoomFactor( 1.0f )
{
QFrame *box = new QFrame(this);
qecko = new QGeckoEmbed(box, "qgecko");
box->setFrameStyle(QFrame::Panel | QFrame::Sunken);
@ -29,22 +31,30 @@ MyMainWindow::MyMainWindow()
QAction *action = new QAction(QIcon(rsrcPath + "/back.png"), tr( "Go Back"), toolbar);
action->setShortcut(Qt::ControlModifier + Qt::Key_B);
// toolbar, "goback");
connect(action, SIGNAL(activated()), this, SLOT(goBack()));
connect(action, SIGNAL(triggered()), this, SLOT(goBack()));
toolbar->addAction(action);
action = new QAction(QIcon(rsrcPath + "/forward.png" ), tr( "Go Forward"), toolbar);
action->setShortcut(Qt::ControlModifier + Qt::Key_F);
// toolbar, "goforward");
connect(action, SIGNAL(activated()), this, SLOT(goForward()));
connect(action, SIGNAL(triggered()), this, SLOT(goForward()));
toolbar->addAction(action);
action = new QAction(QIcon(rsrcPath + "/stop.png" ), tr("Stop"), toolbar);
action->setShortcut(Qt::ControlModifier + Qt::Key_S);
// toolbar, "stop");
connect(action, SIGNAL(activated()), this, SLOT(stop()));
connect(action, SIGNAL(triggered()), this, SLOT(stop()));
toolbar->addAction(action);
action = new QAction(QIcon(rsrcPath + "/stop.png" ), tr("Zoom In"), toolbar);
action->setShortcut(Qt::ControlModifier + Qt::Key_Plus);
connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
toolbar->addAction(action);
action = new QAction(QIcon(rsrcPath + "/stop.png" ), tr("Zoom Out"), toolbar);
action->setShortcut(Qt::ControlModifier + Qt::Key_Minus);
connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
toolbar->addAction(action);
location = new QLineEdit(toolbar);
toolbar->addWidget(location);
@ -53,9 +63,7 @@ MyMainWindow::MyMainWindow()
QAction *a = new QAction( QIcon(rsrcPath + "/fileopen.png" ), tr( "&Open..." ), toolbar);
a->setShortcut( Qt::ControlModifier + Qt::Key_O );
// toolbar, "fileOpen" );
connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
//a->addTo( toolbar );
connect( a, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
menu->addAction(a);
@ -118,6 +126,18 @@ void MyMainWindow::stop()
qecko->stopLoad();
}
void MyMainWindow::zoomIn()
{
zoomFactor += 0.2f;
qecko->zoom( zoomFactor );
}
void MyMainWindow::zoomOut()
{
zoomFactor -= 0.2f;
qecko->zoom( zoomFactor );
}
void MyMainWindow::slotProgress(const QString &url, int current, int max)
{
qDebug("progress %d / %d (%s)", current, max, url.toUtf8().data());

Просмотреть файл

@ -20,6 +20,8 @@ public slots:
void goForward();
void stop();
void mainQuit();
void zoomIn();
void zoomOut();
public:
QGeckoEmbed *qecko;
@ -30,6 +32,7 @@ private slots:
private:
QLineEdit *location;
float zoomFactor;
};
#endif