[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "paletteeditoradvanced.h"
|
---|
| 43 | #include "colorbutton.h"
|
---|
| 44 |
|
---|
| 45 | #include <QCheckBox>
|
---|
| 46 | #include <QComboBox>
|
---|
| 47 | #include <QApplication>
|
---|
| 48 | #include <QPushButton>
|
---|
| 49 | #include <QPainter>
|
---|
| 50 | #include <QGroupBox>
|
---|
| 51 |
|
---|
| 52 | QT_BEGIN_NAMESPACE
|
---|
| 53 |
|
---|
| 54 | PaletteEditorAdvanced::PaletteEditorAdvanced( QWidget * parent,
|
---|
| 55 | const char * name, bool modal, Qt::WindowFlags f )
|
---|
| 56 | : PaletteEditorAdvancedBase( parent, name, modal, f ), selectedPalette(0)
|
---|
| 57 | {
|
---|
[561] | 58 | // work around buggy UI file
|
---|
[2] | 59 | comboEffect->setEnabled(false);
|
---|
| 60 | buttonEffect->setEnabled(false);
|
---|
| 61 | onToggleBuildEffects(true);
|
---|
| 62 |
|
---|
| 63 | editPalette = QApplication::palette();
|
---|
| 64 | setPreviewPalette( editPalette );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | PaletteEditorAdvanced::~PaletteEditorAdvanced()
|
---|
| 68 | {
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void PaletteEditorAdvanced::onToggleBuildInactive( bool v )
|
---|
| 72 | {
|
---|
| 73 | if (selectedPalette == 1) {
|
---|
| 74 | groupCentral->setDisabled(v);
|
---|
| 75 | groupEffect->setDisabled(v);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | if (v) {
|
---|
| 79 | buildInactive();
|
---|
| 80 | updateColorButtons();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void PaletteEditorAdvanced::onToggleBuildDisabled( bool v )
|
---|
| 85 | {
|
---|
| 86 | if (selectedPalette == 2) {
|
---|
| 87 | groupCentral->setDisabled(v);
|
---|
| 88 | groupEffect->setDisabled(v);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | if (v) {
|
---|
| 92 | buildDisabled();
|
---|
| 93 | updateColorButtons();
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void PaletteEditorAdvanced::paletteSelected(int p)
|
---|
| 98 | {
|
---|
| 99 | selectedPalette = p;
|
---|
| 100 |
|
---|
| 101 | if(p == 1) { // inactive
|
---|
| 102 | groupCentral->setDisabled(checkBuildInactive->isChecked());
|
---|
| 103 | groupEffect->setDisabled(checkBuildInactive->isChecked());
|
---|
| 104 | }
|
---|
| 105 | else if (p == 2) { // disabled
|
---|
| 106 | groupCentral->setDisabled(checkBuildDisabled->isChecked());
|
---|
| 107 | groupEffect->setDisabled(checkBuildDisabled->isChecked());
|
---|
| 108 | }
|
---|
| 109 | else {
|
---|
| 110 | groupCentral->setEnabled(true);
|
---|
| 111 | groupEffect->setEnabled(true);
|
---|
| 112 | }
|
---|
| 113 | updateColorButtons();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void PaletteEditorAdvanced::onChooseCentralColor()
|
---|
| 117 | {
|
---|
| 118 | switch(selectedPalette) {
|
---|
| 119 | case 0:
|
---|
| 120 | default:
|
---|
| 121 | mapToActiveCentralRole( buttonCentral->color() );
|
---|
| 122 | break;
|
---|
| 123 | case 1:
|
---|
| 124 | mapToInactiveCentralRole( buttonCentral->color() );
|
---|
| 125 | break;
|
---|
| 126 | case 2:
|
---|
| 127 | mapToDisabledCentralRole( buttonCentral->color() );
|
---|
| 128 | break;
|
---|
| 129 | }
|
---|
| 130 | updateColorButtons();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void PaletteEditorAdvanced::onChooseEffectColor()
|
---|
| 134 | {
|
---|
| 135 | switch(selectedPalette) {
|
---|
| 136 | case 0:
|
---|
| 137 | default:
|
---|
| 138 | mapToActiveEffectRole( buttonEffect->color() );
|
---|
| 139 | break;
|
---|
| 140 | case 1:
|
---|
| 141 | mapToInactiveEffectRole( buttonEffect->color() );
|
---|
| 142 | break;
|
---|
| 143 | case 2:
|
---|
| 144 | mapToDisabledEffectRole( buttonEffect->color() );
|
---|
| 145 | break;
|
---|
| 146 | }
|
---|
| 147 | updateColorButtons();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void PaletteEditorAdvanced::onToggleBuildEffects( bool on )
|
---|
| 151 | {
|
---|
| 152 | if (!on) return;
|
---|
| 153 | buildActiveEffect();
|
---|
| 154 | buildInactiveEffect();
|
---|
| 155 | buildDisabledEffect();
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | QColorGroup::ColorRole PaletteEditorAdvanced::centralFromItem( int item )
|
---|
| 159 | {
|
---|
| 160 | switch( item ) {
|
---|
| 161 | case 0:
|
---|
| 162 | return QColorGroup::Window;
|
---|
| 163 | case 1:
|
---|
| 164 | return QColorGroup::WindowText;
|
---|
| 165 | case 2:
|
---|
| 166 | return QColorGroup::Button;
|
---|
| 167 | case 3:
|
---|
| 168 | return QColorGroup::Base;
|
---|
| 169 | case 4:
|
---|
| 170 | return QColorGroup::Text;
|
---|
| 171 | case 5:
|
---|
| 172 | return QColorGroup::BrightText;
|
---|
| 173 | case 6:
|
---|
| 174 | return QColorGroup::ButtonText;
|
---|
| 175 | case 7:
|
---|
| 176 | return QColorGroup::Highlight;
|
---|
| 177 | case 8:
|
---|
| 178 | return QColorGroup::HighlightedText;
|
---|
| 179 | default:
|
---|
| 180 | return QColorGroup::NColorRoles;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | QColorGroup::ColorRole PaletteEditorAdvanced::effectFromItem( int item )
|
---|
[846] | 185 |
|
---|
[2] | 186 | {
|
---|
| 187 | switch( item ) {
|
---|
| 188 | case 0:
|
---|
| 189 | return QColorGroup::Light;
|
---|
| 190 | case 1:
|
---|
| 191 | return QColorGroup::Midlight;
|
---|
| 192 | case 2:
|
---|
| 193 | return QColorGroup::Mid;
|
---|
| 194 | case 3:
|
---|
| 195 | return QColorGroup::Dark;
|
---|
| 196 | case 4:
|
---|
| 197 | return QColorGroup::Shadow;
|
---|
| 198 | default:
|
---|
| 199 | return QColorGroup::NColorRoles;
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void PaletteEditorAdvanced::onCentral( int item )
|
---|
| 204 | {
|
---|
| 205 | QColor c;
|
---|
| 206 |
|
---|
| 207 | switch(selectedPalette) {
|
---|
| 208 | case 0:
|
---|
| 209 | default:
|
---|
| 210 | c = editPalette.active().color( centralFromItem(item) );
|
---|
| 211 | break;
|
---|
| 212 | case 1:
|
---|
| 213 | c = editPalette.inactive().color( centralFromItem(item) );
|
---|
| 214 | break;
|
---|
| 215 | case 2:
|
---|
| 216 | c = editPalette.disabled().color( centralFromItem(item) );
|
---|
| 217 | break;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | buttonCentral->setColor(c);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | void PaletteEditorAdvanced::onEffect( int item )
|
---|
| 224 | {
|
---|
| 225 | QColor c;
|
---|
| 226 | switch(selectedPalette) {
|
---|
| 227 | case 0:
|
---|
| 228 | default:
|
---|
| 229 | c = editPalette.active().color( effectFromItem(item) );
|
---|
| 230 | break;
|
---|
| 231 | case 1:
|
---|
| 232 | editPalette.inactive().color( effectFromItem(item) );
|
---|
| 233 | break;
|
---|
| 234 | case 2:
|
---|
| 235 | editPalette.disabled().color( effectFromItem(item) );
|
---|
| 236 | break;
|
---|
| 237 | }
|
---|
| 238 | buttonEffect->setColor(c);
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | void PaletteEditorAdvanced::mapToActiveCentralRole( const QColor& c )
|
---|
| 242 | {
|
---|
| 243 | QColorGroup cg = editPalette.active();
|
---|
| 244 | cg.setColor( centralFromItem(comboCentral->currentItem()), c );
|
---|
| 245 | editPalette.setActive( cg );
|
---|
| 246 |
|
---|
| 247 | buildActiveEffect();
|
---|
| 248 | if(checkBuildInactive->isChecked())
|
---|
| 249 | buildInactive();
|
---|
| 250 | if(checkBuildDisabled->isChecked())
|
---|
| 251 | buildDisabled();
|
---|
| 252 |
|
---|
| 253 | setPreviewPalette( editPalette );
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | void PaletteEditorAdvanced::mapToActiveEffectRole( const QColor& c )
|
---|
| 257 | {
|
---|
| 258 | QColorGroup cg = editPalette.active();
|
---|
| 259 | cg.setColor( effectFromItem(comboEffect->currentItem()), c );
|
---|
| 260 | editPalette.setActive( cg );
|
---|
| 261 |
|
---|
| 262 | if(checkBuildInactive->isChecked())
|
---|
| 263 | buildInactive();
|
---|
| 264 | if(checkBuildDisabled->isChecked())
|
---|
| 265 | buildDisabled();
|
---|
| 266 |
|
---|
| 267 | setPreviewPalette( editPalette );
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | void PaletteEditorAdvanced::mapToActivePixmapRole( const QPixmap& pm )
|
---|
| 271 | {
|
---|
| 272 | QColorGroup::ColorRole role = centralFromItem(comboCentral->currentItem());
|
---|
| 273 | QColorGroup cg = editPalette.active();
|
---|
| 274 | if ( !pm.isNull() )
|
---|
| 275 | cg.setBrush( role, QBrush( cg.color( role ), pm ) );
|
---|
| 276 | else
|
---|
| 277 | cg.setBrush( role, QBrush( cg.color( role ) ) );
|
---|
| 278 | editPalette.setActive( cg );
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 | buildActiveEffect();
|
---|
| 282 | if(checkBuildInactive->isChecked())
|
---|
| 283 | buildInactive();
|
---|
| 284 | if(checkBuildDisabled->isChecked())
|
---|
| 285 | buildDisabled();
|
---|
| 286 |
|
---|
| 287 | setPreviewPalette( editPalette );
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | void PaletteEditorAdvanced::mapToInactiveCentralRole( const QColor& c )
|
---|
| 291 | {
|
---|
| 292 | QColorGroup cg = editPalette.inactive();
|
---|
| 293 | cg.setColor( centralFromItem(comboCentral->currentItem()), c );
|
---|
| 294 | editPalette.setInactive( cg );
|
---|
| 295 |
|
---|
| 296 | buildInactiveEffect();
|
---|
| 297 |
|
---|
| 298 | setPreviewPalette( editPalette );
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | void PaletteEditorAdvanced::mapToInactiveEffectRole( const QColor& c )
|
---|
| 302 | {
|
---|
| 303 | QColorGroup cg = editPalette.inactive();
|
---|
| 304 | cg.setColor( effectFromItem(comboEffect->currentItem()), c );
|
---|
| 305 | editPalette.setInactive( cg );
|
---|
| 306 |
|
---|
| 307 | setPreviewPalette( editPalette );
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | void PaletteEditorAdvanced::mapToInactivePixmapRole( const QPixmap& pm )
|
---|
| 311 | {
|
---|
| 312 | QColorGroup::ColorRole role = centralFromItem(comboCentral->currentItem());
|
---|
| 313 | QColorGroup cg = editPalette.inactive();
|
---|
| 314 | if ( !pm.isNull() )
|
---|
| 315 | cg.setBrush( role, QBrush( cg.color( role ), pm ) );
|
---|
| 316 | else
|
---|
| 317 | cg.setBrush( role, QBrush( cg.color( role ) ) );
|
---|
| 318 | editPalette.setInactive( cg );
|
---|
| 319 |
|
---|
| 320 | setPreviewPalette( editPalette );
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | void PaletteEditorAdvanced::mapToDisabledCentralRole( const QColor& c )
|
---|
| 324 | {
|
---|
| 325 | QColorGroup cg = editPalette.disabled();
|
---|
| 326 | cg.setColor( centralFromItem(comboCentral->currentItem()), c );
|
---|
| 327 | editPalette.setDisabled( cg );
|
---|
| 328 |
|
---|
| 329 | buildDisabledEffect();
|
---|
| 330 |
|
---|
| 331 | setPreviewPalette( editPalette );
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | void PaletteEditorAdvanced::mapToDisabledEffectRole( const QColor& c )
|
---|
| 335 | {
|
---|
| 336 | QColorGroup cg = editPalette.disabled();
|
---|
| 337 | cg.setColor( effectFromItem(comboEffect->currentItem()), c );
|
---|
| 338 | editPalette.setDisabled( cg );
|
---|
| 339 |
|
---|
| 340 | setPreviewPalette( editPalette );
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | void PaletteEditorAdvanced::mapToDisabledPixmapRole( const QPixmap& pm )
|
---|
| 344 | {
|
---|
| 345 | QColorGroup::ColorRole role = centralFromItem(comboCentral->currentItem());
|
---|
| 346 | QColorGroup cg = editPalette.disabled();
|
---|
| 347 | if ( !pm.isNull() )
|
---|
| 348 | cg.setBrush( role, QBrush( cg.color( role ), pm ) );
|
---|
| 349 | else
|
---|
| 350 | cg.setBrush( role, QBrush( cg.color( role ) ) );
|
---|
| 351 |
|
---|
| 352 | editPalette.setDisabled( cg );
|
---|
| 353 |
|
---|
| 354 | setPreviewPalette( editPalette );
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | void PaletteEditorAdvanced::buildActiveEffect()
|
---|
| 358 | {
|
---|
| 359 | QColorGroup cg = editPalette.active();
|
---|
| 360 | QColor btn = cg.color( QColorGroup::Button );
|
---|
| 361 |
|
---|
| 362 | QPalette temp( btn, btn );
|
---|
| 363 |
|
---|
| 364 | for (int i = 0; i<5; i++)
|
---|
| 365 | cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
|
---|
| 366 |
|
---|
| 367 | editPalette.setActive( cg );
|
---|
| 368 | setPreviewPalette( editPalette );
|
---|
| 369 |
|
---|
| 370 | updateColorButtons();
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | void PaletteEditorAdvanced::buildInactive()
|
---|
| 374 | {
|
---|
| 375 | editPalette.setInactive( editPalette.active() );
|
---|
| 376 | if ( checkBuildEffect->isChecked() )
|
---|
| 377 | buildInactiveEffect();
|
---|
| 378 | else {
|
---|
| 379 | setPreviewPalette( editPalette );
|
---|
| 380 | updateColorButtons();
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | void PaletteEditorAdvanced::buildInactiveEffect()
|
---|
| 386 | {
|
---|
| 387 | QColorGroup cg = editPalette.inactive();
|
---|
| 388 |
|
---|
| 389 | QColor light, midlight, mid, dark, shadow;
|
---|
| 390 | QColor btn = cg.color( QColorGroup::Button );
|
---|
| 391 |
|
---|
| 392 | light = btn.light(150);
|
---|
| 393 | midlight = btn.light(115);
|
---|
| 394 | mid = btn.dark(150);
|
---|
| 395 | dark = btn.dark();
|
---|
| 396 | shadow = Qt::black;
|
---|
| 397 |
|
---|
| 398 | cg.setColor( QColorGroup::Light, light );
|
---|
| 399 | cg.setColor( QColorGroup::Midlight, midlight );
|
---|
| 400 | cg.setColor( QColorGroup::Mid, mid );
|
---|
| 401 | cg.setColor( QColorGroup::Dark, dark );
|
---|
| 402 | cg.setColor( QColorGroup::Shadow, shadow );
|
---|
| 403 |
|
---|
| 404 | editPalette.setInactive( cg );
|
---|
| 405 | setPreviewPalette( editPalette );
|
---|
| 406 | updateColorButtons();
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | void PaletteEditorAdvanced::buildDisabled()
|
---|
| 410 | {
|
---|
| 411 | QColorGroup cg = editPalette.active();
|
---|
| 412 | cg.setColor( QColorGroup::ButtonText, Qt::darkGray );
|
---|
| 413 | cg.setColor( QColorGroup::WindowText, Qt::darkGray );
|
---|
| 414 | cg.setColor( QColorGroup::Text, Qt::darkGray );
|
---|
| 415 | cg.setColor( QColorGroup::HighlightedText, Qt::darkGray );
|
---|
| 416 | editPalette.setDisabled( cg );
|
---|
| 417 |
|
---|
| 418 | if ( checkBuildEffect->isChecked() )
|
---|
| 419 | buildDisabledEffect();
|
---|
| 420 | else {
|
---|
| 421 | setPreviewPalette( editPalette );
|
---|
| 422 | updateColorButtons();
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | void PaletteEditorAdvanced::buildDisabledEffect()
|
---|
| 427 | {
|
---|
| 428 | QColorGroup cg = editPalette.disabled();
|
---|
| 429 |
|
---|
| 430 | QColor light, midlight, mid, dark, shadow;
|
---|
| 431 | QColor btn = cg.color( QColorGroup::Button );
|
---|
| 432 |
|
---|
| 433 | light = btn.light(150);
|
---|
| 434 | midlight = btn.light(115);
|
---|
| 435 | mid = btn.dark(150);
|
---|
| 436 | dark = btn.dark();
|
---|
| 437 | shadow = Qt::black;
|
---|
| 438 |
|
---|
| 439 | cg.setColor( QColorGroup::Light, light );
|
---|
| 440 | cg.setColor( QColorGroup::Midlight, midlight );
|
---|
| 441 | cg.setColor( QColorGroup::Mid, mid );
|
---|
| 442 | cg.setColor( QColorGroup::Dark, dark );
|
---|
| 443 | cg.setColor( QColorGroup::Shadow, shadow );
|
---|
| 444 |
|
---|
| 445 | editPalette.setDisabled( cg );
|
---|
| 446 | setPreviewPalette( editPalette );
|
---|
| 447 | updateColorButtons();
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | void PaletteEditorAdvanced::setPreviewPalette( const QPalette& pal )
|
---|
| 451 | {
|
---|
| 452 | QColorGroup cg;
|
---|
| 453 |
|
---|
| 454 | switch (selectedPalette) {
|
---|
| 455 | case 0:
|
---|
| 456 | default:
|
---|
| 457 | cg = pal.active();
|
---|
| 458 | break;
|
---|
| 459 | case 1:
|
---|
| 460 | cg = pal.inactive();
|
---|
| 461 | break;
|
---|
| 462 | case 2:
|
---|
| 463 | cg = pal.disabled();
|
---|
| 464 | break;
|
---|
| 465 | }
|
---|
| 466 | previewPalette.setActive( cg );
|
---|
| 467 | previewPalette.setInactive( cg );
|
---|
| 468 | previewPalette.setDisabled( cg );
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | void PaletteEditorAdvanced::updateColorButtons()
|
---|
| 472 | {
|
---|
| 473 | QColor central, effect;
|
---|
| 474 | switch (selectedPalette) {
|
---|
| 475 | case 0:
|
---|
| 476 | default:
|
---|
| 477 | central = editPalette.active().color( centralFromItem( comboCentral->currentItem() ) );
|
---|
| 478 | effect = editPalette.active().color( effectFromItem( comboEffect->currentItem() ) );
|
---|
| 479 | break;
|
---|
| 480 | case 1:
|
---|
| 481 | central = editPalette.inactive().color( centralFromItem( comboCentral->currentItem() ) );
|
---|
| 482 | effect = editPalette.inactive().color( effectFromItem( comboEffect->currentItem() ) );
|
---|
| 483 | break;
|
---|
| 484 | case 2:
|
---|
| 485 | central = editPalette.disabled().color( centralFromItem( comboCentral->currentItem() ) );
|
---|
| 486 | effect = editPalette.disabled().color( effectFromItem( comboEffect->currentItem() ) );
|
---|
| 487 | break;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | buttonCentral->setColor(central);
|
---|
| 491 | buttonEffect->setColor(effect);
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 | void PaletteEditorAdvanced::setPal( const QPalette& pal )
|
---|
| 495 | {
|
---|
| 496 | editPalette = pal;
|
---|
| 497 | setPreviewPalette( pal );
|
---|
| 498 | updateColorButtons();
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | QPalette PaletteEditorAdvanced::pal() const
|
---|
| 502 | {
|
---|
| 503 | return editPalette;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | void PaletteEditorAdvanced::setupBackgroundMode( Qt::BackgroundMode mode )
|
---|
| 507 | {
|
---|
| 508 | int initRole = 0;
|
---|
| 509 |
|
---|
| 510 | switch( mode ) {
|
---|
| 511 | case Qt::PaletteBackground:
|
---|
| 512 | initRole = 0;
|
---|
| 513 | break;
|
---|
| 514 | case Qt::PaletteForeground:
|
---|
| 515 | initRole = 1;
|
---|
| 516 | break;
|
---|
| 517 | case Qt::PaletteButton:
|
---|
| 518 | initRole = 2;
|
---|
| 519 | break;
|
---|
| 520 | case Qt::PaletteBase:
|
---|
| 521 | initRole = 3;
|
---|
| 522 | break;
|
---|
| 523 | case Qt::PaletteText:
|
---|
| 524 | initRole = 4;
|
---|
| 525 | break;
|
---|
| 526 | case Qt::PaletteBrightText:
|
---|
| 527 | initRole = 5;
|
---|
| 528 | break;
|
---|
| 529 | case Qt::PaletteButtonText:
|
---|
| 530 | initRole = 6;
|
---|
| 531 | break;
|
---|
| 532 | case Qt::PaletteHighlight:
|
---|
| 533 | initRole = 7;
|
---|
| 534 | break;
|
---|
| 535 | case Qt::PaletteHighlightedText:
|
---|
| 536 | initRole = 8;
|
---|
| 537 | break;
|
---|
| 538 | case Qt::PaletteLight:
|
---|
| 539 | initRole = 9;
|
---|
| 540 | break;
|
---|
| 541 | case Qt::PaletteMidlight:
|
---|
| 542 | initRole = 10;
|
---|
| 543 | break;
|
---|
| 544 | case Qt::PaletteDark:
|
---|
| 545 | initRole = 11;
|
---|
| 546 | break;
|
---|
| 547 | case Qt::PaletteMid:
|
---|
| 548 | initRole = 12;
|
---|
| 549 | break;
|
---|
| 550 | case Qt::PaletteShadow:
|
---|
| 551 | initRole = 13;
|
---|
| 552 | break;
|
---|
| 553 | default:
|
---|
| 554 | initRole = -1;
|
---|
| 555 | break;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | if ( initRole <= -1 ) return;
|
---|
| 559 |
|
---|
| 560 | if (initRole > 8 ) {
|
---|
| 561 | comboEffect->setCurrentItem( initRole - 9 );
|
---|
| 562 | }
|
---|
| 563 | else {
|
---|
| 564 | comboCentral->setCurrentItem( initRole );
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | QPalette PaletteEditorAdvanced::getPalette( bool *ok, const QPalette &init,
|
---|
| 569 | Qt::BackgroundMode mode, QWidget* parent,
|
---|
| 570 | const char* name )
|
---|
| 571 | {
|
---|
| 572 | PaletteEditorAdvanced* dlg = new PaletteEditorAdvanced( parent, name, true );
|
---|
| 573 | dlg->setupBackgroundMode( mode );
|
---|
| 574 |
|
---|
| 575 | if ( init != QPalette() )
|
---|
| 576 | dlg->setPal( init );
|
---|
| 577 | int resultCode = dlg->exec();
|
---|
| 578 |
|
---|
| 579 | QPalette result = init;
|
---|
| 580 | if ( resultCode == QDialog::Accepted ) {
|
---|
| 581 | if ( ok )
|
---|
| 582 | *ok = true;
|
---|
| 583 | result = dlg->pal();
|
---|
| 584 | } else {
|
---|
| 585 | if ( ok )
|
---|
| 586 | *ok = false;
|
---|
| 587 | }
|
---|
| 588 | delete dlg;
|
---|
| 589 | return result;
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 | QT_END_NAMESPACE
|
---|