Commit 2d4c501b authored by Christoph Cullmann's avatar Christoph Cullmann

make Kate tabbar behave like a normal tabbar

* tabs are added on the right
* tabs use are expanding
* tabs will be scrollable if too many are there
* quickopen will provide the list of all tabs, like before, but without the +XX hint that was broken (and leads to jumping icons)
parent b963565b
......@@ -36,54 +36,32 @@ struct KateTabButtonData {
KTextEditor::Document *doc = nullptr;
};
Q_DECLARE_METATYPE(KateTabButtonData);
class KateTabBar::KateTabBarPrivate
{
public:
// pointer to tabbar
KateTabBar *q = nullptr;
bool isActive = false;
KTextEditor::Document *beingAdded;
};
Q_DECLARE_METATYPE(KateTabButtonData)
/**
* Creates a new tab bar with the given \a parent.
*/
KateTabBar::KateTabBar(QWidget *parent)
: QTabBar(parent)
, d(new KateTabBarPrivate())
{
d->q = this;
d->isActive = false;
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
setAcceptDrops(true);
setExpanding(false);
setExpanding(true);
setTabsClosable(true);
setMovable(true);
}
/**
* Destroys the tab bar.
*/
KateTabBar::~KateTabBar()
{
delete d;
}
void KateTabBar::setActive(bool active)
{
if (active == d->isActive) {
if (active == m_isActive) {
return;
}
d->isActive = active;
m_isActive = active;
update();
}
bool KateTabBar::isActive() const
{
return d->isActive;
return m_isActive;
}
int KateTabBar::prevTab() const
......@@ -195,10 +173,10 @@ KTextEditor::Document *KateTabBar::tabDocument(int idx)
KTextEditor::Document *doc = nullptr;
// The tab got activated before the correct finalixation,
// we need to plug the document before returning.
if (buttonData.doc == nullptr && d->beingAdded) {
setTabDocument(idx, d->beingAdded);
doc = d->beingAdded;
d->beingAdded = nullptr;
if (buttonData.doc == nullptr && m_beingAdded) {
setTabDocument(idx, m_beingAdded);
doc = m_beingAdded;
m_beingAdded = nullptr;
} else {
doc = buttonData.doc;
}
......@@ -208,45 +186,15 @@ KTextEditor::Document *KateTabBar::tabDocument(int idx)
int KateTabBar::insertTab(int idx, KTextEditor::Document* doc)
{
d->beingAdded = doc;
m_beingAdded = doc;
return insertTab(idx, doc->documentName());
}
void KateTabBar::tabInserted(int idx)
{
if (d->beingAdded) {
setTabDocument(idx, d->beingAdded);
if (m_beingAdded) {
setTabDocument(idx, m_beingAdded);
}
setTabToolTip(idx, tabDocument(idx)->url().toDisplayString());
d->beingAdded = nullptr;
calculateHiddenTabs();
}
void KateTabBar::tabRemoved(int idx)
{
calculateHiddenTabs();
}
void KateTabBar::calculateHiddenTabs()
{
QRect r = rect();
int numTabs = count();
int firstVisible = 0;
int lastVisible = numTabs - 1;
while(firstVisible < numTabs && !r.intersects(tabRect(firstVisible))) {
firstVisible += 1;
}
while(lastVisible > 0 && !r.intersects(tabRect(lastVisible))) {
lastVisible -= 1;
}
emit hiddenTabsChanged(count() - (lastVisible - (firstVisible-1)));
}
void KateTabBar::resizeEvent(QResizeEvent *ev)
{
QTabBar::resizeEvent(ev);
calculateHiddenTabs();
m_beingAdded = nullptr;
}
......@@ -42,10 +42,9 @@ class KateTabBar : public QTabBar
public:
explicit KateTabBar(QWidget *parent = nullptr);
~KateTabBar() override;
int insertTab(int idx, KTextEditor::Document *doc);
void tabInserted(int idx) override;
void tabRemoved(int idx) override;
/**
* Get the ID of the tab that is located left of the current tab.
* The return value is -1, if there is no previous tab.
......@@ -101,7 +100,6 @@ public:
*/
bool isActive() const;
void calculateHiddenTabs();
Q_SIGNALS:
/**
* This signal is emitted whenever the context menu is requested for
......@@ -125,8 +123,6 @@ Q_SIGNALS:
*/
void activateViewSpaceRequested();
void hiddenTabsChanged(int nr);
protected:
//! Override to avoid requesting a new tab.
void mouseDoubleClickEvent(QMouseEvent *event) override;
......@@ -140,16 +136,12 @@ protected:
//! Cycle through tabs
void wheelEvent(QWheelEvent *event) override;
//! Update the number of visible tabs.
void resizeEvent(QResizeEvent *event) override;
private:
using QTabBar::insertTab;
using QTabBar::addTab;
class KateTabBarPrivate;
// pimpl data holder
KateTabBarPrivate *const d;
bool m_isActive = false;
KTextEditor::Document *m_beingAdded = nullptr;
};
#endif // KATE_TAB_BAR_H
......@@ -66,7 +66,6 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
connect(m_tabBar, &KateTabBar::tabCloseRequested, this, &KateViewSpace::closeTabRequest, Qt::QueuedConnection);
connect(m_tabBar, &KateTabBar::contextMenuRequest, this, &KateViewSpace::showContextMenu, Qt::QueuedConnection);
connect(m_tabBar, &KateTabBar::newTabRequested, this, &KateViewSpace::createNewDocument);
connect(m_tabBar, &KateTabBar::hiddenTabsChanged, this, &KateViewSpace::updateQuickOpen);
connect(m_tabBar, SIGNAL(activateViewSpaceRequested()), this, SLOT(makeActive()));
hLayout->addWidget(m_tabBar);
......@@ -271,7 +270,7 @@ bool KateViewSpace::showView(KTextEditor::Document *document)
// in case a tab does not exist, add one
if (!m_tabBar->documentIdx(document)) {
insertTab(0, document);
insertTab(-1, document);
}
// follow current view
......@@ -380,7 +379,7 @@ void KateViewSpace::registerDocument(KTextEditor::Document *doc, bool append)
connect(doc, &QObject::destroyed, this, &KateViewSpace::documentDestroyed);
// if space is available, add button
insertTab(0, doc);
insertTab(-1, doc);
}
void KateViewSpace::documentDestroyed(QObject *doc)
......@@ -451,17 +450,6 @@ void KateViewSpace::createNewDocument()
m_viewManager->activateView(doc);
}
void KateViewSpace::updateQuickOpen(int hiddenTabs)
{
if (hiddenTabs == 0) {
m_quickOpen->setToolButtonStyle(Qt::ToolButtonIconOnly);
m_quickOpen->defaultAction()->setText(QString());
} else {
m_quickOpen->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_quickOpen->defaultAction()->setText(i18nc("indicator for more documents", "+%1", hiddenTabs));
}
}
void KateViewSpace::focusPrevTab()
{
const int id = m_tabBar->prevTab();
......
......@@ -154,11 +154,6 @@ private Q_SLOTS:
*/
void createNewDocument();
/**
* Update the quick open button to reflect the currently hidden tabs.
*/
void updateQuickOpen(int hiddenTabs);
private:
/**
* Returns the amount of documents in KateDocManager that currently
......
  • mentioned in merge request !21 (closed)

    Toggle commit list
  • mentioned in merge request !89 (merged)

    Toggle commit list
  • always good to see a lot of red lines in a diff. :)

  • I didn't investigate the full code (nor did I on first glance understand all of it), therefore still not used stuff could lurk there.

    Thanks by the way again for stepping up to help with this!

    Any further improvements are welcome.

  • if you can, I think my original patch broke something, I just created a PR with my findings but I hit a wall. !90 (closed)

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment