Commit 7d5ff41a authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Make modified doc's tab's text italic

This is another attempt that overrides the paintEvent to do the same
thing.
parent 600a996b
Pipeline #196723 failed with stage
in 6 minutes and 37 seconds
......@@ -165,6 +165,7 @@ void KateTabBar::mousePressEvent(QMouseEvent *event)
if (!isActive()) {
Q_EMIT activateViewSpaceRequested();
}
m_dragInProgress = false;
if (event->button() == Qt::LeftButton && tabAt(event->pos()) != -1) {
dragStartPos = event->pos();
......@@ -183,6 +184,12 @@ void KateTabBar::mousePressEvent(QMouseEvent *event)
}
}
void KateTabBar::mouseReleaseEvent(QMouseEvent *e)
{
m_dragInProgress = false;
QTabBar::mouseReleaseEvent(e);
}
void KateTabBar::mouseMoveEvent(QMouseEvent *event)
{
if (dragStartPos.isNull()) {
......@@ -196,6 +203,7 @@ void KateTabBar::mouseMoveEvent(QMouseEvent *event)
}
if (rect().contains(event->pos())) {
m_dragInProgress = true;
return QTabBar::mouseMoveEvent(event);
}
......@@ -278,6 +286,51 @@ void KateTabBar::wheelEvent(QWheelEvent *event)
setCurrentIndex(idx);
}
void KateTabBar::paintEvent(QPaintEvent *e)
{
if (m_dragInProgress) {
QTabBar::paintEvent(e);
return;
}
QStylePainter painter(this);
if (drawBase()) {
QStyleOptionTabBarBase opt;
opt.init(this);
opt.documentMode = true;
opt.shape = shape();
for (int i = 0; i < count(); ++i) {
opt.tabBarRect |= tabRect(i);
}
QStyleOptionTab tabOverlap;
tabOverlap.shape = shape();
int overlap = style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, this);
opt.rect.setRect(0, size().height() - overlap, size().width(), overlap);
painter.drawPrimitive(QStyle::PE_FrameTabBarBase, opt);
}
const int closeBtnWidth = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, nullptr, this);
for (int i = 0; i < count(); i++) {
QStyleOptionTab opt;
initStyleOption(&opt, i);
opt.palette.setColor(QPalette::Button, Qt::red);
painter.drawControl(QStyle::CE_TabBarTabShape, opt);
QFont original = painter.font();
QRect r = tabRect(i);
r.adjust(-closeBtnWidth, 0, 0, 0);
if (tabDocument(i) && tabDocument(i)->isModified()) {
// move it back slightly so the text doesn't jump
auto original = painter.font();
auto copy = original;
copy.setItalic(true);
painter.setFont(copy);
}
painter.drawText(r, Qt::AlignCenter, tabText(i));
painter.setFont(original);
}
}
void KateTabBar::setTabDocument(int idx, KTextEditor::Document *doc)
{
QVariant data = ensureValidTabData(idx);
......
......@@ -129,6 +129,10 @@ protected:
//! Cycle through tabs
void wheelEvent(QWheelEvent *event) override;
void paintEvent(QPaintEvent *) override;
void mouseReleaseEvent(QMouseEvent *e) override;
private:
using QTabBar::addTab;
using QTabBar::insertTab;
......@@ -170,6 +174,8 @@ private:
std::unordered_map<KTextEditor::Document *, std::pair<quint64, bool>> m_docToLruCounterAndHasTab;
QPoint dragStartPos;
bool m_dragInProgress = false;
};
#endif // KATE_TAB_BAR_H
......@@ -516,7 +516,12 @@ void KateViewSpace::registerDocument(KTextEditor::Document *doc)
*/
connect(doc, &KTextEditor::Document::documentNameChanged, this, &KateViewSpace::updateDocumentName);
connect(doc, &KTextEditor::Document::documentUrlChanged, this, &KateViewSpace::updateDocumentUrl);
connect(doc, &KTextEditor::Document::modifiedChanged, this, &KateViewSpace::updateDocumentName);
connect(doc, &KTextEditor::Document::modifiedChanged, this, [this](KTextEditor::Document *doc) {
int tab = m_tabBar->documentIdx(doc);
if (tab >= 0) {
m_tabBar->update(m_tabBar->tabRect(tab));
}
});
/**
* allow signals again, now that the tab is there
......@@ -682,9 +687,6 @@ void KateViewSpace::updateDocumentName(KTextEditor::Document *doc)
// BUG: 441278 We need to escape the & because it is used for accelerators/shortcut mnemonic by default
QString tabName = doc->documentName();
tabName.replace(QLatin1Char('&'), QLatin1String("&&"));
if (doc->isModified()) {
tabName.append(QStringLiteral(" *"));
}
m_tabBar->setTabText(buttonId, tabName);
}
}
......
Supports Markdown
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