Migrate GridComicsView and InfoComicsView to QtQuick and QtQuick.Controls 2.15

This commit is contained in:
Luis Ángel San Martín 2021-10-17 14:54:13 +02:00
parent 71b17fe258
commit 45b94cd8ef
2 changed files with 167 additions and 184 deletions

View File

@ -1,10 +1,12 @@
import QtQuick 2.9
import QtQuick 2.15
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
import QtQuick.Controls.Styles 1.4
import Qt.labs.animation 1.0
import com.yacreader.ComicModel 1.0
@ -12,12 +14,11 @@ import com.yacreader.ComicInfo 1.0
import com.yacreader.ComicDB 1.0
SplitView {
//anchors.fill: parent
orientation: Qt.Horizontal
handleDelegate:Rectangle {
width: 1
height: 1
color: "#202020"
handle: Rectangle {
border.width : 0
implicitWidth: 10
color: info_container.color
}
Rectangle {
@ -47,8 +48,8 @@ Rectangle {
color: backgroundColor
width: parent.width - (info_container.visible ? info_container.width : 0)
Layout.fillWidth: true
Layout.minimumWidth: coverWidth + 100
SplitView.fillWidth: true
SplitView.minimumWidth: coverWidth + 100
height: parent.height
anchors.margins: 0
@ -364,12 +365,24 @@ Rectangle {
}
Menu {
background: Rectangle {
implicitWidth: 42
implicitHeight: 100
//border.color: "#222"
//color: "#444"
}
id: ratingConextMenu
MenuItem { text: "1"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,1) }
MenuItem { text: "2"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,2) }
MenuItem { text: "3"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,3) }
MenuItem { text: "4"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,4) }
MenuItem { text: "5"; enabled: true; iconSource:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,5) }
Action { text: "1"; enabled: true; icon.source:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,1) }
Action { text: "2"; enabled: true; icon.source:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,2) }
Action { text: "3"; enabled: true; icon.source:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,3) }
Action { text: "4"; enabled: true; icon.source:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,4) }
Action { text: "5"; enabled: true; icon.source:"star_menu.png"; onTriggered: comicRatingHelper.rate(index,5) }
delegate: MenuItem {
implicitHeight: 30
}
}
}
@ -383,41 +396,18 @@ Rectangle {
}
}
ScrollView {
__wheelAreaScrollSpeed: grid.cellHeight * 0.40
Rectangle {
id: scrollView
objectName: "topScrollView"
anchors.fill: parent
anchors.margins: 0
children: grid
color: "transparent"
function scrollToOrigin() {
flickableItem.contentY = showCurrentComic ? -270 : -20
flickableItem.contentX = 0
}
style: YACReaderScrollViewStyle {
transientScrollBars: false
incrementControl: Item {}
decrementControl: Item {}
handle: Item {
implicitWidth: 16
implicitHeight: 26
Rectangle {
color: "#88424242"
anchors.fill: parent
anchors.topMargin: 6
anchors.leftMargin: 4
anchors.rightMargin: 4
anchors.bottomMargin: 6
border.color: "#AA313131"
border.width: 1
radius: 8
}
}
scrollBarBackground: Item {
implicitWidth: 16
implicitHeight: 26
}
grid.contentY = grid.originY
grid.contentX = grid.originX
}
DropArea {
@ -620,34 +610,13 @@ Rectangle {
Layout.maximumHeight: (currentComicVisualView.height * 0.32)
Layout.maximumWidth: 960
contentItem: currentComicInfoSinopsis
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
contentItem: currentComicInfoSinopsis
id: synopsisScroller
style: ScrollViewStyle {
transientScrollBars: false
incrementControl: Item {}
decrementControl: Item {}
handle: Item {
implicitWidth: 12
implicitHeight: 26
Rectangle {
color: "#424246"
anchors.fill: parent
anchors.topMargin: 6
anchors.leftMargin: 9
anchors.rightMargin: 0
anchors.bottomMargin: 6
radius: 2
}
}
scrollBarBackground: Item {
implicitWidth: 14
implicitHeight: 26
}
}
clip: true
Text {
Layout.maximumWidth: 960
@ -680,18 +649,16 @@ Rectangle {
anchors.bottomMargin: 15
onClicked: comicOpener.triggerOpenCurrentComic()
style: ButtonStyle {
background: Rectangle {
implicitWidth: 100
implicitHeight: 30
border.width: control.activeFocus ? 2 : 1
border.width: readButton.activeFocus ? 2 : 1
border.color: "#FFCC00"
radius: height / 2
color: "#FFCC00"
}
label: Text {
contentItem: Text {
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
@ -699,9 +666,8 @@ Rectangle {
font.pointSize: 12
font.bold: true
color: "white"
text: control.text
text: readButton.text
}
}
}
@ -725,26 +691,21 @@ Rectangle {
anchors.fill: parent
cellHeight: cellCustomHeight
header: currentComicView
//highlight: appHighlight
focus: true
model: comicsList
delegate: appDelegate
anchors.topMargin: 0 //showCurrentComic ? 0 : 20
anchors.bottomMargin: 20
anchors.topMargin: 0
anchors.bottomMargin: 10
anchors.leftMargin: 0
anchors.rightMargin: 0
pixelAligned: true
//flickDeceleration: -2000
highlightFollowsCurrentItem: true
currentIndex: 0
cacheBuffer: 0
footer: Rectangle { //fix for the scroll issue, TODO find what causes the issue (some times the bottoms cells are hidden for the toolbar, no full scroll)
height : 25
width : parent.width
color : "#00000000"
}
//disable flickable behaviour
interactive: false
move: Transition {
NumberAnimation { properties: "x,y"; duration: 250 }
@ -780,116 +741,130 @@ Rectangle {
}
function calculateCellWidths(cWidth) {
var wholeCells = Math.floor(width / cWidth);
var rest = width - (cWidth * wholeCells)
grid.cellWidth = cWidth + Math.floor(rest / wholeCells);
//console.log("cWidth",cWidth,"wholeCells=",wholeCells,"rest=",rest,"cellWidth=",cellWidth,"width=",width);
}
WheelHandler {
onWheel: {
if (grid.contentHeight <= grid.height) {
return;
}
var newValue = Math.min((grid.contentHeight - grid.height - (showCurrentComic ? 270 : 20)), (Math.max(grid.originY , grid.contentY - event.angleDelta.y)));
grid.contentY = newValue;
}
}
ScrollBar.vertical: ScrollBar {
visible: grid.contentHeight > grid.height
contentItem: Item {
implicitWidth: 12
implicitHeight: 26
Rectangle {
color: "#88424242"
anchors.fill: parent
anchors.topMargin: 6
anchors.leftMargin: 3
anchors.rightMargin: 2
anchors.bottomMargin: 6
border.color: "#AA313131"
border.width: 1
radius: 3.5
}
}
}
Keys.onPressed: {
if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier) {
event.accepted = true
return;
}
var numCells = grid.numCellsPerRow();
var ci = 0;
if (event.key === Qt.Key_Right) {
ci = Math.min(grid.currentIndex+1,grid.count - 1);
}
else if (event.key === Qt.Key_Left) {
ci = Math.max(0,grid.currentIndex-1);
}
else if (event.key === Qt.Key_Up) {
ci = Math.max(0,grid.currentIndex-numCells);
}
else if (event.key === Qt.Key_Down) {
ci = Math.min(grid.currentIndex+numCells,grid.count - 1);
} else {
return;
}
event.accepted = true;
grid.currentIndex = -1
comicsSelectionHelper.clear();
currentIndexHelper.setCurrentIndex(ci);
grid.currentIndex = ci;
}
}
focus: true
Keys.onPressed: {
if (event.modifiers & Qt.ControlModifier || event.modifiers & Qt.ShiftModifier)
return;
var numCells = grid.numCellsPerRow();
var ci
if (event.key === Qt.Key_Right) {
ci = Math.min(grid.currentIndex+1,grid.count - 1);
}
else if (event.key === Qt.Key_Left) {
ci = Math.max(0,grid.currentIndex-1);
}
else if (event.key === Qt.Key_Up) {
ci = Math.max(0,grid.currentIndex-numCells);
}
else if (event.key === Qt.Key_Down) {
ci = Math.min(grid.currentIndex+numCells,grid.count - 1);
} else {
return;
}
event.accepted = true;
//var ci = grid.currentIndex;
grid.currentIndex = -1
comicsSelectionHelper.clear();
currentIndexHelper.setCurrentIndex(ci);
grid.currentIndex = ci;
}
//}
/*MouseArea {
anchors.fill: parent
onClicked: {
clicked.accepted = false;
console.log("xx");
}
onWheel: {
var newValue = Math.max(0,scrollView.flickableItem.contentY - wheel.angleDelta.y)
scrollView.flickableItem.contentY = newValue
}
}*/
/*ScrollBar {
flickable: grid;
}
PerformanceMeter {
anchors {top: parent.top; left: parent.left; margins: 4}
id: performanceMeter
width: 128
height: 64
enabled: (dummyValue || !dummyValue)
}*/
}
}
Rectangle {
id: info_container
objectName: "infoContainer"
Layout.preferredWidth: 350
Layout.minimumWidth: 350
Layout.maximumWidth: 960
SplitView.preferredWidth: 350
SplitView.minimumWidth: 350
SplitView.maximumWidth: 960
height: parent.height
color: infoBackgroundColor
visible: showInfo
ScrollView {
__wheelAreaScrollSpeed: 75
Flickable{
id: infoFlickable
anchors.fill: parent
anchors.margins: 0
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
contentWidth: infoView.width
contentHeight: infoView.height
style: ScrollViewStyle {
transientScrollBars: false
incrementControl: Item {}
decrementControl: Item {}
handle: Item {
implicitWidth: 10
ComicInfoView {
id: infoView
width: info_container.width
}
WheelHandler {
onWheel: {
if (infoFlickable.contentHeight <= infoFlickable.height) {
return;
}
var newValue = Math.min((infoFlickable.contentHeight - infoFlickable.height), (Math.max(infoFlickable.originY , infoFlickable.contentY - event.angleDelta.y)));
infoFlickable.contentY = newValue;
}
}
ScrollBar.vertical: ScrollBar {
visible: infoFlickable.contentHeight > infoFlickable.height
contentItem: Item {
implicitWidth: 12
implicitHeight: 26
Rectangle {
color: "#424246"
anchors.fill: parent
anchors.topMargin: 6
anchors.leftMargin: 4
anchors.leftMargin: 5
anchors.rightMargin: 4
anchors.bottomMargin: 6
radius: 2
}
}
scrollBarBackground: Item {
implicitWidth: 14
implicitHeight: 26
}
}
ComicInfoView {
width: info_container.width
}
}
}
}

View File

@ -1,8 +1,6 @@
import QtQuick 2.5
import QtQuick 2.15
import QtQuick.Controls 1.2
import QtGraphicalEffects 1.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.15
import com.yacreader.ComicModel 1.0
@ -59,39 +57,49 @@ Rectangle {
y: flow.height + flow.additionalBottomSpace - 6
height: parent.height - y
clip: true
color: infoBackgroundColor
ScrollView {
__wheelAreaScrollSpeed: 75
Flickable{
id: infoFlickable
anchors.fill: parent
anchors.margins: 0
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
contentWidth: infoView.width
contentHeight: infoView.height
style: ScrollViewStyle {
transientScrollBars: false
incrementControl: Item {}
decrementControl: Item {}
handle: Item {
implicitWidth: 10
WheelHandler {
onWheel: {
if (infoFlickable.contentHeight <= infoFlickable.height) {
return;
}
var newValue = Math.min((infoFlickable.contentHeight - infoFlickable.height), (Math.max(infoFlickable.originY , infoFlickable.contentY - event.angleDelta.y)));
infoFlickable.contentY = newValue;
}
}
ScrollBar.vertical: ScrollBar {
visible: infoFlickable.contentHeight > infoFlickable.height
contentItem: Item {
implicitWidth: 12
implicitHeight: 26
Rectangle {
color: "#424246"
anchors.fill: parent
anchors.topMargin: 6
anchors.leftMargin: 4
anchors.leftMargin: 5
anchors.rightMargin: 4
anchors.bottomMargin: 6
radius: 2
}
}
scrollBarBackground: Item {
implicitWidth: 14
implicitHeight: 26
}
}
ComicInfoView {
id: infoView
width: info_container.width - 14
}
}