]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistcontainer.h
Fix selection rect after porting from QFontMetrics::width()
[dolphin.git] / src / kitemviews / kitemlistcontainer.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef KITEMLISTCONTAINER_H
23 #define KITEMLISTCONTAINER_H
24
25 #include "dolphin_export.h"
26
27 #include <QAbstractScrollArea>
28
29 class KItemListController;
30 class KItemListSmoothScroller;
31 class KItemListView;
32 class KItemModelBase;
33
34 /**
35 * @brief Provides a QWidget based scrolling view for a KItemListController.
36 *
37 * The model and view are maintained by the KItemListController.
38 *
39 * @see KItemListController
40 */
41 class DOLPHIN_EXPORT KItemListContainer : public QAbstractScrollArea
42 {
43 Q_OBJECT
44
45 public:
46 /**
47 * @param controller Controller that maintains the model and the view.
48 * The KItemListContainer takes ownership of the controller
49 * (the parent will be set to the KItemListContainer).
50 * @param parent Optional parent widget.
51 */
52 explicit KItemListContainer(KItemListController* controller, QWidget* parent = nullptr);
53 ~KItemListContainer() override;
54 KItemListController* controller() const;
55
56 void setEnabledFrame(bool enable);
57 bool enabledFrame() const;
58
59 protected:
60 void keyPressEvent(QKeyEvent* event) override;
61 void showEvent(QShowEvent* event) override;
62 void resizeEvent(QResizeEvent* event) override;
63 void scrollContentsBy(int dx, int dy) override;
64 void wheelEvent(QWheelEvent* event) override;
65
66 private slots:
67 void slotScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous);
68 void slotModelChanged(KItemModelBase* current, KItemModelBase* previous);
69 void slotViewChanged(KItemListView* current, KItemListView* previous);
70 void scrollTo(qreal offset);
71 void updateScrollOffsetScrollBar();
72 void updateItemOffsetScrollBar();
73
74 private:
75 void updateGeometries();
76 void updateSmoothScrollers(Qt::Orientation orientation);
77
78 /**
79 * Helper method for updateScrollOffsetScrollBar(). Updates the scrollbar-policy
80 * to Qt::ScrollBarAlwaysOn for cases where turning off the scrollbar might lead
81 * to an endless layout loop (see bug #293318).
82 */
83 void updateScrollOffsetScrollBarPolicy();
84
85 private:
86 KItemListController* m_controller;
87
88 KItemListSmoothScroller* m_horizontalSmoothScroller;
89 KItemListSmoothScroller* m_verticalSmoothScroller;
90 };
91
92 #endif
93
94