35#include <tdeglobalsettings.h> 
   40#include <tqapplication.h> 
   46    inline TQColor darker( 
const TQColor & c ) {
 
   49      return TQColor( h, s, v*4/5, TQColor::Hsv );
 
   52    inline TQColor desaturate( 
const TQColor & c ) {
 
   55      return TQColor( h, s/8, v, TQColor::Hsv );
 
   58    inline TQColor fixValue( 
const TQColor & c, 
int newV ) {
 
   61      return TQColor( h, s, newV, TQColor::Hsv );
 
   64    inline int getValueOf( 
const TQColor & c ) {
 
   71  CSSHelper::CSSHelper( 
const TQPaintDeviceMetrics &pdm ) :
 
   72    mShrinkQuotes( false ),
 
   76    mForegroundColor = TQApplication::palette().active().text();
 
   77    mLinkColor = TDEGlobalSettings::linkColor();
 
   78    mVisitedLinkColor = TDEGlobalSettings::visitedLinkColor();
 
   79    mBackgroundColor = TQApplication::palette().active().base();
 
   80    cHtmlWarning = TQColor( 0xFF, 0x40, 0x40 ); 
 
   82    cPgpEncrH = TQColor( 0x00, 0x80, 0xFF ); 
 
   83    cPgpOk1H  = TQColor( 0x40, 0xFF, 0x40 ); 
 
   84    cPgpOk0H  = TQColor( 0xFF, 0xFF, 0x40 ); 
 
   85    cPgpWarnH = TQColor( 0xFF, 0xFF, 0x40 ); 
 
   88    for ( 
int i = 0 ; i < 3 ; ++i )
 
   89      mQuoteColor[i] = TQColor( 0x00, 0x80 - i * 0x10, 0x00 ); 
 
   90    mRecycleQuoteColors = 
false;
 
   92    TQFont defaultFont = TDEGlobalSettings::generalFont();
 
   93    TQFont defaultFixedFont = TDEGlobalSettings::fixedFont();
 
   94    mBodyFont = mPrintFont = defaultFont;
 
   95    mFixedFont = mFixedPrintFont = defaultFixedFont;
 
   96    defaultFont.setItalic( 
true );
 
   97    for ( 
int i = 0 ; i < 3 ; ++i )
 
   98      mQuoteFont[i] = defaultFont;
 
  100    mBackingPixmapOn = 
false;
 
  102    recalculatePGPColors();
 
  105  void CSSHelper::recalculatePGPColors() {
 
  117    const int vBG = getValueOf( mBackgroundColor );
 
  118    const bool lightBG = vBG >= 128;
 
  119    if ( cPgpOk1H == mBackgroundColor ) {
 
  120      cPgpOk1F = mBackgroundColor;
 
  121      cPgpOk1B = mBackgroundColor;
 
  123      cPgpOk1F= darker( cPgpOk1H );
 
  124      cPgpOk1B = lightBG ? desaturate( cPgpOk1H ) : fixValue( cPgpOk1H, vBG );
 
  126    if ( cPgpOk0H == mBackgroundColor ) {
 
  127      cPgpOk0F = mBackgroundColor;
 
  128      cPgpOk0B = mBackgroundColor;
 
  130      cPgpOk0F = darker( cPgpOk0H );
 
  131      cPgpOk0B = lightBG ? desaturate( cPgpOk0H ) : fixValue( cPgpOk0H, vBG );
 
  133    if ( cPgpWarnH == mBackgroundColor ) {
 
  134      cPgpWarnF = mBackgroundColor;
 
  135      cPgpWarnB = mBackgroundColor;
 
  137      cPgpWarnF = darker( cPgpWarnH );
 
  138      cPgpWarnB = lightBG ? desaturate( cPgpWarnH ) : fixValue( cPgpWarnH, vBG );
 
  140    if ( cPgpErrH == mBackgroundColor ) {
 
  141      cPgpErrF = mBackgroundColor;
 
  142      cPgpErrB = mBackgroundColor;
 
  144      cPgpErrF = darker( cPgpErrH );
 
  145      cPgpErrB = lightBG ? desaturate( cPgpErrH ) : fixValue( cPgpErrH, vBG );
 
  147    if ( cPgpEncrH == mBackgroundColor ) {
 
  148      cPgpEncrF = mBackgroundColor;
 
  149      cPgpEncrB = mBackgroundColor;
 
  151      cPgpEncrF = darker( cPgpEncrH );
 
  152      cPgpEncrB = lightBG ? desaturate( cPgpEncrH ) : fixValue( cPgpEncrH, vBG );
 
  156  TQString CSSHelper::cssDefinitions( 
bool fixed )
 const {
 
  158      commonCssDefinitions()
 
  160      "@media screen {\n\n" 
  162      screenCssDefinitions( 
this, fixed )
 
  167      printCssDefinitions( fixed )
 
  172  TQString CSSHelper::htmlHead( 
bool  )
 const {
 
  174      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" 
  175      "<html><head><title></title></head>\n" 
  179  TQString CSSHelper::quoteFontTag( 
int level )
 const {
 
  182    static const int numQuoteLevels = 
sizeof mQuoteFont / 
sizeof *mQuoteFont;
 
  183    const int effectiveLevel = mRecycleQuoteColors
 
  184      ? level % numQuoteLevels + 1
 
  185      : kMin( level + 1, numQuoteLevels ) ;
 
  186    if ( level >= numQuoteLevels )
 
  187      return TQString( 
"<div class=\"deepquotelevel%1\">" ).arg( effectiveLevel );
 
  189      return TQString( 
"<div class=\"quotelevel%1\">" ).arg( effectiveLevel );
 
  192  TQString CSSHelper::nonQuotedFontTag()
 const {
 
  193    return "<div class=\"noquote\">";
 
  196  TQFont CSSHelper::bodyFont( 
bool fixed, 
bool print )
 const {
 
  197      return fixed ? ( print ? mFixedPrintFont : mFixedFont )
 
  198        : ( print ? mPrintFont : mBodyFont );
 
  201  int CSSHelper::fontSize( 
bool fixed, 
bool print )
 const {
 
  202    return bodyFont( fixed, print ).pointSize();
 
  207    int pointsToPixel( 
const TQPaintDeviceMetrics & metrics, 
int pointSize ) {
 
  208      return ( pointSize * metrics.logicalDpiY() + 36 ) / 72 ;
 
  212  static const char * 
const quoteFontSizes[] = { 
"85", 
"80", 
"75" };
 
  214  TQString CSSHelper::printCssDefinitions( 
bool fixed )
 const {
 
  215    const TQString headerFont = TQString( 
"  font-family: \"%1\" ! important;\n" 
  216                                        "  font-size: %2pt ! important;\n" )
 
  217                           .arg( mPrintFont.family() )
 
  218                           .arg( mPrintFont.pointSize() );
 
  219    const TQColorGroup & cg = TQApplication::palette().active();
 
  221    const TQFont printFont = bodyFont( fixed, 
true  );
 
  223    if ( printFont.italic() )
 
  224      quoteCSS += 
"  font-style: italic ! important;\n";
 
  225    if ( printFont.bold() )
 
  226      quoteCSS += 
"  font-weight: bold ! important;\n";
 
  227    if ( !quoteCSS.isEmpty() )
 
  228      quoteCSS = 
"div.noquote {\n" + quoteCSS + 
"}\n\n";
 
  232               "  font-family: \"%1\" ! important;\n" 
  233               "  font-size: %2pt ! important;\n" 
  234               "  color: #000000 ! important;\n" 
  235               "  background-color: #ffffff ! important\n" 
  237      .arg( printFont.family(),
 
  238            TQString::number( printFont.pointSize() ) )
 
  240      TQString( 
"tr.textAtmH,\n" 
  241               "tr.signInProgressH,\n" 
  245               "tr.signOkKeyBadH,\n" 
  252               "div.fancy.header > div {\n" 
  253               "  background-color: %2 ! important;\n" 
  254               "  color: %3 ! important;\n" 
  255               "  padding: 4px ! important;\n" 
  256               "  border: solid %3 1px ! important;\n" 
  259               "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" 
  261               "div.fancy.header > table.outer{\n" 
  262               "  background-color: %2 ! important;\n" 
  263               "  color: %3 ! important;\n" 
  264               "  border-bottom: solid %3 1px ! important;\n" 
  265               "  border-left: solid %3 1px ! important;\n" 
  266               "  border-right: solid %3 1px ! important;\n" 
  270               "  display:none ! important;\n" 
  274               "  border: 2px solid #ffffff ! important;\n" 
  278               "  font-size:0.8em ! important;\n" 
  279               "  border:1px solid black ! important;\n" 
  280               "  background-color:%2 ! important;\n" 
  283               "div.senderstatus{\n" 
  284               "  text-align:center ! important;\n" 
  288               "  display:none ! important;\n" 
  292            cg.background().name(),
 
  293            cg.foreground().name() )
 
  297  TQString CSSHelper::screenCssDefinitions( 
const CSSHelper * helper, 
bool fixed )
 const {
 
  298    const TQString fgColor = mForegroundColor.name();
 
  299    const TQString bgColor = mBackgroundColor.name();
 
  300    const TQString linkColor = mLinkColor.name();
 
  301    const TQString headerFont = TQString(
"  font-family: \"%1\" ! important;\n" 
  302                                       "  font-size: %2px ! important;\n")
 
  303      .arg( mBodyFont.family() )
 
  304      .arg( pointsToPixel( helper->mMetrics, mBodyFont.pointSize() ) );
 
  305    const TQString background = ( mBackingPixmapOn
 
  306                         ? TQString( 
"  background-image:url(file://%1) ! important;\n" )
 
  307                           .arg( mBackingPixmapStr )
 
  308                         : TQString( 
"  background-color: %1 ! important;\n" )
 
  310    const TQString bodyFontSize = TQString::number( pointsToPixel( helper->mMetrics, fontSize( fixed ) ) ) + 
"px" ;
 
  311    const TQColorGroup & cg = TQApplication::palette().active();
 
  314    if ( bodyFont( fixed ).italic() )
 
  315      quoteCSS += 
"  font-style: italic ! important;\n";
 
  316    if ( bodyFont( fixed ).bold() )
 
  317      quoteCSS += 
"  font-weight: bold ! important;\n";
 
  318    if ( !quoteCSS.isEmpty() )
 
  319      quoteCSS = 
"div.noquote {\n" + quoteCSS + 
"}\n\n";
 
  322    for ( 
int i = 0 ; i < 3 ; ++i ) {
 
  323      quoteCSS += TQString( 
"div.quotelevel%1 {\n" 
  324                           "  color: %2 ! important;\n" )
 
  325        .arg( TQString::number(i+1), mQuoteColor[i].name() );
 
  326      if ( mQuoteFont[i].italic() )
 
  327        quoteCSS += 
"  font-style: italic ! important;\n";
 
  328      if ( mQuoteFont[i].bold() )
 
  329        quoteCSS += 
"  font-weight: bold ! important;\n";
 
  331        quoteCSS += 
"  font-size: " + TQString::fromLatin1( quoteFontSizes[i] )
 
  332          + 
"% ! important;\n";
 
  337    for ( 
int i = 0 ; i < 3 ; ++i ) {
 
  338      quoteCSS += TQString( 
"div.deepquotelevel%1 {\n" 
  339                           "  color: %2 ! important;\n" )
 
  340        .arg( TQString::number(i+1), mQuoteColor[i].name() );
 
  341      if ( mQuoteFont[i].italic() )
 
  342        quoteCSS += 
"  font-style: italic ! important;\n";
 
  343      if ( mQuoteFont[i].bold() )
 
  344        quoteCSS += 
"  font-weight: bold ! important;\n";
 
  346        quoteCSS += 
"  font-size: 70% ! important;\n";
 
  352               "  font-family: \"%1\" ! important;\n" 
  353               "  font-size: %2 ! important;\n" 
  354               "  color: %3 ! important;\n" 
  357      .arg( bodyFont( fixed ).family(),
 
  363               "  color: %1 ! important;\n" 
  364               "  text-decoration: none ! important;\n" 
  368               "  color: white ! important;\n" 
  372               "  color: black ! important;\n" 
  375               "table.textAtm { background-color: %2 ! important; }\n\n" 
  378               "  background-color: %3 ! important;\n" 
  383               "  background-color: %3 ! important;\n" 
  386               "table.signInProgress,\n" 
  388               "  background-color: %3 ! important;\n" 
  391               "tr.signInProgressH,\n" 
  395      .arg( linkColor, fgColor, bgColor, headerFont )
 
  397      TQString( 
"table.encr {\n" 
  398               "  background-color: %1 ! important;\n" 
  402               "  background-color: %2 ! important;\n" 
  406               "tr.encrB { background-color: %4 ! important; }\n\n" )
 
  407      .arg( cPgpEncrF.name(),
 
  412      TQString( 
"table.signOkKeyOk {\n" 
  413               "  background-color: %1 ! important;\n" 
  416               "tr.signOkKeyOkH {\n" 
  417               "  background-color: %2 ! important;\n" 
  421               "tr.signOkKeyOkB { background-color: %4 ! important; }\n\n" )
 
  422      .arg( cPgpOk1F.name(),
 
  427      TQString( 
"table.signOkKeyBad {\n" 
  428               "  background-color: %1 ! important;\n" 
  431               "tr.signOkKeyBadH {\n" 
  432               "  background-color: %2 ! important;\n" 
  436               "tr.signOkKeyBadB { background-color: %4 ! important; }\n\n" )
 
  437      .arg( cPgpOk0F.name(),
 
  442      TQString( 
"table.signWarn {\n" 
  443               "  background-color: %1 ! important;\n" 
  447               "  background-color: %2 ! important;\n" 
  451               "tr.signWarnB { background-color: %4 ! important; }\n\n" )
 
  452      .arg( cPgpWarnF.name(),
 
  457      TQString( 
"table.signErr {\n" 
  458               "  background-color: %1 ! important;\n" 
  462               "  background-color: %2 ! important;\n" 
  466               "tr.signErrB { background-color: %4 ! important; }\n\n" )
 
  467      .arg( cPgpErrF.name(),
 
  472      TQString( 
"div.htmlWarn {\n" 
  473               "  border: 2px solid %1 ! important;\n" 
  475      .arg( cHtmlWarning.name() )
 
  477      TQString( 
"div.header {\n" 
  481               "div.fancy.header > div {\n" 
  482               "  background-color: %2 ! important;\n" 
  483               "  color: %3 ! important;\n" 
  484               "  border: solid %4 1px ! important;\n" 
  487               "div.fancy.header > div a[href] { color: %3 ! important; }\n\n" 
  489               "div.fancy.header > div a[href]:hover { text-decoration: underline ! important; }\n\n" 
  491               "div.fancy.header > div.spamheader {\n" 
  492               "  background-color: #cdcdcd ! important;\n" 
  493               "  border-top: 0px ! important;\n" 
  494               "  padding: 3px ! important;\n" 
  495               "  color: black ! important;\n" 
  496               "  font-weight: bold ! important;\n" 
  497               "  font-size: smaller ! important;\n" 
  500               "div.fancy.header > table.outer {\n" 
  501               "  background-color: %5 ! important;\n" 
  502               "  color: %4 ! important;\n" 
  503               "  border-bottom: solid %4 1px ! important;\n" 
  504               "  border-left: solid %4 1px ! important;\n" 
  505               "  border-right: solid %4 1px ! important;\n" 
  509               "  padding: 0px ! important;\n" 
  510               "  font-size:0.8em ! important;\n" 
  511               "  border:1px solid %6 ! important;\n" 
  514               "  background-color:%5 ! important;\n" 
  517               "div.senderstatus{\n" 
  518               "  text-align:center ! important;\n" 
  523      .arg( cg.highlight().name(),
 
  524            cg.highlightedText().name(),
 
  525            cg.foreground().name(),
 
  526            cg.background().name() )
 
  527      .arg( cg.mid().name() )
 
  531  TQString CSSHelper::commonCssDefinitions()
 const {
 
  534      "  margin-bottom: 10pt ! important;\n" 
  538      "  margin-top: 10pt ! important;\n" 
  539      "  margin-bottom: 10pt ! important;\n" 
  545      "  font-weight: normal ! important;\n" 
  548      "tr.signInProgressH,\n" 
  552      "tr.signOkKeyBadH,\n" 
  555      "  font-weight: bold ! important;\n" 
  560      "  padding: 3px ! important;\n" 
  564      "  width: 100% ! important;\n" 
  565      "  border: solid 1px black ! important;\n" 
  566      "  margin-top: 10pt ! important;\n" 
  567      "  margin-bottom: 10pt ! important;\n" 
  574      "table.signOkKeyBad,\n" 
  575      "table.signOkKeyOk,\n" 
  576      "table.signInProgress,\n" 
  577      "div.fancy.header table {\n" 
  578      "  width: 100% ! important;\n" 
  579      "  border-width: 0px ! important;\n" 
  583      "  margin: 0px 5% ! important;\n" 
  584      "  padding: 10px ! important;\n" 
  585      "  text-align: left ! important;\n" 
  588      "div.fancy.header > div {\n" 
  589      "  font-weight: bold ! important;\n" 
  590      "  padding: 4px ! important;\n" 
  593      "div.fancy.header table {\n" 
  594      "  padding: 2px ! important;\n"  
  595      "  text-align: left ! important\n" 
  598      "div.fancy.header table th {\n" 
  599      "  padding: 0px ! important;\n" 
  600      "  white-space: nowrap ! important;\n" 
  601      "  border-spacing: 0px ! important;\n" 
  602      "  text-align: left ! important;\n" 
  603      "  vertical-align: top ! important;\n" 
  606      "div.fancy.header table td {\n" 
  607      "  padding: 0px ! important;\n" 
  608      "  border-spacing: 0px ! important;\n" 
  609      "  text-align: left ! important;\n" 
  610      "  vertical-align: top ! important;\n" 
  611      "  width: 100% ! important;\n" 
  614      "span.pimsmileytext {\n" 
  615      "  position: absolute;\n" 
  618      "  visibility: hidden;\n" 
  621      "img.pimsmileyimg {\n" 
  624      "div.quotelevelmark {\n" 
  625      "  position: absolute;\n" 
  626      "  margin-left:-10px;\n" 
  632  void CSSHelper::setBodyFont( 
const TQFont& font )
 
  637  void CSSHelper::setPrintFont( 
const TQFont& font )
 
  642  TQColor CSSHelper::pgpWarnColor()
 const 
TDEPIM classes for drag and drop of mails.