/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#define Min(a, b)             ((a) < (b) ? (a) : (b))
#define Max(a, b)             ((a) > (b) ? (a) : (b))

static char * RightArrowLitle_xpm[] = {
"16 14 3 1",
" 	c None",
".	c #000000",
"+	c #0E9E23",
"                ",
"        ..      ",
"        .+.     ",
"        .++.    ",
"  .......+++.   ",
"  .++++++++++.  ",
"  .+++++++++++. ",
"  .++++++++++.  ",
"  .......+++.   ",
"        .++.    ",
"        .+.     ",
"        ..      ",
"                ",
"                "};


static const char* const image0_data[] = {
"16 14 4 1",
". c None",
"b c #000000",
"a c #7f7f7f",
"# c #ff0000",
"................",
"...........#....",
"...##a....###...",
"....##a..#####..",
".....#######bb..",
"......#####b....",
"......####b.....",
".....######.....",
".....##b.###....",
"....##b...###...",
"....#b.....##a..",
"...#b.......#b..",
"...b.........b..",
"................"};

static const char* const image1_data[] = {
"11 11 30 1",
". c None",
"t c #c00202",
"B c #c00404",
"r c #c10505",
"A c #c10606",
"x c #c10707",
"m c #c10808",
"q c #c20909",
"a c #c20a0a",
"g c #c20c0c",
"c c #c20d0d",
"u c #c30e0e",
"n c #c41111",
"b c #c41212",
"# c #c51515",
"d c #c72001",
"o c #c82101",
"f c #c82301",
"h c #c82501",
"e c #ca2a00",
"l c #ca2b01",
"w c #cb3001",
"z c #cc3401",
"s c #cf4000",
"i c #df7f00",
"p c #e38d00",
"k c #e38f00",
"v c #e69b00",
"y c #e69c00",
"j c #ffff00",
"...#aab....",
"..cdeefa...",
".ghijjklm..",
"noijjjjplq.",
"rejjjjjjst.",
"rejjjjjjst.",
"ufkjjjjvwx.",
".qlpjjyzA..",
"..mlsswA...",
"...aBBm....",
"..........."};

#define Min(a, b)             ((a) < (b) ? (a) : (b))
#define Max(a, b)             ((a) > (b) ? (a) : (b))

//---------------------------- initDialog ------------------------------------------------
void Wdg_RendezVous::initDialog(RendezVous *pRendezVous, int resoPix, MAP_COLOR *colorProfils, int minHeight, int fixedHeight)
{m_pRendezVous   = pRendezVous ;
 m_ResoPix       = resoPix;
 m_pColorProfils = colorProfils;
 m_FixedHeight   = fixedHeight;
 m_MinHeight     = minHeight;
 QTime   end_rdv = m_pRendezVous->m_date.time().addSecs(m_pRendezVous->m_Duree*60);
 textLabel_Heure->setText(m_pRendezVous->m_date.time().toString("hh:mm")+tr(" à ")+end_rdv.toString("hh:mm"));

 textLabel_Type->setText(m_pRendezVous->m_Type);
 QString txt = m_pRendezVous->m_Nom + " " + m_pRendezVous->m_Prenom + " " + m_pRendezVous->m_Note;
 textLabel_Nom->setText(txt);
 txt = txt.stripWhiteSpace();
 if (txt.length())
    {QToolTip::add(textLabel_Nom,   txt );
     QToolTip::add(textLabel_Type,  txt );
     QToolTip::add(textLabel_Heure, txt );
   }

 //.................. couleur ...................................
 QString color = (*colorProfils)[m_pRendezVous->m_Type];
 QColor qcol(color);

 setPaletteBackgroundColor (qcol);
 textLabel_Nom->setPaletteBackgroundColor (qcol);
 textLabel_Heure->setPaletteBackgroundColor (qcol);
 textLabel_Type->setPaletteBackgroundColor (qcol);

 m_ButtonDelete = new CMyButton(this, "Rdv01", this);
 m_ButtonDelete->setGeometry( QRect( 81, 0, 16, 16 ) );
 m_ButtonDelete->setPixmap( QPixmap((const char**)image0_data) );
 m_ButtonDelete->setFlat( TRUE );
 QToolTip::add( m_ButtonDelete, tr( "Effacer ce rendez-vous" ) );

 m_ButtonChange = new CMyButton(this, "Rdv02", this);
 m_ButtonChange->setGeometry( QRect( 98, 0, 16, 16 ) );
 m_ButtonChange->setPixmap( QPixmap((const char**)image1_data) );
 m_ButtonChange->setFlat( TRUE );
 QToolTip::add( m_ButtonChange, tr( "Modifier le rendez-vous" ) );

 m_ButtonAcceder = new CMyButton(this, "Acceder", this);
 m_ButtonAcceder->setGeometry( QRect( 115, 0, 16, 16 ) );
 m_ButtonAcceder->setPixmap( QPixmap((const char**)RightArrowLitle_xpm) );
 m_ButtonAcceder->setFlat( TRUE );
 QToolTip::add( m_ButtonAcceder, tr( "Accéder au dossier du patient" ) );
 if (m_pRendezVous->m_GUID.length()==0)
    {m_ButtonAcceder->setEnabled ( FALSE );
    }
 else
    {connect( m_ButtonAcceder, SIGNAL( Sign_ButtonClickedPtr (const char*, void *)  ),
              this ,                        SLOT(   OnButtonAccederPtr(const char*, void *)  )
            );
    }

 connect( m_ButtonDelete, SIGNAL( Sign_ButtonClickedPtr (const char*, void *)  ),
          this ,                        SLOT(   OnButtonDeleteClickedPtr(const char*, void *)  )
        );
 connect( m_ButtonChange, SIGNAL( Sign_ButtonClickedPtr (const char*, void *)  ),
          this ,                        SLOT(   OnButtonChangePtr(const char*, void *)  )
        );
 connect( textLabel_Heure,               SIGNAL( clicked ()  ),
          this ,                        SLOT(   On_textLabel_HeureClicked()  )
        );

 if (CMoteurBase::IsThisDroitExist(G_pCApp->m_Droits, "agc")) {m_ButtonDelete->setEnabled(TRUE);   m_ButtonChange->setEnabled(TRUE);}
 else                                                         {m_ButtonDelete->setEnabled(FALSE);  m_ButtonChange->setEnabled(FALSE);}
 resize ( QSize ( width (), GetHeight())) ;
}

//---------------------------- On_textLabel_HeureClicked ------------------------------------------------
/*
  QDateTime  m_date;
  long       m_Duree;
  QString    m_Nom;
  QString    m_Prenom;
  QString    m_Tel;
  QString    m_Note;
  QString    m_GUID;
  QString    m_PrisPar;
  QString    m_PrisAvec;
  QString    m_Type;
  QString    m_PrimKey;
*/

void Wdg_RendezVous::On_textLabel_HeureClicked()
{QString nom    = m_pRendezVous->m_Nom;
 QString prenom = m_pRendezVous->m_Prenom;
 QString mess   = "";

 if (nom.length() || prenom.length())        mess += tr("<b>Rendez-vous&nbsp;de&nbsp;:&nbsp;</b><br>" + nom + "&nbsp;" + prenom +"&nbsp;.<br>");
 else                                        mess += tr("<i><b>Rendez-vous&nbsp;anonyme&nbsp;:</b>&nbsp;nom&nbsp;prénom&nbsp;non&nbsp;renseignés&nbsp;.</i><br>");
 mess                                             += tr("<b>Avec&nbsp;:&nbsp;</b>"              + m_pRendezVous->m_PrisAvec+"<b>&nbsp;pris&nbsp;par&nbsp;:&nbsp;</b>"+m_pRendezVous->m_PrisPar+")&nbsp;.<br>");
 if (m_pRendezVous->m_Type.length())         mess += tr("<b>Motif&nbsp;:&nbsp;</b>"             + m_pRendezVous->m_Type  +"<br>");
                                             mess += tr("<b>Durée&nbsp;prévue&nbsp;:&nbsp;</b>" + QString::number(m_pRendezVous->m_Duree) +"&nbsp; minutes<br>");
 if (m_pRendezVous->m_Note.length())         mess += tr("Note&nbsp;:&nbsp;<i>"                  + m_pRendezVous->m_Note +"</i><br>");

 QWhatsThis::display ( mess);
}

//---------------------------- OnButtonDeleteClickedPtr ------------------------------------------------
void Wdg_RendezVous::OnButtonDeleteClickedPtr(const char*, void *ptr)
{if (ptr==0) return;
 emit Sign_RendezVousDeleteClicked(this);
}

//---------------------------- OnButtonChangePtr ------------------------------------------------
void Wdg_RendezVous::OnButtonChangePtr(const char*, void *ptr)
{if (ptr==0) return;
 emit Sign_RendezVousChangeClicked(this);
}

//---------------------------- OnButtonAccederPtr ------------------------------------------------
void Wdg_RendezVous::OnButtonAccederPtr(const char*, void *ptr)
{if (ptr==0) return;
 emit Sign_RendezVousAccederClicked(this);
}

//---------------------------- GetHeight ------------------------------------------------
int Wdg_RendezVous::GetHeight()
{int height = 0;
 if ( m_FixedHeight == 0) height = Max( m_pRendezVous->m_Duree * m_ResoPix,  m_MinHeight);
 else                     height = m_FixedHeight;
 return height;
}
