diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-08-14 09:52:56 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-08-20 09:25:07 +0000 |
commit | ab95b3ca1187347cb4b3bc0a1d01886091e3b2a6 (patch) | |
tree | 9f5f06b188e95fff68945f5d768fe5e4d469ed1a /src/imports/nativestyle/items | |
parent | 3dd369a3af58d4fb0c6734ec945975bfc09c043c (diff) |
Native style: don't draw frame around TextArea
In controls, it's seems to be undefined if the style should draw
a frame around TextArea or not. E.g the Imagine style do, but the
the Fusion style does not. This is a bit unfortunate, because
depending on how you use a TextArea, you might want a frame
around the TextArea itself, or the ScrollView around it (including
the scrollbars), or not at all (*). For this reason, we should
not draw a frame around the TextArea, but leave it to the user
to compose the (style independent) structure, e.g
Frame { ScrollView { TextArea{} } }
Frame { TextArea {} }.
TextArea {}
This patch will remove drawing a frame around TextArea from
the native style. Then at least Fusion, macOS and Windows
will work the same way. This also means that we can remove the
QQuickStyleItemTextArea, since we end up not using QStyle
at all for drawing a TextArea.
(*) Compared to Widgets, a QPlainTextEdit
inherits from QAbstractScrollArea, which inherits from QFrame.
In QFrame, you can choose frameShape, and even set it to NoFrame.
Change-Id: Icabfa294744e87ccf262855faa0992f2d71ec4cb
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r-- | src/imports/nativestyle/items/items.pri | 2 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitemtextarea.cpp | 85 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitemtextarea.h | 60 |
3 files changed, 0 insertions, 147 deletions
diff --git a/src/imports/nativestyle/items/items.pri b/src/imports/nativestyle/items/items.pri index f9caca1c..f572cf24 100644 --- a/src/imports/nativestyle/items/items.pri +++ b/src/imports/nativestyle/items/items.pri @@ -10,7 +10,6 @@ HEADERS += \ $$PWD/qquickstyleitemspinbox.h \ $$PWD/qquickstyleitemtextfield.h \ $$PWD/qquickstyleitemframe.h \ - $$PWD/qquickstyleitemtextarea.h \ $$PWD/qquickstyleitemcombobox.h \ $$PWD/qquickstyleitemscrollbar.h \ $$PWD/qquickstyleitemprogressbar.h \ @@ -26,7 +25,6 @@ SOURCES += \ $$PWD/qquickstyleitemspinbox.cpp \ $$PWD/qquickstyleitemtextfield.cpp \ $$PWD/qquickstyleitemframe.cpp \ - $$PWD/qquickstyleitemtextarea.cpp \ $$PWD/qquickstyleitemcombobox.cpp \ $$PWD/qquickstyleitemscrollbar.cpp \ $$PWD/qquickstyleitemprogressbar.cpp \ diff --git a/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp b/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp deleted file mode 100644 index c149444b..00000000 --- a/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickstyleitemtextarea.h" - -QFont QQuickStyleItemTextArea::styleFont(QQuickItem *control) -{ - return style()->font(QStyle::CE_ComboBoxLabel, controlSize(control)); -} - -void QQuickStyleItemTextArea::connectToControl() -{ - QQuickStyleItem::connectToControl(); - auto textArea = control<QQuickTextArea>(); - connect(textArea, &QQuickTextArea::readOnlyChanged, this, &QQuickStyleItem::markImageDirty); - connect(textArea, &QQuickTextArea::focusChanged, this, &QQuickStyleItem::markImageDirty); -} - -StyleItemGeometry QQuickStyleItemTextArea::calculateGeometry() -{ - QStyleOptionFrame styleOption; - initStyleOption(styleOption); - StyleItemGeometry geometry; - - // There is no CT_TextEdit in QStyle, so we "borrow" CT_LineEdit for now - geometry.minimumSize = style()->sizeFromContents(QStyle::CT_LineEdit, &styleOption, QSize(0, 0)); - geometry.implicitSize = style()->sizeFromContents(QStyle::CT_LineEdit, &styleOption, contentSize()); - styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize); - geometry.contentRect = style()->subElementRect(QStyle::SE_LineEditContents, &styleOption); - geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CE_ShapedFrame, &styleOption, geometry.minimumSize); - - return geometry; -} - -void QQuickStyleItemTextArea::paintEvent(QPainter *painter) -{ - QStyleOptionFrame styleOption; - initStyleOption(styleOption); - style()->drawPrimitive(QStyle::PE_PanelLineEdit, &styleOption, painter); -} - -void QQuickStyleItemTextArea::initStyleOption(QStyleOptionFrame &styleOption) -{ - initStyleOptionBase(styleOption); - auto textArea = control<QQuickTextArea>(); - - styleOption.lineWidth = 1; - styleOption.midLineWidth = 0; - styleOption.state |= QStyle::State_Sunken; - if (textArea->isReadOnly()) - styleOption.state |= QStyle::State_ReadOnly; -} diff --git a/src/imports/nativestyle/items/qquickstyleitemtextarea.h b/src/imports/nativestyle/items/qquickstyleitemtextarea.h deleted file mode 100644 index 90d83ad7..00000000 --- a/src/imports/nativestyle/items/qquickstyleitemtextarea.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKSTYLEITEMTEXTAREA_H -#define QQUICKSTYLEITEMTEXTAREA_H - -#include "qquickstyleitem.h" -#include <QtQuickTemplates2/private/qquicktextarea_p.h> - -class QQuickStyleItemTextArea : public QQuickStyleItem -{ - Q_OBJECT - QML_NAMED_ELEMENT(TextArea) - -public: - QFont styleFont(QQuickItem *control) override; - -protected: - void connectToControl() override; - void paintEvent(QPainter *painter) override; - StyleItemGeometry calculateGeometry() override; - -private: - void initStyleOption(QStyleOptionFrame &styleOption); -}; - -#endif // QQUICKSTYLEITEMTEXTAREA_H |