From kde-commits Tue Jul 31 23:11:45 2012 From: Islam Wazery Date: Tue, 31 Jul 2012 23:11:45 +0000 To: kde-commits Subject: [digikam/development/3.0.0] utilities/cameragui/views: Removed unused classes Message-Id: <20120731231145.89E8DA60CD () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=134377659406001 Git commit 073424d253df080ca4dbe141adfa9f466c06d77b by Islam Wazery. Committed on 01/08/2012 at 01:10. Pushed by wazery into branch 'development/3.0.0'. Removed unused classes D +0 -947 utilities/cameragui/views/icategorizedview.cpp D +0 -199 utilities/cameragui/views/icategorizedview.h D +0 -1918 utilities/cameragui/views/importkcategorizedview.cpp D +0 -125 utilities/cameragui/views/importkcategorizedview.h D +0 -216 utilities/cameragui/views/importkcategorizedview_p.h http://commits.kde.org/digikam/073424d253df080ca4dbe141adfa9f466c06d77b diff --git a/utilities/cameragui/views/icategorizedview.cpp b/utilities/cam= eragui/views/icategorizedview.cpp deleted file mode 100644 index d6dc8d4..0000000 --- a/utilities/cameragui/views/icategorizedview.cpp +++ /dev/null @@ -1,947 +0,0 @@ -/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - * - * This file is a part of digiKam project - * http://www.digikam.org - * - * Date : 2012-07-08 - * Description : Item view to list import interface items. - * - * Copyright (C) 2012 by Islam Wazery - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ - -#include "icategorizedview.moc" - -// Qt includes - -#include -#include -#include - -// KDE includes - -#include -#include - -// Local includes - -#include "thememanager.h" - -namespace Digikam -{ - -class ICategorizedView::Private -{ -public: - - Private(ICategorizedView* const q) : - delegate(0), - currentMouseEvent(0), - usePointingHand(true), - scrollStepFactor(10), - toolTip(0), - notificationToolTip(0), - showToolTip(false), - hintAtSelectionRow(-1), - ensureOneSelectedItem(false), - ensureInitialSelectedItem(false), - q(q) - { - } - - QModelIndex scrollPositionHint() const; - -public: - - DItemDelegate* delegate; - QMouseEvent* currentMouseEvent; - bool usePointingHand; - int scrollStepFactor; - ItemViewToolTip* toolTip; - ItemViewToolTip* notificationToolTip; - bool showToolTip; - - QPersistentModelIndex hintAtSelectionIndex; - QPersistentModelIndex hintAtScrollPosition; - int hintAtSelectionRow; - bool ensureOneSelectedItem; - bool ensureInitialSelectedItem; - - ICategorizedView* const q; -}; - -QModelIndex ICategorizedView::Private::scrollPositionHint() const -{ - if (q->verticalScrollBar()->value() =3D=3D q->verticalScrollBar()->min= imum()) - { - return QModelIndex(); - } - - QModelIndex hint =3D q->currentIndex(); - - // If the user scrolled, do not take current item, but first visible - if (!hint.isValid() || !q->viewport()->rect().intersects(q->visualRect= (hint))) - { - QList visibleIndexes =3D q->categorizedIndexesIn(q->v= iewport()->rect()); - if (!visibleIndexes.isEmpty()) - { - hint =3D visibleIndexes.first(); - } - } - - return hint; -} - -ICategorizedView::ICategorizedView(QWidget* const parent) - : ImportKCategorizedView(parent), d(new Private(this)) -{ - setViewMode(QListView::IconMode); - setLayoutDirection(Qt::LeftToRight); - setFlow(QListView::LeftToRight); - setResizeMode(QListView::Adjust); - setMovement(QListView::Static); - setWrapping(true); - - // important optimization for layouting - setUniformItemSizes(true); - // disable "feature" from ImportKCategorizedView - setDrawDraggedItems(false); - - setSelectionMode(QAbstractItemView::ExtendedSelection); - - setDragEnabled(true); - setEditTriggers(QAbstractItemView::NoEditTriggers); - viewport()->setAcceptDrops(true); - setMouseTracking(true); - - connect(this, SIGNAL(activated(QModelIndex)), - this, SLOT(slotActivated(QModelIndex))); - - connect(this, SIGNAL(clicked(QModelIndex)), - this, SLOT(slotClicked(QModelIndex))); - - connect(this, SIGNAL(entered(QModelIndex)), - this, SLOT(slotEntered(QModelIndex))); - - connect(ThemeManager::instance(), SIGNAL(signalThemeChanged()), - this, SLOT(slotThemeChanged())); -} - -ICategorizedView::~ICategorizedView() -{ - delete d; -} - -int ICategorizedView::numberOfSelectedIndexes() const -{ - return selectedIndexes().size(); -} - -void ICategorizedView::toFirstIndex() -{ - QModelIndex index =3D moveCursor(MoveHome, Qt::NoModifier); - clearSelection(); - setCurrentIndex(index); - scrollToTop(); -} - -void ICategorizedView::toLastIndex() -{ - QModelIndex index =3D moveCursor(MoveEnd, Qt::NoModifier); - clearSelection(); - setCurrentIndex(index); - scrollToTop(); -} - -void ICategorizedView::toNextIndex() -{ - toIndex(moveCursor(MoveNext, Qt::NoModifier)); -} - -void ICategorizedView::toPreviousIndex() -{ - toIndex(moveCursor(MovePrevious, Qt::NoModifier)); -} - -void ICategorizedView::toIndex(const QModelIndex& index) -{ - if (!index.isValid()) - { - return; - } - - clearSelection(); - setCurrentIndex(index); - scrollTo(index); -} - -void ICategorizedView::awayFromSelection() -{ - QItemSelection selection =3D selectionModel()->selection(); - - if (selection.isEmpty()) - { - return; - } - - const QModelIndex first =3D model()->index(0, 0); - const QModelIndex last =3D model()->index(model()->rowCount() -1, 0); - - if (selection.contains(first) && selection.contains(last)) - { - QItemSelection remaining(first, last); - remaining.merge(selection, QItemSelectionModel::Toggle); - QList indexes =3D remaining.indexes(); - - if (indexes.isEmpty()) - { - clearSelection(); - setCurrentIndex(QModelIndex()); - } - else - { - toIndex(remaining.indexes().first()); - } - } - else if (selection.contains(last)) - { - setCurrentIndex(selection.indexes().first()); - toPreviousIndex(); - } - else - { - setCurrentIndex(selection.indexes().last()); - toNextIndex(); - } -} - -void ICategorizedView::scrollToRelaxed(const QModelIndex& index, ScrollHin= t hint) -{ - if (viewport()->rect().intersects(visualRect(index))) - { - return; - } - - scrollTo(index, hint); -} - -void ICategorizedView::setScrollStepGranularity(int factor) -{ - d->scrollStepFactor =3D qMax(1, factor); -} - -void ICategorizedView::setSelectedIndexes(const QList& indexe= s) -{ - if (selectedIndexes() =3D=3D indexes) - { - return; - } - - QItemSelection mySelection; - - foreach (const QModelIndex& index, indexes) - { - mySelection.select(index, index); - } - - selectionModel()->select(mySelection, QItemSelectionModel::ClearAndSel= ect); -} - -void ICategorizedView::invertSelection() -{ - const QModelIndex topLeft =3D model()->index(0, 0); - const QModelIndex bottomRight =3D model()->index(model()->rowCount() -= 1, 0); - - const QItemSelection selection(topLeft, bottomRight); - selectionModel()->select(selection, QItemSelectionModel::Toggle); -} - -void ICategorizedView::setSpacing(int space) -{ - d->delegate->setSpacing(space); -} - -void ICategorizedView::setToolTipEnabled(bool enabled) -{ - d->showToolTip; -} - -bool ICategorizedView::isToolTipEnabled() const -{ - return d->showToolTip; -} - -void ICategorizedView::setUsePointingHandCursor(bool useCursor) -{ - d->usePointingHand =3D useCursor; -} - -void ICategorizedView::showIndexNotification(const QModelIndex& index, con= st QString& message) -{ - hideIndexNotification(); - if (!index.isValid()) - { - return; - } - - if (!d->notificationToolTip) - { - d->notificationToolTip =3D new ItemViewToolTip(this); - } - - d->notificationToolTip->setTipContents(message); - - QStyleOptionViewItem option =3D viewOptions(); - option.rect =3D visualRect(index); - option.state |=3D (index =3D=3D currentIndex() ? QStyle= ::State_HasFocus : QStyle::State_None); - d->notificationToolTip->show(option, index); -} - -void ICategorizedView::hideIndexNotification() -{ - if (d->notificationToolTip) - { - d->notificationToolTip->hide(); - } -} - -void ICategorizedView::slotActivated(const QModelIndex& index) -{ - if (d->currentMouseEvent) - { - // ignore activation if Ctrl or Shift is pressed (for selection) - Qt::KeyboardModifiers modifiers =3D d->currentMouseEvent->modifier= s(); - const bool shiftKeyPressed =3D modifiers & Qt::ShiftModifier; - const bool controlKeyPressed =3D modifiers & Qt::ControlModifie= r; - - if (shiftKeyPressed || controlKeyPressed) - { - return; - } - - const bool rightClick =3D d->currentMouseEvent->button() & Qt::Rig= htButton; - - if (rightClick) - { - return; - } - - // if the activation is caused by mouse click (not keyboard) - // we need to check the hot area - if (!d->delegate->acceptsActivation(d->currentMouseEvent->pos(), v= isualRect(index), index)) - { - return; - } - } - - indexActivated(index); -} - -void ICategorizedView::slotClicked(const QModelIndex& index) -{ - if (d->currentMouseEvent) - { - emit clicked(d->currentMouseEvent, index); - } -} - -void ICategorizedView::slotEntered(const QModelIndex& index) -{ - if (d->currentMouseEvent) - { - emit entered(d->currentMouseEvent, index); - } -} - - -void ICategorizedView::layoutAboutToBeChanged() -{ - d->ensureOneSelectedItem =3D selectionModel()->hasSelection(); - QModelIndex current =3D currentIndex(); - - // store some hints so that if all selected items were removed do not = need to default to 0,0. - if (d->ensureOneSelectedItem) - { - QItemSelection currentSelection =3D selectionModel()->selection(); - QModelIndex indexToAnchor; - - if (currentSelection.contains(current)) - { - indexToAnchor =3D current; - } - else if (!currentSelection.isEmpty()) - { - indexToAnchor =3D currentSelection.first().topLeft(); - } - - if (indexToAnchor.isValid()) - { - d->hintAtSelectionRow =3D indexToAnchor.row(); - d->hintAtSelectionIndex =3D nextIndexHint(indexToAnchor, QItem= SelectionRange(indexToAnchor)); - } - } - - // some precautions to keep current scroll position - d->hintAtScrollPosition =3D d->scrollPositionHint(); -} - -void ICategorizedView::layoutWasChanged() -{ - // connected queued to layoutChanged() - ensureSelectionAfterChanges(); - if (d->hintAtScrollPosition.isValid()) - { - scrollToRelaxed(d->hintAtScrollPosition); - d->hintAtScrollPosition =3D QModelIndex(); - } - else - { - scrollToRelaxed(currentIndex()); - } -} - -void ICategorizedView::slotThemeChanged() -{ - viewport()->update(); -} - -void ICategorizedView::slotSetupChanged() -{ - viewport()->update(); -} - -bool ICategorizedView::showToolTip(const QModelIndex& index, QStyleOptionV= iewItem& option, QHelpEvent* he) -{ - QRect innerRect; - QPoint pos; - - if (he) - { - pos =3D he->pos(); - } - else - { - pos =3D option.rect.center(); - } - - if (d->delegate->acceptsToolTip(he->pos(), option.rect, index,& innerR= ect)) - { - if (!innerRect.isNull()) - { - option.rect =3D innerRect; - } - - d->toolTip->show(option, index); - return true; - } - - return false; -} - -void ICategorizedView::setItemDelegate(DItemDelegate* delegate) -{ - if (d->delegate =3D=3D delegate) - { - return; - } - - if (d->delegate) - { - disconnect(d->delegate, SIGNAL(gridSizeChanged(QSize)), this, SLOT= (slotGridSizeChanged(QSize))); - } - - d->delegate =3D delegate; - ImportKCategorizedView::setItemDelegate(d->delegate); - - connect(d->delegate, SIGNAL(gridSizeChanged(QSize)), this, SLOT(slotGr= idSizeChanged(QSize))); -} - -void ICategorizedView::contextMenuEvent(QContextMenuEvent* event) -{ - userInteraction(); - QModelIndex index =3D indexAt(event->pos()); - - if (index.isValid()) - { - showContextMenuOnIndex(event, index); - } - else - { - showContextMenu(event); - } -} - -void ICategorizedView::keyPressEvent(QKeyEvent* event) -{ - userInteraction(); - - if (event =3D=3D QKeySequence::Copy) - { - copy(); - event->accept(); - return; - } - else if (event =3D=3D QKeySequence::Paste) - { - paste(); - event->accept(); - return; - } - - ImportKCategorizedView::keyPressEvent(event); - - emit keyPressed(event); -} - -void ICategorizedView::mousePressEvent(QMouseEvent* event) -{ - userInteraction(); - const QModelIndex index =3D indexAt(event->pos()); - - // Clear selection on click on empty area. Standard behavior, but not = done by QAbstractItemView for some reason. - Qt::KeyboardModifiers modifiers =3D event->modifiers(); - const Qt::MouseButton button =3D event->button(); - const bool rightButtonPressed =3D button & Qt::RightButton; - const bool shiftKeyPressed =3D modifiers & Qt::ShiftModifier; - const bool controlKeyPressed =3D modifiers & Qt::ControlModifier; - - if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !co= ntrolKeyPressed) - { - clearSelection(); - } - - // store event for entered(), clicked(), activated() signal handlers - if (!rightButtonPressed) - { - d->currentMouseEvent =3D event; - } - else - { - d->currentMouseEvent =3D 0; - } - - ImportKCategorizedView::mousePressEvent(event); - if (!index.isValid()) - { - emit viewportClicked(event); - } - d->currentMouseEvent =3D 0; -} - -void ICategorizedView::mouseReleaseEvent(QMouseEvent* event) -{ - userInteraction(); - d->currentMouseEvent =3D event; - ImportKCategorizedView::mouseReleaseEvent(event); - d->currentMouseEvent =3D 0; -} - -void ICategorizedView::mouseMoveEvent(QMouseEvent* event) -{ - QModelIndex index =3D indexAt(event->pos()); - QRect indexVisualRect; - - if (index.isValid()) - { - indexVisualRect =3D visualRect(index); - - if (d->usePointingHand && - KGlobalSettings::changeCursorOverIcon() && - d->delegate->acceptsActivation(event->pos(), indexVisualRect, = index)) - { - setCursor(Qt::PointingHandCursor); - } - else - { - unsetCursor(); - } - } - else - { - unsetCursor(); - } - - d->currentMouseEvent =3D event; - ImportKCategorizedView::mouseMoveEvent(event); - d->currentMouseEvent =3D 0; - - d->delegate->mouseMoved(event, indexVisualRect, index); -} - -void ICategorizedView::resizeEvent(QResizeEvent* e) -{ - QModelIndex oldPosition =3D d->scrollPositionHint(); - ImportKCategorizedView::resizeEvent(e); - updateDelegateSizes(); - scrollToRelaxed(oldPosition, QAbstractItemView::PositionAtTop); -} - -void ICategorizedView::rowsAboutToBeRemoved(const QModelIndex& parent, int= start, int end) -{ - ImportKCategorizedView::rowsAboutToBeRemoved(parent, start, end); - - // Ensure one selected item - int totalToRemove =3D end - start + 1; - bool remainingRows =3D model()->rowCount(parent) > totalToRemove; - - if (!remainingRows) - { - return; - } - - QItemSelection removed(model()->index(start, 0), model()->index(end, 0= )); - - if (selectionModel()->hasSelection()) - { - // find out which selected indexes are left after rows are removed - QItemSelection selected =3D selectionModel()->selection(); - QModelIndex current =3D currentIndex(); - QModelIndex indexToAnchor; - - if (selected.contains(current)) - { - indexToAnchor =3D current; - } - else if (!selected.isEmpty()) - { - indexToAnchor =3D selected.first().topLeft(); - } - - selected.merge(removed, QItemSelectionModel::Deselect); - - if (selected.isEmpty()) - { - QModelIndex newCurrent =3D nextIndexHint(indexToAnchor, remove= d.first() /*a range*/); - setCurrentIndex(newCurrent); - } - } - - QModelIndex hint =3D d->scrollPositionHint(); - if (removed.contains(hint)) - { - d->hintAtScrollPosition =3D nextIndexHint(hint, removed.first() /*= a range*/); - } -} - -void ICategorizedView::rowsInserted(const QModelIndex& parent, int start, = int end) -{ - ImportKCategorizedView::rowsInserted(parent, start, end); - - if (start =3D=3D 0) - { - ensureSelectionAfterChanges(); - } -} - -void ICategorizedView::reset() -{ - ImportKCategorizedView::reset(); - - emit selectionChanged(); - emit selectionCleared(); - - d->ensureInitialSelectedItem =3D true; - d->hintAtScrollPosition =3D QModelIndex(); - d->hintAtSelectionIndex =3D QModelIndex(); - d->hintAtSelectionRow =3D -1; - verticalScrollBar()->setValue(verticalScrollBar()->minimum()); - horizontalScrollBar()->setValue(horizontalScrollBar()->minimum()); -} - -void ICategorizedView::selectionChanged(const QItemSelection& selectedItem= s, const QItemSelection& deselectedItems) -{ - ImportKCategorizedView::selectionChanged(selectedItems, deselectedItem= s); - - emit selectionChanged(); - - if (!selectionModel()->hasSelection()) - { - emit selectionCleared(); - } - - userInteraction(); -} - -void ICategorizedView::wheelEvent(QWheelEvent* event) -{ - // ImportKCategorizedView updates the single step at some occasions in= a private method - horizontalScrollBar()->setSingleStep(d->delegate->gridSize().height() = / d->scrollStepFactor); - verticalScrollBar()->setSingleStep(d->delegate->gridSize().width() / d= ->scrollStepFactor); - - if (event->modifiers() & Qt::ControlModifier) - { - const int delta =3D event->delta(); - - if (delta > 0) - { - emit zoomInStep(); - } - else if (delta < 0) - { - emit zoomOutStep(); - } - - event->accept(); - return; - } - - if (verticalScrollBarPolicy() =3D=3D Qt::ScrollBarAlwaysOff && event->= orientation() =3D=3D Qt::Vertical) - { - QWheelEvent n(event->pos(), event->globalPos(), event->delta(), - event->buttons(), event->modifiers(), Qt::Horizontal= ); - QApplication::sendEvent(horizontalScrollBar(), &n); - event->setAccepted(n.isAccepted()); - } - else - { - ImportKCategorizedView::wheelEvent(event); - } -} - -bool ICategorizedView::viewportEvent(QEvent* event) -{ - switch (event->type()) - { - case QEvent::FontChange: - { - updateDelegateSizes(); - break; - } - case QEvent::ToolTip: - { - if (!d->showToolTip) - { - return true; - } - - QHelpEvent* he =3D static_cast(event); - const QModelIndex index =3D indexAt(he->pos()); - - if (!index.isValid()) - { - break; - } - - QStyleOptionViewItem option =3D viewOptions(); - option.rect =3D visualRect(index); - option.state |=3D (index =3D=3D currentIndex() = ? QStyle::State_HasFocus : QStyle::State_None); - showToolTip(index, option, he); - return true; - } - default: - break; - } - - return ImportKCategorizedView::viewportEvent(event); -} - -QModelIndex ICategorizedView::moveCursor(CursorAction cursorAction, Qt::Ke= yboardModifiers modifiers) -{ - QModelIndex current =3D currentIndex(); - - if (!current.isValid()) - { - return ImportKCategorizedView::moveCursor(cursorAction, modifiers); - } - - // We want a simple wrapping navigation. - // Default behavior we do not want: right/left does never change row; = Next/Previous is equivalent to Down/Up - switch (cursorAction) - { - case MoveNext: - case MoveRight: - { - QModelIndex next =3D model()->index(current.row() + 1, 0); - - if (next.isValid()) - { - return next; - } - else - { - return current; - } - - break; - } - case MovePrevious: - case MoveLeft: - { - QModelIndex previous =3D model()->index(current.row() - 1, 0); - - if (previous.isValid()) - { - return previous; - } - else - { - return current; - } - - break; - } - default: - break; - } - - return ImportKCategorizedView::moveCursor(cursorAction, modifiers); -} - - -void ICategorizedView::showContextMenuOnIndex(QContextMenuEvent*, const QM= odelIndex&) -{ - // implemented in subclass -} - -void ICategorizedView::showContextMenu(QContextMenuEvent*) -{ - // implemented in subclass -} - -void ICategorizedView::indexActivated(const QModelIndex&) -{ -} - -QModelIndex ICategorizedView::mapIndexForDragDrop(const QModelIndex& index= ) const -{ - return filterModel()->mapToSource(index); -} - -QPixmap ICategorizedView::pixmapForDrag(const QList& indexes)= const -{ - QStyleOptionViewItem option =3D viewOptions(); - option.rect =3D viewport()->rect(); - return d->delegate->pixmapForDrag(option, indexes); -} - -QModelIndex ICategorizedView::nextIndexHint(const QModelIndex& indexToAnch= or, const QItemSelectionRange& removed) const -{ - Q_UNUSED(indexToAnchor); - - if (removed.bottomRight().row() =3D=3D model()->rowCount() - 1) - { - if (removed.topLeft().row() =3D=3D 0) - { - return QModelIndex(); - } - return model()->index(removed.topLeft().row() - 1, 0); // last = remaining, no next one left - } - else - { - return model()->index(removed.bottomRight().row() + 1, 0); // n= ext remaining - } -} - -void ICategorizedView::setToolTip(ItemViewToolTip* tip) -{ - d->toolTip =3D tip; -} - -void ICategorizedView::updateDelegateSizes() -{ - QStyleOptionViewItem option =3D viewOptions(); - option.rect =3D QRect(QPoint(0,0), viewport()->size()); - d->delegate->setDefaultViewOptions(option); -} - -void ICategorizedView::userInteraction() -{ - // as soon as the user did anything affecting selection, we don't inte= rfere anymore - d->ensureInitialSelectedItem =3D false; - d->hintAtSelectionIndex =3D QModelIndex(); -} - - -QModelIndex ICategorizedView::indexForCategoryAt(const QPoint& pos) const -{ - return categoryAt(pos); -} - -void ICategorizedView::slotGridSizeChanged(const QSize& size) -{ - setGridSize(size); - - if (!size.isNull()) - { - horizontalScrollBar()->setSingleStep(size.width() / d->scrollStepF= actor); - verticalScrollBar()->setSingleStep(size.height() / d->scrollStepFa= ctor); - } -} - -void ICategorizedView::ensureSelectionAfterChanges() -{ - if (d->ensureInitialSelectedItem && model()->rowCount()) - { - // Ensure the item (0,0) is selected, if the model was reset previ= ously - // and the user did not change the selection since reset. - // Caveat: Item at (0,0) may have changed. - bool hadInitial =3D d->ensureInitialSelectedItem; - d->ensureInitialSelectedItem =3D false; - d->ensureOneSelectedItem =3D false; - QModelIndex index =3D model()->index(0,0); - - if (index.isValid()) - { - selectionModel()->select(index, QItemSelectionModel::SelectCur= rent | QItemSelectionModel::Clear); - setCurrentIndex(index); - - // we want ensureInitial set to false if and only if the selec= tion - // is done from any other place than the previous line (i.e., = by user action) - // Effect: we select whatever is the current index(0,0) - if (hadInitial) - { - d->ensureInitialSelectedItem =3D true; - } - } - } - else if (d->ensureOneSelectedItem) - { - // ensure we have a selection if there was one before - d->ensureOneSelectedItem =3D false; - - if (model()->rowCount() && selectionModel()->selection().isEmpty()) - { - QModelIndex index; - - if (d->hintAtSelectionIndex.isValid()) - { - index =3D d->hintAtSelectionIndex; - } - else if (d->hintAtSelectionRow !=3D -1) - { - index =3D model()->index(qMin(model()->rowCount(), d->hint= AtSelectionRow), 0); - } - else - { - index =3D currentIndex(); - } - - if (!index.isValid()) - { - index =3D model()->index(0,0); - } - - d->hintAtSelectionRow =3D -1; - d->hintAtSelectionIndex =3D QModelIndex(); - - if (index.isValid()) - { - setCurrentIndex(index); - selectionModel()->select(index, QItemSelectionModel::Selec= tCurrent); - } - } - } -} - -} // namespace Digikam diff --git a/utilities/cameragui/views/icategorizedview.h b/utilities/camer= agui/views/icategorizedview.h deleted file mode 100644 index f7f4bc8..0000000 --- a/utilities/cameragui/views/icategorizedview.h +++ /dev/null @@ -1,199 +0,0 @@ -/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - * - * This file is a part of digiKam project - * http://www.digikam.org - * - * Date : 2012-07-08 - * Description : Item view to list import interface items. - * - * Copyright (C) 2012 by Islam Wazery - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ - -#ifndef ICATEGORIZEDVIEW_H -#define ICATEGORIZEDVIEW_H - -// Local includes - -#include "importkcategorizedview.h" -#include "dragdropimplementations.h" -#include "ditemdelegate.h" -#include "itemviewtooltip.h" - -class QSortFilterProxyModel; - -namespace Digikam -{ - -class ICategorizedView : public ImportKCategorizedView, DragDropViewImplem= entation -{ - Q_OBJECT - -public: - - ICategorizedView(QWidget* const parent =3D 0); - ~ICategorizedView(); - - DItemDelegate* delegate() const; - - int numberOfSelectedIndexes() const; - - /** Selects the index as current and scrolls to it */ - void toFirstIndex(); - void toLastIndex(); - void toNextIndex(); - void toPreviousIndex(); - void toIndex(const QModelIndex& index); - void awayFromSelection(); - - /** Like scrollTo, but only scrolls if the index is not visible, regar= dless of hint. */ - void scrollToRelaxed(const QModelIndex& index, ScrollHint hint =3D Ens= ureVisible); - - /** Determine a step size for scrolling. The larget this number, the s= maller and more - * precise is the scrolling. Default is 10. */ - void setScrollStepGranularity(int factor); - - void setSelectedIndexes(const QList& indexes); - void invertSelection(); - - /** Sets the spacing. Does not use setSpacing()/spacing() from QListVi= ew */ - void setSpacing(int space); - - void setToolTipEnabled(bool enabled); - bool isToolTipEnabled() const; - - /** Set if the PointingHand Cursor should be shown over the activation= area */ - void setUsePointingHandCursor(bool useCursor); - - virtual QSortFilterProxyModel* filterModel() const =3D 0; - -public Q_SLOTS: - - virtual void copy() { DragDropViewImplementation::copy(); } - virtual void cut() { DragDropViewImplementation::cut(); } - virtual void paste() { DragDropViewImplementation::paste(); } - - void showIndexNotification(const QModelIndex& index, const QString& me= ssage); - void hideIndexNotification(); - -Q_SIGNALS: - - /** For overlays: Like the respective parent class signals, but with a= dditional info. - * Do not change the mouse events. - */ - void clicked(const QMouseEvent* e, const QModelIndex& index); - void entered(const QMouseEvent* e, const QModelIndex& index); - - /** While clicked() is emitted with a valid index, this corresponds to= clicking on empty space. - */ - void viewportClicked(const QMouseEvent* e); - - /** Remember you may want to check if the event is accepted or ignore= d. - * This signal is emitted after being handled by this widget. - * You can accept it if ignored. - */ - void keyPressed(QKeyEvent* e); - - void zoomInStep(); - void zoomOutStep(); - - /** Emitted when any selection change occurs. Any of the signals below= will be emitted before. - */ - void selectionChanged(); - - /** Emitted when the selection is completely cleared. - */ - void selectionCleared(); - -protected Q_SLOTS: - - void slotClicked(const QModelIndex& index); - void slotActivated(const QModelIndex& index); - void slotEntered(const QModelIndex& index); - void layoutAboutToBeChanged(); - void layoutWasChanged(); - - virtual void slotThemeChanged(); - virtual void slotSetupChanged(); - -protected: - - /** Provides default behavior, can reimplement in a subclass. - * Returns true if a tooltip was shown. - * The help event is optional. - */ - virtual bool showToolTip(const QModelIndex& index, QStyleOptionViewIte= m& option, QHelpEvent* e =3D 0); - - // reimplemented from parent class - void contextMenuEvent(QContextMenuEvent* event); - void keyPressEvent(QKeyEvent* event); - void mousePressEvent(QMouseEvent* event); - void mouseReleaseEvent(QMouseEvent* event); - void mouseMoveEvent(QMouseEvent* event); - void resizeEvent(QResizeEvent* event); - void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int en= d); - void rowsInserted(const QModelIndex &parent, int start, int end); - void reset(); - void selectionChanged(const QItemSelection& selectedItems, const QItem= Selection& deselectedItems); - void wheelEvent(QWheelEvent* event); - bool viewportEvent(QEvent* event); - QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifier= s modifiers); - - /** Reimplement thses in a subclass. - */ - virtual void showContextMenuOnIndex(QContextMenuEvent* event, const QM= odelIndex& index); - virtual void showContextMenu(QContextMenuEvent* event); - virtual void indexActivated(const QModelIndex& index); - - DECLARE_VIEW_DRAG_DROP_METHODS(ImportKCategorizedView) - - /** Note: pure virtual dragDropHandler() still open from DragDropViewI= mplementation. - */ - virtual QModelIndex mapIndexForDragDrop(const QModelIndex& index) cons= t; - virtual QPixmap pixmapForDrag(const QList& indexes) c= onst; - - /** - * Assuming the given indexes would be removed (hypothetically!), - * return the index to be selected instead, starting from anchor. - * The default implementation returns the next remaining sibling. - */ - virtual QModelIndex nextIndexHint(const QModelIndex& indexToAnchor, co= nst QItemSelectionRange& removed) const; - - void setToolTip(ItemViewToolTip* tip); - void setItemDelegate(DItemDelegate* delegate); - - void updateDelegateSizes(); - void userInteraction(); - - /** Returns an index that is representative for the category at positi= on pos. - */ - QModelIndex indexForCategoryAt(const QPoint& pos) const; - -private Q_SLOTS: - - void slotGridSizeChanged(const QSize&); - -private: - - void ensureSelectionAfterChanges(); - -private: - - class Private; - Private* const d; -}; - -} // namespace Digikam - -#endif // ICATEGORIZEDVIEW_H diff --git a/utilities/cameragui/views/importkcategorizedview.cpp b/utiliti= es/cameragui/views/importkcategorizedview.cpp deleted file mode 100644 index b3d7899..0000000 --- a/utilities/cameragui/views/importkcategorizedview.cpp +++ /dev/null @@ -1,1918 +0,0 @@ -/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - * - * This file is a part of digiKam project - * http://www.digikam.org - * - * Date : 2012-07-05 - * Description : Base item view to list import interface items. - * - * Copyright (C) 2012 by Islam Wazery - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ - -#include "importkcategorizedview.moc" - -// C++ includes - -#include // trunc on C99 compliant systems - -#if !defined(__MINGW32__) -#include // trunc for not C99 compliant systems -#endif - -// Qt includes - -#include -#include - -// KDE includes - -#include "kcategorizedsortfilterproxymodel.h" -#include "kcategorydrawer.h" - -// Local includes - -#include "importkcategorizedview_p.h" - -namespace Digikam -{ - -ImportKCategorizedView::Private::Private(ImportKCategorizedView* const lis= tView) - : listView(listView), - categoryDrawer(0), - biggestItemSize(QSize(0, 0)), - mouseButtonPressed(false), - rightMouseButtonPressed(false), - dragLeftViewport(false), - drawItemsWhileDragging(true), - proxyModel(0) -{ -} - -ImportKCategorizedView::Private::~Private() -{ -} - -const QModelIndexList& ImportKCategorizedView::Private::intersectionSet(co= nst QRect& rect) -{ - QModelIndex index; - QRect indexVisualRect; - int itemHeight; - - intersectedIndexes.clear(); - - if (listView->gridSize().isEmpty()) - { - itemHeight =3D biggestItemSize.height(); - } - else - { - itemHeight =3D listView->gridSize().height(); - } - - // Lets find out where we should start - int top =3D proxyModel->rowCount() - 1; - int bottom =3D 0; - int middle =3D (top + bottom) / 2; - - while (bottom <=3D top) - { - middle =3D (top + bottom) / 2; - index =3D proxyModel->index(middle, 0); - indexVisualRect =3D visualRect(index); - - // We need the whole height (not only the visualRect). This will h= elp us to update - // all needed indexes correctly (ereslibre) - indexVisualRect.setHeight(indexVisualRect.height() + (itemHeight -= indexVisualRect.height())); - - if (qMax(indexVisualRect.topLeft().y(), indexVisualRect.bottomRigh= t().y()) < - qMin(rect.topLeft().y(), rect.bottomRight().y())) - { - bottom =3D middle + 1; - } - else - { - top =3D middle - 1; - } - } - - for (int i =3D middle; i < proxyModel->rowCount(); ++i) - { - index =3D proxyModel->index(i, 0); - indexVisualRect =3D visualRect(index); - - if (rect.intersects(indexVisualRect)) - { - intersectedIndexes.append(index); - } - - // If we passed next item, stop searching for hits - if (qMax(rect.bottomRight().y(), rect.topLeft().y()) < - qMin(indexVisualRect.topLeft().y(), indexVisualRect.bottomRigh= t().y())) - { - break; - } - } - - return intersectedIndexes; -} - -QRect ImportKCategorizedView::Private::visualRectInViewport(const QModelIn= dex& index) const -{ - if (!index.isValid()) - { - return QRect(); - } - - QRect retRect; - QString curCategory =3D elementsInfo[index.row()].category; - const bool leftToRightFlow =3D (listView->flow() =3D=3D QListView::Lef= tToRight); - - if (leftToRightFlow) - { - if (listView->layoutDirection() =3D=3D Qt::LeftToRight) - { - retRect =3D QRect(listView->spacing(), listView->spacing() * 2= + - categoryDrawer->categoryHeight(index, listView= ->viewOptions()), 0, 0); - } - else - { - retRect =3D QRect(listView->viewport()->width() - listView->sp= acing(), listView->spacing() * 2 + - categoryDrawer->categoryHeight(index, listView= ->viewOptions()), 0, 0); - } - } - else - { - retRect =3D QRect(listView->spacing(), listView->spacing() * 2 + - categoryDrawer->categoryHeight(index, listView->vi= ewOptions()), 0, 0); - } - - int viewportWidth =3D listView->viewport()->width() - listView->spacin= g(); - int itemHeight; - int itemWidth; - - if (listView->gridSize().isEmpty() && leftToRightFlow) - { - itemHeight =3D biggestItemSize.height(); - itemWidth =3D biggestItemSize.width(); - } - else if (leftToRightFlow) - { - itemHeight =3D listView->gridSize().height(); - itemWidth =3D listView->gridSize().width(); - } - else if (listView->gridSize().isEmpty() && !leftToRightFlow) - { - itemHeight =3D biggestItemSize.height(); - itemWidth =3D listView->viewport()->width() - listView->spacing()= * 2; - } - else - { - itemHeight =3D listView->gridSize().height(); - itemWidth =3D listView->gridSize().width() - listView->spacing() = * 2; - } - - int itemWidthPlusSeparation =3D listView->spacing() + itemWidth; - - if (!itemWidthPlusSeparation) - { - ++itemWidthPlusSeparation; - } - - int elementsPerRow =3D viewportWidth / itemWidthPlusSeparation; - - if (!elementsPerRow) - { - ++elementsPerRow; - } - - int column; - int row; - - if (leftToRightFlow) - { - column =3D elementsInfo[index.row()].relativeOffsetToCategory % el= ementsPerRow; - row =3D elementsInfo[index.row()].relativeOffsetToCategory / el= ementsPerRow; - - if (listView->layoutDirection() =3D=3D Qt::LeftToRight) - { - retRect.setLeft(retRect.left() + column * listView->spacing() + - column * itemWidth); - } - else - { - retRect.setLeft(retRect.right() - column * listView->spacing()= - - column * itemWidth - itemWidth); - - retRect.setRight(retRect.right() - column * listView->spacing(= ) - - column * itemWidth); - } - } - else - { - elementsPerRow =3D 1; - column =3D elementsInfo[index.row()].relativeOffsetToCateg= ory % elementsPerRow; - row =3D elementsInfo[index.row()].relativeOffsetToCateg= ory / elementsPerRow; - } - - foreach(const QString& category, categories) - { - if (category =3D=3D curCategory) - { - break; - } - - float rows =3D (float) ((float) categoriesIndexes[category].count= () / - (float) elementsPerRow); - - int rowsInt =3D categoriesIndexes[category].count() / elementsPerR= ow; - - if (rows - trunc(rows)) - { - ++rowsInt; - } - - retRect.setTop(retRect.top() + - (rowsInt * itemHeight) + - categoryDrawer->categoryHeight(index, listView->vie= wOptions()) + - listView->spacing() * 2); - - if (listView->gridSize().isEmpty()) - { - retRect.setTop(retRect.top() + - (rowsInt * listView->spacing())); - } - } - - if (listView->gridSize().isEmpty()) - { - retRect.setTop(retRect.top() + row * listView->spacing() + - (row * itemHeight)); - } - else - { - retRect.setTop(retRect.top() + (row * itemHeight)); - } - - retRect.setWidth(itemWidth); - - QModelIndex heightIndex =3D proxyModel->index(index.row(), 0); - - if (listView->gridSize().isEmpty()) - { - retRect.setHeight(listView->sizeHintForIndex(heightIndex).height()= ); - } - else - { - const QSize sizeHint =3D listView->sizeHintForIndex(heightIndex); - - if (sizeHint.width() < itemWidth && leftToRightFlow) - { - retRect.setWidth(sizeHint.width()); - retRect.moveLeft(retRect.left() + (itemWidth - sizeHint.width(= )) / 2); - } - - retRect.setHeight(qMin(sizeHint.height(), listView->gridSize().hei= ght())); - } - - return retRect; -} - -QRect ImportKCategorizedView::Private::visualCategoryRectInViewport(const = QString& category) const -{ - QRect retRect(listView->spacing(), - listView->spacing(), - listView->viewport()->width() - listView->spacing() * 2, - 0); - - if (!proxyModel || !categoryDrawer || !proxyModel->isCategorizedModel(= ) || - !proxyModel->rowCount() || !categories.contains(category)) - { - return QRect(); - } - - QModelIndex index =3D proxyModel->index(0, 0, QModelIndex()); - int viewportWidth =3D listView->viewport()->width() - listView= ->spacing(); - int itemHeight; - int itemWidth; - - if (listView->gridSize().isEmpty()) - { - itemHeight =3D biggestItemSize.height(); - itemWidth =3D biggestItemSize.width(); - } - else - { - itemHeight =3D listView->gridSize().height(); - itemWidth =3D listView->gridSize().width(); - } - - int itemWidthPlusSeparation =3D listView->spacing() + itemWidth; - int elementsPerRow =3D viewportWidth / itemWidthPlusSeparatio= n; - - if (!elementsPerRow) - { - ++elementsPerRow; - } - - if (listView->flow() =3D=3D QListView::TopToBottom) - { - elementsPerRow =3D 1; - } - - foreach(const QString& itCategory, categories) - { - if (itCategory =3D=3D category) - { - break; - } - - float rows =3D (float) ((float) categoriesIndexes[itCategory].cou= nt() / - (float) elementsPerRow); - int rowsInt =3D categoriesIndexes[itCategory].count() / elementsPe= rRow; - - if (rows - trunc(rows)) - { - ++rowsInt; - } - - retRect.setTop(retRect.top() + - (rowsInt * itemHeight) + - categoryDrawer->categoryHeight(index, listView->vie= wOptions()) + - listView->spacing() * 2); - - if (listView->gridSize().isEmpty()) - { - retRect.setTop(retRect.top() + - (rowsInt * listView->spacing())); - } - } - - retRect.setHeight(categoryDrawer->categoryHeight(index, listView->view= Options())); - - return retRect; -} - -// We're sure elementsPosition doesn't contain index -const QRect& ImportKCategorizedView::Private::cacheIndex(const QModelIndex= & index) -{ - QRect rect =3D visualRectInViewport(index); - QHash::iterator it =3D elementsPosition.insert(index.row()= , rect); - - return *it; -} - -// We're sure categoriesPosition doesn't contain category -const QRect& ImportKCategorizedView::Private::cacheCategory(const QString&= category) -{ - QRect rect =3D visualCategoryRectInViewport(ca= tegory); - QHash::iterator it =3D categoriesPosition.insert(categ= ory, rect); - - return *it; -} - -const QRect& ImportKCategorizedView::Private::cachedRectIndex(const QModel= Index& index) -{ - QHash::const_iterator it =3D elementsPosition.constFind(in= dex.row()); - - if (it !=3D elementsPosition.constEnd()) // If we have it cached - { - // return it - return *it; - } - else // Otherwise, cache it - { - // and return it - return cacheIndex(index); - } -} - -const QRect& ImportKCategorizedView::Private::cachedRectCategory(const QSt= ring& category) -{ - QHash::const_iterator it =3D categoriesPosition.constF= ind(category); - - if (it !=3D categoriesPosition.constEnd()) // If we have it cached - { - // return it - return *it; - } - else // Otherwise, cache it= and - { - // return it - return cacheCategory(category); - } -} - -QRect ImportKCategorizedView::Private::visualRect(const QModelIndex& index) -{ - QRect retRect =3D cachedRectIndex(index); - int dx =3D -listView->horizontalOffset(); - int dy =3D -listView->verticalOffset(); - retRect.adjust(dx, dy, dx, dy); - - return retRect; -} - -QRect ImportKCategorizedView::Private::categoryVisualRect(const QString& c= ategory) -{ - QRect retRect =3D cachedRectCategory(category); - int dx =3D -listView->horizontalOffset(); - int dy =3D -listView->verticalOffset(); - retRect.adjust(dx, dy, dx, dy); - - return retRect; -} - -QSize ImportKCategorizedView::Private::contentsSize() -{ - // find the last index in the last category - QModelIndex lastIndex =3D categoriesIndexes.isEmpty() ? QModelIndex() : - proxyModel->index(categoriesIndexes[categories= .last()].last(), 0); - - int lastItemBottom =3D cachedRectIndex(lastIndex).top() + - listView->spacing() + - (listView->gridSize().isEmpty() ? biggestItemS= ize.height() - : listView->gr= idSize().height()) - listView->viewport()->height(); - - return QSize(listView->viewport()->width(), lastItemBottom); -} - -void ImportKCategorizedView::Private::drawNewCategory(const QModelIndex& i= ndex, int sortRole, - c= onst QStyleOption& option, QPainter* const painter) -{ - if (!index.isValid()) - { - return; - } - - QStyleOption optionCopy =3D option; - const QString category =3D proxyModel->data(index, KCategorizedSortFi= lterProxyModel::CategoryDisplayRole).toString(); - optionCopy.state &=3D ~QStyle::State_Selected; - - if ((listView->selectionMode() !=3D SingleSelection) && (listView->sel= ectionMode() !=3D NoSelection)) - { - if ((category =3D=3D hoveredCategory) && !mouseButtonPressed) - { - optionCopy.state |=3D QStyle::State_MouseOver; - } - else if ((category =3D=3D hoveredCategory) && mouseButtonPressed) - { - QPoint initialPressPosition =3D listView->viewport()->mapFromG= lobal(QCursor::pos()); - initialPressPosition.setY(initialPressPosition.y() + listView-= >verticalOffset()); - initialPressPosition.setX(initialPressPosition.x() + listView-= >horizontalOffset()); - - if (initialPressPosition =3D=3D this->initialPressPosition) - { - optionCopy.state |=3D QStyle::State_Selected; - } - } - } - - categoryDrawer->drawCategory(index, sortRole, optionCopy, painter); -} - -void ImportKCategorizedView::Private::updateScrollbars() -{ - listView->horizontalScrollBar()->setRange(0, 0); - - if (listView->verticalScrollMode() =3D=3D QAbstractItemView::ScrollPer= Item) - { - listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - } - - if (listView->horizontalScrollMode() =3D=3D QAbstractItemView::ScrollP= erItem) - { - listView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixe= l); - } - - listView->verticalScrollBar()->setSingleStep(listView->viewport()->hei= ght() / 10); - listView->verticalScrollBar()->setPageStep(listView->viewport()->heigh= t()); - listView->verticalScrollBar()->setRange(0, contentsSize().height()); -} - -void ImportKCategorizedView::Private::drawDraggedItems(QPainter* const pai= nter) -{ - QStyleOptionViewItemV4 option =3D listView->viewOptions(); - option.state &=3D ~QStyle::State_MouseOver; - - foreach(const QModelIndex& index, listView->selectionModel()->selected= Indexes()) - { - const int dx =3D mousePosition.x() - initialPressPosition.x() + li= stView->horizontalOffset(); - const int dy =3D mousePosition.y() - initialPressPosition.y() + li= stView->verticalOffset(); - option.rect =3D visualRect(index); - option.rect.adjust(dx, dy, dx, dy); - - if (option.rect.intersects(listView->viewport()->rect())) - { - listView->itemDelegate(index)->paint(painter, option, index); - } - } -} - -void ImportKCategorizedView::Private::drawDraggedItems() -{ - QRect rectToUpdate; - QRect currentRect; - - foreach(const QModelIndex& index, listView->selectionModel()->selected= Indexes()) - { - int dx =3D mousePosition.x() - initialPressPosition.x() + lis= tView->horizontalOffset(); - int dy =3D mousePosition.y() - initialPressPosition.y() + lis= tView->verticalOffset(); - currentRect =3D visualRect(index); - currentRect.adjust(dx, dy, dx, dy); - - if (currentRect.intersects(listView->viewport()->rect())) - { - rectToUpdate =3D rectToUpdate.united(currentRect); - } - } - - listView->viewport()->update(lastDraggedItemsRect.united(rectToUpdate)= ); - - lastDraggedItemsRect =3D rectToUpdate; -} - -// ---- ImportKCategorizedView ------------------------------ - -ImportKCategorizedView::ImportKCategorizedView(QWidget* const parent) - : QListView(parent), d(new Private(this)) -{ -} - -ImportKCategorizedView::~ImportKCategorizedView() -{ - delete d; -} - -void ImportKCategorizedView::setGridSize(const QSize& size) -{ - QListView::setGridSize(size); - - slotLayoutChanged(); -} - -void ImportKCategorizedView::setModel(QAbstractItemModel* model) -{ - d->lastSelection =3D QItemSelection(); - d->forcedSelectionPosition =3D 0; - d->hovered =3D QModelIndex(); - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - d->elementsInfo.clear(); - d->elementsPosition.clear(); - d->categoriesIndexes.clear(); - d->categoriesPosition.clear(); - d->categories.clear(); - d->intersectedIndexes.clear(); - - if (d->proxyModel) - { - disconnect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slot= LayoutChanged())); - - disconnect(d->proxyModel, SIGNAL(rowsRemoved(QModelIndex,int,int))= , this, SLOT(rowsRemoved(QModelIndex,int,int))); - } - - QListView::setModel(model); - - d->proxyModel =3D dynamic_cast(mode= l); - - if (d->proxyModel) - { - connect(d->proxyModel, SIGNAL(layoutChanged()), this, SLOT(slotLay= outChanged())); - - connect(d->proxyModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), t= his, SLOT(rowsRemoved(QModelIndex,int,int))); - - if (d->proxyModel->rowCount()) - { - slotLayoutChanged(); - } - } -} - -QRect ImportKCategorizedView::visualRect(const QModelIndex& index) const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QListView::visualRect(index); - } - - if (!qobject_cast(index.model())) - { - return d->visualRect(d->proxyModel->mapFromSource(index)); - } - - return d->visualRect(index); -} - -QRect ImportKCategorizedView::categoryVisualRect(const QModelIndex& index)= const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QRect(); - } - - if (!index.isValid()) - { - return QRect(); - } - - QString category =3D d->elementsInfo[index.row()].category; - return d->categoryVisualRect(category); -} - -QModelIndex ImportKCategorizedView::categoryAt(const QPoint& point) const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QModelIndex(); - } - - // We traverse the categories and find the first where point.y() is be= low the visualRect - int y =3D 0; - int lastY =3D 0; - QString lastCategory; - - foreach(const QString& category, d->categories) - { - y =3D d->categoryVisualRect(category).top(); - - if (point.y() >=3D lastY && point.y() < y) - { - break; - } - - lastY =3D y; - y =3D 0; - lastCategory =3D category; - } - - // if lastCategory is the last one in the list y will be 0 - if (!lastCategory.isNull() && point.y() >=3D lastY && (point.y() < y |= | !y)) - { - return d->proxyModel->index(d->categoriesIndexes[lastCategory][0],= d->proxyModel->sortColumn()); - } - - return QModelIndex(); -} - -QItemSelectionRange ImportKCategorizedView::categoryRange(const QModelInde= x& index) const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QItemSelectionRange(); - } - - if (!index.isValid()) - { - return QItemSelectionRange(); - } - - QString category =3D d->elementsInfo[index.row()].category; - QModelIndex first =3D d->proxyModel->index(d->categoriesIndexes[catego= ry].first(), d->proxyModel->sortColumn()); - QModelIndex last =3D d->proxyModel->index(d->categoriesIndexes[catego= ry].last(), d->proxyModel->sortColumn()); - return QItemSelectionRange(first, last); -} - -KCategoryDrawer* ImportKCategorizedView::categoryDrawer() const -{ - return d->categoryDrawer; -} - -void ImportKCategorizedView::setCategoryDrawer(KCategoryDrawer* categoryDr= awer) -{ - d->lastSelection =3D QItemSelection(); - d->forcedSelectionPosition =3D 0; - d->hovered =3D QModelIndex(); - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - d->elementsInfo.clear(); - d->elementsPosition.clear(); - d->categoriesIndexes.clear(); - d->categoriesPosition.clear(); - d->categories.clear(); - d->intersectedIndexes.clear(); - d->categoryDrawer =3D categoryDrawer; - - if (categoryDrawer) - { - if (d->proxyModel) - { - if (d->proxyModel->rowCount()) - { - slotLayoutChanged(); - } - } - } - else - { - updateGeometries(); - } -} - -void ImportKCategorizedView::setDrawDraggedItems(bool drawDraggedItems) -{ - d->drawItemsWhileDragging =3D drawDraggedItems; -} - -QModelIndex ImportKCategorizedView::indexAt(const QPoint& point) const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QListView::indexAt(point); - } - - QModelIndex index; - - const QModelIndexList item =3D d->intersectionSet(QRect(point, point)); - - if (item.count() =3D=3D 1) - { - index =3D item[0]; - } - - return index; -} - -QModelIndexList ImportKCategorizedView::categorizedIndexesIn(const QRect& = rect) const -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return QModelIndexList(); - } - - return d->intersectionSet(rect); -} - -void ImportKCategorizedView::reset() -{ - QListView::reset(); - - d->lastSelection =3D QItemSelection(); - d->forcedSelectionPosition =3D 0; - d->hovered =3D QModelIndex(); - d->biggestItemSize =3D QSize(0, 0); - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - d->elementsInfo.clear(); - d->elementsPosition.clear(); - d->categoriesIndexes.clear(); - d->categoriesPosition.clear(); - d->categories.clear(); - d->intersectedIndexes.clear(); -} - -void ImportKCategorizedView::paintEvent(QPaintEvent* event) -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - QListView::paintEvent(event); - return; - } - - bool alternatingRows =3D alternatingRowColors(); - QStyleOptionViewItemV4 option =3D viewOptions(); - option.widget =3D this; - - if (wordWrap()) - { - option.features |=3D QStyleOptionViewItemV4::WrapText; - } - - QPainter painter(viewport()); - QRect area =3D event->rect(); - const bool focus =3D (hasFocus() || viewport()->hasFocus()) &= & currentIndex().isValid(); - const QStyle::State state =3D option.state; - const bool enabled =3D (state & QStyle::State_Enabled) !=3D 0; - - painter.save(); - - QModelIndexList dirtyIndexes =3D d->intersectionSet(area); - bool alternate =3D false; - - if (dirtyIndexes.count()) - { - alternate =3D dirtyIndexes[0].row() % 2; - } - - foreach(const QModelIndex& index, dirtyIndexes) - { - if (alternatingRows && alternate) - { - option.features |=3D QStyleOptionViewItemV4::Alternate; - alternate =3D false; - } - else if (alternatingRows) - { - option.features &=3D ~QStyleOptionViewItemV4::Alternate; - alternate =3D true; - } - - option.state =3D state; - option.rect =3D visualRect(index); - - if (selectionModel() && selectionModel()->isSelected(index)) - { - option.state |=3D QStyle::State_Selected; - } - - if (enabled) - { - QPalette::ColorGroup cg; - - if ((d->proxyModel->flags(index) & Qt::ItemIsEnabled) =3D=3D 0) - { - option.state &=3D ~QStyle::State_Enabled; - cg =3D QPalette::Disabled; - } - else - { - cg =3D QPalette::Normal; - } - - option.palette.setCurrentColorGroup(cg); - } - - if (focus && currentIndex() =3D=3D index) - { - option.state |=3D QStyle::State_HasFocus; - - if (this->state() =3D=3D EditingState) - { - option.state |=3D QStyle::State_Editing; - } - } - - if (index =3D=3D d->hovered) - { - option.state |=3D QStyle::State_MouseOver; - } - else - { - option.state &=3D ~QStyle::State_MouseOver; - } - - itemDelegate(index)->paint(&painter, option, index); - } - - // Redraw categories - QStyleOptionViewItemV4 otherOption; - bool intersectedInThePast =3D false; - - foreach(const QString& category, d->categories) - { - otherOption =3D option; - otherOption.rect =3D d->categoryVisualRect(category); - otherOption.state &=3D ~QStyle::State_MouseOver; - - if (otherOption.rect.intersects(area)) - { - intersectedInThePast =3D true; - QModelIndex indexToDraw =3D d->proxyModel->index(d->categories= Indexes[category][0], - d->proxyModel->= sortColumn()); - - d->drawNewCategory(indexToDraw, d->proxyModel->sortRole(), oth= erOption, &painter); - } - else if (intersectedInThePast) - { - break; // the visible area has been finished, we don't need to= keep asking, the rest won't intersect - // this is doable because we know that categories are correctl= y ordered on the list - } - } - - if ((selectionMode() !=3D SingleSelection) && (selectionMode() !=3D No= Selection)) - { - if (d->mouseButtonPressed && QListView::state() !=3D DraggingState) - { - QPoint start, end, initialPressPosition; - - initialPressPosition =3D d->initialPressPosition; - - initialPressPosition.setY(initialPressPosition.y() - verticalO= ffset()); - initialPressPosition.setX(initialPressPosition.x() - horizonta= lOffset()); - - if (d->initialPressPosition.x() > d->mousePosition.x() || - d->initialPressPosition.y() > d->mousePosition.y()) - { - start =3D d->mousePosition; - end =3D initialPressPosition; - } - else - { - start =3D initialPressPosition; - end =3D d->mousePosition; - } - - QStyleOptionRubberBand yetAnotherOption; - yetAnotherOption.initFrom(this); - yetAnotherOption.shape =3D QRubberBand::Rectangle; - yetAnotherOption.opaque =3D false; - yetAnotherOption.rect =3D QRect(start, end).intersected(view= port()->rect().adjusted(-16, -16, 16, 16)); - painter.save(); - style()->drawControl(QStyle::CE_RubberBand, &yetAnotherOption,= &painter); - painter.restore(); - } - } - - if (d->drawItemsWhileDragging && QListView::state() =3D=3D DraggingSta= te && !d->dragLeftViewport) - { - painter.setOpacity(0.5); - d->drawDraggedItems(&painter); - } - - painter.restore(); -} - -void ImportKCategorizedView::resizeEvent(QResizeEvent* event) -{ - QListView::resizeEvent(event); - - // Clear the items positions cache - d->elementsPosition.clear(); - d->categoriesPosition.clear(); - d->forcedSelectionPosition =3D 0; - - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return; - } - - d->updateScrollbars(); -} - -QItemSelection ImportKCategorizedView::Private::selectionForRect(const QRe= ct& rect) -{ - QItemSelection selection; - QModelIndex tl, br; - QModelIndexList intersectedIndexes =3D intersectionSet(rect); - QList::const_iterator it =3D intersectedIndexes.constBegi= n(); - - for (; it !=3D intersectedIndexes.constEnd(); ++it) - { - if (!tl.isValid() && !br.isValid()) - { - tl =3D br =3D *it; - } - else if ((*it).row() =3D=3D (tl.row() - 1)) - { - tl =3D *it; // expand current range - } - else if ((*it).row() =3D=3D (br.row() + 1)) - { - br =3D (*it); // expand current range - } - else - { - selection.select(tl, br); // select current range - tl =3D br =3D *it; // start new range - } - } - - if (tl.isValid() && br.isValid()) - { - selection.select(tl, br); - } - else if (tl.isValid()) - { - selection.select(tl, tl); - } - else if (br.isValid()) - { - selection.select(br, br); - } - - return selection; -} - -void ImportKCategorizedView::setSelection(const QRect& rect, QItemSelectio= nModel::SelectionFlags command) -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - QListView::setSelection(rect, command); - return; - } - - QItemSelection selection; -// QRect contentsRect =3D rect.translated(horizontalOffset(), verticalO= ffset()); - QModelIndexList intersectedIndexes =3D d->intersectionSet(rect); - - if (rect.width() =3D=3D 1 && rect.height() =3D=3D 1) - { - QModelIndex tl; - - if (!intersectedIndexes.isEmpty()) - { - tl =3D intersectedIndexes.last(); // special case for mouse= press; only select the top item - } - - if (tl.isValid() && (tl.flags() & Qt::ItemIsEnabled)) - { - selection.select(tl, tl); - } - } - else - { - if (state() =3D=3D DragSelectingState) - { - // visual selection mode (rubberband selection) - selection =3D d->selectionForRect(rect); - } - else - { - // logical selection mode (key and mouse click selection) - QModelIndex tl, br; - // get the first item - const QRect topLeft(rect.left(), rect.top(), 1, 1); - intersectedIndexes =3D d->intersectionSet(topLeft); - - if (!intersectedIndexes.isEmpty()) - { - tl =3D intersectedIndexes.last(); - } - - // get the last item - const QRect bottomRight(rect.right(), rect.bottom(), 1, 1); - intersectedIndexes =3D d->intersectionSet(bottomRight); - - if (!intersectedIndexes.isEmpty()) - { - br =3D intersectedIndexes.last(); - } - - // get the ranges - if (tl.isValid() && br.isValid() && - (tl.flags() & Qt::ItemIsEnabled) && - (br.flags() & Qt::ItemIsEnabled)) - { - // first, middle, last in content coordinates - QRect middle; - QRect first =3D d->cachedRectIndex(tl); - QRect last =3D d->cachedRectIndex(br); - QSize fullSize =3D d->contentsSize(); - - if (flow() =3D=3D LeftToRight) - { - QRect& top =3D first; - QRect& bottom =3D last; - - // if bottom is above top, swap them - if (top.center().y() > bottom.center().y()) - { - QRect tmp =3D top; - top =3D bottom; - bottom =3D tmp; - } - - // if the rect are on differnet lines, expand - if (top.top() !=3D bottom.top()) - { - // top rectangle - if (isRightToLeft()) - { - top.setLeft(0); - } - else - { - top.setRight(fullSize.width()); - } - - // bottom rectangle - if (isRightToLeft()) - { - bottom.setRight(fullSize.width()); - } - else - { - bottom.setLeft(0); - } - } - else if (top.left() > bottom.right()) - { - if (isRightToLeft()) - { - bottom.setLeft(top.right()); - } - else - { - bottom.setRight(top.left()); - } - } - else - { - if (isRightToLeft()) - { - top.setLeft(bottom.right()); - } - else - { - top.setRight(bottom.left()); - } - } - - // middle rectangle - if (top.bottom() < bottom.top()) - { - middle.setTop(top.bottom() + 1); - middle.setLeft(qMin(top.left(), bottom.left())); - middle.setBottom(bottom.top() - 1); - middle.setRight(qMax(top.right(), bottom.right())); - } - } - else - { - // TopToBottom - QRect& left =3D first; - QRect& right =3D last; - - if (left.center().x() > right.center().x()) - { - qSwap(left, right); - } - - int ch =3D fullSize.height(); - - if (left.left() !=3D right.left()) - { - // left rectangle - if (isRightToLeft()) - { - left.setTop(0); - } - else - { - left.setBottom(ch); - } - - // top rectangle - if (isRightToLeft()) - { - right.setBottom(ch); - } - else - { - right.setTop(0); - } - - // only set middle if the - middle.setTop(0); - middle.setBottom(ch); - middle.setLeft(left.right() + 1); - middle.setRight(right.left() - 1); - } - else if (left.bottom() < right.top()) - { - left.setBottom(right.top() - 1); - } - else - { - right.setBottom(left.top() - 1); - } - } - - // get viewport coordinates - first =3D first.translated( - horizontalOffset(), - verti= calOffset()); - middle =3D middle.translated( - horizontalOffset(), - vert= icalOffset()); - last =3D last.translated( - horizontalOffset(), - vertic= alOffset()); - - // do the selections - QItemSelection topSelection =3D d->selectionForRect(fir= st); - QItemSelection middleSelection =3D d->selectionForRect(mid= dle); - QItemSelection bottomSelection =3D d->selectionForRect(las= t); - // merge - selection.merge(topSelection, QItemSelectionModel::Select); - selection.merge(middleSelection, QItemSelectionModel::Sele= ct); - selection.merge(bottomSelection, QItemSelectionModel::Sele= ct); - } - } - } - - selectionModel()->select(selection, command); -} - -void ImportKCategorizedView::mouseMoveEvent(QMouseEvent* event) -{ - QListView::mouseMoveEvent(event); - - // was a dragging started? - if (state() =3D=3D DraggingState) - { - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - - if (d->drawItemsWhileDragging) - { - viewport()->update(d->lastDraggedItemsRect); - } - } - - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return; - } - - const QModelIndexList item =3D d->intersectionSet(QRect(event->pos(), = event->pos())); - - if (item.count() =3D=3D 1) - { - d->hovered =3D item[0]; - } - else - { - d->hovered =3D QModelIndex(); - } - - const QString previousHoveredCategory =3D d->hoveredCategory; - - d->mousePosition =3D event->pos(); - - d->hoveredCategory.clear(); - - // Redraw categories - foreach(const QString& category, d->categories) - { - if (d->categoryVisualRect(category).intersects(QRect(event->pos(),= event->pos()))) - { - d->hoveredCategory =3D category; - viewport()->update(d->categoryVisualRect(category)); - } - else if ((category =3D=3D previousHoveredCategory) && - (!d->categoryVisualRect(previousHoveredCategory).intersec= ts(QRect(event->pos(), event->pos())))) - { - viewport()->update(d->categoryVisualRect(category)); - } - } - - QRect rect; - - if (d->mouseButtonPressed && QListView::state() !=3D DraggingState) - { - QPoint start, end, initialPressPosition; - - initialPressPosition =3D d->initialPressPosition; - - initialPressPosition.setY(initialPressPosition.y() - verticalOffse= t()); - initialPressPosition.setX(initialPressPosition.x() - horizontalOff= set()); - - if (d->initialPressPosition.x() > d->mousePosition.x() || - d->initialPressPosition.y() > d->mousePosition.y()) - { - start =3D d->mousePosition; - end =3D initialPressPosition; - } - else - { - start =3D initialPressPosition; - end =3D d->mousePosition; - } - - rect =3D QRect(start, end).adjusted(-16, -16, 16, 16); - rect =3D rect.united(QRect(start, end).adjusted(16, 16, -16, -16))= .intersected(viewport()->rect()); - - viewport()->update(rect); - } -} - -void ImportKCategorizedView::mousePressEvent(QMouseEvent* event) -{ - d->dragLeftViewport =3D false; - - QListView::mousePressEvent(event); - - if (event->button() =3D=3D Qt::LeftButton) - { - d->mouseButtonPressed =3D true; - - d->initialPressPosition =3D event->pos(); - d->initialPressPosition.setY(d->initialPressPosition.y() + vertica= lOffset()); - d->initialPressPosition.setX(d->initialPressPosition.x() + horizon= talOffset()); - } - else if (event->button() =3D=3D Qt::RightButton) - { - d->rightMouseButtonPressed =3D true; - } - - if (selectionModel()) - { - d->lastSelection =3D selectionModel()->selection(); - } - - viewport()->update(d->categoryVisualRect(d->hoveredCategory)); -} - -void ImportKCategorizedView::mouseReleaseEvent(QMouseEvent* event) -{ - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - - QListView::mouseReleaseEvent(event); - - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return; - } - - QPoint initialPressPosition =3D viewport()->mapFromGlobal(QCursor::pos= ()); - initialPressPosition.setY(initialPressPosition.y() + verticalOffset()); - initialPressPosition.setX(initialPressPosition.x() + horizontalOffset(= )); - - if ((selectionMode() !=3D SingleSelection) && (selectionMode() !=3D No= Selection) && - (initialPressPosition =3D=3D d->initialPressPosition)) - { - foreach(const QString& category, d->categories) - { - if (d->categoryVisualRect(category).contains(event->pos()) && - selectionModel()) - { - QItemSelection selection =3D selectionModel()->select= ion(); - const QVector &indexList =3D d->categoriesIndexes[cat= egory]; - - foreach(int row, indexList) - { - QModelIndex selectIndex =3D d->proxyModel->index(row, = 0); - - selection << QItemSelectionRange(selectIndex); - } - - selectionModel()->select(selection, QItemSelectionModel::S= electCurrent); - - break; - } - } - } - - QRect rect; - - if (state() !=3D DraggingState) - { - QPoint start, end, initialPressPosition; - - initialPressPosition =3D d->initialPressPosition; - - initialPressPosition.setY(initialPressPosition.y() - verticalOffse= t()); - initialPressPosition.setX(initialPressPosition.x() - horizontalOff= set()); - - if (d->initialPressPosition.x() > d->mousePosition.x() || - d->initialPressPosition.y() > d->mousePosition.y()) - { - start =3D d->mousePosition; - end =3D initialPressPosition; - } - else - { - start =3D initialPressPosition; - end =3D d->mousePosition; - } - - rect =3D QRect(start, end).adjusted(-16, -16, 16, 16); - rect =3D rect.united(QRect(start, end).adjusted(16, 16, -16, -16))= .intersected(viewport()->rect()); - - viewport()->update(rect); - } - - if (d->hovered.isValid()) - { - viewport()->update(visualRect(d->hovered)); - } - else if (!d->hoveredCategory.isEmpty()) - { - viewport()->update(d->categoryVisualRect(d->hoveredCategory)); - } -} - -void ImportKCategorizedView::leaveEvent(QEvent* event) -{ - d->hovered =3D QModelIndex(); - d->hoveredCategory.clear(); - - QListView::leaveEvent(event); -} - -void ImportKCategorizedView::startDrag(Qt::DropActions supportedActions) -{ - // FIXME: QAbstractItemView does far better here since it sets the - // pixmap of selected icons to the dragging cursor, but it sets= a non - // ARGB window so it is no transparent. Use QAbstractItemView w= hen - // this is fixed on Qt. - // QAbstractItemView::startDrag(supportedActions); - QListView::startDrag(supportedActions); -} - -void ImportKCategorizedView::dragMoveEvent(QDragMoveEvent* event) -{ - d->mousePosition =3D event->pos(); - - d->dragLeftViewport =3D false; - - QListView::dragMoveEvent(event); - - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - return; - } - - d->hovered =3D indexAt(event->pos()); - - d->drawDraggedItems(); -} - -void ImportKCategorizedView::dragLeaveEvent(QDragLeaveEvent* event) -{ - d->dragLeftViewport =3D true; - - QListView::dragLeaveEvent(event); -} - -void ImportKCategorizedView::dropEvent(QDropEvent* event) -{ - QListView::dropEvent(event); -} - -QModelIndex ImportKCategorizedView::moveCursor(CursorAction cursorAction, - Qt::KeyboardModifiers modifiers) -{ - if ((viewMode() !=3D ImportKCategorizedView::IconMode) || - !d->proxyModel || - !d->categoryDrawer || - d->categories.isEmpty() || - !d->proxyModel->isCategorizedModel()) - { - return QListView::moveCursor(cursorAction, modifiers); - } - - int viewportWidth =3D viewport()->width() - spacing(); - int itemWidth; - - if (gridSize().isEmpty()) - { - itemWidth =3D d->biggestItemSize.width(); - } - else - { - itemWidth =3D gridSize().width(); - } - - int itemWidthPlusSeparation =3D spacing() + itemWidth; - - if (!itemWidthPlusSeparation) - { - ++itemWidthPlusSeparation; - } - - int elementsPerRow =3D viewportWidth / itemWidthPlusSeparation; - - if (!elementsPerRow) - { - ++elementsPerRow; - } - - QModelIndex current =3D selectionModel() ? selectionModel()->currentIn= dex() - : QModelIndex(); - - if (!current.isValid()) - { - if (cursorAction =3D=3D MoveEnd) - { - current =3D model()->index(model()->rowCount() - 1, 0, QModelI= ndex()); - //d->forcedSelectionPosition =3D d->elementsInfo[current.row()= ].relativeOffsetToCategory % elementsPerRow; - } - else - { - current =3D model()->index(0, 0, QModelInde= x()); - d->forcedSelectionPosition =3D 0; - } - - return current; - } - - QString lastCategory =3D d->categories.first(); - QString theCategory =3D d->categories.first(); - QString afterCategory =3D d->categories.first(); - bool hasToBreak =3D false; - - foreach(const QString& category, d->categories) - { - if (hasToBreak) - { - afterCategory =3D category; - - break; - } - - if (category =3D=3D d->elementsInfo[current.row()].category) - { - theCategory =3D category; - hasToBreak =3D true; - } - - if (!hasToBreak) - { - lastCategory =3D category; - } - } - - switch (cursorAction) - { - case QAbstractItemView::MovePageUp: - { - // We need to reimplemt PageUp/Down as well because - // default QListView implementation will not work properly wit= h our custom layout - QModelIndexList visibleIndexes =3D d->intersectionSet(viewport= ()->rect()); - if (!visibleIndexes.isEmpty()) - { - int indexToMove =3D qMax(current.row() - visibleIndexes.si= ze(), 0); - return d->proxyModel->index(indexToMove, 0); - } - break; - } - // fall through - - case QAbstractItemView::MoveUp: - { - if (d->elementsInfo[current.row()].relativeOffsetToCategory >= =3D elementsPerRow) - { - int indexToMove =3D current.row(); - indexToMove -=3D qMin(((d->elementsInfo[current.row()]= .relativeOffsetToCategory) + - d->forcedSelectionPosition), elementsPe= rRow - d->forcedSelectionPosition + - (d->elementsInfo[current.row()].relativ= eOffsetToCategory % elementsPerRow)); - - return d->proxyModel->index(indexToMove, 0); - } - else - { - int lastCategoryLastRow =3D (d->categoriesIndexes[lastCate= gory].count() - 1) % elementsPerRow; - int indexToMove =3D current.row() - d->elementsInf= o[current.row()].relativeOffsetToCategory; - - if (d->forcedSelectionPosition >=3D lastCategoryLastRow) - { - indexToMove -=3D 1; - } - else - { - indexToMove -=3D qMin((lastCategoryLastRow - d->forced= SelectionPosition + 1), - d->forcedSelectionPosition + eleme= ntsPerRow + 1); - } - - return d->proxyModel->index(indexToMove, 0); - } - } - - case QAbstractItemView::MovePageDown: - { - QModelIndexList visibleIndexes =3D d->intersectionSet(viewport= ()->rect()); - if (!visibleIndexes.isEmpty()) - { - int indexToMove =3D qMin(current.row() + visibleIndexes.si= ze(), d->elementsInfo.size() - 1); - return d->proxyModel->index(indexToMove, 0); - } - } - // fall through - case QAbstractItemView::MoveDown: - { - if (d->elementsInfo[current.row()].relativeOffsetToCategory < = (d->categoriesIndexes[theCategory].count() - 1 - ((d->categoriesIndexes[the= Category].count() - 1) % elementsPerRow))) - { - int indexToMove =3D current.row(); - indexToMove +=3D qMin(elementsPerRow, d->categoriesInd= exes[theCategory].count() - 1 - - d->elementsInfo[current.row()].rel= ativeOffsetToCategory); - - return d->proxyModel->index(indexToMove, 0); - } - else - { - int afterCategoryLastRow =3D qMin(elementsPerRow, d->categ= oriesIndexes[afterCategory].count()); - int indexToMove =3D current.row() + (d->categorie= sIndexes[theCategory].count() - - d->elementsInf= o[current.row()].relativeOffsetToCategory); - - if (d->forcedSelectionPosition >=3D afterCategoryLastRow) - { - indexToMove +=3D afterCategoryLastRow - 1; - } - else - { - indexToMove +=3D qMin(d->forcedSelectionPosition, elem= entsPerRow); - } - - return d->proxyModel->index(indexToMove, 0); - } - } - - case QAbstractItemView::MoveLeft: - - if (layoutDirection() =3D=3D Qt::RightToLeft) - { - if (current.row() + 1 =3D=3D d->elementsInfo.size() || - !(d->elementsInfo[current.row() + 1].relativeOffsetToC= ategory % elementsPerRow)) - { - return current; - } - - return d->proxyModel->index(current.row() + 1, 0); - } - - if (current.row() =3D=3D 0 || - !(d->elementsInfo[current.row()].relativeOffsetToCategory = % elementsPerRow)) - { - return current; - } - - return d->proxyModel->index(current.row() - 1, 0); - - case QAbstractItemView::MoveRight: - - if (layoutDirection() =3D=3D Qt::RightToLeft) - { - if (current.row() =3D=3D 0 || - !(d->elementsInfo[current.row()].relativeOffsetToCateg= ory % elementsPerRow)) - { - return current; - } - - return d->proxyModel->index(current.row() - 1, 0); - } - - if (current.row() + 1 =3D=3D d->elementsInfo.size() || - !(d->elementsInfo[current.row() + 1].relativeOffsetToCateg= ory % elementsPerRow)) - { - return current; - } - - return d->proxyModel->index(current.row() + 1, 0); - - default: - break; - } - - return QListView::moveCursor(cursorAction, modifiers); -} - -void ImportKCategorizedView::rowsInserted(const QModelIndex& parent, int s= tart, int end) -{ - QListView::rowsInserted(parent, start, end); - - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - d->forcedSelectionPosition =3D 0; - d->hovered =3D QModelIndex(); - d->biggestItemSize =3D QSize(0, 0); - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - d->elementsInfo.clear(); - d->elementsPosition.clear(); - d->categoriesIndexes.clear(); - d->categoriesPosition.clear(); - d->categories.clear(); - d->intersectedIndexes.clear(); - - return; - } - - rowsInsertedArtifficial(parent, start, end); -} - -int ImportKCategorizedView::Private::categoryUpperBound(SparseModelIndexVe= ctor& modelIndexList, - = int begin, int averageSize) -{ - int end =3D modelIndexList.size(); - QString category =3D proxyModel->data(modelIndexList[begin], - KCategorizedSortFilterProxyModel= ::CategoryDisplayRole).toString(); - - // First case: Small category with <10 entries - const int smallEnd =3D qMin(end, begin + 10); - - for (int k=3Dbegin; k < smallEnd; ++k) - { - if (category !=3D proxyModel->data(modelIndexList[k], - KCategorizedSortFilterProxyModel:= :CategoryDisplayRole).toString()) - { - return k; - } - } - - begin +=3D 10; - - // Second case: only one category, test last value - QString value =3D proxyModel->data(modelIndexList[end - 1], - KCategorizedSortFilterProxyModel::Cat= egoryDisplayRole).toString(); - - if (value =3D=3D category) - { - return end; - } - - // Third case: use average of last category sizes - if (averageSize && begin + averageSize < end) - { - if (category !=3D proxyModel->data(modelIndexList[begin + averageS= ize], - KCategorizedSortFilterProxyModel:= :CategoryDisplayRole).toString()) - { - end =3D begin + averageSize; - } - else if (begin + 2*averageSize < end) - { - if (category !=3D proxyModel->data(modelIndexList[begin + 2*av= erageSize], - KCategorizedSortFilterProxyMo= del::CategoryDisplayRole).toString()) - { - end =3D begin + 2 * averageSize; - } - } - } - - // now apply a binary search - the model is sorted by category - // from qUpperBound, Copyright (C) 2008 Nokia Corporation and/or its s= ubsidiary(-ies) - int middle; - int n =3D end - begin; - int half; - - while (n > 0) - { - half =3D n >> 1; - middle =3D begin + half; - - if (category !=3D proxyModel->data(modelIndexList[middle], - KCategorizedSortFilterProxyModel:= :CategoryDisplayRole).toString()) - { - n =3D half; - } - else - { - begin =3D middle + 1; - n -=3D half + 1; - } - } - - return begin; -} - -void ImportKCategorizedView::rowsInsertedArtifficial(const QModelIndex& pa= rent, int start, int end) -{ - Q_UNUSED(parent); - - d->forcedSelectionPosition =3D 0; - d->hovered =3D QModelIndex(); - d->biggestItemSize =3D QSize(0, 0); - d->mouseButtonPressed =3D false; - d->rightMouseButtonPressed =3D false; - d->elementsInfo.clear(); - d->elementsPosition.clear(); - d->categoriesIndexes.clear(); - d->categoriesPosition.clear(); - d->categories.clear(); - d->intersectedIndexes.clear(); - - if (start > end || end < 0 || start < 0 || !d->proxyModel->rowCount()) - { - return; - } - - // Add all elements mapped to the source model and explore categories - const int rowCount =3D d->proxyModel->rowCount(); - const int sortColumn =3D d->proxyModel->sortColumn(); - QString lastCategory =3D d->proxyModel->data(d->proxyModel->index(0, s= ortColumn), - KCategorizedSortFilterProxy= Model::CategoryDisplayRole).toString(); - int offset =3D -1; - - SparseModelIndexVector modelIndexList(rowCount, d->proxyModel, sortCol= umn); - - d->elementsInfo =3D QVector(rowCount= ); - int categorySizes =3D 0; - int categoryCounts =3D 0; - - if (uniformItemSizes()) - { - // use last index as sample for size hint - QModelIndex sample =3D d->proxyModel->index(rowCount - 1, modelCol= umn(), rootIndex()); - d->biggestItemSize =3D sizeHintForIndex(sample); - } - else - { - QStyleOptionViewItem option =3D viewOptions(); - - for (int k =3D 0; k < rowCount; ++k) - { - QModelIndex indexSize =3D (sortColumn =3D=3D 0) ? modelIndexLi= st[k] : d->proxyModel->index(k, 0); - QSize hint =3D itemDelegate(indexSize)->sizeHint(op= tion, indexSize); - d->biggestItemSize =3D QSize(qMax(hint.width(), d->biggestI= temSize.width()), - qMax(hint.height(), d->biggestIt= emSize.height())); - } - } - - for (int k =3D 0; k < rowCount; ) - { - lastCategory =3D d->proxyModel->data(modelIndexList[k], KCategor= izedSortFilterProxyModel::CategoryDisplayRole).toString(); - int upperBound =3D d->categoryUpperBound(modelIndexList, k, catego= rySizes / ++categoryCounts); - categorySizes +=3D upperBound - k; - offset =3D 0; - - QVector rows(upperBound - k); - - for (int i=3Dk; ielementsInfo[i= ]; - elementInfo.category =3D lastCategory; - elementInfo.relativeOffsetToCategory =3D offset; - } - - k =3D upperBound; - - d->categoriesIndexes.insert(lastCategory, rows); - d->categories << lastCategory; - } - - d->updateScrollbars(); -} - -void ImportKCategorizedView::rowsRemoved(const QModelIndex& parent, int st= art, int end) -{ - Q_UNUSED(parent); - Q_UNUSED(start); - Q_UNUSED(end); - - if (d->proxyModel && d->categoryDrawer && d->proxyModel->isCategorized= Model()) - { - // Force the view to update all elements - rowsInsertedArtifficial(QModelIndex(), 0, d->proxyModel->rowCount(= ) - 1); - } -} - -void ImportKCategorizedView::updateGeometries() -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - QListView::updateGeometries(); - return; - } - - // Avoid QListView::updateGeometries(), since it will try to set anoth= er - // range to our scroll bars, what we don't want. - QAbstractItemView::updateGeometries(); -} - -void ImportKCategorizedView::slotLayoutChanged() -{ - if (d->proxyModel && d->categoryDrawer && d->proxyModel->isCategorized= Model()) - { - // all cached values are invalidated, recompute immediately - rowsInsertedArtifficial(QModelIndex(), 0, d->proxyModel->rowCount(= ) - 1); - } -} - -void ImportKCategorizedView::currentChanged(const QModelIndex& current, co= nst QModelIndex& previous) -{ - if (!d->proxyModel || !d->categoryDrawer || !d->proxyModel->isCategori= zedModel()) - { - QListView::currentChanged(current, previous); - return; - } - - // We need to update the forcedSelectionPosition property in order to = correctly - // navigate after with keyboard using up & down keys - - int viewportWidth =3D viewport()->width() - spacing(); - - //int itemHeight; - int itemWidth; - - if (gridSize().isEmpty()) - { - //itemHeight =3D d->biggestItemSize.height(); - itemWidth =3D d->biggestItemSize.width(); - } - else - { - //itemHeight =3D gridSize().height(); - itemWidth =3D gridSize().width(); - } - - int itemWidthPlusSeparation =3D spacing() + itemWidth; - - if (!itemWidthPlusSeparation) - { - ++itemWidthPlusSeparation; - } - - int elementsPerRow =3D viewportWidth / itemWidthPlusSeparation; - - if (!elementsPerRow) - { - ++elementsPerRow; - } - - if (current.isValid()) - { - d->forcedSelectionPosition =3D d->elementsInfo[current.row()].rela= tiveOffsetToCategory % elementsPerRow; - } - - QListView::currentChanged(current, previous); -} - -} // namespace Digikam diff --git a/utilities/cameragui/views/importkcategorizedview.h b/utilities= /cameragui/views/importkcategorizedview.h deleted file mode 100644 index 54a2aea..0000000 --- a/utilities/cameragui/views/importkcategorizedview.h +++ /dev/null @@ -1,125 +0,0 @@ -/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - * - * This file is a part of digiKam project - * http://www.digikam.org - * - * Date : 2012-07-05 - * Description : Base item view to list import interface items. - * - * Copyright (C) 2012 by Islam Wazery - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ - -#ifndef ImportKCategorizedView_H -#define ImportKCategorizedView_H - -// Qt includes - -#include - -class KCategoryDrawer; - -namespace Digikam -{ - -class ImportKCategorizedView : public QListView -{ - Q_OBJECT - -public: - - ImportKCategorizedView(QWidget* const parent =3D 0); - ~ImportKCategorizedView(); - - void setGridSize(const QSize& size); - - void setCategoryDrawer(KCategoryDrawer* categoryDrawer); - KCategoryDrawer* categoryDrawer() const; - - /** - * Switch on drawing of dragged items. Default: on. - * While dragging over the view, dragged items will be drawn transpare= ntly - * following the mouse cursor. - */ - void setDrawDraggedItems(bool drawDraggedItems); - - virtual void setModel(QAbstractItemModel* model); - virtual QRect visualRect(const QModelIndex& index) const; - virtual QModelIndex indexAt(const QPoint& p) const; - - /** - * This method will return all indexes whose visual rect intersects @p= rect. - * @param rect rectangle to test intersection with - * @note Returns an empty list if the view is not categorized. - */ - virtual QModelIndexList categorizedIndexesIn(const QRect& rect) const; - - /** - * This method will return the visual rect of the header of the catego= ry - * in which @p index is sorted. - * @note Returns QRect() if the view is not categorized. - */ - virtual QRect categoryVisualRect(const QModelIndex& index) const; - - /** - * This method will return the first index of the category - * in the region of which @p point is found. - * @note Returns QModelIndex() if the view is not categorized. - */ - virtual QModelIndex categoryAt(const QPoint& point) const; - - /** - * This method returns the range of indexes contained - * in the category in which @p index is sorted. - * @note Returns an empty range if the view is no categorized. - */ - virtual QItemSelectionRange categoryRange(const QModelIndex& index) co= nst; - -public Q_SLOTS: - - virtual void reset(); - -protected Q_SLOTS: - - virtual void rowsInserted(const QModelIndex& parent, int start, int en= d); - virtual void rowsInsertedArtifficial(const QModelIndex& parent, int st= art, int end); - virtual void rowsRemoved(const QModelIndex& parent, int start, int end= ); - virtual void updateGeometries(); - virtual void slotLayoutChanged(); - virtual void currentChanged(const QModelIndex& current, const QModelIn= dex& previous); - -protected: - - virtual void paintEvent(QPaintEvent* event); - virtual void resizeEvent(QResizeEvent* event); - virtual void setSelection(const QRect& rect, QItemSelectionModel::Sele= ctionFlags flags); - virtual void mouseMoveEvent(QMouseEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void mouseReleaseEvent(QMouseEvent* event); - virtual void leaveEvent(QEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void dropEvent(QDropEvent* event); - virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::Keyboard= Modifiers modifiers); - -private: - - class Private; - Private* const d; -}; - -} //namespace Digikam - -#endif // ImportKCategorizedView_H diff --git a/utilities/cameragui/views/importkcategorizedview_p.h b/utiliti= es/cameragui/views/importkcategorizedview_p.h deleted file mode 100644 index b3c468e..0000000 --- a/utilities/cameragui/views/importkcategorizedview_p.h +++ /dev/null @@ -1,216 +0,0 @@ -/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - * - * This file is a part of digiKam project - * http://www.digikam.org - * - * Date : 2012-07-08 - * Description : Item view to list import interface items. - * - * Copyright (C) 2012 by Islam Wazery - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ - -#ifndef ImportKCategorizedView_P_H -#define ImportKCategorizedView_P_H - -class KCategorizedSortFilterProxyModel; -class KCategoryDrawer; - -namespace Digikam -{ - -class SparseModelIndexVector : public QVector -{ - -public: - - SparseModelIndexVector(int rowCount, QAbstractItemModel* const model, = int column) - : QVector(rowCount), model(model), column(column) - { - } - - inline QModelIndex& operator[](int i) - { - QModelIndex& index =3D QVector::operator[](i); - - if (!index.isValid()) - { - index =3D model->index(i, column); - } - - return index; - } - -private: - - // not to be used - const QModelIndex& operator[](int i) const - { - return QVector::operator[](i); - } - -private: - - QAbstractItemModel* model; - int column; -}; - -// -----------------------------------------------------------------------= ------- - -class ImportKCategorizedView::Private -{ -public: - - Private(ImportKCategorizedView* const listView); - ~Private(); - - /** - * Returns the list of items that intersects with @p rect - */ - const QModelIndexList& intersectionSet(const QRect& rect); - - /** - * Gets the item rect in the viewport for @p index - */ - QRect visualRectInViewport(const QModelIndex& index) const; - - /** - * Returns the category rect in the viewport for @p category - */ - QRect visualCategoryRectInViewport(const QString& category) const; - - /** - * Caches and returns the rect that corresponds to @p index - */ - const QRect& cacheIndex(const QModelIndex& index); - - /** - * Caches and returns the rect that corresponds to @p category - */ - const QRect& cacheCategory(const QString& category); - - /** - * Returns the rect that corresponds to @p index - * @note If the rect is not cached, it becomes cached - */ - const QRect& cachedRectIndex(const QModelIndex& index); - - /** - * Returns the rect that corresponds to @p category - * @note If the rect is not cached, it becomes cached - */ - const QRect& cachedRectCategory(const QString& category); - - /** - * Returns the visual rect (taking in count x and y offsets) for @p i= ndex - * @note If the rect is not cached, it becomes cached - */ - QRect visualRect(const QModelIndex& index); - - /** - * Returns the visual rect (taking in count x and y offsets) for @p c= ategory - * @note If the rect is not cached, it becomes cached - */ - QRect categoryVisualRect(const QString& category); - - /** - * Returns the contents size of this view (topmost category to bottom= most index + spacing) - */ - QSize contentsSize(); - - /** - * This method will draw a new category represented by index - * @p index on the rect specified by @p option.rect, with - * painter @p painter - */ - void drawNewCategory(const QModelIndex& index, - int sortRole, - const QStyleOption& option, - QPainter* const painter); - - /** - * This method will update scrollbars ranges. Called when our model c= hanges - * or when the view is resized - */ - void updateScrollbars(); - - /** - * This method will draw dragged items in the painting operation - */ - void drawDraggedItems(QPainter* const painter); - - /** - * This method will determine which rect needs to be updated because = of a - * dragging operation - */ - void drawDraggedItems(); - - /** - * This method will, starting from the index at begin in the given (s= orted) modelIndex List, - * find the last index having the same category as the index to begin= with. - */ - int categoryUpperBound(SparseModelIndexVector& modelIndexList, int beg= in, int averageSize =3D 0); - - /** - * Returns a QItemSelection for all items intersection rect. - */ - QItemSelection selectionForRect(const QRect& rect); - -public: - - // Attributes - - struct ElementInfo - { - QString category; - int relativeOffsetToCategory; - }; - -public: - - // Basic data - ImportKCategorizedView* listView; - KCategoryDrawer* categoryDrawer; - QSize biggestItemSize; - - // Behavior data - bool mouseButtonPressed; - bool rightMouseButtonPressed; - bool dragLeftViewport; - bool drawItemsWhileDragging; - QModelIndex hovered; - QString hoveredCategory; - QPoint initialPressPosition; - QPoint mousePosition; - int forcedSelectionPosition; - - // Cache data - // We cannot merge some of them into structs because it would affect - // performance - QVector elementsInfo; - QHash elementsPosition; - QHash > categoriesIndexes; - QHash categoriesPosition; - QStringList categories; - QModelIndexList intersectedIndexes; - QRect lastDraggedItemsRect; - QItemSelection lastSelection; - - // Attributes for speed reasons - KCategorizedSortFilterProxyModel* proxyModel; -}; - -} // namespace Digikam - -#endif // ImportKCategorizedView_P_H