Commit c4ea075e authored by kenneth@webkit.org's avatar kenneth@webkit.org

Rubberstamped by Simon Hausmann.

[Qt] Separate implementation from class definition.

* QtLauncher/main.cpp:
(LauncherWindow::webView):
(LauncherWindow::LauncherWindow):
(LauncherWindow::~LauncherWindow):
(LauncherWindow::keyPressEvent):
(LauncherWindow::grabZoomKeys):
(LauncherWindow::sendTouchEvent):
(LauncherWindow::eventFilter):
(LauncherWindow::loadStarted):
(LauncherWindow::loadFinished):
(LauncherWindow::showLinkHover):
(LauncherWindow::zoomIn):
(LauncherWindow::zoomOut):
(LauncherWindow::resetZoom):
(LauncherWindow::toggleZoomTextOnly):
(LauncherWindow::print):
(LauncherWindow::screenshot):
(LauncherWindow::setEditable):
(LauncherWindow::dumpHtml):
(LauncherWindow::selectElements):
(LauncherWindow::setTouchMocking):
(LauncherWindow::newWindow):
(LauncherWindow::setupUI):

git-svn-id: svn://svn.chromium.org/blink/trunk@54077 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 03061356
...@@ -7,6 +7,36 @@ ...@@ -7,6 +7,36 @@
* Scripts/prepare-ChangeLog: * Scripts/prepare-ChangeLog:
2010-01-29 Kenneth Rohde Christiansen <kenneth@webkit.org>
Rubberstamped by Simon Hausmann.
[Qt] Separate implementation from class definition.
* QtLauncher/main.cpp:
(LauncherWindow::webView):
(LauncherWindow::LauncherWindow):
(LauncherWindow::~LauncherWindow):
(LauncherWindow::keyPressEvent):
(LauncherWindow::grabZoomKeys):
(LauncherWindow::sendTouchEvent):
(LauncherWindow::eventFilter):
(LauncherWindow::loadStarted):
(LauncherWindow::loadFinished):
(LauncherWindow::showLinkHover):
(LauncherWindow::zoomIn):
(LauncherWindow::zoomOut):
(LauncherWindow::resetZoom):
(LauncherWindow::toggleZoomTextOnly):
(LauncherWindow::print):
(LauncherWindow::screenshot):
(LauncherWindow::setEditable):
(LauncherWindow::dumpHtml):
(LauncherWindow::selectElements):
(LauncherWindow::setTouchMocking):
(LauncherWindow::newWindow):
(LauncherWindow::setupUI):
2010-01-29 Kenneth Rohde Christiansen <kenneth@webkit.org> 2010-01-29 Kenneth Rohde Christiansen <kenneth@webkit.org>
Reviewed by Ariya Hidayat. Reviewed by Ariya Hidayat.
......
...@@ -74,10 +74,69 @@ class LauncherWindow : public MainWindow { ...@@ -74,10 +74,69 @@ class LauncherWindow : public MainWindow {
Q_OBJECT Q_OBJECT
public: public:
LauncherWindow(QString url = QString()) LauncherWindow(QString url = QString());
virtual ~LauncherWindow();
virtual void keyPressEvent(QKeyEvent* event);
void grabZoomKeys(bool grab);
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
void sendTouchEvent();
bool eventFilter(QObject* obj, QEvent* event);
#endif
QWebView* webView() const { return view; }
protected slots:
void loadStarted();
void loadFinished();
void showLinkHover(const QString &link, const QString &toolTip);
void zoomIn();
void zoomOut();
void resetZoom();
void toggleZoomTextOnly(bool on);
void print();
void screenshot();
void setEditable(bool on);
/* void dumpPlugins() */
void dumpHtml();
void selectElements();
void setTouchMocking(bool on);
public slots:
void newWindow(const QString& url = QString());
private:
// create the status bar, tool bar & menu
void setupUI();
private:
QVector<int> zoomLevels;
int currentZoom;
QWebView* view;
WebInspector* inspector;
QAction* formatMenuAction;
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QList<QTouchEvent::TouchPoint> touchPoints;
bool touchMocking;
#endif
};
LauncherWindow::LauncherWindow(QString url)
: MainWindow(url) : MainWindow(url)
, currentZoom(100) , currentZoom(100)
{ {
QSplitter* splitter = new QSplitter(Qt::Vertical, this); QSplitter* splitter = new QSplitter(Qt::Vertical, this);
setCentralWidget(splitter); setCentralWidget(splitter);
...@@ -109,15 +168,15 @@ public: ...@@ -109,15 +168,15 @@ public:
grabZoomKeys(true); grabZoomKeys(true);
load(url); load(url);
} }
~LauncherWindow() LauncherWindow::~LauncherWindow()
{ {
grabZoomKeys(false); grabZoomKeys(false);
} }
void keyPressEvent(QKeyEvent* event) void LauncherWindow::keyPressEvent(QKeyEvent* event)
{ {
#ifdef Q_WS_MAEMO_5 #ifdef Q_WS_MAEMO_5
switch (event->key()) { switch (event->key()) {
case Qt::Key_F7: case Qt::Key_F7:
...@@ -131,10 +190,10 @@ public: ...@@ -131,10 +190,10 @@ public:
} }
#endif #endif
MainWindow::keyPressEvent(event); MainWindow::keyPressEvent(event);
} }
void grabZoomKeys(bool grab) void LauncherWindow::grabZoomKeys(bool grab)
{ {
#ifdef Q_WS_MAEMO_5 #ifdef Q_WS_MAEMO_5
if (!winId()) { if (!winId()) {
qWarning("Can't grab keys unless we have a window id"); qWarning("Can't grab keys unless we have a window id");
...@@ -150,11 +209,11 @@ public: ...@@ -150,11 +209,11 @@ public:
unsigned long val = (grab) ? 1 : 0; unsigned long val = (grab) ? 1 : 0;
XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&val), 1); XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char*>(&val), 1);
#endif #endif
} }
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
void sendTouchEvent() void LauncherWindow::sendTouchEvent()
{ {
if (touchPoints.isEmpty()) if (touchPoints.isEmpty())
return; return;
...@@ -175,10 +234,10 @@ public: ...@@ -175,10 +234,10 @@ public:
touchPoints.removeAt(0); touchPoints.removeAt(0);
if (touchPoints.size() > 1 && touchPoints[1].state() == Qt::TouchPointReleased) if (touchPoints.size() > 1 && touchPoints[1].state() == Qt::TouchPointReleased)
touchPoints.removeAt(1); touchPoints.removeAt(1);
} }
bool eventFilter(QObject* obj, QEvent* event) bool LauncherWindow::eventFilter(QObject* obj, QEvent* event)
{ {
if (!touchMocking || obj != view) if (!touchMocking || obj != view)
return QObject::eventFilter(obj, event); return QObject::eventFilter(obj, event);
...@@ -241,29 +300,23 @@ public: ...@@ -241,29 +300,23 @@ public:
} }
} }
return false; return false;
} }
#endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) #endif // QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QWebView* webView() const void LauncherWindow::loadStarted()
{ {
return view;
}
protected slots:
void loadStarted()
{
view->setFocus(Qt::OtherFocusReason); view->setFocus(Qt::OtherFocusReason);
} }
void loadFinished() void LauncherWindow::loadFinished()
{ {
QUrl url = page()->mainFrame()->url(); QUrl url = page()->mainFrame()->url();
setAddressUrl(url.toString()); setAddressUrl(url.toString());
addCompleterEntry(url); addCompleterEntry(url);
} }
void showLinkHover(const QString &link, const QString &toolTip) void LauncherWindow::showLinkHover(const QString &link, const QString &toolTip)
{ {
#ifndef Q_WS_MAEMO_5 #ifndef Q_WS_MAEMO_5
statusBar()->showMessage(link); statusBar()->showMessage(link);
#endif #endif
...@@ -271,51 +324,51 @@ protected slots: ...@@ -271,51 +324,51 @@ protected slots:
if (!toolTip.isEmpty()) if (!toolTip.isEmpty())
QToolTip::showText(QCursor::pos(), toolTip); QToolTip::showText(QCursor::pos(), toolTip);
#endif #endif
} }
void zoomIn() void LauncherWindow::zoomIn()
{ {
int i = zoomLevels.indexOf(currentZoom); int i = zoomLevels.indexOf(currentZoom);
Q_ASSERT(i >= 0); Q_ASSERT(i >= 0);
if (i < zoomLevels.count() - 1) if (i < zoomLevels.count() - 1)
currentZoom = zoomLevels[i + 1]; currentZoom = zoomLevels[i + 1];
page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0); page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0);
} }
void zoomOut() void LauncherWindow::zoomOut()
{ {
int i = zoomLevels.indexOf(currentZoom); int i = zoomLevels.indexOf(currentZoom);
Q_ASSERT(i >= 0); Q_ASSERT(i >= 0);
if (i > 0) if (i > 0)
currentZoom = zoomLevels[i - 1]; currentZoom = zoomLevels[i - 1];
page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0); page()->mainFrame()->setZoomFactor(qreal(currentZoom) / 100.0);
} }
void resetZoom() void LauncherWindow::resetZoom()
{ {
currentZoom = 100; currentZoom = 100;
page()->mainFrame()->setZoomFactor(1.0); page()->mainFrame()->setZoomFactor(1.0);
} }
void toggleZoomTextOnly(bool b) void LauncherWindow::toggleZoomTextOnly(bool b)
{ {
page()->settings()->setAttribute(QWebSettings::ZoomTextOnly, b); page()->settings()->setAttribute(QWebSettings::ZoomTextOnly, b);
} }
void print() void LauncherWindow::print()
{ {
#if !defined(QT_NO_PRINTER) #if !defined(QT_NO_PRINTER)
QPrintPreviewDialog dlg(this); QPrintPreviewDialog dlg(this);
connect(&dlg, SIGNAL(paintRequested(QPrinter *)), connect(&dlg, SIGNAL(paintRequested(QPrinter*)),
view, SLOT(print(QPrinter *))); view, SLOT(print(QPrinter*)));
dlg.exec(); dlg.exec();
#endif #endif
} }
void screenshot() void LauncherWindow::screenshot()
{ {
QPixmap pixmap = QPixmap::grabWidget(view); QPixmap pixmap = QPixmap::grabWidget(view);
QLabel* label = new QLabel; QLabel* label = new QLabel;
label->setAttribute(Qt::WA_DeleteOnClose); label->setAttribute(Qt::WA_DeleteOnClose);
...@@ -328,16 +381,16 @@ protected slots: ...@@ -328,16 +381,16 @@ protected slots:
pixmap.save(fileName, "png"); pixmap.save(fileName, "png");
label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName)); label->setWindowTitle(QString("Screenshot - Saved at %1").arg(fileName));
} }
} }
void setEditable(bool on) void LauncherWindow::setEditable(bool on)
{ {
view->page()->setContentEditable(on); view->page()->setContentEditable(on);
formatMenuAction->setVisible(on); formatMenuAction->setVisible(on);
} }
/* /*
void dumpPlugins() { void LauncherWindow::dumpPlugins() {
QList<QWebPluginInfo> plugins = QWebSettings::pluginDatabase()->plugins(); QList<QWebPluginInfo> plugins = QWebSettings::pluginDatabase()->plugins();
foreach (const QWebPluginInfo plugin, plugins) { foreach (const QWebPluginInfo plugin, plugins) {
qDebug() << "Plugin:" << plugin.name(); qDebug() << "Plugin:" << plugin.name();
...@@ -345,16 +398,16 @@ protected slots: ...@@ -345,16 +398,16 @@ protected slots:
qDebug() << " " << mime.name; qDebug() << " " << mime.name;
} }
} }
} }
*/ */
void dumpHtml() void LauncherWindow::dumpHtml()
{ {
qDebug() << "HTML: " << page()->mainFrame()->toHtml(); qDebug() << "HTML: " << page()->mainFrame()->toHtml();
} }
void selectElements() void LauncherWindow::selectElements()
{ {
bool ok; bool ok;
QString str = QInputDialog::getText(this, "Select elements", "Choose elements", QString str = QInputDialog::getText(this, "Select elements", "Choose elements",
QLineEdit::Normal, "a", &ok); QLineEdit::Normal, "a", &ok);
...@@ -367,31 +420,23 @@ protected slots: ...@@ -367,31 +420,23 @@ protected slots:
statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000); statusBar()->showMessage(QString("%1 element(s) selected").arg(result.count()), 5000);
#endif #endif
} }
} }
void setTouchMocking(bool on) void LauncherWindow::setTouchMocking(bool on)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0) #if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
touchMocking = on; touchMocking = on;
#endif #endif
} }
public slots:
void newWindow(const QString& url = QString()) void LauncherWindow::newWindow(const QString& url)
{ {
LauncherWindow* mw = new LauncherWindow(url); LauncherWindow* mw = new LauncherWindow(url);
mw->show(); mw->show();
} }
private:
QVector<int> zoomLevels;
int currentZoom;
// create the status bar, tool bar & menu void LauncherWindow::setupUI()
void setupUI() {
{
QMenu* fileMenu = menuBar()->addMenu("&File"); QMenu* fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New); fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New);
fileMenu->addAction(tr("Open File..."), this, SLOT(openFile()), QKeySequence::Open); fileMenu->addAction(tr("Open File..."), this, SLOT(openFile()), QKeySequence::Open);
...@@ -453,20 +498,7 @@ private: ...@@ -453,20 +498,7 @@ private:
touchMockAction->setCheckable(true); touchMockAction->setCheckable(true);
touchMockAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T)); touchMockAction->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T));
#endif #endif
} }
private:
QWebView* view;
WebInspector* inspector;
QAction* formatMenuAction;
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QList<QTouchEvent::TouchPoint> touchPoints;
bool touchMocking;
#endif
};
QWebPage* WebPage::createWindow(QWebPage::WebWindowType) QWebPage* WebPage::createWindow(QWebPage::WebWindowType)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment