mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 02:37:46 +01:00
WebBrowser management moved to TabWidget.
This commit is contained in:
parent
5afdb205d8
commit
b8d8e6065d
@ -60,48 +60,6 @@ QList<QAction*> FormMain::getActions() {
|
|||||||
void FormMain::prepareTabs() {
|
void FormMain::prepareTabs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::addEmptyBrowser() {
|
|
||||||
addBrowser(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormMain::addLinkedBrowser() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormMain::addBrowser(bool move_after_current,
|
|
||||||
bool make_active,
|
|
||||||
const QUrl &initial_url) {
|
|
||||||
// Create new WebBrowser.
|
|
||||||
WebBrowser *browser = new WebBrowser(m_ui->m_tabWidget);
|
|
||||||
int final_index;
|
|
||||||
|
|
||||||
if (move_after_current) {
|
|
||||||
// Insert web browser after current tab.
|
|
||||||
final_index = m_ui->m_tabWidget->insertTab(m_ui->m_tabWidget->currentIndex() + 1,
|
|
||||||
browser,
|
|
||||||
QIcon(),
|
|
||||||
tr("Web browser"),
|
|
||||||
TabBar::Closable);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Add new browser as the last tab.
|
|
||||||
final_index = m_ui->m_tabWidget->addTab(browser,
|
|
||||||
QIcon(),
|
|
||||||
tr("Web browser"),
|
|
||||||
TabBar::Closable);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load initial web page if desired.
|
|
||||||
if (initial_url.isValid()) {
|
|
||||||
browser->navigateToUrl(initial_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make new web browser active if desired.
|
|
||||||
if (make_active) {
|
|
||||||
m_ui->m_tabWidget->setCurrentIndex(final_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormMain::prepareMenus() {
|
void FormMain::prepareMenus() {
|
||||||
// Setup menu for tray icon.
|
// Setup menu for tray icon.
|
||||||
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
if (SystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
@ -190,13 +148,7 @@ void FormMain::setupIcons() {
|
|||||||
browser->setupIcons();
|
browser->setupIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find tab, which contains "Feeds" page and reload its icon.
|
m_ui->m_tabWidget->setupIcons();
|
||||||
for (int index = 0; index < m_ui->m_tabWidget->count(); index++) {
|
|
||||||
if (m_ui->m_tabWidget->tabBar()->tabType(index) == TabBar::FeedReader) {
|
|
||||||
m_ui->m_tabWidget->setTabIcon(index, QIcon(APP_ICON_PATH));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::createConnections() {
|
void FormMain::createConnections() {
|
||||||
@ -214,10 +166,6 @@ void FormMain::createConnections() {
|
|||||||
|
|
||||||
// General connections.
|
// General connections.
|
||||||
connect(qApp, &QCoreApplication::aboutToQuit, this, &FormMain::cleanupResources);
|
connect(qApp, &QCoreApplication::aboutToQuit, this, &FormMain::cleanupResources);
|
||||||
|
|
||||||
// TabWidget connections.
|
|
||||||
connect(m_ui->m_tabWidget->tabBar(), &TabBar::emptySpaceDoubleClicked,
|
|
||||||
this, &FormMain::addEmptyBrowser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormMain::closeEvent(QCloseEvent *event) {
|
void FormMain::closeEvent(QCloseEvent *event) {
|
||||||
|
@ -67,18 +67,6 @@ class FormMain : public QMainWindow {
|
|||||||
// Displays various dialogs.
|
// Displays various dialogs.
|
||||||
void showSettings();
|
void showSettings();
|
||||||
void showAbout();
|
void showAbout();
|
||||||
|
|
||||||
// Adds new WebBrowser tab to global TabWidget.
|
|
||||||
void addEmptyBrowser();
|
|
||||||
|
|
||||||
// Adds new WebBrowser with link. This is used when user
|
|
||||||
// selects to "Open link in new tab.".
|
|
||||||
void addLinkedBrowser();
|
|
||||||
|
|
||||||
// General method for adding WebBrowsers.
|
|
||||||
void addBrowser(bool move_after_current,
|
|
||||||
bool make_active,
|
|
||||||
const QUrl &initial_url = QUrl());
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FormMain *m_ui;
|
Ui::FormMain *m_ui;
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
|
#include <QUrl>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "core/defs.h"
|
||||||
#include "gui/tabwidget.h"
|
#include "gui/tabwidget.h"
|
||||||
#include "gui/tabbar.h"
|
#include "gui/tabbar.h"
|
||||||
|
#include "gui/themefactory.h"
|
||||||
#include "gui/webbrowser.h"
|
#include "gui/webbrowser.h"
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +19,10 @@ TabWidget::~TabWidget() {
|
|||||||
|
|
||||||
void TabWidget::createConnections() {
|
void TabWidget::createConnections() {
|
||||||
connect(tabBar(), &QTabBar::tabCloseRequested, this, &TabWidget::closeTab);
|
connect(tabBar(), &QTabBar::tabCloseRequested, this, &TabWidget::closeTab);
|
||||||
|
|
||||||
|
// Web browser stuff.
|
||||||
|
connect(tabBar(), &TabBar::emptySpaceDoubleClicked,
|
||||||
|
this, &TabWidget::addEmptyBrowser);
|
||||||
}
|
}
|
||||||
|
|
||||||
TabBar *TabWidget::tabBar() {
|
TabBar *TabWidget::tabBar() {
|
||||||
@ -30,6 +39,16 @@ void TabWidget::initializeTabs() {
|
|||||||
setTabToolTip(index_of_browser, tr("Browse your feeds and messages"));
|
setTabToolTip(index_of_browser, tr("Browse your feeds and messages"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabWidget::setupIcons() {
|
||||||
|
// Find tab, which contains "Feeds" page and reload its icon.
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TabWidget::closeTab(int index) {
|
void TabWidget::closeTab(int index) {
|
||||||
removeTab(index);
|
removeTab(index);
|
||||||
}
|
}
|
||||||
@ -69,3 +88,44 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label,
|
|||||||
|
|
||||||
return tab_index;
|
return tab_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabWidget::addEmptyBrowser() {
|
||||||
|
addBrowser(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabWidget::addLinkedBrowser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabWidget::addBrowser(bool move_after_current,
|
||||||
|
bool make_active,
|
||||||
|
const QUrl &initial_url) {
|
||||||
|
// Create new WebBrowser.
|
||||||
|
WebBrowser *browser = new WebBrowser(this);
|
||||||
|
int final_index;
|
||||||
|
|
||||||
|
if (move_after_current) {
|
||||||
|
// Insert web browser after current tab.
|
||||||
|
final_index = insertTab(currentIndex() + 1,
|
||||||
|
browser,
|
||||||
|
ThemeFactory::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"),
|
||||||
|
tr("Web browser"), TabBar::Closable);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load initial web page if desired.
|
||||||
|
if (initial_url.isValid()) {
|
||||||
|
browser->navigateToUrl(initial_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make new web browser active if desired.
|
||||||
|
if (make_active) {
|
||||||
|
setCurrentIndex(final_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ class TabWidget : public QTabWidget {
|
|||||||
TabBar *tabBar();
|
TabBar *tabBar();
|
||||||
|
|
||||||
void initializeTabs();
|
void initializeTabs();
|
||||||
|
void setupIcons();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Creates necesary connections.
|
// Creates necesary connections.
|
||||||
@ -38,6 +39,18 @@ class TabWidget : public QTabWidget {
|
|||||||
public slots:
|
public slots:
|
||||||
// Closes tab with given index and deletes contained widget.
|
// Closes tab with given index and deletes contained widget.
|
||||||
void closeTab(int index);
|
void closeTab(int index);
|
||||||
|
|
||||||
|
// Adds new WebBrowser tab to global TabWidget.
|
||||||
|
void addEmptyBrowser();
|
||||||
|
|
||||||
|
// Adds new WebBrowser with link. This is used when user
|
||||||
|
// selects to "Open link in new tab.".
|
||||||
|
void addLinkedBrowser();
|
||||||
|
|
||||||
|
// General method for adding WebBrowsers.
|
||||||
|
void addBrowser(bool move_after_current,
|
||||||
|
bool make_active,
|
||||||
|
const QUrl &initial_url = QUrl());
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TABWIDGET_H
|
#endif // TABWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user