File indexing completed on 2024-04-28 17:05:54
0001 /* 0002 SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KRSPECIALWIDGETS_H 0010 #define KRSPECIALWIDGETS_H 0011 0012 // QtCore 0013 #include <QEvent> 0014 // QtGui 0015 #include <QColor> 0016 #include <QKeyEvent> 0017 #include <QPaintEvent> 0018 #include <QPainter> 0019 // QtWidgets 0020 #include <QWidget> 0021 0022 #include <KCompletion/KLineEdit> 0023 #include <KIO/Global> 0024 #include <utility> 0025 0026 class KrPieSlice; 0027 0028 class KrPie : public QWidget 0029 { 0030 Q_OBJECT 0031 public: 0032 explicit KrPie(KIO::filesize_t _totalSize, QWidget *parent = nullptr); 0033 void addSlice(KIO::filesize_t size, QString label); 0034 0035 protected: 0036 void paintEvent(QPaintEvent *) override; 0037 0038 private: 0039 QList<KrPieSlice> slices; 0040 KIO::filesize_t totalSize, sizeLeft; 0041 static QColor colors[12]; 0042 }; 0043 0044 class KrFSDisplay : public QWidget 0045 { 0046 Q_OBJECT 0047 public: 0048 // this constructor is used for a mounted filesystem 0049 KrFSDisplay(QWidget *parent, QString _alias, QString _realName, KIO::filesize_t _total, KIO::filesize_t _free); 0050 // this one is for an unmounted/supermount file system 0051 KrFSDisplay(QWidget *parent, QString _alias, QString _realName, bool sm = false); 0052 // the last one is used inside MountMan(R), when no filesystem is selected 0053 explicit KrFSDisplay(QWidget *parent); 0054 inline void setTotalSpace(KIO::filesize_t t) 0055 { 0056 totalSpace = t; 0057 } 0058 inline void setFreeSpace(KIO::filesize_t t) 0059 { 0060 freeSpace = t; 0061 } 0062 inline void setAlias(QString a) 0063 { 0064 alias = std::move(a); 0065 } 0066 inline void setRealName(QString r) 0067 { 0068 realName = std::move(r); 0069 } 0070 inline void setMounted(bool m) 0071 { 0072 mounted = m; 0073 } 0074 inline void setEmpty(bool e) 0075 { 0076 empty = e; 0077 } 0078 inline void setSupermount(bool s) 0079 { 0080 supermount = s; 0081 } 0082 0083 protected: 0084 void paintEvent(QPaintEvent *) override; 0085 0086 private: 0087 KIO::filesize_t totalSpace, freeSpace; 0088 QString alias, realName; 0089 bool mounted, empty, supermount; 0090 }; 0091 0092 class KrPieSlice 0093 { 0094 public: 0095 KrPieSlice(long double _perct, QColor _color, QString _label) 0096 : perct(_perct) 0097 , color(std::move(_color)) 0098 , label(std::move(_label)) 0099 { 0100 } 0101 inline QColor getColor() 0102 { 0103 return color; 0104 } 0105 inline long double getPerct() 0106 { 0107 return perct; 0108 } 0109 inline QString getLabel() 0110 { 0111 return label; 0112 } 0113 inline void setPerct(float _perct) 0114 { 0115 perct = _perct; 0116 } 0117 inline void setLabel(QString _label) 0118 { 0119 label = std::move(_label); 0120 } 0121 0122 private: 0123 long double perct; 0124 QColor color; 0125 QString label; 0126 }; 0127 0128 #endif