summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qcolordialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs/qcolordialog.cpp')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp206
1 files changed, 74 insertions, 132 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index b133c49b5e..5f3161f39f 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** 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 Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** 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
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -84,7 +84,7 @@ public:
virtual void setCurrent(int row, int col);
virtual void setSelected(int row, int col);
- QSize sizeHint() const;
+ QSize sizeHint() const Q_DECL_OVERRIDE;
virtual void setCellBrush(int row, int col, const QBrush &);
QBrush cellBrush(int row, int col);
@@ -137,12 +137,12 @@ protected:
virtual void paintCell(QPainter *, int row, int col, const QRect&);
virtual void paintCellContents(QPainter *, int row, int col, const QRect&);
- void mousePressEvent(QMouseEvent*);
- void mouseReleaseEvent(QMouseEvent*);
- void keyPressEvent(QKeyEvent*);
- void focusInEvent(QFocusEvent*);
- void focusOutEvent(QFocusEvent*);
- void paintEvent(QPaintEvent *);
+ void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE;
+ void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE;
+ void focusInEvent(QFocusEvent*) Q_DECL_OVERRIDE;
+ void focusOutEvent(QFocusEvent*) Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QWellArray)
@@ -514,15 +514,15 @@ public:
{ setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); }
protected:
- void paintCellContents(QPainter *, int row, int col, const QRect&);
- void mousePressEvent(QMouseEvent *e);
- void mouseMoveEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
+ void paintCellContents(QPainter *, int row, int col, const QRect&) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
#ifndef QT_NO_DRAGANDDROP
- void dragEnterEvent(QDragEnterEvent *e);
- void dragLeaveEvent(QDragLeaveEvent *e);
- void dragMoveEvent(QDragMoveEvent *e);
- void dropEvent(QDropEvent *e);
+ void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
+ void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
#endif
private:
@@ -636,11 +636,11 @@ signals:
void newCol(int h, int s);
protected:
- QSize sizeHint() const;
- void paintEvent(QPaintEvent*);
- void mouseMoveEvent(QMouseEvent *);
- void mousePressEvent(QMouseEvent *);
- void resizeEvent(QResizeEvent *);
+ QSize sizeHint() const Q_DECL_OVERRIDE;
+ void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
private:
int hue;
@@ -673,9 +673,9 @@ signals:
void newHsv(int h, int s, int v);
protected:
- void paintEvent(QPaintEvent*);
- void mouseMoveEvent(QMouseEvent *);
- void mousePressEvent(QMouseEvent *);
+ void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
private:
enum { foff = 3, coff = 4 }; //frame and contents offset
@@ -995,14 +995,14 @@ signals:
void colorDropped(QRgb);
protected:
- void paintEvent(QPaintEvent *);
- void mousePressEvent(QMouseEvent *e);
- void mouseMoveEvent(QMouseEvent *e);
- void mouseReleaseEvent(QMouseEvent *e);
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
#ifndef QT_NO_DRAGANDDROP
- void dragEnterEvent(QDragEnterEvent *e);
- void dragLeaveEvent(QDragLeaveEvent *e);
- void dropEvent(QDropEvent *e);
+ void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
+ void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
+ void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
#endif
private:
@@ -1119,10 +1119,7 @@ QColorShower::QColorShower(QColorDialog *parent)
#if !defined(QT_SMALL_COLORDIALOG)
gl->addWidget(lab, 0, 0, -1, 1);
#else
- if (nonTouchUI)
- gl->addWidget(lab, 0, 0, 1, -1);
- else
- gl->addWidget(lab, 0, 0, -1, 1);
+ gl->addWidget(lab, 0, 0, 1, -1);
#endif
connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb)));
connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb)));
@@ -1138,13 +1135,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblHue, 0, 1);
gl->addWidget(hEd, 0, 2);
#else
- if (nonTouchUI) {
- gl->addWidget(lblHue, 1, 0);
- gl->addWidget(hEd, 2, 0);
- } else {
- lblHue->hide();
- hEd->hide();
- }
+ gl->addWidget(lblHue, 1, 0);
+ gl->addWidget(hEd, 2, 0);
#endif
sEd = new QColSpinBox(this);
@@ -1157,13 +1149,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblSat, 1, 1);
gl->addWidget(sEd, 1, 2);
#else
- if (nonTouchUI) {
- gl->addWidget(lblSat, 1, 1);
- gl->addWidget(sEd, 2, 1);
- } else {
- lblSat->hide();
- sEd->hide();
- }
+ gl->addWidget(lblSat, 1, 1);
+ gl->addWidget(sEd, 2, 1);
#endif
vEd = new QColSpinBox(this);
@@ -1176,13 +1163,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblVal, 2, 1);
gl->addWidget(vEd, 2, 2);
#else
- if (nonTouchUI) {
- gl->addWidget(lblVal, 1, 2);
- gl->addWidget(vEd, 2, 2);
- } else {
- lblVal->hide();
- vEd->hide();
- }
+ gl->addWidget(lblVal, 1, 2);
+ gl->addWidget(vEd, 2, 2);
#endif
rEd = new QColSpinBox(this);
@@ -1195,13 +1177,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblRed, 0, 3);
gl->addWidget(rEd, 0, 4);
#else
- if (nonTouchUI) {
- gl->addWidget(lblRed, 3, 0);
- gl->addWidget(rEd, 4, 0);
- } else {
- lblRed->hide();
- rEd->hide();
- }
+ gl->addWidget(lblRed, 3, 0);
+ gl->addWidget(rEd, 4, 0);
#endif
gEd = new QColSpinBox(this);
@@ -1214,13 +1191,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblGreen, 1, 3);
gl->addWidget(gEd, 1, 4);
#else
- if (nonTouchUI) {
- gl->addWidget(lblGreen, 3, 1);
- gl->addWidget(gEd, 4, 1);
- } else {
- lblGreen->hide();
- gEd->hide();
- }
+ gl->addWidget(lblGreen, 3, 1);
+ gl->addWidget(gEd, 4, 1);
#endif
bEd = new QColSpinBox(this);
@@ -1233,13 +1205,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(lblBlue, 2, 3);
gl->addWidget(bEd, 2, 4);
#else
- if (nonTouchUI) {
- gl->addWidget(lblBlue, 3, 2);
- gl->addWidget(bEd, 4, 2);
- } else {
- lblBlue->hide();
- bEd->hide();
- }
+ gl->addWidget(lblBlue, 3, 2);
+ gl->addWidget(bEd, 4, 2);
#endif
alphaEd = new QColSpinBox(this);
@@ -1252,13 +1219,8 @@ QColorShower::QColorShower(QColorDialog *parent)
gl->addWidget(alphaLab, 3, 1, 1, 3);
gl->addWidget(alphaEd, 3, 4);
#else
- if (nonTouchUI) {
- gl->addWidget(alphaLab, 1, 3, 3, 1);
- gl->addWidget(alphaEd, 4, 3);
- } else {
- alphaLab->hide();
- alphaEd->hide();
- }
+ gl->addWidget(alphaLab, 1, 3, 3, 1);
+ gl->addWidget(alphaEd, 4, 3);
#endif
alphaEd->hide();
alphaLab->hide();
@@ -1598,11 +1560,16 @@ void QColorDialogPrivate::_q_pickScreenColor()
buttons->setDisabled(true);
screenColorPickerButton->setDisabled(true);
- q->setCurrentColor(grabScreenColor(QCursor::pos()));
- lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
- .arg(QCursor::pos().x())
- .arg(QCursor::pos().y())
- .arg(q->currentColor().name()));
+ const QPoint globalPos = QCursor::pos();
+ q->setCurrentColor(grabScreenColor(globalPos));
+ updateColorLabelText(globalPos);
+}
+
+void QColorDialogPrivate::updateColorLabelText(const QPoint &globalPos)
+{
+ lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2\nPress ESC to cancel")
+ .arg(globalPos.x())
+ .arg(globalPos.y()));
}
void QColorDialogPrivate::releaseColorPicking()
@@ -1638,7 +1605,7 @@ void QColorDialogPrivate::init(const QColor &initial)
if (!nativeDialogInUse)
initWidgets();
-#ifdef Q_WS_MAC
+#ifdef Q_DEAD_CODE_FROM_QT4_MAC
delegate = 0;
#endif
#ifdef Q_OS_WIN32
@@ -1674,9 +1641,7 @@ void QColorDialogPrivate::initWidgets()
if (!smallDisplay) {
leftLay = new QVBoxLayout;
topLay->addLayout(leftLay);
- }
- if (!smallDisplay) {
standard = new QColorWell(q, standardColorRows, colorColumns, QColorDialogOptions::standardColors());
lblBasicColors = new QLabel(q);
#ifndef QT_NO_SHORTCUT
@@ -1688,7 +1653,7 @@ void QColorDialogPrivate::initWidgets()
#if !defined(Q_OS_WINCE) && !defined(QT_SMALL_COLORDIALOG)
// The screen color picker button
- screenColorPickerButton = new QPushButton(QColorDialog::tr("Pick Screen Color"));
+ screenColorPickerButton = new QPushButton();
leftLay->addWidget(screenColorPickerButton);
lblScreenColorInfo = new QLabel(QLatin1String("\n"));
leftLay->addWidget(lblScreenColorInfo);
@@ -1743,12 +1708,7 @@ void QColorDialogPrivate::initWidgets()
cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);
#if defined(QT_SMALL_COLORDIALOG)
- if (!nonTouchUI) {
- pickLay->addWidget(cp);
- cLay->addSpacing(lumSpace);
- } else {
- cp->hide();
- }
+ cp->hide();
#else
cLay->addSpacing(lumSpace);
cLay->addWidget(cp);
@@ -1757,15 +1717,7 @@ void QColorDialogPrivate::initWidgets()
lp = new QColorLuminancePicker(q);
#if defined(QT_SMALL_COLORDIALOG)
- QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
- const int minDimension = qMin(screenSize.height(), screenSize.width());
- //set picker to be finger-usable
- int pickerWidth = !nonTouchUI ? minDimension/9 : minDimension/12;
- lp->setFixedWidth(pickerWidth);
- if (!nonTouchUI)
- pickLay->addWidget(lp);
- else
- lp->hide();
+ lp->hide();
#else
lp->setFixedWidth(20);
pickLay->addSpacing(10);
@@ -1784,12 +1736,11 @@ void QColorDialogPrivate::initWidgets()
QObject::connect(cs, SIGNAL(currentColorChanged(QColor)),
q, SIGNAL(currentColorChanged(QColor)));
#if defined(QT_SMALL_COLORDIALOG)
- if (!nonTouchUI)
- pWidth -= cp->size().width();
topLay->addWidget(cs);
#else
rightLay->addWidget(cs);
- leftLay->addSpacing(cs->gl->margin());
+ if (leftLay)
+ leftLay->addSpacing(cs->gl->margin());
#endif
buttons = new QDialogButtonBox(q);
@@ -1835,6 +1786,7 @@ void QColorDialogPrivate::retranslateStrings()
lblBasicColors->setText(QColorDialog::tr("&Basic colors"));
lblCustomColors->setText(QColorDialog::tr("&Custom colors"));
addCusBt->setText(QColorDialog::tr("&Add to Custom Colors"));
+ screenColorPickerButton->setText(QColorDialog::tr("&Pick Screen Color"));
}
cs->retranslateStrings();
@@ -2057,7 +2009,7 @@ QColorDialog::ColorDialogOptions QColorDialog::options() const
\sa color, colorSelected()
*/
-#ifdef Q_WS_MAC
+#ifdef Q_DEAD_CODE_FROM_QT4_MAC
// can only have one Cocoa color panel active
bool QColorDialogPrivate::sharedColorPanelAvailable = true;
#endif
@@ -2088,7 +2040,7 @@ void QColorDialog::setVisible(bool visible)
if (visible)
d->selectedQColor = QColor();
-#if defined(Q_WS_MAC)
+#if defined(Q_DEAD_CODE_FROM_QT4_MAC)
if (visible) {
if (d->delegate || (QColorDialogPrivate::sharedColorPanelAvailable &&
!(testAttribute(Qt::WA_DontShowOnScreen) || (d->opts & DontUseNativeDialog)))){
@@ -2137,16 +2089,6 @@ void QColorDialog::open(QObject *receiver, const char *member)
}
/*!
- \fn QColorDialog::open()
-
- \since 4.5
- Shows the dialog as a \l{QDialog#Modal Dialogs}{window modal dialog},
- returning immediately.
-
- \sa QDialog::open()
-*/
-
-/*!
\since 4.5
Pops up a modal color dialog with the given window \a title (or "Select Color" if none is
@@ -2199,7 +2141,7 @@ QRgb QColorDialog::getRgba(QRgb initial, bool *ok, QWidget *parent)
QColorDialog::~QColorDialog()
{
-#if defined(Q_WS_MAC)
+#if defined(Q_DEAD_CODE_FROM_QT4_MAC)
Q_D(QColorDialog);
if (d->delegate) {
d->releaseCocoaColorPanelDelegate();
@@ -2244,8 +2186,8 @@ void QColorDialogPrivate::updateColorPicking(const QPoint &globalPos)
// QTBUG-39792, do not change standard, custom color selectors while moving as
// otherwise it is not possible to pre-select a custom cell for assignment.
setCurrentColor(color, ShowColor);
- lblScreenColorInfo->setText(QColorDialog::tr("Cursor at %1, %2, color: %3\nPress ESC to cancel")
- .arg(globalPos.x()).arg(globalPos.y()).arg(color.name()));
+ updateColorLabelText(globalPos);
+
}
bool QColorDialogPrivate::handleColorPickingMouseMove(QMouseEvent *e)