Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
New property 'viewportSize' to read and modify the viewport size.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Dec 31, 2010
1 parent 570eee0 commit 069cf54
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/phantomjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Phantom: public QObject
Q_PROPERTY(QString loadStatus READ loadStatus)
Q_PROPERTY(QString storage READ storage WRITE setStorage)
Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent)
Q_PROPERTY(QVariantMap viewportSize READ viewportSize WRITE setViewportSize)

public:
Phantom(QObject *parent = 0);
Expand All @@ -98,6 +99,9 @@ class Phantom: public QObject
void setUserAgent(const QString &ua);
QString userAgent() const;

void setViewportSize(const QVariantMap &size);
QVariantMap viewportSize() const;

public slots:
void exit(int code = 0);
void log(const QString &msg);
Expand Down Expand Up @@ -242,6 +246,23 @@ QString Phantom::userAgent() const
return m_page.m_userAgent;
}

void Phantom::setViewportSize(const QVariantMap &size)
{
int w = size.value("width").toInt();
int h = size.value("height").toInt();
if (w > 0 && h > 0)
m_page.setViewportSize(QSize(w, h));
}

QVariantMap Phantom::viewportSize() const
{
QVariantMap result;
QSize size = m_page.viewportSize();
result["width"] = size.width();
result["height"] = size.height();
return result;
}

#include "phantomjs.moc"

int main(int argc, char** argv)
Expand Down

0 comments on commit 069cf54

Please sign in to comment.