diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-05-25 11:09:30 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-05-28 09:21:44 +0000 |
commit | da61fcd7890f0e259dd97e056518d504eb99efc6 (patch) | |
tree | 31316434580933532111517fa308dc5c77dadcb6 /src/imports/nativestyle/items | |
parent | d0c8d7d5b2a2fb48b919555274a4aa60049f7f1a (diff) |
Native style: add TextArea
Change-Id: Ie8a4ea4ff232fa5aa3064b56aa7ba13f8522590d
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 | 84 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitemtextarea.h | 60 |
3 files changed, 146 insertions, 0 deletions
diff --git a/src/imports/nativestyle/items/items.pri b/src/imports/nativestyle/items/items.pri index 8641adff..1816033f 100644 --- a/src/imports/nativestyle/items/items.pri +++ b/src/imports/nativestyle/items/items.pri @@ -10,6 +10,7 @@ HEADERS += \ $$PWD/qquickstyleitemspinbox.h \ $$PWD/qquickstyleitemtextfield.h \ $$PWD/qquickstyleitemframe.h \ + $$PWD/qquickstyleitemtextarea.h \ SOURCES += \ $$PWD/qquickstyleitem.cpp \ @@ -21,3 +22,4 @@ SOURCES += \ $$PWD/qquickstyleitemspinbox.cpp \ $$PWD/qquickstyleitemtextfield.cpp \ $$PWD/qquickstyleitemframe.cpp \ + $$PWD/qquickstyleitemtextarea.cpp \ diff --git a/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp b/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp new file mode 100644 index 00000000..88dbf065 --- /dev/null +++ b/src/imports/nativestyle/items/qquickstyleitemtextarea.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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); + + 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 new file mode 100644 index 00000000..90d83ad7 --- /dev/null +++ b/src/imports/nativestyle/items/qquickstyleitemtextarea.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 |