lib/ColorButton.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "ColorButton.h"
00023 #include <qcolordialog.h>
00024 
00025 ColorButton::ColorButton (QWidget *w, QColor &c) : QPushButton (w)
00026 {
00027   color = c;
00028   QObject::connect(this, SIGNAL(clicked()), this, SLOT(colorDialog()));
00029   setMaximumHeight(25);
00030   setToggleButton(FALSE);
00031   pix.resize(50, 10);
00032   setToggleType(SingleShot);
00033   readonly = FALSE;
00034   changed = FALSE;
00035 }
00036 
00037 ColorButton::~ColorButton ()
00038 {
00039 }
00040 
00041 void ColorButton::setColorButton ()
00042 {
00043   pix.fill(color);
00044   setPixmap(pix);
00045 }
00046 
00047 void ColorButton::getColor (QColor &c)
00048 {
00049   c = color;
00050 }
00051 
00052 void ColorButton::colorDialog ()
00053 {
00054   if (readonly)
00055   {
00056     emit robPressed(color);
00057   }
00058   else
00059   {
00060     QColor c = QColorDialog::getColor(color, this, 0);
00061     if (c.isValid())
00062     {
00063       if (color != c)
00064       {
00065         color = c;
00066         setColorButton();
00067         changed = TRUE;
00068         emit valueChanged();
00069       }
00070     }
00071   }
00072 }
00073 
00074 void ColorButton::setColor (QColor c)
00075 {
00076   color = c;
00077   pix.fill(color);
00078   setPixmap(pix);
00079 }
00080 
00081 void ColorButton::setDialogOff ()
00082 {
00083   readonly = TRUE;
00084 }
00085 
00086 bool ColorButton::isChanged()
00087 {
00088   bool b = changed;
00089   changed = FALSE;
00090   return b;
00091 }