1 /***************************************************************************** 2 * Copyright (C) 2004 Max Howell <max.howell@methylblue.com> * 3 * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org] * 4 * * 5 * This file is part of Krusader [https://krusader.org]. * 6 * * 7 * Krusader is free software: you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation, either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 * Krusader is distributed in the hope that it will be useful, * 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15 * GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License * 18 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * 19 *****************************************************************************/ 20 21 #ifndef WIDGET_H 22 #define WIDGET_H 23 24 // QtCore 25 #include <QTimer> 26 #include <QUrl> 27 // QtGui 28 #include <QMouseEvent> 29 #include <QResizeEvent> 30 #include <QPaintEvent> 31 32 #include "segmentTip.h" 33 34 template <class T> class Chain; 35 class Directory; 36 class File; 37 class KJob; 38 39 namespace RadialMap 40 { 41 class Segment; 42 43 class Map : public QPixmap 44 { 45 public: 46 Map(); 47 ~Map(); 48 49 void make(const Directory *, bool = false); 50 bool resize(const QRect&); 51 isNull()52 bool isNull() const { 53 return (m_signature == 0); 54 } 55 void invalidate(const bool); 56 57 friend class Builder; 58 friend class Widget; 59 60 private: 61 void paint(uint = 1); 62 void aaPaint(); 63 void colorise(); 64 void setRingBreadth(); 65 66 Chain<Segment> *m_signature; 67 68 QRect m_rect; 69 uint m_ringBreadth; ///ring breadth 70 uint m_innerRadius; ///radius of inner circle 71 uint m_visibleDepth; ///visible level depth of system 72 QString m_centerText; 73 74 uint MAP_2MARGIN; 75 }; 76 77 class Widget : public QWidget 78 { 79 Q_OBJECT 80 81 public: 82 explicit Widget(QWidget* = 0); 83 84 QString path() const; 85 QUrl url(File const * const = 0) const; 86 isValid()87 bool isValid() const { 88 return m_tree != 0; 89 } 90 91 friend class Label; //FIXME badness 92 93 public slots: 94 void zoomIn(); 95 void zoomOut(); 96 void create(const Directory*); 97 void invalidate(const bool = true); 98 void refresh(int); 99 100 private slots: 101 void resizeTimeout(); 102 void sendFakeMouseEvent(); 103 void deleteJobFinished(KJob*); 104 void createFromCache(const Directory*); 105 106 signals: 107 void activated(const QUrl&); 108 void invalidated(const QUrl&); 109 void created(const Directory*); 110 void mouseHover(const QString&); 111 112 protected: 113 virtual void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; 114 virtual void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE; 115 virtual void mouseMoveEvent(QMouseEvent*) Q_DECL_OVERRIDE; 116 virtual void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE; 117 118 protected: 119 const Segment *segmentAt(QPoint&) const; //FIXME const reference for a library others can use rootSegment()120 const Segment *rootSegment() const { 121 return m_rootSegment; 122 } ///never == 0 focusSegment()123 const Segment *focusSegment() const { 124 return m_focus; 125 } ///0 == nothing in focus 126 127 private: 128 void paintExplodedLabels(QPainter&) const; 129 130 const Directory *m_tree; 131 const Segment *m_focus; 132 QPoint m_offset; 133 QTimer m_timer; 134 Map m_map; 135 SegmentTip m_tip; 136 Segment *m_rootSegment; 137 }; 138 } 139 140 #endif 141