HGGitLab

Commit 8256a0f4 authored by luoliangyi's avatar luoliangyi

处理拖入文件自动滚动功能

parent 68251015
......@@ -2615,8 +2615,12 @@ void HGImgThumb::dragMoveEvent(QDragMoveEvent *e)
qDebug("dragMoveEvent");
m_dragInsertPos = getInsertPos(e->pos());
locateInsert(m_dragInsertPos);
recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect);
if (-1 != m_dragInsertPos)
{
locateInsert(m_dragInsertPos);
recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect);
}
Show();
}
......@@ -2635,6 +2639,8 @@ void HGImgThumb::dropEvent(QDropEvent *e)
m_dragInsertPos = -1;
m_draging = false;
bool emitItemCount = false;
bool emitItemChange = false;
int insertPos = getInsertPos(e->pos());
QList<QUrl> urls = e->mimeData()->urls();
......@@ -2667,16 +2673,15 @@ void HGImgThumb::dropEvent(QDropEvent *e)
if (pos > insertPos)
{
bool emitItemChange = false;
if (-1 != m_curItemIndex && m_curItemIndex >= insertPos)
{
m_curItemIndex = pos;
m_curItemIndex += (pos - insertPos);
emitItemChange = true;
}
if (-1 != m_signItemIndex && m_signItemIndex >= insertPos)
{
m_signItemIndex = pos;
m_signItemIndex += (pos - insertPos);
}
int showWidth = 0, showHeight = 0;
......@@ -2689,15 +2694,20 @@ void HGImgThumb::dropEvent(QDropEvent *e)
locateItem(pos - 1);
recalcShowRect(this->width(), this->height(), m_scrollSize, m_type, m_hScroll, m_vScroll, m_showThumb, m_thumbRect);
m_hotItemIndex = getItem(mapFromGlobal(QCursor::pos()), m_mouseMoveStatus);
Show();
emit itemCountChanged(m_frontItems.size());
if (emitItemChange)
{
emit currItemChanged(m_curItemIndex);
}
emitItemCount = true;
}
}
m_hotItemIndex = getItem(mapFromGlobal(QCursor::pos()), m_mouseMoveStatus);
Show();
if (emitItemCount)
{
emit itemCountChanged(m_frontItems.size());
}
if (emitItemChange)
{
emit currItemChanged(m_curItemIndex);
}
}
void HGImgThumb::on_updateItem()
......@@ -3105,59 +3115,63 @@ void HGImgThumb::locateItem(int index)
if (m_vScroll)
{
if (left < m_gapSize && right + (m_gapSize - left) <= (this->width() - m_scrollSize))
int gap = m_gapSize;
if (left < gap && right + (gap - left) <= (this->width() - m_scrollSize))
{
m_thumbRect.left += (m_gapSize - left);
m_thumbRect.right += (m_gapSize - left);
m_thumbRect.left += (gap - left);
m_thumbRect.right += (gap - left);
}
else if (right + m_gapSize > (this->width() - m_scrollSize)
&& left - (right + m_gapSize - this->width() + m_scrollSize) >= m_gapSize)
else if (right > (this->width() - m_scrollSize - gap)
&& left - (right - this->width() + m_scrollSize + gap) >= 0)
{
m_thumbRect.left -= (right + m_gapSize - this->width() + m_scrollSize);
m_thumbRect.right -= (right + m_gapSize - this->width() + m_scrollSize);
m_thumbRect.left -= (right - this->width() + m_scrollSize + gap);
m_thumbRect.right -= (right - this->width() + m_scrollSize + gap);
}
}
else
{
if (left < m_gapSize && right + (m_gapSize - left) <= this->width())
int gap = m_gapSize;
if (left < gap && right + (gap - left) <= this->width())
{
m_thumbRect.left += (m_gapSize - left);
m_thumbRect.right += (m_gapSize - left);
m_thumbRect.left += (gap - left);
m_thumbRect.right += (gap - left);
}
else if (right + m_gapSize > this->width()
&& left - (right + m_gapSize - this->width()) >= m_gapSize)
else if (right > (this->width() - gap)
&& left - (right - this->width() + gap) >= 0)
{
m_thumbRect.left -= (right + m_gapSize - this->width());
m_thumbRect.right -= (right + m_gapSize - this->width());
m_thumbRect.left -= (right - this->width() + gap);
m_thumbRect.right -= (right - this->width() + gap);
}
}
if (m_hScroll)
{
if (top < m_gapSize && bottom + (m_gapSize - top) <= (this->height() - m_scrollSize))
int gap = m_gapSize;
if (top < gap && bottom + (gap - top) <= (this->height() - m_scrollSize))
{
m_thumbRect.top += (m_gapSize - top);
m_thumbRect.bottom += (m_gapSize - top);
m_thumbRect.top += (gap - top);
m_thumbRect.bottom += (gap - top);
}
else if (bottom + m_gapSize > (this->height() - m_scrollSize)
&& top - (bottom + m_gapSize - this->height() + m_scrollSize) >= m_gapSize)
else if (bottom > (this->height() - m_scrollSize - gap)
&& top - (bottom - this->height() + m_scrollSize + gap) >= 0)
{
m_thumbRect.top -= (bottom + m_gapSize - this->height() + m_scrollSize);
m_thumbRect.bottom -= (bottom + m_gapSize - this->height() + m_scrollSize);
m_thumbRect.top -= (bottom - this->height() + m_scrollSize + gap);
m_thumbRect.bottom -= (bottom - this->height() + m_scrollSize + gap);
}
}
else
{
if (top < m_gapSize && bottom + (m_gapSize - top) <= this->height())
int gap = m_gapSize;
if (top < gap && bottom + (gap - top) <= this->height())
{
m_thumbRect.top += (m_gapSize - top);
m_thumbRect.bottom += (m_gapSize - top);
m_thumbRect.top += (gap - top);
m_thumbRect.bottom += (gap - top);
}
else if (bottom + m_gapSize > this->height()
&& top - (bottom + m_gapSize - this->height()) >= m_gapSize)
else if (bottom > (this->height() - gap)
&& top - (bottom - this->height() + gap) >= 0)
{
m_thumbRect.top -= (bottom + m_gapSize - this->height());
m_thumbRect.bottom -= (bottom + m_gapSize - this->height());
m_thumbRect.top -= (bottom - this->height() + gap);
m_thumbRect.bottom -= (bottom - this->height() + gap);
}
}
}
......@@ -3206,59 +3220,63 @@ void HGImgThumb::locateInsert(int pos)
if (m_vScroll)
{
if (left < m_gapSize && right + (m_gapSize - left) <= (this->width() - m_scrollSize))
int gap = m_gapSize + m_itemSize;
if (left < gap && right + (gap - left) <= (this->width() - m_scrollSize))
{
m_thumbRect.left += (m_gapSize - left);
m_thumbRect.right += (m_gapSize - left);
m_thumbRect.left += (gap - left);
m_thumbRect.right += (gap - left);
}
else if (right + m_gapSize > (this->width() - m_scrollSize)
&& left - (right + m_gapSize - this->width() + m_scrollSize) >= m_gapSize)
else if (right > (this->width() - m_scrollSize - gap)
&& left - (right - this->width() + m_scrollSize + gap) >= 0)
{
m_thumbRect.left -= (right + m_gapSize - this->width() + m_scrollSize);
m_thumbRect.right -= (right + m_gapSize - this->width() + m_scrollSize);
m_thumbRect.left -= (right - this->width() + m_scrollSize + gap);
m_thumbRect.right -= (right - this->width() + m_scrollSize + gap);
}
}
else
{
if (left < m_gapSize && right + (m_gapSize - left) <= this->width())
int gap = m_gapSize + m_itemSize;
if (left < gap && right + (gap - left) <= this->width())
{
m_thumbRect.left += (m_gapSize - left);
m_thumbRect.right += (m_gapSize - left);
m_thumbRect.left += (gap - left);
m_thumbRect.right += (gap - left);
}
else if (right + m_gapSize > this->width()
&& left - (right + m_gapSize - this->width()) >= m_gapSize)
else if (right > (this->width() - gap)
&& left - (right - this->width() + gap) >= 0)
{
m_thumbRect.left -= (right + m_gapSize - this->width());
m_thumbRect.right -= (right + m_gapSize - this->width());
m_thumbRect.left -= (right - this->width() + gap);
m_thumbRect.right -= (right - this->width() + gap);
}
}
if (m_hScroll)
{
if (top < m_gapSize && bottom + (m_gapSize - top) <= (this->height() - m_scrollSize))
int gap = m_gapSize + (m_itemSize + m_itemTextHeight);
if (top < gap && bottom + (gap - top) <= (this->height() - m_scrollSize))
{
m_thumbRect.top += (m_gapSize - top);
m_thumbRect.bottom += (m_gapSize - top);
m_thumbRect.top += (gap - top);
m_thumbRect.bottom += (gap - top);
}
else if (bottom + m_gapSize > (this->height() - m_scrollSize)
&& top - (bottom + m_gapSize - this->height() + m_scrollSize) >= m_gapSize)
else if (bottom > (this->height() - m_scrollSize - gap)
&& top - (bottom - this->height() + m_scrollSize + gap) >= 0)
{
m_thumbRect.top -= (bottom + m_gapSize - this->height() + m_scrollSize);
m_thumbRect.bottom -= (bottom + m_gapSize - this->height() + m_scrollSize);
m_thumbRect.top -= (bottom - this->height() + m_scrollSize + gap);
m_thumbRect.bottom -= (bottom - this->height() + m_scrollSize + gap);
}
}
else
{
if (top < m_gapSize && bottom + (m_gapSize - top) <= this->height())
int gap = m_gapSize + (m_itemSize + m_itemTextHeight);
if (top < gap && bottom + (gap - top) <= this->height())
{
m_thumbRect.top += (m_gapSize - top);
m_thumbRect.bottom += (m_gapSize - top);
m_thumbRect.top += (gap - top);
m_thumbRect.bottom += (gap - top);
}
else if (bottom + m_gapSize > this->height()
&& top - (bottom + m_gapSize - this->height()) >= m_gapSize)
else if (bottom > (this->height() - gap)
&& top - (bottom - this->height() + gap) >= 0)
{
m_thumbRect.top -= (bottom + m_gapSize - this->height());
m_thumbRect.bottom -= (bottom + m_gapSize - this->height());
m_thumbRect.top -= (bottom - this->height() + gap);
m_thumbRect.bottom -= (bottom - this->height() + gap);
}
}
}
......@@ -3319,21 +3337,9 @@ void HGImgThumb::getInsertLoc(int pos, QPoint &pt1, QPoint &pt2)
}
else
{
int cols = getTotalCols();
if (cols > 1)
{
x1 = x2 = pt.x() - m_gapSize / 2;
y1 = pt.y();
y2 = y1 + m_itemSize + m_itemTextHeight;
}
else
{
assert(1 == cols);
y1 = y2 = pt.y() - m_gapSize / 2;
x1 = pt.x();
x2 = x1 + m_itemSize;
}
x1 = x2 = pt.x() - m_gapSize / 2;
y1 = pt.y();
y2 = y1 + m_itemSize + m_itemTextHeight;
}
}
else
......@@ -3355,21 +3361,9 @@ void HGImgThumb::getInsertLoc(int pos, QPoint &pt1, QPoint &pt2)
}
else
{
int cols = getTotalCols();
if (cols > 1)
{
x1 = x2 = pt.x() + m_itemSize + m_gapSize / 2;
y1 = pt.y();
y2 = y1 + m_itemSize + m_itemTextHeight;
}
else
{
assert(1 == cols);
y1 = y2 = pt.y() + m_itemSize + m_itemTextHeight + m_gapSize / 2;
x1 = pt.x();
x2 = x1 + m_itemSize;
}
x1 = x2 = pt.x() + m_itemSize + m_gapSize / 2;
y1 = pt.y();
y2 = y1 + m_itemSize + m_itemTextHeight;
}
}
......@@ -3475,6 +3469,35 @@ int HGImgThumb::getTotalCols()
return cols;
}
int HGImgThumb::getRowCount(int row)
{
assert(row >= 0 && row < getTotalRows());
int count;
if (ThumbType_Hori == m_type)
{
count = m_frontItems.size();
}
else if (ThumbType_Vert == m_type)
{
count = 1;
}
else
{
int cols = round((m_thumbRect.right - m_thumbRect.left - m_gapSize) / (m_itemSize + m_gapSize));
if ((row + 1) * cols <= (int)m_frontItems.size())
{
count = cols;
}
else
{
count = (int)m_frontItems.size() - row * cols;
}
}
return count;
}
int HGImgThumb::getItem(const QPoint &pt, MouseStatus &mouseStatus)
{
mouseStatus = MouseStatus_Null;
......@@ -3559,6 +3582,56 @@ int HGImgThumb::getItem(const QPoint &pt, MouseStatus &mouseStatus)
int HGImgThumb::getInsertPos(const QPoint &pt)
{
MouseStatus mouseStatus = MouseStatus_Null;
if (m_hScroll && m_vScroll)
{
if (getHScrollSliderPos().contains(pt))
mouseStatus = MouseStatus_HScrollSlider;
else if (getHScrollPos().contains(pt))
mouseStatus = MouseStatus_HScroll;
else if (getHScrollLeftPos().contains(pt))
mouseStatus = MouseStatus_HScrollLeft;
else if (getHScrollRightPos().contains(pt))
mouseStatus = MouseStatus_HScrollRight;
else if (getVScrollSliderPos().contains(pt))
mouseStatus = MouseStatus_VScrollSlider;
else if (getVScrollPos().contains(pt))
mouseStatus = MouseStatus_VScroll;
else if (getVScrollTopPos().contains(pt))
mouseStatus = MouseStatus_VScrollTop;
else if (getVScrollBottomPos().contains(pt))
mouseStatus = MouseStatus_VScrollBottom;
else if (getNullScrollPos().contains(pt))
mouseStatus = MouseStatus_NullScroll;
}
else if (m_hScroll && !m_vScroll)
{
if (getHScrollSliderPos().contains(pt))
mouseStatus = MouseStatus_HScrollSlider;
else if (getHScrollPos().contains(pt))
mouseStatus = MouseStatus_HScroll;
else if (getHScrollLeftPos().contains(pt))
mouseStatus = MouseStatus_HScrollLeft;
else if (getHScrollRightPos().contains(pt))
mouseStatus = MouseStatus_HScrollRight;
}
else if (!m_hScroll && m_vScroll)
{
if (getVScrollSliderPos().contains(pt))
mouseStatus = MouseStatus_VScrollSlider;
else if (getVScrollPos().contains(pt))
mouseStatus = MouseStatus_VScroll;
else if (getVScrollTopPos().contains(pt))
mouseStatus = MouseStatus_VScrollTop;
else if (getVScrollBottomPos().contains(pt))
mouseStatus = MouseStatus_VScrollBottom;
}
if (MouseStatus_Null != mouseStatus)
{
return -1;
}
if (!m_showThumb)
{
assert(0 == m_frontItems.size());
......@@ -3600,52 +3673,39 @@ int HGImgThumb::getInsertPos(const QPoint &pt)
}
else
{
int rows = getTotalRows();
int cols = getTotalCols();
if (cols > 1)
{
pos = (int)m_frontItems.size();
for (int i = 0; i < (int)m_frontItems.size(); ++i)
{
QPoint pt2 = getItemLoc(i);
int left = pt2.x();
int top = pt2.y();
int right = left + m_itemSize;
int bottom = top + m_itemSize + m_itemTextHeight;
int row = getItemRow(i);
int col = getItemCol(i);
if (0 == col && 0 != row)
{
if (pt.y() < top - m_gapSize)
{
pos = i;
break;
}
}
int row = rows;
for (int i = 0; i < rows; ++i)
{
QPoint pt2 = getItemLoc(cols * i);
if (pt.x() < right && pt.y() < bottom)
{
pos = i;
break;
}
int top = pt2.y();
int bottom = top + m_itemSize + m_itemTextHeight;
if (pt.y() < bottom + m_gapSize / 2)
{
row = i;
break;
}
}
else
{
assert(1 == cols);
if (row == rows)
{
pos = (int)m_frontItems.size();
for (int i = 0; i < (int)m_frontItems.size(); ++i)
}
else
{
pos = row * cols + getRowCount(row);
for (int i = 0; i < getRowCount(row); ++i)
{
QPoint pt2 = getItemLoc(i);
QPoint pt2 = getItemLoc(row * cols + i);
int top = pt2.y();
int bottom = top + m_itemSize + m_itemTextHeight;
if (pt.y() < (top + bottom) / 2)
int left = pt2.x();
int right = left + m_itemSize;
if (pt.x() < (left + right) / 2)
{
pos = i;
pos = row * cols + i;
break;
}
}
......
......@@ -161,6 +161,7 @@ private:
int getItemCol(int index);
int getTotalRows();
int getTotalCols();
int getRowCount(int row); // 获取每行的个数
int getItem(const QPoint &pt, MouseStatus &mouseStatus);
int getInsertPos(const QPoint &pt);
int findIndex(const QString &fileName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment