editor line annotation

This commit is contained in:
Zira project 2019-12-25 01:05:29 +05:00
parent 6faa0d274f
commit b318c995cf
8 changed files with 217 additions and 29 deletions

50
README
View File

@ -1,23 +1,47 @@
Zira Editor is a lightweight PHP Editor for Linux with syntax highlighting and autocomplete.
If you're looking for Geany alternative for KDE, you should try Zira Editor.
It's written in QT and looks native in KDE. But it also can be run in Gnome.
It's written in QT and can be run in both KDE and Gnome.
Main features:
- syntax highlighting for PHP, JavaScript, CSS, HTML
- autocomplete (PHP built-in functions and classes / project classes, functions, variables / JS, CSS, HTML)
- unused variables highlighting (experimental)
- files tree
- low memory usage
- syntax highlighting
PHP
JavaScript
CSS
HTML
- autocomplete
PHP built-in functions and classes
project classes, functions, variables
JS objects, variables
CSS selectors, properties
HTML tags
- unused variables check
- files browser
- file symbols navigator
- matching braces, parentheses and tags highlighting
- function arguments tooltip
- F1 / Help : show functions and classes docs from PHP manual (download required)
- php lint support (syntax check)
- php code sniffer support
- git support
- highlight matching
brackets
tags
php expression (endif; endforeach;)
- function arguments display
- class auto import
- bulk comment in/out
- project state saving on exit
- F1 Help (PHP manual download required)
php function docs
php class docs
php class method docs
- php lint integration (syntax check)
- php code sniffer integration
- git integration
status browser
annotations display
- sass support
- quick access panel
- search in files
- quick access panel (search files + symbols)
- go to declaration
functions
classes
class methods
- search in files
- built-in colorpicker
- built-in light and dark themes
- custom themes support

View File

@ -63,7 +63,8 @@ SOURCES += \
src/settingsdialog.cpp \
src/helpdialog.cpp \
src/popup.cpp \
src/gitbrowser.cpp
src/gitbrowser.cpp \
src/annotation.cpp
HEADERS += \
include/mainwindow.h \
@ -104,7 +105,8 @@ HEADERS += \
include/settingsdialog.h \
include/helpdialog.h \
include/popup.h \
include/gitbrowser.h
include/gitbrowser.h \
include/annotation.h
FORMS += \
ui/mainwindow.ui \

26
include/annotation.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef ANNOTATION_H
#define ANNOTATION_H
#include <QWidget>
#include "editor.h"
class Annotation : public QWidget
{
Q_OBJECT
public:
explicit Annotation(Editor * editor, Settings * settings);
QSize sizeHint() const override;
void setText(QString text);
QString getText();
void setSize(int w, int h);
protected:
void mouseMoveEvent(QMouseEvent *event) override;
private:
Editor * editor;
QLabel * label;
signals:
public slots:
};
#endif // ANNOTATION_H

View File

@ -111,7 +111,9 @@ protected:
void updateWidgetsGeometry();
void setTabsSettings();
void updateViewportMargins();
void updateLineNumberArea();
void updateLineWidgetsArea();
void updateLineAnnotationView();
void showLineAnnotation();
QString cleanUpText(QString blockText);
void cleanForSave();
void showTooltip(int x, int y, QString text, bool richText = true, int fixedWidth = 0);
@ -160,8 +162,9 @@ protected slots:
void resizeEvent(QResizeEvent *event) override;
private slots:
void blockCountChanged(int);
void scrollbarValueChanged(int);
void scrollbarValueChangedDelayed();
void horizontalScrollbarValueChanged(int);
void verticalScrollbarValueChanged(int);
void verticalScrollbarValueChangedDelayed();
void textChanged();
void textChangedDelayed();
void cursorPositionChanged();
@ -213,6 +216,7 @@ private:
QWidget * search;
Highlight * highlight;
QWidget * breadcrumbs;
QWidget * lineAnnotation;
QFont editorFont;
QFont editorPopupFont;
@ -328,6 +332,7 @@ private:
QList<QTextEdit::ExtraSelection> wordsExtraSelections;
QList<QTextEdit::ExtraSelection> errorsExtraSelections;
bool experimentalMode;
int gitAnnotationLastLineNumber;
signals:
void ready(int index);
void statusBarText(int index, QString text);

50
src/annotation.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "annotation.h"
#include <QScrollBar>
Annotation::Annotation(Editor * editor, Settings * settings) :
QWidget(editor),
editor(editor)
{
setCursor(Qt::ArrowCursor);
setMouseTracking(true);
label = new QLabel(this);
label->setTextFormat(Qt::PlainText);
label->setWordWrap(false);
label->setAlignment(Qt::AlignRight);
label->setMinimumWidth(0);
label->setFont(editor->font());
label->setContentsMargins(0, 0, 0, 0);
label->setMargin(0);
label->setMouseTracking(true);
QString colorStr = QString::fromStdString(settings->get("highlight_single_line_comment_color"));
label->setStyleSheet("background:none;color:"+colorStr+";");
hide();
}
QSize Annotation::sizeHint() const {
return QSize(0, 0);
}
void Annotation::mouseMoveEvent(QMouseEvent */*event*/)
{
hide();
}
void Annotation::setText(QString text)
{
label->setText(text);
}
QString Annotation::getText()
{
return label->text();
}
void Annotation::setSize(int w, int h)
{
label->setFixedSize(w, h);
setFixedSize(w, h);
}

View File

@ -10,6 +10,7 @@
#include "linemap.h"
#include "breadcrumbs.h"
#include "completepopup.h"
#include "annotation.h"
#include "search.h"
#include <QScrollBar>
#include <QPainter>
@ -231,7 +232,8 @@ Editor::Editor(Settings * settings, HighlightWords * highlightWords, CompleteWor
// update area slots
connect(this->document(), SIGNAL(blockCountChanged(int)), this, SLOT(blockCountChanged(int)));
connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrollbarValueChanged(int)));
connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarValueChanged(int)));
connect(this->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(horizontalScrollbarValueChanged(int)));
connect(this, SIGNAL(textChanged()), this, SLOT(textChanged()));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
@ -273,12 +275,15 @@ Editor::Editor(Settings * settings, HighlightWords * highlightWords, CompleteWor
QShortcut * shortcutDelete = new QShortcut(QKeySequence(shortcutDeleteStr), this);
connect(shortcutDelete, SIGNAL(activated()), this, SLOT(deleteLine()));
// annotation
lineAnnotation = new Annotation(this, settings);
// line number area
lineNumber = new LineNumber(this);
// line mark area
lineMark = new LineMark(this);
// line map area
lineMap = new LineMap(this);
// breadcrumbs
breadcrumbs = new Breadcrumbs(this);
breadcrumbs->setFont(editorBreadcrumbsFont);
@ -437,6 +442,7 @@ void Editor::reset()
forwardPositions.clear();
lastCursorPositionBlockNumber = -1;
isParseError = false;
gitAnnotationLastLineNumber = -1;
}
void Editor::highlightProgressChanged(int percent)
@ -554,6 +560,8 @@ void Editor::setParseResult(ParseCSS::ParseResult result)
void Editor::setGitAnnotations(QHash<int, Git::Annotation> annotations)
{
gitAnnotations = annotations;
gitAnnotationLastLineNumber = -1;
showLineAnnotation();
}
int Editor::lineNumberAreaWidth()
@ -606,12 +614,79 @@ void Editor::updateViewportMargins()
setViewportMargins(lineW + markW, breadcrumbsH, mapW, searchH);
}
void Editor::updateLineNumberArea()
void Editor::updateLineWidgetsArea()
{
lineNumber->update();
lineMark->update();
}
void Editor::updateLineAnnotationView()
{
lineAnnotation->hide();
if (static_cast<Annotation *>(lineAnnotation)->getText().size() == 0) return;
int blockNumber = getFirstVisibleBlockIndex();
if (blockNumber < 0) return;
if (blockNumber>0) blockNumber--;
QTextBlock block = document()->findBlockByNumber(blockNumber);
//int top = viewport()->geometry().top();
int top = contentsMargins().top();
if (blockNumber == 0) {
top += document()->documentMargin() - verticalScrollBar()->sliderPosition();
} else {
QTextBlock prev_block = document()->findBlockByNumber(blockNumber-1);
int prev_y = static_cast<int>(document()->documentLayout()->blockBoundingRect(prev_block).y());
int prev_h = static_cast<int>(document()->documentLayout()->blockBoundingRect(prev_block).height());
top += prev_y + prev_h - verticalScrollBar()->sliderPosition();
}
int bottom = top + static_cast<int>(document()->documentLayout()->blockBoundingRect(block).height());
while (block.isValid()) {
if (block.isVisible() && block.blockNumber() == textCursor().block().blockNumber()) {
int y = top;
if (breadcrumbs->isVisible()) y += breadcrumbs->geometry().height();
int x = static_cast<int>(document()->documentLayout()->blockBoundingRect(block).width());
x += lineNumber->geometry().width() + lineMark->geometry().width();
x += 50;
QFontMetrics fm(lineAnnotation->font());
int tw = fm.width(static_cast<Annotation *>(lineAnnotation)->getText());
int bw = geometry().width() - lineMap->geometry().width();
bw -= 10;
if (x + tw < bw) x += bw - x - tw;
if (horizontalScrollBar()->isVisible()) x -= horizontalScrollBar()->value();
lineAnnotation->move(x, y);
static_cast<Annotation *>(lineAnnotation)->setSize(tw, bottom - top);
lineAnnotation->show();
break;
}
block = block.next();
top = bottom;
bottom = top + static_cast<int>(document()->documentLayout()->blockBoundingRect(block).height());
blockNumber++;
}
}
void Editor::showLineAnnotation()
{
if (gitAnnotations.size() == 0) return;
QTextBlock block = textCursor().block();
int line = block.blockNumber() + 1;
if (gitAnnotationLastLineNumber == line) {
static_cast<Annotation *>(lineAnnotation)->setText("");
return;
}
if (gitAnnotations.contains(line)) {
Git::Annotation annotation = gitAnnotations.value(line);
QString annotationText = tr("Git") + ": " + annotation.comment + " / " + annotation.committer + " [" + annotation.committerDate + "]";
static_cast<Annotation *>(lineAnnotation)->setText(annotationText);
updateLineAnnotationView();
gitAnnotationLastLineNumber = line;
}
}
std::string Editor::getTabType()
{
return tabType;
@ -1860,8 +1935,8 @@ void Editor::insertFromMimeData(const QMimeData *source)
void Editor::blockCountChanged(int /*blockCount*/)
{
updateViewportMargins();
updateLineNumberArea();
updateLineWidgetsArea();
lineAnnotation->hide();
// updating mark points
markPoints.clear();
QTextCursor curs = textCursor();
@ -1876,10 +1951,16 @@ void Editor::blockCountChanged(int /*blockCount*/)
emit statusBarText(tabIndex, ""); // update status bar
}
void Editor::scrollbarValueChanged(int /* sliderPos */)
void Editor::horizontalScrollbarValueChanged(int /* sliderPos */)
{
updateLineAnnotationView();
}
void Editor::verticalScrollbarValueChanged(int /* sliderPos */)
{
hidePopups();
updateLineNumberArea();
updateLineWidgetsArea();
updateLineAnnotationView();
lineMap->update();
if (is_ready && !scrollBarValueChangeLocked) {
@ -1888,7 +1969,7 @@ void Editor::scrollbarValueChanged(int /* sliderPos */)
}
}
void Editor::scrollbarValueChangedDelayed()
void Editor::verticalScrollbarValueChangedDelayed()
{
highlight->updateBlocks(getLastVisibleBlockIndex());
scrollBarValueChangeLocked = false;
@ -3699,6 +3780,7 @@ void Editor::cursorPositionChanged()
highlightCurrentLine(& extraSelections);
}
setExtraSelections(extraSelections);
lineAnnotation->hide();
if (!cursorPositionChangeLocked) {
cursorPositionChangeLocked = true;
QTimer::singleShot(INTERVAL_CURSOR_POS_CHANGED_MILLISECONDS, this, SLOT(cursorPositionChangedDelayed()));
@ -3811,6 +3893,7 @@ void Editor::cursorPositionChangedDelayed()
}
setBreadcrumbsText(scopeName.trimmed());
}
showLineAnnotation();
if (isReady()) emit statusBarText(tabIndex, ""); // update status bar
}
@ -5057,9 +5140,8 @@ void Editor::showLineNumber(int y)
if (block.isVisible() && top < y && bottom > y) {
int line = blockNumber + 1;
if (gitAnnotations.contains(line)) {
tooltipText = "";
Git::Annotation annotation = gitAnnotations.value(line);
tooltipText += tr("Line") + " " + Helper::intToStr(annotation.line) + ": " + annotation.committer + " [" + annotation.committerDate + "] \"" + annotation.comment.replace("\n"," ") + "\"";
tooltipText = tr("Line") + " " + Helper::intToStr(annotation.line) + ": " + annotation.comment + "\n" + annotation.committer + " [" + annotation.committerDate + "]";
}
break;
}

View File

@ -5,7 +5,6 @@
*******************************************/
#include "linemap.h"
#include "helper.h"
LineMap::LineMap(Editor * codeEditor) : QWidget(codeEditor)
{

View File

@ -5,7 +5,7 @@
*******************************************/
#include "linenumber.h"
#include "helper.h"
LineNumber::LineNumber(Editor * codeEditor) : QWidget(codeEditor)
{
editor = codeEditor;