1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
|
/* ksim - a system monitor for kde
*
* Copyright (C) 2001 Robbie Ward <linuxphreak@gmx.co.uk>
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef THEMELOADER_H
#define THEMELOADER_H
#include <qstring.h>
#include <qrect.h>
#include <qcolor.h>
#include <qfont.h>
#include <qvaluelist.h>
#include <kdemacros.h>
class QStringList;
template<class> class QValueVector;
class KConfig;
class QWidget;
namespace KSim
{
class Base;
/**
* a class containing various information
* about a theme, use KSim::ThemeLoader to
* get an instance
* @author Robbie Ward <linuxphreak@gmx.co.uk>
* @short Provides a loader for the themes
*/
class KDE_EXPORT Theme
{
friend class ThemeLoader;
public:
enum PixmapType { KrellPanel = 0, KrellMeter, KrellSlider };
~Theme();
bool operator==(const KSim::Theme &rhs) const;
bool operator!=(const KSim::Theme &rhs) const;
KSim::Theme &operator=(const KSim::Theme &rhs);
/**
* @return the theme path
*/
const QString &path() const;
/**
* @return the name of the theme
*/
QString name() const;
/**
* @return the author of the theme
*/
QString author() const;
/**
* @return the set font item for the theme
*/
int fontItem() const;
/**
* @return the amount of alternatives the theme has
*/
int alternative() const;
/**
* @return the amount of alternatives the theme has
*/
int alternatives() const;
/**
* @return the width leds should be scaled to (if scaling() returns true)
*/
int chartWidthRef(int defValue = 0) const;
int chartWidthMin(int defValue = 0) const;
/**
* @return true if sacling should be enabled
*/
bool scaling(bool defValue = false) const;
/**
* @return the height of the top frame
*/
int frameTopHeight(int defValue = 0) const;
/**
* @return the height of the bottom frame
*/
int frameBottomHeight(int defValue = 0) const;
/**
* @return the width of the left frame
*/
int frameLeftWidth(int defValue = 0) const;
/**
* @return the width of the right frame
*/
int frameRightWidth(int defValue = 0) const;
/**
* @return a rect of the top frame border
*/
QRect frameTopBorder(const QRect &defValue = QRect()) const;
/**
* @return a rect of the bottom frame border
*/
QRect frameBottomBorder(const QRect &defValue = QRect()) const;
/**
* @return a rect of the left frame border
*/
QRect frameLeftBorder(const QRect &defValue = QRect()) const;
/**
* @return a rect of the right frame border
*/
QRect frameRightBorder(const QRect &defValue = QRect()) const;
/**
* @return the color of the chart in
*/
QColor chartInColour(const QColor &defValue = QColor()) const;
/**
* @return the color of the chart in grid
*/
QColor chartInColourGrid(const QColor &defValue = QColor()) const;
/**
* @return the color of the chart out
*/
QColor chartOutColour(const QColor &defValue = QColor()) const;
/**
* @return the color of the chart out grid
*/
QColor chartOutColourGrid(const QColor &defValue = QColor()) const;
/**
* if false then the grid lines should be drawn at the
* top and bottom of the graphs
*/
bool bgGridMode(bool defValue = false) const;
/**
* @return the X location of the receive led
*/
int rxLedX(int defValue = 0) const;
/**
* @return the Y location of the receive led
*/
int rxLedY(int defValue = 0) const;
/**
* @return the X location of the send led
*/
int txLedX(int defValue = 0) const;
/**
* @return the Y location of the send led
*/
int txLedY(int defValue = 0) const;
/**
* @return the amount of mail frames
*/
int mailFrames(int defValue = 0) const;
/**
* @return the mail check delay
*/
int mailDelay(int defValue = 0) const;
/**
* @return the slider depth
*/
int krellSliderDepth(int defValue = 7) const;
/**
* @return the vertical location of the start of the image
*/
int krellSliderXHot(int defValue = 0) const;
/**
* @return the area for the slider panel
*/
QRect sliderPanel(const QRect &defValue = QRect()) const;
/**
* @return the area for the slider meter
*/
QRect sliderMeter(const QRect &defValue = QRect()) const;
/**
* @return the border for the timer label/button
*/
QRect timerBorder(const QRect &defValue = QRect()) const;
/**
* @return the border for the panel button
*/
QRect buttonPanelBorder(const QRect &defValue = QRect()) const;
/**
* @return the border for the meter button
*/
QRect buttonMeterBorder(const QRect &defValue = QRect()) const;
/**
* @return the large font that the theme specifies
*/
QFont largeFont() const;
/**
* @return the normal font that the theme specifies
*/
QFont normalFont() const;
/**
* @return the small font that the theme specifies
*/
QFont smallFont() const;
/**
* @return the current font to be used
* according to fontItem()
*/
QFont currentFont() const;
/**
* @return the meter image (bg_meter.[png|jpg|gif])
* of the current theme, if type is specified then it will
* look in the folder type.
*
* it will first look in the dir 'type' if no image is found
* it will drop back a dir
* @param type is one of: none, apm, cal, clock, fs,
* host, mail, mem, swap, timer, uptime
*/
QString meterPixmap(int type, bool useDefault = true) const;
/**
* @return the meter image (bg_panel.[png|jpg|gif])
* of the current theme, it will first look in the dir 'type'
* if no image is found it will drop back a dir
* @param type is one of: net, inet
*/
QString panelPixmap(int type, bool useDefault = true) const;
/**
* @return the decal net leds image
* (usually decal_net_leds.[png|jpg|gif]) of the
* current theme, it will first look in the dir 'type'
* if no image is found it will drop back a dir
* @param type is one of: net, inet
*/
QString ledPixmap(int type, bool useDefault = true) const;
/**
* @return the frame image of the current theme,
* @param type is one of: top, bottom, left, right
*/
QString framePixmap(int type, bool useDefault = true) const;
/**
* @return the krell chart image (bg_chart.[png|jpg|gif])
* of the current theme
*/
QString chartPixmap(bool useDefault = true) const;
/**
* @return the krell grid image (bg_grid.[png|jpg|gif])
* of the current theme
*/
QString gridPixmap(bool useDefault = true) const;
/**
* @return the krell panel image (krell_panel.[png|jpg|gif])
* of the current theme
*/
QString krellPanelPixmap(bool useDefault = true) const;
/**
* @return the krell meter image (krell_meter.[png|jpg|gif])
* of the current theme
*/
QString krellMeterPixmap(bool useDefault = true) const;
/**
* @return the krell slider image (krell_slider.[png|jpg|gif])
* of the current theme
*/
QString krellSliderPixmap(bool useDefault = true) const;
/**
* @return the data in image (data_in.[png|jpg|gif])
* of the current theme
*/
QString dataInPixmap(bool useDefault = true) const;
/**
* @return the data out image (data_out.[png|jpg|gif])
* of the current theme
*/
QString dataOutPixmap(bool useDefault = true) const;
/**
* @return the mail image (mail/decal_mail.[png|jpg|gif])
* of the current theme
*/
QString mailPixmap(bool useDefault = true) const;
/**
* @return a segmant of an image, using @p itemNo to
* get the segmant and from the ImageType @p type
*/
QPixmap splitPixmap(PixmapType type, uint itemNo = 0,
bool useDefault = true) const;
/**
* Same as the above function but returns an array of pixmaps
* with the maximum size of limitAmount, or all the pixmaps if @p
* limitAmount is -1 (default)
* @return an array of pixmaps
*/
QValueList<QPixmap> pixmapToList(PixmapType type,
int limitAmount = -1, bool useDefault = true) const;
/**
* returns the transparency level from the specified keys
*/
int transparency(const QString &, const QString &) const;
/**
* @return true if shadow text is enabled
*/
bool textShadow(const QString &, const QString &) const;
/**
* @return the shadow color (if any) for the specified keys
*/
QColor shadowColour(const QString &, const QString &) const;
/**
* @return the text color for the specified keys
*/
QColor textColour(const QString &, const QString &) const;
/**
* reads an entry and returns it as an int
*/
int readIntEntry(const QString &, const QString &) const;
/**
* @return a rect from the specified keys
*/
QRect readRectEntry(const QString &, const QString &) const;
/**
* reads an entry from the specified keys
*/
QString readEntry(const QString &, const QString &) const;
/**
* reads a color entry from the specified keys
*/
QString readColourEntry(const QString &, const QString &, int) const;
/**
* reads a font entry from the specified keys
*/
QFont readFontEntry(const QString &, const QString &) const;
/**
* sets the font, textColour, shadowColour and showShadow to
* the fonts and colours KSim should use depending on type and
* string.
*
* returns true if one of the parameters were changed using
* type and string, else the parameters will be set to the current
* colours and font that KSim should use and returns false.
*
* example usage:
* <pre>
* QFont font;
* QColor textColour, shadowColour;
* bool showShadow;
* if (KSim::ThemeLoader::self().current().fontColours(type(), configString(), font,
* textColour, shadowColour, showShadow)
* {
* setFont(font);
* // Do something with textColour, shadowColour and showShadow
* }
* </pre>
* @param type is the theme type you want, generally if you're calling this
* from a KSim::Base (or derived from) object then use type()
* @param string is the config string entry you want the function to read
* from, generally if you're calling this from a KSim::Base (or derived from)
* object then use configString()
*/
bool fontColours(int type, const QString &string, QFont &font,
QColor &textColour, QColor &shadowColour, bool &showShadow) const;
/**
* convenience function.
*
* collects the theme type and config key from the base pointer
*/
bool fontColours(const KSim::Base *const base, QFont &font,
QColor &textColour, QColor &shadowColour, bool &showShadow) const;
Theme(const KSim::Theme &);
private:
Theme();
Theme(const QString &url, const QString &fileName, int alt,
const QValueVector<QString> &vector, const QStringList &list,
KConfig *globalReader);
void create(const QValueVector<QString> &, const QStringList &, KConfig *);
void init(const QString &url, const QString &fileName, int alt);
void reparse(const QString &url, const QString &fileName, int alt);
QString parseConfig(const QString &, const QString &);
QString loader(int, bool useDefault = true) const;
QString createType(int, const QString &) const;
void setRecolour(bool);
int internalNumEntry(const QString &, int) const;
QRect internalRectEntry(const QString &, const QRect &) const;
QColor internalColourEntry(const QString &, const QColor &) const;
QString internalStringEntry(const QString &, const QString &) const;
class Private;
Private *d;
};
/**
* returns a class Theme containing
* information of the current theme or
* of the theme path specified
* @author Robbie Ward <linuxphreak@gmx.co.uk>
* @short Provides a loader for the themes
*/
class KDE_EXPORT ThemeLoader
{
public:
/**
* @return a reference to the instance
*/
static ThemeLoader &self();
/**
* @return true if the theme has changed
*/
bool isDifferent() const;
/**
* Updates the info to the current theme
*/
void reload();
/**
* @return the current theme that is set
*/
const KSim::Theme ¤t() const;
/**
* @return a theme from the path specified
* @param url is the path of the theme dir
* @param rcFile is the filename of the config file (optional)
* @param alt is the theme alternative number (optional)
*/
KSim::Theme theme(const QString &url,
const QString &rcFile = "gkrellmrc", int alt = 0) const;
/**
* re-colours an image to the current KDE
* color scheme
*/
void reColourImage(QImage &image);
/**
* changes some of the entries in the config file so kconfig
* can handle the file better.
* @return the location of the config file
*/
QString parseConfig(const QString &url, const QString &file);
/**
* change the dir structure of a theme directory
* so KSim can understand them better
*/
void parseDir(const QString &url, int alt);
/**
* checks if the themeUrl entry is valid,
* if not it then reverts the current theme
* to the default url
*/
void validate();
/**
* sets the pallete of the current theme
*/
void themeColours(QWidget *);
/**
* @return current theme name
*/
static QString currentName();
/**
* @return current theme url, if there is no current theme
* then it will return the default theme
*/
static QString currentUrl();
/**
* @return the default theme url
*/
static QString defaultUrl();
/**
* @return the current theme alternative
*/
static int currentAlternative();
/**
* @return the current theme alternative as a string, eg if the
* current theme alt is 1 then this will return '_1'.
* if there is no theme alt this will return a null string.
*
* if this is set to -1 (the default) then the current alternative
* will be used
*/
static QString alternativeAsString(int alt = -1);
/**
* @return the font of the theme if the theme font is set to custom
*/
static QFont currentFont();
/**
* @return the font item of the theme, eg: 0 would be the small font
*/
static int currentFontItem();
protected:
/**
* Default constructor, use self() to get an instance
*/
ThemeLoader();
~ThemeLoader();
private:
ThemeLoader(const ThemeLoader &);
ThemeLoader &operator=(const ThemeLoader &);
/**
* Deletes the instance and cleans up after itself
*/
static void cleanup();
void reColourItems();
void grabColour();
class Private;
Private *d;
KSim::Theme m_theme;
static ThemeLoader *m_self;
};
}
#endif
|