/********************f*******************************************************
                          dockwidget.h  -  description
                             -------------------
    begin                : Mon Apr 23 2001
    copyright            : (C) 2001 by Dieter Landolt
    email                : dieter.landolt@secs.ch
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 DOCKWIDGET_H
#define DOCKWIDGET_H

#include <qwidget.h>
#include <ksystemtray.h>
#include <kstandarddirs.h>
#include <qfileinfo.h>

// #include <kiconloader.h>

#include <qwidget.h>
#include <qpixmap.h>
#include <qtimer.h>
#include <qevent.h>
#include <qmovie.h>

class QPoint;

/**Das Widget welches ins Panel eindocken soll
  *@author Dieter Landolt
  */

class DockWidget : public KSystemTray  {
   Q_OBJECT
public: 
  /**
   * Type off Keyboard Led
   *
  */
  enum Type {Numlock, Capslock, Scrollock };
	
   DockWidget(QWidget *parent=0,
	           const char *name=0,
	           DockWidget::Type type=DockWidget::Capslock);
   ~DockWidget();
	
  /**
   * Status of the light is on/off.
   * @short LED on/off.
   */
  enum State { Off=false, On=true, Undeff=-10 };

  /**
   * Sets the state of the widget to On or Off.
   *
   * The widget will be painted immediately.
   * @see on() off() toggle() toggleState()
   *
   * @param state The LED state: on or off.
   * @short Set LED state.
   */
  // void setState( State state );
  void toggleState();
  /** Overwrites the default Mouse Event */
  void mousePressEvent(QMouseEvent *e);
  /** Ask if is locked or not */
  bool isLocked() {
    return keylocked;
  }

public slots:
  /**
   * Sets the state of the widget to On or Off.
   *
   * The widget will be painted immediately.
   * @see on() off() toggle() toggleState()
   *
   * @param state The LED state: on or off.
   * @short Set LED state.
   */
  void setState( State state );

  /**
   * Toggle the state of the led from Off to On or vice versa.
   *
   * The widget repaints itself immediately.
   */
  void toggle();
  void toggle(int);

  /**
   * Sets the state of the widget to On.
   *
   * The widget will be painted immediately.
   * @see off() toggle() toggleState() setState()
   */
  void on();

  /**
   * Sets the state of the widget to Off.
   *
   * The widget will be painted immediately.
   * @see on() toggle() toggleState() setState()
   */
  void off();

  /**
   * Checks the State of the Global Numlock... Items
   *
   * Set the State to the state of the Keyboard
   * @see on() toggle() toggleState() setState()
   */

    /*!
        MovieButton::slotStatus(int state)
	Needes for Workaround an Infinite Loop on MNG Files 
	to Workaround a bug by QT
     */
    void slotStatusOn(int state)
    {
    if (state == QMovie::EndOfLoop)
         movOn.pause();
    }
    void slotStatusOff(int state)
    {
    if (state == QMovie::EndOfLoop)
         movOff.pause();
    }
    // QT End Workarournd
  void checkState();
  /** uses the hide or show dependig from bool show */
  virtual void changeVisible(int s);
  /** Paints a Iconon into a pixmap and returns it to the caller.
It's the default icon, witch can be used. */
  static QPixmap paintIcon(State state);
  /** return the state for the led */
  bool getState();
  /** read's the configuration after change is notified */
  void readConfig();
  /** to set the key locked or unlockef */
  void setlocked(bool state);
  /** Lets Paint */
    /*!
        DockWidget::lockOn()
     */
    void lockOn()
    {
        setlocked(true);
	repaint();
    }

    /*!
        \fn DockWidget::lockOff()
     */
    void lockOff()
    {
        setlocked(false);
	repaint();
    }

    /*!
        \fn DockWidget::lockToggle()
     */
    void lockToggle()
    {
        setlocked(! keylocked);
	repaint();
    }
protected slots: // Protected attributes
  void paintEvent(QPaintEvent *ev);
private:
  State led_state;
  Type  led_type;
  QString *sname;
    /*!
        \fn kkeyleddtlcfg::locate(QString type, QString filename)
	I build the funktion with the return QString::null if file is not found
     */
    QString locate(QString type, QString filename)
    {
	QFileInfo fi;
	fi.setFile(KGlobal::dirs()->findResource(type,filename));
	if ( fi.isFile() ) {
		return fi.absFilePath();
	} else {
		return QString::null;
	}
    }

signals: // Signals
  /** tels to all that the state is changed */
  void stateChanged(bool);
private slots: // Private slots
  /** Handels the Contextmenu */
  virtual void menuHandler(int menuitem);
public: // Public attributes
  /** The effektive Position of the widget in the Panel after a Mousbutton is pressed */
  static QPoint *globalPos;
protected: // Protected attributes
  /** Holds the pixmap for the off state */
  QPixmap pixOff;
  /** Holds the pixmap for the on State */
  QPixmap pixOn;
  /** Holds the soundpath for the off state */
  QString soundOffPath;
  /** Holds the soundpath for the on State */
  QString soundOnPath;
  /** idendifies if it should use the pixmaps or draw the led internali */
  bool usepixmap;
  /** idendifies if it should use the sound or be quiet */
  bool usesounds;
  /** is set if the button shold lock the state */
  bool keylocked;
  /** Holds the movie for the off State */
  QMovie movOff;
  /** Holds the movie for the on State */
  QMovie movOn;
};

#endif


syntax highlighted by Code2HTML, v. 0.9.1