Fixing more bugs

This commit is contained in:
Jan Dalheimer 2013-12-30 23:10:53 +01:00
parent 1e1b2342f4
commit e6be883d14

View File

@ -170,6 +170,8 @@ void CategorizedView::updateGeometries()
{ {
QListView::updateGeometries(); QListView::updateGeometries();
int previousScroll = verticalScrollBar()->value();
invalidateCaches(); invalidateCaches();
QMap<QString, Category *> cats; QMap<QString, Category *> cats;
@ -216,6 +218,8 @@ void CategorizedView::updateGeometries()
verticalScrollBar()->setRange(0, totalHeight- height()); verticalScrollBar()->setRange(0, totalHeight- height());
} }
verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
update(); update();
} }
@ -435,13 +439,7 @@ void CategorizedView::mousePressEvent(QMouseEvent *event)
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
setAutoScroll(autoScroll); setAutoScroll(autoScroll);
QRect rect(m_pressedPosition, pos); QRect rect(m_pressedPosition, pos);
if (command.testFlag(QItemSelectionModel::Toggle)) setSelection(rect, QItemSelectionModel::ClearAndSelect);
{
command &= ~QItemSelectionModel::Toggle;
m_ctrlDragSelectionFlag = selectionModel()->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
command |= m_ctrlDragSelectionFlag;
}
setSelection(rect, command);
// signal handlers may change the model // signal handlers may change the model
emit pressed(index); emit pressed(index);
@ -519,7 +517,7 @@ void CategorizedView::mouseMoveEvent(QMouseEvent *event)
} }
void CategorizedView::mouseReleaseEvent(QMouseEvent *event) void CategorizedView::mouseReleaseEvent(QMouseEvent *event)
{ {
QPoint pos = event->pos() - offset(); QPoint pos = event->pos() + offset();
QPersistentModelIndex index = indexAt(pos); QPersistentModelIndex index = indexAt(pos);
bool click = (index == m_pressedIndex && index.isValid()) || (m_pressedCategory && m_pressedCategory == categoryAt(pos)); bool click = (index == m_pressedIndex && index.isValid()) || (m_pressedCategory && m_pressedCategory == categoryAt(pos));
@ -611,7 +609,7 @@ void CategorizedView::paintEvent(QPaintEvent *event)
option.rect = visualRect(index); option.rect = visualRect(index);
option.widget = this; option.widget = this;
option.features |= wordWrap() ? QStyleOptionViewItemV2::WrapText : QStyleOptionViewItemV2::None; option.features |= wordWrap() ? QStyleOptionViewItemV2::WrapText : QStyleOptionViewItemV2::None;
if (flags & Qt::ItemIsSelectable) if (flags & Qt::ItemIsSelectable && selectionModel()->isSelected(index))
{ {
option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected : QStyle::State_None; option.state |= selectionModel()->isSelected(index) ? QStyle::State_Selected : QStyle::State_None;
} }
@ -844,16 +842,15 @@ QModelIndex CategorizedView::indexAt(const QPoint &point) const
} }
void CategorizedView::setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands) void CategorizedView::setSelection(const QRect &rect, const QItemSelectionModel::SelectionFlags commands)
{ {
QItemSelection selection;
for (int i = 0; i < model()->rowCount(); ++i) for (int i = 0; i < model()->rowCount(); ++i)
{ {
QModelIndex index = model()->index(i, 0); QModelIndex index = model()->index(i, 0);
if (visualRect(index).intersects(rect)) if (visualRect(index).intersects(rect))
{ {
selection.merge(QItemSelection(index, index), QItemSelectionModel::Select); selectionModel()->select(index, commands);
} }
} }
selectionModel()->select(selection, commands); update();
} }
QPixmap CategorizedView::renderToPixmap(const QModelIndexList &indices, QRect *r) const QPixmap CategorizedView::renderToPixmap(const QModelIndexList &indices, QRect *r) const