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)
|
for(int i=selFirstRow; i<=selLastRow && i<lines.size() && i >= 0; ++i)
|
||||||
lines[i]->selectionCleared();
|
lines[i]->selectionCleared();
|
||||||
|
|
||||||
selGraphItem->hide();
|
|
||||||
|
|
||||||
selFirstRow = -1;
|
selFirstRow = -1;
|
||||||
selLastRow = -1;
|
selLastRow = -1;
|
||||||
selClickedCol = -1;
|
selClickedCol = -1;
|
||||||
selClickedRow = -1;
|
selClickedRow = -1;
|
||||||
|
|
||||||
selectionMode = None;
|
selectionMode = None;
|
||||||
|
|
||||||
|
updateMultiSelectionRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect ChatLog::getVisibleRect() const
|
QRect ChatLog::getVisibleRect() const
|
||||||
|
@ -140,7 +140,7 @@ QRect ChatLog::getVisibleRect() const
|
||||||
|
|
||||||
void ChatLog::updateSceneRect()
|
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)
|
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];
|
ChatLine* l = lines[i];
|
||||||
|
|
||||||
qreal oldHeight = l->boundingSceneRect().height();
|
qreal oldHeight = l->boundingSceneRect().height();
|
||||||
l->layout(width, QPointF(0, h));
|
l->layout(width, QPointF(0.0, h));
|
||||||
|
|
||||||
if(oldHeight != l->boundingSceneRect().height())
|
if(oldHeight != l->boundingSceneRect().height())
|
||||||
needsReposition = true;
|
needsReposition = true;
|
||||||
|
@ -299,12 +299,7 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev)
|
||||||
|
|
||||||
lines[selClickedRow]->selectionCleared();
|
lines[selClickedRow]->selectionCleared();
|
||||||
|
|
||||||
QRectF selBBox;
|
updateMultiSelectionRect();
|
||||||
selBBox = selBBox.united(lines[selFirstRow]->boundingSceneRect());
|
|
||||||
selBBox = selBBox.united(lines[selLastRow]->boundingSceneRect());
|
|
||||||
|
|
||||||
selGraphItem->setRect(selBBox);
|
|
||||||
selGraphItem->show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -338,9 +333,9 @@ bool ChatLog::isOverSelection(QPointF scenePos)
|
||||||
return false;
|
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)
|
void ChatLog::reposition(int start, int end)
|
||||||
|
@ -550,4 +545,23 @@ void ChatLog::resizeEvent(QResizeEvent* ev)
|
||||||
|
|
||||||
if(stb)
|
if(stb)
|
||||||
scrollToBottom();
|
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 <QGraphicsView>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QMarginsF>
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class QGraphicsRectItem;
|
class QGraphicsRectItem;
|
||||||
|
@ -55,7 +56,7 @@ protected:
|
||||||
bool isOverSelection(QPointF scenePos);
|
bool isOverSelection(QPointF scenePos);
|
||||||
bool stickToBottom();
|
bool stickToBottom();
|
||||||
|
|
||||||
int useableWidth();
|
qreal useableWidth();
|
||||||
|
|
||||||
void reposition(int start, int end);
|
void reposition(int start, int end);
|
||||||
void repositionDownTo(int start, qreal end);
|
void repositionDownTo(int start, qreal end);
|
||||||
|
@ -72,6 +73,8 @@ protected:
|
||||||
virtual void scrollContentsBy(int dx, int dy);
|
virtual void scrollContentsBy(int dx, int dy);
|
||||||
virtual void resizeEvent(QResizeEvent *ev);
|
virtual void resizeEvent(QResizeEvent *ev);
|
||||||
|
|
||||||
|
void updateMultiSelectionRect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum SelectionMode {
|
enum SelectionMode {
|
||||||
None,
|
None,
|
||||||
|
@ -101,6 +104,7 @@ private:
|
||||||
QAction* copyAction = nullptr;
|
QAction* copyAction = nullptr;
|
||||||
|
|
||||||
// layout
|
// layout
|
||||||
|
QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0);
|
||||||
qreal lineSpacing = 10.0f;
|
qreal lineSpacing = 10.0f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user