Commit 3639663c authored by Kåre Särs's avatar Kåre Särs
Browse files

Fix minimap dragging with QtCurve.

Translate minimap-sliders y-coordinates to standard coordinates on small files.

BUG: 311685
FIXED-IN 4.10.1
parent 32f6ef4a
......@@ -154,9 +154,47 @@ QSize KateScrollBar::sizeHint() const
return QScrollBar::sizeHint();
}
int KateScrollBar::minimapYToStdY(int y)
{
// Check if the minimap fills the whole scrollbar
if (m_stdGroveRect.height() == m_mapGroveRect.height()){
return y;
}
// check if y is on the step up/down
if ((y < m_stdGroveRect.top()) || (y > m_stdGroveRect.bottom())) {
return y;
}
if (y < m_mapGroveRect.top()) {
return m_stdGroveRect.top() + 1;
}
if (y > m_mapGroveRect.bottom()) {
return m_stdGroveRect.bottom() - 1;
}
// check for div/0
if (m_mapGroveRect.height() == 0) {
return y;
}
int newY = (y - m_mapGroveRect.top()) * m_stdGroveRect.height() / m_mapGroveRect.height();
newY += m_stdGroveRect.top();
return newY;
}
void KateScrollBar::mousePressEvent(QMouseEvent* e)
{
QScrollBar::mousePressEvent(e);
if (m_showMiniMap) {
QMouseEvent eMod(QEvent::MouseButtonPress,
QPoint(6, minimapYToStdY(e->pos().y())),
e->button(), e->buttons(), e->modifiers());
QScrollBar::mousePressEvent(&eMod);
}
else {
QScrollBar::mousePressEvent(e);
}
if (e->button() == Qt::MidButton)
m_middleMouseDown = true;
......@@ -184,12 +222,28 @@ void KateScrollBar::mouseReleaseEvent(QMouseEvent* e)
QToolTip::hideText();
}
QScrollBar::mouseReleaseEvent(e);
if (m_showMiniMap) {
QMouseEvent eMod(QEvent::MouseButtonRelease,
QPoint(e->pos().x(), minimapYToStdY(e->pos().y())),
e->button(), e->buttons(), e->modifiers());
QScrollBar::mouseReleaseEvent(&eMod);
}
else {
QScrollBar::mouseReleaseEvent(e);
}
}
void KateScrollBar::mouseMoveEvent(QMouseEvent* e)
{
QScrollBar::mouseMoveEvent(e);
if (m_showMiniMap) {
QMouseEvent eMod(QEvent::MouseMove,
QPoint(e->pos().x(), minimapYToStdY(e->pos().y())),
e->button(), e->buttons(), e->modifiers());
QScrollBar::mouseMoveEvent(&eMod);
}
else {
QScrollBar::mouseMoveEvent(e);
}
if (e->buttons() & (Qt::LeftButton | Qt::MidButton)) {
redrawMarks();
......@@ -437,6 +491,7 @@ void KateScrollBar::miniMapPaintEvent(QPaintEvent *e)
int docXMargin = 1;
QRect grooveRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarGroove, this);
m_stdGroveRect = grooveRect;
if (style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSubLine, this).height() == 0) {
int alignMargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &opt, this);
grooveRect.moveTop(alignMargin);
......@@ -449,6 +504,7 @@ void KateScrollBar::miniMapPaintEvent(QPaintEvent *e)
m_grooveHeight = grooveRect.height();
QRect sliderRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, QStyle::SC_ScrollBarSlider, this);
m_stdSliderRect = sliderRect;
sliderRect.adjust(docXMargin+1, 1, -(docXMargin+1), -1);
//style()->drawControl(QStyle::CE_ScrollBarAddLine, &opt, &painter, this);
......@@ -458,6 +514,7 @@ void KateScrollBar::miniMapPaintEvent(QPaintEvent *e)
int docHeight = qMin(grooveRect.height(), m_pixmap.height()*2) - 2*docXMargin;
int yoffset = (grooveRect.height() - docHeight) / 2;
QRect docRect(QPoint(grooveRect.left()+docXMargin, yoffset+grooveRect.top()), QSize(grooveRect.width()-2*docXMargin, docHeight));
m_mapGroveRect = docRect;
// calculate the visible area
int max = qMax(maximum()+1, 1);
......@@ -466,6 +523,7 @@ void KateScrollBar::miniMapPaintEvent(QPaintEvent *e)
QRect visibleRect = docRect;
visibleRect.moveTop(visibleStart);
visibleRect.setHeight(visibleEnd-visibleStart);
m_mapSliderRect = visibleRect;
// calculate colors
QColor backgroundColor = m_doc->defaultStyle(KTextEditor::HighlightInterface::dsNormal)->background().color();
......
......@@ -112,6 +112,8 @@ Q_SIGNALS:
void miniMapPaintEvent(QPaintEvent *e);
void normalPaintEvent(QPaintEvent *e);
int minimapYToStdY(int y);
const QColor charColor(const QVector<int> &attributes, int &attributeIndex,
const QList<QTextLayout::FormatRange> &decorations,
const QColor &defaultColor, int x, QChar ch);
......@@ -132,6 +134,10 @@ Q_SIGNALS:
QPixmap m_pixmap;
int m_grooveHeight;
QRect m_stdGroveRect;
QRect m_mapGroveRect;
QRect m_stdSliderRect;
QRect m_mapSliderRect;
QTimer m_updateTimer;
QPoint m_toolTipPos;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment