You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
374 lines
9.5 KiB
374 lines
9.5 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1997 Martin Jones (mjones@kde.org)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// Selector widgets for KDE Color Selector, but probably useful for other
|
||
|
// stuff also.
|
||
|
|
||
|
#ifndef __KSELECT_H__
|
||
|
#define __KSELECT_H__
|
||
|
|
||
15 years ago
|
#include <tqwidget.h>
|
||
|
#include <tqrangecontrol.h>
|
||
|
#include <tqpixmap.h>
|
||
15 years ago
|
|
||
13 years ago
|
#include <tdelibs_export.h>
|
||
15 years ago
|
|
||
|
/**
|
||
|
* KXYSelector is the base class for other widgets which
|
||
|
* provides the ability to choose from a two-dimensional
|
||
|
* range of values. The currently chosen value is indicated
|
||
|
* by a cross. An example is the KHSSelector which
|
||
|
* allows to choose from a range of colors, and which is
|
||
|
* used in KColorDialog.
|
||
|
*
|
||
|
* A custom drawing routine for the widget surface has
|
||
|
* to be provided by the subclass.
|
||
|
*/
|
||
13 years ago
|
class TDEUI_EXPORT KXYSelector : public TQWidget
|
||
15 years ago
|
{
|
||
|
Q_OBJECT
|
||
12 years ago
|
TQ_PROPERTY( int xValue READ xValue WRITE setXValue )
|
||
|
TQ_PROPERTY( int yValue READ yValue WRITE setYValue )
|
||
15 years ago
|
|
||
|
public:
|
||
|
/**
|
||
|
* Constructs a two-dimensional selector widget which
|
||
|
* has a value range of [0..100] in both directions.
|
||
|
*/
|
||
15 years ago
|
KXYSelector( TQWidget *parent=0, const char *name=0 );
|
||
15 years ago
|
/**
|
||
|
* Destructs the widget.
|
||
|
*/
|
||
|
~KXYSelector();
|
||
|
|
||
|
/**
|
||
|
* Sets the current values in horizontal and
|
||
|
* vertical direction.
|
||
|
* @param xPos the horizontal value
|
||
|
* @param yPos the veritcal value
|
||
|
*/
|
||
|
void setValues( int xPos, int yPos );
|
||
|
|
||
|
/**
|
||
|
* Sets the current horizontal value
|
||
|
* @param xPos the horizontal value
|
||
|
*/
|
||
|
void setXValue( int xPos );
|
||
|
|
||
|
/**
|
||
|
* Sets the current vertical value
|
||
|
* @param yPos the veritcal value
|
||
|
*/
|
||
|
void setYValue( int yPos );
|
||
|
|
||
|
/**
|
||
|
* Sets the range of possible values.
|
||
|
*/
|
||
|
void setRange( int minX, int minY, int maxX, int maxY );
|
||
|
|
||
|
/**
|
||
|
* @return the current value in horizontal direction.
|
||
|
*/
|
||
|
int xValue() const { return xPos; }
|
||
|
/**
|
||
|
* @return the current value in vertical direction.
|
||
|
*/
|
||
|
int yValue() const { return yPos; }
|
||
|
|
||
|
/**
|
||
|
* @return the rectangle on which subclasses should draw.
|
||
|
*/
|
||
15 years ago
|
TQRect contentsRect() const;
|
||
15 years ago
|
|
||
|
signals:
|
||
|
/**
|
||
|
* This signal is emitted whenever the user chooses a value,
|
||
|
* e.g. by clicking with the mouse on the widget.
|
||
|
*/
|
||
|
void valueChanged( int x, int y );
|
||
|
|
||
|
protected:
|
||
|
/**
|
||
|
* Override this function to draw the contents of the widget.
|
||
|
* The default implementation does nothing.
|
||
|
*
|
||
|
* Draw within contentsRect() only.
|
||
|
*/
|
||
15 years ago
|
virtual void drawContents( TQPainter * );
|
||
15 years ago
|
/**
|
||
|
* Override this function to draw the cursor which
|
||
|
* indicates the currently selected value pair.
|
||
|
*/
|
||
15 years ago
|
virtual void drawCursor( TQPainter *p, int xp, int yp );
|
||
15 years ago
|
|
||
15 years ago
|
virtual void paintEvent( TQPaintEvent *e );
|
||
|
virtual void mousePressEvent( TQMouseEvent *e );
|
||
|
virtual void mouseMoveEvent( TQMouseEvent *e );
|
||
|
virtual void wheelEvent( TQWheelEvent * );
|
||
15 years ago
|
|
||
|
/**
|
||
|
* Converts a pixel position to its corresponding values.
|
||
|
*/
|
||
|
void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
|
||
|
|
||
|
private:
|
||
|
void setPosition( int xp, int yp );
|
||
|
int px;
|
||
|
int py;
|
||
|
int xPos;
|
||
|
int yPos;
|
||
|
int minX;
|
||
|
int maxX;
|
||
|
int minY;
|
||
|
int maxY;
|
||
15 years ago
|
TQPixmap store;
|
||
15 years ago
|
|
||
|
protected:
|
||
|
virtual void virtual_hook( int id, void* data );
|
||
|
private:
|
||
|
class KXYSelectorPrivate;
|
||
|
KXYSelectorPrivate *d;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
12 years ago
|
* TDESelector is the base class for other widgets which
|
||
15 years ago
|
* provides the ability to choose from a one-dimensional
|
||
|
* range of values. An example is the KGradientSelector
|
||
|
* which allows to choose from a range of colors.
|
||
|
*
|
||
|
* A custom drawing routine for the widget surface has
|
||
|
* to be provided by the subclass.
|
||
|
*/
|
||
12 years ago
|
class TDEUI_EXPORT TDESelector : public TQWidget, public TQRangeControl
|
||
15 years ago
|
{
|
||
|
Q_OBJECT
|
||
12 years ago
|
TQ_PROPERTY( int value READ value WRITE setValue )
|
||
|
TQ_PROPERTY( int minValue READ minValue WRITE setMinValue )
|
||
|
TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
|
||
15 years ago
|
public:
|
||
|
|
||
|
/**
|
||
|
* Constructs a horizontal one-dimensional selection widget.
|
||
|
*/
|
||
12 years ago
|
TDESelector( TQWidget *parent=0, const char *name=0 );
|
||
15 years ago
|
/**
|
||
|
* Constructs a one-dimensional selection widget with
|
||
|
* a given orientation.
|
||
|
*/
|
||
12 years ago
|
TDESelector( Orientation o, TQWidget *parent = 0L, const char *name = 0L );
|
||
15 years ago
|
/*
|
||
|
* Destructs the widget.
|
||
|
*/
|
||
12 years ago
|
~TDESelector();
|
||
15 years ago
|
|
||
|
/**
|
||
|
* @return the orientation of the widget.
|
||
|
*/
|
||
|
Orientation orientation() const
|
||
|
{ return _orientation; }
|
||
|
|
||
|
/**
|
||
|
* @return the rectangle on which subclasses should draw.
|
||
|
*/
|
||
15 years ago
|
TQRect contentsRect() const;
|
||
15 years ago
|
|
||
|
/**
|
||
|
* Sets the indent option of the widget to i.
|
||
|
* This determines whether a shaded frame is drawn.
|
||
|
*/
|
||
|
void setIndent( bool i )
|
||
|
{ _indent = i; }
|
||
|
/**
|
||
|
* @return whether the indent option is set.
|
||
|
*/
|
||
|
bool indent() const
|
||
|
{ return _indent; }
|
||
|
|
||
|
/**
|
||
|
* Sets the value.
|
||
|
*/
|
||
|
void setValue(int value)
|
||
15 years ago
|
{ TQRangeControl::setValue(value); }
|
||
15 years ago
|
|
||
|
/**
|
||
|
* @returns the value.
|
||
|
*/
|
||
|
int value() const
|
||
15 years ago
|
{ return TQRangeControl::value(); }
|
||
15 years ago
|
|
||
|
/**
|
||
|
* Sets the min value.
|
||
|
*/
|
||
|
void setMinValue(int value)
|
||
15 years ago
|
{ TQRangeControl::setMinValue(value); }
|
||
15 years ago
|
|
||
|
/**
|
||
|
* @return the min value.
|
||
|
*/
|
||
|
int minValue() const
|
||
15 years ago
|
{ return TQRangeControl::minValue(); }
|
||
15 years ago
|
|
||
|
/**
|
||
|
* Sets the max value.
|
||
|
*/
|
||
|
void setMaxValue(int value)
|
||
15 years ago
|
{ TQRangeControl::setMaxValue(value); }
|
||
15 years ago
|
|
||
|
/**
|
||
|
* @return the max value.
|
||
|
*/
|
||
|
int maxValue() const
|
||
15 years ago
|
{ return TQRangeControl::maxValue(); }
|
||
15 years ago
|
|
||
|
signals:
|
||
|
/**
|
||
|
* This signal is emitted whenever the user chooses a value,
|
||
|
* e.g. by clicking with the mouse on the widget.
|
||
|
*/
|
||
|
void valueChanged( int value );
|
||
|
|
||
|
protected:
|
||
|
/**
|
||
|
* Override this function to draw the contents of the control.
|
||
|
* The default implementation does nothing.
|
||
|
*
|
||
|
* Draw only within contentsRect().
|
||
|
*/
|
||
15 years ago
|
virtual void drawContents( TQPainter * );
|
||
15 years ago
|
/**
|
||
|
* Override this function to draw the cursor which
|
||
|
* indicates the current value. This function is
|
||
|
* always called twice, once with argument show=false
|
||
|
* to clear the old cursor, once with argument show=true
|
||
|
* to draw the new one.
|
||
|
*/
|
||
15 years ago
|
virtual void drawArrow( TQPainter *painter, bool show, const TQPoint &pos );
|
||
15 years ago
|
|
||
|
virtual void valueChange();
|
||
15 years ago
|
virtual void paintEvent( TQPaintEvent * );
|
||
|
virtual void mousePressEvent( TQMouseEvent *e );
|
||
|
virtual void mouseMoveEvent( TQMouseEvent *e );
|
||
|
virtual void wheelEvent( TQWheelEvent * );
|
||
15 years ago
|
|
||
|
private:
|
||
15 years ago
|
TQPoint calcArrowPos( int val );
|
||
|
void moveArrow( const TQPoint &pos );
|
||
15 years ago
|
|
||
|
Orientation _orientation;
|
||
|
bool _indent;
|
||
|
|
||
|
protected:
|
||
|
virtual void virtual_hook( int id, void* data );
|
||
|
private:
|
||
12 years ago
|
class TDESelectorPrivate;
|
||
|
TDESelectorPrivate *d;
|
||
15 years ago
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* The KGradientSelector widget allows the user to choose
|
||
|
* from a one-dimensional range of colors which is given as a
|
||
|
* gradient between two colors provided by the programmer.
|
||
|
*
|
||
|
* \image html kgradientselector.png "KDE Gradient Selector Widget"
|
||
|
*
|
||
|
**/
|
||
12 years ago
|
class TDEUI_EXPORT KGradientSelector : public TDESelector
|
||
15 years ago
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
12 years ago
|
TQ_PROPERTY( TQColor firstColor READ firstColor WRITE setFirstColor )
|
||
|
TQ_PROPERTY( TQColor secondColor READ secondColor WRITE setSecondColor )
|
||
|
TQ_PROPERTY( TQString firstText READ firstText WRITE setFirstText )
|
||
|
TQ_PROPERTY( TQString secondText READ secondText WRITE setSecondText )
|
||
15 years ago
|
|
||
|
public:
|
||
|
/**
|
||
|
* Constructs a horizontal color selector which
|
||
14 years ago
|
* contains a gradient between white and black.
|
||
15 years ago
|
*/
|
||
15 years ago
|
KGradientSelector( TQWidget *parent=0, const char *name=0 );
|
||
15 years ago
|
/**
|
||
|
* Constructs a colors selector with orientation o which
|
||
14 years ago
|
* contains a gradient between white and black.
|
||
15 years ago
|
*/
|
||
15 years ago
|
KGradientSelector( Orientation o, TQWidget *parent=0, const char *name=0 );
|
||
15 years ago
|
/**
|
||
|
* Destructs the widget.
|
||
|
*/
|
||
|
~KGradientSelector();
|
||
|
/**
|
||
|
* Sets the two colors which span the gradient.
|
||
|
*/
|
||
15 years ago
|
void setColors( const TQColor &col1, const TQColor &col2 )
|
||
15 years ago
|
{ color1 = col1; color2 = col2; update();}
|
||
15 years ago
|
void setText( const TQString &t1, const TQString &t2 )
|
||
15 years ago
|
{ text1 = t1; text2 = t2; update(); }
|
||
|
|
||
|
/**
|
||
|
* Set each color on its own.
|
||
|
*/
|
||
15 years ago
|
void setFirstColor( const TQColor &col )
|
||
15 years ago
|
{ color1 = col; update(); }
|
||
15 years ago
|
void setSecondColor( const TQColor &col )
|
||
15 years ago
|
{ color2 = col; update(); }
|
||
|
|
||
|
/**
|
||
|
* Set each description on its own
|
||
|
*/
|
||
15 years ago
|
void setFirstText( const TQString &t )
|
||
15 years ago
|
{ text1 = t; update(); }
|
||
15 years ago
|
void setSecondText( const TQString &t )
|
||
15 years ago
|
{ text2 = t; update(); }
|
||
|
|
||
15 years ago
|
const TQColor firstColor() const
|
||
15 years ago
|
{ return color1; }
|
||
15 years ago
|
const TQColor secondColor() const
|
||
15 years ago
|
{ return color2; }
|
||
|
|
||
15 years ago
|
const TQString firstText() const
|
||
15 years ago
|
{ return text1; }
|
||
15 years ago
|
const TQString secondText() const
|
||
15 years ago
|
{ return text2; }
|
||
|
|
||
|
protected:
|
||
|
|
||
15 years ago
|
virtual void drawContents( TQPainter * );
|
||
13 years ago
|
virtual TQSize minimumSize() const
|
||
13 years ago
|
{ return sizeHint(); }
|
||
15 years ago
|
|
||
|
private:
|
||
|
void init();
|
||
15 years ago
|
TQColor color1;
|
||
|
TQColor color2;
|
||
|
TQString text1;
|
||
|
TQString text2;
|
||
15 years ago
|
|
||
|
protected:
|
||
|
virtual void virtual_hook( int id, void* data );
|
||
|
private:
|
||
|
class KGradientSelectorPrivate;
|
||
|
KGradientSelectorPrivate *d;
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif // __KSELECT_H__
|
||
|
|