
   /*  kopeteballoon.cpp  -  Nice Balloon

    Copyright (c) 2002      by Duncan Mac-Vicar Prett <duncan@kde.org>

    Kopete    (c) 2002-2003      by the Kopete developers  <kopete-devel@kde.org>

    Portions of this code based on Kim Applet code
    Copyright (c) 2000-2002 by Malte Starostik        <malte@kde.org>

    *************************************************************************
    *                                                                       *
    * 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.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <qimage.h>
#include <qpointarray.h>
#include <qpushbutton.h>
#include <qtooltip.h>
#include <qlayout.h>
#include <kdeversion.h>
#if KDE_VERSION <= 320
#include <kglobalsettings.h>
#endif
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <kapplication.h>
#include <kdialog.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kactivelabel.h>
#include <kmessagebox.h>
#include <qpixmap.h>

#include "notify.h"
#include "docking.h"
#include "configuration.h"

KopeteBalloon::KopeteBalloon(const QString &text)
: QWidget(0L, "KopeteBalloon", WStyle_StaysOnTop | 
	WStyle_Customize |  WX11BypassWM)
{
    KStandardDirs *dirs = KGlobal::dirs();
    QString themePath;
    themePath = dirs->findResource ("data", "kdsl/pics/");
 // setBackgroundMode( QWidget::NoBackground);

   QString nthemedir;
  nthemedir = gpppdata.themename(); 
// setBackgroundPixmap(themePath + "notifybg.png"); 
 setPaletteBackgroundPixmap(themePath + "notifybg.png"); 
 // setScaledContents(TRUE);
 resize(148,120);
// QLabel *mCaption = new QLabel(text, this, "mCaption");

	setCaption("");

	QVBoxLayout *BalloonLayout = new QVBoxLayout(this, 0,
		KDialog::spacingHint(), "BalloonLayout");
//		 unsetPalette();
 QLabel *mCaption = new QLabel(text, this, "mCaption"); 		
 //    mCaption->setBackgroundOrigin(Parent);
	BalloonLayout->addWidget(mCaption);
// mCaption->unsetPalette();

}

void KopeteBalloon::setAnchor(const QPoint &anchor)
{
	mAnchor = anchor;
	 #if KDE_VERSION <= 320
		QRect deskRect = KGlobalSettings::desktopGeometry(mAnchor);
	#else
		QDesktopWidget* tmp = QApplication::desktop();
		QRect deskRect = tmp->screenGeometry(tmp->screenNumber(mAnchor));
	#endif
//	KMessageBox::information(this, i18n("Height = %1  Width = %2 .Good Luck!").arg(mAnchor.x()).arg(mAnchor.y()));
	bool bottom = (mAnchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
	bool right = (mAnchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));	

//	bool bottom = (mAnchor.y() + height()) > (deskRect.height() - 48);
//	bool right = (mAnchor.x() + width()) > (deskRect.width() - 48);
		
	move( right ? mAnchor.x() - width() : ( mAnchor.x() < 0 ? 0 : mAnchor.x() ),
	      bottom ? mAnchor.y() - height() : ( mAnchor.y() < 0 ? 0 : mAnchor.y() )  );

//	move(right ? mAnchor.x() - width() : mAnchor.x(),
//	     bottom ? mAnchor.y() - height() : mAnchor.y());	    
//	KMessageBox::information(this, i18n("Height = %1  Width = %2 .Good Luck!").arg(mAnchor.x()).arg(mAnchor.y()));
//	move (1024 - mAnchor.x(),868-mAnchor.y());  	
}
