File indexing completed on 2024-05-05 16:27:56

0001 /* SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org>
0002 
0003    SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef CENTERINGICONVIEW_H
0007 #define CENTERINGICONVIEW_H
0008 #include <QListView>
0009 class QTimer;
0010 
0011 namespace Browser
0012 {
0013 
0014 /**
0015  * \brief QListView subclass which shows its content as icons centered in the middle
0016  *
0017  * To make KPhotoAlbum slightly more sexy, the overview page has its items
0018  * centered at the middle of the screen. This class has the capability to
0019  * do that when \ref setViewMode is called with \ref CenterView as argument.
0020  */
0021 class CenteringIconView : public QListView
0022 {
0023     Q_OBJECT
0024 public:
0025     enum ViewMode { CenterView,
0026                     NormalIconView };
0027 
0028     explicit CenteringIconView(QWidget *parent);
0029     void setViewMode(ViewMode);
0030     void setModel(QAbstractItemModel *) override;
0031     void showEvent(QShowEvent *) override;
0032 
0033 protected:
0034     void resizeEvent(QResizeEvent *) override;
0035 
0036 private:
0037     void setupMargins();
0038     int columnCount(int elementCount) const;
0039     int availableWidth() const;
0040     int availableHeight() const;
0041 
0042 private:
0043     ViewMode m_viewMode;
0044 };
0045 
0046 }
0047 
0048 #endif /* CENTERINGICONVIEW_H */
0049 
0050 // vi:expandtab:tabstop=4 shiftwidth=4: