mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
margins, update selection rect during resize
This commit is contained in:
parent
2b20a23c3d
commit
0f2a339a98
|
@ -123,14 +123,14 @@ void ChatLog::clearSelection()
|
|||
for(int i=selFirstRow; i<=selLastRow && i<lines.size() && i >= 0; ++i)
|
||||
lines[i]->selectionCleared();
|
||||
|
||||
selGraphItem->hide();
|
||||
|
||||
selFirstRow = -1;
|
||||
selLastRow = -1;
|
||||
selClickedCol = -1;
|
||||
selClickedRow = -1;
|
||||
|
||||
selectionMode = None;
|
||||
|
||||
updateMultiSelectionRect();
|
||||
}
|
||||
|
||||
QRect ChatLog::getVisibleRect() const
|
||||
|
@ -140,7 +140,7 @@ QRect ChatLog::getVisibleRect() const
|
|||
|
||||
void ChatLog::updateSceneRect()
|
||||
{
|
||||
setSceneRect(QRectF(0, 0, width(), lines.empty() ? 0.0 : lines.last()->boundingSceneRect().bottom()));
|
||||
setSceneRect(QRectF(-margins.left(), -margins.top(), useableWidth(), (lines.empty() ? 0.0 : lines.last()->boundingSceneRect().bottom()) + margins.bottom() + margins.top()));
|
||||
}
|
||||
|
||||
bool ChatLog::layout(int start, int end, qreal width)
|
||||
|
@ -160,7 +160,7 @@ bool ChatLog::layout(int start, int end, qreal width)
|
|||
ChatLine* l = lines[i];
|
||||
|
||||
qreal oldHeight = l->boundingSceneRect().height();
|
||||
l->layout(width, QPointF(0, h));
|
||||
l->layout(width, QPointF(0.0, h));
|
||||
|
||||
if(oldHeight != l->boundingSceneRect().height())
|
||||
needsReposition = true;
|
||||
|
@ -299,12 +299,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
|||
|
||||
lines[selClickedRow]->selectionCleared();
|
||||
|
||||
QRectF selBBox;
|
||||
selBBox = selBBox.united(lines[selFirstRow]->boundingSceneRect());
|
||||
selBBox = selBBox.united(lines[selLastRow]->boundingSceneRect());
|
||||
|
||||
selGraphItem->setRect(selBBox);
|
||||
selGraphItem->show();
|
||||
updateMultiSelectionRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -338,9 +333,9 @@ bool ChatLog::isOverSelection(QPointF scenePos)
|
|||
return false;
|
||||
}
|
||||
|
||||
int ChatLog::useableWidth()
|
||||
qreal ChatLog::useableWidth()
|
||||
{
|
||||
return width() - verticalScrollBar()->sizeHint().width() - 10.0;
|
||||
return width() - verticalScrollBar()->sizeHint().width() - margins.right() - margins.left();
|
||||
}
|
||||
|
||||
void ChatLog::reposition(int start, int end)
|
||||
|
@ -550,4 +545,23 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
|
|||
|
||||
if(stb)
|
||||
scrollToBottom();
|
||||
|
||||
updateMultiSelectionRect();
|
||||
}
|
||||
|
||||
void ChatLog::updateMultiSelectionRect()
|
||||
{
|
||||
if(selectionMode == Multi && selFirstRow >= 0 && selLastRow >= 0)
|
||||
{
|
||||
QRectF selBBox;
|
||||
selBBox = selBBox.united(lines[selFirstRow]->boundingSceneRect());
|
||||
selBBox = selBBox.united(lines[selLastRow]->boundingSceneRect());
|
||||
|
||||
selGraphItem->setRect(selBBox);
|
||||
selGraphItem->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
selGraphItem->hide();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <QGraphicsView>
|
||||
#include <QDateTime>
|
||||
#include <QMarginsF>
|
||||
|
||||
class QGraphicsScene;
|
||||
class QGraphicsRectItem;
|
||||
|
@ -55,7 +56,7 @@ protected:
|
|||
bool isOverSelection(QPointF scenePos);
|
||||
bool stickToBottom();
|
||||
|
||||
int useableWidth();
|
||||
qreal useableWidth();
|
||||
|
||||
void reposition(int start, int end);
|
||||
void repositionDownTo(int start, qreal end);
|
||||
|
@ -72,6 +73,8 @@ protected:
|
|||
virtual void scrollContentsBy(int dx, int dy);
|
||||
virtual void resizeEvent(QResizeEvent *ev);
|
||||
|
||||
void updateMultiSelectionRect();
|
||||
|
||||
private:
|
||||
enum SelectionMode {
|
||||
None,
|
||||
|
@ -101,6 +104,7 @@ private:
|
|||
QAction* copyAction = nullptr;
|
||||
|
||||
// layout
|
||||
QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0);
|
||||
qreal lineSpacing = 10.0f;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user