Thanks Vailton,

I think it can also be a good example of working with hbqt and I translated to 
prg.
Just as exercise of programming. :)
Is this wrong?

Xavi


#define Qt_PlainText             0

#define QMessageBox_ActionRole   3
#define QMessageBox_Ok           1024

/*******************************************************************************************
* ALERT IN PRG  ( Please, NEVER use supress shortcutting! :)
* 
-----------------------------------------------------------------------------------------
* nSelectedOption := Qt_Alert_PRG( <xText>, [<aOptions>|<cOption>], [<xTitle>], 
[<nIcon>] )
********************************************************************************************/
Function QT_Alert_PRG( cText, xOption, cTitle, nIcon )
   Local cOpt, apBtnOpc := {}, nSelectedOption := 0

   if( !Empty(cText) )
      cText := StrTran( cText, ';', Chr(10) )
      WITH OBJECT QMessageBox():New()
         :setTextFormat( Qt_PlainText )
         :setText( cText )
         if( Empty(xOption) )
            AAdd( apBtnOpc, :addButton_2( QMessageBox_Ok ) )
         else
            xOption := iif( HB_IsArray(xOption), xOption, {xOption} )
            for each cOpt in xOption
               AAdd( apBtnOpc, :addButton_1( cOpt, QMessageBox_ActionRole ) )
            next
         endif
         if( !Empty(cTitle) )
            :setWindowTitle( cTitle )
         endif
         if( HB_IsNumeric(nIcon) .and. nIcon >= 0 .and. nIcon <= 4 )
            :setIcon( nIcon )
         endif
         :exec()
         nSelectedOption := AScan( apBtnOpc, :clickedButton() )
      END
   endif
return nSelectedOption

#include "hbapi.h"
#include "hbapiitm.h"
#include "QtGui/QMessageBox.h"

/*
 * ALERT() function basead on QT MessageBox. By Vailton Renato 
<vail...@gmail.com>
 * Syntax: Qt_Alert( <xText>, [<aOptions>|<cOption>], [<xTitle>], [<nIcon>] ) 
-> nSelectedOption
 * 15/04/2009 - 09:47:01
 */
HB_FUNC( QT_ALERT )
{
   QString text;
   QMessageBox  msgBox;
   //QList<QAbstractButton *> btnList;
   QList<QPushButton *> btnList;

   char *szText;
   PHB_ITEM pItem;
   BOOL fFree;
   ULONG ulSize, ulLen, ul;

   /* Text of window .. */
   if (!HB_ISNIL(1))
   {
      szText = hb_itemString( hb_param( 1, HB_IT_ANY ), &ulLen, &fFree );
      if (ulLen)
         text.append( szText );
      if( fFree )
         hb_xfree( szText );
   }

   if (text.isEmpty())
   {
      hb_retni(0);
      return;
   }

   text.replace( ';', '\n' );

   if (ISARRAY(2))
   {
      pItem  = hb_param( 2, HB_IT_ARRAY );
      ulSize = hb_arrayLen( pItem );

      for( ul = 1; ul <= ulSize; ++ul )
      {
         szText = hb_itemString( hb_arrayGetItemPtr( pItem, ul ), &ulLen, 
&fFree );
         if (ulLen)
            btnList << msgBox.addButton( szText, QMessageBox::ActionRole );
         if( fFree )
            hb_xfree( szText );
      }
   } else {
      if (!HB_ISNIL(2))
      {
         szText = hb_itemString( hb_param( 2, HB_IT_ANY ), &ulLen, &fFree );

         if (ulLen)
            btnList << msgBox.addButton( szText, QMessageBox::ActionRole );
         if( fFree )
            hb_xfree( szText );
      }
   }

   if (btnList.isEmpty())
      btnList << msgBox.addButton( QMessageBox::Ok );

   /* Title of window */
   if (!HB_ISNIL(3))
   {
      szText = hb_itemString( hb_param( 3, HB_IT_ANY ), &ulLen, &fFree );
      if (ulLen)
         msgBox.setWindowTitle( szText );
      if( fFree )
         hb_xfree( szText );
   }

   if (ISNUM(4))
   {
      int nIcon = hb_parni(4);

      if ((nIcon >= 0) && (nIcon <= 4 ))
         msgBox.setIcon( QMessageBox::Icon( nIcon ) );
   }

   msgBox.setTextFormat( Qt::PlainText );
   msgBox.setText( text );
   msgBox.exec();

   // hb_retni( btnList.indexOf( msgBox.clickedButton() ) +1 );
   hb_retni( btnList.indexOf( (QPushButton *)msgBox.clickedButton() ) +1 );
}

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to