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
00131 signals:
00133 void traceChanged();
00134
00136 void positionChanged(int);
00137
00139 void packetLeftClicked(int);
00140
00142 void packetDoubleLeftClicked(int);
00143
00144 public slots:
00146 void setPosition(int p = 0);
00147
00153 void setSwapContent(bool b = false);
00154
00156 virtual void update();
00157
00158 protected:
00160
00161 virtual void keyPressEvent(QKeyEvent*);
00162 virtual void mouseMoveEvent(QMouseEvent*);
00163 virtual void mousePressEvent(QMouseEvent*);
00164 virtual void mouseDoubleClickEvent(QMouseEvent*);
00165 virtual void resizeEvent(QResizeEvent*);
00166 virtual void scrollContentsBy(int, int);
00168
00169 private:
00170 int packetAt(const QPoint& pos) const;
00171 void startUpdateTimer(int ms);
00172 void resizeView(const QSize& size,
00173 bool resize_pkts,
00174 bool update_if_needed);
00175
00176 struct selection
00177 {
00179 struct range: public std::pair<int, int>
00180 {
00182 range(int, int);
00183 };
00184
00185 void clear();
00186 bool contains(int) const;
00187 std::ostream& print(std::ostream&) const;
00188 selection& toggle(int);
00189
00190 selection& operator = (int);
00191 selection& operator = (const range&);
00192
00193 private:
00194 typedef std::list<range> list_of_ranges;
00195 typedef list_of_ranges::iterator iterator;
00196
00197 void cleanup(iterator&);
00198
00199 list_of_ranges ranges_;
00200 };
00201
00202 pcapxx::descriptor<>* trace_;
00203 bool swap_content_;
00204 QWidget view_;
00205 int pos_;
00206 QTimer update_timer_;
00207 std::vector<Packet*> pkts_;
00208 selection selection_;
00209 int last_selected_;
00210 int last_left_clicked_;
00211 };
00212
00213 }
00214
00215 }
00216
00217 # include "wscout_gui_trace.hxx"
00218
00219 #endif // ! WSCOUT_GUI_TRACE_HH_