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 "wscout_gui_packet.hh"
00032 # include "wscout_pcap_trace.hh"
00033
00034 namespace wscout
00035 {
00036
00037 namespace gui
00038 {
00039
00041 class Trace: public QAbstractScrollArea
00042 {
00043 Q_OBJECT
00044
00046 Q_PROPERTY(int position
00047 READ position
00048 WRITE setPosition
00049 RESET setPosition
00050 DESIGNABLE false
00051 NOTIFY positionChanged(int)
00052 USER true)
00053
00054 enum
00055 {
00057 set_position_update_delay = 0,
00058
00060 scroll_contents_by_update_delay = 20,
00061
00063 packet_spacing = 4,
00064
00066 trace_vmargin = packet_spacing,
00067
00069 trace_hmargin = 8
00070 };
00071
00072 public:
00074 explicit Trace(pcap::Trace* trace = 0, QWidget* parent = 0);
00075 virtual ~Trace();
00076
00078 void setTrace(pcap::Trace* trace = 0);
00079
00081 const pcap::Trace* trace() const;
00082
00084 int position() const;
00085
00087 int lastPosition() const;
00088
00100 QString positionString(int pos = -1) const;
00101
00102 signals:
00104 void traceChanged();
00105
00107 void positionChanged(int);
00108
00109 public slots:
00111 void setPosition(int p = 0);
00112
00114 virtual void update();
00115
00116 protected:
00118
00119 virtual void keyPressEvent(QKeyEvent*);
00120 virtual void mouseMoveEvent(QMouseEvent*);
00121 virtual void mousePressEvent(QMouseEvent*);
00122 virtual void resizeEvent(QResizeEvent*);
00123 virtual void scrollContentsBy(int, int);
00125
00126 private:
00127 int packetAt(const QPoint& pos) const;
00128 void startUpdateTimer(int ms);
00129 void resizeView(const QSize& size,
00130 bool resize_pkts,
00131 bool update_if_needed);
00132
00133 struct selection
00134 {
00135 struct range: public std::pair<int, int>
00136 {
00137 range(int, int);
00138 };
00139
00140 void clear();
00141 bool contains(int) const;
00142 std::ostream& print(std::ostream&) const;
00143 selection& toggle(int);
00144
00145 selection& operator = (int);
00146 selection& operator = (const range&);
00147
00148 private:
00149 typedef std::list<range> list_of_ranges;
00150 typedef list_of_ranges::iterator iterator;
00151
00152 void cleanup(iterator&);
00153
00154 list_of_ranges ranges_;
00155 };
00156
00157 pcap::Trace* trace_;
00158 QWidget view_;
00159 int pos_;
00160 QTimer update_timer_;
00161 std::vector<Packet*> pkts_;
00162 selection selection_;
00163 int last_selected_;
00164 };
00165
00166 }
00167
00168 }
00169
00170 #endif // ! WSCOUT_GUI_TRACE_HH_