Files
Sourcetrail/src/lib_gui/qt/element/QtCodeArea.h
T
Eberhard Graether 95ef8c3eec ui: Added on-screen search feature (issue #79)
* Use menu action "Edit -> Find in View" or Ctrl + D
* UI displayed as search bar at bottom of main window
* Hide search bar with ECS or close button
* Entering a query searches in name of graph nodes and code contents of code view
* Use Enter to iterate through matches, well move match into view in graph and code view
* Checkboxes allow for adding/removing results for certain views
* Create Bookmark shortcut is now CTRL + S

bug id = 79
2017-09-19 14:00:40 +02:00

136 lines
3.2 KiB
C++

#ifndef QT_CODE_AREA_H
#define QT_CODE_AREA_H
#include <memory>
#include <vector>
#include "qt/element/QtCodeField.h"
#include "qt/utility/QtScrollSpeedChangeListener.h"
class QDragMoveEvent;
class QPaintEvent;
class QResizeEvent;
class QSize;
class QtCodeNavigator;
class QWidget;
class QtCodeArea;
class MouseWheelOverScrollbarFilter
: public QObject
{
Q_OBJECT
public:
MouseWheelOverScrollbarFilter();
protected:
bool eventFilter(QObject* obj, QEvent* event);
};
class QtLineNumberArea
: public QWidget
{
Q_OBJECT
public:
QtLineNumberArea(QtCodeArea* codeArea);
virtual ~QtLineNumberArea();
QSize sizeHint() const Q_DECL_OVERRIDE;
protected:
virtual void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
private:
QtCodeArea* m_codeArea;
};
class QtCodeArea
: public QtCodeField
{
Q_OBJECT
public:
QtCodeArea(
uint startLineNumber,
const std::string& code,
std::shared_ptr<SourceLocationFile> locationFile,
QtCodeNavigator* navigator,
bool showLineNumbers,
QWidget* parent = nullptr
);
virtual ~QtCodeArea();
virtual QSize sizeHint() const Q_DECL_OVERRIDE;
void lineNumberAreaPaintEvent(QPaintEvent* event);
int lineNumberDigits() const;
int lineNumberAreaWidth() const;
void updateLineNumberAreaWidthForDigits(int digits);
void updateContent();
void setIsActiveFile(bool isActiveFile);
uint getLineNumberForLocationId(Id locationId) const;
std::pair<uint, uint> getLineNumbersForLocationId(Id locationId) const;
Id getLocationIdOfFirstActiveLocation(Id tokenId) const;
Id getLocationIdOfFirstActiveScopeLocation(Id tokenId) const;
uint getActiveLocationCount() const;
QRectF getLineRectForLineNumber(uint lineNumber) const;
void findScreenMatches(const std::string& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches);
void clearScreenMatches();
protected:
virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
virtual void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
virtual void contextMenuEvent(QContextMenuEvent* event) Q_DECL_OVERRIDE;
virtual void focusTokenIds(const std::vector<Id>& tokenIds) override;
virtual void defocusTokenIds(const std::vector<Id>& tokenIds) override;
private slots:
void updateLineNumberAreaWidth(int newBlockCount = 0);
void updateLineNumberArea(const QRect&, int);
void clearSelection();
void setNewTextCursor(const QTextCursor& cursor);
void setIDECursorPosition();
private:
void activateErrors(const std::vector<const Annotation*>& annotations);
void annotateText();
void createActions();
QtCodeNavigator* m_navigator;
QWidget* m_lineNumberArea;
int m_digits;
bool m_isSelecting;
bool m_isPanning;
QPoint m_oldMousePosition;
int m_panningDistance;
QAction* m_setIDECursorPositionAction;
QPoint m_eventPosition; // is needed for IDE cursor control via context menu
// the position where the context menu is opened needs to be stored]
bool m_isActiveFile;
bool m_showLineNumbers;
QtScrollSpeedChangeListener m_scrollSpeedChangeListener;
};
#endif // QT_CODE_AREA_H