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 <wipal/pcap/stream.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(wpl::pcap::indexed_file<>* trace = 0,
00084 QWidget* parent = 0);
00085
00087 Trace(const Trace& t);
00088
00090 virtual ~Trace();
00091
00093 void setTrace(wpl::pcap::indexed_file<>* t = 0);
00094
00096 const wpl::pcap::indexed_file<>* trace() const;
00097
00099 wpl::pcap::indexed_file<>* trace();
00100
00103 int position() const;
00104
00106 int lastPosition() const;
00107
00119 QString positionString(int pos = -1) const;
00120
00128 bool swapContent() const;
00129
00131 int lastLeftClicked() const;
00132
00134 void writeSelection(const QString& file);
00135
00136 signals:
00138 void traceChanged();
00139
00141 void positionChanged(int);
00142
00144 void packetLeftClicked(int);
00145
00147 void packetDoubleLeftClicked(int);
00148
00149 public slots:
00151 void setPosition(int p = 0);
00152
00158 void setSwapContent(bool b = false);
00159
00161 virtual void update();
00162
00163 protected:
00165
00166 virtual void keyPressEvent(QKeyEvent*);
00167 virtual void mouseMoveEvent(QMouseEvent*);
00168 virtual void mousePressEvent(QMouseEvent*);
00169 virtual void mouseDoubleClickEvent(QMouseEvent*);
00170 virtual void resizeEvent(QResizeEvent*);
00171 virtual void scrollContentsBy(int, int);
00173
00174 private:
00175 int packetAt(const QPoint& pos) const;
00176 void startUpdateTimer(int ms);
00177 void resizeView(const QSize& size,
00178 bool resize_pkts,
00179 bool update_if_needed);
00180
00181 struct selection
00182 {
00184 struct range: public std::pair<int, int>
00185 {
00187 range(int, int);
00188 };
00189
00190 typedef std::list<range> list_of_ranges;
00191
00192 void clear();
00193 bool contains(int) const;
00194 std::ostream& print(std::ostream&) const;
00195 selection& toggle(int);
00196
00197 selection& operator = (int);
00198 selection& operator = (const range&);
00199
00200 const list_of_ranges& ranges() const;
00201
00202 private:
00203 typedef list_of_ranges::iterator iterator;
00204
00205 void cleanup(iterator&);
00206
00207 list_of_ranges ranges_;
00208 };
00209
00210 wpl::pcap::indexed_file<>* trace_;
00211 bool swap_content_;
00212 QWidget view_;
00213 int pos_;
00214 QTimer update_timer_;
00215 std::vector<Packet*> pkts_;
00216 selection selection_;
00217 int last_selected_;
00218 int last_left_clicked_;
00219 };
00220
00221 }
00222
00223 }
00224
00225 # include "wscout_gui_trace.hxx"
00226
00227 #endif // ! WSCOUT_GUI_TRACE_HH_