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
00077 Trace(const Trace& t);
00078
00080 virtual ~Trace();
00081
00083 void setTrace(pcap::Trace* trace = 0);
00084
00086 const pcap::Trace* trace() const;
00087
00089 int position() const;
00090
00092 int lastPosition() const;
00093
00105 QString positionString(int pos = -1) const;
00106
00107 signals:
00109 void traceChanged();
00110
00112 void positionChanged(int);
00113
00114 public slots:
00116 void setPosition(int p = 0);
00117
00119 virtual void update();
00120
00121 protected:
00123
00124 virtual void keyPressEvent(QKeyEvent*);
00125 virtual void mouseMoveEvent(QMouseEvent*);
00126 virtual void mousePressEvent(QMouseEvent*);
00127 virtual void resizeEvent(QResizeEvent*);
00128 virtual void scrollContentsBy(int, int);
00130
00131 private:
00132 int packetAt(const QPoint& pos) const;
00133 void startUpdateTimer(int ms);
00134 void resizeView(const QSize& size,
00135 bool resize_pkts,
00136 bool update_if_needed);
00137
00138 struct selection
00139 {
00140 struct range: public std::pair<int, int>
00141 {
00142 range(int, int);
00143 };
00144
00145 void clear();
00146 bool contains(int) const;
00147 std::ostream& print(std::ostream&) const;
00148 selection& toggle(int);
00149
00150 selection& operator = (int);
00151 selection& operator = (const range&);
00152
00153 private:
00154 typedef std::list<range> list_of_ranges;
00155 typedef list_of_ranges::iterator iterator;
00156
00157 void cleanup(iterator&);
00158
00159 list_of_ranges ranges_;
00160 };
00161
00162 pcap::Trace* trace_;
00163 QWidget view_;
00164 int pos_;
00165 QTimer update_timer_;
00166 std::vector<Packet*> pkts_;
00167 selection selection_;
00168 int last_selected_;
00169 };
00170
00171 }
00172
00173 }
00174
00175 #endif // ! WSCOUT_GUI_TRACE_HH_