aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2024-04-24 16:51:40 +0200
committerEike Ziller <eike.ziller@qt.io>2024-05-13 08:53:52 +0000
commit0f9270ed7dcfe57034f2844aabf54ae2ddb50241 (patch)
treeddd74caab54a2cbb3a19e8384c7571edf6f9c78e
parent1c04192c51fee21b4f9c2f4d732ddb68376b708a (diff)
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>
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp64
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager_p.h3
-rw-r--r--src/plugins/coreplugin/editormanager/editorview.cpp32
3 files changed, 73 insertions, 26 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 9041d2bd4a..95eb0def6c 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -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,31 +2286,33 @@ void EditorManagerPrivate::editorAreaDestroyed(QObject *area)
}
}
// check if the destroyed editor area had the current view or current editor
- if (currentEditorView())
- return;
- // we need to set a new current editor or view
- if (!newActiveArea) {
- // some window managers behave weird and don't activate another window
- // or there might be a Qt Creator toplevel activated that doesn't have editor windows
- newActiveArea = d->m_editorAreas.first();
- }
-
- // check if the focusWidget points to some view
- SplitterOrView *focusSplitterOrView = nullptr;
- QWidget *candidate = newActiveArea->focusWidget();
- while (candidate && candidate != newActiveArea) {
- if ((focusSplitterOrView = qobject_cast<SplitterOrView *>(candidate)))
- break;
- candidate = candidate->parentWidget();
+ 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
+ // or there might be a Qt Creator toplevel activated that doesn't have editor windows
+ newActiveArea = d->m_editorAreas.first();
+ }
+
+ // check if the focusWidget points to some view
+ SplitterOrView *focusSplitterOrView = nullptr;
+ QWidget *candidate = newActiveArea->focusWidget();
+ while (candidate && candidate != newActiveArea) {
+ if ((focusSplitterOrView = qobject_cast<SplitterOrView *>(candidate)))
+ break;
+ candidate = candidate->parentWidget();
+ }
+ // focusWidget might have been 0
+ if (!focusSplitterOrView)
+ focusSplitterOrView = newActiveArea->findFirstView()->parentSplitterOrView();
+ QTC_ASSERT(focusSplitterOrView, focusSplitterOrView = newActiveArea);
+ EditorView *focusView
+ = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView
+ QTC_ASSERT(focusView, focusView = newActiveArea->findFirstView());
+ if (QTC_GUARD(focusView))
+ EditorManagerPrivate::activateView(focusView);
}
- // focusWidget might have been 0
- if (!focusSplitterOrView)
- focusSplitterOrView = newActiveArea->findFirstView()->parentSplitterOrView();
- QTC_ASSERT(focusSplitterOrView, focusSplitterOrView = newActiveArea);
- EditorView *focusView = focusSplitterOrView->findFirstView(); // can be just focusSplitterOrView
- QTC_ASSERT(focusView, focusView = newActiveArea->findFirstView());
- QTC_ASSERT(focusView, return);
- 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.
*/
diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h
index 789acd16e1..db5bf759ae 100644
--- a/src/plugins/coreplugin/editormanager/editormanager_p.h
+++ b/src/plugins/coreplugin/editormanager/editormanager_p.h
@@ -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();
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index 6aa20510cb..ae9c047a77 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -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;