/***************************************************************************
 *   Copyright (C) 2004 by Armando Navarro-Vazquez                         *
 *   qoajnv@usc.es                                                         *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program 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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <iostream>

#include <qtimer.h>
#include <qcursor.h>
#include "qtimeropenmenu.h"
//Added by qt3to4:
#include <Q3PopupMenu>
#include <QEvent>

QTimerOpenMenu::QTimerOpenMenu(QWidget* parent, const char* name)
    : Q3PopupMenu(parent, name)
{
  m_timer=new QTimer(this);
  parent->installEventFilter(this);
  connect(m_timer,SIGNAL(timeout()),this,SLOT(open()));

}


QTimerOpenMenu::~QTimerOpenMenu()
{}

void QTimerOpenMenu::start(int time /*=5*/)
{
  m_pos=QCursor::pos();
  m_timer->start(time,true);

}

void QTimerOpenMenu::open()
{
  this->exec(QCursor::pos());
}

/* calling mouseMoveEvent(QMouseEvent*) does not work till the menu is shown*/
/** This introduces a lot of overhead so try to search for another solution*/
bool QTimerOpenMenu::eventFilter(QObject* watched,QEvent* e)
{

  if( e->type()==QEvent::MouseMove && m_timer->isActive() )
  {
    m_timer->stop();
  }
  return false;
}


