Editors: Highlight the view that has focus

If there is more than one editor view, i.e. if the view is split or an
additional editor window open, paint a small line in the highlight color
below the editor tool bar to indicate which view is "current", and
therefore the target for opening files, and keystrokes (if it also has
focus).

Fixes: QTCREATORBUG-23654
Change-Id: I9950c133a6633c6e68943c038669895dce1dd7ef
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Eike Ziller
2024-04-24 16:51:40 +02:00
parent 1c04192c51
commit 0f9270ed7d
3 changed files with 72 additions and 25 deletions

View File

@@ -1724,6 +1724,8 @@ void EditorManagerPrivate::setCurrentEditor(IEditor *editor, bool ignoreNavigati
updateActions();
if (QTC_GUARD(!d->m_currentView.isEmpty()) && d->m_currentView.constFirst() != previousView)
emit d->currentViewChanged();
if (d->m_currentEditor != previousEditor)
emit m_instance->currentEditorChanged(d->m_currentEditor);
}
@@ -1742,6 +1744,8 @@ void EditorManagerPrivate::setCurrentView(EditorView *view)
previousView->update();
if (d->m_currentView.constFirst())
view->update();
emit d->currentViewChanged();
}
setCurrentEditor(view->currentEditor());
@@ -1869,6 +1873,8 @@ void EditorManagerPrivate::addEditorArea(EditorArea *area)
// If we didn't find a better view, so be it
},
Qt::QueuedConnection);
connect(area, &SplitterOrView::splitStateChanged, d, &EditorManagerPrivate::viewCountChanged);
emit d->viewCountChanged();
}
void EditorManagerPrivate::splitNewWindow(EditorView *view)
@@ -2280,8 +2286,7 @@ void EditorManagerPrivate::editorAreaDestroyed(QObject *area)
}
}
// check if the destroyed editor area had the current view or current editor
if (currentEditorView())
return;
if (!currentEditorView()) {
// we need to set a new current editor or view
if (!newActiveArea) {
// some window managers behave weird and don't activate another window
@@ -2301,11 +2306,14 @@ void EditorManagerPrivate::editorAreaDestroyed(QObject *area)
if (!focusSplitterOrView)
focusSplitterOrView = newActiveArea->findFirstView()->parentSplitterOrView();
QTC_ASSERT(focusSplitterOrView, focusSplitterOrView = newActiveArea);
EditorView *focusView = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView
EditorView *focusView
= focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView
QTC_ASSERT(focusView, focusView = newActiveArea->findFirstView());
QTC_ASSERT(focusView, return);
if (QTC_GUARD(focusView))
EditorManagerPrivate::activateView(focusView);
}
emit viewCountChanged();
}
void EditorManagerPrivate::autoSave()
{
@@ -2665,6 +2673,14 @@ QList<EditorView *> EditorManagerPrivate::allEditorViews()
return views;
}
bool EditorManagerPrivate::hasMoreThanOneview()
{
if (d->m_editorAreas.size() > 1)
return true;
QTC_ASSERT(d->m_editorAreas.size() > 0, return false);
return d->m_editorAreas.constFirst()->isSplitter();
}
/*!
Returns the pointer to the instance. Only use for connecting to signals.
*/

View File

@@ -61,6 +61,7 @@ public:
static EditorArea *mainEditorArea();
static EditorView *currentEditorView();
static QList<EditorView *> allEditorViews();
static bool hasMoreThanOneview();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static IEditor *openEditor(EditorView *view,
const Utils::FilePath &filePath,
@@ -137,6 +138,8 @@ public slots:
signals:
void placeholderTextChanged(const QString &text);
void currentViewChanged();
void viewCountChanged();
private:
static void gotoNextDocHistory();

View File

@@ -14,10 +14,11 @@
#include <utils/algorithm.h>
#include <utils/infobar.h>
#include <utils/qtcassert.h>
#include <utils/theme/theme.h>
#include <utils/layoutbuilder.h>
#include <utils/link.h>
#include <utils/overlaywidget.h>
#include <utils/qtcassert.h>
#include <utils/theme/theme.h>
#include <utils/utilsicons.h>
#include <QFileInfo>
@@ -125,6 +126,33 @@ EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) :
this, &EditorView::openDroppedFiles);
updateNavigatorActions();
auto currentViewOverlay = new OverlayWidget;
currentViewOverlay->attachToWidget(this);
currentViewOverlay->setPaintFunction([this](QWidget *w, QPainter &p, QPaintEvent *) {
const int width = 2;
const QPoint margin{0, width};
p.setPen({w->palette().color(QPalette::Highlight), width});
p.drawLine(
m_toolBar->geometry().bottomLeft() + margin,
m_toolBar->geometry().bottomRight() + margin);
});
currentViewOverlay->setVisible(false);
const auto updateCurrentViewOverlay = [this, currentViewOverlay] {
currentViewOverlay->setVisible(
EditorManagerPrivate::hasMoreThanOneview()
&& EditorManagerPrivate::currentEditorView() == this);
};
connect(
EditorManagerPrivate::instance(),
&EditorManagerPrivate::currentViewChanged,
currentViewOverlay,
updateCurrentViewOverlay);
connect(
EditorManagerPrivate::instance(),
&EditorManagerPrivate::viewCountChanged,
currentViewOverlay,
updateCurrentViewOverlay);
}
EditorView::~EditorView() = default;