]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemlistwidget.h
Fix rating pixmap alignment on high-dpi screens
[dolphin.git] / src / panels / places / placesitemlistwidget.h
1 /*
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef PLACESITEMLISTWIDGET_H
8 #define PLACESITEMLISTWIDGET_H
9
10 #include "kitemviews/kstandarditemlistwidget.h"
11
12 #include <QDeadlineTimer>
13 #include <QPainter>
14 #include <QPointer>
15 #include <QStyleOptionGraphicsItem>
16 #include <QWidget>
17
18 #include <KIO/FileSystemFreeSpaceJob>
19
20
21 // The free space / capacity bar is based on KFilePlacesView.
22 // https://invent.kde.org/frameworks/kio/-/commit/933887dc334f3498505af7a86d25db7faae91019
23 struct PlaceFreeSpaceInfo
24 {
25 QDeadlineTimer lastUpdated;
26 KIO::filesize_t used = 0;
27 KIO::filesize_t size = 0;
28 qreal usedRatio = 0;
29 QPointer<KIO::FileSystemFreeSpaceJob> job;
30 };
31
32
33 /**
34 * @brief Extends KStandardItemListWidget to interpret the hidden
35 * property of the PlacesModel and use the right text color.
36 */
37 class PlacesItemListWidget : public KStandardItemListWidget
38 {
39 Q_OBJECT
40
41 public:
42 PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent);
43 ~PlacesItemListWidget() override;
44
45 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
46 void polishEvent() override;
47
48 protected:
49 bool isHidden() const override;
50 QPalette::ColorRole normalTextColorRole() const override;
51 void updateCapacityBar();
52 void resetCapacityBar();
53
54 private:
55 bool m_drawCapacityBar;
56 PlaceFreeSpaceInfo m_freeSpaceInfo;
57 };
58
59 #endif
60
61