/***************************************************************************
              kscanslider.h - some helpfull widgets for kooka
                             -------------------
    begin                : Wed Jan 5 2000
    copyright            : (C) 2000 by Klaas Freitag
    email                : freitag@suse.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef KSCANSLIDER_H
#define KSCANSLIDER_H

#include <qframe.h>
#include <qslider.h>
#include <qlineedit.h>
#include <qstrlist.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qhbox.h>
/**
  *@author Klaas Freitag
  */

class QPushButton;
class QSpinBox;

/**
 * a kind of extended slider which has a spinbox beside the slider offering
 * the possibility to enter an exact numeric value to the slider. If
 * desired, the slider has a neutral button by the side. A descriptional
 * text is handled automatically.
 *
 * @author Klaas Freitag <freitag@suse.de>
 */
class KScanSlider : public QFrame
{
   Q_OBJECT
   Q_PROPERTY( int slider_val READ value WRITE slSetSlider )
   
public:
   /**
    * Create the slider.
    *
    * @param parent parent widget
    * @param text is the text describing the the slider value. If the text
    *        contains a '&', a buddy for the slider will be created.
    * @param min minimum slider value
    * @param max maximum slider value
    * @param haveStdButt make a 'set to standard'-button visible. The button
    *        appears on the left of the slider.
    * @param stdValue the value to which the standard button resets the slider.
    */
   KScanSlider( QWidget *parent, const QString& text,
		double min, double max, bool haveStdButt=false,
		int stdValue=0);
   /**
    * Destructor
    */
   ~KScanSlider();

   /**
    * @return the current slider value
    */
   int value( ) const
      { return( slider->value()); }
   
public slots:
  /**
   * sets the slider value
   */
   void		slSetSlider( int );

   /**
    * enables the complete slider.
    */
   void		setEnabled( bool b );

protected slots:
    /**
     * reverts the slider back to the standard value given in the constructor
     */
     void         slRevertValue(); 

   signals:
    /**
     * emitted if the slider value changes
     */
     void	  valueChanged( int );
		
private slots:
   void		slSliderChange( int );

private:
   QSlider	*slider;
   QLabel	*l1, *numdisp;
   QSpinBox     *m_spin;
   int          m_stdValue;
   QPushButton  *m_stdButt;
   class KScanSliderPrivate;
   KScanSliderPrivate *d;
   
};

/**
 * a entry field with a prefix text for description.
 */
class KScanEntry : public QFrame
{
   Q_OBJECT
   Q_PROPERTY( QString text READ text WRITE slSetEntry )
      
public:
   /**
    * create a new entry field prepended by text.
    * @param parent the parent widget
    * @text the prefix text
    */
   KScanEntry( QWidget *parent, const QString& text );
   // ~KScanEntry();

   /**
    * @return the current entry field contents.
    */
   QString text( ) const;

public slots:
   /**
    * set the current text
    * @param t the new string
    */
   void		slSetEntry( const QString& t );
   /**
    * enable or disable the text entry.
    * @param b set enabled if true, else disabled.
    */
   void		setEnabled( bool b ){ if( entry) entry->setEnabled( b ); }
      
protected slots:
   void         slReturnPressed( void );

signals:
   void		valueChanged( const QCString& );
   void         returnPressed( const QCString& );

private slots:
   void		slEntryChange( const QString& );
 
private:
   QLineEdit 	*entry;

   class KScanEntryPrivate;
   KScanEntryPrivate *d;
	
};


/**
 * a combobox filled with a decriptional text.
 */
class KScanCombo : public QHBox
{
   Q_OBJECT
   Q_PROPERTY( QString cbEntry READ currentText WRITE slSetEntry )
      
public:
   /**
    * create a combobox with prepended text.
    *
    * @param parent parent widget
    * @param text the text the combobox is prepended by
    * @param list a stringlist with values the list should contain.
    */
   KScanCombo( QWidget *parent, const QString& text, const QStrList& list );
   // ~KScanCombo();

   /**
    * @return the current selected text
    */
   QString      currentText( ) const;

   /**
    * @return the text a position i
    */
   QString      text( int i ) const;

   /**
    * @return the amount of list entries.
    */
   int  	count( ) const;

public slots:
   /**
    * set the current entry to the given string if it is member of the list.
    * if not, the entry is not changed.
    */
   void		slSetEntry( const QString &);

   /**
    * enable or disable the combobox.
    * @param b enables the combobox if true.
    */
   void		setEnabled( bool b){ if(combo) combo->setEnabled( b ); };

   /**
    * set an icon for a string in the combobox
    * @param pix the pixmap to set.
    * @param str the string for which the pixmap should be set.
    */
   void         slSetIcon( const QPixmap& pix, const QString& str);

   /**
    * set the current item of the combobox.
    */
   void         setCurrentItem( int i );

private slots:
   void         slFireActivated( int);
   void		slComboChange( const QString & );

signals:
   void		valueChanged( const QCString& );
   void         activated(int);

private:
   QComboBox	*combo;
   QStrList	combolist;

   class KScanComboPrivate;
   KScanComboPrivate *d;
};

#endif
