File indexing completed on 2024-05-05 05:51:13
0001 /*********************************************************************** 0002 * SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com> 0003 * SPDX-FileCopyrightText: 2008-2009 Martin Sandsmark <martin.sandsmark@kde.org> 0004 * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 ***********************************************************************/ 0008 0009 #pragma once 0010 0011 #include <memory> 0012 0013 #include "fileTree.h" 0014 #include <QColor> 0015 #include <QObject> 0016 #include <QQmlEngine> 0017 #include <QUrl> 0018 namespace RadialMap 0019 { 0020 class Segment : public QObject // all angles are in 16ths of degrees 0021 { 0022 Q_OBJECT 0023 public: 0024 bool m_highlight = false; 0025 Q_SIGNAL void highlightChanged(); 0026 Q_PROPERTY(bool fake MEMBER m_fake CONSTANT) 0027 0028 Q_PROPERTY(QColor color READ color NOTIFY paletteChanged) 0029 Q_PROPERTY(QColor brush READ brush NOTIFY paletteChanged) 0030 Q_PROPERTY(QColor pen READ pen NOTIFY paletteChanged) 0031 Q_SIGNAL void paletteChanged(); 0032 0033 Q_PROPERTY(QString uuid MEMBER m_uuid CONSTANT) 0034 0035 Segment(const std::shared_ptr<File> &f, uint s, uint l, bool isFake = false); 0036 ~Segment() override; 0037 Q_DISABLE_COPY_MOVE(Segment) 0038 0039 Q_INVOKABLE uint start() const 0040 { 0041 return m_angleStart; 0042 } 0043 Q_INVOKABLE uint length() const 0044 { 0045 return m_angleSegment; 0046 } 0047 Q_INVOKABLE uint end() const 0048 { 0049 return m_angleStart + m_angleSegment; 0050 } 0051 Q_INVOKABLE QUrl url() const 0052 { 0053 return m_file->url(); 0054 } 0055 Q_INVOKABLE bool isFolder() const 0056 { 0057 return m_file->isFolder(); 0058 } 0059 Q_INVOKABLE QString displayName() const 0060 { 0061 return m_file->displayName(); 0062 } 0063 Q_INVOKABLE QString displayPath() const 0064 { 0065 return m_file->displayPath(); 0066 } 0067 0068 const std::shared_ptr<File> file() const 0069 { 0070 return m_file; 0071 } 0072 Q_INVOKABLE const QColor &pen() const 0073 { 0074 return m_pen; 0075 } 0076 Q_INVOKABLE const QColor &brush() const 0077 { 0078 return m_brush; 0079 } 0080 0081 Q_INVOKABLE QString color() 0082 { 0083 return m_brush.name(); 0084 } 0085 bool isFake() const 0086 { 0087 return m_fake; 0088 } 0089 bool hasHiddenChildren() const 0090 { 0091 return m_hasHiddenChildren; 0092 } 0093 0094 Q_INVOKABLE QString humanReadableSize() const 0095 { 0096 return m_file->humanReadableSize(); 0097 } 0098 0099 Q_INVOKABLE uint files() const 0100 { 0101 if (auto folder = std::dynamic_pointer_cast<Folder>(file())) { 0102 return folder->children(); 0103 } 0104 return 0; 0105 } 0106 0107 bool intersects(uint a) const 0108 { 0109 return ((a >= start()) && (a < end())); 0110 } 0111 0112 QString uuid() const 0113 { 0114 return m_uuid; 0115 } 0116 0117 friend class Map; 0118 friend class Builder; 0119 0120 private: 0121 void setPalette(const QColor &p, const QColor &b) 0122 { 0123 m_pen = p; 0124 m_brush = b; 0125 Q_EMIT paletteChanged(); 0126 } 0127 0128 const uint m_angleStart; 0129 const uint m_angleSegment; 0130 const std::shared_ptr<File> m_file = nullptr; 0131 QColor m_pen, m_brush; 0132 bool m_hasHiddenChildren = false; 0133 const bool m_fake; 0134 const QString m_uuid; 0135 }; 0136 } // namespace RadialMap 0137 0138 #ifndef PI 0139 #define PI 3.141592653589793 0140 #endif 0141 #ifndef M_PI 0142 #define M_PI 3.14159265358979323846264338327 0143 #endif 0144 0145 #define MIN_RING_BREADTH 20 0146 #define MAX_RING_BREADTH 60 0147 #define DEFAULT_RING_DEPTH 4 // first level = 0 0148 #define MIN_RING_DEPTH 0 0149 0150 #define MAP_HIDDEN_TRIANGLE_SIZE 5 0151 0152 #define LABEL_MAP_SPACER 7 0153 #define LABEL_TEXT_HMARGIN 5 0154 #define LABEL_TEXT_VMARGIN 0 0155 #define LABEL_ANGLE_MARGIN 32 0156 #define LABEL_MIN_ANGLE_FACTOR 0.05 0157 #define LABEL_MAX_CHARS 30 0158 0159 // QPainter::paintPie: 0160 // The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean 0161 // counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position. 0162 #define MAX_DEGREE 5760 0163 #define DEGREE_FACTOR 16