| 1 | /* |
| 2 | * Copyright (C) 2016, Mike Walters <[email protected]> |
| 3 | * |
| 4 | * This file is part of inspectrum. |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <QApplication> |
| 21 | #include <QDebug> |
| 22 | #include "cursors.h"cxx . . $ `<file>/src/cursors.h`/ |
| 23 | |
| 24 | Cursorscxx . . $ Cursors#::Cursorscxx . . $ Cursors#Cursors(749de1b6ae65bddd).(QObjectcxx . . $ QObject# * parent) : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).::QObjectcxx . . $ QObject#(parent) |
| 25 | { |
| 26 | minCursorcxx . . $ Cursors#minCursor. = new Cursorcxx . . $ Cursor#(Qtcxx . . $ Qt/::Verticalcxx . . $ Qt/Vertical., Qtcxx . . $ Qt/::SizeHorCursorcxx . . $ Qt/SizeHorCursor., this); |
| 27 | maxCursorcxx . . $ Cursors#maxCursor. = new Cursorcxx . . $ Cursor#(Qtcxx . . $ Qt/::Verticalcxx . . $ Qt/Vertical., Qtcxx . . $ Qt/::SizeHorCursorcxx . . $ Qt/SizeHorCursor., this); |
| 28 | connectcxx . . $ QObject#connect(835f87066c895669).(minCursorcxx . . $ Cursors#minCursor., &Cursorcxx . . $ Cursor#::posChangedcxx . . $ Cursor#posChanged(49f6e7a06ebc5aa8)., this, &Cursorscxx . . $ Cursors#::cursorMovedcxx . . $ Cursors#cursorMoved(49f6e7a06ebc5aa8).); |
| 29 | connectcxx . . $ QObject#connect(835f87066c895669).(maxCursorcxx . . $ Cursors#maxCursor., &Cursorcxx . . $ Cursor#::posChangedcxx . . $ Cursor#posChanged(49f6e7a06ebc5aa8)., this, &Cursorscxx . . $ Cursors#::cursorMovedcxx . . $ Cursors#cursorMoved(49f6e7a06ebc5aa8).); |
| 30 | } |
| 31 | |
| 32 | void Cursorscxx . . $ Cursors#::cursorMovedcxx . . $ Cursors#cursorMoved(49f6e7a06ebc5aa8).() |
| 33 | { |
| 34 | // Swap cursors if one has been dragged past the other |
| 35 | if (minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).() > maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).()) { |
| 36 | stdcxx . . $ std/::swapcxx . . $ std/swap(fd14d5ffdc2aa84d).(minCursorcxx . . $ Cursors#minCursor., maxCursorcxx . . $ Cursors#maxCursor.); |
| 37 | } |
| 38 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! cursorsMovedcxx . . $ Cursors#cursorsMoved(49f6e7a06ebc5aa8).(); |
| 39 | } |
| 40 | |
| 41 | bool Cursorscxx . . $ Cursors#::pointWithinDragRegioncxx . . $ Cursors#pointWithinDragRegion(578814ae554e72f6).(QPointcxx . . $ QPoint# point) { |
| 42 | int margin = 10; |
| 43 | range_tcxx . . $ range_t#<int> range = {minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).()+margin, maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).()-margin}; |
| 44 | return range.containscxx . . $ range_t#contains(8877ebe272b9620d).(point.xcxx . . $ QPoint#x(455f465bc33b4cdf).()); |
| 45 | } |
| 46 | |
| 47 | bool Cursorscxx . . $ Cursors#::mouseEventcxx . . $ Cursors#mouseEvent(bf65bbe40893342c).(QEventcxx . . $ QEvent#::Typecxx . . $ QEvent#Type# type, QMouseEventcxx . . $ QMouseEvent# *event) |
| 48 | { |
| 49 | if (minCursorcxx . . $ Cursors#minCursor.->mouseEventcxx . . $ Cursor#mouseEvent(bf65bbe40893342c).(type, event)) |
| 50 | return true; |
| 51 | if (maxCursorcxx . . $ Cursors#maxCursor.->mouseEventcxx . . $ Cursor#mouseEvent(bf65bbe40893342c).(type, event)) |
| 52 | return true; |
| 53 | |
| 54 | // If the mouse pointer is between the cursors, display a resize pointer |
| 55 | if (pointWithinDragRegioncxx . . $ Cursors#pointWithinDragRegion(578814ae554e72f6).(event->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).()) ) { |
| 56 | if (!cursorOverridecxx . . $ Cursors#cursorOverride.) { |
| 57 | cursorOverridecxx . . $ Cursors#cursorOverride. = true; |
| 58 | QApplicationcxx . . $ QApplication#::setOverrideCursorcxx . . $ QGuiApplication#setOverrideCursor(abdcfda6ee8376ea).(QCursorcxx . . $ QCursor#QCursor(1a9232e7b845eb22).(Qtcxx . . $ Qt/::SizeAllCursorcxx . . $ Qt/SizeAllCursor.)); |
| 59 | } |
| 60 | // Restore pointer otherwise |
| 61 | } else { |
| 62 | if (cursorOverridecxx . . $ Cursors#cursorOverride.) { |
| 63 | cursorOverridecxx . . $ Cursors#cursorOverride. = false; |
| 64 | QApplicationcxx . . $ QApplication#::restoreOverrideCursorcxx . . $ QGuiApplication#restoreOverrideCursor(49f6e7a06ebc5aa8).(); |
| 65 | } |
| 66 | } |
| 67 | // Start dragging on left mouse button press, if between the cursors |
| 68 | if (type == QEventcxx . . $ QEvent#::MouseButtonPresscxx . . $ QEvent#MouseButtonPress.) { |
| 69 | if (event->buttoncxx . . $ QMouseEvent#button(4a2598559eeedfc9).() == Qtcxx . . $ Qt/::LeftButtoncxx . . $ Qt/LeftButton.) { |
| 70 | if (pointWithinDragRegioncxx . . $ Cursors#pointWithinDragRegion(578814ae554e72f6).(event->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).())) { |
| 71 | draggingcxx . . $ Cursors#dragging. = true; |
| 72 | dragPoscxx . . $ Cursors#dragPos. =cxx . . $ QPoint#`operator=`(4505ae15944d373c). event->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).(); |
| 73 | return true; |
| 74 | } |
| 75 | } |
| 76 | // Update both cursor positons if we're dragging |
| 77 | } else if (type == QEventcxx . . $ QEvent#::MouseMovecxx . . $ QEvent#MouseMove.) { |
| 78 | if (draggingcxx . . $ Cursors#dragging.) { |
| 79 | int dx = event->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).().xcxx . . $ QPoint#x(455f465bc33b4cdf).() - dragPoscxx . . $ Cursors#dragPos..xcxx . . $ QPoint#x(455f465bc33b4cdf).(); |
| 80 | minCursorcxx . . $ Cursors#minCursor.->setPoscxx . . $ Cursor#setPos(d4f767463ce0a6b3).(minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).() + dx); |
| 81 | maxCursorcxx . . $ Cursors#maxCursor.->setPoscxx . . $ Cursor#setPos(d4f767463ce0a6b3).(maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).() + dx); |
| 82 | dragPoscxx . . $ Cursors#dragPos. =cxx . . $ QPoint#`operator=`(4505ae15944d373c). event->poscxx . . $ QMouseEvent#pos(75d69cfbd3c4b2dd).(); |
| 83 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! cursorsMovedcxx . . $ Cursors#cursorsMoved(49f6e7a06ebc5aa8).(); |
| 84 | } |
| 85 | // Stop dragging on left mouse button release |
| 86 | } else if (type == QEventcxx . . $ QEvent#::MouseButtonReleasecxx . . $ QEvent#MouseButtonRelease.) { |
| 87 | if (event->buttoncxx . . $ QMouseEvent#button(4a2598559eeedfc9).() == Qtcxx . . $ Qt/::LeftButtoncxx . . $ Qt/LeftButton. && draggingcxx . . $ Cursors#dragging.) { |
| 88 | draggingcxx . . $ Cursors#dragging. = false; |
| 89 | return true; |
| 90 | } |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | void Cursorscxx . . $ Cursors#::leaveEventcxx . . $ Cursors#leaveEvent(49f6e7a06ebc5aa8).() |
| 96 | { |
| 97 | minCursorcxx . . $ Cursors#minCursor.->leaveEventcxx . . $ Cursor#leaveEvent(49f6e7a06ebc5aa8).(); |
| 98 | maxCursorcxx . . $ Cursors#maxCursor.->leaveEventcxx . . $ Cursor#leaveEvent(49f6e7a06ebc5aa8).(); |
| 99 | |
| 100 | if (cursorOverridecxx . . $ Cursors#cursorOverride.) { |
| 101 | cursorOverridecxx . . $ Cursors#cursorOverride. = false; |
| 102 | QApplicationcxx . . $ QApplication#::restoreOverrideCursorcxx . . $ QGuiApplication#restoreOverrideCursor(49f6e7a06ebc5aa8).(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void Cursorscxx . . $ Cursors#::paintFrontcxx . . $ Cursors#paintFront(dba2c6533854c69f).(QPaintercxx . . $ QPainter# &painter, QRectcxx . . $ QRect# &rect, range_tcxx . . $ range_t#<size_t> sampleRange) |
| 107 | { |
| 108 | painter.savecxx . . $ QPainter#save(49f6e7a06ebc5aa8).(); |
| 109 | |
| 110 | QRectcxx . . $ QRect# cursorRectcxx . . $ QRect#QRect(748afa4755bc9595).(minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.topcxx . . $ QRect#top(455f465bc33b4cdf).(), maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).() - minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.heightcxx . . $ QRect#height(455f465bc33b4cdf).()); |
| 111 | |
| 112 | // Draw translucent white fill for highlight |
| 113 | painter.fillRectcxx . . $ QPainter#fillRect(a493e38a50e0b286).( |
| 114 | cursorRect, |
| 115 | QBrushcxx . . $ QBrush#QBrush(b50947b0752ea6ac).(QColorcxx . . $ QColor#QColor(748afa4755bc9595).(255, 255, 255, 50)) |
| 116 | ); |
| 117 | |
| 118 | // Draw vertical edges for individual segments |
| 119 | painter.setPencxx . . $ QPainter#setPen(af0a25dfda3214db).(QPencxx . . $ QPen#QPen(c1f9b1cc0228302b).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::graycxx . . $ Qt/gray., 1, Qtcxx . . $ Qt/::DashLinecxx . . $ Qt/DashLine.)); |
| 120 | for (long i = 1; i < segmentCountcxx . . $ Cursors#segmentCount.; i++) { |
| 121 | int pos = minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).() + (i * cursorRect.widthcxx . . $ QRect#width(455f465bc33b4cdf).() / segmentCountcxx . . $ Cursors#segmentCount.); |
| 122 | painter.drawLinecxx . . $ QPainter#drawLine(748afa4755bc9595).(pos, rect.topcxx . . $ QRect#top(455f465bc33b4cdf).(), pos, rect.bottomcxx . . $ QRect#bottom(455f465bc33b4cdf).()); |
| 123 | } |
| 124 | |
| 125 | // Draw vertical edges |
| 126 | painter.setPencxx . . $ QPainter#setPen(af0a25dfda3214db).(QPencxx . . $ QPen#QPen(c1f9b1cc0228302b).(Qtcxx . . $ QBrush#QBrush(1975e3c608654284).::whitecxx . . $ Qt/white., 1, Qtcxx . . $ Qt/::SolidLinecxx . . $ Qt/SolidLine.)); |
| 127 | painter.drawLinecxx . . $ QPainter#drawLine(748afa4755bc9595).(minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.topcxx . . $ QRect#top(455f465bc33b4cdf).(), minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.bottomcxx . . $ QRect#bottom(455f465bc33b4cdf).()); |
| 128 | painter.drawLinecxx . . $ QPainter#drawLine(748afa4755bc9595).(maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.topcxx . . $ QRect#top(455f465bc33b4cdf).(), maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), rect.bottomcxx . . $ QRect#bottom(455f465bc33b4cdf).()); |
| 129 | |
| 130 | painter.restorecxx . . $ QPainter#restore(49f6e7a06ebc5aa8).(); |
| 131 | } |
| 132 | |
| 133 | int Cursorscxx . . $ Cursors#::segmentscxx . . $ Cursors#segments(b126dc7c1de90089).() |
| 134 | { |
| 135 | return segmentCountcxx . . $ Cursors#segmentCount.; |
| 136 | } |
| 137 | |
| 138 | range_tcxx . . $ range_t#<int> Cursorscxx . . $ Cursors#::selectioncxx . . $ Cursors#selection(8edf043d21a94c0c).() |
| 139 | { |
| 140 | return {minCursorcxx . . $ Cursors#minCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).(), maxCursorcxx . . $ Cursors#maxCursor.->poscxx . . $ Cursor#pos(b126dc7c1de90089).()}; |
| 141 | } |
| 142 | |
| 143 | void Cursorscxx . . $ Cursors#::setSegmentscxx . . $ Cursors#setSegments(d4f767463ce0a6b3).(int segments) |
| 144 | { |
| 145 | segmentCountcxx . . $ Cursors#segmentCount. = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(segments, 1); |
| 146 | } |
| 147 | |
| 148 | void Cursorscxx . . $ Cursors#::setSelectioncxx . . $ Cursors#setSelection(3ae39a1630889ffb).(range_tcxx . . $ range_t#<int> selection) |
| 149 | { |
| 150 | minCursorcxx . . $ Cursors#minCursor.->setPoscxx . . $ Cursor#setPos(d4f767463ce0a6b3).(selection.minimumcxx . . $ range_t#minimum.); |
| 151 | maxCursorcxx . . $ Cursors#maxCursor.->setPoscxx . . $ Cursor#setPos(d4f767463ce0a6b3).(selection.maximumcxx . . $ range_t#maximum.); |
| 152 | } |