Work on zooming.

This commit is contained in:
Martin Rotter 2013-09-28 09:49:43 +02:00
parent d981a767ae
commit 6aacfcf359
5 changed files with 50 additions and 7 deletions

View File

@ -219,3 +219,7 @@ void BaseWebView::paintEvent(QPaintEvent *event) {
style()->drawControl(QStyle::CE_ShapedFrame, &style_option, &painter, this);
}
void BaseWebView::setWebPageZoom(int percentage) {
setZoomFactor(percentage / 100.0);
}

View File

@ -26,6 +26,9 @@ class BaseWebView : public QWebView {
// User wants to open new empty web browser tab.
void newTabRequested();
public slots:
void setWebPageZoom(int percentage = 150);
protected slots:
// Executes if loading of any page is done.
void onLoadFinished(bool ok);

View File

@ -176,12 +176,13 @@ int TabWidget::addBrowser(bool move_after_current,
return final_index;
}
void TabWidget::changeIcon(int column, const QIcon &new_icon) {
setTabIcon(column, new_icon);
void TabWidget::changeIcon(int index, const QIcon &new_icon) {
setTabIcon(index, new_icon);
}
void TabWidget::changeTitle(int column, const QString &new_title) {
setTabText(column, TextFactory::shorten(new_title));
void TabWidget::changeTitle(int index, const QString &new_title) {
setTabText(index, TextFactory::shorten(new_title));
setTabToolTip(index, new_title);
}
void TabWidget::fixContentAfterIndexChange(int from) {

View File

@ -55,8 +55,8 @@ class TabWidget : public QTabWidget {
void fixContentsIndexes(int starting_index, int ending_index);
// Changes icon/text of the tab.
void changeTitle(int column, const QString &new_title);
void changeIcon(int column, const QIcon &new_icon);
void changeTitle(int index, const QString &new_title);
void changeIcon(int index, const QIcon &new_icon);
// Closes tab with given index and deletes contained widget.
void closeTab(int index);

View File

@ -3,8 +3,13 @@
#include <QAction>
#include <QPointer>
#include <QApplication>
#include <QWebFrame>
#include <QWidgetAction>
#include <QSlider>
#include <QLabel>
#include <QMessageBox>
#include <QToolButton>
#include "core/basenetworkaccessmanager.h"
#include "core/webbrowsernetworkaccessmanager.h"
@ -21,7 +26,8 @@ QPointer<WebBrowserNetworkAccessManager> WebBrowser::m_networkManager;
QList<WebBrowser*> WebBrowser::m_runningWebBrowsers;
WebBrowser::WebBrowser(QWidget *parent)
: TabContent(parent), m_layout(new QVBoxLayout(this)),
: TabContent(parent),
m_layout(new QVBoxLayout(this)),
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
m_webView(new BaseWebView(this)),
m_txtLocation(new LocationLineEdit(this)),
@ -92,6 +98,8 @@ void WebBrowser::createConnections() {
// Forward title/icon changes.
connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)));
connect(m_webView, SIGNAL(iconChanged()), this, SLOT(onIconChanged()));
// Misc connections.
}
void WebBrowser::onIconChanged() {
@ -144,8 +152,35 @@ WebBrowser *WebBrowser::webBrowser() {
QList<QAction *> WebBrowser::globalMenu() {
QList<QAction*> browser_menu;
// Add needed actions into the menu.
browser_menu.append(m_actionReload);
QWidget *wid = new QWidget(this);
QHBoxLayout *lay = new QHBoxLayout(wid);
QToolButton *but1 = new QToolButton(wid);
but1->setText("-");
QToolButton *but2 = new QToolButton(wid);
but2->setText("100%");
QToolButton *but3 = new QToolButton(wid);
but3->setText("+");
lay->addWidget(new QLabel("Zoom ", wid));
lay->addWidget(but1);
lay->addWidget(but2);
lay->addWidget(but3);
lay->setSpacing(2);
lay->setMargin(3);
wid->setLayout(lay);
// TODO: Make zooming better written, it looks good, impelement
// just webpage zoom (no text zoom for now), then move to implementing
// feed core.
connect(but3, SIGNAL(clicked()), m_webView, SLOT(setWebPageZoom()));
QWidgetAction *act = new QWidgetAction(this);
act->setDefaultWidget(wid);
browser_menu.append(act);
return browser_menu;
}