Work on zoom.
This commit is contained in:
parent
6aacfcf359
commit
1a3c56a332
Binary file not shown.
Before Width: | Height: | Size: 42 B After Width: | Height: | Size: 1.3 KiB |
@ -44,8 +44,7 @@ void BaseWebView::createConnections() {
|
|||||||
this, SLOT(popupContextMenu(QPoint)));
|
this, SLOT(popupContextMenu(QPoint)));
|
||||||
|
|
||||||
connect(m_actionOpenLinkNewTab,SIGNAL(triggered()), this, SLOT(openLinkInNewTab()));
|
connect(m_actionOpenLinkNewTab,SIGNAL(triggered()), this, SLOT(openLinkInNewTab()));
|
||||||
connect(m_actionOpenImageNewTab, SIGNAL(triggered()),
|
connect(m_actionOpenImageNewTab, SIGNAL(triggered()), this, SLOT(openImageInNewTab()));
|
||||||
this, SLOT(openImageInNewTab()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWebView::setupIcons() {
|
void BaseWebView::setupIcons() {
|
||||||
@ -220,6 +219,14 @@ void BaseWebView::paintEvent(QPaintEvent *event) {
|
|||||||
style()->drawControl(QStyle::CE_ShapedFrame, &style_option, &painter, this);
|
style()->drawControl(QStyle::CE_ShapedFrame, &style_option, &painter, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWebView::setWebPageZoom(int percentage) {
|
void BaseWebView::increaseWebPageZoom() {
|
||||||
setZoomFactor(percentage / 100.0);
|
setZoomFactor(zoomFactor() + 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWebView::decreaseWebPageZoom() {
|
||||||
|
setZoomFactor(zoomFactor() - 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWebView::resetWebPageZoom() {
|
||||||
|
setZoomFactor(1.0);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,9 @@ class BaseWebView : public QWebView {
|
|||||||
void newTabRequested();
|
void newTabRequested();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setWebPageZoom(int percentage = 150);
|
void increaseWebPageZoom();
|
||||||
|
void decreaseWebPageZoom();
|
||||||
|
void resetWebPageZoom();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Executes if loading of any page is done.
|
// Executes if loading of any page is done.
|
||||||
|
@ -75,9 +75,42 @@ WebBrowser::WebBrowser(QWidget *parent)
|
|||||||
setTabOrder(m_toolBar, m_webView);
|
setTabOrder(m_toolBar, m_webView);
|
||||||
|
|
||||||
createConnections();
|
createConnections();
|
||||||
|
initializeZoomWidget();
|
||||||
setupIcons();
|
setupIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowser::initializeZoomWidget() {
|
||||||
|
// Initializations.
|
||||||
|
m_zoomButtons = new QWidget(this);
|
||||||
|
QLabel *zoom_label = new QLabel(tr("Zoom "), m_zoomButtons);
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(m_zoomButtons);
|
||||||
|
QToolButton *button_decrease = new QToolButton(m_zoomButtons);
|
||||||
|
m_btnResetZoom = new QToolButton(m_zoomButtons);
|
||||||
|
QToolButton *button_increase = new QToolButton(m_zoomButtons);
|
||||||
|
|
||||||
|
// Set texts.
|
||||||
|
button_decrease->setText("-");
|
||||||
|
m_btnResetZoom->setText("100%");
|
||||||
|
button_increase->setText("+");
|
||||||
|
|
||||||
|
// Setup layout.
|
||||||
|
layout->addWidget(zoom_label);
|
||||||
|
layout->addWidget(button_decrease);
|
||||||
|
layout->addWidget(m_btnResetZoom);
|
||||||
|
layout->addWidget(button_increase);
|
||||||
|
layout->setSpacing(2);
|
||||||
|
layout->setMargin(3);
|
||||||
|
m_zoomButtons->setLayout(layout);
|
||||||
|
|
||||||
|
// Make connections..
|
||||||
|
connect(button_increase, SIGNAL(clicked()), this, SLOT(increaseZoom()));
|
||||||
|
connect(button_decrease, SIGNAL(clicked()), this, SLOT(decreaseZoom()));
|
||||||
|
connect(m_btnResetZoom, SIGNAL(clicked()), this, SLOT(resetZoom()));
|
||||||
|
|
||||||
|
m_actionZoom = new QWidgetAction(this);
|
||||||
|
m_actionZoom->setDefaultWidget(m_zoomButtons);
|
||||||
|
}
|
||||||
|
|
||||||
void WebBrowser::createConnections() {
|
void WebBrowser::createConnections() {
|
||||||
// When user confirms new url, then redirect to it.
|
// When user confirms new url, then redirect to it.
|
||||||
connect(m_txtLocation,SIGNAL(submitted(QString)),
|
connect(m_txtLocation,SIGNAL(submitted(QString)),
|
||||||
@ -127,6 +160,25 @@ void WebBrowser::navigateToUrl(const QUrl &url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowser::increaseZoom() {
|
||||||
|
m_webView->increaseWebPageZoom();
|
||||||
|
m_btnResetZoom->setText(
|
||||||
|
QString("%1%").arg(QString::number(m_webView->zoomFactor() * 100, 'f', 0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::decreaseZoom() {
|
||||||
|
m_webView->decreaseWebPageZoom();
|
||||||
|
m_btnResetZoom->setText(
|
||||||
|
QString("%1%").arg(QString::number(m_webView->zoomFactor() * 100, 'f', 0))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebBrowser::resetZoom() {
|
||||||
|
m_webView->resetWebPageZoom();
|
||||||
|
m_btnResetZoom->setText("100%");
|
||||||
|
}
|
||||||
|
|
||||||
void WebBrowser::navigateToUrl(const QString &textual_url) {
|
void WebBrowser::navigateToUrl(const QString &textual_url) {
|
||||||
// Prepare input url.
|
// Prepare input url.
|
||||||
QString better_url = textual_url;
|
QString better_url = textual_url;
|
||||||
@ -143,6 +195,8 @@ WebBrowser::~WebBrowser() {
|
|||||||
|
|
||||||
// Delete members.
|
// Delete members.
|
||||||
delete m_layout;
|
delete m_layout;
|
||||||
|
delete m_zoomButtons;
|
||||||
|
delete m_actionZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebBrowser *WebBrowser::webBrowser() {
|
WebBrowser *WebBrowser::webBrowser() {
|
||||||
@ -153,33 +207,7 @@ QList<QAction *> WebBrowser::globalMenu() {
|
|||||||
QList<QAction*> browser_menu;
|
QList<QAction*> browser_menu;
|
||||||
|
|
||||||
// Add needed actions into the menu.
|
// Add needed actions into the menu.
|
||||||
browser_menu.append(m_actionReload);
|
browser_menu.append(m_actionZoom);
|
||||||
|
|
||||||
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;
|
return browser_menu;
|
||||||
}
|
}
|
||||||
@ -193,6 +221,7 @@ void WebBrowser::setFocus(Qt::FocusReason reason) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::setupIcons() {
|
void WebBrowser::setupIcons() {
|
||||||
|
m_actionZoom->setIcon(IconThemeFactory::getInstance()->fromTheme("zoom-fit-best"));
|
||||||
m_actionBack->setIcon(IconThemeFactory::getInstance()->fromTheme("go-previous"));
|
m_actionBack->setIcon(IconThemeFactory::getInstance()->fromTheme("go-previous"));
|
||||||
m_actionForward->setIcon(IconThemeFactory::getInstance()->fromTheme("go-next"));
|
m_actionForward->setIcon(IconThemeFactory::getInstance()->fromTheme("go-next"));
|
||||||
m_actionReload->setIcon(IconThemeFactory::getInstance()->fromTheme("view-refresh"));
|
m_actionReload->setIcon(IconThemeFactory::getInstance()->fromTheme("view-refresh"));
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
|
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
|
class QToolButton;
|
||||||
|
class QWidgetAction;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class LocationLineEdit;
|
class LocationLineEdit;
|
||||||
class BaseWebView;
|
class BaseWebView;
|
||||||
@ -57,10 +59,18 @@ class WebBrowser : public TabContent {
|
|||||||
void navigateToUrl(const QString &url);
|
void navigateToUrl(const QString &url);
|
||||||
void navigateToUrl(const QUrl &url);
|
void navigateToUrl(const QUrl &url);
|
||||||
|
|
||||||
|
// Zoom manipulators.
|
||||||
|
void increaseZoom();
|
||||||
|
void decreaseZoom();
|
||||||
|
void resetZoom();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Creates necessary connections.
|
// Creates necessary connections.
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
||||||
|
// Initializes all buttons and widgets, which are needed for "Zoom" menu item.
|
||||||
|
void initializeZoomWidget();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Updates url (for example on location text box).
|
// Updates url (for example on location text box).
|
||||||
void updateUrl(const QUrl &url);
|
void updateUrl(const QUrl &url);
|
||||||
@ -80,7 +90,10 @@ class WebBrowser : public TabContent {
|
|||||||
QToolBar *m_toolBar;
|
QToolBar *m_toolBar;
|
||||||
BaseWebView *m_webView;
|
BaseWebView *m_webView;
|
||||||
LocationLineEdit *m_txtLocation;
|
LocationLineEdit *m_txtLocation;
|
||||||
|
QWidget *m_zoomButtons;
|
||||||
|
QToolButton *m_btnResetZoom;
|
||||||
|
|
||||||
|
QWidgetAction *m_actionZoom;
|
||||||
QAction *m_actionBack;
|
QAction *m_actionBack;
|
||||||
QAction *m_actionForward;
|
QAction *m_actionForward;
|
||||||
QAction *m_actionReload;
|
QAction *m_actionReload;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user