Add flag to hide eye dropper button from qml ColorDialog
In devices with small screen like smartphone the ColorDialog dialog covers almost the entire screen so the eye dropper button doesn't make much sense and risks confusing the user. This patch add a flag to hide the button. Also if both title and button are not showed the header is resized to a fixed height. [ChangeLog][Dialogs][ColorDialog] Added a NoEyeDropperButton option to hide the eye dropper button Change-Id: I89f740b254a8f9d4a1274a2624d1b9b5da648184 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
This commit is contained in:
parent
9c33258ff5
commit
2e44d316c8
|
@ -102,6 +102,7 @@ void QQuickColorDialog::setSelectedColor(const QColor &color)
|
|||
\value ColorDialog.ShowAlphaChannel Show a slider and additional input fields for the alpha value.
|
||||
\value ColorDialog.NoButtons Don't display \uicontrol Open and \uicontrol Cancel buttons (useful
|
||||
for "live dialogs").
|
||||
\value ColorDialog.NoEyeDropperButton Don't display \uicontrol {Eye Dropper} button. This value was added in Qt 6.6.
|
||||
\value ColorDialog.DontUseNativeDialog Forces the dialog to use a non-native quick implementation.
|
||||
*/
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ ColorDialogImpl {
|
|||
padding: 6
|
||||
|
||||
Layout.preferredWidth: control.title.length > 0 ? implicitWidth : 0
|
||||
Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 15
|
||||
Layout.leftMargin: 12
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ ColorDialogImpl {
|
|||
|
||||
header: RowLayout {
|
||||
Label {
|
||||
objectName: "titleLabel"
|
||||
text: control.title
|
||||
elide: Label.ElideRight
|
||||
font.bold: true
|
||||
|
@ -67,10 +68,12 @@ ColorDialogImpl {
|
|||
bottomPadding: 16
|
||||
|
||||
Layout.preferredWidth: control.title.length > 0 ? implicitWidth : 0
|
||||
Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 15
|
||||
}
|
||||
|
||||
Button {
|
||||
id: eyeDropperButton
|
||||
objectName: "eyeDropperButton"
|
||||
icon.source: "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/images/eye-dropper.png"
|
||||
flat: true
|
||||
topPadding: 16
|
||||
|
|
|
@ -50,6 +50,7 @@ ColorDialogImpl {
|
|||
|
||||
header: RowLayout {
|
||||
Label {
|
||||
objectName: "titleLabel"
|
||||
text: control.title
|
||||
elide: Label.ElideRight
|
||||
font.bold: true
|
||||
|
@ -60,10 +61,12 @@ ColorDialogImpl {
|
|||
bottomPadding: 24
|
||||
|
||||
Layout.preferredWidth: control.title.length > 0 ? implicitWidth : 0
|
||||
Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 15
|
||||
}
|
||||
|
||||
Button {
|
||||
id: eyeDropperButton
|
||||
objectName: "eyeDropperButton"
|
||||
icon.source: "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/images/eye-dropper.png"
|
||||
flat: true
|
||||
topPadding: 24
|
||||
|
|
|
@ -47,6 +47,7 @@ ColorDialogImpl {
|
|||
spacing: 12
|
||||
|
||||
Label {
|
||||
objectName: "titleLabel"
|
||||
text: control.title
|
||||
elide: Label.ElideRight
|
||||
// TODO: QPlatformTheme::TitleBarFont
|
||||
|
@ -63,10 +64,12 @@ ColorDialogImpl {
|
|||
Layout.leftMargin: 18
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: control.title.length > 0 ? implicitHeight : 0
|
||||
Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 15
|
||||
}
|
||||
|
||||
Button {
|
||||
id: eyeDropperButton
|
||||
objectName: "eyeDropperButton"
|
||||
icon.source: "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/images/eye-dropper.png"
|
||||
flat: true
|
||||
topPadding: 24
|
||||
|
|
|
@ -59,6 +59,7 @@ ColorDialogImpl {
|
|||
font.bold: true
|
||||
|
||||
Layout.preferredWidth: control.title.length > 0 ? implicitWidth : 0
|
||||
Layout.preferredHeight: control.title.length > 0 ? implicitHeight : 15
|
||||
Layout.leftMargin: 12
|
||||
Layout.alignment: Qt.AlignLeft
|
||||
}
|
||||
|
|
|
@ -425,7 +425,8 @@ void QQuickColorDialogImpl::setOptions(const QSharedPointer<QColorDialogOptions>
|
|||
if (attached) {
|
||||
const bool screenGrabbingAllowed = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing);
|
||||
const bool offscreen = qgetenv("QT_QPA_PLATFORM").compare(QLatin1String("offscreen"), Qt::CaseInsensitive) == 0;
|
||||
attached->eyeDropperButton()->setVisible(screenGrabbingAllowed && !offscreen);
|
||||
const bool noEyeDropperButton = (d->options && d->options->options() & QColorDialogOptions::NoEyeDropperButton);
|
||||
attached->eyeDropperButton()->setVisible(!noEyeDropperButton && screenGrabbingAllowed && !offscreen);
|
||||
|
||||
if (d->options) {
|
||||
attached->buttonBox()->setVisible(
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <QtQuickTemplates2/private/qquicklabel_p.h>
|
||||
#include <QtQuickTemplates2/private/qquickoverlay_p.h>
|
||||
#include <QtQuickTemplates2/private/qquickslider_p.h>
|
||||
#include <QtQuickTemplates2/private/qquickbutton_p.h>
|
||||
#include <QtQuickControls2/qquickstyle.h>
|
||||
|
||||
#include <qpa/qplatformintegration.h>
|
||||
|
@ -127,6 +128,23 @@ void tst_QQuickColorDialogImpl::defaultValues()
|
|||
QVERIFY(dialogHelper.openDialog());
|
||||
QVERIFY(alphaSlider->isVisible());
|
||||
|
||||
const bool wayland = QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive) == 0;
|
||||
const bool offscreen = qgetenv("QT_QPA_PLATFORM").compare(QLatin1String("offscreen"), Qt::CaseInsensitive) == 0;
|
||||
|
||||
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing) && !wayland && !offscreen) {
|
||||
QQuickButton *eyeDropperButton = dialogHelper.quickDialog->findChild<QQuickButton *>("eyeDropperButton");
|
||||
QVERIFY(eyeDropperButton);
|
||||
|
||||
QVERIFY2(eyeDropperButton->isVisible(),
|
||||
"The Eye Dropper Button should be visible unless the NoEyeDropperButton option has "
|
||||
"explicitly been set");
|
||||
dialogHelper.dialog->close();
|
||||
QTRY_VERIFY(!dialogHelper.isQuickDialogOpen());
|
||||
dialogHelper.dialog->setOptions(QColorDialogOptions::NoEyeDropperButton);
|
||||
QVERIFY(dialogHelper.openDialog());
|
||||
QVERIFY(!eyeDropperButton->isVisible());
|
||||
}
|
||||
|
||||
QVERIFY(dialogHelper.quickDialog->isHsl());
|
||||
QCOMPARE(dialogHelper.quickDialog->alpha(), 1.0);
|
||||
QCOMPARE(dialogHelper.quickDialog->hue(), 0.0);
|
||||
|
|
|
@ -131,6 +131,13 @@ ColumnLayout {
|
|||
|
||||
readonly property int colorOption: checked ? ColorDialog.NoButtons : 0
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: noEyeDropperButton
|
||||
text: qsTr("NoEyeDropperButton")
|
||||
|
||||
readonly property int colorOption: checked ? ColorDialog.NoEyeDropperButton : 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +146,7 @@ ColumnLayout {
|
|||
id: colorDialog
|
||||
modality: modalityButtonGroup.checkedButton.modality
|
||||
title: titleTextField.text
|
||||
options: showAlphaChannel.colorOption | noButtons.colorOption
|
||||
options: showAlphaChannel.colorOption | noButtons.colorOption | noEyeDropperButton.colorOption
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue