diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 18:41:30 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 20:55:03 +0900 |
commit | 5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90 (patch) | |
tree | f89cc49efc9ca1d0e1579ecb079ee7e7088ff8c8 /src/libs/themeengine | |
parent | 0bfbf616d9c1fd7abb1bd02732389ab35e5f8771 (diff) | |
download | digikam-5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90.tar.gz digikam-5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90.zip |
Rename 'digikam' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit ee0d99607c14cb63d3ebdb3a970b508949fa8219)
Diffstat (limited to 'src/libs/themeengine')
-rw-r--r-- | src/libs/themeengine/Makefile.am | 12 | ||||
-rw-r--r-- | src/libs/themeengine/texture.cpp | 495 | ||||
-rw-r--r-- | src/libs/themeengine/texture.h | 83 | ||||
-rw-r--r-- | src/libs/themeengine/theme.cpp | 181 | ||||
-rw-r--r-- | src/libs/themeengine/theme.h | 112 | ||||
-rw-r--r-- | src/libs/themeengine/themeengine.cpp | 1132 | ||||
-rw-r--r-- | src/libs/themeengine/themeengine.h | 107 |
7 files changed, 2122 insertions, 0 deletions
diff --git a/src/libs/themeengine/Makefile.am b/src/libs/themeengine/Makefile.am new file mode 100644 index 00000000..f2e5f4ce --- /dev/null +++ b/src/libs/themeengine/Makefile.am @@ -0,0 +1,12 @@ +METASOURCES = AUTO + +noinst_LTLIBRARIES = libthemeengine.la + +libthemeengine_la_SOURCES = theme.cpp themeengine.cpp texture.cpp + +libthemeengine_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor + +INCLUDES = -I$(top_srcdir)/src/libs/dimg \ + -I$(top_srcdir)/src/digikam \ + -I$(top_srcdir)/src/ \ + $(all_includes) diff --git a/src/libs/themeengine/texture.cpp b/src/libs/themeengine/texture.cpp new file mode 100644 index 00000000..e728dd59 --- /dev/null +++ b/src/libs/themeengine/texture.cpp @@ -0,0 +1,495 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-07-26 + * Description : texture pixmap methods + * + * Copyright (C) 2004 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * + * Adapted from fluxbox: Texture/TextureRender + * + * Texture.cc for Fluxbox Window Manager + * Copyright (c) 2002-2003 Henrik Kinnunen <fluxbox@users.sourceforge.net> + * + * from Image.cc for Blackbox - an X11 Window manager + * Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * + * ============================================================ */ + +// C++ includes. + +#include <cstring> +#include <cstdio> + +// TQt includes. + +#include <tqpainter.h> +#include <tqimage.h> +#include <tqpixmap.h> + +// Local includes. + +#include "theme.h" +#include "texture.h" + +namespace Digikam +{ + +class TexturePriv +{ +public: + + TexturePriv() + { + red = 0; + green = 0; + blue = 0; + } + + bool border; + + unsigned char *red; + unsigned char *green; + unsigned char *blue; + + int width; + int height; + + TQPixmap pixmap; + + TQColor color0; + TQColor color1; + TQColor borderColor; + + Theme::Bevel bevel; + Theme::Gradient gradient; +}; + +Texture::Texture(int w, int h, const TQColor& from, const TQColor& to, + Theme::Bevel bevel, Theme::Gradient gradient, + bool border, const TQColor& borderColor) +{ + d = new TexturePriv; + + d->bevel = bevel; + d->gradient = gradient; + d->border = border; + d->borderColor = borderColor; + + if (!border) + { + d->width = w; + d->height = h; + } + else + { + d->width = w-2; + d->height = h-2; + } + + if (d->width <= 0 || d->height <= 0) + return; + + if (bevel & Theme::SUNKEN) + { + d->color0 = to; + d->color1 = from; + } + else + { + d->color0 = from; + d->color1 = to; + } + + if (gradient == Theme::SOLID) + { + doSolid(); + } + else + { + d->red = new unsigned char[w*h]; + d->green = new unsigned char[w*h]; + d->blue = new unsigned char[w*h]; + + if (gradient == Theme::HORIZONTAL) + doHgradient(); + else if (gradient == Theme::VERTICAL) + doVgradient(); + else if (gradient == Theme::DIAGONAL) + doDgradient(); + + if (bevel & Theme::RAISED || bevel & Theme::SUNKEN) + doBevel(); + + buildImage(); + } +} + +Texture::~Texture() +{ + if (d->red) + delete [] d->red; + if (d->green) + delete [] d->green; + if (d->blue) + delete [] d->blue; + + delete d; +} + +TQPixmap Texture::renderPixmap() const +{ + if (d->width <= 0 || d->height <= 0) + return TQPixmap(); + + if (!d->border) + return d->pixmap; + + TQPixmap pix(d->width+2, d->height+2); + bitBlt(&pix, 1, 1, &d->pixmap, 0, 0); + TQPainter p(&pix); + p.setPen(d->borderColor); + p.drawRect(0, 0, d->width+2, d->height+2); + p.end(); + + return pix; +} + +void Texture::doSolid() +{ + d->pixmap.resize(d->width, d->height); + TQPainter p(&d->pixmap); + p.fillRect(0, 0, d->width, d->height, d->color0); + if (d->bevel == Theme::RAISED) + { + p.setPen(d->color0.light(120)); + p.drawLine(0, 0, d->width-1, 0); // top + p.drawLine(0, 0, 0, d->height-1); // left + p.setPen(d->color0.dark(120)); + p.drawLine(0, d->height-1, d->width-1, d->height-1); // bottom + p.drawLine(d->width-1, 0, d->width-1, d->height-1); // right + } + else if (d->bevel == Theme::SUNKEN) + { + p.setPen(d->color0.dark(120)); + p.drawLine(0, 0, d->width-1, 0); // top + p.drawLine(0, 0, 0, d->height-1); // left + p.setPen(d->color0.light(120)); + p.drawLine(0, d->height-1, d->width-1, d->height-1); // bottom + p.drawLine(d->width-1, 0, d->width-1, d->height-1); // right + } + p.end(); +} + +void Texture::doHgradient() +{ + float drx, dgx, dbx, + xr = (float) d->color0.red(), + xg = (float) d->color0.green(), + xb = (float) d->color0.blue(); + unsigned char *pr = d->red, *pg = d->green, *pb = d->blue; + + int x, y; + + drx = (float) (d->color1.red() - d->color0.red()); + dgx = (float) (d->color1.green() - d->color0.green()); + dbx = (float) (d->color1.blue() - d->color0.blue()); + + drx /= d->width; + dgx /= d->width; + dbx /= d->width; + + for (x = 0; x < d->width; x++) + { + *(pr++) = (unsigned char) (xr); + *(pg++) = (unsigned char) (xg); + *(pb++) = (unsigned char) (xb); + + xr += drx; + xg += dgx; + xb += dbx; + } + + for (y = 1; y < d->height; y++, pr += d->width, pg += d->width, pb += d->width) + { + memcpy(pr, d->red, d->width); + memcpy(pg, d->green, d->width); + memcpy(pb, d->blue, d->width); + } +} + +void Texture::doVgradient() +{ + float dry, dgy, dby, + yr = (float) d->color0.red(), + yg = (float) d->color0.green(), + yb = (float) d->color0.blue(); + + dry = (float) (d->color1.red() - d->color0.red()); + dgy = (float) (d->color1.green() - d->color0.green()); + dby = (float) (d->color1.blue() - d->color0.blue()); + + dry /= d->height; + dgy /= d->height; + dby /= d->height; + + unsigned char *pr = d->red, *pg = d->green, *pb = d->blue; + int y; + + for (y = 0; y < d->height; y++, pr += d->width, pg += d->width, pb += d->width) { + memset(pr, (unsigned char) yr, d->width); + memset(pg, (unsigned char) yg, d->width); + memset(pb, (unsigned char) yb, d->width); + + yr += dry; + yg += dgy; + yb += dby; + } +} + +void Texture::doDgradient() +{ + unsigned int* xtable = new unsigned int[d->width*3]; + unsigned int* ytable = new unsigned int[d->height*3]; + + float drx, dgx, dbx, dry, dgy, dby, yr = 0.0, yg = 0.0, yb = 0.0, + xr = (float) d->color0.red(), + xg = (float) d->color0.green(), + xb = (float) d->color0.blue(); + unsigned char *pr = d->red, *pg = d->green, *pb = d->blue; + unsigned int w = d->width * 2, h = d->height * 2; + unsigned int *xt = xtable; + unsigned int *yt = ytable; + + int x, y; + + dry = drx = (float) (d->color1.red() - d->color0.red()); + dgy = dgx = (float) (d->color1.green() - d->color0.green()); + dby = dbx = (float) (d->color1.blue() - d->color0.blue()); + + // Create X table + drx /= w; + dgx /= w; + dbx /= w; + + for (x = 0; x < d->width; x++) + { + *(xt++) = (unsigned char) (xr); + *(xt++) = (unsigned char) (xg); + *(xt++) = (unsigned char) (xb); + + xr += drx; + xg += dgx; + xb += dbx; + } + + // Create Y table + dry /= h; + dgy /= h; + dby /= h; + + for (y = 0; y < d->height; y++) + { + *(yt++) = ((unsigned char) yr); + *(yt++) = ((unsigned char) yg); + *(yt++) = ((unsigned char) yb); + + yr += dry; + yg += dgy; + yb += dby; + } + + // Combine tables to create gradient + + for (yt = ytable, y = 0; y < d->height; y++, yt += 3) + { + for (xt = xtable, x = 0; x < d->width; x++) + { + *(pr++) = *(xt++) + *(yt); + *(pg++) = *(xt++) + *(yt + 1); + *(pb++) = *(xt++) + *(yt + 2); + } + } + + delete [] xtable; + delete [] ytable; +} + +void Texture::doBevel() +{ + unsigned char *pr = d->red, *pg = d->green, *pb = d->blue; + + unsigned char r, g, b, rr ,gg ,bb; + unsigned int w = d->width, h = d->height - 1, wh = w * h; + + while (--w) + { + r = *pr; + rr = r + (r >> 1); + if (rr < r) rr = ~0; + g = *pg; + gg = g + (g >> 1); + if (gg < g) gg = ~0; + b = *pb; + bb = b + (b >> 1); + if (bb < b) bb = ~0; + + *pr = rr; + *pg = gg; + *pb = bb; + + r = *(pr + wh); + rr = (r >> 2) + (r >> 1); + if (rr > r) rr = 0; + g = *(pg + wh); + gg = (g >> 2) + (g >> 1); + if (gg > g) gg = 0; + b = *(pb + wh); + bb = (b >> 2) + (b >> 1); + if (bb > b) bb = 0; + + *((pr++) + wh) = rr; + *((pg++) + wh) = gg; + *((pb++) + wh) = bb; + } + + r = *pr; + rr = r + (r >> 1); + if (rr < r) rr = ~0; + g = *pg; + gg = g + (g >> 1); + if (gg < g) gg = ~0; + b = *pb; + bb = b + (b >> 1); + if (bb < b) bb = ~0; + + *pr = rr; + *pg = gg; + *pb = bb; + + r = *(pr + wh); + rr = (r >> 2) + (r >> 1); + if (rr > r) rr = 0; + g = *(pg + wh); + gg = (g >> 2) + (g >> 1); + if (gg > g) gg = 0; + b = *(pb + wh); + bb = (b >> 2) + (b >> 1); + if (bb > b) bb = 0; + + *(pr + wh) = rr; + *(pg + wh) = gg; + *(pb + wh) = bb; + + pr = d->red + d->width; + pg = d->green + d->width; + pb = d->blue + d->width; + + while (--h) + { + r = *pr; + rr = r + (r >> 1); + if (rr < r) rr = ~0; + g = *pg; + gg = g + (g >> 1); + if (gg < g) gg = ~0; + b = *pb; + bb = b + (b >> 1); + if (bb < b) bb = ~0; + + *pr = rr; + *pg = gg; + *pb = bb; + + pr += d->width - 1; + pg += d->width - 1; + pb += d->width - 1; + + r = *pr; + rr = (r >> 2) + (r >> 1); + if (rr > r) rr = 0; + g = *pg; + gg = (g >> 2) + (g >> 1); + if (gg > g) gg = 0; + b = *pb; + bb = (b >> 2) + (b >> 1); + if (bb > b) bb = 0; + + *(pr++) = rr; + *(pg++) = gg; + *(pb++) = bb; + } + + r = *pr; + rr = r + (r >> 1); + if (rr < r) rr = ~0; + g = *pg; + gg = g + (g >> 1); + if (gg < g) gg = ~0; + b = *pb; + bb = b + (b >> 1); + if (bb < b) bb = ~0; + + *pr = rr; + *pg = gg; + *pb = bb; + + pr += d->width - 1; + pg += d->width - 1; + pb += d->width - 1; + + r = *pr; + rr = (r >> 2) + (r >> 1); + if (rr > r) rr = 0; + g = *pg; + gg = (g >> 2) + (g >> 1); + if (gg > g) gg = 0; + b = *pb; + bb = (b >> 2) + (b >> 1); + if (bb > b) bb = 0; + + *pr = rr; + *pg = gg; + *pb = bb; +} + +void Texture::buildImage() +{ + unsigned char *pr = d->red, *pg = d->green, *pb = d->blue; + + TQImage image(d->width, d->height, 32); + + unsigned int* bits = (unsigned int*) image.bits(); + + int p; + for (p =0; p < d->width*d->height; p++) + { + *bits = 0xff << 24 | *pr << 16 | *pg << 8 | *pb; + bits++; + pr++; + pg++; + pb++; + } + + d->pixmap = TQPixmap(image); +} + +} // NameSpace Digikam diff --git a/src/libs/themeengine/texture.h b/src/libs/themeengine/texture.h new file mode 100644 index 00000000..27ba73ee --- /dev/null +++ b/src/libs/themeengine/texture.h @@ -0,0 +1,83 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-07-26 + * Description : texture pixmap methods + * + * Copyright (C) 2004 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * + * Adapted from fluxbox: Texture/TextureRender + * + * Texture.hh for Fluxbox Window Manager + * Copyright (c) 2002-2003 Henrik Kinnunen <fluxbox@users.sourceforge.net> + * + * from Image.hh for Blackbox - an X11 Window manager + * Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * ============================================================ */ + +#ifndef TEXTURE_H +#define TEXTURE_H + +// TQt includes. + +#include <tqcolor.h> + +// Local includes. + +#include "digikam_export.h" + +namespace Digikam +{ + +class TexturePriv; + +class DIGIKAM_EXPORT Texture +{ + +public: + + Texture(int w, int h, const TQColor& from, const TQColor& to, + Theme::Bevel bevel, Theme::Gradient gradient, + bool border, const TQColor& borderColor); + ~Texture(); + + TQPixmap renderPixmap() const; + +private: + + void doBevel(); + + void doSolid(); + void doHgradient(); + void doVgradient(); + void doDgradient(); + + void buildImage(); + +private: + + TexturePriv* d; + +}; + +} // NameSpace Digikam + +#endif /* TEXTURE_H */ diff --git a/src/libs/themeengine/theme.cpp b/src/libs/themeengine/theme.cpp new file mode 100644 index 00000000..8e4b5142 --- /dev/null +++ b/src/libs/themeengine/theme.cpp @@ -0,0 +1,181 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-08-02 + * Description : theme manager + * + * Copyright (C) 2004 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +// Local includes. + +#include "ddebug.h" +#include "theme.h" + +namespace Digikam +{ + +Theme::Theme(const TQString& _name, const TQString& _path) +{ + name = _name; + filePath = _path; +} + +Theme::Theme(const Theme& theme) +{ + if (this != &theme) + { + baseColor = theme.baseColor; + textRegColor = theme.textRegColor; + textSelColor = theme.textSelColor; + textSpecialRegColor = theme.textSpecialRegColor; + textSpecialSelColor = theme.textSpecialSelColor; + + bannerColor = theme.bannerColor; + bannerColorTo = theme.bannerColorTo; + bannerBevel = theme.bannerBevel; + bannerGrad = theme.bannerGrad; + bannerBorder = theme.bannerBorder; + bannerBorderColor = theme.bannerBorderColor; + + thumbRegColor = theme.thumbRegColor; + thumbRegColorTo = theme.thumbRegColorTo; + thumbRegBevel = theme.thumbRegBevel; + thumbRegGrad = theme.thumbRegGrad; + thumbRegBorder = theme.thumbRegBorder; + thumbRegBorderColor = theme.thumbRegBorderColor; + + thumbSelColor = theme.thumbSelColor; + thumbSelColorTo = theme.thumbSelColorTo; + thumbSelBevel = theme.thumbSelBevel; + thumbSelGrad = theme.thumbSelGrad; + thumbSelBorder = theme.thumbSelBorder; + thumbSelBorderColor = theme.thumbSelBorderColor; + + listRegColor = theme.listRegColor; + listRegColorTo = theme.listRegColorTo; + listRegBevel = theme.listRegBevel; + listRegGrad = theme.listRegGrad; + listRegBorder = theme.listRegBorder; + listRegBorderColor = theme.listRegBorderColor; + + listSelColor = theme.listSelColor; + listSelColorTo = theme.listSelColorTo; + listSelBevel = theme.listSelBevel; + listSelGrad = theme.listSelGrad; + listSelBorder = theme.listSelBorder; + listSelBorderColor = theme.listSelBorderColor; + } +} + +Theme& Theme::operator=(const Theme& theme) +{ + if (this != &theme) + { + baseColor = theme.baseColor; + textRegColor = theme.textRegColor; + textSelColor = theme.textSelColor; + textSpecialRegColor = theme.textSpecialRegColor; + textSpecialSelColor = theme.textSpecialSelColor; + + bannerColor = theme.bannerColor; + bannerColorTo = theme.bannerColorTo; + bannerBevel = theme.bannerBevel; + bannerGrad = theme.bannerGrad; + bannerBorder = theme.bannerBorder; + bannerBorderColor = theme.bannerBorderColor; + + thumbRegColor = theme.thumbRegColor; + thumbRegColorTo = theme.thumbRegColorTo; + thumbRegBevel = theme.thumbRegBevel; + thumbRegGrad = theme.thumbRegGrad; + thumbRegBorder = theme.thumbRegBorder; + thumbRegBorderColor = theme.thumbRegBorderColor; + + thumbSelColor = theme.thumbSelColor; + thumbSelColorTo = theme.thumbSelColorTo; + thumbSelBevel = theme.thumbSelBevel; + thumbSelGrad = theme.thumbSelGrad; + thumbSelBorder = theme.thumbSelBorder; + thumbSelBorderColor = theme.thumbSelBorderColor; + + listRegColor = theme.listRegColor; + listRegColorTo = theme.listRegColorTo; + listRegBevel = theme.listRegBevel; + listRegGrad = theme.listRegGrad; + listRegBorder = theme.listRegBorder; + listRegBorderColor = theme.listRegBorderColor; + + listSelColor = theme.listSelColor; + listSelColorTo = theme.listSelColorTo; + listSelBevel = theme.listSelBevel; + listSelGrad = theme.listSelGrad; + listSelBorder = theme.listSelBorder; + listSelBorderColor = theme.listSelBorderColor; + } + return *this; +} + +void Theme::print() +{ + /* + DDebug() << "Theme : " << name << endl; + + DDebug() << "Base Color: " << baseColor << endl; + DDebug() << "Text Regular Color: " << textRegColor << endl; + DDebug() << "Text Selected Color: " << textSelColor << endl; + DDebug() << "Text Special Regular Color: " << textSpecialRegColor << endl; + DDebug() << "Text Special Selected Color: " << textSpecialSelColor << endl; + + DDebug() << "Banner Color: " << bannerColor << endl; + DDebug() << "Banner ColorTo : " << bannerColorTo << endl; + DDebug() << "Banner Bevel : " << bannerBevel << endl; + DDebug() << "Banner Gradient : " << bannerGrad << endl; + DDebug() << "Banner Border : " << bannerBorder << endl; + DDebug() << "Banner Border Color : " << bannerBorderColor << endl; + + DDebug() << "ThumbReg Color: " << thumbRegColor << endl; + DDebug() << "ThumbReg ColorTo : " << thumbRegColorTo << endl; + DDebug() << "ThumbReg Bevel : " << thumbRegBevel << endl; + DDebug() << "ThumbReg Gradient : " << thumbRegGrad << endl; + DDebug() << "ThumbReg Border : " << thumbRegBorder << endl; + DDebug() << "ThumbReg Border Color : " << thumbRegBorderColor << endl; + + DDebug() << "ThumbSel Color: " << thumbSelColor << endl; + DDebug() << "ThumbSel ColorTo : " << thumbSelColorTo << endl; + DDebug() << "ThumbSel Bevel : " << thumbSelBevel << endl; + DDebug() << "ThumbSel Gradient : " << thumbSelGrad << endl; + DDebug() << "ThumbSel Border : " << thumbSelBorder << endl; + DDebug() << "ThumbSel Border Color : " << thumbSelBorderColor << endl; + + DDebug() << "ListReg Color: " << listRegColor << endl; + DDebug() << "ListReg ColorTo : " << listRegColorTo << endl; + DDebug() << "ListReg Bevel : " << listRegBevel << endl; + DDebug() << "ListReg Gradient : " << listRegGrad << endl; + DDebug() << "ListReg Border : " << listRegBorder << endl; + DDebug() << "ListReg Border Color : " << listRegBorderColor << endl; + + DDebug() << "ListSel Color: " << listSelColor << endl; + DDebug() << "ListSel ColorTo : " << listSelColorTo << endl; + DDebug() << "ListSel Bevel : " << listSelBevel << endl; + DDebug() << "ListSel Gradient : " << listSelGrad << endl; + DDebug() << "ListSel Border : " << listSelBorder << endl; + DDebug() << "ListSel Border Color : " << listSelBorderColor << endl; + */ +} + +} // NameSpace Digikam diff --git a/src/libs/themeengine/theme.h b/src/libs/themeengine/theme.h new file mode 100644 index 00000000..fd80deff --- /dev/null +++ b/src/libs/themeengine/theme.h @@ -0,0 +1,112 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-08-02 + * Description : theme manager + * + * Copyright (C) 2004 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#ifndef THEME_H +#define THEME_H + +// TQt includes. + +#include <tqstring.h> +#include <tqcolor.h> + +// Digikam includes. + +#include "digikam_export.h" + +namespace Digikam +{ + +class DIGIKAM_EXPORT Theme +{ +public: + + enum Bevel + { + FLAT = 0x00001, + SUNKEN = 0x00002, + RAISED = 0x00004 + }; + + enum Gradient + { + SOLID = 0x00000, + HORIZONTAL = 0x00010, + VERTICAL = 0x00020, + DIAGONAL = 0x00040 + }; + + Theme(const TQString& _name, const TQString& _path); + Theme(const Theme& theme); + Theme& operator=(const Theme& theme); + + void print(); + + TQString name; + TQString filePath; + + TQColor baseColor; + TQColor textRegColor; + TQColor textSelColor; + TQColor textSpecialRegColor; + TQColor textSpecialSelColor; + + TQColor bannerColor; + TQColor bannerColorTo; + Bevel bannerBevel; + Gradient bannerGrad; + bool bannerBorder; + TQColor bannerBorderColor; + + TQColor thumbRegColor; + TQColor thumbRegColorTo; + Bevel thumbRegBevel; + Gradient thumbRegGrad; + bool thumbRegBorder; + TQColor thumbRegBorderColor; + + TQColor thumbSelColor; + TQColor thumbSelColorTo; + Bevel thumbSelBevel; + Gradient thumbSelGrad; + bool thumbSelBorder; + TQColor thumbSelBorderColor; + + TQColor listRegColor; + TQColor listRegColorTo; + Bevel listRegBevel; + Gradient listRegGrad; + bool listRegBorder; + TQColor listRegBorderColor; + + TQColor listSelColor; + TQColor listSelColorTo; + Bevel listSelBevel; + Gradient listSelGrad; + bool listSelBorder; + TQColor listSelBorderColor; +}; + +} // NameSpace Digikam + +#endif /* THEME_H */ diff --git a/src/libs/themeengine/themeengine.cpp b/src/libs/themeengine/themeengine.cpp new file mode 100644 index 00000000..331ffa5d --- /dev/null +++ b/src/libs/themeengine/themeengine.cpp @@ -0,0 +1,1132 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-08-02 + * Description : theme engine methods + * + * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +// TQt includes. + +#include <tqdict.h> +#include <tqptrlist.h> +#include <tqfileinfo.h> +#include <tqfile.h> +#include <tqapplication.h> +#include <tqpalette.h> +#include <tqtimer.h> +#include <tqtextstream.h> + +// KDE includes. + +#include <tdeglobal.h> +#include <tdelocale.h> +#include <kstandarddirs.h> +#include <kuser.h> +#include <tdeapplication.h> +#include <tdeglobalsettings.h> + +// Local includes. + +#include "ddebug.h" +#include "theme.h" +#include "texture.h" +#include "themeengine.h" +#include "themeengine.moc" + +namespace Digikam +{ + +class ThemeEnginePriv +{ +public: + + ThemeEnginePriv() + { + defaultTheme = 0; + currTheme = 0; + themeInitiallySet = false; + } + + TQPalette defaultPalette; + + TQPtrList<Theme> themeList; + TQDict<Theme> themeDict; + + Theme *currTheme; + Theme *defaultTheme; + bool themeInitiallySet; +}; + +ThemeEngine* ThemeEngine::m_instance = 0; + +ThemeEngine* ThemeEngine::instance() +{ + if (!m_instance) + { + new ThemeEngine(); + } + return m_instance; +} + +ThemeEngine::ThemeEngine() +{ + m_instance = this; + TDEGlobal::dirs()->addResourceType("themes", + TDEGlobal::dirs()->kde_default("data") + + "digikam/themes"); + + d = new ThemeEnginePriv; + + d->themeList.setAutoDelete(false); + d->themeDict.setAutoDelete(false); + d->defaultTheme = new Theme(i18n("Default"), TQString()); + d->themeList.append(d->defaultTheme); + d->themeDict.insert(i18n("Default"), d->defaultTheme); + d->currTheme = d->defaultTheme; + + buildDefaultTheme(); +} + +ThemeEngine::~ThemeEngine() +{ + d->themeList.setAutoDelete(true); + d->themeList.clear(); + delete d; + m_instance = 0; +} + +TQColor ThemeEngine::baseColor() const +{ + return d->currTheme->baseColor; +} + +TQColor ThemeEngine::thumbSelColor() const +{ + return d->currTheme->thumbSelColor; +} + +TQColor ThemeEngine::thumbRegColor() const +{ + return d->currTheme->thumbRegColor; +} + +TQColor ThemeEngine::textRegColor() const +{ + return d->currTheme->textRegColor; +} + +TQColor ThemeEngine::textSelColor() const +{ + return d->currTheme->textSelColor; +} + +TQColor ThemeEngine::textSpecialRegColor() const +{ + return d->currTheme->textSpecialRegColor; +} + +TQColor ThemeEngine::textSpecialSelColor() const +{ + return d->currTheme->textSpecialSelColor; +} + +TQPixmap ThemeEngine::bannerPixmap(int w, int h) +{ + Texture tex(w, h, d->currTheme->bannerColor, d->currTheme->bannerColorTo, + d->currTheme->bannerBevel, d->currTheme->bannerGrad, + d->currTheme->bannerBorder, d->currTheme->bannerBorderColor); + return tex.renderPixmap(); +} + +TQPixmap ThemeEngine::thumbRegPixmap(int w, int h) +{ + Texture tex(w, h, d->currTheme->thumbRegColor, d->currTheme->thumbRegColorTo, + d->currTheme->thumbRegBevel, d->currTheme->thumbRegGrad, + d->currTheme->thumbRegBorder, d->currTheme->thumbRegBorderColor); + return tex.renderPixmap(); +} + +TQPixmap ThemeEngine::thumbSelPixmap(int w, int h) +{ + Texture tex(w, h, d->currTheme->thumbSelColor, d->currTheme->thumbSelColorTo, + d->currTheme->thumbSelBevel, d->currTheme->thumbSelGrad, + d->currTheme->thumbSelBorder, d->currTheme->thumbSelBorderColor); + return tex.renderPixmap(); +} + +TQPixmap ThemeEngine::listRegPixmap(int w, int h) +{ + Texture tex(w, h, d->currTheme->listRegColor, d->currTheme->listRegColorTo, + d->currTheme->listRegBevel, d->currTheme->listRegGrad, + d->currTheme->listRegBorder, d->currTheme->listRegBorderColor); + return tex.renderPixmap(); +} + +TQPixmap ThemeEngine::listSelPixmap(int w, int h) +{ + Texture tex(w, h, d->currTheme->listSelColor, d->currTheme->listSelColorTo, + d->currTheme->listSelBevel, d->currTheme->listSelGrad, + d->currTheme->listSelBorder, d->currTheme->listSelBorderColor); + return tex.renderPixmap(); +} + +void ThemeEngine::scanThemes() +{ + d->themeList.remove(d->defaultTheme); + d->themeList.setAutoDelete(true); + d->themeList.clear(); + d->themeDict.clear(); + d->currTheme = 0; + + TQStringList themes = TDEGlobal::dirs()->findAllResources( "themes", TQString(), false, true ); + + for (TQStringList::iterator it=themes.begin(); it != themes.end(); + ++it) + { + TQFileInfo fi(*it); + Theme* theme = new Theme(fi.fileName(), *it); + d->themeList.append(theme); + d->themeDict.insert(fi.fileName(), theme); + } + + d->themeList.append(d->defaultTheme); + d->themeDict.insert(i18n("Default"), d->defaultTheme); + d->currTheme = d->defaultTheme; +} + +TQStringList ThemeEngine::themeNames() const +{ + TQStringList names; + for (Theme *t = d->themeList.first(); t; t = d->themeList.next()) + { + names << t->name; + } + names.sort(); + return names; +} + +void ThemeEngine::slotChangeTheme(const TQString& name) +{ + setCurrentTheme(name); +} + +void ThemeEngine::setCurrentTheme(const TQString& name) +{ + Theme* theme = d->themeDict.find(name); + if (!theme) + { + d->currTheme = d->defaultTheme; + return; + } + + if (d->currTheme == theme && d->themeInitiallySet) + return; + + d->currTheme = theme; + loadTheme(); + + // this is only to ensure that even if the chosen theme is the default theme, + // the signalThemeChanged is emitted when themes are loaded in DigikamApp + d->themeInitiallySet = true; + + changePalette(); + + TQTimer::singleShot(0, this, TQ_SIGNAL(signalThemeChanged())); +} + +void ThemeEngine::setCurrentTheme(const Theme& theme, const TQString& name, bool loadFromDisk) +{ + Theme* t = d->themeDict.find(name); + if (t) + { + d->themeDict.remove(name); + d->themeList.remove(t); + } + + t = new Theme(theme); + t->filePath = theme.filePath; + d->themeDict.insert(name, t); + d->themeList.append(t); + + d->currTheme = t; + if (loadFromDisk) + loadTheme(); + + changePalette(); + + TQTimer::singleShot(0, this, TQ_SIGNAL(signalThemeChanged())); +} + +void ThemeEngine::changePalette() +{ + // Make palette for all widgets. + TQPalette plt; + + if (d->currTheme == d->defaultTheme) + plt = d->defaultPalette; + else + { + plt = kapp->palette(); + int h, s, v; + const TQColor fg(ThemeEngine::instance()->textRegColor()); + const TQColor bg(ThemeEngine::instance()->baseColor()); + TQColorGroup cg(plt.active()); + + /* bg.hsv(&h, &s, &v); + v += (v < 128) ? +50 : -50; + v &= 255; //ensures 0 <= v < 256 + d->currTheme->altBase = TQColor(h, s, v, TQColor::Hsv); + */ + fg.hsv(&h, &s, &v); + v += (v < 128) ? +150 : -150; + v &= 255; //ensures 0 <= v < 256 + const TQColor highlight(h, s, v, TQColor::Hsv); + + cg.setColor(TQColorGroup::Base, bg); + cg.setColor(TQColorGroup::Background, bg.dark(115)); + cg.setColor(TQColorGroup::Foreground, ThemeEngine::instance()->textRegColor()); + cg.setColor(TQColorGroup::Highlight, highlight); + cg.setColor(TQColorGroup::HighlightedText, ThemeEngine::instance()->textSelColor()); + cg.setColor(TQColorGroup::Dark, TQt::darkGray); + + cg.setColor(TQColorGroup::Button, bg); + cg.setColor(TQColorGroup::ButtonText, ThemeEngine::instance()->textRegColor()); + + cg.setColor(TQColorGroup::Text, ThemeEngine::instance()->textRegColor()); + cg.setColor(TQColorGroup::Link, ThemeEngine::instance()->textSpecialRegColor()); + cg.setColor(TQColorGroup::LinkVisited, ThemeEngine::instance()->textSpecialSelColor()); + + /* + cg.setColor(TQColorGroup::Light, ThemeEngine::instance()->textRegColor()); + cg.setColor(TQColorGroup::Midlight, ThemeEngine::instance()->textRegColor()); + cg.setColor(TQColorGroup::Mid, ThemeEngine::instance()->textRegColor()); + cg.setColor(TQColorGroup::Shadow, ThemeEngine::instance()->textRegColor()); + */ + + plt.setActive(cg); + plt.setInactive(cg); + plt.setDisabled(cg); + } + + kapp->setPalette(plt, true); +} + +Theme* ThemeEngine::getCurrentTheme() const +{ + return d->currTheme; +} + +TQString ThemeEngine::getCurrentThemeName() const +{ + return d->currTheme->name; +} + +void ThemeEngine::buildDefaultTheme() +{ + Theme* t = d->defaultTheme; + + d->defaultPalette = kapp->palette(); + TQColorGroup cg = d->defaultPalette.active(); + + t->baseColor = cg.base(); + t->textRegColor = cg.text(); + t->textSelColor = cg.highlightedText(); + t->textSpecialRegColor = TQColor("#0000EF"); + t->textSpecialSelColor = cg.highlightedText(); + + t->bannerColor = cg.highlight(); + t->bannerColorTo = cg.highlight().dark(120); + t->bannerBevel = Theme::FLAT; + t->bannerGrad = Theme::SOLID; + t->bannerBorder = false; + t->bannerBorderColor = TQt::black; + + t->thumbRegColor = cg.base(); + t->thumbRegColorTo = cg.base(); + t->thumbRegBevel = Theme::FLAT; + t->thumbRegGrad = Theme::SOLID; + t->thumbRegBorder = true; + t->thumbRegBorderColor = TQColor("#E0E0EF"); + + t->thumbSelColor = cg.highlight(); + t->thumbSelColorTo = cg.highlight(); + t->thumbSelBevel = Theme::FLAT; + t->thumbSelGrad = Theme::SOLID; + t->thumbSelBorder = true; + t->thumbSelBorderColor = TQColor("#E0E0EF"); + + t->listRegColor = cg.base(); + t->listRegColorTo = cg.base(); + t->listRegBevel = Theme::FLAT; + t->listRegGrad = Theme::SOLID; + t->listRegBorder = false; + t->listRegBorderColor = TQt::black; + + t->listSelColor = cg.highlight(); + t->listSelColorTo = cg.highlight(); + t->listSelBevel = Theme::FLAT; + t->listSelGrad = Theme::SOLID; + t->listSelBorder = true; + t->listSelBorderColor = TQt::black; +} + +bool ThemeEngine::loadTheme() +{ + Q_ASSERT( d->currTheme ); + if (!d->currTheme || d->currTheme == d->defaultTheme) + return false; + + Theme *t = d->currTheme; + + // use the default theme as base template to build the themes + *(t) = *(d->defaultTheme); + + TQFile themeFile(t->filePath); + + if (!themeFile.open(IO_ReadOnly)) + return false; + + TQDomDocument xmlDoc; + TQString error; + int row, col; + if (!xmlDoc.setContent(&themeFile, true, &error, &row, &col)) + { + DDebug() << "Theme file: " << t->filePath << endl; + DDebug() << error << " :: row=" << row << " , col=" << col << endl; + return false; + } + + TQDomElement rootElem = xmlDoc.documentElement(); + if (rootElem.tagName() != TQString::fromLatin1("digikamtheme")) + return false; + + TQString resource; + + // -- base ------------------------------------------------------------------------ + + resource = resourceValue(rootElem, "BaseColor"); + if (!resource.isEmpty()) + t->baseColor = resource; + + resource = resourceValue(rootElem, "TextRegularColor"); + if (!resource.isEmpty()) + t->textRegColor = resource; + + resource = resourceValue(rootElem, "TextSelectedColor"); + if (!resource.isEmpty()) + t->textSelColor = resource; + + resource = resourceValue(rootElem, "TextSpecialRegularColor"); + if (!resource.isEmpty()) + t->textSpecialRegColor = resource; + + resource = resourceValue(rootElem, "TextSpecialSelectedColor"); + if (!resource.isEmpty()) + t->textSpecialSelColor = resource; + + // -- banner ------------------------------------------------------------------------ + + resource = resourceValue(rootElem, "BannerColor"); + if (!resource.isEmpty()) + t->bannerColor = resource; + + resource = resourceValue(rootElem, "BannerColorTo"); + if (!resource.isEmpty()) + t->bannerColorTo = resource; + + resource = resourceValue(rootElem, "BannerBevel"); + if (!resource.isEmpty()) + { + if (resource.contains("flat", false)) + t->bannerBevel = Theme::FLAT; + else if (resource.contains("sunken", false)) + t->bannerBevel = Theme::SUNKEN; + else if (resource.contains("raised", false)) + t->bannerBevel = Theme::RAISED; + } + + resource = resourceValue(rootElem, "BannerGradient"); + if (!resource.isEmpty()) + { + if (resource.contains("solid", false)) + t->bannerGrad = Theme::SOLID; + else if (resource.contains("horizontal", false)) + t->bannerGrad = Theme::HORIZONTAL; + else if (resource.contains("vertical", false)) + t->bannerGrad = Theme::VERTICAL; + else if (resource.contains("diagonal", false)) + t->bannerGrad = Theme::DIAGONAL; + } + + resource = resourceValue(rootElem, "BannerBorder"); + if (!resource.isEmpty()) + { + t->bannerBorder = resource.contains("true", false); + } + + resource = resourceValue(rootElem, "BannerBorderColor"); + if (!resource.isEmpty()) + { + t->bannerBorderColor = resource; + } + + // -- thumbnail view ---------------------------------------------------------------- + + resource = resourceValue(rootElem, "ThumbnailRegularColor"); + if (!resource.isEmpty()) + t->thumbRegColor = resource; + + resource = resourceValue(rootElem, "ThumbnailRegularColorTo"); + if (!resource.isEmpty()) + t->thumbRegColorTo = resource; + + resource = resourceValue(rootElem, "ThumbnailRegularBevel"); + if (!resource.isEmpty()) + { + if (resource.contains("flat", false)) + t->thumbRegBevel = Theme::FLAT; + else if (resource.contains("sunken", false)) + t->thumbRegBevel = Theme::SUNKEN; + else if (resource.contains("raised", false)) + t->thumbRegBevel = Theme::RAISED; + } + + resource = resourceValue(rootElem, "ThumbnailRegularGradient"); + if (!resource.isEmpty()) + { + if (resource.contains("solid", false)) + t->thumbRegGrad = Theme::SOLID; + else if (resource.contains("horizontal", false)) + t->thumbRegGrad = Theme::HORIZONTAL; + else if (resource.contains("vertical", false)) + t->thumbRegGrad = Theme::VERTICAL; + else if (resource.contains("diagonal", false)) + t->thumbRegGrad = Theme::DIAGONAL; + } + + resource = resourceValue(rootElem, "ThumbnailRegularBorder"); + if (!resource.isEmpty()) + { + t->thumbRegBorder = resource.contains("true", false); + } + + resource = resourceValue(rootElem, "ThumbnailRegularBorderColor"); + if (!resource.isEmpty()) + { + t->thumbRegBorderColor = resource; + } + + resource = resourceValue(rootElem, "ThumbnailSelectedColor"); + if (!resource.isEmpty()) + t->thumbSelColor = resource; + + resource = resourceValue(rootElem, "ThumbnailSelectedColorTo"); + if (!resource.isEmpty()) + t->thumbSelColorTo = resource; + + resource = resourceValue(rootElem, "ThumbnailSelectedBevel"); + if (!resource.isEmpty()) + { + if (resource.contains("flat", false)) + t->thumbSelBevel = Theme::FLAT; + else if (resource.contains("sunken", false)) + t->thumbSelBevel = Theme::SUNKEN; + else if (resource.contains("raised", false)) + t->thumbSelBevel = Theme::RAISED; + } + + resource = resourceValue(rootElem, "ThumbnailSelectedGradient"); + if (!resource.isEmpty()) + { + if (resource.contains("solid", false)) + t->thumbSelGrad = Theme::SOLID; + else if (resource.contains("horizontal", false)) + t->thumbSelGrad = Theme::HORIZONTAL; + else if (resource.contains("vertical", false)) + t->thumbSelGrad = Theme::VERTICAL; + else if (resource.contains("diagonal", false)) + t->thumbSelGrad = Theme::DIAGONAL; + } + + resource = resourceValue(rootElem, "ThumbnailSelectedBorder"); + if (!resource.isEmpty()) + { + t->thumbSelBorder = resource.contains("true", false); + } + + resource = resourceValue(rootElem, "ThumbnailSelectedBorderColor"); + if (!resource.isEmpty()) + { + t->thumbSelBorderColor = resource; + } + + // -- listview view ---------------------------------------------------------------- + + resource = resourceValue(rootElem, "ListviewRegularColor"); + if (!resource.isEmpty()) + t->listRegColor = resource; + + resource = resourceValue(rootElem, "ListviewRegularColorTo"); + if (!resource.isEmpty()) + t->listRegColorTo = resource; + + resource = resourceValue(rootElem, "ListviewRegularBevel"); + if (!resource.isEmpty()) + { + if (resource.contains("flat", false)) + t->listRegBevel = Theme::FLAT; + else if (resource.contains("sunken", false)) + t->listRegBevel = Theme::SUNKEN; + else if (resource.contains("raised", false)) + t->listRegBevel = Theme::RAISED; + } + + resource = resourceValue(rootElem, "ListviewRegularGradient"); + if (!resource.isEmpty()) + { + if (resource.contains("solid", false)) + t->listRegGrad = Theme::SOLID; + else if (resource.contains("horizontal", false)) + t->listRegGrad = Theme::HORIZONTAL; + else if (resource.contains("vertical", false)) + t->listRegGrad = Theme::VERTICAL; + else if (resource.contains("diagonal", false)) + t->listRegGrad = Theme::DIAGONAL; + } + + resource = resourceValue(rootElem, "ListviewRegularBorder"); + if (!resource.isEmpty()) + { + t->listRegBorder = resource.contains("true", false); + } + + resource = resourceValue(rootElem, "ListviewRegularBorderColor"); + if (!resource.isEmpty()) + { + t->listRegBorderColor = resource; + } + + resource = resourceValue(rootElem, "ListviewSelectedColor"); + if (!resource.isEmpty()) + t->listSelColor = resource; + + resource = resourceValue(rootElem, "ListviewSelectedColorTo"); + if (!resource.isEmpty()) + t->listSelColorTo = resource; + + resource = resourceValue(rootElem, "ListviewSelectedBevel"); + if (!resource.isEmpty()) + { + if (resource.contains("flat", false)) + t->listSelBevel = Theme::FLAT; + else if (resource.contains("sunken", false)) + t->listSelBevel = Theme::SUNKEN; + else if (resource.contains("raised", false)) + t->listSelBevel = Theme::RAISED; + } + + resource = resourceValue(rootElem, "ListviewSelectedGradient"); + if (!resource.isEmpty()) + { + if (resource.contains("solid", false)) + t->listSelGrad = Theme::SOLID; + else if (resource.contains("horizontal", false)) + t->listSelGrad = Theme::HORIZONTAL; + else if (resource.contains("vertical", false)) + t->listSelGrad = Theme::VERTICAL; + else if (resource.contains("diagonal", false)) + t->listSelGrad = Theme::DIAGONAL; + } + + resource = resourceValue(rootElem, "ListviewSelectedBorder"); + if (!resource.isEmpty()) + { + t->listSelBorder = resource.contains("true", false); + } + + resource = resourceValue(rootElem, "ListviewSelectedBorderColor"); + if (!resource.isEmpty()) + { + t->listSelBorderColor = resource; + } + + DDebug() << "Theme file loaded: " << t->filePath << endl; + return true; +} + +TQString ThemeEngine::resourceValue(const TQDomElement &rootElem, const TQString& key) +{ + for (TQDomNode node = rootElem.firstChild(); + !node.isNull(); node = node.nextSibling()) + { + TQDomElement e = node.toElement(); + TQString name = e.tagName(); + TQString val = e.attribute(TQString::fromLatin1("value")); + + if (key == name) + { + return val; + } + } + + return TQString(""); +} + +bool ThemeEngine::saveTheme() +{ + Q_ASSERT( d->currTheme ); + if (!d->currTheme) + return false; + + Theme *t = d->currTheme; + + TQFileInfo fi(t->filePath); + + TQFile themeFile(fi.filePath()); + + if (!themeFile.open(IO_WriteOnly)) + return false; + + KUser user; + TQDomDocument xmlDoc; + TQDomElement e; + TQString val; + + // header ------------------------------------------------------------------ + + xmlDoc.appendChild(xmlDoc.createProcessingInstruction(TQString::fromLatin1("xml"), + TQString::fromLatin1("version=\"1.0\" encoding=\"UTF-8\""))); + + TQString banner = TQString("\n/* ============================================================" + "\n *" + "\n * This file is a part of digiKam project" + "\n * http://www.digikam.org" + "\n *" + "\n * Date : %1-%2-%3" + "\n * Description : %4 colors theme." + "\n *" + "\n * Copyright (C) %5 by %6" + "\n *" + "\n * This program is free software; you can redistribute it" + "\n * and/or modify it under the terms of the GNU General" + "\n * Public License as published by the Free Software Foundation;" + "\n * either version 2, or (at your option)" + "\n * any later version." + "\n * " + "\n * This program is distributed in the hope that it will be useful," + "\n * but WITHOUT ANY WARRANTY; without even the implied warranty of" + "\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" + "\n * GNU General Public License for more details." + "\n *" + "\n * ============================================================ */\n") + .arg(TQDate::currentDate().year()) + .arg(TQDate::currentDate().month()) + .arg(TQDate::currentDate().day()) + .arg(fi.fileName()) + .arg(TQDate::currentDate().year()) + .arg(user.fullName()); + + xmlDoc.appendChild(xmlDoc.createComment(banner)); + + TQDomElement themeElem = xmlDoc.createElement(TQString::fromLatin1("digikamtheme")); + xmlDoc.appendChild(themeElem); + + // base props -------------------------------------------------------------- + + e = xmlDoc.createElement(TQString::fromLatin1("name")); + e.setAttribute(TQString::fromLatin1("value"), fi.fileName()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("BaseColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->baseColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("TextRegularColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->textRegColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("TextSelectedColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->textSelColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("TextSpecialRegularColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->textSpecialRegColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("TextSpecialSelectedColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->textSpecialSelColor.name()).upper()); + themeElem.appendChild(e); + + // banner props ------------------------------------------------------------ + + e = xmlDoc.createElement(TQString::fromLatin1("BannerColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->bannerColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("BannerColorTo")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->bannerColorTo.name()).upper()); + themeElem.appendChild(e); + + switch(t->bannerBevel) + { + case(Theme::FLAT): + { + val = TQString("FLAT"); + break; + } + case(Theme::RAISED): + { + val = TQString("RAISED"); + break; + } + case(Theme::SUNKEN): + { + val = TQString("SUNKEN"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("BannerBevel")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + switch(t->bannerGrad) + { + case(Theme::SOLID): + { + val = TQString("SOLID"); + break; + } + case(Theme::HORIZONTAL): + { + val = TQString("HORIZONTAL"); + break; + } + case(Theme::VERTICAL): + { + val = TQString("VERTICAL"); + break; + } + case(Theme::DIAGONAL): + { + val = TQString("DIAGONAL"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("BannerGradient")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("BannerBorder")); + e.setAttribute(TQString::fromLatin1("value"), (t->bannerBorder ? "TRUE" : "FALSE")); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("BannerBorderColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->bannerBorderColor.name()).upper()); + themeElem.appendChild(e); + + // thumbnail.regular props ------------------------------------------------- + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbRegColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularColorTo")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbRegColorTo.name()).upper()); + themeElem.appendChild(e); + + switch(t->thumbRegBevel) + { + case(Theme::FLAT): + { + val = TQString("FLAT"); + break; + } + case(Theme::RAISED): + { + val = TQString("RAISED"); + break; + } + case(Theme::SUNKEN): + { + val = TQString("SUNKEN"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularBevel")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + switch(t->thumbRegGrad) + { + case(Theme::SOLID): + { + val = TQString("SOLID"); + break; + } + case(Theme::HORIZONTAL): + { + val = TQString("HORIZONTAL"); + break; + } + case(Theme::VERTICAL): + { + val = TQString("VERTICAL"); + break; + } + case(Theme::DIAGONAL): + { + val = TQString("DIAGONAL"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularGradient")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularBorder")); + e.setAttribute(TQString::fromLatin1("value"), (t->thumbRegBorder ? "TRUE" : "FALSE")); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailRegularBorderColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbRegBorderColor.name()).upper()); + themeElem.appendChild(e); + + // thumbnail.selected props ------------------------------------------------- + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbSelColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedColorTo")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbSelColorTo.name()).upper()); + themeElem.appendChild(e); + + switch(t->thumbSelBevel) + { + case(Theme::FLAT): + { + val = TQString("FLAT"); + break; + } + case(Theme::RAISED): + { + val = TQString("RAISED"); + break; + } + case(Theme::SUNKEN): + { + val = TQString("SUNKEN"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedBevel")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + switch(t->thumbSelGrad) + { + case(Theme::SOLID): + { + val = TQString("SOLID"); + break; + } + case(Theme::HORIZONTAL): + { + val = TQString("HORIZONTAL"); + break; + } + case(Theme::VERTICAL): + { + val = TQString("VERTICAL"); + break; + } + case(Theme::DIAGONAL): + { + val = TQString("DIAGONAL"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedGradient")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedBorder")); + e.setAttribute(TQString::fromLatin1("value"), (t->thumbSelBorder ? "TRUE" : "FALSE")); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ThumbnailSelectedBorderColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->thumbSelBorderColor.name()).upper()); + themeElem.appendChild(e); + + // listview.regular props ------------------------------------------------- + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listRegColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularColorTo")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listRegColorTo.name()).upper()); + themeElem.appendChild(e); + + switch(t->listRegBevel) + { + case(Theme::FLAT): + { + val = TQString("FLAT"); + break; + } + case(Theme::RAISED): + { + val = TQString("RAISED"); + break; + } + case(Theme::SUNKEN): + { + val = TQString("SUNKEN"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularBevel")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + switch(t->listRegGrad) + { + case(Theme::SOLID): + { + val = TQString("SOLID"); + break; + } + case(Theme::HORIZONTAL): + { + val = TQString("HORIZONTAL"); + break; + } + case(Theme::VERTICAL): + { + val = TQString("VERTICAL"); + break; + } + case(Theme::DIAGONAL): + { + val = TQString("DIAGONAL"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularGradient")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularBorder")); + e.setAttribute(TQString::fromLatin1("value"), (t->listRegBorder ? "TRUE" : "FALSE")); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewRegularBorderColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listRegBorderColor.name()).upper()); + themeElem.appendChild(e); + + // listview.selected props ------------------------------------------------- + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listSelColor.name()).upper()); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedColorTo")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listSelColorTo.name()).upper()); + themeElem.appendChild(e); + + switch(t->listSelBevel) + { + case(Theme::FLAT): + { + val = TQString("FLAT"); + break; + } + case(Theme::RAISED): + { + val = TQString("RAISED"); + break; + } + case(Theme::SUNKEN): + { + val = TQString("SUNKEN"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedBevel")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + switch(t->listSelGrad) + { + case(Theme::SOLID): + { + val = TQString("SOLID"); + break; + } + case(Theme::HORIZONTAL): + { + val = TQString("HORIZONTAL"); + break; + } + case(Theme::VERTICAL): + { + val = TQString("VERTICAL"); + break; + } + case(Theme::DIAGONAL): + { + val = TQString("DIAGONAL"); + break; + } + }; + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedGradient")); + e.setAttribute(TQString::fromLatin1("value"), val); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedBorder")); + e.setAttribute(TQString::fromLatin1("value"), (t->listSelBorder ? "TRUE" : "FALSE")); + themeElem.appendChild(e); + + e = xmlDoc.createElement(TQString::fromLatin1("ListviewSelectedBorderColor")); + e.setAttribute(TQString::fromLatin1("value"), TQString(t->listSelBorderColor.name()).upper()); + themeElem.appendChild(e); + + // ------------------------------------------------------------------------- + + TQTextStream stream(&themeFile); + stream.setEncoding(TQTextStream::UnicodeUTF8); + stream << xmlDoc.toString(); + themeFile.close(); + + return true; +} + +} // NameSpace Digikam diff --git a/src/libs/themeengine/themeengine.h b/src/libs/themeengine/themeengine.h new file mode 100644 index 00000000..33abfb07 --- /dev/null +++ b/src/libs/themeengine/themeengine.h @@ -0,0 +1,107 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-08-02 + * Description : theme engine methods + * + * Copyright (C) 2004-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + * Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#ifndef THEMEENGINE_H +#define THEMEENGINE_H + +// TQt includes. + +#include <tqstringlist.h> +#include <tqobject.h> +#include <tqcolor.h> +#include <tqpixmap.h> +#include <tqdom.h> + +// Digikam includes. + +#include "digikam_export.h" + +namespace Digikam +{ + +class Theme; +class ThemeEnginePriv; + +class DIGIKAM_EXPORT ThemeEngine : public TQObject +{ + TQ_OBJECT + + +public: + + ~ThemeEngine(); + static ThemeEngine* instance(); + + void scanThemes(); + TQStringList themeNames() const; + bool saveTheme(); + + void setCurrentTheme(const TQString& name); + void setCurrentTheme(const Theme& theme, const TQString& name, + bool loadFromDisk=false); + + Theme* getCurrentTheme() const; + TQString getCurrentThemeName() const; + + TQColor baseColor() const; + TQColor thumbSelColor() const; + TQColor thumbRegColor() const; + + TQColor textRegColor() const; + TQColor textSelColor() const; + TQColor textSpecialRegColor() const; + TQColor textSpecialSelColor() const; + + TQPixmap bannerPixmap(int w, int h); + TQPixmap thumbRegPixmap(int w, int h); + TQPixmap thumbSelPixmap(int w, int h); + TQPixmap listRegPixmap(int w, int h); + TQPixmap listSelPixmap(int w, int h); + +private: + + ThemeEngine(); + static ThemeEngine* m_instance; + + void buildDefaultTheme(); + bool loadTheme(); + void changePalette(); + TQString resourceValue(const TQDomElement &rootElem, const TQString& key); + +signals: + + void signalThemeChanged(); + +public slots: + + void slotChangeTheme(const TQString& name); + +private: + + ThemeEnginePriv* d; +}; + +} // NameSpace Digikam + +#endif /* THEMEENGINE_H */ |