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/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 pcapxx::descriptor<>* trace();
00099
00101 int position() const;
00102
00104 int lastPosition() const;
00105
00117 QString positionString(int pos = -1) const;
00118
00126 bool swapContent() const;
00127
00129 int lastLeftClicked() const;
00130
00132 void writeSelection(const QString& file);
00133
00134 signals:
00136 void traceChanged();
00137
00139 void positionChanged(int);
00140
00142 void packetLeftClicked(int);
00143
00145 void packetDoubleLeftClicked(int);
00146
00147 public slots:
00149 void setPosition(int p = 0);
00150
00156 void setSwapContent(bool b = false);
00157
00159 virtual void update();
00160
00161 protected:
00163
00164 virtual void keyPressEvent(QKeyEvent*);
00165 virtual void mouseMoveEvent(QMouseEvent*);
00166 virtual void mousePressEvent(QMouseEvent*);
00167 virtual void mouseDoubleClickEvent(QMouseEvent*);
00168 virtual void resizeEvent(QResizeEvent*);
00169 virtual void scrollContentsBy(int, int);
00171
00172 private:
00173 int packetAt(const QPoint& pos) const;
00174 void startUpdateTimer(int ms);
00175 void resizeView(const QSize& size,
00176 bool resize_pkts,
00177 bool update_if_needed);
00178
00179 struct selection
00180 {
00182 struct range: public std::pair<int, int>
00183 {
00185 range(int, int);
00186 };
00187
00188 typedef std::list<range> list_of_ranges;
00189
00190 void clear();
00191 bool contains(int) const;
00192 std::ostream& print(std::ostream&) const;
00193 selection& toggle(int);
00194
00195 selection& operator = (int);
00196 selection& operator = (const range&);
00197
00198 const list_of_ranges& ranges() const;
00199
00200 private:
00201 typedef list_of_ranges::iterator iterator;
00202
00203 void cleanup(iterator&);
00204
00205 list_of_ranges ranges_;
00206 };
00207
00208 pcapxx::descriptor<>* trace_;
00209 bool swap_content_;
00210 QWidget view_;
00211 int pos_;
00212 QTimer update_timer_;
00213 std::vector<Packet*> pkts_;
00214 selection selection_;
00215 int last_selected_;
00216 int last_left_clicked_;
00217 };
00218
00219 }
00220
00221 }
00222
00223 # include "wscout_gui_trace.hxx"
00224
00225 #endif // ! WSCOUT_GUI_TRACE_HH_