diff options
author | Katja Marttila <katja.marttila@qt.io> | 2018-11-23 07:01:15 +0200 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-01-15 14:56:26 +0200 |
commit | c3a84add1c8ed3c879168cba4e9a84af58129da6 (patch) | |
tree | 54cdc5142e8043af98372bb5527f0c5dec6280ab /src | |
parent | 57078aec62049ac08c5df94db06c79e956fd0eeb (diff) |
Replace usage of derived LazyPlainTextEdit class with QTextEdit
Remove LazyPlainTextEdit class and replace usage in
PerformInstallationForm details browser to QTextEdit. This adds
support for RTL text alignment as the base class of the removed
class, QPlainTextEdit does not fully support RTL and automatic
alignment. Text will now be automatically aligned based on the
direction of the characters.
This also improves the usability of the details browser, as it
does not force scrolling to bottom if the user has scrolled the
widget contents to inspect previous lines.
Task-number: QTIFW-1994
Change-Id: If01eaea121000edc0b5039edfede88ffb7bacd6f
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/installer.pro | 2 | ||||
-rw-r--r-- | src/libs/installer/lazyplaintextedit.cpp | 101 | ||||
-rw-r--r-- | src/libs/installer/lazyplaintextedit.h | 56 | ||||
-rw-r--r-- | src/libs/installer/packagemanagergui.cpp | 1 | ||||
-rw-r--r-- | src/libs/installer/performinstallationform.cpp | 11 | ||||
-rw-r--r-- | src/libs/installer/performinstallationform.h | 5 |
6 files changed, 3 insertions, 173 deletions
diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index 2462dbe63..437ab002f 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -78,7 +78,6 @@ HEADERS += packagemanagercore.h \ adminauthorization.h \ elevatedexecuteoperation.h \ fakestopprocessforupdateoperation.h \ - lazyplaintextedit.h \ progresscoordinator.h \ minimumprogressoperation.h \ performinstallationform.h \ @@ -172,7 +171,6 @@ SOURCES += packagemanagercore.cpp \ init.cpp \ elevatedexecuteoperation.cpp \ fakestopprocessforupdateoperation.cpp \ - lazyplaintextedit.cpp \ progresscoordinator.cpp \ minimumprogressoperation.cpp \ performinstallationform.cpp \ diff --git a/src/libs/installer/lazyplaintextedit.cpp b/src/libs/installer/lazyplaintextedit.cpp deleted file mode 100644 index a4a699a78..000000000 --- a/src/libs/installer/lazyplaintextedit.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#include "lazyplaintextedit.h" - -#include <QScrollBar> - -const int INTERVAL = 20; - -LazyPlainTextEdit::LazyPlainTextEdit(QWidget *parent) - : QPlainTextEdit(parent) - , m_timerId(0) -{ -} - -void LazyPlainTextEdit::timerEvent(QTimerEvent *event) -{ - if (event->timerId() == m_timerId) { - killTimer(m_timerId); - m_timerId = 0; - m_cachedOutput.chop(1); //removes the last \n - if (!m_cachedOutput.isEmpty()) { - appendPlainText(m_cachedOutput); - updateCursor(TextCursorPosition::Keep); - horizontalScrollBar()->setValue(0); - m_cachedOutput.clear(); - } - } -} - -void LazyPlainTextEdit::append(const QString &text) -{ - m_cachedOutput.append(text + QLatin1String("\n")); - if (isVisible() && m_timerId == 0) - m_timerId = startTimer(INTERVAL); -} - -void LazyPlainTextEdit::clear() -{ - if (m_timerId) { - killTimer(m_timerId); - m_timerId = 0; - m_cachedOutput.clear(); - } - QPlainTextEdit::clear(); -} - -void LazyPlainTextEdit::setVisible(bool visible) -{ - if (m_timerId) { - killTimer(m_timerId); - m_timerId = 0; - } - - if (visible) - m_timerId = startTimer(INTERVAL); - - QPlainTextEdit::setVisible(visible); - updateCursor(TextCursorPosition::Keep); -} - -void LazyPlainTextEdit::updateCursor(TextCursorPosition position) -{ - QTextCursor cursor = textCursor(); - if ((position == TextCursorPosition::ForceEnd) || cursor.atEnd()) { - // Workaround for height calculation issue if scrollbar is set to Qt::ScrollBarAsNeeded. - Qt::ScrollBarPolicy policy = horizontalScrollBarPolicy(); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); // enforce always on - - cursor.movePosition(QTextCursor::End); - setTextCursor(cursor); - ensureCursorVisible(); - - setHorizontalScrollBarPolicy(policy); // but reset once we updated the cursor position - } -} diff --git a/src/libs/installer/lazyplaintextedit.h b/src/libs/installer/lazyplaintextedit.h deleted file mode 100644 index 445fa752d..000000000 --- a/src/libs/installer/lazyplaintextedit.h +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#ifndef LAZYPLAINTEXTEDIT_H -#define LAZYPLAINTEXTEDIT_H - -#include <QPlainTextEdit> - -class LazyPlainTextEdit : public QPlainTextEdit -{ - Q_OBJECT -public: - enum struct TextCursorPosition { - Keep, - ForceEnd - }; - explicit LazyPlainTextEdit(QWidget *parent = 0); - void updateCursor(TextCursorPosition position); - -public slots: - void append(const QString &text); - virtual void clear(); - virtual void setVisible ( bool visible ); -protected: - void timerEvent(QTimerEvent *event); -private: - int m_timerId; - QString m_cachedOutput; -}; - -#endif // LAZYPLAINTEXTEDIT_H diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index 13113755e..04f7770e9 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -2797,7 +2797,6 @@ void PerformInstallationPage::installationFinished() { m_performInstallationForm->stopUpdateProgress(); if (!isAutoSwitching()) { - m_performInstallationForm->scrollDetailsToTheEnd(); m_performInstallationForm->setDetailsButtonEnabled(false); setComplete(true); diff --git a/src/libs/installer/performinstallationform.cpp b/src/libs/installer/performinstallationform.cpp index f60ef0ab1..2fb6026cc 100644 --- a/src/libs/installer/performinstallationform.cpp +++ b/src/libs/installer/performinstallationform.cpp @@ -28,7 +28,6 @@ #include "performinstallationform.h" -#include "lazyplaintextedit.h" #include "progresscoordinator.h" #include "globals.h" @@ -147,7 +146,7 @@ void PerformInstallationForm::setupUi(QWidget *widget) m_productImagesScrollArea->setWidget(m_productImagesLabel); bottomLayout->addWidget(m_productImagesScrollArea); - m_detailsBrowser = new LazyPlainTextEdit(widget); + m_detailsBrowser = new QTextEdit(widget); m_detailsBrowser->setReadOnly(true); m_detailsBrowser->setWordWrapMode(QTextOption::NoWrap); m_detailsBrowser->setObjectName(QLatin1String("DetailsBrowser")); @@ -269,14 +268,6 @@ void PerformInstallationForm::setDetailsButtonEnabled(bool enable) } /*! - Scrolls to the bottom of the details browser. -*/ -void PerformInstallationForm::scrollDetailsToTheEnd() -{ - m_detailsBrowser->updateCursor(LazyPlainTextEdit::TextCursorPosition::ForceEnd); -} - -/*! Returns \c true if the details browser is visible. */ bool PerformInstallationForm::isShowingDetails() const diff --git a/src/libs/installer/performinstallationform.h b/src/libs/installer/performinstallationform.h index 20b193857..d67f6ac4b 100644 --- a/src/libs/installer/performinstallationform.h +++ b/src/libs/installer/performinstallationform.h @@ -32,6 +32,7 @@ #include "aspectratiolabel.h" #include <QObject> +#include <QTextEdit> QT_BEGIN_NAMESPACE class QLabel; @@ -43,7 +44,6 @@ class QWinTaskbarButton; class QScrollArea; QT_END_NAMESPACE -class LazyPlainTextEdit; namespace QInstaller { @@ -60,7 +60,6 @@ public: void startUpdateProgress(); void stopUpdateProgress(); void setDetailsButtonEnabled(bool enable); - void scrollDetailsToTheEnd(); bool isShowingDetails() const; signals: @@ -81,7 +80,7 @@ private: QScrollArea *m_productImagesScrollArea; AspectRatioLabel *m_productImagesLabel; QPushButton *m_detailsButton; - LazyPlainTextEdit *m_detailsBrowser; + QTextEdit *m_detailsBrowser; QTimer *m_updateTimer; #ifdef Q_OS_WIN |