diff options
Diffstat (limited to 'widgets/displaytext.cpp')
| -rw-r--r-- | widgets/displaytext.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/widgets/displaytext.cpp b/widgets/displaytext.cpp index 73df8af6..ca3372f4 100644 --- a/widgets/displaytext.cpp +++ b/widgets/displaytext.cpp @@ -12,6 +12,8 @@ #include <QAction> #include <QListIterator> #include <QRegularExpression> +#include <QScrollBar> +#include <QDebug> #include "Configuration.hpp" #include "LotWUsers.hpp" @@ -25,6 +27,8 @@ DisplayText::DisplayText(QWidget *parent) : QTextEdit(parent) , m_config {nullptr} , erase_action_ {new QAction {tr ("&Erase"), this}} + , high_volume_ {false} + , modified_vertical_scrollbar_max_ {-1} { setReadOnly (true); setUndoRedoEnabled (false); @@ -68,14 +72,16 @@ void DisplayText::setContentFont(QFont const& font) cursor.movePosition (QTextCursor::StartOfLine); cursor.endEditBlock (); - setTextCursor (cursor); - ensureCursorVisible (); + if (!high_volume_ || !m_config || !m_config->decodes_from_top ()) + { + setTextCursor (cursor); + ensureCursorVisible (); + } } void DisplayText::mouseDoubleClickEvent(QMouseEvent *e) { Q_EMIT selectCallsign(e->modifiers ()); - QTextEdit::mouseDoubleClickEvent(e); } void DisplayText::insertLineSpacer(QString const& line) @@ -198,11 +204,44 @@ void DisplayText::appendText(QString const& text, QColor bg, QColor fg // position so viewport scrolled to left cursor.movePosition (QTextCursor::StartOfLine); - setTextCursor (cursor); - ensureCursorVisible (); + if (!high_volume_ || !m_config || !m_config->decodes_from_top ()) + { + setTextCursor (cursor); + ensureCursorVisible (); + } document ()->setMaximumBlockCount (document ()->maximumBlockCount ()); } +void DisplayText::extend_vertical_scrollbar (int min, int max) +{ + if (high_volume_ + && m_config && m_config->decodes_from_top ()) + { + if (max && max != modified_vertical_scrollbar_max_) + { + auto vp_margins = viewportMargins (); + // add enough to vertical scroll bar range to allow last + // decode to just scroll of the top of the view port + max += viewport ()->height () - vp_margins.top () - vp_margins.bottom (); + modified_vertical_scrollbar_max_ = max; + } + verticalScrollBar ()->setRange (min, max); + } +} + +void DisplayText::new_period () +{ + extend_vertical_scrollbar (verticalScrollBar ()->minimum (), verticalScrollBar ()->maximum ()); + if (high_volume_ && m_config && m_config->decodes_from_top () && !vertical_scroll_connection_) + { + vertical_scroll_connection_ = connect (verticalScrollBar (), &QScrollBar::rangeChanged + , [this] (int min, int max) { + extend_vertical_scrollbar (min, max ); + }); + } + verticalScrollBar ()->setSliderPosition (verticalScrollBar ()->maximum ()); +} + QString DisplayText::appendWorkedB4 (QString message, QString call, QString const& grid, QColor * bg, QColor * fg, LogBook const& logBook, QString const& currentBand, QString const& currentMode) @@ -400,7 +439,11 @@ void DisplayText::displayDecodedText(DecodedText const& decodedText, QString con } else { - highlight_types types {Highlight::CQ, Highlight::LotW}; + highlight_types types {Highlight::CQ}; + if (m_config && m_config->lotw_users ().user (decodedText.CQersCall())) + { + types.push_back (Highlight::LotW); + } set_colours (m_config, &bg, &fg, types); } } |
