TQtBrush.cxx

Go to the documentation of this file.
00001 // @(#)root/qt:$Id: TQtBrush.cxx 30386 2009-09-23 19:06:28Z brun $
00002 // Author: Valeri Fine   21/01/2002
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * Copyright (C) 2002 by Valeri Fine.                                    *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 
00014 /////////////////////////////////////////////////////////////////////////////////
00015 //
00016 // TQtBrush creates the QBrush Qt object based on the ROOT "TAttFill" attributes 
00017 //
00018 /////////////////////////////////////////////////////////////////////////////////
00019 
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 
00023 #include "TQtBrush.h"
00024 #include "TGQt.h"
00025 #include "qbitmap.h"
00026 #include <QDebug>
00027 
00028 //
00029 //*-*- data to create fill area interior style
00030 //
00031 
00032 static uchar p1_bits[] = {
00033   (0xaa),(0xaa),(0x55),(0x55),(0xaa),(0xaa),(0x55),(0x55),(0xaa),(0xaa),(0x55),(0x55),
00034   (0xaa),(0xaa),(0x55),(0x55),(0xaa),(0xaa),(0x55),(0x55),(0xaa),(0xaa),(0x55),(0x55),
00035   (0xaa),(0xaa),(0x55),(0x55),(0xaa),(0xaa),(0x55),(0x55)};
00036 static uchar p2_bits[] = {
00037   (0x44),(0x44),(0x11),(0x11),(0x44),(0x44),(0x11),(0x11),(0x44),(0x44),(0x11),(0x11),
00038   (0x44),(0x44),(0x11),(0x11),(0x44),(0x44),(0x11),(0x11),(0x44),(0x44),(0x11),(0x11),
00039   (0x44),(0x44),(0x11),(0x11),(0x44),(0x44),(0x11),(0x11)};
00040 static uchar p3_bits[] = {
00041   (0x00),(0x00),(0x44),(0x44),(0x00),(0x00),(0x11),(0x11),(0x00),(0x00),(0x44),(0x44),
00042   (0x00),(0x00),(0x11),(0x11),(0x00),(0x00),(0x44),(0x44),(0x00),(0x00),(0x11),(0x11),
00043   (0x00),(0x00),(0x44),(0x44),(0x00),(0x00),(0x11),(0x11)};
00044 static uchar p4_bits[] = {
00045   (0x80),(0x80),(0x40),(0x40),(0x20),(0x20),(0x10),(0x10),(0x08),(0x08),(0x04),(0x04),
00046   (0x02),(0x02),(0x01),(0x01),(0x80),(0x80),(0x40),(0x40),(0x20),(0x20),(0x10),(0x10),
00047   (0x08),(0x08),(0x04),(0x04),(0x02),(0x02),(0x01),(0x01)};
00048 static uchar p5_bits[] = {
00049   (0x20),(0x20),(0x40),(0x40),(0x80),(0x80),(0x01),(0x01),(0x02),(0x02),(0x04),(0x04),
00050   (0x08),(0x08),(0x10),(0x10),(0x20),(0x20),(0x40),(0x40),(0x80),(0x80),(0x01),(0x01),
00051   (0x02),(0x02),(0x04),(0x04),(0x08),(0x08),(0x10),(0x10)};
00052 static uchar p6_bits[] = {
00053   (0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),
00054   (0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),
00055   (0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44)};
00056 static uchar p7_bits[] = {
00057   (0x00),(0x00),(0x00),(0x00),(0x00),(0x00),(0xff),(0xff),(0x00),(0x00),(0x00),(0x00),
00058   (0x00),(0x00),(0xff),(0xff),(0x00),(0x00),(0x00),(0x00),(0x00),(0x00),(0xff),(0xff),
00059   (0x00),(0x00),(0x00),(0x00),(0x00),(0x00),(0xff),(0xff)};
00060 static uchar p8_bits[] = {
00061   (0x11),(0x11),(0xb8),(0xb8),(0x7c),(0x7c),(0x3a),(0x3a),(0x11),(0x11),(0xa3),(0xa3),
00062   (0xc7),(0xc7),(0x8b),(0x8b),(0x11),(0x11),(0xb8),(0xb8),(0x7c),(0x7c),(0x3a),(0x3a),
00063   (0x11),(0x11),(0xa3),(0xa3),(0xc7),(0xc7),(0x8b),(0x8b)};
00064 static uchar p9_bits[] = {
00065   (0x10),(0x10),(0x10),(0x10),(0x28),(0x28),(0xc7),(0xc7),(0x01),(0x01),(0x01),(0x01),
00066   (0x82),(0x82),(0x7c),(0x7c),(0x10),(0x10),(0x10),(0x10),(0x28),(0x28),(0xc7),(0xc7),
00067   (0x01),(0x01),(0x01),(0x01),(0x82),(0x82),(0x7c),(0x7c)};
00068 static uchar p10_bits[] = {
00069   (0x10),(0x10),(0x10),(0x10),(0x10),(0x10),(0xff),(0xff),(0x01),(0x01),(0x01),(0x01),
00070   (0x01),(0x01),(0xff),(0xff),(0x10),(0x10),(0x10),(0x10),(0x10),(0x10),(0xff),(0xff),
00071   (0x01),(0x01),(0x01),(0x01),(0x01),(0x01),(0xff),(0xff)};
00072 static uchar p11_bits[] = {
00073   (0x08),(0x08),(0x49),(0x49),(0x2a),(0x2a),(0x1c),(0x1c),(0x2a),(0x2a),(0x49),(0x49),
00074   (0x08),(0x08),(0x00),(0x00),(0x80),(0x80),(0x94),(0x94),(0xa2),(0xa2),(0xc1),(0xc1),
00075   (0xa2),(0xa2),(0x94),(0x94),(0x80),(0x80),(0x00),(0x00)};
00076 static uchar p12_bits[] = {
00077   (0x1c),(0x1c),(0x22),(0x22),(0x41),(0x41),(0x41),(0x41),(0x41),(0x41),(0x22),(0x22),
00078   (0x1c),(0x1c),(0x00),(0x00),(0xc1),(0xc1),(0x22),(0x22),(0x14),(0x14),(0x14),(0x14),
00079   (0x14),(0x14),(0x22),(0x22),(0xc1),(0xc1),(0x00),(0x00)};
00080 static uchar p13_bits[] = {
00081   (0x01),(0x01),(0x82),(0x82),(0x44),(0x44),(0x28),(0x28),(0x10),(0x10),(0x28),(0x28),
00082   (0x44),(0x44),(0x82),(0x82),(0x01),(0x01),(0x82),(0x82),(0x44),(0x44),(0x28),(0x28),
00083   (0x10),(0x10),(0x28),(0x28),(0x44),(0x44),(0x82),(0x82)};
00084 static uchar p14_bits[] = {
00085   (0xff),(0xff),(0x11),(0x10),(0x11),(0x10),(0x11),(0x10),(0xf1),(0x1f),(0x11),(0x11),
00086   (0x11),(0x11),(0x11),(0x11),(0xff),(0x11),(0x01),(0x11),(0x01),(0x11),(0x01),(0x11),
00087   (0xff),(0xff),(0x01),(0x10),(0x01),(0x10),(0x01),(0x10)};
00088 static uchar p15_bits[] = {
00089   (0x22),(0x22),(0x55),(0x55),(0x22),(0x22),(0x00),(0x00),(0x88),(0x88),(0x55),(0x55),
00090   (0x88),(0x88),(0x00),(0x00),(0x22),(0x22),(0x55),(0x55),(0x22),(0x22),(0x00),(0x00),
00091   (0x88),(0x88),(0x55),(0x55),(0x88),(0x88),(0x00),(0x00)};
00092 static uchar p16_bits[] = {
00093   (0x0e),(0x0e),(0x11),(0x11),(0xe0),(0xe0),(0x00),(0x00),(0x0e),(0x0e),(0x11),(0x11),
00094   (0xe0),(0xe0),(0x00),(0x00),(0x0e),(0x0e),(0x11),(0x11),(0xe0),(0xe0),(0x00),(0x00),
00095   (0x0e),(0x0e),(0x11),(0x11),(0xe0),(0xe0),(0x00),(0x00)};
00096 static uchar p17_bits[] = {
00097   (0x44),(0x44),(0x22),(0x22),(0x11),(0x11),(0x00),(0x00),(0x44),(0x44),(0x22),(0x22),
00098   (0x11),(0x11),(0x00),(0x00),(0x44),(0x44),(0x22),(0x22),(0x11),(0x11),(0x00),(0x00),
00099   (0x44),(0x44),(0x22),(0x22),(0x11),(0x11),(0x00),(0x00)};
00100 static uchar p18_bits[] = {
00101   (0x11),(0x11),(0x22),(0x22),(0x44),(0x44),(0x00),(0x00),(0x11),(0x11),(0x22),(0x22),
00102   (0x44),(0x44),(0x00),(0x00),(0x11),(0x11),(0x22),(0x22),(0x44),(0x44),(0x00),(0x00),
00103   (0x11),(0x11),(0x22),(0x22),(0x44),(0x44),(0x00),(0x00)};
00104 static uchar p19_bits[] = {
00105   (0xe0),(0x03),(0x98),(0x0c),(0x84),(0x10),(0x42),(0x21),(0x42),(0x21),(0x21),(0x42),
00106   (0x19),(0x4c),(0x07),(0xf0),(0x19),(0x4c),(0x21),(0x42),(0x42),(0x21),(0x42),(0x21),
00107   (0x84),(0x10),(0x98),(0x0c),(0xe0),(0x03),(0x80),(0x00)};
00108 static uchar p20_bits[] = {
00109   (0x22),(0x22),(0x11),(0x11),(0x11),(0x11),(0x11),(0x11),(0x22),(0x22),(0x44),(0x44),
00110   (0x44),(0x44),(0x44),(0x44),(0x22),(0x22),(0x11),(0x11),(0x11),(0x11),(0x11),(0x11),
00111   (0x22),(0x22),(0x44),(0x44),(0x44),(0x44),(0x44),(0x44)};
00112 static uchar p21_bits[] = {
00113   (0xf1),(0xf1),(0x10),(0x10),(0x10),(0x10),(0x10),(0x10),(0x1f),(0x1f),(0x01),(0x01),
00114   (0x01),(0x01),(0x01),(0x01),(0xf1),(0xf1),(0x10),(0x10),(0x10),(0x10),(0x10),(0x10),
00115   (0x1f),(0x1f),(0x01),(0x01),(0x01),(0x01),(0x01),(0x01)};
00116 static uchar p22_bits[] = {
00117   (0x8f),(0x8f),(0x08),(0x08),(0x08),(0x08),(0x08),(0x08),(0xf8),(0xf8),(0x80),(0x80),
00118   (0x80),(0x80),(0x80),(0x80),(0x8f),(0x8f),(0x08),(0x08),(0x08),(0x08),(0x08),(0x08),
00119   (0xf8),(0xf8),(0x80),(0x80),(0x80),(0x80),(0x80),(0x80)};
00120 static uchar p23_bits[] = {
00121   (0xAA),(0xAA),(0x55),(0x55),(0x6a),(0x6a),(0x74),(0x74),(0x78),(0x78),(0x74),(0x74),
00122   (0x6a),(0x6a),(0x55),(0x55),(0xAA),(0xAA),(0x55),(0x55),(0x6a),(0x6a),(0x74),(0x74),
00123   (0x78),(0x78),(0x74),(0x74),(0x6a),(0x6a),(0x55),(0x55)};
00124 static uchar p24_bits[] = {
00125   (0x80),(0x00),(0xc0),(0x00),(0xea),(0xa8),(0xd5),(0x54),(0xea),(0xa8),(0xd5),(0x54),
00126   (0xeb),(0xe8),(0xd5),(0xd4),(0xe8),(0xe8),(0xd4),(0xd4),(0xa8),(0xe8),(0x54),(0xd5),
00127   (0xa8),(0xea),(0x54),(0xd5),(0xfc),(0xff),(0xfe),(0xff)};
00128 static uchar p25_bits[] = {
00129   (0x80),(0x00),(0xc0),(0x00),(0xe0),(0x00),(0xf0),(0x00),(0xff),(0xf0),(0xff),(0xf0),
00130   (0xfb),(0xf0),(0xf9),(0xf0),(0xf8),(0xf0),(0xf8),(0x70),(0xf8),(0x30),(0xff),(0xf0),
00131   (0xff),(0xf8),(0xff),(0xfc),(0xff),(0xfe),(0xff),(0xff)};
00132 
00133 
00134 static uchar *patter_bits[]= { p1_bits, p2_bits,   p3_bits,  p4_bits,  p5_bits,
00135                                p6_bits, p7_bits,   p8_bits,  p9_bits, p10_bits,
00136                               p11_bits, p12_bits, p13_bits, p14_bits, p15_bits,
00137                               p16_bits, p17_bits, p18_bits, p19_bits, p20_bits,
00138                               p21_bits, p22_bits, p23_bits, p24_bits, p25_bits};
00139 
00140 ClassImp(TQtBrush)
00141 //______________________________________________________________________________
00142 TQtBrush::TQtBrush(): QBrush(),fStyle(0),fFasi(0),fAlpha(255)
00143 {}
00144 //______________________________________________________________________________
00145 TQtBrush::TQtBrush(const TAttFill &rootFillAttributes)
00146 {
00147         // TQtBrush ctor from ROOT TAttFill object
00148         SetFillAttributes(rootFillAttributes);
00149 
00150 }
00151 //______________________________________________________________________________
00152 TQtBrush::~TQtBrush() 
00153 {
00154         // TQtBrush dtor
00155 }
00156 //______________________________________________________________________________
00157 TQtBrush &TQtBrush::operator=(const TAttFill &rootFillAttributes)
00158 {
00159         SetFillAttributes(rootFillAttributes);
00160    return *this;
00161 }
00162 //______________________________________________________________________________
00163 void  TQtBrush::SetFillAttributes(const TAttFill &rootFillAttributes)
00164 {
00165         SetColor(rootFillAttributes.GetFillColor());
00166         SetStyle(rootFillAttributes.GetFillStyle());
00167 }
00168 
00169 //______________________________________________________________________________
00170  void TQtBrush::SetColor(Color_t cindex)
00171  {
00172    // Set color index for to fill shapes
00173    //  cindex    : color index
00174     if (cindex >= 0)  SetColor(gQt->ColorIndex(gQt->UpdateColor(cindex)));
00175     else fAlpha = cindex;
00176  }
00177 //______________________________________________________________________________
00178 void TQtBrush::SetColor(const QColor &qtcolor)
00179 {
00180    // remember the user's alpha value and set the  brush color
00181    fAlpha = qtcolor.alpha();
00182         fBackground = qtcolor;
00183    SetColorOwn();
00184 }
00185 
00186 //______________________________________________________________________________
00187 void TQtBrush::SetColorOwn()
00188 {
00189   // Set the brush color and adjust its alpha value from fStyle
00190   // Take in account the new transperency if needed
00191 
00192   static const int opaqAlpha = QColor(0,0,0).alpha(); // Qt   alpha range is  [0:255]
00193   static const float opaqFactor = opaqAlpha/100.;     // ROOT alpha range is  [0:100]
00194   if (fAlpha >=0 ) {
00195           int alpha = ( fStyle == 4) ? int(opaqFactor*fFasi) : fAlpha;
00196           if (fBackground.alpha() != alpha) fBackground.setAlpha(alpha);
00197           setColor(fBackground);
00198   }
00199 }
00200 
00201 //______________________________________________________________________________
00202 void TQtBrush::SetStyle(int sty, int fasi)
00203 {
00204 //*-*-*-*-*-*-*-*-*-*-*Set fill area style index*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00205 //*-*                  =========================
00206 //*-*  style   : fill area interior style hollow or solid
00207 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00208   fStyle =  sty;
00209   fFasi  =  fasi;
00210 
00211   switch( fStyle ) {
00212 
00213   case 0:
00214     setStyle(Qt::NoBrush);                          // hollow
00215     fBackground = Qt::transparent;
00216          fAlpha = 0;
00217     break;
00218   case 1:                                           // solid
00219     setStyle(Qt::SolidPattern);
00220     break;
00221   case 3:                                           // pattern
00222      {
00223         int pattern = 1;
00224         if (fasi > 0 && fasi < 26 ) pattern = fasi-1;
00225         QBitmap bm =  QBitmap::fromData(QSize(16,16),patter_bits[pattern]);
00226         setTexture(bm);
00227      }
00228     break;
00229   case 2:                                           // hatch
00230       switch (fasi)
00231         {
00232           case 1: setStyle(Qt::BDiagPattern);
00233                   break;
00234           case 2: setStyle(Qt::CrossPattern);
00235                   break;
00236           case 3: setStyle(Qt::DiagCrossPattern);
00237                   break;
00238           case 4: setStyle(Qt::FDiagPattern);
00239                   break;
00240           case 5: setStyle(Qt::HorPattern);
00241                   break;
00242           case 6: setStyle(Qt::VerPattern );
00243                   break;
00244          default: setStyle(Qt::FDiagPattern);
00245                   break;
00246         }
00247      break;
00248   case 4:                                      // transparent
00249      if (!fasi)    setStyle(Qt::NoBrush);      // the window is transparent
00250           else          setStyle(Qt::SolidPattern);
00251      break;
00252   default:                                          // solid  - default
00253       setStyle(Qt::SolidPattern);
00254       break;
00255   }
00256   SetColorOwn();
00257 }

Generated on Tue Jul 5 14:14:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1