QCDEStyle Class Reference

#include <qcdestyle.h>

Inheritance diagram for QCDEStyle:

Inheritance graph
[legend]
Collaboration diagram for QCDEStyle:

Collaboration graph
[legend]
List of all members.

Detailed Description

The QCDEStyle class provides a CDE look and feel.

This style provides a slightly improved Motif look similar to some versions of the Common Desktop Environment (CDE). The main differences are thinner frames and more modern radio buttons and checkboxes. Together with a dark background and a bright text/foreground color, the style looks quite attractive (at least for Motif fans).

Note that most of the functions provided by QCDEStyle are reimplementations of QStyle functions; see QStyle for their documentation. QCDEStyle provides overloads for drawControl() and drawPrimitive() which are documented here.

qcdestyle.png

See also:
QWindowsXPStyle, QMacStyle, QWindowsStyle, QPlastiqueStyle, QMotifStyle

Definition at line 36 of file qcdestyle.h.

Public Member Functions

 QCDEStyle (bool useHighlightCols=false)
virtual ~QCDEStyle ()
int pixelMetric (PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
void drawControl (ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
void drawPrimitive (PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
QPalette standardPalette () const

Protected Slots

QIcon standardIconImplementation (StandardPixmap standardIcon, const QStyleOption *opt=0, const QWidget *widget=0) const


Constructor & Destructor Documentation

QCDEStyle::QCDEStyle ( bool  useHighlightCols = false  )  [explicit]

Constructs a QCDEStyle.

If useHighlightCols is false (the default), then the style will polish the application's color palette to emulate the Motif way of highlighting, which is a simple inversion between the base and the text color.

Definition at line 82 of file qcdestyle.cpp.

00083     : QMotifStyle(useHighlightCols)
00084 {
00085 }

QCDEStyle::~QCDEStyle (  )  [virtual]

Destroys the style.

Definition at line 90 of file qcdestyle.cpp.

00091 {
00092 }


Member Function Documentation

int QCDEStyle::pixelMetric ( PixelMetric  metric,
const QStyleOption option = 0,
const QWidget widget = 0 
) const [virtual]

Reimplemented from QMotifStyle.

Definition at line 97 of file qcdestyle.cpp.

References QMotifStyle::pixelMetric().

Referenced by drawPrimitive().

00103 {
00104     int ret = 0;
00105 
00106     switch(metric) {
00107     case PM_MenuBarPanelWidth:
00108     case PM_DefaultFrameWidth:
00109     case PM_FocusFrameVMargin:
00110     case PM_FocusFrameHMargin:
00111     case PM_MenuPanelWidth:
00112     case PM_SpinBoxFrameWidth:
00113     case PM_MenuBarVMargin:
00114     case PM_MenuBarHMargin:
00115     case PM_DockWidgetFrameWidth:
00116         ret = 1;
00117         break;
00118     case PM_ScrollBarExtent:
00119         ret = 13;
00120         break;
00121     default:
00122         ret = QMotifStyle::pixelMetric(metric, option, widget);
00123         break;
00124     }
00125     return ret;
00126 }

Here is the call graph for this function:

void QCDEStyle::drawControl ( ControlElement  element,
const QStyleOption opt,
QPainter p,
const QWidget widget = 0 
) const [virtual]

Reimplemented from QMotifStyle.

Definition at line 131 of file qcdestyle.cpp.

References QRect::adjusted(), QPalette::brush(), QPalette::Button, QStyle::CE_MenuBarItem, QStyle::CE_RubberBand, QPalette::dark(), QMotifStyle::drawControl(), QCommonStyle::drawControl(), p, QStyleOption::palette, path, qDrawShadePanel(), QStyleOption::rect, QStyleOption::state, and QStyle::State_Selected.

00133 {
00134 
00135     switch(element) {
00136     case CE_MenuBarItem: {
00137         if (opt->state & State_Selected)  // active item
00138             qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
00139                             &opt->palette.brush(QPalette::Button));
00140         else  // other item
00141             p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
00142         QCommonStyle::drawControl(element, opt, p, widget);
00143         break; }
00144     case CE_RubberBand: {
00145         p->save();
00146         p->setClipping(false);
00147         QPainterPath path;
00148         path.addRect(opt->rect);
00149         path.addRect(opt->rect.adjusted(2, 2, -2, -2));
00150         p->fillPath(path, opt->palette.dark());
00151         p->restore();
00152         break; }
00153     default:
00154         QMotifStyle::drawControl(element, opt, p, widget);
00155     break;
00156     }
00157 }

Here is the call graph for this function:

void QCDEStyle::drawPrimitive ( PrimitiveElement  pe,
const QStyleOption opt,
QPainter p,
const QWidget widget = 0 
) const [virtual]

Reimplemented from QMotifStyle.

Definition at line 162 of file qcdestyle.cpp.

References a, QPalette::background(), QPalette::brush(), QPalette::Button, QBrush::color(), QPalette::Dark, QPalette::dark(), Qt::Dense5Pattern, QMotifStyle::drawPrimitive(), QPalette::foreground(), i, INTARRLEN, QPalette::light(), QPalette::Mid, p, QStyleOption::palette, QStyle::PE_IndicatorCheckBox, QStyle::PE_IndicatorRadioButton, pixelMetric(), QStyle::PM_DefaultFrameWidth, qDrawShadePanel(), QStyleOption::rect, QStyle::SH_DitherDisabledText, QStyleOption::state, QStyle::State_Enabled, QStyle::State_NoChange, QStyle::State_On, QStyle::State_Sunken, QMotifStyle::styleHint(), QRect::width(), QPalette::Window, QRect::x(), and QRect::y().

00164 {
00165     switch(pe) {
00166     case PE_IndicatorCheckBox: {
00167         bool down = opt->state & State_Sunken;
00168         bool on = opt->state & State_On;
00169         bool showUp = !(down ^ on);
00170         QBrush fill = (showUp || (opt->state & State_NoChange)) ? opt->palette.brush(QPalette::Button) : opt->palette.brush(QPalette::Mid);
00171         qDrawShadePanel(p, opt->rect, opt->palette, !showUp, pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush(QPalette::Button));
00172 
00173         if (on || (opt->state & State_NoChange)) {
00174             QRect r = opt->rect;
00175             QPolygon a(7 * 2);
00176             int i, xx, yy;
00177             xx = r.x() + 3;
00178             yy = r.y() + 5;
00179             if (opt->rect.width() <= 9) {
00180                 // When called from CE_MenuItem in QMotifStyle
00181                 xx -= 2;
00182                 yy -= 2;
00183             }
00184 
00185             for (i = 0; i < 3; i++) {
00186                 a.setPoint(2 * i, xx, yy);
00187                 a.setPoint(2 * i + 1, xx, yy + 2);
00188                 xx++; yy++;
00189             }
00190             yy -= 2;
00191             for (i = 3; i < 7; i++) {
00192                 a.setPoint(2 * i, xx, yy);
00193                 a.setPoint(2 * i + 1, xx, yy + 2);
00194                 xx++; yy--;
00195             }
00196             if (opt->state & State_NoChange)
00197                 p->setPen(opt->palette.dark().color());
00198             else
00199                 p->setPen(opt->palette.foreground().color());
00200             p->drawPolyline(a);
00201         }
00202         if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
00203             p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
00204     } break;
00205     case PE_IndicatorRadioButton:
00206         {
00207             QRect r = opt->rect;
00208 #define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)
00209             static const int pts1[] = {              // up left  lines
00210                 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
00211             static const int pts4[] = {              // bottom right  lines
00212                 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
00213                 11,4, 10,3, 10,2 };
00214             static const int pts5[] = {              // inner fill
00215                 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
00216             bool down = opt->state & State_Sunken;
00217             bool on = opt->state & State_On;
00218             QPolygon a(INTARRLEN(pts1), pts1);
00219             a.translate(r.x(), r.y());
00220             QPen oldPen = p->pen();
00221             QBrush oldBrush = p->brush();
00222             p->setPen((down || on) ? opt->palette.dark().color() : opt->palette.light().color());
00223             p->drawPolyline(a);
00224             a.setPoints(INTARRLEN(pts4), pts4);
00225             a.translate(r.x(), r.y());
00226             p->setPen((down || on) ? opt->palette.light().color() : opt->palette.dark().color());
00227             p->drawPolyline(a);
00228             a.setPoints(INTARRLEN(pts5), pts5);
00229             a.translate(r.x(), r.y());
00230             QColor fillColor = on ? opt->palette.dark().color() : opt->palette.background().color();
00231             p->setPen(fillColor);
00232             p->setBrush(on ? opt->palette.brush(QPalette::Dark) :
00233                          opt->palette.brush(QPalette::Window));
00234             p->drawPolygon(a);
00235             if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
00236                 p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
00237             p->setPen(oldPen);
00238             p->setBrush(oldBrush);
00239         } break;
00240     default:
00241         QMotifStyle::drawPrimitive(pe, opt, p, widget);
00242     }
00243 }

Here is the call graph for this function:

QPalette QCDEStyle::standardPalette (  )  const [virtual]

Reimplemented from QMotifStyle.

Definition at line 246 of file qcdestyle.cpp.

References background, QPalette::Base, Qt::black, QPalette::ButtonText, QPalette::Disabled, palette, QPalette::Text, Qt::white, and QPalette::WindowText.

00247 {
00248     QColor background = QColor(0xb6, 0xb6, 0xcf);
00249     QColor light = background.light();
00250     QColor mid = background.dark(150);
00251     QColor dark = background.dark();
00252     QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
00253     palette.setBrush(QPalette::Disabled, QPalette::WindowText, dark);
00254     palette.setBrush(QPalette::Disabled, QPalette::Text, dark);
00255     palette.setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
00256     palette.setBrush(QPalette::Disabled, QPalette::Base, background);
00257     return palette;
00258 }

QIcon QCDEStyle::standardIconImplementation ( StandardPixmap  standardIcon,
const QStyleOption opt = 0,
const QWidget widget = 0 
) const [protected, slot]

Since:
4.1
Returns an icon for the given standardIcon.

Reimplement this slot to provide your own icons in a QStyle subclass; because of binary compatibility constraints, the standardIcon() function (introduced in Qt 4.1) is not virtual. Instead, standardIcon() will dynamically detect and call this slot. The default implementation simply calls the standardPixmap() function with the given parameters.

The standardIcon is a standard pixmap which can follow some existing GUI style or guideline. The option argument can be used to pass extra information required when defining the appropriate icon. The widget argument is optional and can also be used to aid the determination of the icon.

See also:
standardIcon()

Reimplemented from QMotifStyle.

Definition at line 263 of file qcdestyle.cpp.

References QMotifStyle::standardIconImplementation().

00265 {
00266     return QMotifStyle::standardIconImplementation(standardIcon, opt, widget);
00267 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:57:51 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1