ui: Added tabs UI to top of main window (issue #215)

* Added tab bar to top of main window with UI/shortcuts similar to web browsers
* ComponentManager offers components for 2 use-cases: application and tab
* Application components: log view (status/errors), bookmarks, screen search, status bar, tabs, tooltips, dialogs and all tab views disabled
* Tab components: graph, code, history and search
* When a project is loaded there is always at least one tab, otherwise there is none
* Each tab replaces the application views of the same name in the main layout when activated
* Each tab has it's own TaskScheduler, to process tasks independent from other tabs
* The application has a global TaskScheduler for application wide tasks
* The singloton class TaskManager is responsible for managing the TaskSchedulers
* MessageListeners and Messages hold an optional schedulerId, both must be set to only send to a specific TaskScheduler
* Bookmark buttons where split off into a separate view per tab, bookmark managemement is done in the application
* History menu processing is done by the QtMainWindow now
* Screen search is an application component, the responders are always changed to the active tab
* Plugin messages are opened in a new tab
* Symbols can be opened in a new tab via middle click/context menu in graph, code, history dropdown
* Full text index creation is mutexed now in PersistenStorage to make it fully thread-safe
* All tabs are closed when switching projects
* Tab contents are only animated when visible

fortune cookie message = Catch your lucky star!
This commit is contained in:
Eberhard Graether
2018-11-05 01:28:12 +01:00
parent bd4a554b27
commit f13aec70dd
170 changed files with 2972 additions and 823 deletions
+64 -6
View File
@@ -1,17 +1,20 @@
#include "QtCodeField.h"
#include <QAction>
#include <QPainter>
#include <QTextBlock>
#include <QTextCodec>
#include "SourceLocation.h"
#include "SourceLocationFile.h"
#include "QtContextMenu.h"
#include "QtHighlighter.h"
#include "ApplicationSettings.h"
#include "ColorScheme.h"
#include "MessageActivateLocalSymbols.h"
#include "MessageActivateSourceLocations.h"
#include "MessageActivateTokenIds.h"
#include "MessageTabOpenWith.h"
#include "MessageTooltipShow.h"
#include "TextCodec.h"
#include "tracing.h"
@@ -99,6 +102,12 @@ QtCodeField::QtCodeField(
font.setPixelSize(appSettings->getFontSize());
setFont(font);
setTabStopWidth(appSettings->getCodeTabWidth() * fontMetrics().width('9'));
m_openInTabAction = new QAction("Open in New Tab", this);
m_openInTabAction->setStatusTip("Opens the node in a new tab");
m_openInTabAction->setToolTip("Opens the node in a new tab");
m_openInTabAction->setEnabled(false);
connect(m_openInTabAction, &QAction::triggered, this, &QtCodeField::openInTab);
}
QtCodeField::~QtCodeField()
@@ -251,8 +260,7 @@ void QtCodeField::leaveEvent(QEvent* event)
void QtCodeField::mouseMoveEvent(QMouseEvent* event)
{
QTextCursor cursor = this->cursorForPosition(event->pos());
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(event->pos());
bool same = annotations.size() == m_hoveredAnnotations.size();
if (same)
@@ -275,6 +283,13 @@ void QtCodeField::mouseMoveEvent(QMouseEvent* event)
void QtCodeField::mouseReleaseEvent(QMouseEvent* event)
{
if (event->button() == Qt::MiddleButton)
{
checkOpenInTabActionEnabled(event->pos());
openInTab();
return;
}
if (event->button() != Qt::LeftButton)
{
return;
@@ -282,9 +297,7 @@ void QtCodeField::mouseReleaseEvent(QMouseEvent* event)
viewport()->setCursor(Qt::ArrowCursor);
QTextCursor cursor = this->cursorForPosition(event->pos());
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(event->pos());
if (!annotations.size())
{
return;
@@ -293,6 +306,16 @@ void QtCodeField::mouseReleaseEvent(QMouseEvent* event)
activateAnnotations(annotations);
}
void QtCodeField::contextMenuEvent(QContextMenuEvent* event)
{
checkOpenInTabActionEnabled(event->pos());
QtContextMenu menu(event, nullptr);
menu.addAction(m_openInTabAction);
menu.addUndoActions();
menu.show();
}
void QtCodeField::focusTokenIds(const std::vector<Id>& focusedTokenIds)
{
annotateText(std::set<Id>(), std::set<Id>(), std::set<Id>(focusedTokenIds.begin(), focusedTokenIds.end()));
@@ -639,10 +662,13 @@ void QtCodeField::setTextColorForAnnotation(const Annotation& annotation, QColor
m_highlighter->applyFormat(annotation.start, annotation.end, format);
}
std::vector<const QtCodeField::Annotation*> QtCodeField::getInteractiveAnnotationsForPosition(int pos) const
std::vector<const QtCodeField::Annotation*> QtCodeField::getInteractiveAnnotationsForPosition(QPoint position) const
{
std::vector<const QtCodeField::Annotation*> annotations;
QTextCursor cursor = this->cursorForPosition(position);
int pos = cursor.position();
for (const Annotation& annotation : m_annotations)
{
const LocationType& type = annotation.locationType;
@@ -656,6 +682,38 @@ std::vector<const QtCodeField::Annotation*> QtCodeField::getInteractiveAnnotatio
return annotations;
}
void QtCodeField::checkOpenInTabActionEnabled(QPoint position)
{
std::vector<Id> locationIds;
for (const Annotation* annotation : getInteractiveAnnotationsForPosition(position))
{
const LocationType& type = annotation->locationType;
if (type == LOCATION_TOKEN || type == LOCATION_QUALIFIER)
{
locationIds.emplace_back(annotation->locationId);
}
}
if (locationIds.size())
{
m_openInTabLocationId = locationIds[0];
}
else
{
m_openInTabLocationId = 0;
}
m_openInTabAction->setEnabled(m_openInTabLocationId);
}
void QtCodeField::openInTab()
{
if (m_openInTabLocationId)
{
MessageTabOpenWith(0, m_openInTabLocationId).dispatch();
}
}
void QtCodeField::createLineLengthCache()
{
m_endTextEditPosition = -1;