show line numbers

This commit is contained in:
royqh1979@gmail.com 2021-04-11 13:55:31 +08:00
parent 74b9b59bbd
commit 7600035d09
6 changed files with 76 additions and 1 deletions

View File

@ -1,2 +1,4 @@
# RedPanda-CPP
A light-weight C/C++ IDE based on Qt
This project is an attempt to port Red Panda Dev-C++ from delphi to Qt, to support non-windows systems.

View File

@ -47,12 +47,51 @@ Editor::Editor(QWidget *parent, const QString& filename,
//
QsciLexerCPP *lexer = new QsciLexerCPP();
lexer->setHighlightEscapeSequences(true);
lexer->setFoldComments(true);
this->setLexer(lexer);
this->setAutoIndent(pSettings->value(EDITOR_AUTO_INDENT).toBool());
this->setFolding(FoldStyle::BoxedTreeFoldStyle,3);
//行号显示区域
setMarginType(0, QsciScintilla::NumberMargin);
setMarginLineNumbers(0, true);
setMarginWidth(0,30);
//断点设置区域
setMarginType(1, QsciScintilla::SymbolMargin);
setMarginLineNumbers(1, false);
setMarginWidth(1,20);
setMarginSensitivity(1, true); //设置是否可以显示断点
setMarginsBackgroundColor(QColor("#bbfaae"));
setMarginMarkerMask(1, 0x02);
// connect(textEdit, SIGNAL(marginClicked(int, int, Qt::KeyboardModifiers)),this,
// SLOT(on_margin_clicked(int, int, Qt::KeyboardModifiers)));
markerDefine(QsciScintilla::Circle, 1);
setMarkerBackgroundColor(QColor("#ee1111"), 1);
//单步执行显示区域
setMarginType(2, QsciScintilla::SymbolMargin);
setMarginLineNumbers(2, false);
setMarginWidth(2, 20);
setMarginSensitivity(2, false);
setMarginMarkerMask(2, 0x04);
markerDefine(QsciScintilla::RightArrow, 2);
setMarkerBackgroundColor(QColor("#eaf593"), 2);
//自动折叠区域
setMarginType(3, QsciScintilla::SymbolMargin);
setMarginLineNumbers(3, false);
setMarginWidth(3, 15);
setMarginSensitivity(3, true);
// connect will fail if use new function pointer syntax
// connect(this, &QsciScintilla::modificationChanged,
// this, &Editor::onModificationChanged);
// connect(this , &QsciScintilla::cursorPositionChanged,
// this, &Editor::onCursorPositionChanged);
connect(this,SIGNAL(modificationChanged(bool)),
this,SLOT(onModificationChanged(bool)));
connect(this , SIGNAL(cursorPositionChanged(int,int)),
this, SLOT(onCursorPositionChanged(int,int)));
connect(this, SIGNAL(linesChanged()),
this,SLOT(onLinesChanged()));
}
Editor::~Editor() {
@ -194,10 +233,19 @@ void Editor::wheelEvent(QWheelEvent *event) {
}
void Editor::onModificationChanged(bool status) {
qDebug()<<"???";
updateCaption();
}
void Editor::onCursorPositionChanged(int line, int index)
{
pMainWindow->updateStatusBarForEditingInfo(line,index+1,lines(),text().length());
}
void Editor::onLinesChanged()
{
qDebug()<<"lala"<<lines();
}
void Editor::updateCaption(const QString& newCaption) {
if (mParentPageControl==NULL) {
return;

View File

@ -43,6 +43,8 @@ signals:
protected slots:
void onModificationChanged(bool status);
void onCursorPositionChanged(int line, int index);
void onLinesChanged();
private:
QByteArray mEncodingOption; // the encoding type set by the user

View File

@ -40,6 +40,16 @@ void MainWindow::updateStatusBarForEncoding() {
}
}
void MainWindow::updateStatusBarForEditingInfo(int line,int col,int lines,int charCount)
{
Editor * editor = mEditorList->getEditor();
if (editor!=NULL) {
mFileInfoStatus->setText(
QString(tr("Line: %1 Col: %2 Lines: %3 Chars: %4")).arg(line)
.arg(col).arg(lines).arg(charCount));
}
}
void MainWindow::setupActions() {
}

View File

@ -19,6 +19,7 @@ public:
~MainWindow();
void updateStatusBarForEncoding();
void updateStatusBarForEditingInfo(int line,int col,int lines,int charCount);
private slots:

View File

@ -115,17 +115,29 @@
<property name="currentIndex">
<number>-1</number>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<property name="movable">
<bool>true</bool>
</property>
</widget>
<widget class="QTabWidget" name="EditorTabsRight">
<property name="enabled">
<bool>true</bool>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<property name="movable">
<bool>true</bool>
</property>
</widget>
</widget>
</item>