Skip to content

Commit

Permalink
Changed selection popup
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Mar 29, 2024
1 parent 5166115 commit e6a9748
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 403 deletions.
16 changes: 8 additions & 8 deletions src/presentation/modules/CppElements/page_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void PageView::mousePressEvent(QMouseEvent* event)
void PageView::handleClickingOnHighlight(const Highlight* highlight)
{
// Scale the highlight rects (initially zoom of 1) to the current zoom and
// get the center x and top y position of the highlight.
// get the center x and bottom y position of the highlight.
auto rects = highlight->getRects();
QList<QRectF> qRects;
qRects.reserve(rects.size());
Expand All @@ -223,7 +223,7 @@ void PageView::handleClickingOnHighlight(const Highlight* highlight)
qRectF, m_pageController->getZoom() / window()->devicePixelRatio());
qRects.append(qRectF);
}
auto positions = getCenterXAndTopYFromRects(qRects);
auto positions = getCenterXAndBottomYFromRects(qRects);

auto uuidAsString = highlight->getUuid().toString(QUuid::WithoutBraces);
m_bookController->highlightSelected(positions.first, positions.second,
Expand Down Expand Up @@ -270,7 +270,7 @@ void PageView::mouseReleaseEvent(QMouseEvent* event)
restoredRects.push_back(rect);
}

auto positions = getCenterXAndTopYFromRects(restoredRects);
auto positions = getCenterXAndBottomYFromRects(restoredRects);

emit m_bookController->textSelectionFinished(positions.first,
positions.second);
Expand All @@ -279,12 +279,12 @@ void PageView::mouseReleaseEvent(QMouseEvent* event)
m_doubleClickHold = false;
}

QPair<float, float> PageView::getCenterXAndTopYFromRects(
QPair<float, float> PageView::getCenterXAndBottomYFromRects(
const QList<QRectF>& rects)
{
float mostLeftX = std::numeric_limits<float>::max();
float mostRightX = 0;
float topY = std::numeric_limits<float>::max();
float bottomY = 0;
for(auto& rect : rects)
{
if(rect.x() < mostLeftX)
Expand All @@ -293,12 +293,12 @@ QPair<float, float> PageView::getCenterXAndTopYFromRects(
if(rect.x() + rect.width() > mostRightX)
mostRightX = rect.x() + rect.width();

if(rect.top() < topY)
topY = rect.top();
if(rect.bottom() > bottomY)
bottomY = rect.bottom();
}

auto centerX = (mostLeftX + mostRightX) / 2;
return { centerX, topY };
return { centerX, bottomY };
}

void PageView::mouseMoveEvent(QMouseEvent* event)
Expand Down
2 changes: 1 addition & 1 deletion src/presentation/modules/CppElements/page_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private slots:
void setCorrectCursor(int x, int y);

bool rectsAreOnSameLine(const QRectF& rect1, const QRectF& rect2);
QPair<float, float> getCenterXAndTopYFromRects(const QList<QRectF>& rects);
QPair<float, float> getCenterXAndBottomYFromRects(const QList<QRectF>& rects);

std::unique_ptr<adapters::controllers::PageController> m_pageController;
adapters::IBookController* m_bookController = nullptr;
Expand Down
1 change: 0 additions & 1 deletion src/presentation/qmlSources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<file>modules/CustomComponents/MConfirmAccountDeletionPopup.qml</file>
<file>settings/updatesPage/MWindowsUpdatingPopup.qml</file>
<file>readingPage/MSelectionOptionsPopup.qml</file>
<file>readingPage/MColorSelectionPopup.qml</file>
<file>modules/CustomComponents/MSlider.qml</file>
<file>readingPage/MDictionaryPopup.qml</file>
<file>readingPage/MBookmarkItem.qml</file>
Expand Down
121 changes: 0 additions & 121 deletions src/presentation/readingPage/MColorSelectionPopup.qml

This file was deleted.

39 changes: 9 additions & 30 deletions src/presentation/readingPage/MDocumentView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,9 @@ Pane {
onContentYChanged: {
NavigationLogic.updateCurrentPageCounter()
selectionOptionsPopup.close()
colorSelectionPopup.close()
}

onContentXChanged: {
selectionOptionsPopup.close()
colorSelectionPopup.close()
}
onContentXChanged: selectionOptionsPopup.close()

Component.onCompleted: root.setPage(root.bookController.currentPage)

Expand Down Expand Up @@ -238,33 +234,16 @@ Pane {
MSelectionOptionsPopup {
id: selectionOptionsPopup
property real highlightCenterX
property real highlightTopY
property real highlightBottomY

onNewWidth: internal.openSelectionOptionsPopup(-1, -1)

onHighlightOptionSelected: uuid => {
if (selectionOptionsPopup.highlight == "")
colorSelectionPopup.highlight = uuid
else
colorSelectionPopup.highlight
= selectionOptionsPopup.highlight

internal.openPopupAt(
colorSelectionPopup,
selectionOptionsPopup.highlightCenterX,
selectionOptionsPopup.highlightTopY)
}

onExplanationOptionSelected: text => {
explanationPopup.question = text
explanationPopup.open()
}
}

MColorSelectionPopup {
id: colorSelectionPopup
}

MDictionaryPopup {
id: dictionaryPopup
}
Expand Down Expand Up @@ -319,22 +298,22 @@ Pane {
id: internal
property string optionNameCursorModeHiddenAfterDelay: "Hidden after delay"

function openSelectionOptionsPopup(centerX, topY) {
if (centerX === -1 && topY === -1) {
function openSelectionOptionsPopup(centerX, bottomY) {
if (centerX === -1 && bottomY === -1) {
centerX = selectionOptionsPopup.highlightCenterX
topY = selectionOptionsPopup.highlightTopY
bottomY = selectionOptionsPopup.highlightBottomY
}
selectionOptionsPopup.highlightCenterX = centerX
selectionOptionsPopup.highlightTopY = topY
selectionOptionsPopup.highlightBottomY = bottomY

internal.openPopupAt(selectionOptionsPopup, centerX, topY)
internal.openPopupAt(selectionOptionsPopup, centerX, bottomY)
}

function openPopupAt(popup, centerX, topY) {
function openPopupAt(popup, centerX, bottomY) {
let pageYOffset = pageView.contentY - activeFocusItem.y
let pageXOffset = pageView.contentX - activeFocusItem.x
let posX = centerX + pageView.x - popup.width / 2 - pageXOffset
let posY = topY - popup.height - pageYOffset - 6
let posY = bottomY + -pageYOffset + 6

let spaceToRight = (pageView.x + pageView.width) - (posX + popup.width)
if (spaceToRight < 0)
Expand Down
Loading

0 comments on commit e6a9748

Please sign in to comment.