~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/dialogs/qcolordialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtGui module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
23
**
23
 
** In addition, as a special exception, Nokia gives you certain
24
 
** additional rights. These rights are described in the Nokia Qt LGPL
25
 
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26
 
** package.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
63
63
#include "qspinbox.h"
64
64
#include "qdialogbuttonbox.h"
65
65
 
 
66
#ifdef Q_WS_S60
 
67
#include "private/qt_s60_p.h"
 
68
#endif
 
69
 
66
70
QT_BEGIN_NAMESPACE
67
71
 
68
72
//////////// QWellArray BEGIN
1066
1070
    QGridLayout *gl = new QGridLayout(this);
1067
1071
    gl->setMargin(gl->spacing());
1068
1072
    lab = new QColorShowLabel(this);
1069
 
#ifndef Q_OS_WINCE
 
1073
 
 
1074
#ifdef Q_WS_S60
 
1075
    QS60Data s60Data = QS60Data();
 
1076
    const bool nonTouchUI = !s60Data.hasTouchscreen;
 
1077
#endif
 
1078
 
 
1079
 
 
1080
#ifndef Q_WS_WINCE
 
1081
#ifdef Q_WS_S60
 
1082
    lab->setMinimumHeight(60);
 
1083
#endif
1070
1084
    lab->setMinimumWidth(60);
1071
1085
#else
1072
1086
    lab->setMinimumWidth(20);
1073
1087
#endif
 
1088
 
 
1089
// In S60, due to small screen and different screen layouts need to re-arrange the widgets.
 
1090
// For QVGA screens only the comboboxes and color label are visible.
 
1091
// For nHD screens only color and luminence pickers and color label are visible.
 
1092
#ifndef Q_WS_S60
1074
1093
    gl->addWidget(lab, 0, 0, -1, 1);
 
1094
#else
 
1095
    if (nonTouchUI)
 
1096
        gl->addWidget(lab, 0, 0, 1, -1);
 
1097
    else
 
1098
        gl->addWidget(lab, 0, 0, -1, 1);
 
1099
#endif
1075
1100
    connect(lab, SIGNAL(colorDropped(QRgb)), this, SIGNAL(newCol(QRgb)));
1076
1101
    connect(lab, SIGNAL(colorDropped(QRgb)), this, SLOT(setRgb(QRgb)));
1077
1102
 
1082
1107
    lblHue->setBuddy(hEd);
1083
1108
#endif
1084
1109
    lblHue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1110
#ifndef Q_WS_S60
1085
1111
    gl->addWidget(lblHue, 0, 1);
1086
1112
    gl->addWidget(hEd, 0, 2);
 
1113
#else
 
1114
    if (nonTouchUI) {
 
1115
        gl->addWidget(lblHue, 1, 0);
 
1116
        gl->addWidget(hEd, 2, 0);
 
1117
    } else {
 
1118
        lblHue->hide();
 
1119
        hEd->hide();
 
1120
    }
 
1121
#endif
1087
1122
 
1088
1123
    sEd = new QColSpinBox(this);
1089
1124
    lblSat = new QLabel(this);
1091
1126
    lblSat->setBuddy(sEd);
1092
1127
#endif
1093
1128
    lblSat->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1129
#ifndef Q_WS_S60
1094
1130
    gl->addWidget(lblSat, 1, 1);
1095
1131
    gl->addWidget(sEd, 1, 2);
 
1132
#else
 
1133
    if (nonTouchUI) {
 
1134
        gl->addWidget(lblSat, 1, 1);
 
1135
        gl->addWidget(sEd, 2, 1);
 
1136
    } else {
 
1137
        lblSat->hide();
 
1138
        sEd->hide();
 
1139
    }
 
1140
#endif
1096
1141
 
1097
1142
    vEd = new QColSpinBox(this);
1098
1143
    lblVal = new QLabel(this);
1100
1145
    lblVal->setBuddy(vEd);
1101
1146
#endif
1102
1147
    lblVal->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1148
#ifndef Q_WS_S60
1103
1149
    gl->addWidget(lblVal, 2, 1);
1104
1150
    gl->addWidget(vEd, 2, 2);
 
1151
#else
 
1152
    if (nonTouchUI) {
 
1153
        gl->addWidget(lblVal, 1, 2);
 
1154
        gl->addWidget(vEd, 2, 2);
 
1155
    } else {
 
1156
        lblVal->hide();
 
1157
        vEd->hide();
 
1158
    }
 
1159
#endif
1105
1160
 
1106
1161
    rEd = new QColSpinBox(this);
1107
1162
    lblRed = new QLabel(this);
1109
1164
    lblRed->setBuddy(rEd);
1110
1165
#endif
1111
1166
    lblRed->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1167
#ifndef Q_WS_S60
1112
1168
    gl->addWidget(lblRed, 0, 3);
1113
1169
    gl->addWidget(rEd, 0, 4);
 
1170
#else
 
1171
    if (nonTouchUI) {
 
1172
        gl->addWidget(lblRed, 3, 0);
 
1173
        gl->addWidget(rEd, 4, 0);
 
1174
    } else {
 
1175
        lblRed->hide();
 
1176
        rEd->hide();
 
1177
    }
 
1178
#endif
1114
1179
 
1115
1180
    gEd = new QColSpinBox(this);
1116
1181
    lblGreen = new QLabel(this);
1118
1183
    lblGreen->setBuddy(gEd);
1119
1184
#endif
1120
1185
    lblGreen->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1186
#ifndef Q_WS_S60
1121
1187
    gl->addWidget(lblGreen, 1, 3);
1122
1188
    gl->addWidget(gEd, 1, 4);
 
1189
#else
 
1190
    if (nonTouchUI) {
 
1191
        gl->addWidget(lblGreen, 3, 1);
 
1192
        gl->addWidget(gEd, 4, 1);
 
1193
    } else {
 
1194
        lblGreen->hide();
 
1195
        gEd->hide();
 
1196
    }
 
1197
#endif
1123
1198
 
1124
1199
    bEd = new QColSpinBox(this);
1125
1200
    lblBlue = new QLabel(this);
1127
1202
    lblBlue->setBuddy(bEd);
1128
1203
#endif
1129
1204
    lblBlue->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1205
#ifndef Q_WS_S60
1130
1206
    gl->addWidget(lblBlue, 2, 3);
1131
1207
    gl->addWidget(bEd, 2, 4);
 
1208
#else
 
1209
    if (nonTouchUI) {
 
1210
        gl->addWidget(lblBlue, 3, 2);
 
1211
        gl->addWidget(bEd, 4, 2);
 
1212
    } else {
 
1213
        lblBlue->hide();
 
1214
        bEd->hide();
 
1215
    }
 
1216
#endif
1132
1217
 
1133
1218
    alphaEd = new QColSpinBox(this);
1134
1219
    alphaLab = new QLabel(this);
1136
1221
    alphaLab->setBuddy(alphaEd);
1137
1222
#endif
1138
1223
    alphaLab->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
 
1224
#ifndef Q_WS_S60
1139
1225
    gl->addWidget(alphaLab, 3, 1, 1, 3);
1140
1226
    gl->addWidget(alphaEd, 3, 4);
 
1227
#else
 
1228
    if (nonTouchUI) {
 
1229
        gl->addWidget(alphaLab, 1, 3, 3, 1);
 
1230
        gl->addWidget(alphaEd, 4, 3);
 
1231
    } else {
 
1232
        alphaLab->hide();
 
1233
        alphaEd->hide();
 
1234
    }
 
1235
#endif
1141
1236
    alphaEd->hide();
1142
1237
    alphaLab->hide();
1143
1238
 
1262
1357
void QColorShower::updateQColor()
1263
1358
{
1264
1359
    QColor oldQColor(curQColor);
1265
 
    curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), qAlpha(curCol)));
 
1360
    curQColor.setRgba(qRgba(qRed(curCol), qGreen(curCol), qBlue(curCol), currentAlpha()));
1266
1361
    if (curQColor != oldQColor)
1267
1362
        emit currentColorChanged(curQColor);
1268
1363
}
1369
1464
 
1370
1465
    leftLay = 0;
1371
1466
 
1372
 
#if defined(Q_OS_WINCE)
 
1467
#if (defined(Q_WS_WINCE) || defined(Q_WS_S60))
1373
1468
    smallDisplay = true;
1374
1469
    const int lumSpace = 20;
1375
1470
#else
1376
1471
    // small displays (e.g. PDAs) cannot fit the full color dialog,
1377
1472
    // so just use the color picker.
1378
 
    smallDisplay = (qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350);
 
1473
    smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350);
1379
1474
    const int lumSpace = topLay->spacing() / 2;
1380
1475
#endif
1381
1476
 
1399
1494
    }
1400
1495
#endif
1401
1496
 
 
1497
#if defined(Q_WS_S60)
 
1498
    QS60Data s60Data = QS60Data();
 
1499
    const bool nonTouchUI = !s60Data.hasTouchscreen;
 
1500
#endif
 
1501
 
1402
1502
    if (!smallDisplay) {
1403
1503
        standard = new QColorWell(q, 6, 8, stdrgb);
1404
1504
        lblBasicColors = new QLabel(q);
1409
1509
        leftLay->addWidget(lblBasicColors);
1410
1510
        leftLay->addWidget(standard);
1411
1511
 
1412
 
#if !defined(Q_OS_WINCE)
 
1512
#if !defined(Q_WS_WINCE)
1413
1513
        leftLay->addStretch();
1414
1514
#endif
1415
1515
 
1429
1529
        leftLay->addWidget(addCusBt);
1430
1530
    } else {
1431
1531
        // better color picker size for small displays
 
1532
#ifdef Q_WS_S60
 
1533
        QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
 
1534
        pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
 
1535
        pHeight -= 20;
 
1536
        if(screenSize.height() > screenSize.width())
 
1537
            pWidth -= 20;
 
1538
#else
1432
1539
        pWidth = 150;
1433
1540
        pHeight = 100;
 
1541
#endif
1434
1542
        custom = 0;
1435
1543
        standard = 0;
1436
1544
    }
1446
1554
    cp = new QColorPicker(q);
1447
1555
 
1448
1556
    cp->setFrameStyle(QFrame::Panel + QFrame::Sunken);
 
1557
 
 
1558
#if defined(Q_WS_S60)
 
1559
    if (!nonTouchUI) {
 
1560
        pickLay->addWidget(cp);
 
1561
        cLay->addSpacing(lumSpace);
 
1562
    } else {
 
1563
        cp->hide();
 
1564
    }
 
1565
#else
1449
1566
    cLay->addSpacing(lumSpace);
1450
1567
    cLay->addWidget(cp);
 
1568
#endif
1451
1569
    cLay->addSpacing(lumSpace);
1452
1570
 
1453
1571
    lp = new QColorLuminancePicker(q);
 
1572
#if defined(Q_WS_S60)
 
1573
    QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
 
1574
    const int minDimension = qMin(screenSize.height(), screenSize.width());
 
1575
    //set picker to be finger-usable
 
1576
    int pickerWidth = !nonTouchUI ? minDimension/9 : minDimension/12;
 
1577
    lp->setFixedWidth(pickerWidth);
 
1578
    if (!nonTouchUI)
 
1579
        pickLay->addWidget(lp);
 
1580
    else
 
1581
        lp->hide();
 
1582
#else
1454
1583
    lp->setFixedWidth(20);
1455
1584
    pickLay->addWidget(lp);
 
1585
#endif
1456
1586
 
1457
1587
    QObject::connect(cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)));
1458
1588
    QObject::connect(lp, SIGNAL(newHsv(int,int,int)), q, SLOT(_q_newHsv(int,int,int)));
1463
1593
    QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb)));
1464
1594
    QObject::connect(cs, SIGNAL(currentColorChanged(const QColor&)),
1465
1595
                     q, SIGNAL(currentColorChanged(const QColor&)));
 
1596
#if defined(Q_WS_S60)
 
1597
    if (!nonTouchUI)
 
1598
        pWidth -= cp->size().width();
 
1599
    topLay->addWidget(cs);
 
1600
#else
1466
1601
    rightLay->addWidget(cs);
 
1602
#endif
1467
1603
 
1468
1604
    buttons = new QDialogButtonBox(q);
1469
1605
    mainLay->addWidget(buttons);
1510
1646
    \class QColorDialog
1511
1647
    \brief The QColorDialog class provides a dialog widget for specifying colors.
1512
1648
 
1513
 
    \mainclass
1514
 
    \ingroup dialogs
1515
 
    \ingroup multimedia
 
1649
    \ingroup standard-dialogs
1516
1650
 
1517
1651
    The color dialog's function is to allow users to choose colors.
1518
1652
    For example, you might use this in a drawing program to allow the
1578
1712
{
1579
1713
    Q_D(QColorDialog);
1580
1714
    d->setCurrentColor(color.rgb());
1581
 
    d->selectColor(color.rgb());
 
1715
    d->selectColor(color);
1582
1716
    d->setCurrentAlpha(color.alpha());
1583
1717
 
1584
1718
#ifdef Q_WS_MAC
1585
 
    if (d->delegate)
1586
 
        QColorDialogPrivate::setColor(d->delegate, color);
 
1719
    d->setCurrentQColor(color);
 
1720
    d->setCocoaPanelColor(color);
1587
1721
#endif
1588
1722
}
1589
1723
 
1724
1858
 
1725
1859
#if defined(Q_WS_MAC)
1726
1860
    if (visible) {
1727
 
        if (!d->delegate && QColorDialogPrivate::sharedColorPanelAvailable &&
1728
 
                !(testAttribute(Qt::WA_DontShowOnScreen) || (d->opts & DontUseNativeDialog))){
1729
 
            d->delegate = QColorDialogPrivate::openCocoaColorPanel(
1730
 
                    currentColor(), parentWidget(), windowTitle(), options(), d);
 
1861
        if (d->delegate || (QColorDialogPrivate::sharedColorPanelAvailable &&
 
1862
                !(testAttribute(Qt::WA_DontShowOnScreen) || (d->opts & DontUseNativeDialog)))){
 
1863
            d->openCocoaColorPanel(currentColor(), parentWidget(), windowTitle(), options());
1731
1864
            QColorDialogPrivate::sharedColorPanelAvailable = false;
1732
1865
            setAttribute(Qt::WA_DontShowOnScreen);
1733
1866
        }
1734
1867
        setWindowFlags(windowModality() == Qt::WindowModal ? Qt::Sheet : DefaultWindowFlags);
1735
1868
    } else {
1736
1869
        if (d->delegate) {
1737
 
            QColorDialogPrivate::closeCocoaColorPanel(d->delegate);
1738
 
            d->delegate = 0;
1739
 
            QColorDialogPrivate::sharedColorPanelAvailable = true;
 
1870
            d->closeCocoaColorPanel();
1740
1871
            setAttribute(Qt::WA_DontShowOnScreen, false);
1741
1872
        }
1742
1873
    }
1839
1970
 
1840
1971
QColorDialog::~QColorDialog()
1841
1972
{
 
1973
#if defined(Q_WS_MAC)
 
1974
    Q_D(QColorDialog);
 
1975
    if (d->delegate) {
 
1976
        d->releaseCocoaColorPanelDelegate();
 
1977
        QColorDialogPrivate::sharedColorPanelAvailable = true;
 
1978
    }
 
1979
#endif
 
1980
 
1842
1981
#ifndef QT_NO_SETTINGS
1843
1982
    if (!customSet) {
1844
1983
        QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
1872
2011
    Q_D(QColorDialog);
1873
2012
    QDialog::done(result);
1874
2013
    if (result == Accepted) {
1875
 
        d->selectedQColor = d->currentQColor(); 
 
2014
        d->selectedQColor = d->currentQColor();
1876
2015
        emit colorSelected(d->selectedQColor);
1877
2016
    } else {
1878
2017
        d->selectedQColor = QColor();