mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 02:37:46 +01:00
Color changing for all tabs.
This commit is contained in:
parent
b8d8e6065d
commit
5ee4c611a1
@ -109,12 +109,19 @@ void BaseWebView::mousePressEvent(QMouseEvent *event) {
|
||||
|
||||
// Check if user clicked with middle mouse button on some
|
||||
// hyperlink.
|
||||
if (hit_result.linkUrl().isValid()) {
|
||||
emit linkMiddleClicked(hit_result.linkUrl());
|
||||
QUrl link_url = hit_result.linkUrl();
|
||||
QUrl image_url = hit_result.imageUrl();
|
||||
|
||||
if (link_url.isValid()) {
|
||||
emit linkMiddleClicked(link_url);
|
||||
|
||||
// No more handling of event is now needed. Return.
|
||||
return;
|
||||
}
|
||||
else if (image_url.isValid()) {
|
||||
emit linkMiddleClicked(image_url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (event->button() & Qt::RightButton) {
|
||||
m_gestureOrigin = event->pos();
|
||||
|
@ -17,7 +17,7 @@ class TabContent : public QWidget {
|
||||
virtual int index() const;
|
||||
virtual void setIndex(int index);
|
||||
|
||||
// Obtains instance contained in this TabContent.
|
||||
// Obtains instance contained in this TabContent or nullptr.
|
||||
// This is used for obtaining the menu from the instance and so on.
|
||||
virtual WebBrowser *webBrowser() = 0;
|
||||
|
||||
|
@ -39,13 +39,27 @@ void TabWidget::initializeTabs() {
|
||||
setTabToolTip(index_of_browser, tr("Browse your feeds and messages"));
|
||||
}
|
||||
|
||||
TabContent *TabWidget::contentAt(int index) {
|
||||
return static_cast<TabContent*>(widget(index));
|
||||
}
|
||||
|
||||
void TabWidget::setupIcons() {
|
||||
// Find tab, which contains "Feeds" page and reload its icon.
|
||||
// Iterate through all tabs and update icons
|
||||
// accordingly.
|
||||
for (int index = 0; index < count(); index++) {
|
||||
if (tabBar()->tabType(index) == TabBar::FeedReader) {
|
||||
setTabIcon(index, ThemeFactory::getInstance()->fromTheme("application-rss+xml"));
|
||||
}
|
||||
// TODO: Add changing of tab icons for webbrowser tabs.
|
||||
else {
|
||||
WebBrowser *active_browser = contentAt(index)->webBrowser();
|
||||
if (active_browser != nullptr) {
|
||||
// We found WebBrowser instance of this tab page.
|
||||
if (active_browser->icon().isNull()) {
|
||||
// WebBrowser has no suitable icon, load new from icon theme.
|
||||
setTabIcon(index, ThemeFactory::getInstance()->fromTheme("text-html"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,8 +107,8 @@ void TabWidget::addEmptyBrowser() {
|
||||
addBrowser(false, true);
|
||||
}
|
||||
|
||||
void TabWidget::addLinkedBrowser() {
|
||||
|
||||
void TabWidget::addLinkedBrowser(const QUrl &initial_url) {
|
||||
addBrowser(true, false, initial_url);
|
||||
}
|
||||
|
||||
void TabWidget::addBrowser(bool move_after_current,
|
||||
|
@ -28,6 +28,7 @@ class TabWidget : public QTabWidget {
|
||||
|
||||
// Returns tab bar.
|
||||
TabBar *tabBar();
|
||||
TabContent *contentAt(int index);
|
||||
|
||||
void initializeTabs();
|
||||
void setupIcons();
|
||||
@ -45,7 +46,7 @@ class TabWidget : public QTabWidget {
|
||||
|
||||
// Adds new WebBrowser with link. This is used when user
|
||||
// selects to "Open link in new tab.".
|
||||
void addLinkedBrowser();
|
||||
void addLinkedBrowser(const QUrl &initial_url);
|
||||
|
||||
// General method for adding WebBrowsers.
|
||||
void addBrowser(bool move_after_current,
|
||||
|
@ -13,12 +13,13 @@
|
||||
#include "gui/webbrowser.h"
|
||||
#include "gui/locationlineedit.h"
|
||||
#include "gui/themefactory.h"
|
||||
#include "gui/tabwidget.h"
|
||||
|
||||
|
||||
QPointer<WebBrowserNetworkAccessManager> WebBrowser::m_networkManager;
|
||||
QList<WebBrowser*> WebBrowser::m_runningWebBrowsers;
|
||||
|
||||
WebBrowser::WebBrowser(QWidget *parent)
|
||||
WebBrowser::WebBrowser(TabWidget *parent)
|
||||
: TabContent(parent), m_layout(new QVBoxLayout(this)),
|
||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||
m_webView(new BaseWebView(this)),
|
||||
@ -61,6 +62,9 @@ WebBrowser::WebBrowser(QWidget *parent)
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setContentsMargins(0, -1, 0, 0);
|
||||
|
||||
setTabOrder(m_txtLocation, m_toolBar);
|
||||
setTabOrder(m_toolBar, m_webView);
|
||||
|
||||
createConnections();
|
||||
setupIcons();
|
||||
}
|
||||
@ -75,9 +79,13 @@ void WebBrowser::createConnections() {
|
||||
connect(m_webView, &BaseWebView::urlChanged,
|
||||
this, &WebBrowser::updateUrl);
|
||||
|
||||
// Signal forwarding.
|
||||
// Connect this WebBrowser to global TabWidget.
|
||||
TabWidget *parent_widget = static_cast<TabWidget*>(parent());
|
||||
connect(m_webView, &BaseWebView::newTabRequested,
|
||||
this, &WebBrowser::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,
|
||||
@ -118,6 +126,10 @@ QMenu *WebBrowser::globalMenu() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QIcon WebBrowser::icon() {
|
||||
return m_webView->icon();
|
||||
}
|
||||
|
||||
void WebBrowser::setupIcons() {
|
||||
m_actionBack->setIcon(ThemeFactory::getInstance()->fromTheme("go-previous"));
|
||||
m_actionForward->setIcon(ThemeFactory::getInstance()->fromTheme("go-next"));
|
||||
|
@ -12,18 +12,22 @@ class LocationLineEdit;
|
||||
class BaseWebView;
|
||||
class WebBrowserNetworkAccessManager;
|
||||
class QMenu;
|
||||
class TabWidget;
|
||||
|
||||
class WebBrowser : public TabContent {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
explicit WebBrowser(QWidget *parent = 0);
|
||||
explicit WebBrowser(TabWidget *parent = 0);
|
||||
~WebBrowser();
|
||||
|
||||
// Reloads icons for all buttons.
|
||||
void setupIcons();
|
||||
|
||||
// Returns icon associated with currently loaded website.
|
||||
QIcon icon();
|
||||
|
||||
// Returns this instance.
|
||||
// NOTE: This is needed due to TabContent interface.
|
||||
WebBrowser *webBrowser();
|
||||
@ -58,6 +62,8 @@ class WebBrowser : public TabContent {
|
||||
|
||||
signals:
|
||||
void newTabRequested();
|
||||
void linkMiddleClicked(const QUrl &link_url);
|
||||
void iconChanged(int index, const QIcon &icon);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
|
Loading…
x
Reference in New Issue
Block a user