mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-31 01:24:49 +01:00
Work on refactoring.
This commit is contained in:
parent
5ee4c611a1
commit
61e0ff26db
@ -148,6 +148,7 @@ void FormMain::setupIcons() {
|
||||
browser->setupIcons();
|
||||
}
|
||||
|
||||
// Setup icons on TabWidget too.
|
||||
m_ui->m_tabWidget->setupIcons();
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ class TabBar : public QTabBar {
|
||||
Closable = 1002
|
||||
};
|
||||
|
||||
// Constructors.
|
||||
explicit TabBar(QWidget *parent = 0);
|
||||
virtual ~TabBar();
|
||||
|
||||
@ -22,6 +23,7 @@ class TabBar : public QTabBar {
|
||||
TabBar::TabType tabType(int index);
|
||||
|
||||
protected:
|
||||
// Reimplementations.
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
|
@ -11,14 +11,18 @@ class TabContent : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TabContent(QWidget *parent = 0);
|
||||
// Contructors.
|
||||
explicit TabContent(QWidget *parent = 0);
|
||||
virtual ~TabContent();
|
||||
|
||||
// Gets/sets current index of this TabContent.
|
||||
// NOTE: This is the index under which this object lies
|
||||
// in some TabWidget instance.
|
||||
virtual int index() const;
|
||||
virtual void setIndex(int index);
|
||||
|
||||
// Obtains instance contained in this TabContent or nullptr.
|
||||
// This is used for obtaining the menu from the instance and so on.
|
||||
// This can be used for obtaining the menu from the instance and so on.
|
||||
virtual WebBrowser *webBrowser() = 0;
|
||||
|
||||
private:
|
||||
|
@ -19,8 +19,6 @@ TabWidget::~TabWidget() {
|
||||
|
||||
void TabWidget::createConnections() {
|
||||
connect(tabBar(), &QTabBar::tabCloseRequested, this, &TabWidget::closeTab);
|
||||
|
||||
// Web browser stuff.
|
||||
connect(tabBar(), &TabBar::emptySpaceDoubleClicked,
|
||||
this, &TabWidget::addEmptyBrowser);
|
||||
}
|
||||
@ -39,25 +37,25 @@ void TabWidget::initializeTabs() {
|
||||
setTabToolTip(index_of_browser, tr("Browse your feeds and messages"));
|
||||
}
|
||||
|
||||
TabContent *TabWidget::contentAt(int index) {
|
||||
return static_cast<TabContent*>(widget(index));
|
||||
TabContent *TabWidget::widget(int index) const {
|
||||
return static_cast<TabContent*>(QTabWidget::widget(index));
|
||||
}
|
||||
|
||||
void TabWidget::setupIcons() {
|
||||
// Iterate through all tabs and update icons
|
||||
// accordingly.
|
||||
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"));
|
||||
}
|
||||
// Other indexes probably contain WebBrowsers.
|
||||
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"));
|
||||
}
|
||||
WebBrowser *active_browser = widget(index)->webBrowser();
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -104,10 +102,14 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label,
|
||||
}
|
||||
|
||||
void TabWidget::addEmptyBrowser() {
|
||||
// TODO: Add reading of move_after_current and make_active
|
||||
// flags from settings.
|
||||
addBrowser(false, true);
|
||||
}
|
||||
|
||||
void TabWidget::addLinkedBrowser(const QUrl &initial_url) {
|
||||
// TODO: Add reading of move_after_current and make_active
|
||||
// flags from settings.
|
||||
addBrowser(true, false, initial_url);
|
||||
}
|
||||
|
||||
@ -130,7 +132,9 @@ void TabWidget::addBrowser(bool move_after_current,
|
||||
// Add new browser as the last tab.
|
||||
final_index = addTab(browser,
|
||||
ThemeFactory::getInstance()->fromTheme("text-html"),
|
||||
tr("Web browser"), TabBar::Closable);
|
||||
tr("Web browser"),
|
||||
TabBar::Closable);
|
||||
browser->setFocus(Qt::OtherFocusReason);
|
||||
}
|
||||
|
||||
// Load initial web page if desired.
|
||||
|
@ -28,9 +28,13 @@ class TabWidget : public QTabWidget {
|
||||
|
||||
// Returns tab bar.
|
||||
TabBar *tabBar();
|
||||
TabContent *contentAt(int index);
|
||||
TabContent *widget(int index) const;
|
||||
|
||||
// Initializes TabWidget with tabs, this includes initialization
|
||||
// of main "Feeds" widget.
|
||||
void initializeTabs();
|
||||
|
||||
// Sets up icons for this TabWidget.
|
||||
void setupIcons();
|
||||
|
||||
protected:
|
||||
|
@ -80,22 +80,28 @@ void ThemeFactory::loadCurrentIconTheme(bool notify_widgets) {
|
||||
"icon_theme",
|
||||
"mini-kfaenza").toString();
|
||||
|
||||
// Display list of installed themes.
|
||||
qDebug("Installed icon themes are: %s.",
|
||||
qPrintable(installed_themes.join(", ")));
|
||||
|
||||
// User wants to load icon theme, but it's not installed.
|
||||
if (!installed_themes.contains(theme_name_from_settings)) {
|
||||
|
||||
if (installed_themes.contains(theme_name_from_settings)) {
|
||||
// Desired icon theme is installed and can be loaded.
|
||||
qDebug("Loading theme '%s'.", qPrintable(theme_name_from_settings));
|
||||
QIcon::setThemeName(theme_name_from_settings);
|
||||
m_currentIconTheme = theme_name_from_settings;
|
||||
}
|
||||
else {
|
||||
// Desired icon theme is not currently available.
|
||||
// Install "default" icon theme instead.
|
||||
// NOTE: "Default" icon theme is:
|
||||
// a) system icon theme on Linux,
|
||||
// b) no icon theme on other platforms.
|
||||
qDebug("Icon theme '%s' cannot be loaded because it is not installed. Loading 'default' theme.",
|
||||
qPrintable(theme_name_from_settings));
|
||||
QIcon::setThemeName(APP_THEME_SYSTEM);
|
||||
m_currentIconTheme = APP_THEME_SYSTEM;
|
||||
}
|
||||
// Icon theme is found so it can be installed.
|
||||
else {
|
||||
qDebug("Loading theme '%s'.", qPrintable(theme_name_from_settings));
|
||||
QIcon::setThemeName(theme_name_from_settings);
|
||||
m_currentIconTheme = theme_name_from_settings;
|
||||
}
|
||||
|
||||
// We need to deliver custom event for all widgets
|
||||
// to make sure they get a chance to setup their icons.
|
||||
|
@ -80,6 +80,9 @@ 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.
|
||||
TabWidget *parent_widget = static_cast<TabWidget*>(parent());
|
||||
connect(m_webView, &BaseWebView::newTabRequested,
|
||||
parent_widget, &TabWidget::addEmptyBrowser);
|
||||
@ -130,6 +133,10 @@ QIcon WebBrowser::icon() {
|
||||
return m_webView->icon();
|
||||
}
|
||||
|
||||
void WebBrowser::setFocus(Qt::FocusReason reason) {
|
||||
m_txtLocation->setFocus(reason);
|
||||
}
|
||||
|
||||
void WebBrowser::setupIcons() {
|
||||
m_actionBack->setIcon(ThemeFactory::getInstance()->fromTheme("go-previous"));
|
||||
m_actionForward->setIcon(ThemeFactory::getInstance()->fromTheme("go-next"));
|
||||
|
@ -28,6 +28,9 @@ class WebBrowser : public TabContent {
|
||||
// Returns icon associated with currently loaded website.
|
||||
QIcon icon();
|
||||
|
||||
// Sets this WebBrowser instance as focused.
|
||||
void setFocus(Qt::FocusReason reason);
|
||||
|
||||
// Returns this instance.
|
||||
// NOTE: This is needed due to TabContent interface.
|
||||
WebBrowser *webBrowser();
|
||||
|
Loading…
x
Reference in New Issue
Block a user