constructor ...
// Thumbnail View Constructor ..
{
m_bDragging = false;
m_grdLayout->setSpacing(5);
m_wgtViewport->setLayout(m_grdLayout);
setWidget(m_wgtViewport);
}
// Thumbnail View Constructor ..
RoboThumbnailView::RoboThumbnailView(QWidget * parent) : QScrollArea(parent)
{
m_bDragging = false;
m_wgtViewport = new QWidget();
m_grdLayout = new QGridLayout();
m_grdLayout->setSpacing(5);
m_wgtViewport->setLayout(m_grdLayout);
setWidget(m_wgtViewport);
}
To copy to clipboard, switch view to plain text mode
mousePressEvent :
void RoboThumbnailView
::mousePressEvent(QMouseEvent *e
) {
RoboThumbnailClickable * thumb = thumbAt(e->pos());
if (thumb)
{
if (e->button() == Qt::RightButton)
{
// do context menu.
}
else if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
{
m_bDragging = true;
if (e->modifiers() & Qt::ControlModifier)
{
thumb->toggleSelected();
}
else
{
for (int i = 0; i < m_grdLayout->count(); i++)
{
static_cast<RoboThumbnailClickable *>(child->widget())->setSelected(false);
}
thumb->setSelected(true);
}
}
}
}
void RoboThumbnailView::mousePressEvent(QMouseEvent *e)
{
RoboThumbnailClickable * thumb = thumbAt(e->pos());
if (thumb)
{
if (e->button() == Qt::RightButton)
{
// do context menu.
}
else if (e->button() == Qt::LeftButton || e->button() == Qt::MidButton)
{
m_bDragging = true;
if (e->modifiers() & Qt::ControlModifier)
{
thumb->toggleSelected();
}
else
{
for (int i = 0; i < m_grdLayout->count(); i++)
{
QLayoutItem * child = m_grdLayout->itemAt(i);
static_cast<RoboThumbnailClickable *>(child->widget())->setSelected(false);
}
thumb->setSelected(true);
}
}
}
}
To copy to clipboard, switch view to plain text mode
thumbAt function that doesn't work ...
RoboThumbnailClickable
* RoboThumbnailView
::thumbAt(const QPoint & pos
){
for (int i = 0; i < m_grdLayout->count(); i++)
{
if (layoutItem->geometry().contains(pos()))
{
return static_cast<RoboThumbnailClickable *>(layoutItem->widget());
}
}
return NULL;
}
RoboThumbnailClickable * RoboThumbnailView::thumbAt(const QPoint & pos)
{
for (int i = 0; i < m_grdLayout->count(); i++)
{
QLayoutItem *layoutItem = m_grdLayout->itemAt(i);
if (layoutItem->geometry().contains(pos()))
{
return static_cast<RoboThumbnailClickable *>(layoutItem->widget());
}
}
return NULL;
}
To copy to clipboard, switch view to plain text mode
thanks
Bookmarks