delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / plasma / applets / folderview / abstractitemview.h
blobb126d7f68bd1042e20768bb7e5a3beb506fbfe8a
1 /*
2 * Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef ABSTRACTITEMVIEW_H
21 #define ABSTRACTITEMVIEW_H
23 #include <QGraphicsWidget>
24 #include <QAbstractItemDelegate>
25 #include <QPointer>
26 #include <QCache>
27 #include <QTime>
28 #include <QBasicTimer>
30 #include <plasma/widgets/scrollbar.h>
33 class KUrl;
34 class KDirModel;
35 class KFileItemDelegate;
36 class KFilePreviewGenerator;
37 class KNewMenu;
38 class QItemSelectionModel;
39 class ProxyModel;
40 class QStyleOptionViewItemV4;
41 class QScrollBar;
44 // The abstract base class for IconView and ListView
45 class AbstractItemView : public QGraphicsWidget
47 Q_OBJECT
49 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
51 public:
52 AbstractItemView(QGraphicsWidget *parent = 0);
53 ~AbstractItemView();
55 virtual void setModel(QAbstractItemModel *model);
56 QAbstractItemModel *model() const;
58 void setSelectionModel(QItemSelectionModel *model);
59 QItemSelectionModel *selectionModel() const;
61 void setItemDelegate(KFileItemDelegate *delegate);
62 KFileItemDelegate *itemDelegate() const;
64 virtual void setIconSize(const QSize &iconSize);
65 QSize iconSize() const;
67 QScrollBar *verticalScrollBar() const;
69 QRect visibleArea() const;
70 virtual QModelIndex indexAt(const QPointF &point) const = 0;
71 virtual QRect visualRect(const QModelIndex &index) const = 0;
73 signals:
74 void activated(const QModelIndex &index);
75 void contextMenuRequest(QWidget *widget, const QPoint &screenPos);
77 protected:
78 void markAreaDirty(const QRect &rect);
79 void markAreaDirty(const QRectF &rect) { markAreaDirty(rect.toAlignedRect()); }
80 QRect scrollBackBuffer();
81 void prepareBackBuffer();
82 void syncBackBuffer(QPainter *painter, const QRect &clipRect);
84 QPointF mapToViewport(const QPointF &point) const;
85 QRectF mapToViewport(const QRectF &rect) const;
86 QPointF mapFromViewport(const QPointF &point) const;
87 QRectF mapFromViewport(const QRectF &rect) const;
89 void timerEvent(QTimerEvent *event);
91 void smoothScroll(int dx, int dy);
92 void startScrolling();
93 void stopScrolling();
94 void scrollTick();
96 protected slots:
97 virtual void rowsInserted(const QModelIndex &parent, int first, int last);
98 virtual void rowsRemoved(const QModelIndex &parent, int first, int last);
99 virtual void modelReset();
100 virtual void layoutChanged();
101 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
102 virtual void commitData(QWidget *editor);
103 virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
105 virtual void finishedScrolling();
107 private slots:
108 void scrollBarValueChanged(int value);
109 void scrollBarActionTriggered(int action);
110 void scrollBarSliderReleased();
112 protected:
113 KFileItemDelegate *m_delegate;
114 QPointer<KDirModel> m_dirModel;
115 QPointer<ProxyModel> m_model;
116 QPointer<QItemSelectionModel> m_selectionModel;
117 QSize m_iconSize;
118 QRegion m_dirtyRegion;
119 QPixmap m_pixmap;
120 QPixmap m_topFadeTile;
121 QPixmap m_bottomFadeTile;
122 Plasma::ScrollBar *m_scrollBar;
123 QStyle *m_style;
124 QWidget *m_styleWidget;
125 int m_lastScrollValue;
126 bool m_viewScrolled;
128 // These variables are for the smooth scrolling code
129 int m_dx;
130 int m_ddx;
131 int m_dddx;
132 int m_rdx;
133 int m_dy;
134 int m_ddy;
135 int m_dddy;
136 int m_rdy;
137 bool m_smoothScrolling;
138 QBasicTimer m_smoothScrollTimer;
142 inline QPointF AbstractItemView::mapToViewport(const QPointF &point) const
144 return point + QPointF(0, m_scrollBar->value());
147 inline QRectF AbstractItemView::mapToViewport(const QRectF &rect) const
149 return rect.translated(0, m_scrollBar->value());
152 inline QPointF AbstractItemView::mapFromViewport(const QPointF &point) const
154 return point - QPointF(0, m_scrollBar->value());
157 inline QRectF AbstractItemView::mapFromViewport(const QRectF &rect) const
159 return rect.translated(0, -m_scrollBar->value());
162 #endif // ABSTRACTITEMVIEW_H