Back to index

texmacs  1.0.7.15
Classes | Functions
QTMStyle.cpp File Reference
#include "QTMStyle.hpp"
#include <QApplication>
#include <QStyleOptionMenuItem>
#include "tm_ostream.hpp"
#include <qdrawutil.h>
#include <QPainter>
#include <QMainWindow>

Go to the source code of this file.

Classes

class  QTMProxyStyle
class  QTMStyle

Functions

static void qtmDrawRoundedRect (QPainter *p, const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
static void qtmDrawShadeRoundPanel (QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
QStyle * qtmstyle ()

Function Documentation

static void qtmDrawRoundedRect ( QPainter *  p,
const QRectF &  rect,
qreal  xRadius,
qreal  yRadius,
Qt::SizeMode  mode 
) [static]

Definition at line 214 of file QTMStyle.cpp.

{
  QRectF r = rect.normalized();
  
  if (r.isNull())
    return;
  
  if (mode == Qt::AbsoluteSize) {
    qreal w = r.width() / 2;
    qreal h = r.height() / 2;
    
    xRadius = 100 * qMin(xRadius, w) / w;
    yRadius = 100 * qMin(yRadius, h) / h;
  } else {
    if (xRadius > 100)                          // fix ranges
      xRadius = 100;
    
    if (yRadius > 100)
      yRadius = 100;
  }
  
  QPainterPath path;
  
  if (xRadius <= 0 || yRadius <= 0) {             // add normal rectangle
    path.addRect(r);
  } else {
    qreal x = r.x();
    qreal y = r.y();
    qreal w = r.width();
    qreal h = r.height();
    qreal rxx2 = w*xRadius/100;
    qreal ryy2 = h*yRadius/100;
    
#ifdef Q_WS_X11
    // There is a bug (probably in arcTo) for small sizes.
    // We use a rough linear approx.
    rxx2 /= 4;
    ryy2 /= 4;
    path.moveTo(x+rxx2,y);
    path.lineTo(x+w-rxx2, y);
    path.lineTo(x+w, y+ryy2);
    path.lineTo(x+w, y+h-ryy2);    
    path.lineTo(x+w-rxx2, y+h);    
    path.lineTo(x+rxx2, y+h);    
    path.lineTo(x, y+h-ryy2);    
    path.lineTo(x, y+ryy2);    
    path.closeSubpath();
#else
    path.moveTo(x+rxx2,y);
    path.arcMoveTo(x, y, rxx2, ryy2, 90);
    path.arcTo(x, y, rxx2, ryy2, 90, 90);
    path.arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    path.arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    path.arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
    path.closeSubpath();
#endif
  }
  
  p->drawPath(path);
}

Here is the caller graph for this function:

static void qtmDrawShadeRoundPanel ( QPainter *  p,
const QRect &  r,
const QPalette &  pal,
bool  sunken,
int  lineWidth,
const QBrush *  fill 
) [static]

Definition at line 276 of file QTMStyle.cpp.

{
  if (r.width() == 0 || r.height() == 0)
    return;
  if (!(r.width() > 0 && r.height() > 0 && lineWidth >= 0)) {
    qWarning("qtmDrawShadeRoundPanel: Invalid parameters");
  }
  
  QColor shade = pal.dark().color();
  QColor light = pal.light().color();
  if (fill) {
    if (fill->color() == shade)
      shade = pal.shadow().color();
    if (fill->color() == light)
      light = pal.midlight().color();
  }
  
  QPen oldPen = p->pen();                        // save pen
  QBrush oldBrush = p->brush();                  // save brush  
  QRect rect(r);
  int border = 8;
  
  p->setPen(Qt::NoPen);
  
  if (sunken) {
    p->setBrush(light);
    qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize);
    //    p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize);
    rect.adjust(0,0,-1,-1);
    p->setBrush(shade);
    qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize);
    //    p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize);
    rect.adjust(1,1,0,0);
  }
  
  p->setBrush(fill ? *fill : shade);
  qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize);
  //  p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize);
  
  p->setPen(oldPen);                        // restore pen
  p->setBrush(oldBrush);                        // restore brush
}

Here is the call graph for this function:

Here is the caller graph for this function:

QStyle* qtmstyle ( )

Definition at line 527 of file QTMStyle.cpp.

            {
  static QStyle* qtmstyle= NULL;
  if (!qtmstyle) {
    qtmstyle = new QTMStyle ();
  }
  if (!qtmstyle) {
    qtmstyle = qApp->style ();
  }
  return qtmstyle;
}

Here is the call graph for this function:

Here is the caller graph for this function: