ui: Select code in code view with SHIFT + drag

bug id = 7
This commit is contained in:
Eberhard Graether
2016-09-21 11:23:47 +02:00
parent 589962b09e
commit 77cf33666f
8 changed files with 60 additions and 20 deletions
+6 -1
View File
@@ -117,6 +117,11 @@
</syntax>
<selection>
<text>black</text>
<background>#CCCCCC</background>
</selection>
<annotation>
<token>
<normal>
<border>transparent</border>
@@ -173,7 +178,7 @@
<fill>#987CEA</fill>
</focus>
</fulltext>
</selection>
</annotation>
</snippet>
</code>
+6 -1
View File
@@ -117,6 +117,11 @@
</syntax>
<selection>
<text>black</text>
<background>#E0E0E0</background>
</selection>
<annotation>
<token>
<normal>
<border>transparent</border>
@@ -171,7 +176,7 @@
<fill>#ABABDD</fill>
</focus>
</fulltext>
</selection>
</annotation>
</snippet>
</code>
+6 -1
View File
@@ -136,6 +136,11 @@
</syntax>
<selection>
<text>white</text>
<background>#777777</background>
</selection>
<annotation>
<token>
<normal>
<border>transparent</border>
@@ -193,7 +198,7 @@
<fill>#134B63</fill>
</focus>
</fulltext>
</selection>
</annotation>
</snippet>
</code>
+2
View File
@@ -95,6 +95,8 @@
color: <color:code/snippet/syntax/normal>;
font-family: "<setting:font_name>";
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 {
+4 -4
View File
@@ -102,19 +102,19 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const
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();
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)
{
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)
{
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())
+1 -1
View File
@@ -31,7 +31,7 @@ public:
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 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:
ColorScheme();
+33 -12
View File
@@ -91,6 +91,7 @@ QtCodeArea::QtCodeArea(
, m_code(code)
, m_locationFile(locationFile)
, m_digits(0)
, m_isSelecting(false)
, m_isPanning(false)
, m_setIDECursorPositionAction(nullptr)
, m_eventPosition(0, 0)
@@ -124,7 +125,6 @@ QtCodeArea::QtCodeArea(
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
this->setMouseTracking(true);
@@ -398,11 +398,22 @@ void QtCodeArea::leaveEvent(QEvent* event)
void QtCodeArea::mousePressEvent(QMouseEvent* event)
{
clearSelection();
if (event->button() == Qt::LeftButton)
{
m_isPanning = true;
m_oldMousePosition = event->pos();
m_panningDistance = 0;
if (Qt::KeyboardModifier::ShiftModifier & QApplication::keyboardModifiers())
{
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;
if (event->button() == Qt::LeftButton)
{
if (m_isSelecting)
{
m_isSelecting = false;
return;
}
m_isPanning = false;
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();
setIDECursorPosition();
@@ -434,7 +451,13 @@ void QtCodeArea::mouseReleaseEvent(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 int deltaX = currentMousePosition.x() - m_oldMousePosition.x();
@@ -449,7 +472,6 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
m_panningDistance += abs(deltaX + deltaY);
}
QTextCursor cursor = this->cursorForPosition(event->pos());
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(cursor.position());
@@ -824,8 +846,7 @@ std::vector<QRect> QtCodeArea::getCursorRectsForAnnotation(const Annotation& ann
{
std::vector<QRect> rects;
QTextCursor cursor = textCursor();
cursor.clearSelection();
QTextCursor cursor = QTextCursor(document());
cursor.setPosition(annotation.start);
QRect rectStart = cursorRect(cursor);
QRect rectEnd;
@@ -880,9 +901,9 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
for (const ColorScheme::ColorState& state : states)
{
AnnotationColor color;
color.border = scheme->getCodeSelectionTypeColor(type, "border", state);
color.fill = scheme->getCodeSelectionTypeColor(type, "fill", state);
color.text = scheme->getCodeSelectionTypeColor(type, "text", state);
color.border = scheme->getCodeAnnotationTypeColor(type, "border", state);
color.fill = scheme->getCodeAnnotationTypeColor(type, "fill", state);
color.text = scheme->getCodeAnnotationTypeColor(type, "text", state);
s_annotationColors.push_back(color);
}
}
+2
View File
@@ -177,6 +177,8 @@ private:
std::vector<const Annotation*> m_hoveredAnnotations;
int m_digits;
bool m_isSelecting;
bool m_isPanning;
QPoint m_oldMousePosition;
int m_panningDistance;