Work on webbrowser.

This commit is contained in:
Martin Rotter 2013-08-05 21:31:41 +02:00
parent 61e0ff26db
commit 705811a401
17 changed files with 116 additions and 73 deletions

View File

@ -160,7 +160,7 @@ set(APP_SOURCES
# GUI sources.
src/gui/formmain.cpp
src/gui/systemtrayicon.cpp
src/gui/themefactory.cpp
src/gui/iconthemefactory.cpp
src/gui/formsettings.cpp
src/gui/formwelcome.cpp
src/gui/formabout.cpp
@ -202,7 +202,7 @@ set(APP_HEADERS
# GUI headers.
src/gui/formmain.h
src/gui/systemtrayicon.h
src/gui/themefactory.h
src/gui/iconthemefactory.h
src/gui/formsettings.h
src/gui/formwelcome.h
src/gui/formabout.h

View File

@ -6,7 +6,8 @@
#include "gui/webbrowser.h"
BaseWebPage::BaseWebPage(QObject *parent) : QWebPage(parent) {
BaseWebPage::BaseWebPage(QObject *parent)
: QWebPage(parent), m_openInNewTab(false) {
// Setup global network access manager.
// NOTE: This makes network settings easy for all web browsers.
setNetworkAccessManager(WebBrowser::globalNetworkManager());
@ -14,3 +15,7 @@ BaseWebPage::BaseWebPage(QObject *parent) : QWebPage(parent) {
BaseWebPage::~BaseWebPage() {
}
QWebPage *BaseWebPage::createWindow(WebWindowType type) {
return QWebPage::createWindow(type);
}

View File

@ -11,6 +11,14 @@ class BaseWebPage : public QWebPage {
// Constructors and destructors.
explicit BaseWebPage(QObject *parent = 0);
virtual ~BaseWebPage();
protected:
QWebPage *createWindow(WebWindowType type);
private:
friend class BaseWebView;
bool m_openInNewTab;
};
#endif // BASEWEBPAGE_H

View File

@ -8,7 +8,7 @@
#include "core/settings.h"
#include "core/basewebpage.h"
#include "gui/basewebview.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
BaseWebView::BaseWebView(QWidget *parent)
@ -38,10 +38,10 @@ void BaseWebView::createConnections() {
}
void BaseWebView::setupIcons() {
m_actionReload->setIcon(ThemeFactory::getInstance()->fromTheme("view-refresh"));
m_actionCopyLink->setIcon(ThemeFactory::getInstance()->fromTheme("edit-copy"));
m_actionCopyImage->setIcon(ThemeFactory::getInstance()->fromTheme("insert-image"));
m_actionCopyImageUrl->setIcon(ThemeFactory::getInstance()->fromTheme("edit-copy"));
m_actionReload->setIcon(IconThemeFactory::getInstance()->fromTheme("view-refresh"));
m_actionCopyLink->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy"));
m_actionCopyImage->setIcon(IconThemeFactory::getInstance()->fromTheme("insert-image"));
m_actionCopyImageUrl->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy"));
}
void BaseWebView::initializeActions() {
@ -56,17 +56,22 @@ void BaseWebView::initializeActions() {
m_actionCopyLink->setText(tr("Copy link url"));
m_actionCopyLink->setToolTip(tr("Copy link url to clipboard"));
m_actionCopyImage = pageAction(QWebPage::CopyImageToClipboard);
m_actionCopyImage->setParent(this);
m_actionCopyImage->setText(tr("Copy image"));
m_actionCopyImage->setToolTip(tr("Copy image to clipboard"));
m_actionCopyImageUrl = pageAction(QWebPage::CopyImageUrlToClipboard);
m_actionCopyImageUrl->setParent(this);
m_actionCopyImageUrl->setText(tr("Copy image url"));
m_actionCopyImageUrl->setToolTip(tr("Copy image url to clipboard"));
// TODO: Finish implementation of "open link in new tab"
// viz WebPage::createWindow in browser example.
m_actionOpenLinkNewTab = pageAction(QWebPage::OpenLinkInNewWindow);
m_actionOpenLinkNewTab->setParent(this);
m_actionOpenLinkNewTab->setText(tr("Open link in new tab"));
m_actionOpenLinkNewTab->setToolTip(tr("Open this hyperlink in new tab"));
}
void BaseWebView::displayErrorPage() {
@ -79,7 +84,7 @@ void BaseWebView::popupContextMenu(const QPoint &pos) {
QMenu image_submenu(tr("Image"), &context_menu);
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(pos);
image_submenu.setIcon(ThemeFactory::getInstance()->fromTheme("image-x-generic"));
image_submenu.setIcon(IconThemeFactory::getInstance()->fromTheme("image-x-generic"));
// Assemble the menu from actions.
context_menu.addAction(m_actionReload);

View File

@ -56,6 +56,7 @@ class BaseWebView : public QWebView {
QAction *m_actionCopyLink;
QAction *m_actionCopyImage;
QAction *m_actionCopyImageUrl;
QAction *m_actionOpenLinkNewTab;
QPoint m_gestureOrigin;
};

View File

@ -3,7 +3,7 @@
#include "core/datetime.h"
#include "gui/formabout.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout) {
@ -11,7 +11,7 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
// Set flags and attributes.
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
setWindowIcon(ThemeFactory::getInstance()->fromTheme("help-about"));
setWindowIcon(IconThemeFactory::getInstance()->fromTheme("help-about"));
m_ui->m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
// Load information from embedded text files.

View File

@ -5,7 +5,7 @@
#include "gui/formabout.h"
#include "gui/formsettings.h"
#include "gui/webbrowser.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "gui/systemtrayicon.h"
#include "gui/tabbar.h"
#include "core/settings.h"
@ -49,6 +49,10 @@ QMenu *FormMain::getTrayMenu() {
return m_trayMenu;
}
TabWidget *FormMain::getTabWidget() {
return m_ui->m_tabWidget;
}
QList<QAction*> FormMain::getActions() {
QList<QAction*> actions;
actions << m_ui->m_actionImport << m_ui->m_actionExport <<
@ -136,12 +140,12 @@ bool FormMain::event(QEvent *event) {
void FormMain::setupIcons() {
// Setup icons of this main window.
m_ui->m_actionSettings->setIcon(ThemeFactory::getInstance()->fromTheme("preferences-system"));
m_ui->m_actionQuit->setIcon(ThemeFactory::getInstance()->fromTheme("application-exit"));
m_ui->m_actionAboutGuard->setIcon(ThemeFactory::getInstance()->fromTheme("help-about"));
m_ui->m_actionImport->setIcon(ThemeFactory::getInstance()->fromTheme("document-import"));
m_ui->m_actionExport->setIcon(ThemeFactory::getInstance()->fromTheme("document-export"));
m_ui->m_actionFullscreen->setIcon(ThemeFactory::getInstance()->fromTheme("view-fullscreen"));
m_ui->m_actionSettings->setIcon(IconThemeFactory::getInstance()->fromTheme("preferences-system"));
m_ui->m_actionQuit->setIcon(IconThemeFactory::getInstance()->fromTheme("application-exit"));
m_ui->m_actionAboutGuard->setIcon(IconThemeFactory::getInstance()->fromTheme("help-about"));
m_ui->m_actionImport->setIcon(IconThemeFactory::getInstance()->fromTheme("document-import"));
m_ui->m_actionExport->setIcon(IconThemeFactory::getInstance()->fromTheme("document-export"));
m_ui->m_actionFullscreen->setIcon(IconThemeFactory::getInstance()->fromTheme("view-fullscreen"));
// Setup icons for underlying components: opened web browsers...
foreach (WebBrowser *browser, WebBrowser::runningWebBrowsers()) {

View File

@ -18,6 +18,8 @@ class FormMain : public QMainWindow {
// Returns menu for the tray icon.
QMenu *getTrayMenu();
TabWidget *getTabWidget();
// Returns list of all globally available actions.
// NOTE: This is used for setting dynamic shortcuts for given actions.
QList<QAction*> getActions();

View File

@ -4,7 +4,7 @@
#include <QColorDialog>
#include "gui/formsettings.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "gui/systemtrayicon.h"
#include "gui/formmain.h"
#include "gui/webbrowser.h"
@ -21,7 +21,7 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
// Set flags and attributes.
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
setWindowIcon(ThemeFactory::getInstance()->fromTheme("preferences-system"));
setWindowIcon(IconThemeFactory::getInstance()->fromTheme("preferences-system"));
// Setup behavior.
m_ui->m_treeLanguages->setColumnCount(5);
@ -117,6 +117,9 @@ void FormSettings::loadBrowser() {
m_ui->m_checkMouseGestures->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER,
"gestures_enabled",
true).toBool());
m_ui->m_checkQueueTabs->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER,
"queue_tabs",
true).toBool());
}
void FormSettings::saveBrowser() {
@ -130,6 +133,9 @@ void FormSettings::saveBrowser() {
Settings::getInstance()->setValue(APP_CFG_BROWSER,
"gestures_enabled",
m_ui->m_checkMouseGestures->isChecked());
Settings::getInstance()->setValue(APP_CFG_BROWSER,
"queue_tabs",
m_ui->m_checkQueueTabs->isChecked());
}
void FormSettings::loadProxy() {
@ -290,9 +296,9 @@ void FormSettings::loadInterface() {
}
// Load settings of icon theme.
QString current_theme = ThemeFactory::getInstance()->getCurrentIconTheme();
QString current_theme = IconThemeFactory::getInstance()->getCurrentIconTheme();
foreach (QString icon_theme_name, ThemeFactory::getInstance()->getInstalledIconThemes()) {
foreach (QString icon_theme_name, IconThemeFactory::getInstance()->getInstalledIconThemes()) {
if (icon_theme_name == APP_THEME_SYSTEM) {
#if defined(Q_OS_LINUX)
m_ui->m_cmbIconTheme->addItem(tr("system icon theme (default)"),
@ -349,7 +355,7 @@ void FormSettings::saveInterface() {
// Save selected icon theme.
QString selected_icon_theme = m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString();
ThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
// Save tab settings.
Settings::getInstance()->setValue(APP_CFG_GUI, "tab_close_mid_button",

View File

@ -327,7 +327,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkMouseGestures">
<property name="text">
<string>Enable mouse gestures</string>
@ -353,6 +353,13 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkQueueTabs">
<property name="text">
<string>Queue new tabs (with hyperlinks) after the active tab</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="m_btnBrowserProgressColor">
<property name="sizePolicy">

View File

@ -4,13 +4,13 @@
#include <QPointer>
#include <QApplication>
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "core/settings.h"
#include "core/defs.h"
QPointer<ThemeFactory> ThemeFactory::s_instance;
QPointer<IconThemeFactory> IconThemeFactory::s_instance;
QEvent::Type ThemeFactoryEvent::m_typeOfEvent = QEvent::None;
//
@ -36,45 +36,45 @@ QEvent::Type ThemeFactoryEvent::type() {
// ThemeFactory class
//
ThemeFactory::ThemeFactory(QObject *parent)
IconThemeFactory::IconThemeFactory(QObject *parent)
: QObject(parent), m_currentIconTheme(APP_THEME_SYSTEM) {
}
ThemeFactory::~ThemeFactory() {
IconThemeFactory::~IconThemeFactory() {
qDebug("Destroying ThemeFactory instance.");
}
ThemeFactory *ThemeFactory::getInstance() {
IconThemeFactory *IconThemeFactory::getInstance() {
if (s_instance.isNull()) {
s_instance = new ThemeFactory(qApp);
s_instance = new IconThemeFactory(qApp);
}
return s_instance;
}
void ThemeFactory::setupSearchPaths() {
void IconThemeFactory::setupSearchPaths() {
// Add custom icon theme path to existing ones.
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << APP_THEME_PATH);
qDebug("Available icon theme paths: %s.",
qPrintable(QIcon::themeSearchPaths().join(", ")));
}
QString ThemeFactory::getCurrentIconTheme() {
QString IconThemeFactory::getCurrentIconTheme() {
return m_currentIconTheme;
}
QIcon ThemeFactory::fromTheme(const QString &name, const QIcon &fallback) {
QIcon IconThemeFactory::fromTheme(const QString &name, const QIcon &fallback) {
return QIcon::fromTheme(name, fallback);
}
void ThemeFactory::setCurrentIconTheme(const QString &theme_name) {
void IconThemeFactory::setCurrentIconTheme(const QString &theme_name) {
Settings::getInstance()->setValue(APP_CFG_GUI,
"icon_theme",
theme_name);
loadCurrentIconTheme(true);
}
void ThemeFactory::loadCurrentIconTheme(bool notify_widgets) {
void IconThemeFactory::loadCurrentIconTheme(bool notify_widgets) {
QStringList installed_themes = getInstalledIconThemes();
QString theme_name_from_settings = Settings::getInstance()->value(APP_CFG_GUI,
"icon_theme",
@ -113,7 +113,7 @@ void ThemeFactory::loadCurrentIconTheme(bool notify_widgets) {
}
}
QStringList ThemeFactory::getInstalledIconThemes() {
QStringList IconThemeFactory::getInstalledIconThemes() {
QStringList icon_theme_names;
icon_theme_names << APP_THEME_SYSTEM;

View File

@ -6,12 +6,12 @@
#include <QIcon>
class ThemeFactory : public QObject {
class IconThemeFactory : public QObject {
Q_OBJECT
public:
// Singleton getter.
static ThemeFactory *getInstance();
static IconThemeFactory *getInstance();
// Wrapper for QIcon::fromTheme.
// TODO: If icon is not found in user-defined icon theme,
@ -41,14 +41,14 @@ class ThemeFactory : public QObject {
private:
// Constructors and destructors
explicit ThemeFactory(QObject *parent = 0);
virtual ~ThemeFactory();
explicit IconThemeFactory(QObject *parent = 0);
virtual ~IconThemeFactory();
// Holds name of the current icon theme.
QString m_currentIconTheme;
// Singleton.
static QPointer<ThemeFactory> s_instance;
static QPointer<IconThemeFactory> s_instance;
};
class ThemeFactoryEvent : public QEvent {

View File

@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "gui/shortcutcatcher.h"
#include "gui/shortcutbutton.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
ShortcutCatcher::ShortcutCatcher(QWidget *parent)
@ -43,7 +43,7 @@ ShortcutCatcher::ShortcutCatcher(QWidget *parent)
// Create clear button.
m_clearButton = new QToolButton(this);
m_clearButton->setIcon(ThemeFactory::getInstance()->fromTheme("document-revert"));
m_clearButton->setIcon(IconThemeFactory::getInstance()->fromTheme("document-revert"));
m_clearButton->setFocusPolicy(Qt::NoFocus);
// Clear main shortcut catching button.

View File

@ -2,9 +2,10 @@
#include <QApplication>
#include "core/defs.h"
#include "core/settings.h"
#include "gui/tabwidget.h"
#include "gui/tabbar.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "gui/webbrowser.h"
@ -47,7 +48,7 @@ void TabWidget::setupIcons() {
for (int index = 0; index < count(); index++) {
// Index 0 usually contains widget which displays feeds & messages.
if (tabBar()->tabType(index) == TabBar::FeedReader) {
setTabIcon(index, ThemeFactory::getInstance()->fromTheme("application-rss+xml"));
setTabIcon(index, IconThemeFactory::getInstance()->fromTheme("application-rss+xml"));
}
// Other indexes probably contain WebBrowsers.
else {
@ -55,7 +56,7 @@ void TabWidget::setupIcons() {
if (active_browser != nullptr && active_browser->icon().isNull()) {
// We found WebBrowser instance of this tab page, which
// has no suitable icon, load a new one from the icon theme.
setTabIcon(index, ThemeFactory::getInstance()->fromTheme("text-html"));
setTabIcon(index, IconThemeFactory::getInstance()->fromTheme("text-html"));
}
}
}
@ -101,21 +102,25 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label,
return tab_index;
}
void TabWidget::addEmptyBrowser() {
int TabWidget::addEmptyBrowser() {
// TODO: Add reading of move_after_current and make_active
// flags from settings.
addBrowser(false, true);
return addBrowser(false, true);
}
void TabWidget::addLinkedBrowser(const QUrl &initial_url) {
int TabWidget::addLinkedBrowser(const QUrl &initial_url) {
// TODO: Add reading of move_after_current and make_active
// flags from settings.
addBrowser(true, false, initial_url);
return addBrowser(Settings::getInstance()->value(APP_CFG_BROWSER,
"queue_tabs",
true).toBool(),
false,
initial_url);
}
void TabWidget::addBrowser(bool move_after_current,
bool make_active,
const QUrl &initial_url) {
int TabWidget::addBrowser(bool move_after_current,
bool make_active,
const QUrl &initial_url) {
// Create new WebBrowser.
WebBrowser *browser = new WebBrowser(this);
int final_index;
@ -124,17 +129,16 @@ void TabWidget::addBrowser(bool move_after_current,
// Insert web browser after current tab.
final_index = insertTab(currentIndex() + 1,
browser,
ThemeFactory::getInstance()->fromTheme("text-html"),
IconThemeFactory::getInstance()->fromTheme("text-html"),
tr("Web browser"),
TabBar::Closable);
}
else {
// Add new browser as the last tab.
final_index = addTab(browser,
ThemeFactory::getInstance()->fromTheme("text-html"),
IconThemeFactory::getInstance()->fromTheme("text-html"),
tr("Web browser"),
TabBar::Closable);
browser->setFocus(Qt::OtherFocusReason);
}
// Load initial web page if desired.
@ -145,5 +149,8 @@ void TabWidget::addBrowser(bool move_after_current,
// Make new web browser active if desired.
if (make_active) {
setCurrentIndex(final_index);
browser->setFocus(Qt::OtherFocusReason);
}
return final_index;
}

View File

@ -46,14 +46,14 @@ class TabWidget : public QTabWidget {
void closeTab(int index);
// Adds new WebBrowser tab to global TabWidget.
void addEmptyBrowser();
int addEmptyBrowser();
// Adds new WebBrowser with link. This is used when user
// selects to "Open link in new tab.".
void addLinkedBrowser(const QUrl &initial_url);
int addLinkedBrowser(const QUrl &initial_url);
// General method for adding WebBrowsers.
void addBrowser(bool move_after_current,
int addBrowser(bool move_after_current,
bool make_active,
const QUrl &initial_url = QUrl());
};

View File

@ -12,7 +12,7 @@
#include "gui/basewebview.h"
#include "gui/webbrowser.h"
#include "gui/locationlineedit.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "gui/tabwidget.h"
@ -80,16 +80,14 @@ void WebBrowser::createConnections() {
this, &WebBrowser::updateUrl);
// Connect this WebBrowser to global TabWidget.
// TODO: Přemýšlet nad tím, zda toto navázání spojení
// nepředělat například do TabWidget::AddBrowser a ty signály
// z m_webView tedy neforwardovat z WebBrowseru.
// TODO: Think over moving this connections from here to
// e.g. TabWidget::addBrowser.
TabWidget *parent_widget = static_cast<TabWidget*>(parent());
connect(m_webView, &BaseWebView::newTabRequested,
parent_widget, &TabWidget::addEmptyBrowser);
connect(m_webView, &BaseWebView::linkMiddleClicked,
parent_widget, &TabWidget::addLinkedBrowser);
// Change location textbox status according to webpage status.
connect(m_webView, &BaseWebView::loadProgress,
m_txtLocation, &LocationLineEdit::setProgress);
@ -138,10 +136,10 @@ void WebBrowser::setFocus(Qt::FocusReason reason) {
}
void WebBrowser::setupIcons() {
m_actionBack->setIcon(ThemeFactory::getInstance()->fromTheme("go-previous"));
m_actionForward->setIcon(ThemeFactory::getInstance()->fromTheme("go-next"));
m_actionReload->setIcon(ThemeFactory::getInstance()->fromTheme("view-refresh"));
m_actionStop->setIcon(ThemeFactory::getInstance()->fromTheme("process-stop"));
m_actionBack->setIcon(IconThemeFactory::getInstance()->fromTheme("go-previous"));
m_actionForward->setIcon(IconThemeFactory::getInstance()->fromTheme("go-next"));
m_actionReload->setIcon(IconThemeFactory::getInstance()->fromTheme("view-refresh"));
m_actionStop->setIcon(IconThemeFactory::getInstance()->fromTheme("process-stop"));
m_webView->setupIcons();
}

View File

@ -10,7 +10,7 @@
#include "core/localization.h"
#include "core/settings.h"
#include "core/dynamicshortcuts.h"
#include "gui/themefactory.h"
#include "gui/iconthemefactory.h"
#include "gui/formmain.h"
#include "gui/formwelcome.h"
#include "gui/systemtrayicon.h"
@ -63,8 +63,8 @@ int main(int argc, char *argv[]) {
#endif
// Add an extra path for non-system icon themes and set current icon theme.
ThemeFactory::getInstance()->setupSearchPaths();
ThemeFactory::getInstance()->loadCurrentIconTheme(false);
IconThemeFactory::getInstance()->setupSearchPaths();
IconThemeFactory::getInstance()->loadCurrentIconTheme(false);
// Load localization and setup locale before any widget is constructed.
LoadLocalization();