Commit 66cccf23 authored by zoltan@webkit.org's avatar zoltan@webkit.org
Browse files

[Qt] Add simple zooming features to MiniBrowser

https://bugs.webkit.org/show_bug.cgi?id=53231

Reviewed by Andreas Kling.

Add View menu and Zoom In, Zoom Out, Zoom Reset actions to MiniBrowser.

* MiniBrowser/qt/BrowserWindow.cpp:
(BrowserWindow::BrowserWindow):
(BrowserWindow::zoomIn):
(BrowserWindow::zoomOut):
(BrowserWindow::resetZoom):
(BrowserWindow::updateUserAgentList):
(BrowserWindow::applyZoom):
* MiniBrowser/qt/BrowserWindow.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76778 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 542b6fc3
2011-01-27 Zoltan Horvath <zoltan@webkit.org>
Reviewed by Andreas Kling.
[Qt] Add simple zooming features to MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=53231
Add View menu and Zoom In, Zoom Out, Zoom Reset actions to MiniBrowser.
* MiniBrowser/qt/BrowserWindow.cpp:
(BrowserWindow::BrowserWindow):
(BrowserWindow::zoomIn):
(BrowserWindow::zoomOut):
(BrowserWindow::resetZoom):
(BrowserWindow::updateUserAgentList):
(BrowserWindow::applyZoom):
* MiniBrowser/qt/BrowserWindow.h:
2011-01-26 Maciej Stachowiak <mjs@apple.com>
 
Reviewed by Dan Bernstein.
......@@ -36,26 +36,41 @@ static QWKPage* newPageFunction(QWKPage* page)
QGraphicsWKView::BackingStoreType BrowserWindow::backingStoreTypeForNewWindow = QGraphicsWKView::Simple;
QVector<int> BrowserWindow::m_zoomLevels;
BrowserWindow::BrowserWindow(QWKContext* context)
: m_currentZoom(100) ,
m_browser(new BrowserView(backingStoreTypeForNewWindow, context))
{
setAttribute(Qt::WA_DeleteOnClose);
connect(m_browser->view(), SIGNAL(loadProgress(int)), SLOT(loadProgress(int)));
connect(m_browser->view(), SIGNAL(titleChanged(const QString&)), SLOT(titleChanged(const QString&)));
connect(m_browser->view(), SIGNAL(urlChanged(const QUrl&)), SLOT(urlChanged(const QUrl&)));
this->setCentralWidget(m_browser);
m_browser->setFocus(Qt::OtherFocusReason);
QMenu* fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction("New Window", this, SLOT(newWindow()), QKeySequence::New);
fileMenu->addAction("Open File", this, SLOT(openFile()), QKeySequence::Open);
fileMenu->addSeparator();
fileMenu->addAction("Quit", this, SLOT(close()));
QMenu* toolsMenu = menuBar()->addMenu("&Develop");
toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog()));
QMenu* viewMenu = menuBar()->addMenu("&View");
viewMenu->addAction(page()->action(QWKPage::Stop));
viewMenu->addAction(page()->action(QWKPage::Reload));
viewMenu->addSeparator();
QAction* zoomIn = viewMenu->addAction("Zoom &In", this, SLOT(zoomIn()));
QAction* zoomOut = viewMenu->addAction("Zoom &Out", this, SLOT(zoomOut()));
QAction* resetZoom = viewMenu->addAction("Reset Zoom", this, SLOT(resetZoom()));
m_browser = new BrowserView(backingStoreTypeForNewWindow, context);
connect(m_browser->view(), SIGNAL(loadProgress(int)), SLOT(loadProgress(int)));
connect(m_browser->view(), SIGNAL(titleChanged(const QString&)), SLOT(titleChanged(const QString&)));
connect(m_browser->view(), SIGNAL(urlChanged(const QUrl&)), SLOT(urlChanged(const QUrl&)));
zoomIn->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Plus));
zoomOut->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Minus));
resetZoom->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
this->setCentralWidget(m_browser);
m_browser->setFocus(Qt::OtherFocusReason);
QMenu* toolsMenu = menuBar()->addMenu("&Develop");
toolsMenu->addAction("Change User Agent", this, SLOT(showUserAgentDialog()));
m_addressBar = new QLineEdit();
connect(m_addressBar, SIGNAL(returnPressed()), SLOT(changeLocation()));
......@@ -72,6 +87,13 @@ BrowserWindow::BrowserWindow(QWKContext* context)
page()->setCreateNewPageFunction(newPageFunction);
// the zoom values are chosen to be like in Mozilla Firefox 3
if (!m_zoomLevels.count()) {
m_zoomLevels << 30 << 50 << 67 << 80 << 90;
m_zoomLevels << 100;
m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
}
resize(960, 640);
show();
}
......@@ -153,23 +175,30 @@ void BrowserWindow::openFile()
#endif
}
void BrowserWindow::updateUserAgentList()
void BrowserWindow::zoomIn()
{
QFile file(":/useragentlist.txt");
int i = m_zoomLevels.indexOf(m_currentZoom);
Q_ASSERT(i >= 0);
if (i < m_zoomLevels.count() - 1)
m_currentZoom = m_zoomLevels[i + 1];
if (file.open(QIODevice::ReadOnly)) {
while (!file.atEnd()) {
QString agent = file.readLine().trimmed();
if (!m_userAgentList.contains(agent))
m_userAgentList << agent;
}
file.close();
}
applyZoom();
}
Q_ASSERT(!m_userAgentList.isEmpty());
QWKPage* wkPage = page();
if (!(wkPage->customUserAgent().isEmpty() || m_userAgentList.contains(wkPage->customUserAgent())))
m_userAgentList << wkPage->customUserAgent();
void BrowserWindow::zoomOut()
{
int i = m_zoomLevels.indexOf(m_currentZoom);
Q_ASSERT(i >= 0);
if (i > 0)
m_currentZoom = m_zoomLevels[i - 1];
applyZoom();
}
void BrowserWindow::resetZoom()
{
m_currentZoom = 100;
applyZoom();
}
void BrowserWindow::showUserAgentDialog()
......@@ -201,6 +230,30 @@ void BrowserWindow::showUserAgentDialog()
page()->setCustomUserAgent(combo->currentText());
}
void BrowserWindow::updateUserAgentList()
{
QFile file(":/useragentlist.txt");
if (file.open(QIODevice::ReadOnly)) {
while (!file.atEnd()) {
QString agent = file.readLine().trimmed();
if (!m_userAgentList.contains(agent))
m_userAgentList << agent;
}
file.close();
}
Q_ASSERT(!m_userAgentList.isEmpty());
QWKPage* wkPage = page();
if (!(wkPage->customUserAgent().isEmpty() || m_userAgentList.contains(wkPage->customUserAgent())))
m_userAgentList << wkPage->customUserAgent();
}
void BrowserWindow::applyZoom()
{
page()->setPageZoomFactor(qreal(m_currentZoom) / 100.0);
}
BrowserWindow::~BrowserWindow()
{
delete m_addressBar;
......
......@@ -56,11 +56,21 @@ protected slots:
void titleChanged(const QString&);
void urlChanged(const QUrl&);
void openFile();
void zoomIn();
void zoomOut();
void resetZoom();
void showUserAgentDialog();
private:
void updateUserAgentList();
void applyZoom();
static QVector<int> m_zoomLevels;
int m_currentZoom;
BrowserView* m_browser;
QLineEdit* m_addressBar;
QStringList m_userAgentList;
......
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