From 77cf33666f3c3c30a30b8e71b2ec30cd9df35530 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 21 Sep 2016 11:23:47 +0200 Subject: [PATCH] ui: Select code in code view with SHIFT + drag bug id = 7 --- bin/app/data/color_schemes/bad_rainbow.xml | 7 +++- bin/app/data/color_schemes/bright.xml | 7 +++- bin/app/data/color_schemes/dark.xml | 7 +++- bin/app/data/gui/code_view/code_view.css | 2 + src/lib/settings/ColorScheme.cpp | 8 ++-- src/lib/settings/ColorScheme.h | 2 +- src/lib_gui/qt/element/QtCodeArea.cpp | 45 ++++++++++++++++------ src/lib_gui/qt/element/QtCodeArea.h | 2 + 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/bin/app/data/color_schemes/bad_rainbow.xml b/bin/app/data/color_schemes/bad_rainbow.xml index 1a8a6b80..e7064465 100644 --- a/bin/app/data/color_schemes/bad_rainbow.xml +++ b/bin/app/data/color_schemes/bad_rainbow.xml @@ -117,6 +117,11 @@ + black + #CCCCCC + + + transparent @@ -173,7 +178,7 @@ #987CEA - + diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index f8fcd2d5..c17a1e50 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -117,6 +117,11 @@ + black + #E0E0E0 + + + transparent @@ -171,7 +176,7 @@ #ABABDD - + diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 9159d01b..88fbe954 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -136,6 +136,11 @@ + white + #777777 + + + transparent @@ -193,7 +198,7 @@ #134B63 - + diff --git a/bin/app/data/gui/code_view/code_view.css b/bin/app/data/gui/code_view/code_view.css index 932b77a7..f77f5076 100644 --- a/bin/app/data/gui/code_view/code_view.css +++ b/bin/app/data/gui/code_view/code_view.css @@ -95,6 +95,8 @@ color: ; font-family: ""; font-size: px; + selection-color: ; + selection-background-color: ; } #code_file #maximize_button, #code_file #snippet_button, #code_file #minimize_button { diff --git a/src/lib/settings/ColorScheme.cpp b/src/lib/settings/ColorScheme.cpp index 39b86cf7..42e472d5 100644 --- a/src/lib/settings/ColorScheme.cpp +++ b/src/lib/settings/ColorScheme.cpp @@ -102,19 +102,19 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const return getValue("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("code/snippet/selection/" + typeStr + "/" + stateToString(state) + "/" + key, ""); + std::string color = getValue("code/snippet/annotation/" + typeStr + "/" + stateToString(state) + "/" + key, ""); if (!color.size() && state == ACTIVE) { - color = getValue("code/snippet/selection/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, ""); + color = getValue("code/snippet/annotation/" + typeStr + "/" + stateToString(FOCUS) + "/" + key, ""); } if (!color.size() && state != NORMAL) { - color = getValue("code/snippet/selection/" + typeStr + "/" + stateToString(NORMAL) + "/" + key, ""); + color = getValue("code/snippet/annotation/" + typeStr + "/" + stateToString(NORMAL) + "/" + key, ""); } if (!color.size()) diff --git a/src/lib/settings/ColorScheme.h b/src/lib/settings/ColorScheme.h index 55298b49..f846ab30 100644 --- a/src/lib/settings/ColorScheme.h +++ b/src/lib/settings/ColorScheme.h @@ -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(); diff --git a/src/lib_gui/qt/element/QtCodeArea.cpp b/src/lib_gui/qt/element/QtCodeArea.cpp index 1d6f0183..c1b51d47 100644 --- a/src/lib_gui/qt/element/QtCodeArea.cpp +++ b/src/lib_gui/qt/element/QtCodeArea.cpp @@ -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 annotations = getInteractiveAnnotationsForPosition(cursor.position()); @@ -824,8 +846,7 @@ std::vector QtCodeArea::getCursorRectsForAnnotation(const Annotation& ann { std::vector 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); } } diff --git a/src/lib_gui/qt/element/QtCodeArea.h b/src/lib_gui/qt/element/QtCodeArea.h index 0a2e3c7a..fbd4029e 100644 --- a/src/lib_gui/qt/element/QtCodeArea.h +++ b/src/lib_gui/qt/element/QtCodeArea.h @@ -177,6 +177,8 @@ private: std::vector m_hoveredAnnotations; int m_digits; + + bool m_isSelecting; bool m_isPanning; QPoint m_oldMousePosition; int m_panningDistance;