//
// C++ Implementation: ThemePopup
//
// Description: 
//
//
// Author: Roland Sevin <data.medical.design@club-internet.fr>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <qcursor.h> 
#include "ThemePopup.h"

//--------------------------------- ThemePopup -----------------------------------------------------
ThemePopup::ThemePopup(QWidget * parent, const char * name )
 : QPopupMenu(parent, name)
{ if (Theme::getPath()!="")
  { QFont f = QPopupMenu::font();
    int size = Theme::getFontSize_Popups();
    if (size != -1) 
       {f.setPointSize( Theme::getFontSize_Popups() );
        QPopupMenu::setFont( f );
       }
  }
 m_CurrentPopupItem = "";
 m_RetPopupItem     = "";
 connect( this, SIGNAL( activated( int)),            this, SLOT(OnMenuActivated( int))  );
}

//--------------------------------- ThemePopup -----------------------------------------------------
ThemePopup::ThemePopup(QStringList &list, QWidget * parent, const char * name )
 : QPopupMenu(parent, name)
{ if (Theme::getPath()!="")
  { QFont f  = QPopupMenu::font();
    int size = Theme::getFontSize_Popups();
    if (size != -1) 
       {f.setPointSize( Theme::getFontSize_Popups() );
        QPopupMenu::setFont( f );
       }
  }
 //............................... chercher une zone de liste deroulante (bleue) .....................
 for ( QStringList::Iterator it =list.begin(); it != list.end(); ++it )
     { QString str = *(it);
       if (str.left(4) == "----")
               {insertSeparator();
               }
       else if (str[0]=='#')
               {int pc = str.find('#',1);
                if (pc != -1)
                   {QString icone = str.mid(1,pc-1);
                    insertItem(Theme::getIconSet(icone), str.mid(pc+1), this, SLOT( GetPopupItem()),  0 );
                   }
                else insertItem( str,    this, SLOT( GetPopupItem()),  0 );
               }
       else    {insertItem( str,    this, SLOT( GetPopupItem()),  0 );
               }
     }
 connect( this, SIGNAL( activated( int)),            this, SLOT(OnMenuActivated( int))  );
}

//--------------------------------- DoPopupList -----------------------------------------------------
QString ThemePopup::DoPopupList()
{m_CurrentPopupItem = "";
 m_RetPopupItem     = "";
 exec( QCursor::pos() /* mapToGlobal (  QPoint ( x, y) )*/ );
 return  m_RetPopupItem;
}

//--------------------------------- OnMenuActivated  --------------------------------------------------
void ThemePopup::OnMenuActivated (int id)
{if (id != -1 )
    {m_CurrentPopupItem = text(id);
    }
}

//--------------------------------- GetPopupItem  --------------------------------------------------
void ThemePopup::GetPopupItem ()
{m_RetPopupItem  = m_CurrentPopupItem;
}
