File indexing completed on 2024-05-19 04:27:45

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2019 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISRESOURCEITEMLISTVIEW_H
0008 #define KISRESOURCEITEMLISTVIEW_H
0009 
0010 #include <QListView>
0011 #include <QScopedPointer>
0012 
0013 #include <KisKineticScroller.h>
0014 
0015 #include "kritaresourcewidgets_export.h"
0016 #include "ResourceListViewModes.h"
0017 
0018 
0019 class KRITARESOURCEWIDGETS_EXPORT KisResourceItemListView : public QListView
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     KisResourceItemListView(QWidget *parent = nullptr);
0025     ~KisResourceItemListView() override;
0026 
0027     void setListViewMode(ListViewMode layout);
0028 
0029     /**
0030      * @brief setItemSize
0031      * convenience function which sets both the icon and the grid size
0032      * to the same value.
0033      * @param size - the size you wish either to be.
0034      */
0035     void setItemSize(QSize size);
0036 
0037     /**
0038      * @brief setStrictSelectionMode sets additional restrictions on the selection.
0039      *
0040      * When in QAbstractItemView::SingleSelection mode, this ensures that the
0041      * selection never gets transferred to another item. Instead, the selection
0042      * is cleared if the current item gets removed (filtered) from the model.
0043      * Furthermore, it prevents users from deselecting the current item with Ctrl+click.
0044      * This behavior is important for resource selectors.
0045      * @param enable Determines if strict mode is enabled.
0046      */
0047     void setStrictSelectionMode(bool enable);
0048 
0049     void setFixedToolTipThumbnailSize(const QSize &size);
0050     void setToolTipShouldRenderCheckers(bool value);
0051 
0052 public Q_SLOTS:
0053     void slotScrollerStateChange(QScroller::State state){ KisKineticScroller::updateCursor(this, state); }
0054 
0055 Q_SIGNALS:
0056 
0057     void sigSizeChanged();
0058 
0059     void currentResourceChanged(const QModelIndex &);
0060     void currentResourceClicked(const QModelIndex &);
0061 
0062     void contextMenuRequested(const QPoint &);
0063 
0064 protected Q_SLOTS:
0065     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
0066     void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
0067 
0068 protected:
0069     QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *event = nullptr) const override;
0070     void contextMenuEvent(QContextMenuEvent *event) override;
0071 
0072     bool viewportEvent(QEvent *event) override;
0073 
0074 private:
0075     void resizeEvent(QResizeEvent *event) override;
0076 
0077 private:
0078     struct Private;
0079     const QScopedPointer<Private> m_d;
0080 };
0081 
0082 #endif // KISRESOURCEITEMLISTVIEW_H