Some work.

This commit is contained in:
Martin Rotter 2013-11-05 19:33:21 +01:00
parent dfd193b2de
commit 2feb05328f
7 changed files with 87 additions and 8 deletions

View file

@ -207,6 +207,23 @@ void BaseWebView::mouseReleaseEvent(QMouseEvent *event) {
QWebView::mouseReleaseEvent(event);
}
void BaseWebView::wheelEvent(QWheelEvent *event) {
if (event->modifiers() & Qt::ControlModifier) {
if (event->delta() > 0) {
increaseWebPageZoom();
emit zoomFactorChanged();
return;
}
else if (event->delta() < 0) {
decreaseWebPageZoom();
emit zoomFactorChanged();
return;
}
}
QWebView::wheelEvent(event);
}
void BaseWebView::paintEvent(QPaintEvent *event) {
QWebView::paintEvent(event);

View file

@ -26,6 +26,9 @@ class BaseWebView : public QWebView {
// User wants to open new empty web browser tab.
void newTabRequested();
// Emitted if user changes zoom factor via CTRL + mouse wheel combo.
void zoomFactorChanged();
public slots:
bool increaseWebPageZoom();
bool decreaseWebPageZoom();
@ -51,6 +54,9 @@ class BaseWebView : public QWebView {
// Displays custom error page.
void displayErrorPage();
// Customize mouse wheeling.
void wheelEvent(QWheelEvent *event);
// Does additional painting.
void paintEvent(QPaintEvent *event);

View file

@ -179,9 +179,13 @@ void FormMain::createConnections() {
void FormMain::loadWebBrowserMenu(int index) {
WebBrowser *active_browser = m_ui->m_tabWidget->widget(index)->webBrowser();
m_ui->m_menuWebBrowser->clear();
m_ui->m_menuCurrentTab->clear();
if (active_browser != NULL) {
m_ui->m_menuWebBrowser->addActions(active_browser->globalMenu());
m_ui->m_menuCurrentTab->addActions(active_browser->globalMenu());
if (m_ui->m_menuCurrentTab->actions().size() == 0) {
m_ui->m_menuCurrentTab->insertAction(NULL, m_ui->m_actionNoActions);
}
}
}

View file

@ -82,6 +82,16 @@
<property name="title">
<string>Web browser</string>
</property>
<widget class="QMenu" name="m_menuCurrentTab">
<property name="title">
<string>&amp;Current tab</string>
</property>
</widget>
<addaction name="m_actionAddBrowser"/>
<addaction name="m_actionCloseCurrentTab"/>
<addaction name="m_actionCloseAllTabs"/>
<addaction name="separator"/>
<addaction name="m_menuCurrentTab"/>
</widget>
<addaction name="m_menuFile"/>
<addaction name="m_menuView"/>
@ -141,6 +151,38 @@
<string notr="true">Ctrl+Shift+F</string>
</property>
</action>
<action name="m_actionAddBrowser">
<property name="text">
<string>&amp;Add tab</string>
</property>
<property name="toolTip">
<string>Add tab</string>
</property>
</action>
<action name="m_actionCloseAllTabs">
<property name="text">
<string>Close &amp;all tabs except current one</string>
</property>
<property name="toolTip">
<string>Close all tabs except current one</string>
</property>
</action>
<action name="m_actionCloseCurrentTab">
<property name="text">
<string>Close current &amp;tab</string>
</property>
</action>
<action name="m_actionNoActions">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;No actions possible</string>
</property>
<property name="toolTip">
<string>No actions are possible at this point of time.</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -13,6 +13,7 @@ LocationLineEdit::LocationLineEdit(QWidget *parent)
m_progress(0),
m_defaultPalette(palette()),
m_mouseSelectsAllText(true) {
setPlaceholderText(tr("Website address goes here"));
}
LocationLineEdit::~LocationLineEdit() {

View file

@ -133,6 +133,9 @@ 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.
connect(m_webView, SIGNAL(zoomFactorChanged()), this, SLOT(updateZoomGui()));
}
void WebBrowser::onIconChanged() {
@ -160,23 +163,25 @@ void WebBrowser::navigateToUrl(const QUrl &url) {
}
}
void WebBrowser::increaseZoom() {
m_webView->increaseWebPageZoom();
void WebBrowser::updateZoomGui() {
m_btnResetZoom->setText(QString("%1%").arg(QString::number(m_webView->zoomFactor() * 100,
'f',
0)));
}
void WebBrowser::increaseZoom() {
m_webView->increaseWebPageZoom();
updateZoomGui();
}
void WebBrowser::decreaseZoom() {
m_webView->decreaseWebPageZoom();
m_btnResetZoom->setText(QString("%1%").arg(QString::number(m_webView->zoomFactor() * 100,
'f',
0)));
updateZoomGui();
}
void WebBrowser::resetZoom() {
m_webView->resetWebPageZoom();
m_btnResetZoom->setText("100%");
updateZoomGui();
}
void WebBrowser::navigateToUrl(const QString &textual_url) {

View file

@ -65,6 +65,7 @@ class WebBrowser : public TabContent {
void resetZoom();
protected:
// Creates necessary connections.
void createConnections();
@ -72,6 +73,9 @@ class WebBrowser : public TabContent {
void initializeZoomWidget();
protected slots:
// Updates zoom-related gui.
void updateZoomGui();
// Updates url (for example on location text box).
void updateUrl(const QUrl &url);