2015-11-26 17:02:15 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-01-09 16:13:48 +00:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2021-11-25 16:22:05 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-11-26 17:02:15 +00:00
|
|
|
**
|
2016-04-14 06:07:48 +00:00
|
|
|
** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
|
2015-11-26 17:02:15 +00:00
|
|
|
**
|
2021-11-25 16:22:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2015-11-26 17:02:15 +00:00
|
|
|
** 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
|
2021-11-25 16:22:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-11-26 17:02:15 +00:00
|
|
|
**
|
|
|
|
** 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
|
2021-11-25 16:22:05 +00:00
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
2015-11-26 17:02:15 +00:00
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
2021-11-25 16:22:05 +00:00
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2015-11-26 17:02:15 +00:00
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2021-11-25 16:22:05 +00:00
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** 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-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-11-26 17:02:15 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-26 16:01:51 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Window
|
|
|
|
import QtQuick.Controls.impl
|
|
|
|
import QtQuick.Templates as T
|
|
|
|
import QtQuick.Controls.Universal
|
2015-11-26 17:02:15 +00:00
|
|
|
|
|
|
|
T.ComboBox {
|
|
|
|
id: control
|
|
|
|
|
2018-04-19 19:55:37 +00:00
|
|
|
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
|
2018-04-12 12:53:59 +00:00
|
|
|
implicitContentWidth + leftPadding + rightPadding)
|
2018-04-19 19:55:37 +00:00
|
|
|
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
|
2018-04-19 14:16:11 +00:00
|
|
|
implicitContentHeight + topPadding + bottomPadding,
|
|
|
|
implicitIndicatorHeight + topPadding + bottomPadding)
|
2015-11-26 17:02:15 +00:00
|
|
|
|
2016-10-28 11:56:17 +00:00
|
|
|
leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
|
|
|
|
rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
|
2015-11-26 17:02:15 +00:00
|
|
|
|
2016-10-01 19:08:09 +00:00
|
|
|
Universal.theme: editable && activeFocus ? Universal.Light : undefined
|
|
|
|
|
2015-11-26 17:02:15 +00:00
|
|
|
delegate: ItemDelegate {
|
2020-02-25 11:16:39 +00:00
|
|
|
width: ListView.view.width
|
2016-01-25 16:06:30 +00:00
|
|
|
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
|
2018-11-13 15:11:48 +00:00
|
|
|
font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal
|
2015-11-26 17:02:15 +00:00
|
|
|
highlighted: control.highlightedIndex === index
|
2016-06-28 12:25:53 +00:00
|
|
|
hoverEnabled: control.hoverEnabled
|
2015-11-26 17:02:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 09:22:34 +00:00
|
|
|
indicator: ColorImage {
|
2016-10-28 11:56:17 +00:00
|
|
|
x: control.mirrored ? control.padding : control.width - width - control.padding
|
2016-04-28 10:37:58 +00:00
|
|
|
y: control.topPadding + (control.availableHeight - height) / 2
|
2017-04-10 09:22:34 +00:00
|
|
|
color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseMediumHighColor
|
2020-03-27 10:17:35 +00:00
|
|
|
source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/downarrow.png"
|
2016-10-01 19:08:09 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
z: -1
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
color: control.activeFocus ? control.Universal.accent :
|
|
|
|
control.pressed ? control.Universal.baseMediumLowColor :
|
|
|
|
control.hovered ? control.Universal.baseLowColor : "transparent"
|
2020-04-24 12:21:44 +00:00
|
|
|
visible: control.editable && !control.contentItem.hovered && (control.pressed || control.hovered)
|
2016-10-01 19:08:09 +00:00
|
|
|
opacity: control.activeFocus && !control.pressed ? 0.4 : 1.0
|
|
|
|
}
|
2016-04-28 10:37:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-01 19:08:09 +00:00
|
|
|
contentItem: T.TextField {
|
|
|
|
leftPadding: control.mirrored ? 1 : 12
|
|
|
|
rightPadding: control.mirrored ? 10 : 1
|
2016-10-28 11:56:17 +00:00
|
|
|
topPadding: 5 - control.topPadding
|
|
|
|
bottomPadding: 7 - control.bottomPadding
|
2016-04-28 10:37:58 +00:00
|
|
|
|
2016-10-01 19:08:09 +00:00
|
|
|
text: control.editable ? control.editText : control.displayText
|
|
|
|
|
|
|
|
enabled: control.editable
|
|
|
|
autoScroll: control.editable
|
2017-12-13 12:35:52 +00:00
|
|
|
readOnly: control.down
|
2016-10-01 19:08:09 +00:00
|
|
|
inputMethodHints: control.inputMethodHints
|
|
|
|
validator: control.validator
|
2019-12-11 15:38:14 +00:00
|
|
|
selectByMouse: control.selectTextByMouse
|
2016-10-01 19:08:09 +00:00
|
|
|
|
2015-11-26 17:02:15 +00:00
|
|
|
font: control.font
|
2016-10-01 19:08:09 +00:00
|
|
|
color: !control.enabled ? control.Universal.chromeDisabledLowColor :
|
|
|
|
control.editable && control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.foreground
|
|
|
|
selectionColor: control.Universal.accent
|
|
|
|
selectedTextColor: control.Universal.chromeWhiteColor
|
2015-11-26 17:02:15 +00:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
implicitWidth: 120
|
|
|
|
implicitHeight: 32
|
|
|
|
|
2016-08-09 11:42:56 +00:00
|
|
|
border.width: control.flat ? 0 : 2 // ComboBoxBorderThemeThickness
|
2015-11-26 17:02:15 +00:00
|
|
|
border.color: !control.enabled ? control.Universal.baseLowColor :
|
2016-10-01 19:08:09 +00:00
|
|
|
control.editable && control.activeFocus ? control.Universal.accent :
|
2017-12-13 12:35:52 +00:00
|
|
|
control.down ? control.Universal.baseMediumLowColor :
|
2016-06-28 12:19:31 +00:00
|
|
|
control.hovered ? control.Universal.baseMediumColor : control.Universal.baseMediumLowColor
|
2015-11-26 17:02:15 +00:00
|
|
|
color: !control.enabled ? control.Universal.baseLowColor :
|
2016-11-04 11:54:38 +00:00
|
|
|
control.down ? control.Universal.listMediumColor :
|
2016-10-01 19:08:09 +00:00
|
|
|
control.flat && control.hovered ? control.Universal.listLowColor :
|
|
|
|
control.editable && control.activeFocus ? control.Universal.background : control.Universal.altMediumLowColor
|
2016-08-09 11:42:56 +00:00
|
|
|
visible: !control.flat || control.pressed || control.hovered || control.visualFocus
|
2015-11-26 17:02:15 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
x: 2
|
|
|
|
y: 2
|
|
|
|
width: parent.width - 4
|
|
|
|
height: parent.height - 4
|
|
|
|
|
2016-10-01 19:08:09 +00:00
|
|
|
visible: control.visualFocus && !control.editable
|
2015-12-22 21:40:54 +00:00
|
|
|
color: control.Universal.accent
|
2015-11-26 17:02:15 +00:00
|
|
|
opacity: control.Universal.theme === Universal.Light ? 0.4 : 0.6
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 13:26:51 +00:00
|
|
|
popup: T.Popup {
|
2016-05-09 14:09:07 +00:00
|
|
|
width: control.width
|
ComboBox: fix empty popup being shown after model is cleared
Currently, ComboBox's popup is sized vertically in this way:
implicitHeight: contentItem.implicitHeight
Adding an item to a ComboBox with an empty model and then opening
the popup results in the implicitHeight being used in the line below
(in QQuickPopupPositioner::reposition()):
QRectF rect(p->allowHorizontalMove ? p->x : popupItem->x(),
p->allowVerticalMove ? p->y : popupItem->y(),
!p->hasWidth && iw > 0 ? iw : w,
!p->hasHeight && ih > 0 ? ih : h);
An explicit height was never set on the popup, and ih (the
implicitHeight of the popupItem) is greater than 0. This is fine.
However, when a ComboBox's popup item grows large enough that it has to
be resized to fit within the window, its explicit height is set. The
problem occurs when the model is then cleared, as the implicit height
of the popup item becomes 0. So, while "!p->hasHeight" is still true,
"ih > 0" is not, and the explicit height of the popup item is used,
which is still the previous "let's fill the entire height of the
window" size.
To fix this, we bind the height of the popup to a different expression:
height: Math.min(contentItem.implicitHeight,
control.Window.height - topMargin - bottomMargin)
This ensures that the popup has a zero height when the ListView's
implicitHeight is zero (i.e the model is empty), and a height
that fits within the window in all other cases.
Ideally, we'd have a maximumHeight property that controls this, but
for 5.9, we have to fix it this way.
Task-number: QTBUG-60684
Change-Id: Ied94c79bb7b0e693be34e9c7282d991f6f704770
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
2017-05-31 15:14:49 +00:00
|
|
|
height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin)
|
2016-01-30 15:21:16 +00:00
|
|
|
topMargin: 8
|
|
|
|
bottomMargin: 8
|
2015-11-26 17:02:15 +00:00
|
|
|
|
2016-03-11 12:40:45 +00:00
|
|
|
Universal.theme: control.Universal.theme
|
|
|
|
Universal.accent: control.Universal.accent
|
|
|
|
|
2016-01-22 11:10:12 +00:00
|
|
|
contentItem: ListView {
|
|
|
|
clip: true
|
2016-09-30 15:05:40 +00:00
|
|
|
implicitHeight: contentHeight
|
2017-12-13 12:35:52 +00:00
|
|
|
model: control.delegateModel
|
2016-01-22 11:10:12 +00:00
|
|
|
currentIndex: control.highlightedIndex
|
2016-10-01 21:02:43 +00:00
|
|
|
highlightMoveDuration: 0
|
2015-11-26 17:02:15 +00:00
|
|
|
|
2016-01-29 15:23:01 +00:00
|
|
|
T.ScrollIndicator.vertical: ScrollIndicator { }
|
2016-01-22 11:10:12 +00:00
|
|
|
}
|
2015-11-26 17:02:15 +00:00
|
|
|
|
2016-01-22 11:10:12 +00:00
|
|
|
background: Rectangle {
|
|
|
|
color: control.Universal.chromeMediumLowColor
|
|
|
|
border.color: control.Universal.chromeHighColor
|
|
|
|
border.width: 1 // FlyoutBorderThemeThickness
|
2015-11-26 17:02:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|