mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
fixed more selection issues in grid view
This commit is contained in:
parent
1a04358a83
commit
8c6a1dcf49
@ -102,6 +102,7 @@ void GridComicsView::setModel(ComicModel *model)
|
||||
void GridComicsView::setCurrentIndex(const QModelIndex &index)
|
||||
{
|
||||
QLOG_INFO() << "setCurrentIndex";
|
||||
_selectionModel->clear();
|
||||
_selectionModel->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
view->rootContext()->setContextProperty("dummyValue", true);
|
||||
}
|
||||
@ -206,7 +207,24 @@ void GridComicsView::selectIndex(int index)
|
||||
{
|
||||
QLOG_INFO() << "selectIndex" << index;
|
||||
if(_selectionModel != NULL && model!=NULL)
|
||||
{
|
||||
_selectionModel->select(model->index(index,0),QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
view->rootContext()->setContextProperty("dummyValue", true);
|
||||
}
|
||||
}
|
||||
|
||||
void GridComicsView::setCurrentIndex(int index)
|
||||
{
|
||||
setCurrentIndex(model->index(index,0));
|
||||
}
|
||||
|
||||
void GridComicsView::deselectIndex(int index)
|
||||
{
|
||||
if(_selectionModel != NULL && model!=NULL)
|
||||
{
|
||||
_selectionModel->select(model->index(index,0),QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
|
||||
view->rootContext()->setContextProperty("dummyValue", true);
|
||||
}
|
||||
}
|
||||
|
||||
bool GridComicsView::isSelectedIndex(int index)
|
||||
@ -237,6 +255,27 @@ void GridComicsView::selectedItem(int index)
|
||||
emit doubleClicked(model->index(index,0));
|
||||
}
|
||||
|
||||
int GridComicsView::numItemsSelected()
|
||||
{
|
||||
if(_selectionModel != NULL)
|
||||
{
|
||||
return _selectionModel->selectedRows().length();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GridComicsView::lastSelectedIndex()
|
||||
{
|
||||
if(_selectionModel != NULL)
|
||||
{
|
||||
QLOG_INFO() << "last selected index " << _selectionModel->selectedRows().last().row();
|
||||
return _selectionModel->selectedRows().last().row();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void GridComicsView::setShowMarks(bool show)
|
||||
{
|
||||
QLOG_INFO() << "setShowMarks";
|
||||
|
@ -38,10 +38,14 @@ signals:
|
||||
public slots:
|
||||
//selection helper
|
||||
void selectIndex(int index);
|
||||
void setCurrentIndex(int index);
|
||||
void deselectIndex(int index);
|
||||
bool isSelectedIndex(int index);
|
||||
void clear();
|
||||
//double clicked item
|
||||
void selectedItem(int index);
|
||||
int numItemsSelected();
|
||||
int lastSelectedIndex();
|
||||
|
||||
//ComicsView
|
||||
void setShowMarks(bool show);
|
||||
|
@ -12,7 +12,7 @@ Rectangle {
|
||||
|
||||
function selectAll(from,to)
|
||||
{
|
||||
for(var i = from;i<to;i++)
|
||||
for(var i = from;i<=to;i++)
|
||||
{
|
||||
comicsSelectionHelper.selectIndex(i);
|
||||
}
|
||||
@ -26,13 +26,7 @@ Rectangle {
|
||||
width: grid.cellWidth
|
||||
height: grid.cellHeight
|
||||
color: backgroundColor
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
comicsSelectionHelper.clear();
|
||||
comicsSelectionHelper.selectIndex(grid.currentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: realCell
|
||||
@ -55,8 +49,8 @@ Rectangle {
|
||||
}
|
||||
|
||||
width: 156; height: 287
|
||||
color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index)) || grid.currentIndex === index?selectedColor:cellColor;
|
||||
border.color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index)) || grid.currentIndex === index?selectedBorderColor:borderColor;
|
||||
color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedColor:cellColor;
|
||||
border.color: ((dummyValue || !dummyValue) && comicsSelectionHelper.isSelectedIndex(index))?selectedBorderColor:borderColor;
|
||||
border.width: (Qt.platform.os === "osx")?1:0;
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
@ -85,17 +79,23 @@ Rectangle {
|
||||
//grid.currentIndex = index
|
||||
//comicsSelection.setCurrentIndex(index,0x0002)
|
||||
var ci = grid.currentIndex;
|
||||
if(mouse.button != Qt.RightButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier))
|
||||
/*if(mouse.button != Qt.RightButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier))
|
||||
{
|
||||
if(!comicsSelectionHelper.isSelectedIndex(index))
|
||||
comicsSelectionHelper.clear();
|
||||
}
|
||||
}*/
|
||||
|
||||
if(mouse.modifiers & Qt.ShiftModifier)
|
||||
if(index < ci)
|
||||
{
|
||||
selectAll(index,ci);
|
||||
grid.currentIndex = index;
|
||||
}
|
||||
else if (index > ci)
|
||||
{
|
||||
selectAll(ci,index);
|
||||
grid.currentIndex = index;
|
||||
}
|
||||
|
||||
mouse.accepted = true;
|
||||
|
||||
@ -104,8 +104,7 @@ Rectangle {
|
||||
|
||||
if(!comicsSelectionHelper.isSelectedIndex(index))
|
||||
{
|
||||
comicsSelectionHelper.clear();
|
||||
comicsSelectionHelper.selectIndex(index)
|
||||
comicsSelectionHelper.setCurrentIndex(index)
|
||||
grid.currentIndex = index;
|
||||
}
|
||||
|
||||
@ -114,8 +113,23 @@ Rectangle {
|
||||
|
||||
} else
|
||||
{
|
||||
comicsSelectionHelper.selectIndex(index)
|
||||
grid.currentIndex = index;
|
||||
if(mouse.modifiers & Qt.ControlModifier)
|
||||
{
|
||||
if(comicsSelectionHelper.isSelectedIndex(index))
|
||||
{
|
||||
if(comicsSelectionHelper.numItemsSelected()>1)
|
||||
{
|
||||
comicsSelectionHelper.deselectIndex(index);
|
||||
if(grid.currentIndex === index)
|
||||
grid.currentIndex = comicsSelectionHelper.lastSelectedIndex();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
comicsSelectionHelper.selectIndex(index);
|
||||
grid.currentIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -123,7 +137,7 @@ Rectangle {
|
||||
onReleased: {
|
||||
if(mouse.button != Qt.RightButton && !(mouse.modifiers & Qt.ControlModifier || mouse.modifiers & Qt.ShiftModifier))
|
||||
{
|
||||
comicsSelectionHelper.clear();
|
||||
comicsSelectionHelper.setCurrentIndex(index)
|
||||
grid.currentIndex = index;
|
||||
}
|
||||
}
|
||||
@ -299,7 +313,7 @@ Rectangle {
|
||||
//var ci = grid.currentIndex;
|
||||
grid.currentIndex = -1
|
||||
comicsSelectionHelper.clear();
|
||||
comicsSelectionHelper.selectIndex(ci);
|
||||
comicsSelectionHelper.setCurrentIndex(ci);
|
||||
grid.currentIndex = ci;
|
||||
}
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user