mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +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:
|
||||
return t->isRestored();
|
||||
|
||||
case CurrentTabRole:
|
||||
return t->isCurrentTab();
|
||||
|
||||
case LoadingRole:
|
||||
return t->isLoading();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -196,6 +202,8 @@ void TabModel::tabInserted(int index)
|
||||
connect(tab, &WebTab::iconChanged, this, std::bind(emitDataChanged, tab, IconRole));
|
||||
connect(tab, &WebTab::pinnedChanged, this, std::bind(emitDataChanged, tab, PinnedRole));
|
||||
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)
|
||||
|
@ -34,7 +34,9 @@ public:
|
||||
TitleRole = Qt::UserRole + 2,
|
||||
IconRole = Qt::UserRole + 3,
|
||||
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);
|
||||
|
@ -164,6 +164,8 @@ WebTab::WebTab(QWidget *parent)
|
||||
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleWasChanged);
|
||||
connect(m_webView, &TabbedWebView::titleChanged, this, &WebTab::titleChanged);
|
||||
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
|
||||
connect(m_tabIcon, &TabIcon::resized, this, [this]() {
|
||||
@ -300,6 +302,12 @@ void WebTab::detach()
|
||||
// Detach TabbedWebView
|
||||
m_webView->setBrowserWindow(nullptr);
|
||||
|
||||
if (m_isCurrentTab) {
|
||||
m_isCurrentTab = false;
|
||||
emit currentTabChanged(m_isCurrentTab);
|
||||
}
|
||||
m_tabBar->disconnect(this);
|
||||
|
||||
// WebTab is now standalone widget
|
||||
m_window = nullptr;
|
||||
m_tabBar = nullptr;
|
||||
@ -315,6 +323,17 @@ void WebTab::attach(BrowserWindow* window)
|
||||
m_tabBar->setTabText(tabIndex(), title());
|
||||
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), m_tabIcon);
|
||||
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
|
||||
@ -528,7 +547,7 @@ void WebTab::titleWasChanged(const QString &title)
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCurrentTab()) {
|
||||
if (m_isCurrentTab) {
|
||||
m_window->setWindowTitle(tr("%1 - Falkon").arg(title));
|
||||
}
|
||||
|
||||
@ -560,14 +579,12 @@ void WebTab::resizeEvent(QResizeEvent *event)
|
||||
|
||||
bool WebTab::isCurrentTab() const
|
||||
{
|
||||
return m_tabBar && tabIndex() == m_tabBar->currentIndex();
|
||||
return m_isCurrentTab;
|
||||
}
|
||||
|
||||
int WebTab::tabIndex() const
|
||||
{
|
||||
Q_ASSERT(m_tabBar);
|
||||
|
||||
return m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this));
|
||||
return m_tabBar ? m_tabBar->tabWidget()->indexOf(const_cast<WebTab*>(this)) : -1;
|
||||
}
|
||||
|
||||
void WebTab::togglePinned()
|
||||
|
@ -122,6 +122,8 @@ signals:
|
||||
void iconChanged(const QIcon &icon);
|
||||
void pinnedChanged(bool pinned);
|
||||
void restoredChanged(bool restored);
|
||||
void currentTabChanged(bool current);
|
||||
void loadingChanged(bool loading);
|
||||
void parentTabChanged(WebTab *tab);
|
||||
void childTabAdded(WebTab *tab, int index);
|
||||
void childTabRemoved(WebTab *tab, int index);
|
||||
@ -146,6 +148,7 @@ private:
|
||||
|
||||
SavedTab m_savedTab;
|
||||
bool m_isPinned = false;
|
||||
bool m_isCurrentTab = false;
|
||||
};
|
||||
|
||||
#endif // WEBTAB_H
|
||||
|
Loading…
Reference in New Issue
Block a user