2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2012-02-27 20:55:36 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-02-27 20:55:36 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-02-27 20:55:36 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-02-27 20:55:36 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2012-02-27 20:55:36 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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>
|
2020-01-03 14:43:35 +01:00
|
|
|
#include <utils/optional.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
#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
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-07-19 11:27:28 +02:00
|
|
|
class TEXTEDITOR_EXPORT TextMark
|
2012-02-27 20:55:36 +01:00
|
|
|
{
|
2021-02-02 16:24:21 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::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,
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id category,
|
2018-05-02 15:02:00 +02:00
|
|
|
double widthFactor = 1.0);
|
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);
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id category() const { return m_category; }
|
2012-05-02 13:10:14 +02:00
|
|
|
double widthFactor() const;
|
|
|
|
|
void setWidthFactor(double factor);
|
2012-02-27 20:55:36 +01:00
|
|
|
|
2020-01-03 14:43:35 +01:00
|
|
|
Utils::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
|
|
|
|
|
|
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;
|
2013-02-18 18:47:54 +01:00
|
|
|
QIcon m_icon;
|
2020-09-24 10:14:57 +02:00
|
|
|
std::function<QIcon()> m_iconProvider;
|
2020-01-03 14:43:35 +01:00
|
|
|
Utils::optional<Utils::Theme::Color> m_color;
|
2017-07-18 23:15:52 +02:00
|
|
|
bool m_visible = false;
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id m_category;
|
2017-06-01 08:48:11 +02:00
|
|
|
double m_widthFactor = 1.0;
|
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;
|
2019-01-28 09:32:11 +01:00
|
|
|
QVector<QAction *> m_actions;
|
2021-01-15 11:17:21 +01:00
|
|
|
QAction *m_settingsAction = nullptr;
|
2012-02-27 20:55:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|