Back to index

kdeartwork  4.3.2
Public Member Functions | Private Member Functions | Private Attributes
IceWM::ThemeHandler Class Reference

#include <icewm.h>

List of all members.

Public Member Functions

 ThemeHandler ()
 ~ThemeHandler ()
virtual KDecoration * createDecoration (KDecorationBridge *)
virtual bool reset (unsigned long changed)
virtual bool supports (Ability ability)

Private Member Functions

void readConfig ()
QColor decodeColor (QString &s)
bool isFrameValid ()
void initTheme ()
void freePixmaps ()
void freePixmapGroup (QPixmap *p[])
void setPixmap (QPixmap *p[], QString s1, QString s2, bool stretch=false, bool stretchHoriz=true)
void setPixmapButton (QPixmap *p[], QString s1, QString s2)
QPixmap * stretchPixmap (QPixmap *src, bool stretchHoriz=true, int stretchSize=-1)
QPixmap * duplicateValidPixmap (bool act, int size=-1)
void convertButtons (QString &s)
QString reverseString (QString s)

Private Attributes

bool initialized
QString themeName

Detailed Description

Definition at line 79 of file icewm.h.


Constructor & Destructor Documentation

Definition at line 163 of file icewm.cpp.

{
       initialized = false;

       // Prevent having globals objects (use pointers to objects)
       titleButtonsLeft     = new QString();
       titleButtonsRight    = new QString();

       colorActiveBorder                  = new QColor();
       colorInActiveBorder         = new QColor();
       colorActiveButton            = new QColor();
       colorInActiveButton         = new QColor();
       colorActiveTitleBarText     = new QColor();
       colorInActiveTitleBarText   = new QColor();
       colorActiveTitleBar         = new QColor();
       colorInActiveTitleBar              = new QColor();
       colorActiveTitleTextShadow  = new QColor();
       colorInActiveTitleTextShadow = new QColor();

       // Initialize
       readConfig();
       initTheme();
       validframe = isFrameValid();
       initialized = true;
}

Here is the call graph for this function:

Definition at line 190 of file icewm.cpp.

Here is the call graph for this function:


Member Function Documentation

void IceWM::ThemeHandler::convertButtons ( QString &  s) [private]

Definition at line 218 of file icewm.cpp.

{
       s.replace( QRegExp("_"), "");      // Spacer     (ignored)
       s.replace( QRegExp("H"), "");      // Help              (ignored)
       s.replace( QRegExp("M"), "s");     // Sysmenu
       s.replace( QRegExp("S"), "d");     // Sticky/OnAllDesktops
       s.replace( QRegExp("I"), "i");     // Minimize
       s.replace( QRegExp("A"), "m");     // Maximize
       s.replace( QRegExp("X"), "x");     // Close
}

Here is the caller graph for this function:

KDecoration * IceWM::ThemeHandler::createDecoration ( KDecorationBridge *  bridge) [virtual]

Definition at line 211 of file icewm.cpp.

{
       return new IceWMClient( bridge, this );
}
QColor IceWM::ThemeHandler::decodeColor ( QString &  s) [private]

Definition at line 513 of file icewm.cpp.

{
       // Make rgb:C0/C0/C0, or #C0/C0/C0  -> C0C0C0
       s.replace( QRegExp("r"), "");
       s.replace( QRegExp("g"), "");
       s.replace( QRegExp("b"), "");
       s.replace( QRegExp("#"), "");
       s.replace( QRegExp("/"), "");
       s.replace( QRegExp(":"), "");
       s.replace( QRegExp("\\"), "");
       s.replace( QRegExp("\""), "");

       // Wierd error - return grey
       if (s.length() != 6)
              return QColor( 0xC0, 0xC0, 0xC0 );

       // Qt makes this conversion very easy
       return QColor( QString("#") + s );
}

Here is the caller graph for this function:

QPixmap * IceWM::ThemeHandler::duplicateValidPixmap ( bool  act,
int  size = -1 
) [private]

Definition at line 445 of file icewm.cpp.

{
       QPixmap* p1 = NULL;
       // Use the stretch or title pixmaps instead
       if ( titleS[act] )
              p1 = new QPixmap( *titleS[act] );
       else if ( titleB[act] )
              p1 = new QPixmap( *titleB[act] );
       else if ( titleT[act] )
              p1 = new QPixmap( *titleT[act] );

       // Stretch if required
       if ( (size != -1) && p1 && (!p1->isNull()) )
              p1 = stretchPixmap( p1, true, size );

       return p1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IceWM::ThemeHandler::freePixmapGroup ( QPixmap *  p[]) [private]

Definition at line 499 of file icewm.cpp.

{
       if (p)
       {
              if (p[Active])   delete p[Active];
              if (p[InActive]) delete p[InActive];
              p[Active] = NULL;
              p[InActive] = NULL;
       } else
              qWarning("kwin-icewm: freePixmapGroup - invalid QPixmap** 'p'\n");
}

Here is the caller graph for this function:

void IceWM::ThemeHandler::initTheme ( ) [private]

Definition at line 275 of file icewm.cpp.

{
       // Add a slash if required
       if ( !themeName.isEmpty() )
              themeName += "/";

       // We use kconfig to read icewm config files...
       // this is easy since icewm uses key=value pairs!
       KConfig config( locate("data", QString("kwin/icewm-themes/") +
                                   themeName + QString("default.theme")) );

       // Load specifics, or use IceWM defaults instead.
       borderSizeX = config.readNumEntry("BorderSizeX", 6);
       borderSizeY = config.readNumEntry("BorderSizeY", 6);
       cornerSizeX = config.readNumEntry("CornerSizeX", 24);
       cornerSizeY = config.readNumEntry("CornerSizeY", 24);
       titleBarCentered = (bool) config.readNumEntry("TitleBarCentered", 0);

       // Check if readConfig() hasn't overridden this value...
       if (!showMenuButtonIcon)
              showMenuButtonIcon = (bool) config.readNumEntry("ShowMenuButtonIcon", 0);
       titleBarHeight = config.readNumEntry("TitleBarHeight", 20);

       if (!customButtonPositions)
       {
              // Read in the button configuration, stripping any quotes
              // Ignore on all desktops 'd' on the left buttons
              // (some themes look bad with it on by default)
              *titleButtonsLeft = config.readEntry("TitleButtonsLeft", "s");
              *titleButtonsLeft = titleButtonsLeft->replace( QRegExp(QString("\"")), "");
              *titleButtonsRight = config.readEntry("TitleButtonsRight", "xmir");
              *titleButtonsRight = titleButtonsRight->replace( QRegExp(QString("\"")), "");

              // I have no idea why the right side buttons in icewm are reversed
              *titleButtonsRight = reverseString( *titleButtonsRight );
       }

       // Read the default border and text colours from the config file
       // And use IceWM defaults if not found
       QString s;

       s = config.readEntry("Look", "other");
       if (s=="motif") themeLook = MOTIF;
       else if (s=="warp3") themeLook = WARP3;
       else if (s=="warp4") themeLook = WARP4;
       else if (s=="win95") themeLook = WIN95;
       else if (s=="nice") themeLook = NICE;
       else themeLook = OTHER;

       s = config.readEntry("ColorActiveBorder", "#C0C0C0");
       *colorActiveBorder = decodeColor( s );
       s = config.readEntry("ColorNormalBorder", "#C0C0C0");
       *colorInActiveBorder = decodeColor( s );
       s = config.readEntry("ColorActiveButton", "#C0C0C0");
       *colorActiveButton = decodeColor( s );
       s = config.readEntry("ColorNormalButton", "#C0C0C0");
       *colorInActiveButton = decodeColor( s );

       // Use these as a last resort
       s = config.readEntry("ColorActiveTitleBar", "#0000A0");
       *colorActiveTitleBar = decodeColor( s );
       s = config.readEntry("ColorNormalTitleBar", "#808080");
       *colorInActiveTitleBar = decodeColor( s );

       // Read titlebar text colours
       s = config.readEntry("ColorActiveTitleBarText", "#FFFFFF");
       *colorActiveTitleBarText = decodeColor( s );
       s = config.readEntry("ColorNormalTitleBarText", "#000000");
       *colorInActiveTitleBarText = decodeColor( s );

       // Use title text shadows only with theme title text colors
       if ( themeTitleTextColors )
       {
              s = config.readEntry("ColorActiveTitleBarShadow");
              if (!s.isEmpty())
              {
                     *colorActiveTitleTextShadow = decodeColor( s );
                     useActiveShadow = true;
              } else
                     useActiveShadow = false;

              s = config.readEntry("ColorNormalTitleBarShadow");
              if (!s.isEmpty())
              {
                     *colorInActiveTitleTextShadow = decodeColor( s );
                     useInActiveShadow = true;
              } else
                     useInActiveShadow = false;
       } else
              {
                     useActiveShadow = false;
                     useInActiveShadow = false;
              }

       // Stretch pixmaps for speed, where required
       setPixmap( titleJ, "title", "J.xpm" );
       setPixmap( titleL, "title", "L.xpm" );
       setPixmap( titleS, "title", "S.xpm", true );

       setPixmap( titleP, "title", "P.xpm" );
       setPixmap( titleT, "title", "T.xpm", true );
       setPixmap( titleM, "title", "M.xpm" );
       setPixmap( titleB, "title", "B.xpm", true );
       setPixmap( titleR, "title", "R.xpm" );
       setPixmap( titleQ, "title", "Q.xpm" );

       setPixmapButton( closePix,     "close",     ".xpm" );
       setPixmapButton( depthPix,     "depth",     ".xpm" );
       setPixmapButton( maximizePix,  "maximize",  ".xpm" );
       setPixmapButton( minimizePix,  "minimize",  ".xpm" );
       setPixmapButton( restorePix,   "restore",   ".xpm" );
       setPixmapButton( hidePix,      "hide",      ".xpm" );
       setPixmapButton( rollupPix,    "rollup",    ".xpm" );
       setPixmapButton( rolldownPix,  "rolldown",  ".xpm" );
       setPixmapButton( menuButtonPix,"menuButton",".xpm" );

       // Top
       setPixmap( frameTL, "frame", "TL.xpm" );
       setPixmap( frameT,  "frame", "T.xpm", true );
       setPixmap( frameTR, "frame", "TR.xpm" );

       // Sides
       setPixmap( frameL, "frame", "L.xpm", true, Vertical );
       setPixmap( frameR, "frame", "R.xpm", true, Vertical );

       // Bottom
       setPixmap( frameBL, "frame", "BL.xpm" );
       setPixmap( frameB,  "frame", "B.xpm", true );
       setPixmap( frameBR, "frame", "BR.xpm" );

    // Make sure border sizes are at least reasonable...
       if (borderSizeX < 0)
              borderSizeX = 0;
       if (borderSizeY < 0)
              borderSizeY = 0;
       // ...and titleBarHeight as well
       if (titleBarHeight < 0)
              titleBarHeight = 0;

       // This is a work-around for some themes
       if (!titleT[Active])
              titleT[Active] = duplicateValidPixmap( Active );

       if (!titleB[Active])
              titleB[Active] = duplicateValidPixmap( Active );


       if (titleL[Active] && !titleL[InActive])
              titleL[InActive] = duplicateValidPixmap( InActive, titleL[Active]->width() );

       if (titleS[Active] && !titleS[InActive])
              titleS[InActive] = duplicateValidPixmap( InActive, titleS[Active]->width() );

       if (titleP[Active] && !titleP[InActive])
              titleP[InActive] = duplicateValidPixmap( InActive, titleP[Active]->width() );

       if (titleT[Active] && !titleT[InActive])
              titleT[InActive] = duplicateValidPixmap( InActive, titleT[Active]->width() );

       if (titleM[Active] && !titleM[InActive])
              titleM[InActive] = duplicateValidPixmap( InActive, titleM[Active]->width() );

       if (titleB[Active] && !titleB[InActive])
              titleB[InActive] = duplicateValidPixmap( InActive, titleB[Active]->width() );

       if (titleR[Active] && !titleR[InActive])
              titleR[InActive] = duplicateValidPixmap( InActive, titleR[Active]->width() );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 724 of file icewm.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void IceWM::ThemeHandler::readConfig ( ) [private]

Definition at line 247 of file icewm.cpp.

{
       KConfig conf("kwinicewmrc");
       conf.setGroup("General");
       themeName = conf.readEntry("CurrentTheme");
       themeTitleTextColors = conf.readEntry("ThemeTitleTextColors", true);
       showMenuButtonIcon = conf.readEntry("ShowMenuButtonIcon", false);
       titleBarOnTop = conf.readEntry("TitleBarOnTop", true);

       customButtonPositions = KDecoration::options()->customButtonPositions();
       if (customButtonPositions)
       {
              *titleButtonsLeft  = KDecoration::options()->titleButtonsLeft();
              *titleButtonsRight = KDecoration::options()->titleButtonsRight();

              // Convert KDE to icewm style buttons
              convertButtons( *titleButtonsLeft );
              convertButtons( *titleButtonsRight );
       }

       // Provide a default theme alias
       if (themeName == "default")
              themeName = "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IceWM::ThemeHandler::reset ( unsigned long  changed) [virtual]

Definition at line 739 of file icewm.cpp.

{
       initialized = false;
       freePixmaps();
       readConfig();
       initTheme();
       validframe = isFrameValid();
       initialized = true;

       // recreate all clients
       return true;
}

Here is the call graph for this function:

QString IceWM::ThemeHandler::reverseString ( QString  s) [private]

Definition at line 231 of file icewm.cpp.

{
       if (s.length() <= 1)
              return s;

       QString tmpStr;
       for(int i = s.length()-1; i >= 0; i--)
       {
              tmpStr += s[(unsigned int)i];
       }

       return tmpStr;
}

Here is the caller graph for this function:

void IceWM::ThemeHandler::setPixmap ( QPixmap *  p[],
QString  s1,
QString  s2,
bool  stretch = false,
bool  stretchHoriz = true 
) [private]

Definition at line 690 of file icewm.cpp.

{
       if ( p[Active] )
              qWarning("kwin-icewm: setPixmap - should be null (1)\n");
       if ( p[InActive] )
              qWarning("kwin-icewm: setPixmap - should be null (2)\n");

       p[Active]   = new QPixmap( locate("data", QString("kwin/icewm-themes/")
                                                        + themeName + s1 + "A" + s2) );
       p[InActive] = new QPixmap( locate("data", QString("kwin/icewm-themes/")
                                                        + themeName + s1 + "I" + s2) );

       // Stretch the pixmap if requested.
       if ( stretch )
       {
              if (p[Active])
                     p[Active] = stretchPixmap( p[Active], stretchHoriz );
              if (p[InActive])
                     p[InActive] = stretchPixmap( p[InActive], stretchHoriz );
       }

       if ( p[Active] && p[InActive] )
       {
              // Make sure active and inactive pixmaps are the same width for proper painting
              if (p[Active]->width() > p[InActive]->width())
                     p[InActive] = stretchPixmap( p[InActive], true, p[Active]->width() );
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void IceWM::ThemeHandler::setPixmapButton ( QPixmap *  p[],
QString  s1,
QString  s2 
) [private]

Definition at line 592 of file icewm.cpp.

{
       if ( p[Active] )
              qWarning("kwin-icewm: setPixmap - should be null (1)\n");
       if ( p[InActive] )
              qWarning("kwin-icewm: setPixmap - should be null (2)\n");

       QString str = locate("appdata", QString("icewm-themes/")
                            + themeName + s1 + "A" + s2);
       if (str.isEmpty())
              str = locate("appdata", QString("icewm-themes/")
                            + themeName + s1 + s2);

        QPixmap *qp = new QPixmap(str);
       QColor cActive = themeLook == WIN95 ? *colorActiveTitleBar : *colorActiveButton;
       QColor cInActive = themeLook == WIN95 ? *colorInActiveTitleBar : *colorInActiveButton;

       if (!qp->isNull() && themeLook > 0) {
              int w = qp->width();
              if (themeLook > 0 && titleBarHeight > w) w = titleBarHeight;
              p[Active] = new QPixmap(w, 2*titleBarHeight );
              p[Active] -> fill(cActive);

              QPainter pnt( p[Active] );

              int offX = (w - qp->width())/2;
              int offY = (titleBarHeight - qp->height())/2;
              if (offY < 0) offY = 0;

              if (themeLook == WIN95) {
                     draw3DRect(pnt, *colorActiveButton, offX-1, offY-1,
                               qp->width()+1, qp->height()+1, true);
                     draw3DRect(pnt, *colorActiveButton, offX-1, offY-1 + titleBarHeight,
                               qp->width()+1, qp->height()+1, false);
              } else if (themeLook != WARP4) {
                     draw3DRect(pnt, *colorActiveButton, 0, 0,
                               w-1, titleBarHeight-1, true);
                     draw3DRect(pnt, *colorActiveButton, 0, titleBarHeight,
                               w-1, 2*titleBarHeight-1, false);
              }

              pnt.drawPixmap(offX, offY, *qp);
              if (qp->height() <= titleBarHeight) {
                     pnt.drawPixmap(offX, titleBarHeight+offY, *qp);
              }
              pnt.end();
              delete qp;
       } else {
              p[Active] = qp;
       }

       str = locate("appdata", QString("icewm-themes/")
                   + themeName + s1 + "I" + s2);
       if (str.isEmpty())
              str = locate("appdata", QString("icewm-themes/")
                          + themeName + s1 + s2);

        qp = new QPixmap(str);
       if (!qp->isNull() && themeLook > 0) {
              int w = qp->width();
              if (titleBarHeight > w) w = titleBarHeight;
              p[InActive] = new QPixmap(w, 2*titleBarHeight );
              p[InActive] -> fill(cInActive);

              QPainter pnt( p[InActive] );

              int offX = (w - qp->width())/2;
              int offY = (titleBarHeight - qp->height())/2;
              if (offY < 0) offY = 0;

              if (themeLook == WIN95) {
                     draw3DRect(pnt, *colorInActiveButton, offX-1, offY-1,
                               qp->width()+1, qp->height()+1, true);
                     draw3DRect(pnt, *colorInActiveButton, offX-1, offY-1 + titleBarHeight,
                               qp->width()+1, qp->height()+1, false);
              } else if (themeLook != WARP4) {
                     draw3DRect(pnt, *colorInActiveButton, 0, 0,
                               w-1, titleBarHeight-1, true);
                     draw3DRect(pnt, *colorActiveButton, 0, titleBarHeight,
                               w-1, 2*titleBarHeight-1, false);
              }
              pnt.drawPixmap(offX, offY, *qp);
              if (qp->height() <= titleBarHeight) {
                     pnt.drawPixmap(offX, titleBarHeight+offY, *qp);
              }
              pnt.end();
              delete qp;
       } else {
              p[InActive] = qp;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

QPixmap * IceWM::ThemeHandler::stretchPixmap ( QPixmap *  src,
bool  stretchHoriz = true,
int  stretchSize = -1 
) [private]

Definition at line 536 of file icewm.cpp.

{
       if (!src) return NULL;
       if (src->isNull()) return NULL;

       int s_inc, size;

       // If it is the right size already, just return
       if (stretchSize == -1)
       {
              if (stretchHoriz)
                     s_inc = src->width();
              else
                     s_inc = src->height();

              size = s_inc;
              if (size >= 100)
                     return src;

              // Stretch an appropriate amount - taking care of pattern repetition
              while( size < 100 )
                     size += s_inc;
       } else
              size = stretchSize;

       QPixmap* p = new QPixmap();
       if ( stretchHoriz )
              p->resize( size, src->height() );
       else
              p->resize( src->width(), size );

       QPainter pnt( p );
       if ( stretchHoriz )
              pnt.drawTiledPixmap( 0, 0, size, src->height(), *src);
       else
              pnt.drawTiledPixmap( 0, 0, src->width(), size, *src);
       pnt.end();

       delete src;
       return p;
}

Here is the caller graph for this function:

bool IceWM::ThemeHandler::supports ( Ability  ability) [virtual]

Definition at line 752 of file icewm.cpp.

{
    switch( ability )
    {
        case AbilityAnnounceButtons:
        case AbilityButtonMenu:
        case AbilityButtonOnAllDesktops:
        case AbilityButtonMinimize:
        case AbilityButtonMaximize:
        case AbilityButtonClose:
            return true;
        default:
            return false;
    };
}

Member Data Documentation

Definition at line 90 of file icewm.h.

QString IceWM::ThemeHandler::themeName [private]

Definition at line 91 of file icewm.h.


The documentation for this class was generated from the following files: