-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from PauloCarvalhoRJ/Issues20180311
Issues20180311
- Loading branch information
Showing
32 changed files
with
952 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "calccodeeditor.h" | ||
#include "calclinenumberarea.h" | ||
#include <QPainter> | ||
#include <QTextBlock> | ||
|
||
CalcCodeEditor::CalcCodeEditor(QWidget *parent) : QPlainTextEdit(parent) | ||
{ | ||
lineNumberArea = new CalcLineNumberArea(this); | ||
|
||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); | ||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); | ||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); | ||
|
||
updateLineNumberAreaWidth(0); | ||
highlightCurrentLine(); | ||
} | ||
|
||
int CalcCodeEditor::lineNumberAreaWidth() | ||
{ | ||
int digits = 1; | ||
int max = qMax(1, blockCount()); | ||
while (max >= 10) { | ||
max /= 10; | ||
++digits; | ||
} | ||
|
||
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; | ||
|
||
return space; | ||
} | ||
|
||
void CalcCodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) | ||
{ | ||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); | ||
} | ||
|
||
void CalcCodeEditor::updateLineNumberArea(const QRect &rect, int dy) | ||
{ | ||
if (dy) | ||
lineNumberArea->scroll(0, dy); | ||
else | ||
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); | ||
|
||
if (rect.contains(viewport()->rect())) | ||
updateLineNumberAreaWidth(0); | ||
} | ||
|
||
void CalcCodeEditor::resizeEvent(QResizeEvent *e) | ||
{ | ||
QPlainTextEdit::resizeEvent(e); | ||
|
||
QRect cr = contentsRect(); | ||
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); | ||
} | ||
|
||
void CalcCodeEditor::highlightCurrentLine() | ||
{ | ||
QList<QTextEdit::ExtraSelection> extraSelections; | ||
|
||
if (!isReadOnly()) { | ||
QTextEdit::ExtraSelection selection; | ||
|
||
QColor lineColor = QColor(Qt::yellow).lighter(160); | ||
|
||
selection.format.setBackground(lineColor); | ||
selection.format.setProperty(QTextFormat::FullWidthSelection, true); | ||
selection.cursor = textCursor(); | ||
selection.cursor.clearSelection(); | ||
extraSelections.append(selection); | ||
} | ||
|
||
setExtraSelections(extraSelections); | ||
} | ||
|
||
void CalcCodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) | ||
{ | ||
QPainter painter(lineNumberArea); | ||
painter.fillRect(event->rect(), Qt::lightGray); | ||
QTextBlock block = firstVisibleBlock(); | ||
/* The lineNumberAreaPaintEvent() is called from LineNumberArea whenever it receives a paint event. | ||
* We start off by painting the widget's background. */ | ||
int blockNumber = block.blockNumber(); | ||
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); | ||
int bottom = top + (int) blockBoundingRect(block).height(); | ||
/*We will now loop through all visible lines and paint the line numbers in the extra area for each line. | ||
* Notice that in a plain text edit each line will consist of one QTextBlock; though, if line wrapping | ||
* is enabled, a line may span several rows in the text edit's viewport. | ||
* We get the top and bottom y-coordinate of the first text block, and adjust these values by the height | ||
* of the current text block in each iteration in the loop. */ | ||
while (block.isValid() && top <= event->rect().bottom()) { | ||
if (block.isVisible() && bottom >= event->rect().top()) { | ||
QString number = QString::number(blockNumber + 1); | ||
painter.setPen(Qt::black); | ||
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), | ||
Qt::AlignRight, number); | ||
} | ||
block = block.next(); | ||
top = bottom; | ||
bottom = top + (int) blockBoundingRect(block).height(); | ||
++blockNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef CALCCODEEDITOR_H | ||
#define CALCCODEEDITOR_H | ||
|
||
#include <QPlainTextEdit> | ||
|
||
/** This class extends QPlainTextEdit to include script line numbers. */ | ||
class CalcCodeEditor : public QPlainTextEdit | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
CalcCodeEditor(QWidget *parent = 0); | ||
|
||
void lineNumberAreaPaintEvent(QPaintEvent *event); | ||
int lineNumberAreaWidth(); | ||
|
||
protected: | ||
void resizeEvent(QResizeEvent *event) override; | ||
|
||
private slots: | ||
void updateLineNumberAreaWidth(int newBlockCount); | ||
void highlightCurrentLine(); | ||
void updateLineNumberArea(const QRect &, int); | ||
|
||
private: | ||
QWidget *lineNumberArea; | ||
}; | ||
|
||
#endif // CALCCODEEDITOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "calclinenumberarea.h" | ||
#include "calccodeeditor.h" | ||
|
||
CalcLineNumberArea::CalcLineNumberArea(CalcCodeEditor *editor) : | ||
QWidget(editor) | ||
{ | ||
codeEditor = editor; | ||
} | ||
|
||
QSize CalcLineNumberArea::sizeHint() const | ||
{ | ||
return QSize(codeEditor->lineNumberAreaWidth(), 0); | ||
} | ||
|
||
void CalcLineNumberArea::paintEvent(QPaintEvent *event) | ||
{ | ||
codeEditor->lineNumberAreaPaintEvent(event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef CALCLINENUMBERAREA_H | ||
#define CALCLINENUMBERAREA_H | ||
|
||
#include <QWidget> | ||
|
||
class CalcCodeEditor; | ||
|
||
/** This class is a widget that draws the script line numbers in the editor. */ | ||
class CalcLineNumberArea : public QWidget | ||
{ | ||
|
||
Q_OBJECT | ||
|
||
public: | ||
explicit CalcLineNumberArea (CalcCodeEditor *editor); | ||
|
||
QSize sizeHint() const override; | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override; | ||
|
||
private: | ||
CalcCodeEditor *codeEditor; | ||
}; | ||
|
||
#endif // CALCLINENUMBERAREA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
#include "icalcpropertycollection.h" | ||
#include "icalcproperty.h" | ||
|
||
ICalcPropertyCollection::ICalcPropertyCollection() | ||
{ | ||
} | ||
|
||
int ICalcPropertyCollection::getCalcPropertyIndexByScriptCompatibleName(const std::string& name) | ||
{ | ||
int n = getCalcPropertyCount(); | ||
for( int i = 0; i < n; ++i){ | ||
ICalcProperty* prop = getCalcProperty( i ); | ||
if( prop->getScriptCompatibleName() == QString( name.c_str() )) | ||
return i; | ||
} | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.