File indexing completed on 2024-05-19 16:52:04

0001 /*
0002     SPDX-FileCopyrightText: 2004 Max Howell <max.howell@methylblue.com>
0003     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef WIDGET_H
0009 #define WIDGET_H
0010 
0011 // QtCore
0012 #include <QTimer>
0013 #include <QUrl>
0014 // QtGui
0015 #include <QMouseEvent>
0016 #include <QPaintEvent>
0017 #include <QResizeEvent>
0018 
0019 #include "segmentTip.h"
0020 
0021 template<class T>
0022 class Chain;
0023 class Directory;
0024 class File;
0025 class KJob;
0026 
0027 namespace RadialMap
0028 {
0029 class Segment;
0030 
0031 class Map : public QPixmap
0032 {
0033 public:
0034     Map();
0035     ~Map() override;
0036 
0037     void make(const Directory *, bool = false);
0038     bool resize(const QRect &);
0039 
0040     bool isNull() const
0041     {
0042         return (m_signature == nullptr);
0043     }
0044     void invalidate(const bool);
0045 
0046     friend class Builder;
0047     friend class Widget;
0048 
0049 private:
0050     void paint(uint = 1);
0051     void aaPaint();
0052     void colorise();
0053     void setRingBreadth();
0054 
0055     Chain<Segment> *m_signature;
0056 
0057     QRect m_rect;
0058     uint m_ringBreadth; /// ring breadth
0059     uint m_innerRadius; /// radius of inner circle
0060     uint m_visibleDepth; /// visible level depth of system
0061     QString m_centerText;
0062 
0063     uint MAP_2MARGIN;
0064 };
0065 
0066 class Widget : public QWidget
0067 {
0068     Q_OBJECT
0069 
0070 public:
0071     explicit Widget(QWidget * = nullptr);
0072 
0073     QString path() const;
0074     QUrl url(File const *const = nullptr) const;
0075 
0076     bool isValid() const
0077     {
0078         return m_tree != nullptr;
0079     }
0080 
0081     friend struct Label; // FIXME badness
0082 
0083 public slots:
0084     void zoomIn();
0085     void zoomOut();
0086     void create(const Directory *);
0087     void invalidate(const bool = true);
0088     void refresh(int);
0089 
0090 private slots:
0091     void resizeTimeout();
0092     void sendFakeMouseEvent();
0093     void deleteJobFinished(KJob *);
0094     void createFromCache(const Directory *);
0095 
0096 signals:
0097     void activated(const QUrl &);
0098     void invalidated(const QUrl &);
0099     void created(const Directory *);
0100     void mouseHover(const QString &);
0101 
0102 protected:
0103     void paintEvent(QPaintEvent *) override;
0104     void resizeEvent(QResizeEvent *) override;
0105     void mouseMoveEvent(QMouseEvent *) override;
0106     void mousePressEvent(QMouseEvent *) override;
0107 
0108 protected:
0109     const Segment *segmentAt(QPoint &) const; // FIXME const reference for a library others can use
0110     const Segment *rootSegment() const
0111     {
0112         return m_rootSegment;
0113     } /// never == 0
0114     const Segment *focusSegment() const
0115     {
0116         return m_focus;
0117     } /// 0 == nothing in focus
0118 
0119 private:
0120     void paintExplodedLabels(QPainter &) const;
0121 
0122     const Directory *m_tree;
0123     const Segment *m_focus;
0124     QPoint m_offset;
0125     QTimer m_timer;
0126     Map m_map;
0127     SegmentTip m_tip;
0128     Segment *m_rootSegment;
0129 };
0130 }
0131 
0132 #endif