CMS 3D CMS Logo

AdvListView Class Reference

AdvListView provides extra flexibility to QListView. More...

#include <Iguana/Studio/interface/AdvListView.h>

List of all members.

Public Member Functions

 AdvListView (QWidget *parent=0, const char *name=0)
 Creates list view witdh a parent widget.
uint getCheckPosition ()
 Gets the column used to for checking box.
void initItem (QListViewItem *item)
 Initiates an inserted item.
void resizeEvent (QResizeEvent *e)
 Reimplemented from QListView.
void setChecked (AdvListViewItem *item, bool is_checked)
 Set the item to be checked.
void setCheckPosition (uint pos)
 Sets the column used to for checking box.

Protected Member Functions

void contentsMouseDoubleClickEvent (QMouseEvent *e)
 Reimplemented from QListView.
void contentsMousePressEvent (QMouseEvent *e)
 Reimplemented from QListView.
void contentsMouseReleaseEvent (QMouseEvent *e)
 Reimplemented from QListView.
void init ()
 Initiates the AdvListView.
bool isInsideChecker (int x)
 Returns true if mouse is inside checker rectangle.

Private Attributes

uint checkAtPosition_
QPixmap checkedPixmap_
bool disableMouseRelease_
int oldWidth_
QPixmap uncheckedPixmap_


Detailed Description

AdvListView provides extra flexibility to QListView.

Features:

It can display and control a hierarchy of multi-column items, and provides the ability to add new items at run-time, lets the user select one or many items, sort the list in increasing or decreasing order by any column, and so on.

AdvListView can also contain QListViewItems.

AdvListView.gif

The simplest mode of usage is to create a AdvListView, add some column headers using setColumn(), create one or more QListViewItem or AdvListViewItem objects with the AdvListView as parent, set up the list view's geometry(), and show() it.

The main setup functions are

Definition at line 66 of file AdvListView.h.


Constructor & Destructor Documentation

AdvListView::AdvListView ( QWidget *  parent = 0,
const char *  name = 0 
)

Creates list view witdh a parent widget.

Definition at line 52 of file AdvListView.cc.

References header.

00053     : QListView(parent, name), checkAtPosition_(1), 
00054     oldWidth_(-1), disableMouseRelease_(false), checkedPixmap_(QPixmap(checked_)), uncheckedPixmap_(QPixmap(unchecked_))
00055 {
00056     header()->setResizeEnabled(false);
00057     header()->setMovingEnabled(false);
00058 }


Member Function Documentation

void AdvListView::contentsMouseDoubleClickEvent ( QMouseEvent *  e  )  [protected]

Reimplemented from QListView.

Definition at line 120 of file AdvListView.cc.

00121 {
00122     QPoint vp = contentsToViewport(e->pos());
00123 
00124     AdvListViewItem*  item  = static_cast<AdvListViewItem*>(itemAt(vp));
00125     if (!item || !item->isMagic())
00126         QListView::contentsMouseDoubleClickEvent(e);
00127     
00128     QListViewItem* qitem = itemAt(vp);
00129     if (qitem)
00130         emit doubleClicked( qitem );
00131 }

void AdvListView::contentsMousePressEvent ( QMouseEvent *  e  )  [protected]

Reimplemented from QListView.

Definition at line 133 of file AdvListView.cc.

References disableMouseRelease_, isInsideChecker(), and setChecked().

00134 {
00135     QPoint vp = contentsToViewport(e->pos());
00136     AdvListViewItem*  item  = static_cast<AdvListViewItem*>(itemAt( vp ));
00137     if (item && item->isCheckable() && isInsideChecker(e->x())) {
00138         if (item->isChecked()) 
00139             setChecked(item, false);
00140         else 
00141             setChecked(item, true);
00142         disableMouseRelease_ = true;
00143     }    
00144     else {
00145         disableMouseRelease_ = false;
00146         QListView::contentsMousePressEvent(e);
00147     }
00148 }

void AdvListView::contentsMouseReleaseEvent ( QMouseEvent *  e  )  [protected]

Reimplemented from QListView.

Definition at line 150 of file AdvListView.cc.

References disableMouseRelease_.

00151 {
00152     if (disableMouseRelease_)
00153         disableMouseRelease_ = false;
00154     else
00155         QListView::contentsMouseReleaseEvent(e);
00156 }

uint AdvListView::getCheckPosition (  )  [inline]

Gets the column used to for checking box.

Definition at line 76 of file AdvListView.h.

00076 { return checkAtPosition_; }

void AdvListView::init ( void   )  [protected]

Initiates the AdvListView.

Definition at line 60 of file AdvListView.cc.

References initItem().

00061 {
00062     QListViewItem* child = firstChild();
00063     while (child) {
00064         initItem(child);
00065         child = child->nextSibling();
00066     }
00067 }

void AdvListView::initItem ( QListViewItem *  item  ) 

Initiates an inserted item.

Definition at line 94 of file AdvListView.cc.

References AdvListViewItem::isCheckable(), AdvListViewItem::isChecked(), and setChecked().

Referenced by init().

00095 {
00096     // Check the item itself
00097     AdvListViewItem* a_item = static_cast<AdvListViewItem*>(item);
00098     if (a_item && a_item->isCheckable()) 
00099         setChecked(a_item, a_item->isChecked());
00100     // Check all its children
00101     QListViewItem* child = item->firstChild();
00102     while (child) {
00103         initItem(child);
00104         child = child->nextSibling();
00105     }
00106 }

bool AdvListView::isInsideChecker ( int  x  )  [protected]

Returns true if mouse is inside checker rectangle.

Definition at line 158 of file AdvListView.cc.

References c, and checkAtPosition_.

Referenced by contentsMousePressEvent().

00159 {
00160     for (uint c = 0; c<checkAtPosition_; c++)
00161         x -= columnWidth(c);
00162     return  (x >= 0 && x <= columnWidth(checkAtPosition_));
00163 }

void AdvListView::resizeEvent ( QResizeEvent *  e  ) 

Reimplemented from QListView.

Definition at line 69 of file AdvListView.cc.

References c, int, w, and width.

00070 {
00071     QListView::resizeEvent(e);
00072 
00073     int h_width = 0;
00074     int c = 0;
00075     while (columnWidth(c)) {
00076         h_width +=columnWidth(c);
00077         c++;
00078     }
00079     int columns = c;
00080     if (!h_width)
00081         return;
00082     
00083     float coeff = 1.0*viewport()->width()/h_width;
00084     int new_width = 0;
00085     for (c = 0; c<columns-1; c++) {
00086         int w = int(coeff*columnWidth(c));
00087         setColumnWidth(c, w);
00088         new_width += w;
00089     }
00090     setColumnWidth(columns-1, viewport()->width()-new_width);
00091     viewport()->repaint();
00092 }

void AdvListView::setChecked ( AdvListViewItem item,
bool  is_checked 
)

Set the item to be checked.

Definition at line 108 of file AdvListView.cc.

References checkAtPosition_, checkedPixmap_, AdvListViewItem::isCheckable(), AdvListViewItem::isChecked(), AdvListViewItem::setChecked(), and uncheckedPixmap_.

Referenced by contentsMousePressEvent(), initItem(), and AdvListViewItem::setChecked().

00109 {
00110     if (item && item->isCheckable()) {
00111         if (item->isChecked() != is_checked)
00112             item->setChecked(is_checked);
00113         if (is_checked) 
00114             item->setPixmap(checkAtPosition_, checkedPixmap_);
00115         else 
00116             item->setPixmap(checkAtPosition_, uncheckedPixmap_);
00117     }    
00118 }

void AdvListView::setCheckPosition ( uint  pos  )  [inline]

Sets the column used to for checking box.

Definition at line 78 of file AdvListView.h.

00078 { checkAtPosition_ = pos; }


Member Data Documentation

uint AdvListView::checkAtPosition_ [private]

Definition at line 93 of file AdvListView.h.

Referenced by isInsideChecker(), and setChecked().

QPixmap AdvListView::checkedPixmap_ [private]

Definition at line 96 of file AdvListView.h.

Referenced by setChecked().

bool AdvListView::disableMouseRelease_ [private]

Definition at line 95 of file AdvListView.h.

Referenced by contentsMousePressEvent(), and contentsMouseReleaseEvent().

int AdvListView::oldWidth_ [private]

Definition at line 94 of file AdvListView.h.

QPixmap AdvListView::uncheckedPixmap_ [private]

Definition at line 97 of file AdvListView.h.

Referenced by setChecked().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:13:53 2009 for CMSSW by  doxygen 1.5.4