2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-02-27 20:55:36 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2012-02-27 20:55:36 +01:00
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
|
|
|
|
|
2018-05-02 15:02:00 +02:00
|
|
|
#include <utils/fileutils.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#include <utils/id.h>
|
|
|
|
|
#include <utils/theme/theme.h>
|
2015-04-17 12:46:28 +02:00
|
|
|
|
2021-02-02 16:24:21 +01:00
|
|
|
#include <QCoreApplication>
|
2012-02-27 20:55:36 +01:00
|
|
|
#include <QIcon>
|
2019-01-28 09:32:11 +01:00
|
|
|
#include <QVector>
|
2012-02-27 20:55:36 +01:00
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
2012-02-27 20:55:36 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
2019-01-28 09:32:11 +01:00
|
|
|
class QAction;
|
2016-08-16 14:19:41 +02:00
|
|
|
class QGridLayout;
|
2016-07-22 08:57:32 +02:00
|
|
|
class QLayout;
|
2012-02-27 20:55:36 +01:00
|
|
|
class QPainter;
|
|
|
|
|
class QRect;
|
|
|
|
|
class QTextBlock;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2014-09-22 18:43:31 +02:00
|
|
|
class TextDocument;
|
2012-02-27 20:55:36 +01:00
|
|
|
|
2023-01-09 13:14:39 +01:00
|
|
|
class TextMarkCategory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString displayName;
|
|
|
|
|
Utils::Id id;
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-19 11:27:28 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextMark
|
2012-02-27 20:55:36 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2019-05-28 13:49:26 +02:00
|
|
|
TextMark(const Utils::FilePath &fileName,
|
2018-05-02 15:02:00 +02:00
|
|
|
int lineNumber,
|
2023-01-09 13:14:39 +01:00
|
|
|
TextMarkCategory category);
|
2017-06-01 08:48:11 +02:00
|
|
|
TextMark() = delete;
|
2014-07-19 11:27:28 +02:00
|
|
|
virtual ~TextMark();
|
2012-02-27 20:55:36 +01:00
|
|
|
|
|
|
|
|
// determine order on markers on the same line.
|
|
|
|
|
enum Priority
|
|
|
|
|
{
|
|
|
|
|
LowPriority,
|
|
|
|
|
NormalPriority,
|
|
|
|
|
HighPriority // shown on top.
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
Utils::FilePath fileName() const;
|
2012-02-27 20:55:36 +01:00
|
|
|
int lineNumber() const;
|
2014-07-19 11:27:28 +02:00
|
|
|
|
2017-06-20 08:28:10 +02:00
|
|
|
virtual void paintIcon(QPainter *painter, const QRect &rect) const;
|
2022-03-11 13:37:21 +01:00
|
|
|
virtual void paintAnnotation(QPainter &painter,
|
|
|
|
|
const QRect &eventRect,
|
|
|
|
|
QRectF *annotationRect,
|
|
|
|
|
const qreal fadeInOffset,
|
|
|
|
|
const qreal fadeOutOffset,
|
2017-10-05 10:03:25 +02:00
|
|
|
const QPointF &contentOffset) const;
|
2017-07-05 11:09:07 +02:00
|
|
|
struct AnnotationRects
|
|
|
|
|
{
|
2017-07-19 14:51:21 +02:00
|
|
|
QRectF fadeInRect;
|
2017-07-05 11:09:07 +02:00
|
|
|
QRectF annotationRect;
|
|
|
|
|
QRectF iconRect;
|
|
|
|
|
QRectF textRect;
|
2017-07-19 14:51:21 +02:00
|
|
|
QRectF fadeOutRect;
|
2017-07-05 11:09:07 +02:00
|
|
|
QString text;
|
|
|
|
|
};
|
2017-07-19 14:51:21 +02:00
|
|
|
AnnotationRects annotationRects(const QRectF &boundingRect, const QFontMetrics &fm,
|
|
|
|
|
const qreal fadeInOffset, const qreal fadeOutOffset) const;
|
2014-07-19 11:27:28 +02:00
|
|
|
/// called if the filename of the document changed
|
2019-05-28 13:49:26 +02:00
|
|
|
virtual void updateFileName(const Utils::FilePath &fileName);
|
2012-02-27 20:55:36 +01:00
|
|
|
virtual void updateLineNumber(int lineNumber);
|
|
|
|
|
virtual void updateBlock(const QTextBlock &block);
|
2014-07-09 17:18:03 +03:00
|
|
|
virtual void move(int line);
|
2012-02-27 20:55:36 +01:00
|
|
|
virtual void removedFromEditor();
|
2012-10-09 14:02:52 +02:00
|
|
|
virtual bool isClickable() const;
|
2012-05-02 13:10:14 +02:00
|
|
|
virtual void clicked();
|
2012-10-09 22:32:44 +02:00
|
|
|
virtual bool isDraggable() const;
|
|
|
|
|
virtual void dragToLine(int lineNumber);
|
2017-06-20 08:28:10 +02:00
|
|
|
void addToToolTipLayout(QGridLayout *target) const;
|
|
|
|
|
virtual bool addToolTipContent(QLayout *target) const;
|
2022-05-09 14:58:37 +02:00
|
|
|
virtual QColor annotationColor() const;
|
2012-05-02 13:10:14 +02:00
|
|
|
|
2020-09-24 10:14:57 +02:00
|
|
|
void setIcon(const QIcon &icon);
|
|
|
|
|
void setIconProvider(const std::function<QIcon()> &iconProvider);
|
|
|
|
|
const QIcon icon() const;
|
2012-03-30 11:40:31 +02:00
|
|
|
void updateMarker();
|
2017-06-01 08:48:11 +02:00
|
|
|
Priority priority() const { return m_priority;}
|
2017-06-26 14:39:13 +02:00
|
|
|
void setPriority(Priority prioriy);
|
2012-10-09 14:02:52 +02:00
|
|
|
bool isVisible() const;
|
|
|
|
|
void setVisible(bool isVisible);
|
2023-01-09 13:14:39 +01:00
|
|
|
TextMarkCategory category() const { return m_category; }
|
2012-02-27 20:55:36 +01:00
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<Utils::Theme::Color> color() const;
|
2017-06-01 08:48:11 +02:00
|
|
|
void setColor(const Utils::Theme::Color &color);
|
2014-07-18 15:29:04 +02:00
|
|
|
|
2017-06-01 08:48:11 +02:00
|
|
|
QString defaultToolTip() const { return m_defaultToolTip; }
|
|
|
|
|
void setDefaultToolTip(const QString &toolTip) { m_defaultToolTip = toolTip; }
|
|
|
|
|
|
|
|
|
|
TextDocument *baseTextDocument() const { return m_baseTextDocument; }
|
|
|
|
|
void setBaseTextDocument(TextDocument *baseTextDocument) { m_baseTextDocument = baseTextDocument; }
|
|
|
|
|
|
2017-06-20 08:28:10 +02:00
|
|
|
QString lineAnnotation() const { return m_lineAnnotation; }
|
2022-03-11 13:20:57 +01:00
|
|
|
void setLineAnnotation(const QString &lineAnnotation);
|
2017-06-20 08:28:10 +02:00
|
|
|
|
2020-09-24 10:14:57 +02:00
|
|
|
QString toolTip() const;
|
|
|
|
|
void setToolTip(const QString &toolTip);
|
|
|
|
|
void setToolTipProvider(const std::function<QString ()> &toolTipProvider);
|
2016-07-19 11:58:15 +02:00
|
|
|
|
2019-01-28 09:32:11 +01:00
|
|
|
QVector<QAction *> actions() const;
|
|
|
|
|
void setActions(const QVector<QAction *> &actions); // Takes ownership
|
2022-08-03 15:25:17 +02:00
|
|
|
void setActionsProvider(const std::function<QList<QAction *>()> &actionsProvider); // Takes ownership
|
2019-01-28 09:32:11 +01:00
|
|
|
|
2022-09-06 13:01:51 +02:00
|
|
|
bool isLocationMarker() const;;
|
|
|
|
|
void setIsLocationMarker(bool newIsLocationMarker);
|
|
|
|
|
|
2021-01-15 11:17:21 +01:00
|
|
|
protected:
|
|
|
|
|
void setSettingsPage(Utils::Id settingsPage);
|
|
|
|
|
|
2012-02-27 20:55:36 +01:00
|
|
|
private:
|
2014-07-19 11:27:28 +02:00
|
|
|
Q_DISABLE_COPY(TextMark)
|
|
|
|
|
|
2017-06-01 08:48:11 +02:00
|
|
|
TextDocument *m_baseTextDocument = nullptr;
|
2019-05-28 13:49:26 +02:00
|
|
|
Utils::FilePath m_fileName;
|
2017-06-01 08:48:11 +02:00
|
|
|
int m_lineNumber = 0;
|
|
|
|
|
Priority m_priority = LowPriority;
|
2022-09-06 13:01:51 +02:00
|
|
|
bool m_isLocationMarker = false;
|
2013-02-18 18:47:54 +01:00
|
|
|
QIcon m_icon;
|
2020-09-24 10:14:57 +02:00
|
|
|
std::function<QIcon()> m_iconProvider;
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<Utils::Theme::Color> m_color;
|
2017-07-18 23:15:52 +02:00
|
|
|
bool m_visible = false;
|
2023-01-09 13:14:39 +01:00
|
|
|
TextMarkCategory m_category;
|
2017-06-20 08:28:10 +02:00
|
|
|
QString m_lineAnnotation;
|
2016-07-19 11:58:15 +02:00
|
|
|
QString m_toolTip;
|
2020-09-24 10:14:57 +02:00
|
|
|
std::function<QString()> m_toolTipProvider;
|
2017-06-01 08:48:11 +02:00
|
|
|
QString m_defaultToolTip;
|
2022-08-03 15:25:17 +02:00
|
|
|
QVector<QAction *> m_actions; // FIXME Remove in master
|
|
|
|
|
std::function<QList<QAction *>()> m_actionsProvider;
|
|
|
|
|
Utils::Id m_settingsPage;
|
2012-02-27 20:55:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|