- enhancement: drag & drop text in the editor
- enhancement: auto calcuate caret line size basing on font size - enhancement: shift+mouse wheel to scroll horizontally
This commit is contained in:
parent
33ba4afc20
commit
a6e8846282
3
NEWS.md
3
NEWS.md
|
@ -3,6 +3,9 @@ Version 0.8.7 For Dev-C++ 7 Beta
|
||||||
- fix: when enter '{' or '}' at beginning of line, auto indent will remove all contents of the line
|
- fix: when enter '{' or '}' at beginning of line, auto indent will remove all contents of the line
|
||||||
- fix: auto indent should be turned off when reformat code
|
- fix: auto indent should be turned off when reformat code
|
||||||
- fix: auto indent should be turned off when replace in code
|
- fix: auto indent should be turned off when replace in code
|
||||||
|
- enhancement: drag & drop text in the editor
|
||||||
|
- enhancement: auto calcuate caret line size basing on font size
|
||||||
|
- enhancement: shift+mouse wheel to scroll horizontally
|
||||||
|
|
||||||
Version 0.8.6 For Dev-C++ 7 Beta
|
Version 0.8.6 For Dev-C++ 7 Beta
|
||||||
- enhancement: greatly reduces memory usage for symbol parsing ( memory needed for bits/stdc++.h reduced from 150m+ to 80m+)
|
- enhancement: greatly reduces memory usage for symbol parsing ( memory needed for bits/stdc++.h reduced from 150m+ to 80m+)
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QStyleHints>
|
#include <QStyleHints>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
|
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
|
||||||
{
|
{
|
||||||
|
@ -142,6 +144,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
|
||||||
setAttribute(Qt::WA_InputMethodEnabled);
|
setAttribute(Qt::WA_InputMethodEnabled);
|
||||||
|
|
||||||
//setMouseTracking(true);
|
//setMouseTracking(true);
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SynEdit::displayLineCount() const
|
int SynEdit::displayLineCount() const
|
||||||
|
@ -1208,6 +1211,8 @@ void SynEdit::showCaret()
|
||||||
{
|
{
|
||||||
if (m_blinkTimerId==0)
|
if (m_blinkTimerId==0)
|
||||||
m_blinkTimerId = startTimer(500);
|
m_blinkTimerId = startTimer(500);
|
||||||
|
m_blinkStatus = 1;
|
||||||
|
updateCaret();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::hideCaret()
|
void SynEdit::hideCaret()
|
||||||
|
@ -3580,25 +3585,40 @@ void SynEdit::paintCaret(QPainter &painter, const QRect rcClip)
|
||||||
} else {
|
} else {
|
||||||
ct =mOverwriteCaret;
|
ct =mOverwriteCaret;
|
||||||
}
|
}
|
||||||
|
QColor caretColor;
|
||||||
if (mCaretUseTextColor) {
|
if (mCaretUseTextColor) {
|
||||||
painter.setPen(mForegroundColor);
|
caretColor = mForegroundColor;
|
||||||
} else {
|
} else {
|
||||||
painter.setPen(mCaretColor);
|
caretColor = mCaretColor;
|
||||||
}
|
}
|
||||||
switch(ct) {
|
switch(ct) {
|
||||||
case SynEditCaretType::ctVerticalLine:
|
case SynEditCaretType::ctVerticalLine: {
|
||||||
painter.drawLine(rcClip.left()+1,rcClip.top(),rcClip.left()+1,rcClip.bottom());
|
QRect caretRC;
|
||||||
|
int size = std::max(1,(rcClip.bottom()-rcClip.top())/15);
|
||||||
|
caretRC.setLeft(rcClip.left()+1);
|
||||||
|
caretRC.setTop(rcClip.top());
|
||||||
|
caretRC.setBottom(rcClip.bottom());
|
||||||
|
caretRC.setRight(rcClip.left()+1+size);
|
||||||
|
painter.fillRect(caretRC,caretColor);
|
||||||
break;
|
break;
|
||||||
case SynEditCaretType::ctHorizontalLine:
|
}
|
||||||
painter.drawLine(rcClip.left(),rcClip.bottom()-1,rcClip.right(),rcClip.bottom()-1);
|
case SynEditCaretType::ctHorizontalLine: {
|
||||||
|
QRect caretRC;
|
||||||
|
int size = std::max(1,(rcClip.bottom()-rcClip.top())/15);
|
||||||
|
caretRC.setLeft(rcClip.left());
|
||||||
|
caretRC.setTop(rcClip.bottom()-1+size);
|
||||||
|
caretRC.setBottom(rcClip.bottom()-1);
|
||||||
|
caretRC.setRight(rcClip.right());
|
||||||
|
painter.fillRect(caretRC,caretColor);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SynEditCaretType::ctBlock:
|
case SynEditCaretType::ctBlock:
|
||||||
painter.fillRect(rcClip, mCaretColor);
|
painter.fillRect(rcClip, caretColor);
|
||||||
break;
|
break;
|
||||||
case SynEditCaretType::ctHalfBlock:
|
case SynEditCaretType::ctHalfBlock:
|
||||||
QRect rc=rcClip;
|
QRect rc=rcClip;
|
||||||
rc.setTop(rcClip.top()+rcClip.height() / 2);
|
rc.setTop(rcClip.top()+rcClip.height() / 2);
|
||||||
painter.fillRect(rcClip, mCaretColor);
|
painter.fillRect(rcClip, caretColor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5899,7 +5919,7 @@ void SynEdit::mousePressEvent(QMouseEvent *event)
|
||||||
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false);
|
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false);
|
||||||
if (bWasSel && mOptions.testFlag(eoDragDropEditing) && (X >= mGutterWidth + 2)
|
if (bWasSel && mOptions.testFlag(eoDragDropEditing) && (X >= mGutterWidth + 2)
|
||||||
&& (mSelectionMode == SynSelectionMode::smNormal) && isPointInSelection(displayToBufferPos(pixelsToRowColumn(X, Y))) ) {
|
&& (mSelectionMode == SynSelectionMode::smNormal) && isPointInSelection(displayToBufferPos(pixelsToRowColumn(X, Y))) ) {
|
||||||
bStartDrag = true;
|
bStartDrag = true;
|
||||||
}
|
}
|
||||||
if (bStartDrag) {
|
if (bStartDrag) {
|
||||||
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging);
|
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging);
|
||||||
|
@ -5959,7 +5979,15 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
|
||||||
if ((mStateFlags.testFlag(SynStateFlag::sfWaitForDragging))) {
|
if ((mStateFlags.testFlag(SynStateFlag::sfWaitForDragging))) {
|
||||||
if ( ( event->pos() - mMouseDownPos).manhattanLength()>=QApplication::startDragDistance()) {
|
if ( ( event->pos() - mMouseDownPos).manhattanLength()>=QApplication::startDragDistance()) {
|
||||||
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging);
|
mStateFlags.setFlag(SynStateFlag::sfWaitForDragging,false);
|
||||||
|
QDrag *drag = new QDrag(this);
|
||||||
|
QMimeData *mimeData = new QMimeData;
|
||||||
|
|
||||||
|
mimeData->setText(selText());
|
||||||
|
drag->setMimeData(mimeData);
|
||||||
|
|
||||||
|
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||||
|
//drag->setPixmap(iconPixmap);
|
||||||
//BeginDrag(false);
|
//BeginDrag(false);
|
||||||
}
|
}
|
||||||
// } else if ((buttons == Qt::LeftButton) && (X > mGutterWidth)) {
|
// } else if ((buttons == Qt::LeftButton) && (X > mGutterWidth)) {
|
||||||
|
@ -6017,14 +6045,26 @@ void SynEdit::leaveEvent(QEvent *)
|
||||||
|
|
||||||
void SynEdit::wheelEvent(QWheelEvent *event)
|
void SynEdit::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (event->angleDelta().y()>0) {
|
if (event->modifiers() == Qt::ShiftModifier) {
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->value()-mMouseWheelScrollSpeed);
|
if (event->angleDelta().y()>0) {
|
||||||
event->accept();
|
horizontalScrollBar()->setValue(horizontalScrollBar()->value()-mMouseWheelScrollSpeed);
|
||||||
return;
|
event->accept();
|
||||||
} else if (event->angleDelta().y()<0) {
|
return;
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->value()+mMouseWheelScrollSpeed);
|
} else if (event->angleDelta().y()<0) {
|
||||||
event->accept();
|
horizontalScrollBar()->setValue(horizontalScrollBar()->value()+mMouseWheelScrollSpeed);
|
||||||
return;
|
event->accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (event->angleDelta().y()>0) {
|
||||||
|
verticalScrollBar()->setValue(verticalScrollBar()->value()-mMouseWheelScrollSpeed);
|
||||||
|
event->accept();
|
||||||
|
return;
|
||||||
|
} else if (event->angleDelta().y()<0) {
|
||||||
|
verticalScrollBar()->setValue(verticalScrollBar()->value()+mMouseWheelScrollSpeed);
|
||||||
|
event->accept();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QAbstractScrollArea::wheelEvent(event);
|
QAbstractScrollArea::wheelEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -6052,6 +6092,63 @@ QVariant SynEdit::inputMethodQuery(Qt::InputMethodQuery property) const
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SynEdit::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("text/plain")) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
mDragCaretSave = caretXY();
|
||||||
|
mDragSelBeginSave = blockBegin();
|
||||||
|
mDragSelEndSave = blockEnd();
|
||||||
|
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
||||||
|
event->pos().y()));
|
||||||
|
setCaretXY(coord);
|
||||||
|
setBlockBegin(mDragSelBeginSave);
|
||||||
|
setBlockEnd(mDragSelEndSave);
|
||||||
|
showCaret();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynEdit::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
mUndoList->BeginBlock();
|
||||||
|
auto action = finally([this] {
|
||||||
|
mUndoList->EndBlock();
|
||||||
|
});
|
||||||
|
if (event->proposedAction() == Qt::DropAction::MoveAction) {
|
||||||
|
setBlockBegin(mDragSelBeginSave);
|
||||||
|
setBlockEnd(mDragSelEndSave);
|
||||||
|
setSelText("");
|
||||||
|
}
|
||||||
|
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
||||||
|
event->pos().y()));
|
||||||
|
setCaretXY(coord);
|
||||||
|
setSelText(event->mimeData()->text());
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
|
if (event->keyboardModifiers() == Qt::ControlModifier) {
|
||||||
|
event->setDropAction(Qt::CopyAction);
|
||||||
|
} else {
|
||||||
|
event->setDropAction(Qt::MoveAction);
|
||||||
|
}
|
||||||
|
BufferCoord coord = displayToBufferPos(pixelsToNearestRowColumn(event->pos().x(),
|
||||||
|
event->pos().y()));
|
||||||
|
setCaretXY(coord);
|
||||||
|
setBlockBegin(mDragSelBeginSave);
|
||||||
|
setBlockEnd(mDragSelEndSave);
|
||||||
|
showCaret();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynEdit::dragLeaveEvent(QDragLeaveEvent *event)
|
||||||
|
{
|
||||||
|
setCaretXY(mDragCaretSave);
|
||||||
|
setBlockBegin(mDragSelBeginSave);
|
||||||
|
setBlockEnd(mDragSelEndSave);
|
||||||
|
showCaret();
|
||||||
|
}
|
||||||
|
|
||||||
int SynEdit::maxScrollHeight() const
|
int SynEdit::maxScrollHeight() const
|
||||||
{
|
{
|
||||||
if (mOptions.testFlag(eoScrollPastEof))
|
if (mOptions.testFlag(eoScrollPastEof))
|
||||||
|
|
|
@ -696,6 +696,10 @@ private:
|
||||||
|
|
||||||
int mMouseWheelScrollSpeed;
|
int mMouseWheelScrollSpeed;
|
||||||
|
|
||||||
|
BufferCoord mDragCaretSave;
|
||||||
|
BufferCoord mDragSelBeginSave;
|
||||||
|
BufferCoord mDragSelEndSave;
|
||||||
|
|
||||||
friend class SynEditTextPainter;
|
friend class SynEditTextPainter;
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
|
@ -722,6 +726,13 @@ bool viewportEvent(QEvent * event) override;
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
public:
|
public:
|
||||||
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
|
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
|
||||||
|
|
||||||
|
// QWidget interface
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYNEDIT_H
|
#endif // SYNEDIT_H
|
||||||
|
|
Loading…
Reference in New Issue