summaryrefslogtreecommitdiff
path: root/libopie/colordialog.cpp
Side-by-side diff
Diffstat (limited to 'libopie/colordialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/colordialog.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/libopie/colordialog.cpp b/libopie/colordialog.cpp
index 684d6ea..35f15d6 100644
--- a/libopie/colordialog.cpp
+++ b/libopie/colordialog.cpp
@@ -12,96 +12,101 @@
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "colordialog.h"
#include "qpainter.h"
#include "qlayout.h"
#include "qlabel.h"
#include "qpushbutton.h"
#include "qlineedit.h"
#include "qimage.h"
#include "qpixmap.h"
#include "qdrawutil.h"
#include "qvalidator.h"
#include "qdragobject.h"
#include "qapplication.h"
#include "qdragobject.h"
static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
{
QColor c;
c.setRgb( rgb );
c.getHsv(h,s,v);
}
+/*
+ * avoid clashes with the original Qt
+ */
+namespace {
+
class QColorPicker : public QFrame
{
Q_OBJECT
public:
QColorPicker(QWidget* parent=0, const char* name=0);
~QColorPicker();
public slots:
void setCol( int h, int s );
signals:
void newCol( int h, int s );
protected:
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
void drawContents(QPainter* p);
void mouseMoveEvent( QMouseEvent * );
void mousePressEvent( QMouseEvent * );
private:
int hue;
int sat;
QPoint colPt();
int huePt( const QPoint &pt );
int satPt( const QPoint &pt );
void setCol( const QPoint &pt );
QPixmap *pix;
};
static int pWidth = 200;
static int pHeight = 200;
class QColorLuminancePicker : public QWidget
{
Q_OBJECT
public:
QColorLuminancePicker(QWidget* parent=0, const char* name=0);
~QColorLuminancePicker();
public slots:
void setCol( int h, int s, int v );
void setCol( int h, int s );
signals:
void newHsv( int h, int s, int v );
@@ -562,290 +567,292 @@ void QColorShower::hsvEd()
val = vEd->val();
curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
emit newCol( currentColor() );
}
void QColorShower::setRgb( QRgb rgb )
{
rgbOriginal = TRUE;
curCol = rgb;
rgb2hsv( currentColor(), hue, sat, val );
hEd->setNum( hue );
sEd->setNum( sat );
vEd->setNum( val );
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
}
void QColorShower::setHsv( int h, int s, int v )
{
rgbOriginal = FALSE;
hue = h; val = v; sat = s; //Range check###
curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
hEd->setNum( hue );
sEd->setNum( sat );
vEd->setNum( val );
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
}
+}
+
class OColorDialogPrivate : public QObject
{
Q_OBJECT
public:
OColorDialogPrivate( OColorDialog *p );
QRgb currentColor() const { return cs->currentColor(); }
- void setCurrentColor( QRgb rgb );
+ void setCurrentColor( const QRgb& rgb );
int currentAlpha() const { return cs->currentAlpha(); }
void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
void showAlpha( bool b ) { cs->showAlpha( b ); }
private slots:
void newHsv( int h, int s, int v );
void newColorTypedIn( QRgb rgb );
private:
QColorPicker *cp;
QColorLuminancePicker *lp;
QColorShower *cs;
};
//sets all widgets to display h,s,v
void OColorDialogPrivate::newHsv( int h, int s, int v )
{
cs->setHsv( h, s, v );
cp->setCol( h, s );
lp->setCol( h, s, v );
}
//sets all widgets to display rgb
-void OColorDialogPrivate::setCurrentColor( QRgb rgb )
+void OColorDialogPrivate::setCurrentColor( const QRgb& rgb )
{
cs->setRgb( rgb );
newColorTypedIn( rgb );
}
//sets all widgets exept cs to display rgb
void OColorDialogPrivate::newColorTypedIn( QRgb rgb )
{
int h, s, v;
rgb2hsv(rgb, h, s, v );
cp->setCol( h, s );
lp->setCol( h, s, v);
}
OColorDialogPrivate::OColorDialogPrivate( OColorDialog *dialog ) :
QObject(dialog)
{
int border = 2;
QVBoxLayout *topLay = new QVBoxLayout( dialog, border, 2 );
QHBoxLayout *pickLay = new QHBoxLayout( topLay );
cp = new QColorPicker( dialog );
cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
pickLay->addWidget( cp );
pickLay->addStretch();
lp = new QColorLuminancePicker( dialog );
lp->setFixedWidth( 20 ); //###
pickLay->addWidget( lp );
connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
topLay->addStretch();
cs = new QColorShower( dialog );
connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
topLay->addWidget( cs );
}
// BEING REVISED: jo
/*!
\class OColorDialog OColorDialog.h
\brief The OColorDialog class provides a dialog widget for specifying colors.
\ingroup dialogs
The color dialog's function is to allow users to choose colors -
for instance, you might use this in a drawing program to allow the
user to set the brush color.
This version of Qt only provides modal color dialogs. The static
getColor() function shows the dialog and allows the user to specify a color,
while getRgba() does the same but allows the user to specify a color with an
alpha channel (transparency) value.
The user can store customCount() different custom colors. The custom
colors are shared by all color dialogs, and remembered during the
execution of the program. Use setCustomColor() to set the
custom colors, and customColor() to get them.
<img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
*/
/*!
Constructs a default color dialog. Use setColor() for setting an initial value.
\sa getColor()
*/
OColorDialog::OColorDialog(QWidget* parent, const char* name, bool modal) :
QDialog(parent, name, modal )
{
d = new OColorDialogPrivate( this );
}
/*!
Pops up a modal color dialog letting the user choose a color and returns
that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
the dialog. All colors allocated by the dialog will be deallocated
before this function returns.
*/
-QColor OColorDialog::getColor( QColor initial, QWidget *parent,
+QColor OColorDialog::getColor( const QColor& initial, QWidget *parent,
const char *name )
{
int allocContext = QColor::enterAllocContext();
OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal
if ( parent && parent->icon() && !parent->icon()->isNull() )
dlg->setIcon( *parent->icon() );
else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
dlg->setIcon( *qApp->mainWidget()->icon() );
dlg->setCaption( OColorDialog::tr( "Select color" ) );
dlg->setColor( initial );
dlg->showMaximized();
int resultCode = dlg->exec();
QColor::leaveAllocContext();
QColor result;
if ( resultCode == QDialog::Accepted ) {
result = dlg->color();
} else {
result = initial;
}
QColor::destroyAllocContext(allocContext);
delete dlg;
return result;
}
/*!
Pops up a modal color dialog, letting the user choose a color and an
alpha channel value. The color+alpha is initially set to \a initial.
If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
and FALSE if the user clicked Cancel.
If the user clicks Cancel the \a initial value is returned.
*/
-QRgb OColorDialog::getRgba( QRgb initial, bool *ok,
+QRgb OColorDialog::getRgba( const QRgb& initial, bool *ok,
QWidget *parent, const char* name )
{
int allocContext = QColor::enterAllocContext();
OColorDialog *dlg = new OColorDialog( parent, name, TRUE ); //modal
dlg->setColor( initial );
dlg->setSelectedAlpha( qAlpha(initial) );
dlg->showMaximized();
int resultCode = dlg->exec();
QColor::leaveAllocContext();
QRgb result = initial;
if ( resultCode == QDialog::Accepted ) {
QRgb c = dlg->color().rgb();
int alpha = dlg->selectedAlpha();
result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
}
if ( ok )
*ok = resultCode == QDialog::Accepted;
QColor::destroyAllocContext(allocContext);
delete dlg;
return result;
}
/*!
Returns the color currently selected in the dialog.
\sa setColor()
*/
QColor OColorDialog::color() const
{
return QColor(d->currentColor());
}
/*! Destructs the dialog and frees any memory it allocated.
*/
OColorDialog::~OColorDialog()
{
//d inherits QObject, so it is deleted by Qt.
}
/*!
Sets the color shown in the dialog to \a c.
\sa color()
*/
-void OColorDialog::setColor( QColor c )
+void OColorDialog::setColor( const QColor& c )
{
d->setCurrentColor( c.rgb() );
}
/*!
Sets the initial alpha channel value to \a a, and show the alpha channel
entry box.
*/
void OColorDialog::setSelectedAlpha( int a )
{
d->showAlpha( TRUE );
d->setCurrentAlpha( a );
}
/*!
Returns the value selected for the alpha channel.
*/
int OColorDialog::selectedAlpha() const
{
return d->currentAlpha();
}
#include "colordialog.moc"