/***************************************************************************
 *   Copyright (C) 2008 by SK Communications.                              *
 *   http://kldp.net/projects/nateon/                                      *
 *                                                                         *
 *   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 3 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 "memoviewinterface.h"

#include <qvariant.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qtoolbutton.h>
#include <qtextedit.h>
// #include <qcheckbox.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>

static const unsigned char image0_data[] = { 
    0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
    0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
    0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x03,
    0x46, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0x85, 0x93, 0xff, 0x6b, 0x94,
    0x75, 0x00, 0xc7, 0x5f, 0xf7, 0x3c, 0xcf, 0xdd, 0xcd, 0x7b, 0x6e, 0x9d,
    0xe7, 0x7d, 0xdb, 0x8d, 0xcd, 0x6d, 0xe7, 0xdc, 0xdc, 0xe6, 0x35, 0xd7,
    0x34, 0x0a, 0xc3, 0x4d, 0xa4, 0x44, 0x8d, 0x48, 0xc2, 0x88, 0x92, 0xa0,
    0x41, 0x7e, 0x01, 0x09, 0x6c, 0x0a, 0x92, 0x62, 0x6b, 0x14, 0x8b, 0xa6,
    0x46, 0xf4, 0x65, 0x54, 0x3f, 0xc4, 0x4a, 0x4a, 0x42, 0xc2, 0xe9, 0x74,
    0x4d, 0x9a, 0xc6, 0xd2, 0xdc, 0x5a, 0xad, 0x95, 0x73, 0x67, 0x18, 0xd5,
    0x6e, 0x6d, 0xed, 0x5b, 0x76, 0x9e, 0xdb, 0xdd, 0xed, 0xf9, 0xf2, 0x79,
    0xfa, 0xe1, 0xea, 0x97, 0x0a, 0x7a, 0xfd, 0x01, 0x2f, 0x78, 0xc3, 0xfb,
    0x65, 0x7b, 0xaa, 0xe1, 0x0d, 0x00, 0x74, 0x3d, 0x63, 0x25, 0x13, 0x71,
    0x52, 0xe9, 0x04, 0xb9, 0xae, 0x25, 0xe4, 0x7a, 0x97, 0x22, 0xcb, 0x0e,
    0x1b, 0xff, 0x83, 0x02, 0xb0, 0x73, 0xc7, 0x6a, 0xeb, 0x70, 0x73, 0x0b,
    0x25, 0xeb, 0x37, 0x61, 0xf9, 0xf2, 0x39, 0xd3, 0x37, 0x48, 0xf9, 0x54,
    0x3f, 0xfb, 0x0e, 0x34, 0x59, 0x77, 0xe4, 0x47, 0x98, 0xd3, 0x4c, 0xe6,
    0x17, 0x04, 0x29, 0x4d, 0x90, 0xd6, 0x4d, 0x16, 0x74, 0x93, 0x05, 0x43,
    0x10, 0x7b, 0xff, 0x63, 0x9b, 0x92, 0xc9, 0x24, 0xad, 0xc3, 0xcd, 0x2d,
    0x34, 0xbd, 0xfa, 0x1a, 0xa5, 0xc5, 0x85, 0x74, 0x8f, 0x4c, 0x90, 0x8e,
    0xde, 0xcf, 0xe9, 0x4b, 0x97, 0x69, 0x7e, 0x6e, 0x2f, 0x45, 0xe1, 0x30,
    0x86, 0x61, 0xa2, 0x4b, 0x4e, 0xf2, 0xcb, 0x6b, 0xf0, 0x47, 0x2a, 0xf1,
    0x17, 0x57, 0x61, 0x98, 0x02, 0x00, 0xb9, 0x30, 0x50, 0xd0, 0x54, 0xb3,
    0xb9, 0x9e, 0x2b, 0x1d, 0x27, 0xf1, 0xa8, 0x2a, 0xdd, 0xed, 0x6d, 0xec,
    0x7a, 0x70, 0x23, 0xd7, 0x9c, 0x79, 0x7c, 0x3b, 0x34, 0xc8, 0x93, 0xae,
    0x61, 0xd6, 0x56, 0x04, 0xf1, 0xa5, 0x6e, 0xe0, 0x9a, 0xf9, 0x9e, 0x2b,
    0x5d, 0xa7, 0xf8, 0x69, 0x7c, 0x9a, 0x50, 0xd9, 0x9d, 0x24, 0x63, 0x3f,
    0xbe, 0xa0, 0xa8, 0x8b, 0x2c, 0x2c, 0xc9, 0x01, 0xf7, 0x6e, 0xa1, 0xb6,
    0xae, 0x9e, 0xda, 0xba, 0x7a, 0x62, 0xe3, 0x73, 0x08, 0x4b, 0x60, 0xc9,
    0x76, 0x1e, 0xde, 0x7b, 0x8c, 0xc2, 0xf2, 0x3c, 0xec, 0xe9, 0x6b, 0x30,
    0x71, 0x99, 0x1d, 0x83, 0x57, 0x79, 0xf1, 0xf8, 0x59, 0xce, 0xb7, 0x4d,
    0xb2, 0x22, 0x50, 0x6b, 0x29, 0x2e, 0x5f, 0x25, 0x7d, 0x5d, 0x9d, 0x14,
    0xef, 0x3b, 0x4a, 0xeb, 0x0f, 0x1a, 0xc5, 0x0e, 0xb8, 0x9e, 0x56, 0x18,
    0x18, 0xb8, 0xc4, 0x3a, 0x69, 0x86, 0xfc, 0x22, 0x0f, 0x76, 0x69, 0x0e,
    0xdd, 0x90, 0x30, 0x17, 0x97, 0x12, 0x58, 0x67, 0xe7, 0xa8, 0x27, 0x87,
    0x86, 0xd6, 0x7e, 0x46, 0xd3, 0x32, 0x92, 0xac, 0xb8, 0x6d, 0xd1, 0x68,
    0x35, 0xbf, 0x1c, 0x69, 0x64, 0xa8, 0xfb, 0x13, 0xbe, 0xfa, 0x75, 0x8a,
    0x9e, 0x8e, 0x93, 0xdc, 0xd3, 0xdf, 0xce, 0x5b, 0xcf, 0xef, 0x42, 0xb2,
    0x3b, 0x39, 0x78, 0xa8, 0x8d, 0xd1, 0x49, 0x1b, 0x76, 0x35, 0xc2, 0x58,
    0x62, 0x31, 0x46, 0x61, 0x98, 0x3d, 0x1b, 0xf3, 0xb8, 0x39, 0x39, 0x82,
    0x04, 0xf0, 0xf8, 0xee, 0x46, 0xa2, 0xd1, 0x6a, 0xe6, 0x3f, 0x3c, 0xc2,
    0x58, 0xeb, 0x6e, 0x32, 0x1f, 0xbc, 0xcc, 0xbb, 0xcd, 0xfb, 0x89, 0x54,
    0xad, 0x61, 0x6c, 0x6c, 0x96, 0x73, 0x9f, 0x7e, 0x89, 0xa5, 0x2c, 0x41,
    0x56, 0x43, 0x34, 0x1f, 0xeb, 0xe5, 0xf3, 0xe1, 0x04, 0x15, 0x15, 0x7e,
    0x54, 0x29, 0x9d, 0x15, 0x68, 0x36, 0x07, 0x0f, 0x3d, 0xbd, 0x1f, 0xaf,
    0xcf, 0xc7, 0x7b, 0x8f, 0x04, 0x78, 0xe7, 0x60, 0x2d, 0x9e, 0xa0, 0x17,
    0xcb, 0x4c, 0xa3, 0x1b, 0x06, 0xdb, 0xb7, 0x6f, 0x23, 0xb2, 0xac, 0x84,
    0x89, 0xf8, 0x34, 0x23, 0xb1, 0x38, 0x21, 0x7f, 0x2e, 0x58, 0x20, 0x61,
    0x64, 0x05, 0x73, 0x0b, 0x26, 0x29, 0x5d, 0x60, 0xb9, 0x03, 0xdc, 0x1e,
    0x1f, 0x65, 0x43, 0x75, 0x0e, 0x5e, 0x25, 0x86, 0xd0, 0x33, 0x94, 0x16,
    0x87, 0x78, 0xf6, 0x99, 0x27, 0x10, 0xe9, 0x29, 0x64, 0x91, 0xe4, 0x50,
    0xe3, 0x06, 0x56, 0x2e, 0x5d, 0xc4, 0xec, 0x58, 0x02, 0x0d, 0x57, 0xf6,
    0x48, 0x73, 0x9a, 0xc0, 0x14, 0x16, 0xc1, 0xb2, 0x55, 0x74, 0x5f, 0x1d,
    0xa6, 0xaa, 0xec, 0x37, 0x34, 0xb9, 0x0b, 0x29, 0xf8, 0x3b, 0xd8, 0x83,
    0x08, 0x21, 0x30, 0x8d, 0x79, 0xbc, 0x6a, 0x82, 0x4d, 0xf7, 0x79, 0x60,
    0x64, 0x98, 0xf3, 0x5f, 0xcf, 0xe0, 0x0d, 0x47, 0xb3, 0x82, 0x94, 0x66,
    0x60, 0x9a, 0x16, 0xd5, 0x0f, 0x3c, 0x4a, 0xc7, 0x77, 0xfd, 0x94, 0x7c,
    0x31, 0xcd, 0x56, 0xf7, 0x1f, 0x68, 0x99, 0x5e, 0x0c, 0xd5, 0x83, 0xe4,
    0x70, 0x81, 0x30, 0x20, 0x93, 0x84, 0xc9, 0x59, 0x7a, 0x3f, 0x8b, 0xf3,
    0xf6, 0x90, 0xce, 0xca, 0xd5, 0x77, 0x21, 0xd7, 0xd4, 0x6c, 0x26, 0xb8,
    0xaa, 0xaa, 0x49, 0x33, 0x05, 0x42, 0xb2, 0x93, 0x57, 0x79, 0x37, 0x1f,
    0xf5, 0x7c, 0xc3, 0xec, 0xcf, 0x93, 0x94, 0xb9, 0x3c, 0xa8, 0xba, 0x85,
    0x2d, 0x71, 0x9b, 0x9c, 0x44, 0x8a, 0x5b, 0x37, 0x6e, 0xd1, 0xde, 0x19,
    0xe7, 0xa5, 0xde, 0x9b, 0x04, 0xd7, 0x6e, 0xc3, 0x2d, 0xfe, 0x9a, 0x90,
    0xd1, 0x05, 0xa6, 0x29, 0x30, 0x84, 0x40, 0x71, 0x7b, 0xa9, 0xdb, 0xf3,
    0x0a, 0x3d, 0xa7, 0xdb, 0x39, 0xf7, 0xfa, 0x09, 0x76, 0x6e, 0x5d, 0x0f,
    0x92, 0xc6, 0xd9, 0x81, 0x38, 0xd7, 0xc7, 0x13, 0xe4, 0x04, 0x0a, 0x58,
    0xd1, 0x70, 0x00, 0x57, 0xa8, 0x04, 0x71, 0xf1, 0xa2, 0x4d, 0xf9, 0xaf,
    0xc2, 0x24, 0xc5, 0x4e, 0xa8, 0xa8, 0x94, 0x0b, 0x9d, 0xf3, 0xb4, 0x9c,
    0xb8, 0x80, 0x2b, 0x90, 0x8f, 0x2b, 0x6f, 0x19, 0xcb, 0x1f, 0xdb, 0x42,
    0x8e, 0xbf, 0x00, 0xd9, 0xa9, 0x82, 0x2d, 0x1b, 0xaa, 0xed, 0xef, 0x9c,
    0xff, 0xc9, 0x50, 0xdf, 0x9b, 0x16, 0x80, 0x3f, 0xbc, 0x06, 0x5f, 0x60,
    0x39, 0x0e, 0xa7, 0x1b, 0x59, 0xb6, 0xff, 0x2b, 0xef, 0x3f, 0x01, 0x4b,
    0xd0, 0x53, 0x12, 0x37, 0x98, 0xa3, 0x76, 0x00, 0x00, 0x00, 0x00, 0x49,
    0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};

static const char* const image1_data[] = { 
	"18 18 13 1",
	"c c #000000",
	"d c #5a5664",
	"i c #655b60",
	"g c #790000",
	"k c #898792",
	"# c #a58363",
	"j c #c4c3c9",
	"f c #cc6600",
	"e c #e99900",
	"h c #ffb287",
	"b c #ffbf55",
	"a c #ffdfaa",
	". c #ffffff",
	"......######......",
	"....##aaaaab##....",
	"...#ccaaaaaccb#...",
	"..#caacaaacaacb#..",
	".#aaaaaaaaaaaabb#.",
	".#aaaaaaaaaaaaab#.",
	"#aaaadcaaadcaaabb#",
	"#aaaadcaaadcaaabb#",
	"#aaaadcaaadcaaabb#",
	"#aeeeaaaaaaaeeebb#",
	"#aeeeaaaaaaaeeeab#",
	"#baaafgggggfaaabb#",
	".#baaghhhhhgaabb#.",
	".#bbaaghhhgaabbb#.",
	"..#bbaagggabbbb#..",
	"...#bbbbbbbbbb#ijj",
	"....##bbbbbb##iikj",
	"......######iikjjj"};


/*
 *  Constructs a MemoQW as a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'.
 */
MemoQW::MemoQW( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl ),
      image1( (const char **) image1_data )
{

	KStandardDirs   *dirs   = KGlobal::dirs();
	QString         sPicsPath;
	sPicsPath = dirs->findResource( "data", QString( KGlobal::instance()->aboutData()->appName() ) + "/pics/" );

    QImage img;
    img.loadFromData( image0_data, sizeof( image0_data ), "PNG" );
    image0 = img;
    if ( !name )
		setName( "MemoQW" );
    setIcon( image0 );
    MemoQWLayout = new QVBoxLayout( this, 11, 6, "MemoQWLayout"); 

    layout19 = new QVBoxLayout( 0, 0, 6, "layout19"); 

    layout16 = new QHBoxLayout( 0, 0, 6, "layout16"); 

    pushButton3 = new ShapeButton( this, sPicsPath + "bt_img_receiver_nor.bmp" );
    pushButton3->setPressedShape( sPicsPath + "bt_img_receiver_down.bmp" );
    pushButton3->setMouseOverShape( sPicsPath + "bt_img_receiver_ov.bmp" );
    pushButton3->setMinimumSize( QSize( 80, 24 ) );
    pushButton3->setMaximumSize( QSize( 80, 24 ) );

    layout16->addWidget( pushButton3 );

    lineEdit1 = new QLineEdit( this, "lineEdit1" );
    layout16->addWidget( lineEdit1 );

    emoticonTB = new ShapeButton( this, sPicsPath + "chw_emoticon.bmp" );
    emoticonTB->setPressedShape( sPicsPath + "chw_emoticon_down.bmp" );
    emoticonTB->setMouseOverShape( sPicsPath + "chw_emoticon_ov.bmp" );
    emoticonTB->setMinimumSize( QSize( 30, 20 ) );
    emoticonTB->setMaximumSize( QSize( 30, 20 ) );
    // emoticonTB->setIconSet( QIconSet( image1 ) );
    layout16->addWidget( emoticonTB );

    fontButton = new ShapeButton( this, sPicsPath + "chw_font.bmp" );
    fontButton->setPressedShape( sPicsPath + "chw_font_down.bmp" );
    fontButton->setMouseOverShape( sPicsPath + "chw_font_ov.bmp" );
    fontButton->setMinimumSize( QSize( 30, 20 ) );
    fontButton->setMaximumSize( QSize( 30, 20 ) );

    layout16->addWidget( fontButton );

    layout19->addLayout( layout16 );

    textEdit2 = new QTextEdit( this, "textEdit2" );
	// textEdit2->setWordWrap( QTextEdit::WidgetWidth );
    layout19->addWidget( textEdit2 );

    layout18 = new QHBoxLayout( 0, 0, 6, "layout18"); 

    textLabel2 = new QLabel( this, "textLabel2" );
    layout18->addWidget( textLabel2 );

	/*
	  checkBox1 = new QCheckBox( this, "checkBox1" );
	  layout18->addWidget( checkBox1 );
	*/

    textLabel1 = new MyLabel( this, "textLabel1" );
    textLabel1->setMinimumSize( QSize( 80, 24 ) );
    textLabel1->setMaximumSize( QSize( 80, 24 ) );
    textLabel1->setPaletteForegroundColor( QColor( 51, 102, 153 ) );
    layout18->addWidget( textLabel1 );
    spacer8 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
    layout18->addItem( spacer8 );

    sendPB = new ShapeButton( this, sPicsPath + "bt_img_send_nor.bmp" );
    sendPB->setPressedShape( sPicsPath + "bt_img_send_down.bmp" );
    sendPB->setMouseOverShape( sPicsPath + "bt_img_send_ov.bmp" );
    sendPB->setMinimumSize( QSize( 80, 24 ) );
    sendPB->setMaximumSize( QSize( 80, 24 ) );

    layout18->addWidget( sendPB );

    clearPB = new ShapeButton( this, sPicsPath + "bt_img_rewri_nor.bmp" );
    clearPB->setPressedShape( sPicsPath + "bt_img_rewri_down.bmp" );
    clearPB->setMouseOverShape( sPicsPath + "bt_img_rewri_ov.bmp" );
    clearPB->setMinimumSize( QSize( 81, 24 ) );
    clearPB->setMaximumSize( QSize( 81, 24 ) );

    // clearPB->setEnabled( FALSE );
    layout18->addWidget( clearPB );
    layout19->addLayout( layout18 );
    MemoQWLayout->addLayout( layout19 );
    languageChange();
    resize( QSize(443, 315).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );

    // signals and slots connections
	connect( clearPB, SIGNAL( clicked() ), SLOT( slotClear() ) );
}

/*
 *  Destroys the object and frees any allocated resources
 */
MemoQW::~MemoQW()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void MemoQW::languageChange()
{
	//  setCaption( trUtf8( "\xec\xaa\xbd\xec\xa7\x80\xeb\xb3\xb4\xeb\x82\xb4\xea\xb8\xb0" ) );
	setCaption( trUtf8( "쪽지 쓰기" ) );
    // pushButton3->setText( tr( "&Receiver" ) );
    // pushButton3->setAccel( QKeySequence( tr( "Alt+R" ) ) );
	// lineEdit1->setText( tr( "Doo-Hyun Jang <ring0320@lycos.co.kr>;Doo-Hyun Jang <ring0320@nate.com>" ) );
    // emoticonTB->setText( QString::null );
    // fontButton->setText( tr( "PB" ) );
    // fontButton->setAccel( QKeySequence( QString::null ) );
    textLabel2->setText( tr( "0000/2000" ) );
	// checkBox1->setText( trUtf8( "\xec\x88\x98\xec\x8b\xa0\xed\x99\x95\xec\x9d\xb8" ) );
    textLabel1->setText( trUtf8( "\x3c\x75\x3e\xec\x9b\x90\xeb\xac\xb8\xed\x91\x9c\xec\x8b\x9c\x20\xec\x84\xa4\xec\xa0"
								 "\x95\x3c\x2f\x75\x3e" ) );
    // sendPB->setText( tr( "Se&nd" ) );
    // sendPB->setAccel( QKeySequence( tr( "Alt+N" ) ) );
    // clearPB->setText( tr( "Cle&ar" ) );
    //clearPB->setAccel( QKeySequence( tr( "Alt+A" ) ) );
}

void MyLabel::mousePressEvent(QMouseEvent * e)
{
	emit clicked();
	QLabel::mousePressEvent( e );
}

MyLabel::MyLabel(QWidget * parent, const char * name):
	QLabel( parent, name )
{
}

void MemoQW::slotClear()
{
	int nResult = KMessageBox::messageBox(this, KMessageBox::QuestionYesNo, QString::fromUtf8("쪽지 내용을 모두 지우시겠습니까?"), QString::fromUtf8("다시쓰기 확인") );
  
	if ( nResult == KMessageBox::Yes )
	{
		textEdit2->clear();
	}
}

#include "memoviewinterface.moc"
