QvisColorTableButton.C 19.6 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
19 20 21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
27 28 29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37 38
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39
#include <QvisColorTableButton.h>
whitlocb's avatar
whitlocb committed
40 41 42 43 44
#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QDesktopWidget>
#include <QMenu>
whitlocb's avatar
whitlocb committed
45 46 47 48 49 50 51 52
#include <QPainter>
#include <QPixmap>

#include <ColorTableAttributes.h>
#include <ColorControlPointList.h>

#define ICON_NX 32
#define ICON_NY 16
hrchilds's avatar
hrchilds committed
53 54 55 56 57

//
// Static members.
//

whitlocb's avatar
whitlocb committed
58 59 60
int           QvisColorTableButton::numInstances = 0;
QMenu        *QvisColorTableButton::colorTableMenu = 0;
QActionGroup *QvisColorTableButton::colorTableMenuActionGroup = 0;
hrchilds's avatar
hrchilds committed
61 62 63 64
QvisColorTableButton::ColorTableButtonVector QvisColorTableButton::buttons;
int         QvisColorTableButton::numColorTableNames = 0;
QString    *QvisColorTableButton::colorTableNames = 0;
bool        QvisColorTableButton::popupHasEntries = false;
whitlocb's avatar
whitlocb committed
65
ColorTableAttributes *QvisColorTableButton::colorTableAtts = NULL;
hrchilds's avatar
hrchilds committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

// ****************************************************************************
// Method: QvisColorTableButton::QvisColorTableButton
//
// Purpose: 
//   Constructor for the QvisColorTableButton class.
//
// Arguments:
//   parent : The parent widget.
//   name   : The name to associate with this widget.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:06:13 PST 2001
//
// Modifications:
//   Brad Whitlock, Thu Feb 14 13:38:42 PST 2002
//   Added code to count the number of instances.
//
whitlocb's avatar
whitlocb committed
84 85 86
//   Brad Whitlock, Fri May  9 11:23:57 PDT 2008
//   Qt 4.
//
hrchilds's avatar
hrchilds committed
87 88
// ****************************************************************************

whitlocb's avatar
whitlocb committed
89 90
QvisColorTableButton::QvisColorTableButton(QWidget *parent) :
    QPushButton(parent), colorTable("Default")
hrchilds's avatar
hrchilds committed
91 92 93 94 95
{
    // Increase the instance count.
    ++numInstances;

    // Create the button's color table popup menu.
whitlocb's avatar
whitlocb committed
96
    if(colorTableMenu == 0)
hrchilds's avatar
hrchilds committed
97
    {
whitlocb's avatar
whitlocb committed
98 99 100 101 102
        colorTableMenuActionGroup = new QActionGroup(0);

        colorTableMenu = new QMenu(0);
        colorTableMenuActionGroup->addAction(colorTableMenu->addAction("Default"));
        colorTableMenu->addSeparator();
hrchilds's avatar
hrchilds committed
103 104 105 106 107 108 109
    }
    buttons.push_back(this);

    // Make the popup active when this button is clicked.
    connect(this, SIGNAL(pressed()), this, SLOT(popupPressed()));

    setText(colorTable);
whitlocb's avatar
whitlocb committed
110
    setIconSize(QSize(ICON_NX,ICON_NY));
hrchilds's avatar
hrchilds committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
}

// ****************************************************************************
// Method: QvisColorTableButton::~QvisColorTableButton
//
// Purpose: 
//   This is the destructor for the QvisColorTableButton class.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:06:57 PST 2001
//
// Modifications:
//   Brad Whitlock, Thu Feb 14 13:31:46 PST 2002
//   Deleted the popup menu if it exists.
//
// ****************************************************************************

QvisColorTableButton::~QvisColorTableButton()
{
    // Decrease the instance count.
    --numInstances;

    // Remove the "this" pointer from the vector.
134
    size_t index = 0;
hrchilds's avatar
hrchilds committed
135
    bool notFound = true;
136
    for(size_t i = 0; i < buttons.size() && notFound; ++i)
hrchilds's avatar
hrchilds committed
137 138 139 140 141 142 143 144 145 146 147 148
    {
        if(this == buttons[i])
        {
            notFound = false;
            index = i;
        }
    }

    // If the pointer was found, shift the pointers in the vector and pop the
    // last element.
    if(!notFound)
    {
149
        for(size_t i = index; i < buttons.size() - 1; ++i)
hrchilds's avatar
hrchilds committed
150 151 152 153 154 155
            buttons[i] = buttons[i + 1];
        buttons.pop_back();
    }

    if(numInstances == 0)
    {
whitlocb's avatar
whitlocb committed
156 157 158 159 160 161
        if(colorTableMenuActionGroup != 0)
        {
            delete colorTableMenuActionGroup;
            colorTableMenuActionGroup = 0;
        }

hrchilds's avatar
hrchilds committed
162 163
        // Delete the popup menu if it exists because it will not be deleted
        // unless we do it since it is a parentless widget.
whitlocb's avatar
whitlocb committed
164
        if(colorTableMenu != 0)
hrchilds's avatar
hrchilds committed
165
        {
whitlocb's avatar
whitlocb committed
166 167
            delete colorTableMenu;
            colorTableMenu = 0;
hrchilds's avatar
hrchilds committed
168 169 170
        }

        // Delete the color table names.
hrchilds's avatar
hrchilds committed
171 172 173 174 175 176
        if(colorTableNames != 0)
        {
            delete [] colorTableNames;
            colorTableNames = 0;
            numColorTableNames = 0;
        }
hrchilds's avatar
hrchilds committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    }
}

// ****************************************************************************
// Method: QvisColorTableButton::sizeHint
//
// Purpose: 
//   Returns the widget's preferred size.
//
// Returns:    The widget's preferred size.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:07:23 PST 2001
//
// Modifications:
//   
// ****************************************************************************

QSize
QvisColorTableButton::sizeHint() const
{
whitlocb's avatar
whitlocb committed
198
     return QSize(125, 40).expandedTo(QApplication::globalStrut());
hrchilds's avatar
hrchilds committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
}

// ****************************************************************************
// Method: QvisColorTableButton::sizePolicy
//
// Purpose: 
//   Returns the widget's size policy -- how allows itself to be resized.
//
// Returns:    The widget's size policy.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:07:55 PST 2001
//
// Modifications:
//   
// ****************************************************************************

QSizePolicy
QvisColorTableButton::sizePolicy() const
{
    return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}

// ****************************************************************************
// Method: QvisColorTableButton::useDefaultColorTable
//
// Purpose: 
//   Tells the widget to use the default color table.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:08:42 PST 2001
//
// Modifications:
hrchilds's avatar
hrchilds committed
232 233
//   Brad Whitlock, Tue Jan 17 11:41:44 PDT 2006
//   Added a tooltip so long color table names can be put in a tooltip.
hrchilds's avatar
hrchilds committed
234 235 236 237 238 239 240 241
//   
// ****************************************************************************

void
QvisColorTableButton::useDefaultColorTable()
{
    colorTable = QString("Default");
    setText(colorTable);
whitlocb's avatar
whitlocb committed
242
    setToolTip(colorTable);
whitlocb's avatar
whitlocb committed
243
    setIcon(QIcon());
hrchilds's avatar
hrchilds committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
}

// ****************************************************************************
// Method: QvisColorTableButton::setColorTable
//
// Purpose: 
//   Tells the widget to use a specified color table.
//
// Arguments:
//   ctName : The name of the color table to use.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:09:09 PST 2001
//
// Modifications:
//   Brad Whitlock, Fri Feb 15 10:15:43 PDT 2002
//   Made it set the menu text to "Default" if no color table is found.
//
hrchilds's avatar
hrchilds committed
262 263 264
//   Brad Whitlock, Tue Jan 17 11:41:44 PDT 2006
//   Added a tooltip so long color table names can be put in a tooltip.
//
hrchilds's avatar
hrchilds committed
265 266 267 268 269 270 271 272 273
// ****************************************************************************

void
QvisColorTableButton::setColorTable(const QString &ctName)
{
    if(getColorTableIndex(ctName) != -1)
    {
        colorTable = ctName;
        setText(colorTable);
whitlocb's avatar
whitlocb committed
274
        setToolTip(colorTable);
whitlocb's avatar
whitlocb committed
275
        setIcon(getIcon(ctName));
hrchilds's avatar
hrchilds committed
276 277
    }
    else
hrchilds's avatar
hrchilds committed
278 279 280
    {
        QString def("Default");
        setText(def);
whitlocb's avatar
whitlocb committed
281
        setToolTip(def);
whitlocb's avatar
whitlocb committed
282
        setIcon(QIcon());
hrchilds's avatar
hrchilds committed
283
    }
hrchilds's avatar
hrchilds committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
}

// ****************************************************************************
// Method: QvisColorTableButton::getColorTable
//
// Purpose: 
//   Returns the name of the widget's color table.
//
// Returns:    The name of the widget's color table.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:09:46 PST 2001
//
// Modifications:
//   
// ****************************************************************************

const QString &
QvisColorTableButton::getColorTable() const
{
    return colorTable;
}

//
// Qt slot functions.
//

// ****************************************************************************
// Method: QvisColorTableButton::popupPressed
//
// Purpose: 
//   This is a Qt slot function that pops up the color table popup menu when
//   the button is pressed.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:10:16 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisColorTableButton::popupPressed()
{
whitlocb's avatar
whitlocb committed
328
    if(isDown() && colorTableMenu)
hrchilds's avatar
hrchilds committed
329 330 331 332 333 334 335 336 337 338 339
    {
        // If the popup menu does not have anything in it, fill it up.
        if(!popupHasEntries)
            regeneratePopupMenu();

        QPoint p1(mapToGlobal(rect().bottomLeft()));
        QPoint p2(mapToGlobal(rect().topRight()));
        QPoint buttonMiddle(p1.x() + ((p2.x() - p1.x()) >> 1),
                            p1.y() + ((p2.y() - p1.y()) >> 1));

        // Disconnect all other color table buttons.
340
        for(size_t i = 0; i < buttons.size(); ++i)
hrchilds's avatar
hrchilds committed
341
        {
whitlocb's avatar
whitlocb committed
342 343
            disconnect(colorTableMenuActionGroup, SIGNAL(triggered(QAction *)),
                       buttons[i], SLOT(colorTableSelected(QAction *)));
hrchilds's avatar
hrchilds committed
344 345 346
        }

        // Connect this colorbutton to the popup menu.
whitlocb's avatar
whitlocb committed
347 348
        connect(colorTableMenuActionGroup, SIGNAL(triggered(QAction *)),
                this, SLOT(colorTableSelected(QAction *)));
hrchilds's avatar
hrchilds committed
349 350

        // Figure out a good place to popup the menu.
whitlocb's avatar
whitlocb committed
351 352
        int menuW = colorTableMenu->sizeHint().width();
        int menuH = colorTableMenu->sizeHint().height();
hrchilds's avatar
hrchilds committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        int menuX = buttonMiddle.x();
        int menuY = buttonMiddle.y() - (menuH >> 1);

        // Fix the X dimension.
        if(menuX < 0)
           menuX = 0;
        else if(menuX + menuW > QApplication::desktop()->width())
           menuX -= (menuW + 5);

        // Fix the Y dimension.
        if(menuY < 0)
           menuY = 0;
        else if(menuY + menuH > QApplication::desktop()->height())
           menuY -= ((menuY + menuH) - QApplication::desktop()->height());

        // Show the popup menu.         
whitlocb's avatar
whitlocb committed
369
        colorTableMenu->exec(QPoint(menuX, menuY));
hkrishna's avatar
hkrishna committed
370
        setDown(false);
hrchilds's avatar
hrchilds committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    }
}

// ****************************************************************************
// Method: QvisColorTableButton::colorTableSelected
//
// Purpose: 
//   This is a Qt slot function that is called when a color table has been
//   selected from the popup menu. The widget then emits a selectedColorTable
//   signal.
//
// Arguments:
//   index : The index of the color table chosen from the popup menu.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:11:06 PST 2001
//
// Modifications:
hrchilds's avatar
hrchilds committed
389 390
//   Brad Whitlock, Tue Jan 17 11:41:44 PDT 2006
//   Added a tooltip so long color table names can be put in a tooltip.
whitlocb's avatar
whitlocb committed
391 392 393 394
//
//   Brad Whitlock, Fri May  9 11:39:40 PDT 2008
//   Qt 4.
//
hrchilds's avatar
hrchilds committed
395 396 397
// ****************************************************************************

void
whitlocb's avatar
whitlocb committed
398
QvisColorTableButton::colorTableSelected(QAction *action)
hrchilds's avatar
hrchilds committed
399
{
whitlocb's avatar
whitlocb committed
400 401
    int index = colorTableMenuActionGroup->actions().indexOf(action);

hrchilds's avatar
hrchilds committed
402 403
    if(index == 0)
    {
hrchilds's avatar
hrchilds committed
404 405 406
        QString def("Default");
        emit selectedColorTable(true, def);
        setText(def);
whitlocb's avatar
whitlocb committed
407
        setToolTip(def);
whitlocb's avatar
whitlocb committed
408
        setIcon(QIcon());
hrchilds's avatar
hrchilds committed
409
    }
whitlocb's avatar
whitlocb committed
410
    else
hrchilds's avatar
hrchilds committed
411
    {
whitlocb's avatar
whitlocb committed
412 413
        emit selectedColorTable(false, colorTableNames[index - 1]);
        setText(colorTableNames[index-1]);
whitlocb's avatar
whitlocb committed
414
        setIcon(getIcon(colorTableNames[index - 1]));
whitlocb's avatar
whitlocb committed
415
        setToolTip(colorTableNames[index-1]);
hrchilds's avatar
hrchilds committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
    }
}

//
// Static methods...
//

// ****************************************************************************
// Method: QvisColorTableButton::clearAllColorTables
//
// Purpose: 
//   This is a static method to clear all of the known color tables.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:12:33 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisColorTableButton::clearAllColorTables()
{
    delete [] colorTableNames;
    colorTableNames = 0;
    numColorTableNames = 0;

    // Clear out the popup menu.
    popupHasEntries = false;
}

// ****************************************************************************
// Method: QvisColorTableButton::addColorTable
//
// Purpose: 
//   This is a static method that tells the widget about a new color table.
//
// Arguments:
//   ctName : The name of the new color table.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:13:09 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisColorTableButton::addColorTable(const QString &ctName)
{
    QString *newList = new QString[numColorTableNames + 1];
    for(int i = 0; i < numColorTableNames; ++i)
        newList[i] = colorTableNames[i];
    newList[numColorTableNames] = ctName;
    if(colorTableNames != NULL)
        delete [] colorTableNames;
    colorTableNames = newList;
    ++numColorTableNames;
}

// ****************************************************************************
// Method: QvisColorTableButton::updateColorTableButtons
//
// Purpose: 
//   This is a static method that iterates through all instances of
//   QvisColorTableButton to make sure that the color table that they use is
//   a valid color table. This will also be used to update their color table
//   pixmaps -- someday.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:13:46 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisColorTableButton::updateColorTableButtons()
{
495
    for(size_t i = 0; i < buttons.size(); ++i)
hrchilds's avatar
hrchilds committed
496 497 498 499 500 501 502 503
    {
        // If the color table that was being used by the button is no
        // longer in the list, make it use the default.
        if(getColorTableIndex(buttons[i]->getColorTable()) == -1)
        {
            buttons[i]->setText("Default");
            buttons[i]->setColorTable("Default");
        }
whitlocb's avatar
whitlocb committed
504 505
        else
            buttons[i]->setIcon(getIcon(buttons[i]->text()));
hrchilds's avatar
hrchilds committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    }
}

// ****************************************************************************
// Method: QvisColorTableButton::getColorTableIndex
//
// Purpose: 
//   Returns the index of the specified color table in the internal color
//   table list. If the color table is not found, -1 is returned.
//
// Arguments:
//   ctName : The name of the color table to look for.
//
// Returns:    The index of the color table, or -1.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:15:16 PST 2001
//
// Modifications:
//   
// ****************************************************************************

int
QvisColorTableButton::getColorTableIndex(const QString &ctName)
{
    int retval = -1;
    if(colorTableNames)
    {
        for(int i = 0; i < numColorTableNames; ++i)
        {
            if(colorTableNames[i] == ctName)
            {
                retval = i;
                break;
            }
        }
    }

    return retval;
}

// ****************************************************************************
// Method: QvisColorTableButton::regeneratePopupMenu
//
// Purpose: 
//   This method is called when the popup menu needs to be regenerated. This
//   happens when the color table list changes.
//
// Programmer: Brad Whitlock
// Creation:   Sat Jun 16 20:16:34 PST 2001
//
// Modifications:
whitlocb's avatar
whitlocb committed
558 559 560
//   Brad Whitlock, Fri May  9 11:21:28 PDT 2008
//   Qt 4.
//
whitlocb's avatar
whitlocb committed
561 562 563
//   Brad Whitlock, Wed Apr 25 13:32:01 PDT 2012
//   Add pixmaps of the color table.
//
hrchilds's avatar
hrchilds committed
564 565 566 567 568 569
// ****************************************************************************

void
QvisColorTableButton::regeneratePopupMenu()
{
    // Remove all items and add the default.
whitlocb's avatar
whitlocb committed
570 571 572 573 574 575 576
    QList<QAction*> actions = colorTableMenuActionGroup->actions();
    for(int i = 0; i < actions.count(); ++i)
        colorTableMenuActionGroup->removeAction(actions[i]);
    colorTableMenu->clear();

    colorTableMenuActionGroup->addAction(colorTableMenu->addAction("Default"));
    colorTableMenu->addSeparator();
whitlocb's avatar
whitlocb committed
577

hrchilds's avatar
hrchilds committed
578 579
    // Add an item for each color table.
    for(int i = 0; i < numColorTableNames; ++i)
whitlocb's avatar
whitlocb committed
580 581 582 583
    {
        QAction *action = colorTableMenu->addAction(makeIcon(colorTableNames[i]), colorTableNames[i]);
        colorTableMenuActionGroup->addAction(action);
    }
hrchilds's avatar
hrchilds committed
584 585 586 587

    // Indicate that we've added choices to the menu.
    popupHasEntries = true;
}
whitlocb's avatar
whitlocb committed
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668

// ****************************************************************************
// Method: QvisColorTableButton::getIcon
//
// Purpose: 
//   This method gets the existing icon or makes one if necessary.
//
// Programmer: Brad Whitlock
// Creation:   Wed Apr 25 16:04:54 PDT 2012
//
// Modifications:
//
// ****************************************************************************

QIcon
QvisColorTableButton::getIcon(const QString &ctName)
{
    QList<QAction*> a = colorTableMenuActionGroup->actions();
    for(int i = 0; i < a.size(); ++i)
        if(a[i]->text() == ctName)
            return a[i]->icon();

    return makeIcon(ctName);
}

// ****************************************************************************
// Method: QvisColorTableButton::makeIcon
//
// Purpose: 
//   This method makes an icon from the color table definition.
//
// Programmer: Brad Whitlock
// Creation:   Wed Apr 25 16:04:54 PDT 2012
//
// Modifications:
//
// ****************************************************************************

QIcon
QvisColorTableButton::makeIcon(const QString &ctName)
{
    QIcon icon;
    const ColorControlPointList *cTable = NULL;
    if(colorTableAtts != NULL)
        cTable = colorTableAtts->GetColorControlPoints(ctName.toStdString());
    if(cTable != NULL)
    {
        QPixmap pix(ICON_NX, ICON_NY);
        unsigned char rgb[ICON_NX*3];
        cTable->GetColors(rgb, ICON_NX);
        QPainter paint(&pix);
        for(int ii = 0; ii < ICON_NX; ++ii)
        {
            paint.setPen(QPen(QColor((int)rgb[3*ii+0], (int)rgb[3*ii+1], (int)rgb[3*ii+2])));
            paint.drawLine(ii, 0, ii, ICON_NY-1);
        }

        icon = QIcon(pix);
    }

    return icon;
}

// ****************************************************************************
// Method: QvisColorTableButton::setColorTableAttributes
//
// Purpose: 
//   This method sets the color table attributes.
//
// Programmer: Brad Whitlock
// Creation:   Wed Apr 25 16:04:54 PDT 2012
//
// Modifications:
//
// ****************************************************************************

void
QvisColorTableButton::setColorTableAttributes(ColorTableAttributes *cAtts)
{
    colorTableAtts = cAtts;
}