constructor ...

Qt Code:
  1. // Thumbnail View Constructor ..
  2. RoboThumbnailView::RoboThumbnailView(QWidget * parent) : QScrollArea(parent)
  3. {
  4. m_bDragging = false;
  5. m_wgtViewport = new QWidget();
  6. m_grdLayout = new QGridLayout();
  7. m_grdLayout->setSpacing(5);
  8. m_wgtViewport->setLayout(m_grdLayout);
  9. setWidget(m_wgtViewport);
  10. }
To copy to clipboard, switch view to plain text mode 

mousePressEvent :

Qt Code:
  1. void RoboThumbnailView::mousePressEvent(QMouseEvent *e)
  2. {
  3. RoboThumbnailClickable * thumb = thumbAt(e->pos());
  4. if (thumb)
  5. {
  6. if (e->button() == Qt::RightButton)
  7. {
  8. // do context menu.
  9. }
  10. else if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
  11. {
  12. m_bDragging = true;
  13. if (e->modifiers() & Qt::ControlModifier)
  14. {
  15. thumb->toggleSelected();
  16. }
  17. else
  18. {
  19. for (int i = 0; i < m_grdLayout->count(); i++)
  20. {
  21. QLayoutItem * child = m_grdLayout->itemAt(i);
  22. static_cast<RoboThumbnailClickable *>(child->widget())->setSelected(false);
  23. }
  24. thumb->setSelected(true);
  25. }
  26. }
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

thumbAt function that doesn't work ...

Qt Code:
  1. RoboThumbnailClickable * RoboThumbnailView::thumbAt(const QPoint & pos)
  2. {
  3. for (int i = 0; i < m_grdLayout->count(); i++)
  4. {
  5. QLayoutItem *layoutItem = m_grdLayout->itemAt(i);
  6. if (layoutItem->geometry().contains(pos()))
  7. {
  8. return static_cast<RoboThumbnailClickable *>(layoutItem->widget());
  9. }
  10. }
  11.  
  12. return NULL;
  13.  
  14. }
To copy to clipboard, switch view to plain text mode 

thanks