scrollbar values based on messages
This commit is contained in:
@@ -61,7 +61,7 @@ ChatWidget::setChannelName(const QString &name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->view.layoutMessages();
|
this->view.layoutMessages();
|
||||||
this->view.repaint();
|
this->view.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
auto originalLocation = page->removeFromLayout(chatWidget);
|
auto originalLocation = page->removeFromLayout(chatWidget);
|
||||||
|
|
||||||
// page->repaint();
|
// page->update();
|
||||||
|
|
||||||
QDrag *drag = new QDrag(chatWidget);
|
QDrag *drag = new QDrag(chatWidget);
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event)
|
|||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
this->mouseDown = true;
|
this->mouseDown = true;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
this->mouseDown = false;
|
this->mouseDown = false;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
|
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ ChatWidgetHeaderButton::enterEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
this->mouseOver = true;
|
this->mouseOver = true;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -82,7 +82,7 @@ ChatWidgetHeaderButton::leaveEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
this->mouseOver = false;
|
this->mouseOver = false;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -90,7 +90,7 @@ ChatWidgetHeaderButton::labelMouseUp()
|
|||||||
{
|
{
|
||||||
this->mouseDown = false;
|
this->mouseDown = false;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
|
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ ChatWidgetHeaderButton::labelMouseDown()
|
|||||||
{
|
{
|
||||||
this->mouseDown = true;
|
this->mouseDown = true;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-13
@@ -23,7 +23,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
|||||||
QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged,
|
QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged,
|
||||||
this, &ChatWidgetView::wordTypeMaskChanged);
|
this, &ChatWidgetView::wordTypeMaskChanged);
|
||||||
|
|
||||||
this->scrollbar.getValueChanged().connect([this] { repaint(); });
|
this->scrollbar.getValueChanged().connect([this] { update(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatWidgetView::~ChatWidgetView()
|
ChatWidgetView::~ChatWidgetView()
|
||||||
@@ -38,8 +38,13 @@ ChatWidgetView::layoutMessages()
|
|||||||
{
|
{
|
||||||
auto c = this->chatWidget->getChannel();
|
auto c = this->chatWidget->getChannel();
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL) {
|
||||||
|
this->scrollbar.hide();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool showScrollbar = false;
|
||||||
|
|
||||||
auto messages = c->getMessagesClone();
|
auto messages = c->getMessagesClone();
|
||||||
|
|
||||||
@@ -49,23 +54,29 @@ ChatWidgetView::layoutMessages()
|
|||||||
redraw |= message.get()->layout(this->width(), true);
|
redraw |= message.get()->layout(this->width(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateScrollbar();
|
int h = this->height();
|
||||||
|
|
||||||
return redraw;
|
for (int i = messages.size() - 1; i >= 0; i--) {
|
||||||
}
|
auto *message = messages[i].get();
|
||||||
|
|
||||||
void
|
message->layout(this->width(), true);
|
||||||
ChatWidgetView::updateScrollbar()
|
|
||||||
{
|
|
||||||
auto c = this->chatWidget->getChannel();
|
|
||||||
|
|
||||||
if (c == NULL) {
|
h -= message->getHeight();
|
||||||
return;
|
|
||||||
|
if (h < 0) {
|
||||||
|
this->scrollbar.setLargeChange((messages.length() - i) +
|
||||||
|
(qreal)h / message->getHeight());
|
||||||
|
this->scrollbar.setValue(this->scrollbar.getValue());
|
||||||
|
|
||||||
|
showScrollbar = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this->scrollbar.setValue(0);
|
this->scrollbar.setVisible(showScrollbar);
|
||||||
this->scrollbar.setLargeChange(10);
|
|
||||||
this->scrollbar.setMaximum(c->getMessages().size());
|
this->scrollbar.setMaximum(c->getMessages().size());
|
||||||
|
|
||||||
|
return redraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -161,6 +172,8 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
|||||||
else {
|
else {
|
||||||
QColor color = wordPart.getWord().getColor();
|
QColor color = wordPart.getWord().getColor();
|
||||||
|
|
||||||
|
ColorScheme::getInstance().normalizeColor(color);
|
||||||
|
|
||||||
painter.setPen(color);
|
painter.setPen(color);
|
||||||
painter.setFont(wordPart.getWord().getFont());
|
painter.setFont(wordPart.getWord().getFont());
|
||||||
|
|
||||||
|
|||||||
@@ -24,16 +24,12 @@ public:
|
|||||||
|
|
||||||
bool layoutMessages();
|
bool layoutMessages();
|
||||||
|
|
||||||
void updateScrollbar();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void wheelEvent(QWheelEvent *event);
|
void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
void scroll(int dx, int dy);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChatWidget *chatWidget;
|
ChatWidget *chatWidget;
|
||||||
|
|
||||||
@@ -44,7 +40,7 @@ private slots:
|
|||||||
wordTypeMaskChanged()
|
wordTypeMaskChanged()
|
||||||
{
|
{
|
||||||
if (layoutMessages()) {
|
if (layoutMessages()) {
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ MainWindow::layoutVisibleChatWidgets(Channel *channel)
|
|||||||
|
|
||||||
if (channel == NULL || channel == widget->getChannel()) {
|
if (channel == NULL || channel == widget->getChannel()) {
|
||||||
if (widget->getView().layoutMessages()) {
|
if (widget->getView().layoutMessages()) {
|
||||||
widget->repaint();
|
widget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ MainWindow::repaintVisibleChatWidgets(Channel *channel)
|
|||||||
|
|
||||||
if (channel == NULL || channel == widget->getChannel()) {
|
if (channel == NULL || channel == widget->getChannel()) {
|
||||||
widget->getView().layoutMessages();
|
widget->getView().layoutMessages();
|
||||||
widget->repaint();
|
widget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ NotebookButton::mousePressEvent(QMouseEvent *event)
|
|||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
mouseDown = true;
|
mouseDown = true;
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ NotebookButton::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
|
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ NotebookButton::enterEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
mouseOver = true;
|
mouseOver = true;
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -122,7 +122,7 @@ NotebookButton::leaveEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
mouseOver = false;
|
mouseOver = false;
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ NotebookTab::mousePressEvent(QMouseEvent *event)
|
|||||||
this->mouseDown = true;
|
this->mouseDown = true;
|
||||||
this->mouseDownX = this->getXRect().contains(event->pos());
|
this->mouseDownX = this->getXRect().contains(event->pos());
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
|
|
||||||
this->notebook->select(page);
|
this->notebook->select(page);
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
this->notebook->removePage(this->page);
|
this->notebook->removePage(this->page);
|
||||||
} else {
|
} else {
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ NotebookTab::enterEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
this->mouseOver = true;
|
this->mouseOver = true;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -172,7 +172,7 @@ NotebookTab::leaveEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
this->mouseOverX = this->mouseOver = false;
|
this->mouseOverX = this->mouseOver = false;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -189,7 +189,7 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event)
|
|||||||
if (overX != this->mouseOverX) {
|
if (overX != this->mouseOverX) {
|
||||||
this->mouseOverX = overX;
|
this->mouseOverX = overX;
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) {
|
if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
setSelected(bool value)
|
setSelected(bool value)
|
||||||
{
|
{
|
||||||
this->selected = value;
|
this->selected = value;
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
HighlightStyle
|
HighlightStyle
|
||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
setHighlightStyle(HighlightStyle style)
|
setHighlightStyle(HighlightStyle style)
|
||||||
{
|
{
|
||||||
this->highlightStyle = style;
|
this->highlightStyle = style;
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveAnimated(QPoint pos, bool animated = true);
|
void moveAnimated(QPoint pos, bool animated = true);
|
||||||
@@ -115,7 +115,7 @@ private slots:
|
|||||||
hideTabXChanged(bool)
|
hideTabXChanged(bool)
|
||||||
{
|
{
|
||||||
calcSize();
|
calcSize();
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ ScrollBar::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldIndex != this->mouseOverIndex) {
|
if (oldIndex != this->mouseOverIndex) {
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
} else if (this->mouseDownIndex == 2) {
|
} else if (this->mouseDownIndex == 2) {
|
||||||
int delta = event->pos().y() - lastMousePosition.y();
|
int delta = event->pos().y() - lastMousePosition.y();
|
||||||
@@ -191,7 +191,7 @@ ScrollBar::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->mouseDownIndex = -1;
|
this->mouseDownIndex = -1;
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -199,7 +199,7 @@ ScrollBar::leaveEvent(QEvent *)
|
|||||||
{
|
{
|
||||||
this->mouseOverIndex = -1;
|
this->mouseOverIndex = -1;
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -216,7 +216,7 @@ ScrollBar::updateScroll()
|
|||||||
(int)(this->largeChange / this->maximum * this->trackHeight) +
|
(int)(this->largeChange / this->maximum * this->trackHeight) +
|
||||||
MIN_THUMB_HEIGHT);
|
MIN_THUMB_HEIGHT);
|
||||||
|
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ public:
|
|||||||
this->updateScroll();
|
this->updateScroll();
|
||||||
this->valueChanged();
|
this->valueChanged();
|
||||||
|
|
||||||
this->repaint();
|
this->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user