src/wscout_gui_packet.hxx

00001 /*
00002  * WScout - Lightweight PCAP visualizer.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
00021  */
00022 
00023 #ifndef WSCOUT_GUI_PACKET_HXX_
00024 # define WSCOUT_GUI_PACKET_HXX_
00025 
00026 # include <QtGui/QVBoxLayout>
00027 
00028 # include "wscout_gui_packet.hh"
00029 
00030 namespace wscout
00031 {
00032 
00033   namespace gui
00034   {
00035 
00036     inline
00037     Packet::Packet(QWidget* parent): QFrame (parent)
00038     {
00039       setFrameStyle(QFrame::Box | QFrame::Plain);
00040       setSizePolicy(QSizePolicy (QSizePolicy::Minimum, QSizePolicy::Fixed));
00041       setupLayout();
00042       setSelected(false);
00043     }
00044 
00045     inline
00046     QBoxLayout*
00047     Packet::layout()
00048     {
00049       QLayout* const    l = QFrame::layout();
00050       QBoxLayout* const r = dynamic_cast<QBoxLayout*> (l);
00051 
00052       assert(not l or r);
00053       return r;
00054     }
00055 
00056     inline
00057     void
00058     Packet::registerProtocol(protocol::id id, header_allocator a)
00059     {
00060       protocols()[id] = a;
00061     }
00062 
00063     inline
00064     Packet::protocol_map&
00065     Packet::protocols()
00066     {
00067       static protocol_map       m;
00068 
00069       return m;
00070     }
00071 
00072     inline
00073     void
00074     Packet::setSelected(bool state)
00075     {
00076       selected_ = state;
00077       setupBorders();
00078     }
00079 
00080     inline
00081     int
00082     Packet::lineWidth() const
00083     {
00084       return selected_ ? border_sel : border_unsel;
00085     }
00086 
00087     inline
00088     int
00089     Packet::margin() const
00090     {
00091       return selected_ ? packet_margin_sel : packet_margin_unsel;
00092     }
00093 
00094     inline
00095     void
00096     Packet::setupBorders()
00097     {
00098       const int m = margin();
00099 
00100       setUpdatesEnabled(false);
00101 
00102       setLineWidth(lineWidth());
00103       layout()->setContentsMargins(m, m, m, m);
00104       updateMinimumSize();
00105 
00106       setUpdatesEnabled(true);
00107     }
00108 
00109     inline
00110     void
00111     Packet::setupLayout()
00112     {
00113       QVBoxLayout* l = new QVBoxLayout;
00114 
00115       l->setSpacing(header_spacing);
00116       setLayout(l);
00117     }
00118 
00119     inline
00120     void
00121     Packet::updateMinimumSize()
00122     {
00123       const int l = lineWidth();
00124 
00125       setMinimumSize(layout()->minimumSize() + QSize (l, l) * 2);
00126     }
00127 
00128   } // End of namespace gui.
00129 
00130 } // End of namespace wscout.
00131 
00132 #endif // ! WSCOUT_GUI_PACKET_HXX_

Generated on Wed Jan 30 19:02:27 2008 for WScout by  doxygen 1.5.4