mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
TabModel: add CurrentTabRole and LoadingRole
This commit is contained in:
parent
a8bda61f3e
commit
57b605e4e0
@ -89,6 +89,12 @@ QVariant TabModel::data(const QModelIndex &index, int role) const
|
|||||||
case RestoredRole:
|
case RestoredRole:
|
||||||
return t->isRestored();
|
return t->isRestored();
|
||||||
|
|
||||||
|
case CurrentTabRole:
|
||||||
|
return t->isCurrentTab();
|
||||||
|
|
||||||
|
case LoadingRole:
|
||||||
|
return t->isLoading();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@ -196,6 +202,8 @@ void TabModel::tabInserted(int index)
|
|||||||
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, IconRole));
|
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, IconRole));
|
||||||
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, PinnedRole));
|
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, PinnedRole));
|
||||||
connect(tab, &WebTab::restoredChanged, this, std::bind(emitDataChanged, tab, RestoredRole));
|
connect(tab, &WebTab::restoredChanged, this, std::bind(emitDataChanged, tab, RestoredRole));
|
||||||
|
connect(tab, &WebTab::currentTabChanged, this, std::bind(emitDataChanged, tab, CurrentTabRole));
|
||||||
|
connect(tab, &WebTab::loadingChanged, this, std::bind(emitDataChanged, tab, LoadingRole));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabModel::tabRemoved(int index)
|
void TabModel::tabRemoved(int index)
|
||||||
|
@ -34,7 +34,9 @@ public:
|
|||||||
TitleRole = Qt::UserRole + 2,
|
TitleRole = Qt::UserRole + 2,
|
||||||
IconRole = Qt::UserRole + 3,
|
IconRole = Qt::UserRole + 3,
|
||||||
PinnedRole = Qt::UserRole + 4,
|
PinnedRole = Qt::UserRole + 4,
|
||||||
RestoredRole = Qt::UserRole + 5
|
RestoredRole = Qt::UserRole + 5,
|
||||||
|
CurrentTabRole = Qt::UserRole + 6,
|
||||||
|
LoadingRole = Qt::UserRole + 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit TabModel(BrowserWindow *window, QObject *parent = nullptr);
|
explicit TabModel(BrowserWindow *window, QObject *parent = nullptr);
|
||||||
|
@ -164,6 +164,8 @@ WebTab::WebTab(QWidget *parent)
|
|||||||
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleWasChanged);
|
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleWasChanged);
|
||||||
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleChanged);
|
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleChanged);
|
||||||
connect(m_webView, &TabbedWebView::iconChanged, this, &WebTab::iconChanged);
|
connect(m_webView, &TabbedWebView::iconChanged, this, &WebTab::iconChanged);
|
||||||
|
connect(m_webView, &TabbedWebView::loadStarted, this, std::bind(&WebTab::loadingChanged, this, true));
|
||||||
|
connect(m_webView, &TabbedWebView::loadFinished, this, std::bind(&WebTab::loadingChanged, this, false));
|
||||||
|
|
||||||
// Workaround QTabBar not immediately noticing resizing of tab buttons
|
// Workaround QTabBar not immediately noticing resizing of tab buttons
|
||||||
connect(m_tabIcon, &TabIcon::resized, this, [this]() {
|
connect(m_tabIcon, &TabIcon::resized, this, [this]() {
|
||||||
@ -300,6 +302,12 @@ void WebTab::detach()
|
|||||||
// Detach TabbedWebView
|
// Detach TabbedWebView
|
||||||
m_webView->setBrowserWindow(nullptr);
|
m_webView->setBrowserWindow(nullptr);
|
||||||
|
|
||||||
|
if (m_isCurrentTab) {
|
||||||
|
m_isCurrentTab = false;
|
||||||
|
emit currentTabChanged(m_isCurrentTab);
|
||||||
|
}
|
||||||
|
m_tabBar->disconnect(this);
|
||||||
|
|
||||||
// WebTab is now standalone widget
|
// WebTab is now standalone widget
|
||||||
m_window = nullptr;
|
m_window = nullptr;
|
||||||
m_tabBar = nullptr;
|
m_tabBar = nullptr;
|
||||||
@ -315,6 +323,17 @@ void WebTab::attach(BrowserWindow* window)
|
|||||||
m_tabBar->setTabText(tabIndex(), title());
|
m_tabBar->setTabText(tabIndex(), title());
|
||||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
||||||
m_tabIcon->updateIcon();
|
m_tabIcon->updateIcon();
|
||||||
|
|
||||||
|
auto currentChanged = [this](int index) {
|
||||||
|
const bool wasCurrent = m_isCurrentTab;
|
||||||
|
m_isCurrentTab = index == tabIndex();
|
||||||
|
if (wasCurrent != m_isCurrentTab) {
|
||||||
|
emit currentTabChanged(m_isCurrentTab);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
currentTabChanged(m_tabBar->currentIndex());
|
||||||
|
connect(m_tabBar, &TabBar::currentChanged, this, currentChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray WebTab::historyData() const
|
QByteArray WebTab::historyData() const
|
||||||
@ -528,7 +547,7 @@ void WebTab::titleWasChanged(const QString &title)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCurrentTab()) {
|
if (m_isCurrentTab) {
|
||||||
m_window->setWindowTitle(tr("%1 - Falkon").arg(title));
|
m_window->setWindowTitle(tr("%1 - Falkon").arg(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,14 +579,12 @@ void WebTab::resizeEvent(QResizeEvent *event)
|
|||||||
|
|
||||||
bool WebTab::isCurrentTab() const
|
bool WebTab::isCurrentTab() const
|
||||||
{
|
{
|
||||||
return m_tabBar && tabIndex() == m_tabBar->currentIndex();
|
return m_isCurrentTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebTab::tabIndex() const
|
int WebTab::tabIndex() const
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_tabBar);
|
return m_tabBar ? m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this)) : -1;
|
||||||
|
|
||||||
return m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebTab::togglePinned()
|
void WebTab::togglePinned()
|
||||||
|
@ -122,6 +122,8 @@ signals:
|
|||||||
void iconChanged(const QIcon &icon);
|
void iconChanged(const QIcon &icon);
|
||||||
void pinnedChanged(bool pinned);
|
void pinnedChanged(bool pinned);
|
||||||
void restoredChanged(bool restored);
|
void restoredChanged(bool restored);
|
||||||
|
void currentTabChanged(bool current);
|
||||||
|
void loadingChanged(bool loading);
|
||||||
void parentTabChanged(WebTab *tab);
|
void parentTabChanged(WebTab *tab);
|
||||||
void childTabAdded(WebTab *tab, int index);
|
void childTabAdded(WebTab *tab, int index);
|
||||||
void childTabRemoved(WebTab *tab, int index);
|
void childTabRemoved(WebTab *tab, int index);
|
||||||
@ -146,6 +148,7 @@ private:
|
|||||||
|
|
||||||
SavedTab m_savedTab;
|
SavedTab m_savedTab;
|
||||||
bool m_isPinned = false;
|
bool m_isPinned = false;
|
||||||
|
bool m_isCurrentTab = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBTAB_H
|
#endif // WEBTAB_H
|
||||||
|
Loading…
Reference in New Issue
Block a user