Skip to content

Commit

Permalink
Github Issue #133: Code blocks shapes are improved with more precise …
Browse files Browse the repository at this point in the history
…variables.
  • Loading branch information
AngryFender committed Feb 18, 2024
1 parent 6135496 commit 6804490
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
25 changes: 16 additions & 9 deletions mkedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ void MkEdit::initialialCursorPosition()
void MkEdit::paintEvent(QPaintEvent *e)
{
QPainter painter(viewport());
painter.save();
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::TextAntialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);


int xBlock =0, yBlock =0;
int fontSize = this->document()->defaultFont().pointSizeF();
int scrollPos = this->verticalScrollBar()->value();
penCodeBlock.setColor(codeBlockColor);
painter.setBrush(brushDefault);
painter.setPen(penCodeBlock);

QAbstractTextDocumentLayout* layout = this->document()->documentLayout();
QRect rect = getVisibleRect();
Expand All @@ -84,42 +87,39 @@ void MkEdit::paintEvent(QPaintEvent *e)
QTextBlock nextBlock = block.next();
if(blockData){
if(blockData->getStatus()==BlockData::start){
xBlock = block.layout()->position().x()-2;
xBlock = this->x();
yBlock = block.layout()->position().y()-scrollPos - (fontSize*0.4);
}
else{
if(blockData->getStatus()==BlockData::end
|| (blockData->getStatus()==BlockData::content && layout->blockBoundingRect(nextBlock).bottom()>= (rect.bottom()+40))){
int height = block.layout()->position().y() - yBlock + (fontSize*0.6)-scrollPos;

QBrush brushDefault(codeBlockColor);
painter.setBrush(brushDefault);
painter.setPen(penCodeBlock);
painter.drawRoundedRect(xBlock,yBlock,widthCodeBlock,height,BLOCKRADIUS,BLOCKRADIUS);
}
}
}else{
LineData* lineData = dynamic_cast<LineData*>(data);
if(lineData){
if(lineData->getStatus() == LineData::horizontalLine && lineData->getDraw()){
int lineX1 = block.layout()->position().x()-2;
int lineX1 = this->x();
int lineY1 = block.layout()->position().y()+fontSize-scrollPos;
int lineX2 = block.layout()->position().x()-2+widthCodeBlock;
painter.setPen(penCodeBlock);
int lineX2 = this->x()+widthCodeBlock;
painter.drawLine(lineX1,lineY1,lineX2,lineY1);
}
}
}
}
block = block.next();
}
painter.restore();
QTextEdit::paintEvent(e);
}

void MkEdit::resizeEvent(QResizeEvent *event)
{
QTextEdit::resizeEvent(event);
widthCodeBlock = event->size().width() - this->verticalScrollBar()->width();
widthCodeBlock = event->size().width()+2 - this->verticalScrollBar()->width()/2;
}

void MkEdit::wheelEvent(QWheelEvent *e)
Expand Down Expand Up @@ -432,6 +432,13 @@ void MkEdit::blockColor(const QColor &color)
if (codeBlockColor != color) {
codeBlockColor = color;
emit blockColorChanged(codeBlockColor);

brushDefault.setColor(codeBlockColor);
brushDefault.setStyle(Qt::SolidPattern);

penCodeBlock.setColor(codeBlockColor);
penCodeBlock.setWidth(2);

update();
}
}
Expand Down
1 change: 1 addition & 0 deletions mkedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class MkEdit : public QTextEdit
private:
QColor codeBlockColor;
int widthCodeBlock;
QBrush brushDefault;
QPen penCodeBlock;
int savedCharacterNumber;
UndoData undoData;
Expand Down
6 changes: 4 additions & 2 deletions theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const QString lightTheme = QStringLiteral( "QMainWindow {"
" border-style: none;"
"}");

const QString darkTheme = QStringLiteral( "QMessageBox { background-color: #353535; } " "QMainWindow {"
const QString darkTheme = QStringLiteral( "QMessageBox { background-color: #353535; } "
"QMainWindow {"
" background-color:#353535;"
" border-color: transparent;"
"}"
Expand All @@ -144,7 +145,8 @@ const QString darkTheme = QStringLiteral( "QMessageBox { background-color: #3535
" border-style: none;"
" color: white;"
" selection-background-color: #3379B7;"
" padding-left:40; padding-top:10; padding-bottom:10; padding-right:40"
" margin-top:10; margin-bottom:10;"
" margin-left:40; margin-right:20;"
"}"
// "QLabel {"
// " background:#353535;"
Expand Down

0 comments on commit 6804490

Please sign in to comment.