Skip to content

Commit

Permalink
Github Issue #135: Added a context menu option to set/unset line wrap…
Browse files Browse the repository at this point in the history
…ping
  • Loading branch information
AngryFender committed Feb 21, 2024
1 parent bf6676a commit 854a8d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mkedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MkEdit::MkEdit(QWidget *parent):QTextEdit(parent){
selectAllAction.setText("Select All Ctrl+A");
selectBlockAction.setText("Copy Block");
disableMarkdown.setText("Disable Markdown");
lineWrapAction.setText("Disable line-wrap");

connect(&undoAction, &QAction::triggered, this, &MkEdit::undoContextMenu);
connect(&redoAction, &QAction::triggered, this, &MkEdit::redoContextMenu);
Expand All @@ -28,6 +29,7 @@ MkEdit::MkEdit(QWidget *parent):QTextEdit(parent){
connect(&selectAllAction, &QAction::triggered, this, &MkEdit::selectAll);
connect(&selectBlockAction, &QAction::triggered, this, &MkEdit::selectBlock);
connect(&disableMarkdown, &QAction::triggered,this, &MkEdit::diableMarkdown_internal);
connect(&lineWrapAction, &QAction::triggered,this, &MkEdit::lineWrapHandler);
connect(this, &MkEdit::customContextMenuRequested,
this, &MkEdit::contextMenuHandler);

Expand Down Expand Up @@ -378,6 +380,7 @@ void MkEdit::contextMenuHandler(QPoint pos)
menu.addAction(&selectAllAction);
menu.addSeparator();
menu.addAction(&disableMarkdown);
menu.addAction(&lineWrapAction);
menu.exec(viewport()->mapToGlobal(pos));
}

Expand Down Expand Up @@ -653,6 +656,7 @@ void MkEdit::setFont(const QFont &font)
selectAllAction.setFont(menuFont);
selectBlockAction.setFont(menuFont);
disableMarkdown.setFont(menuFont);
lineWrapAction.setFont(menuFont);

QTextEdit::setFont(font);
}
Expand Down Expand Up @@ -686,6 +690,17 @@ void MkEdit::diableMarkdown_internal()
}
}

void MkEdit::lineWrapHandler()
{
if("Enable line-wrap" == lineWrapAction.text()){
this->setLineWrapMode(QTextEdit::WidgetWidth);
lineWrapAction.setText("Disable line-wrap");
}else{
this->setLineWrapMode(QTextEdit::NoWrap);
lineWrapAction.setText("Enable line-wrap");
}
}

void MkEdit::cursorPositionChangedHandle()
{
int currentBlockNumber = textCursor().blockNumber();
Expand Down
3 changes: 2 additions & 1 deletion mkedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class MkEdit : public QTextEdit
QAction selectAllAction;
QAction selectBlockAction;
QAction disableMarkdown;
QAction lineWrapAction;
QPoint contextMenuPos;

QRegularExpression regexUrl;
Expand Down Expand Up @@ -118,7 +119,7 @@ class MkEdit : public QTextEdit
private slots:
void fileSaveHandle();
void diableMarkdown_internal();

void lineWrapHandler();
signals:
void cursorPosChanged(bool hasSelection, int blockNumber, QRect rect, SelectRange *selectRange);
void fileSave();
Expand Down

0 comments on commit 854a8d8

Please sign in to comment.