00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef WSCOUT_GUI_TRACE_HH_
00024 # define WSCOUT_GUI_TRACE_HH_
00025
00026 # include <ostream>
00027
00028 # include <QtGui/QAbstractScrollArea>
00029 # include <QtCore/QTimer>
00030
00031 # include <trace-tools/pcap/descriptor.hh>
00032
00033 namespace wscout
00034 {
00035
00036 namespace gui
00037 {
00038
00039
00040 struct Packet;
00041
00043 class Trace: public QAbstractScrollArea
00044 {
00045 Q_OBJECT
00046
00048 Q_PROPERTY(int position
00049 READ position
00050 WRITE setPosition
00051 RESET setPosition
00052 DESIGNABLE false
00053 NOTIFY positionChanged(int)
00054 USER true)
00055
00056 Q_PROPERTY(bool swapContent
00057 READ swapContent
00058 WRITE setSwapContent
00059 RESET setSwapContent
00060 DESIGNABLE false)
00061
00062
00063 enum
00064 {
00066 set_position_update_delay = 0,
00067
00069 scroll_contents_by_update_delay = 20,
00070
00072 packet_spacing = 4,
00073
00075 trace_vmargin = packet_spacing,
00076
00078 trace_hmargin = 8
00079 };
00080
00081 public:
00083 explicit Trace(pcapxx::descriptor<>* trace = 0, QWidget* parent = 0);
00084
00086 Trace(const Trace& t);
00087
00089 virtual ~Trace();
00090
00092 void setTrace(pcapxx::descriptor<>* t = 0);
00093
00095 const pcapxx::descriptor<>* trace() const;
00096
00098 int position() const;
00099
00101 int lastPosition() const;
00102
00114 QString positionString(int pos = -1) const;
00115
00123 bool swapContent() const;
00124
00125 signals:
00127 void traceChanged();
00128
00130 void positionChanged(int);
00131
00132 public slots:
00134 void setPosition(int p = 0);
00135
00141 void setSwapContent(bool b = false);
00142
00144 virtual void update();
00145
00146 protected:
00148
00149 virtual void keyPressEvent(QKeyEvent*);
00150 virtual void mouseMoveEvent(QMouseEvent*);
00151 virtual void mousePressEvent(QMouseEvent*);
00152 virtual void resizeEvent(QResizeEvent*);
00153 virtual void scrollContentsBy(int, int);
00155
00156 private:
00157 int packetAt(const QPoint& pos) const;
00158 void startUpdateTimer(int ms);
00159 void resizeView(const QSize& size,
00160 bool resize_pkts,
00161 bool update_if_needed);
00162
00163 struct selection
00164 {
00166 struct range: public std::pair<int, int>
00167 {
00169 range(int, int);
00170 };
00171
00172 void clear();
00173 bool contains(int) const;
00174 std::ostream& print(std::ostream&) const;
00175 selection& toggle(int);
00176
00177 selection& operator = (int);
00178 selection& operator = (const range&);
00179
00180 private:
00181 typedef std::list<range> list_of_ranges;
00182 typedef list_of_ranges::iterator iterator;
00183
00184 void cleanup(iterator&);
00185
00186 list_of_ranges ranges_;
00187 };
00188
00189 pcapxx::descriptor<>* trace_;
00190 bool swap_content_;
00191 QWidget view_;
00192 int pos_;
00193 QTimer update_timer_;
00194 std::vector<Packet*> pkts_;
00195 selection selection_;
00196 int last_selected_;
00197 };
00198
00199 }
00200
00201 }
00202
00203 #endif // ! WSCOUT_GUI_TRACE_HH_