colorbutton.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                         colorbutton.cpp  -  description
00003                              -------------------
00004     begin                : Tue Apr 1 2003
00005     copyright            : (C) 2003-2006 by Ben Swerts
00006     email                : bswerts@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00019 
00027 
00028 
00029 
00031 
00032 // Qt header files
00033 #include <qcolor.h>
00034 #include <qcolordialog.h>
00035  
00036 // Xbrabo header files
00037 #include <colorbutton.h>
00038 
00042 
00044 ColorButton::ColorButton(QWidget* parent, const char* name) : QPushButton(parent, name)
00046 {
00047   pixmap = new QPixmap();
00048   setColor(QColor(0, 0, 0));
00049 
00050   connect(this, SIGNAL(resized()), this, SLOT(updatePixmap()));
00051   connect(this, SIGNAL(clicked()), this, SLOT(selectColor()));
00052 }
00053 
00055 ColorButton::ColorButton(const QColor& color, QWidget* parent, const char* name) : QPushButton(parent, name)
00057 {
00058   pixmap = new QPixmap();
00059   setColor(color);
00060 
00061   connect(this, SIGNAL(resized()), this, SLOT(updatePixmap()));
00062   connect(this, SIGNAL(clicked()), this, SLOT(selectColor()));  
00063 }
00064 
00066 ColorButton::~ColorButton()
00068 {
00069   delete pixmap;
00070 }
00071 
00073 QColor ColorButton::color() const
00075 {  
00076   return fillColor;
00077 }
00078 
00080 void ColorButton::setColor(const QColor color)
00082 {  
00083   fillColor = color;
00084   updatePixmap();
00085 }
00086 
00087 
00091 
00093 void ColorButton::resizeEvent(QResizeEvent* e)
00095 {  
00096   QPushButton::resizeEvent(e);
00097   emit resized();
00098 }
00099 
00100 
00104 
00106 void ColorButton::selectColor()
00108 {  
00109   QColor tempColor = QColorDialog::getColor(fillColor, this);
00110   if(tempColor.isValid())
00111   {
00112     setColor(tempColor);
00113     emit newColor(&fillColor);
00114   }
00115 }
00116 
00118 void ColorButton::updatePixmap()
00120 {  
00121   pixmap->resize(width() - height()/2, height()/2);
00122   pixmap->fill(fillColor);
00123   this->setPixmap(*pixmap);
00124 }
00125 

Generated on Fri May 19 14:31:54 2006 for Brabosphere by  doxygen 1.4.6-NO