/*
  'Acqua' kwin client

  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@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.

  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; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
*/

#include <qpainter.h>
//#include <kconfig.h>
#include "AcquaButton.h"
#include "Acqua.h"

using namespace KWinInternal;


//static  const char * inactive_xpm[] = {
//"22 16 180 2",
//"  	c None",
//". 	c #97A7C8",
//"+ 	c #97A7C6",
//"@ 	c #8594AB",
//"# 	c #808FA6",
//"$ 	c #77869D",
//"% 	c #6F7E95",
//"& 	c #707F96",
//"* 	c #7B8AA1",
//"= 	c #8E9DB4",
//"- 	c #9AA9C4",
//"; 	c #96A9CB",
//"> 	c #93A4C5",
//", 	c #8393B4",
//"' 	c #8B9AAF",
//") 	c #9AA9BE",
//"! 	c #AAB9CE",
//"~ 	c #AFBED3",
//"{ 	c #A8B7CC",
//"] 	c #9CABC0",
//"^ 	c #8D9CB1",
//"/ 	c #8392A7",
//"( 	c #95A6C8",
//"_ 	c #9DB3D0",
//": 	c #9BB0CC",
//"< 	c #899DB8",
//"[ 	c #879BB6",
//"} 	c #A1B2C6",
//"| 	c #B0C1D5",
//"1 	c #BDCEE2",
//"2 	c #BECFE3",
//"3 	c #BACBDF",
//"4 	c #B2C3D7",
//"5 	c #A0B1C5",
//"6 	c #8E9FB3",
//"7 	c #8EA1BF",
//"8 	c #9DB1CE",
//"9 	c #93ACC2",
//"0 	c #94ACC2",
//"a 	c #869CB1",
//"b 	c #7C93A5",
//"c 	c #8EA5B7",
//"d 	c #A3B5CB",
//"e 	c #AABCD2",
//"f 	c #ACBED4",
//"g 	c #A7B9CF",
//"h 	c #A9BBD1",
//"i 	c #AEC0D6",
//"j 	c #A4B6CC",
//"k 	c #93A5BB",
//"l 	c #788EA3",
//"m 	c #8BA1B6",
//"n 	c #92A6C3",
//"o 	c #96A8C4",
//"p 	c #7A8AA3",
//"q 	c #919FB9",
//"r 	c #98A7BE",
//"s 	c #A0AFC2",
//"t 	c #A3B2C5",
//"u 	c #A5B4C7",
//"v 	c #9EADC0",
//"w 	c #97A6B9",
//"x 	c #8E9FB1",
//"y 	c #7B8BA2",
//"z 	c #96A9C4",
//"A 	c #95AAC6",
//"B 	c #96A8C2",
//"C 	c #7C8CA5",
//"D 	c #99A7C1",
//"E 	c #A2B1C8",
//"F 	c #A4B3C6",
//"G 	c #A6B5C8",
//"H 	c #A7B6C9",
//"I 	c #A2B1C4",
//"J 	c #97A8BA",
//"K 	c #8090A7",
//"L 	c #9AACC6",
//"M 	c #9EB2CF",
//"N 	c #98A9C3",
//"O 	c #8797B0",
//"P 	c #A3B1CB",
//"Q 	c #A9B8CF",
//"R 	c #ABBACD",
//"S 	c #ACBBCE",
//"T 	c #AEBDD0",
//"U 	c #B0BFD2",
//"V 	c #ADBCCF",
//"W 	c #A2B3C5",
//"X 	c #8898AF",
//"Y 	c #9CADC7",
//"Z 	c #93A7C4",
//"` 	c #96A7C1",
//" .	c #8C9CB5",
//"..	c #A4B2CC",
//"+.	c #A6B5CC",
//"@.	c #B2C1D4",
//"#.	c #B6C5D8",
//"$.	c #B5C4D7",
//"%.	c #AFBED1",
//"&.	c #AAB9CC",
//"*.	c #A9B8CB",
//"=.	c #A4B5C7",
//"-.	c #97A8C2",
//";.	c #8FA0BA",
//">.	c #8898B1",
//",.	c #9FADC7",
//"'.	c #B4C3D6",
//").	c #B1C0D3",
//"!.	c #9FB0C2",
//"~.	c #8797AE",
//"{.	c #91A2BC",
//"].	c #8FA1BC",
//"^.	c #9DABC5",
//"/.	c #B3C2D9",
//"(.	c #B3C2D5",
//"_.	c #B7C6D9",
//":.	c #B9C8DB",
//"<.	c #BBCADD",
//"[.	c #B8C7DA",
//"}.	c #9CADBF",
//"|.	c #8C9CB3",
//"1.	c #96A7C2",
//"2.	c #9AAFCB",
//"3.	c #98ABC6",
//"4.	c #93A1BB",
//"5.	c #ACBBD2",
//"6.	c #BCCBDE",
//"7.	c #BAC9DC",
//"8.	c #BFCEE1",
//"9.	c #94A5B7",
//"0.	c #8E9EB5",
//"a.	c #9BADC8",
//"b.	c #91A5C2",
//"c.	c #92A6C2",
//"d.	c #8D9DB6",
//"e.	c #8391AB",
//"f.	c #96A5BC",
//"g.	c #96A5B8",
//"h.	c #8596A8",
//"i.	c #8CA5C3",
//"j.	c #8AA3BC",
//"k.	c #7F98AE",
//"l.	c #7891A7",
//"m.	c #8899AB",
//"n.	c #96A7B9",
//"o.	c #A6B7C9",
//"p.	c #ADBED0",
//"q.	c #A7B8CA",
//"r.	c #8697A9",
//"s.	c #7C8D9F",
//"t.	c #8199B3",
//"u.	c #89A1BD",
//"v.	c #91A6C0",
//"w.	c #8D9EBE",
//"x.	c #8696B8",
//"y.	c #7C87A5",
//"z.	c #7D88A6",
//"A.	c #7E89A7",
//"B.	c #818CAA",
//"C.	c #848FAD",
//"D.	c #8EA0C1",
//"E.	c #9AAECB",
//"F.	c #98A8C8",
//"G.	c #95A0BC",
//"H.	c #919CB8",
//"I.	c #8B96B2",
//"J.	c #8792AE",
//"K.	c #8893AF",
//"L.	c #8F9AB6",
//"M.	c #97A2BE",
//"N.	c #9CABC7",
//"O.	c #8DA0C0",
//"P.	c #8EA1BD",
//"Q.	c #8EA2B9",
//"R.	c #8CA0B4",
//"S.	c #8BA0B3",
//"T.	c #8DA2B9",
//"U.	c #8DA1BD",
//"V.	c #89A1C2",
//"W.	c #89A3C0",
//". . . . . . . + @ # $ % & * = - . . . . . . ",
//"; ; ; ; ; ; > , ' ) ! ~ { ] ^ / ( ; ; ; ; ; ",
//"_ _ _ _ _ : < [ } | 1 2 3 4 5 6 7 8 _ _ _ _ ",
//"9 9 9 9 0 a b c d e f g h i j k l m 0 9 9 9 ",
//"n n n n o p q r s t u t t t v w x y z n n n ",
//"A A A A B C D E F G H H H H u I J K L A A A ",
//"M M M M N O P Q R S T U U V R R W X Y M M M ",
//"Z Z Z Z `  ...+.S T @.#.$.%.&.*.=.X -.Z Z Z ",
//"Z Z Z Z ;.>.,.Q R T @.$.'.).V &.!.~.{.Z Z Z ",
//"Z Z Z Z ].>.^./.(.#._._.:.<.[.(.}.|.1.Z Z Z ",
//"2.2.2.2.3. .4.5.$.<.6.7.6.8.[.S 9.0.a.2.2.2.",
//"b.b.b.b.c.d.e.f.V _.7._.[.[.&.g.h.~.b.b.b.b.",
//"i.i.i.i.i.j.k.l.m.n.o.p.q.J r.s.t.u.i.i.i.i.",
//"v.v.v.v.v.v.w.x.y.z.A.z.y.z.B.C.D.v.v.v.v.v.",
//"2.2.2.2.2.2.E.F.G.H.I.J.K.L.M.N.E.2.2.2.2.2.",
//"O.O.O.O.O.O.O.O.P.Q.R.S.R.T.U.O.O.O.O.O.O.O.",
//"V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.V.",
//"W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W.W."};

AcquaButton::AcquaButton(QWidget * parent, const QString& tip)
  : KWinWidgetButton (parent, 0, 0, tip),
    mouseOver_  (false),
    mouseDown_  (false)
{
  setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
  setBackgroundMode(NoBackground);
  setFixedSize(16, 16);
 }


AcquaButton::AcquaButton(QWidget * parent, const QString& tip, int s)
  : KWinWidgetButton (parent, 0, 0, tip),
    mouseOver_  (false),
    mouseDown_  (false)
{
  setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
  setBackgroundMode(NoBackground);
  setFixedSize(s, 16);
  }

AcquaButton::~AcquaButton()
{
  // Empty.
}

void
AcquaButton::mousePressEvent(QMouseEvent * e)
{
  mouseDown_ = true;
  repaint();
  KWinWidgetButton::mousePressEvent(e);
}

void
AcquaButton::mouseReleaseEvent(QMouseEvent * e)
{
  mouseDown_ = false;
  repaint();

  if (rect().contains(e->pos()))
  {
    clickEvent(e->button());
  }
  KWinWidgetButton::mouseReleaseEvent(e);
}

  void
AcquaButton::enterEvent(QEvent * e)
{
  mouseOver_ = true;
  repaint();
  KWinWidgetButton::enterEvent(e);
}

  void
AcquaButton::leaveEvent(QEvent * e)
{
  mouseOver_ = false;
  repaint();
  KWinWidgetButton::leaveEvent(e);
}

  void
AcquaButton::paintEvent(QPaintEvent *)
{
#if 0  
  QPen highlightPen;

  p.setBrush(NoBrush);
  p.setPen(Qt::black);

  if (mouseDown_)
    highlightPen = QPen(colorGroup().light());

  else
  {
    if (mouseOver_)
      highlightPen = QPen(colorGroup().highlight());
    else
      highlightPen = QPen(NoPen);
  }
#endif
  QPainter p(this);

//  p.fillRect(rect(), colorGroup().background());

  Acqua *owner=dynamic_cast<Acqua *>(parent());
  if(!owner)return;

    // Draw icon.

  QPoint center(rect().center());

  int bwby2(pixmap_.width() / 2);    // Bitmap Width BY 2
  int bhby2(pixmap_.height() / 2);   // Bitmap Height BY 2

  if(owner->isActive()){
    if(mouseDown_){
      p.drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1, pixmap_down);
    }
    else if(mouseOver_){
      p.drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1, pixmap_over);
    }
    else {
      p.drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1, pixmap_);
    }
  }
  else 
      p.drawPixmap(center.x() - bwby2 + 1, center.y() - bhby2 + 1,
QPixmap(pixmap_inactive)); }

  QSize
AcquaButton::sizeHint() const
{
  return QSize(16, 16);
}

  QSize
AcquaButton::minimumSizeHint() const
{
  return QSize(16, 16);
}

  void
AcquaButton::resizeEvent(QResizeEvent *)
{
  repaint();
}

#include "AcquaButton.moc"
// vim:ts=2:sw=2:tw=78:set et:
