| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the tools applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $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.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 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 [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | /*
|
|---|
| 43 | TRANSLATOR qdesigner_internal::QtGradientDialog
|
|---|
| 44 | */
|
|---|
| 45 |
|
|---|
| 46 | #include "qtgradientdialog.h"
|
|---|
| 47 | #include "ui_qtgradientdialog.h"
|
|---|
| 48 | #include <QtGui/QPushButton>
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_NAMESPACE
|
|---|
| 51 |
|
|---|
| 52 | class QtGradientDialogPrivate
|
|---|
| 53 | {
|
|---|
| 54 | QtGradientDialog *q_ptr;
|
|---|
| 55 | Q_DECLARE_PUBLIC(QtGradientDialog)
|
|---|
| 56 | public:
|
|---|
| 57 |
|
|---|
| 58 | void slotAboutToShowDetails(bool details, int extensionWidthHint);
|
|---|
| 59 |
|
|---|
| 60 | Ui::QtGradientDialog m_ui;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | void QtGradientDialogPrivate::slotAboutToShowDetails(bool details, int extensionWidthHint)
|
|---|
| 64 | {
|
|---|
| 65 | if (details) {
|
|---|
| 66 | q_ptr->resize(q_ptr->size() + QSize(extensionWidthHint, 0));
|
|---|
| 67 | } else {
|
|---|
| 68 | q_ptr->setMinimumSize(1, 1);
|
|---|
| 69 | q_ptr->resize(q_ptr->size() - QSize(extensionWidthHint, 0));
|
|---|
| 70 | q_ptr->setMinimumSize(0, 0);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /*!
|
|---|
| 75 | \class QtGradientDialog
|
|---|
| 76 |
|
|---|
| 77 | \brief The QtGradientDialog class provides a dialog for specifying gradients.
|
|---|
| 78 |
|
|---|
| 79 | The gradient dialog's function is to allow users to edit gradients.
|
|---|
| 80 | For example, you might use this in a drawing program to allow the user to set the brush gradient.
|
|---|
| 81 |
|
|---|
| 82 | \table
|
|---|
| 83 | \row
|
|---|
| 84 | \o \inlineimage qtgradientdialog.png
|
|---|
| 85 | \o \inlineimage qtgradientdialogextension.png
|
|---|
| 86 | \header
|
|---|
| 87 | \o Details extension hidden
|
|---|
| 88 | \o Details extension visible
|
|---|
| 89 | \endtable
|
|---|
| 90 |
|
|---|
| 91 | Starting from the top of the dialog there are several buttons:
|
|---|
| 92 |
|
|---|
| 93 | \image qtgradientdialogtopbuttons.png
|
|---|
| 94 |
|
|---|
| 95 | The first three buttons allow for changing a type of the gradient (QGradient::Type), while the second three allow for
|
|---|
| 96 | changing spread of the gradient (QGradient::Spread). The last button shows or hides the details extension of the dialog.
|
|---|
| 97 | Conceptually the default view with hidden details provides the full functional control over gradient editing.
|
|---|
| 98 | The additional extension with details allows to set gradient's parameters more precisely. The visibility
|
|---|
| 99 | of extension can be controlled by detailsVisible property. Moreover, if you don't want the user to
|
|---|
| 100 | switch on or off the visibility of extension you can set the detailsButtonVisible property to false.
|
|---|
| 101 |
|
|---|
| 102 | Below top buttons there is an area where edited gradient is interactively previewed.
|
|---|
| 103 | In addition the user can edit gradient type's specific parameters directly in this area by dragging
|
|---|
| 104 | appropriate handles.
|
|---|
| 105 |
|
|---|
| 106 | \table
|
|---|
| 107 | \row
|
|---|
| 108 | \o \inlineimage qtgradientdialoglineareditor.png
|
|---|
| 109 | \o \inlineimage qtgradientdialogradialeditor.png
|
|---|
| 110 | \o \inlineimage qtgradientdialogconicaleditor.png
|
|---|
| 111 | \header
|
|---|
| 112 | \o Editing linear type
|
|---|
| 113 | \o Editing radial type
|
|---|
| 114 | \o Editing conical type
|
|---|
| 115 | \row
|
|---|
| 116 | \o The user can change the start and final point positions by dragging the circular handles.
|
|---|
| 117 | \o The user can change the center and focal point positions by dragging the circular handles
|
|---|
| 118 | and can change the gradient's radius by dragging horizontal or vertical line.
|
|---|
| 119 | \o The user can change the center point by dragging the circular handle
|
|---|
| 120 | and can change the gradient's angle by dragging the big wheel.
|
|---|
| 121 | \endtable
|
|---|
| 122 |
|
|---|
| 123 | In the middle of the dialog there is an area where the user can edit gradient stops.
|
|---|
| 124 |
|
|---|
| 125 | \table
|
|---|
| 126 | \row
|
|---|
| 127 | \o \inlineimage qtgradientdialogstops.png
|
|---|
| 128 | \o \inlineimage qtgradientdialogstopszoomed.png
|
|---|
| 129 | \endtable
|
|---|
| 130 |
|
|---|
| 131 | The top part of this area contains stop handles, and bottom part shows the preview of gradient stops path.
|
|---|
| 132 | In order to create a new gradient stop double click inside the view over the desired position.
|
|---|
| 133 | If you double click on existing stop handle in the top part of the view, clicked handle will be duplicated
|
|---|
| 134 | (duplicate will contain the same color).
|
|---|
| 135 | The stop can be activated by clicking on its handle. You can activate previous or next stop by pressing
|
|---|
| 136 | left or right key respectively. To jump to the first or last stop press home or end key respectively.
|
|---|
| 137 | The gradient stops editor supports multiselection.
|
|---|
| 138 | Clicking a handle holding the shift modifier key down will select a range of stops between
|
|---|
| 139 | the active stop and clicked one. Clicking a handle holding control modifier key down will remove from or
|
|---|
| 140 | add to selection the clicked stop depending if it was or wasn't already selected respectively.
|
|---|
| 141 | Multiselection can also be created using rubberband (by pressing the left mouse button outside
|
|---|
| 142 | of any handle and dragging).
|
|---|
| 143 | Sometimes it's hard to select a stop because its handle can be partially covered by other handle.
|
|---|
| 144 | In that case the user can zoom in the view by spinning mouse wheel.
|
|---|
| 145 | The selected stop handles can be moved by drag & drop. In order to remove selected stops press delete key.
|
|---|
| 146 | For convenience context menu is provided with the following actions:
|
|---|
| 147 |
|
|---|
| 148 | \list
|
|---|
| 149 | \o New Stop - creates a new gradient stop
|
|---|
| 150 | \o Delete - removes the active and all selected stops
|
|---|
| 151 | \o Flip All - mirrors all stops
|
|---|
| 152 | \o Select All - selects all stops
|
|---|
| 153 | \o Zoom In - zooms in
|
|---|
| 154 | \o Zoom Out - zooms out
|
|---|
| 155 | \o Zoom All - goes back to original 100% zoom
|
|---|
| 156 | \endlist
|
|---|
| 157 |
|
|---|
| 158 | The bottom part of the QtGradientDialog contains a set of widgets allowing to control the color of
|
|---|
| 159 | the active and selected stops.
|
|---|
| 160 |
|
|---|
| 161 | \table
|
|---|
| 162 | \row
|
|---|
| 163 | \o \inlineimage qtgradientdialogcolorhsv.png
|
|---|
| 164 | \o \inlineimage qtgradientdialogcolorrgb.png
|
|---|
| 165 | \endtable
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | The color button shows the color of the active gradient stop. It also allows for choosing
|
|---|
| 169 | a color from standard color dialog and applying it to the
|
|---|
| 170 | active stop and all selected stops. It's also possible to drag a color directly from the color button
|
|---|
| 171 | and to drop it in gradient stops editor at desired position (it will create new stop with dragged color)
|
|---|
| 172 | or at desired stop handle (it will change the color of that handle).
|
|---|
| 173 |
|
|---|
| 174 | To the right of color button there is a set of 2 radio buttons which allows to switch between
|
|---|
| 175 | HVS and RGB color spec.
|
|---|
| 176 |
|
|---|
| 177 | Finally there are 4 color sliders working either in HSVA (hue saturation value alpha) or
|
|---|
| 178 | RGBA (red green blue alpha) mode, depending on which radio button is chosen. The radio buttons
|
|---|
| 179 | can be controlled programatically by spec() and setSpec() methods. The sliders show the
|
|---|
| 180 | color of the active stop. By double clicking inside color slider you can set directly the desired color.
|
|---|
| 181 | Changes of slider's are applied to stop selection in the way that the color
|
|---|
| 182 | component being changed is applied to stops in selection only, while other components
|
|---|
| 183 | remain unchanged in selected stops (e.g. when the user is changing the saturation,
|
|---|
| 184 | new saturation is applied to selected stops preventing original hue, value and alpha in multiselection).
|
|---|
| 185 |
|
|---|
| 186 | The convenient static functions getGradient() provide modal gradient dialogs, e.g.:
|
|---|
| 187 |
|
|---|
| 188 | \snippet doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp 0
|
|---|
| 189 |
|
|---|
| 190 | In order to have more control over the properties of QtGradientDialog use
|
|---|
| 191 | standard QDialog::exec() method:
|
|---|
| 192 |
|
|---|
| 193 | \snippet doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp 1
|
|---|
| 194 |
|
|---|
| 195 | \sa {Gradient View Example}
|
|---|
| 196 | */
|
|---|
| 197 |
|
|---|
| 198 | /*!
|
|---|
| 199 | Constructs a gradient dialog with \a parent as parent widget.
|
|---|
| 200 | */
|
|---|
| 201 |
|
|---|
| 202 | QtGradientDialog::QtGradientDialog(QWidget *parent)
|
|---|
| 203 | : QDialog(parent)
|
|---|
| 204 | {
|
|---|
| 205 | // setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|---|
| 206 | d_ptr = new QtGradientDialogPrivate();
|
|---|
| 207 | d_ptr->q_ptr = this;
|
|---|
| 208 | d_ptr->m_ui.setupUi(this);
|
|---|
| 209 | QPushButton *button = d_ptr->m_ui.buttonBox->button(QDialogButtonBox::Ok);
|
|---|
| 210 | if (button)
|
|---|
| 211 | button->setAutoDefault(false);
|
|---|
| 212 | button = d_ptr->m_ui.buttonBox->button(QDialogButtonBox::Cancel);
|
|---|
| 213 | if (button)
|
|---|
| 214 | button->setAutoDefault(false);
|
|---|
| 215 | connect(d_ptr->m_ui.gradientEditor, SIGNAL(aboutToShowDetails(bool, int)),
|
|---|
| 216 | this, SLOT(slotAboutToShowDetails(bool, int)));
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | /*!
|
|---|
| 220 | Destroys the gradient dialog
|
|---|
| 221 | */
|
|---|
| 222 |
|
|---|
| 223 | QtGradientDialog::~QtGradientDialog()
|
|---|
| 224 | {
|
|---|
| 225 | delete d_ptr;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | /*!
|
|---|
| 229 | \property QtGradientDialog::gradient
|
|---|
| 230 | \brief the gradient of the dialog
|
|---|
| 231 | */
|
|---|
| 232 | void QtGradientDialog::setGradient(const QGradient &gradient)
|
|---|
| 233 | {
|
|---|
| 234 | d_ptr->m_ui.gradientEditor->setGradient(gradient);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | QGradient QtGradientDialog::gradient() const
|
|---|
| 238 | {
|
|---|
| 239 | return d_ptr->m_ui.gradientEditor->gradient();
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | /*!
|
|---|
| 243 | \property QtGradientDialog::backgroundCheckered
|
|---|
| 244 | \brief whether the background of widgets able to show the colors with alpha channel is checkered.
|
|---|
| 245 |
|
|---|
| 246 | \table
|
|---|
| 247 | \row
|
|---|
| 248 | \o \inlineimage qtgradientdialogbackgroundcheckered.png
|
|---|
| 249 | \o \inlineimage qtgradientdialogbackgroundtransparent.png
|
|---|
| 250 | \row
|
|---|
| 251 | \o \snippet doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp 2
|
|---|
| 252 | \o \snippet doc/src/snippets/code/tools_shared_qtgradienteditor_qtgradientdialog.cpp 3
|
|---|
| 253 | \endtable
|
|---|
| 254 |
|
|---|
| 255 | When this property is set to true (the default) widgets inside gradient dialog like color button,
|
|---|
| 256 | color sliders, gradient stops editor and gradient editor will show checkered background
|
|---|
| 257 | in case of transparent colors. Otherwise the background of these widgets is transparent.
|
|---|
| 258 | */
|
|---|
| 259 |
|
|---|
| 260 | bool QtGradientDialog::isBackgroundCheckered() const
|
|---|
| 261 | {
|
|---|
| 262 | return d_ptr->m_ui.gradientEditor->isBackgroundCheckered();
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | void QtGradientDialog::setBackgroundCheckered(bool checkered)
|
|---|
| 266 | {
|
|---|
| 267 | d_ptr->m_ui.gradientEditor->setBackgroundCheckered(checkered);
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | /*!
|
|---|
| 271 | \property QtGradientDialog::detailsVisible
|
|---|
| 272 | \brief whether details extension is visible.
|
|---|
| 273 |
|
|---|
| 274 | When this property is set to true the details extension is visible. By default
|
|---|
| 275 | this property is set to false and the details extension is hidden.
|
|---|
| 276 |
|
|---|
| 277 | \sa detailsButtonVisible
|
|---|
| 278 | */
|
|---|
| 279 | bool QtGradientDialog::detailsVisible() const
|
|---|
| 280 | {
|
|---|
| 281 | return d_ptr->m_ui.gradientEditor->detailsVisible();
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | void QtGradientDialog::setDetailsVisible(bool visible)
|
|---|
| 285 | {
|
|---|
| 286 | d_ptr->m_ui.gradientEditor->setDetailsVisible(visible);
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | /*!
|
|---|
| 290 | \property QtGradientDialog::detailsButtonVisible
|
|---|
| 291 | \brief whether the details button allowing for showing and hiding details extension is visible.
|
|---|
| 292 |
|
|---|
| 293 | When this property is set to true (the default) the details button is visible and the user
|
|---|
| 294 | can show and hide details extension interactively. Otherwise the button is hidden and the details
|
|---|
| 295 | extension is always visible or hidded depending on the value of detailsVisible property.
|
|---|
| 296 |
|
|---|
| 297 | \sa detailsVisible
|
|---|
| 298 | */
|
|---|
| 299 | bool QtGradientDialog::isDetailsButtonVisible() const
|
|---|
| 300 | {
|
|---|
| 301 | return d_ptr->m_ui.gradientEditor->isDetailsButtonVisible();
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | void QtGradientDialog::setDetailsButtonVisible(bool visible)
|
|---|
| 305 | {
|
|---|
| 306 | d_ptr->m_ui.gradientEditor->setDetailsButtonVisible(visible);
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | /*!
|
|---|
| 310 | Returns the current QColor::Spec used for the color sliders in the dialog.
|
|---|
| 311 | */
|
|---|
| 312 | QColor::Spec QtGradientDialog::spec() const
|
|---|
| 313 | {
|
|---|
| 314 | return d_ptr->m_ui.gradientEditor->spec();
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | /*!
|
|---|
| 318 | Sets the current QColor::Spec to \a spec used for the color sliders in the dialog.
|
|---|
| 319 | */
|
|---|
| 320 | void QtGradientDialog::setSpec(QColor::Spec spec)
|
|---|
| 321 | {
|
|---|
| 322 | d_ptr->m_ui.gradientEditor->setSpec(spec);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | /*!
|
|---|
| 326 | Executes a modal gradient dialog, lets the user to specify a gradient, and returns that gradient.
|
|---|
| 327 |
|
|---|
| 328 | If the user clicks \gui OK, the gradient specified by the user is returned. If the user clicks \gui Cancel, the \a initial gradient is returned.
|
|---|
| 329 |
|
|---|
| 330 | The dialog is constructed with the given \a parent. \a caption is shown as the window title of the dialog and
|
|---|
| 331 | \a initial is the initial gradient shown in the dialog. If the \a ok parameter is not-null,
|
|---|
| 332 | the value it refers to is set to true if the user clicks \gui OK, and set to false if the user clicks \gui Cancel.
|
|---|
| 333 | */
|
|---|
| 334 | QGradient QtGradientDialog::getGradient(bool *ok, const QGradient &initial, QWidget *parent, const QString &caption)
|
|---|
| 335 | {
|
|---|
| 336 | QtGradientDialog dlg(parent);
|
|---|
| 337 | if (!caption.isEmpty())
|
|---|
| 338 | dlg.setWindowTitle(caption);
|
|---|
| 339 | dlg.setGradient(initial);
|
|---|
| 340 | const int res = dlg.exec();
|
|---|
| 341 | if (ok) {
|
|---|
| 342 | *ok = (res == QDialog::Accepted) ? true : false;
|
|---|
| 343 | }
|
|---|
| 344 | if (res == QDialog::Accepted)
|
|---|
| 345 | return dlg.gradient();
|
|---|
| 346 | return initial;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | /*!
|
|---|
| 350 | This method calls getGradient(ok, QLinearGradient(), parent, caption).
|
|---|
| 351 | */
|
|---|
| 352 | QGradient QtGradientDialog::getGradient(bool *ok, QWidget *parent, const QString &caption)
|
|---|
| 353 | {
|
|---|
| 354 | return getGradient(ok, QLinearGradient(), parent, caption);
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | QT_END_NAMESPACE
|
|---|
| 358 |
|
|---|
| 359 | #include "moc_qtgradientdialog.cpp"
|
|---|