Call adjustSize before showing the timeline widget

This commit is contained in:
Konstantinos Sideris 2018-08-28 00:19:39 +03:00
parent 7e16730692
commit db9c37d336
4 changed files with 34 additions and 26 deletions

View file

@ -37,6 +37,32 @@
constexpr int MSG_RIGHT_MARGIN = 7;
constexpr int MSG_PADDING = 20;
TextLabel::TextLabel(const QString &text, QWidget *parent)
: QTextBrowser(parent)
{
setText(text);
setOpenExternalLinks(true);
// Make it look and feel like an ordinary label.
setReadOnly(true);
setFrameStyle(QFrame::NoFrame);
QPalette pal = palette();
pal.setColor(QPalette::Base, Qt::transparent);
setPalette(pal);
// Wrap anywhere but prefer words, adjust minimum height on the fly.
setLineWrapMode(QTextEdit::WidgetWidth);
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
connect(document()->documentLayout(),
&QAbstractTextDocumentLayout::documentSizeChanged,
this,
&TextLabel::adjustHeight);
document()->setDocumentMargin(0);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setFixedHeight(0);
}
StatusIndicator::StatusIndicator(QWidget *parent)
: QWidget(parent)
{

View file

@ -93,30 +93,7 @@ class TextLabel : public QTextBrowser
Q_OBJECT
public:
TextLabel(const QString &text, QWidget *parent = 0)
: QTextBrowser(parent)
{
setText(text);
setOpenExternalLinks(true);
// Make it look and feel like an ordinary label.
setReadOnly(true);
setFrameStyle(QFrame::NoFrame);
QPalette pal = palette();
pal.setColor(QPalette::Base, Qt::transparent);
setPalette(pal);
// Wrap anywhere but prefer words, adjust minimum height on the fly.
setLineWrapMode(QTextEdit::WidgetWidth);
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
connect(document()->documentLayout(),
&QAbstractTextDocumentLayout::documentSizeChanged,
this,
&TextLabel::adjustHeight);
document()->setDocumentMargin(0);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
TextLabel(const QString &text, QWidget *parent = nullptr);
void wheelEvent(QWheelEvent *event) override { event->ignore(); }

View file

@ -626,7 +626,7 @@ TimelineView::addTimelineItem(QWidget *item, TimelineDirection direction)
auto separator = new DateSeparator(newDate, this);
if (separator)
scroll_layout_->addWidget(separator);
pushTimelineItem(separator);
}
}

View file

@ -194,9 +194,14 @@ private:
//! of the timeline.
void pushTimelineItem(QWidget *item)
{
setUpdatesEnabled(false);
item->hide();
scroll_layout_->addWidget(item);
QTimer::singleShot(0, this, [item]() { item->show(); });
QTimer::singleShot(0, this, [item, this]() {
item->show();
item->adjustSize();
setUpdatesEnabled(true);
});
};
//! Decides whether or not to show or hide the scroll down button.