ui: Select code in code view with SHIFT + drag
bug id = 7
This commit is contained in:
@@ -117,6 +117,11 @@
|
|||||||
</syntax>
|
</syntax>
|
||||||
|
|
||||||
<selection>
|
<selection>
|
||||||
|
<text>black</text>
|
||||||
|
<background>#CCCCCC</background>
|
||||||
|
</selection>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
<token>
|
<token>
|
||||||
<normal>
|
<normal>
|
||||||
<border>transparent</border>
|
<border>transparent</border>
|
||||||
@@ -173,7 +178,7 @@
|
|||||||
<fill>#987CEA</fill>
|
<fill>#987CEA</fill>
|
||||||
</focus>
|
</focus>
|
||||||
</fulltext>
|
</fulltext>
|
||||||
</selection>
|
</annotation>
|
||||||
</snippet>
|
</snippet>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,11 @@
|
|||||||
</syntax>
|
</syntax>
|
||||||
|
|
||||||
<selection>
|
<selection>
|
||||||
|
<text>black</text>
|
||||||
|
<background>#E0E0E0</background>
|
||||||
|
</selection>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
<token>
|
<token>
|
||||||
<normal>
|
<normal>
|
||||||
<border>transparent</border>
|
<border>transparent</border>
|
||||||
@@ -171,7 +176,7 @@
|
|||||||
<fill>#ABABDD</fill>
|
<fill>#ABABDD</fill>
|
||||||
</focus>
|
</focus>
|
||||||
</fulltext>
|
</fulltext>
|
||||||
</selection>
|
</annotation>
|
||||||
</snippet>
|
</snippet>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,11 @@
|
|||||||
</syntax>
|
</syntax>
|
||||||
|
|
||||||
<selection>
|
<selection>
|
||||||
|
<text>white</text>
|
||||||
|
<background>#777777</background>
|
||||||
|
</selection>
|
||||||
|
|
||||||
|
<annotation>
|
||||||
<token>
|
<token>
|
||||||
<normal>
|
<normal>
|
||||||
<border>transparent</border>
|
<border>transparent</border>
|
||||||
@@ -193,7 +198,7 @@
|
|||||||
<fill>#134B63</fill>
|
<fill>#134B63</fill>
|
||||||
</focus>
|
</focus>
|
||||||
</fulltext>
|
</fulltext>
|
||||||
</selection>
|
</annotation>
|
||||||
</snippet>
|
</snippet>
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,8 @@
|
|||||||
color: <color:code/snippet/syntax/normal>;
|
color: <color:code/snippet/syntax/normal>;
|
||||||
font-family: "<setting:font_name>";
|
font-family: "<setting:font_name>";
|
||||||
font-size: <setting:font_size>px;
|
font-size: <setting:font_size>px;
|
||||||
|
selection-color: <color:code/snippet/selection/text>;
|
||||||
|
selection-background-color: <color:code/snippet/selection/background>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#code_file #maximize_button, #code_file #snippet_button, #code_file #minimize_button {
|
#code_file #maximize_button, #code_file #snippet_button, #code_file #minimize_button {
|
||||||
|
|||||||
@@ -102,19 +102,19 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const
|
|||||||
return getValue<std::string>("code/snippet/syntax/" + key, "#FFFFFF");
|
return getValue<std::string>("code/snippet/syntax/" + key, "#FFFFFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ColorScheme::getCodeSelectionTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const
|
std::string ColorScheme::getCodeAnnotationTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const
|
||||||
{
|
{
|
||||||
disableWarnings();
|
disableWarnings();
|
||||||
std::string color = getValue<std::string>("code/snippet/selection/" + typeStr + "/" + stateToString(state) + "/" + key, "");
|
std::string color = getValue<std::string>("code/snippet/annotation/" + typeStr + "/" + stateToString(state) + "/" + key, "");
|
||||||
|
|
||||||
if (!color.size() && state == ACTIVE)
|
if (!color.size() && state == ACTIVE)
|
||||||
{
|
{
|
||||||
color = getValue<std::string>("code/snippet/selection/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, "");
|
color = getValue<std::string>("code/snippet/annotation/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!color.size() && state != NORMAL)
|
if (!color.size() && state != NORMAL)
|
||||||
{
|
{
|
||||||
color = getValue<std::string>("code/snippet/selection/" + typeStr + "/" + stateToString(NORMAL) + "/" + key, "");
|
color = getValue<std::string>("code/snippet/annotation/" + typeStr + "/" + stateToString(NORMAL) + "/" + key, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!color.size())
|
if (!color.size())
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& key, const std::string& state = "normal") const;
|
std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& key, const std::string& state = "normal") const;
|
||||||
std::string getSyntaxColor(const std::string& key) const;
|
std::string getSyntaxColor(const std::string& key) const;
|
||||||
|
|
||||||
std::string getCodeSelectionTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const;
|
std::string getCodeAnnotationTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ColorScheme();
|
ColorScheme();
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ QtCodeArea::QtCodeArea(
|
|||||||
, m_code(code)
|
, m_code(code)
|
||||||
, m_locationFile(locationFile)
|
, m_locationFile(locationFile)
|
||||||
, m_digits(0)
|
, m_digits(0)
|
||||||
|
, m_isSelecting(false)
|
||||||
, m_isPanning(false)
|
, m_isPanning(false)
|
||||||
, m_setIDECursorPositionAction(nullptr)
|
, m_setIDECursorPositionAction(nullptr)
|
||||||
, m_eventPosition(0, 0)
|
, m_eventPosition(0, 0)
|
||||||
@@ -124,7 +125,6 @@ QtCodeArea::QtCodeArea(
|
|||||||
|
|
||||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
|
|
||||||
|
|
||||||
this->setMouseTracking(true);
|
this->setMouseTracking(true);
|
||||||
|
|
||||||
@@ -398,11 +398,22 @@ void QtCodeArea::leaveEvent(QEvent* event)
|
|||||||
|
|
||||||
void QtCodeArea::mousePressEvent(QMouseEvent* event)
|
void QtCodeArea::mousePressEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
|
clearSelection();
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
m_isPanning = true;
|
if (Qt::KeyboardModifier::ShiftModifier & QApplication::keyboardModifiers())
|
||||||
m_oldMousePosition = event->pos();
|
{
|
||||||
m_panningDistance = 0;
|
m_isSelecting = true;
|
||||||
|
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||||
|
setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_isPanning = true;
|
||||||
|
m_oldMousePosition = event->pos();
|
||||||
|
m_panningDistance = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,11 +422,17 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
|||||||
const int panningThreshold = 5;
|
const int panningThreshold = 5;
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
|
if (m_isSelecting)
|
||||||
|
{
|
||||||
|
m_isSelecting = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_isPanning = false;
|
m_isPanning = false;
|
||||||
|
|
||||||
if (m_panningDistance < panningThreshold) // dont do anything if mouse is release to end some real panning action.
|
if (m_panningDistance < panningThreshold) // dont do anything if mouse is release to end some real panning action.
|
||||||
{
|
{
|
||||||
if (Qt::KeyboardModifier::ControlModifier && QApplication::keyboardModifiers())
|
if (Qt::KeyboardModifier::ControlModifier & QApplication::keyboardModifiers())
|
||||||
{
|
{
|
||||||
m_eventPosition = event->pos();
|
m_eventPosition = event->pos();
|
||||||
setIDECursorPosition();
|
setIDECursorPosition();
|
||||||
@@ -434,7 +451,13 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
|||||||
|
|
||||||
void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (m_isPanning)
|
if (m_isSelecting)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = textCursor();
|
||||||
|
cursor.setPosition(this->cursorForPosition(event->pos()).position(), QTextCursor::KeepAnchor);
|
||||||
|
setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
else if (m_isPanning)
|
||||||
{
|
{
|
||||||
const QPoint currentMousePosition = event->pos();
|
const QPoint currentMousePosition = event->pos();
|
||||||
const int deltaX = currentMousePosition.x() - m_oldMousePosition.x();
|
const int deltaX = currentMousePosition.x() - m_oldMousePosition.x();
|
||||||
@@ -449,7 +472,6 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
|||||||
m_panningDistance += abs(deltaX + deltaY);
|
m_panningDistance += abs(deltaX + deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||||
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
|
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
|
||||||
|
|
||||||
@@ -824,8 +846,7 @@ std::vector<QRect> QtCodeArea::getCursorRectsForAnnotation(const Annotation& ann
|
|||||||
{
|
{
|
||||||
std::vector<QRect> rects;
|
std::vector<QRect> rects;
|
||||||
|
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = QTextCursor(document());
|
||||||
cursor.clearSelection();
|
|
||||||
cursor.setPosition(annotation.start);
|
cursor.setPosition(annotation.start);
|
||||||
QRect rectStart = cursorRect(cursor);
|
QRect rectStart = cursorRect(cursor);
|
||||||
QRect rectEnd;
|
QRect rectEnd;
|
||||||
@@ -880,9 +901,9 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
|
|||||||
for (const ColorScheme::ColorState& state : states)
|
for (const ColorScheme::ColorState& state : states)
|
||||||
{
|
{
|
||||||
AnnotationColor color;
|
AnnotationColor color;
|
||||||
color.border = scheme->getCodeSelectionTypeColor(type, "border", state);
|
color.border = scheme->getCodeAnnotationTypeColor(type, "border", state);
|
||||||
color.fill = scheme->getCodeSelectionTypeColor(type, "fill", state);
|
color.fill = scheme->getCodeAnnotationTypeColor(type, "fill", state);
|
||||||
color.text = scheme->getCodeSelectionTypeColor(type, "text", state);
|
color.text = scheme->getCodeAnnotationTypeColor(type, "text", state);
|
||||||
s_annotationColors.push_back(color);
|
s_annotationColors.push_back(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ private:
|
|||||||
std::vector<const Annotation*> m_hoveredAnnotations;
|
std::vector<const Annotation*> m_hoveredAnnotations;
|
||||||
|
|
||||||
int m_digits;
|
int m_digits;
|
||||||
|
|
||||||
|
bool m_isSelecting;
|
||||||
bool m_isPanning;
|
bool m_isPanning;
|
||||||
QPoint m_oldMousePosition;
|
QPoint m_oldMousePosition;
|
||||||
int m_panningDistance;
|
int m_panningDistance;
|
||||||
|
|||||||
Reference in New Issue
Block a user