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_RIGHT_MARGIN = 7;
constexpr int MSG_PADDING = 20; 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) StatusIndicator::StatusIndicator(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {

View File

@ -93,30 +93,7 @@ class TextLabel : public QTextBrowser
Q_OBJECT Q_OBJECT
public: public:
TextLabel(const QString &text, QWidget *parent = 0) TextLabel(const QString &text, QWidget *parent = nullptr);
: 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);
}
void wheelEvent(QWheelEvent *event) override { event->ignore(); } 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); auto separator = new DateSeparator(newDate, this);
if (separator) if (separator)
scroll_layout_->addWidget(separator); pushTimelineItem(separator);
} }
} }

View File

@ -194,9 +194,14 @@ private:
//! of the timeline. //! of the timeline.
void pushTimelineItem(QWidget *item) void pushTimelineItem(QWidget *item)
{ {
setUpdatesEnabled(false);
item->hide(); item->hide();
scroll_layout_->addWidget(item); 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. //! Decides whether or not to show or hide the scroll down button.