Skip to content

Commit

Permalink
Merge pull request #91 from dmitr-fedorov/feat/booksSelection
Browse files Browse the repository at this point in the history
Added book selection for home page
  • Loading branch information
DavidLazarescu authored Dec 16, 2023
2 parents 2904e1d + b31b596 commit e45754b
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/presentation/Globals.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import QtQuick
Item {
property var selectedBook: null
property var bookTags: []
property bool bookSelectionModeEnabled: false
property var selectedBooks: []
}
24 changes: 24 additions & 0 deletions src/presentation/homePage/MBook.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Librum.style
import Librum.icons
import CustomComponents
import Librum.fonts
import Librum.globals

Item {
id: root
Expand Down Expand Up @@ -265,6 +266,12 @@ Item {
// Delegate mouse clicks events to parent
onClicked: mouse => {
if (mouse.button === Qt.LeftButton) {
if (Globals.bookSelectionModeEnabled) {
checkBox.checked = checkBox.checked ? false : true
Globals.selectedBooks.push(model.uuid)
return
}

if (moreOptionsArea.containsMouse) {
root.moreOptionClicked(root.index, mouse)
return
Expand All @@ -277,9 +284,26 @@ Item {
}
}

MCheckBox {
id: checkBox
anchors.top: root.top
anchors.left: root.left
anchors.topMargin: 10
anchors.leftMargin: 10
visible: Globals.bookSelectionModeEnabled
uncheckedBackgroundColor: Style.colorControlBackground
}

QtObject {
id: internal
property int lowerBookPartPadding: 14
property var bookSelectionModeEnabled: Globals.bookSelectionModeEnabled

onBookSelectionModeEnabledChanged: {
if (bookSelectionModeEnabled === false) {
checkBox.checked = false
}
}
}

MToolTip {
Expand Down
48 changes: 48 additions & 0 deletions src/presentation/homePage/MBookMultiSelectRightClickPopup.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import CustomComponents
import QtQml.Models
import Librum.globals
import Librum.icons
import Librum.style

MRightClickMenu {
id: root
signal markAsReadClicked
signal deleteClicked
signal uninstallClicked

implicitHeight: 108 // 32px per item

objectModel: ObjectModel {

MRightClickMenuItem {
width: root.width
imagePath: Icons.bookPopupMarkAsRead
imageSize: 17
//: If this is too long in any language, use "Read" (past form) instead
text: qsTr("Mark as read")

onClicked: root.markAsReadClicked()
}

MRightClickMenuItem {
width: root.width
imagePath: Icons.bookPopupUninstall
imageSize: 13
text: qsTr("Uninstall books")

onClicked: root.uninstallClicked()
}

MRightClickMenuItem {
width: root.width
imagePath: Icons.bookPopupDelete
imageSize: 16
text: qsTr("Delete books")

onClicked: root.deleteClicked()
}
}
}
80 changes: 75 additions & 5 deletions src/presentation/homePage/MHomePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ Page {
z: 2

onSearchRequested: query => LibraryController.libraryModel.sortString = query

onCheckBoxActivated: activated => Globals.bookSelectionModeEnabled = activated
}

Pane {
Expand Down Expand Up @@ -208,10 +210,18 @@ Page {
mouse.x, mouse.y)
let absoluteMousePosition = mapToItem(
root, mouse.x, mouse.y)
bookOptionsPopup.setSpawnPosition(
currentMousePosition,
absoluteMousePosition,
root)

if (Globals.bookSelectionModeEnabled) {
bookMultiSelectOptionsPopup.setSpawnPosition(
currentMousePosition,
absoluteMousePosition,
root)
} else {
bookOptionsPopup.setSpawnPosition(
currentMousePosition,
absoluteMousePosition,
root)
}

// Open the bookOptions
internal.openBookOptionsPopup(
Expand All @@ -227,6 +237,7 @@ Page {
let currentMousePosition = mapToItem(
bookGridContainer,
mouse.x, mouse.y)

bookOptionsPopup.x = currentMousePosition.x
- bookOptionsPopup.implicitWidth / 2
bookOptionsPopup.y = currentMousePosition.y
Expand Down Expand Up @@ -277,6 +288,40 @@ Page {
close()
}
}


/*
The options menu when e.g. right-clicking a book while multi selection is enabled
*/
MBookMultiSelectRightClickPopup {
id: bookMultiSelectOptionsPopup

onMarkAsReadClicked: {

toolbar.selectBooksCheckBoxActivated = false
close()
}

onUninstallClicked: {
for (var i = 0; i < Globals.selectedBooks.length; i++) {
LibraryController.uninstallBook(
Globals.selectedBooks[i])
}

toolbar.selectBooksCheckBoxActivated = false
close()
}

onDeleteClicked: {
for (var i = 0; i < Globals.selectedBooks.length; i++) {
LibraryController.deleteBook(
Globals.selectedBooks[i])
}

toolbar.selectBooksCheckBoxActivated = false
close()
}
}
}

ScrollBar {
Expand Down Expand Up @@ -482,6 +527,25 @@ Page {
onAccepted: internal.addBooks(files)
}

Keys.onPressed: event => {
if (event.key === Qt.Key_Control) {
toolbar.selectBooksCheckBoxActivated = true
event.accepted = true
} else if (event.key === Qt.Key_Escape) {
toolbar.selectBooksCheckBoxActivated = false
event.accepted = true
}
}

Keys.onReleased: event => {
if (event.key === Qt.Key_Control) {
toolbar.selectBooksCheckBoxActivated = false
event.accepted = true
}
}

Component.onDestruction: toolbar.selectBooksCheckBoxActivated = false

QtObject {
id: internal
property bool libraryIsEmpty: LibraryController.bookCount === 0
Expand All @@ -497,12 +561,18 @@ Page {
Globals.bookTags = Qt.binding(function () {
return item.tags
})
bookOptionsPopup.open()

if (Globals.bookSelectionModeEnabled)
bookMultiSelectOptionsPopup.open()
else
bookOptionsPopup.open()
}

function openBook() {
if (bookOptionsPopup.opened)
bookOptionsPopup.close()
else if (bookMultiSelectOptionsPopup.opened)
bookMultiSelectOptionsPopup.close()

BookController.setUp(Globals.selectedBook.uuid)

Expand Down
12 changes: 10 additions & 2 deletions src/presentation/homePage/toolbar/MToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ import CustomComponents
import Librum.controllers
import Librum.models
import Librum.icons
import Librum.globals
import "filterByButton"
import "sortByButton"
import "tagSelector"

Item {
id: root
property alias selectBooksCheckBoxActivated: selectBooksCheckBox.activated
signal searchRequested(string query)
signal checkBoxClicked
signal checkBoxActivated(bool activated)

implicitWidth: 1714
implicitHeight: 36

onWidthChanged: if (searchButton.opened)
searchButton.close()

onSelectBooksCheckBoxActivatedChanged: {
if (!selectBooksCheckBoxActivated)
Globals.selectedBooks = []
}

RowLayout {
id: layout
anchors.fill: parent
Expand All @@ -28,7 +35,8 @@ Item {
MWrappedCheckBox {
id: selectBooksCheckBox

onChecked: checkBoxClicked()
onActivatedChanged: root.checkBoxActivated(
selectBooksCheckBox.activated)
}

MSortByButton {
Expand Down
51 changes: 22 additions & 29 deletions src/presentation/modules/CustomComponents/MCheckBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import QtQuick.Layouts
import Librum.style
import Librum.icons


/**
A checkbox which toggles between two pictures, depending on its state
*/
Item
{
Item {
id: root
property color borderColor: Style.colorCheckboxBorder
property color checkedBorderColor: Style.colorContainerBorder
Expand All @@ -21,53 +21,46 @@ Item
property int imageSize: container.width - 10
property bool checked: false
property bool enabled: true
signal clicked()
signal clicked

implicitWidth: 22
implicitHeight: 22


Rectangle
{

Rectangle {
id: container
anchors.fill: parent
radius: root.borderRadius
border.width: root.checked ? root.checkedBorderWidth : root.borderWidth
border.color: root.activeFocus ? root.checkedBorderColor : root.borderColor
color: root.checked ? root.checkedBackgroundColor : root.uncheckedBackgroundColor
antialiasing: true

Image
{

Image {
id: image
anchors.centerIn: parent
visible: root.checked ? true : false
sourceSize.width: root.imageSize
source: root.image
fillMode: Image.PreserveAspectFit
}

MouseArea
{

MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: root.toggle();

onClicked: root.toggle()
}
}


function toggle()
{
if(!root.enabled)
return;

root.clicked();
root.checked = !root.checked;

function toggle() {
if (!root.enabled)
return

root.clicked()
root.checked = !root.checked
}

function giveFocus()
{
root.forceActiveFocus();

function giveFocus() {
root.forceActiveFocus()
}
}
1 change: 1 addition & 0 deletions src/presentation/qmlSources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
<file>readingPage/MBookmarkItem.qml</file>
<file>readingPage/MExplanationPopup.qml</file>
<file>LanguageModel.qml</file>
<file>homePage/MBookMultiSelectRightClickPopup.qml</file>
</qresource>
</RCC>
Loading

0 comments on commit e45754b

Please sign in to comment.