/usr/include/digits/kgamesvgdigits.h is in libkdegames-dev 4:4.8.2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | /** @file
* This file contains the KGameSvgDigits base class, used for displaying
* a series of svg digits.
*/
/***************************************************************************
* Copyright (C) 2007 Mark A. Taff <kde@marktaff.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License *
* version 2 as published by the Free Software Foundation *
* *
* 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library 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 _KGAMESVGDIGITS_H_
#define _KGAMESVGDIGITS_H_
#include <QtCore/QObject>
#include <QtGui/QColor>
#include <QtGui/QPixmap>
#include <kgamesvgdocument.h>
#include <ksvgrenderer.h>
#include <libkdegames_export.h>
class KGameSvgDigitsPrivate;
/**
* \class KGameSvgDigits kgamesvgdigits.h <KGameSvgDigits>
*
* @brief Renders a string of digits using an SVG theme
*
* @note To help limit rounding errors as the svg elements get scaled,
* make sure the svg container elements have whole integer widths and heights.
*
* Basic use case:
* @code
* QString themePath = "kdegames/libkdegames/digits/themes/individual-digits-sample.svg";
* digits = new KGameSvgDigits(themePath);
* digits.refreshCache();
* QPixmap pixmap = digits.display("12:16");
* @endcode
*
* You can overide any values specified in the theme if you need to. Make your changes after
* the theme is loaded, and before you call @c refreshCache(). Make sure you
* document any such overides for theme authors.
*
* To change the theme:
* @code
* QString newThemePath = "kdegames/libkdegames/digits/themes/fourteen-segment-sample.svg";
* digits.loadTheme(newThemePath);
* digits.refreshCache();
* QPixmap pixmap = digits.display(" 12:16.7");
* @endcode
*
* To enable the display to update, you need to connect the signal @c signalDisplayDirty
* to an appropriate slot in your application, such as:
* @code
* connect (digits, SIGNAL(signalDisplayDirty()),
* this, SLOT(display()));
* @endcode
*
* To toggle between the highlighted colors and the regular colors, call @c highlight():
* @code
* // Use highlight colors
* digits.highlight();
*
* // Revert to normal colors
* digits.highlight();
* @endcode
*
* To flash the display, call @c flash():
* @code
* // Flash to display every 800 milli-seconds
* digits.flash();
*
* // Flash the display every 2 seconds
* digits.flash(2000);
* @endcode
*
* To stop flashing the display, call @c stopFlashing():
* @code
* // Stop flashing the display
* digits.stopFlashing();
* @endcode
*
* For caching options, you will most likely find either \ref CachePreviouslyRendered
* or \ref CacheNumeralsOnly to fit your needs. \ref CacheNone and \ref CacheAll
* are probably only useful in a few edge cases.
*
* There are two basic digit types: individual digits and segmented digits. Individual digits
* are have a foreground, a backgound, and a container. Segemented digits have their segments
* turned on or off according to a bitmask, like a real segmented display.
*
* A theme for an \ref IndividualDigit type must contain a glyph for every charcater to be
* rendered. A theme for a \ref SevenSegmentDigit or \ref FourteenSegmentDigit omly
* needs to contain a glyph for the digit, and a glyph for the punctuation.
*
* \ref IndividualDigit type themes require more work from the artist, but they render
* much faster (generally) at runtime. The inverse is true for segmented digits.
*
* Note that an artist can create a seven, fourteen, or grid display as a \ref IndividualDigit
* type. This is probably the way to go from a performance perspective.
*
* We ignore and skip displaying any invalid digits in the string passed in to \ref display().
*
* Characters that <b>must</b> be in every theme for it to be valid are a blank space, the numbers 0-9, the
* punctuation characters comma, period, colon, semi-colon, and minus sign.
*
* @author Mark A. Taff \<kde@marktaff.com\>
*/
class KDEGAMES_EXPORT KGameSvgDigits : public QObject
{
Q_OBJECT
public:
/**
* @brief Constructor
*
* Create a KGameSvgDigits object with default values:
* @li @c foregroundColor to ARGB \#ffffaa00 orange
* @li @c backgroundColor to ARGB \#ff323232 dark gray
* @li @c foregroundHighlightColor to ARGB \#ffff0000 red
* @li @c backgroundHighlightColor to ARGB \#ffeeeeec very light gray
* @li @c cache to @c CacheNumeralsOnly
* @li @c style to @c LedStyle
*
* @param themeFile The path to the theme's *.desktop file to load
* @returns nothing
*/
explicit KGameSvgDigits(const QString& themeFile);
/**
* @overload
* @brief Constructor
*
* Create a KGameSvgDigits object with default values:
* @li @c foregroundColor to ARGB \#ffffaa00 orange
* @li @c backgroundColor to ARGB \#ff323232 dark gray
* @li @c foregroundHighlightColor to ARGB \#ffff0000 red
* @li @c backgroundHighlightColor to ARGB \#ffeeeeec very light gray
* @li @c cache to @c CacheNumeralsOnly
* @li @c style to @c LedStyle
*
* @returns nothing
*/
KGameSvgDigits();
/**
* @brief Destructor
*
* @returns nothing
*/
virtual ~KGameSvgDigits();
/**
* @brief Loads a theme
*
* @param themeFile The path to the theme's *.desktop file to load
* @returns nothing
*/
void loadTheme(const QString& themeFile);
/**
* @brief Options for caching pixmaps of rendered digits
*/
enum CacheOption {
/**
* Render & cache numerals & punctuation in advance
*/
CacheNumeralsOnly = 0x01,
/**
* Do not cache in advance; only cache digits actually used
*/
CachePreviouslyRendered = 0x02,
/**
* Do not cache at all. Render directly. Could take a lot of resources.
*/
CacheNone = 0x03,
/**
* Render & cache in advance all possible digits
* This is only used if DigitType is IndividualDigit
*/
CacheAll = 0x04
};
/** @brief Q_DECLARE_FLAGS macro confuses doxygen, so create typedef's manually */
typedef QFlags<CacheOption> CacheOptions;
/**
* @brief Type of the svg digit
*/
enum DigitType {
/**
* Any digit that is directly rendered.
*/
IndividualDigit = 0x01,
/**
* A seven segment digit where each segment is on/off according to the bitmask passed in.
*/
SevenSegmentDigit = 0x02,
/**
* A fourteen segment digit where each segment is on/off according to the bitmask passed in.
*/
FourteenSegmentDigit = 0x03
};
/** @brief Q_DECLARE_FLAGS macro confuses doxygen, so create typedef's manually */
typedef QFlags<DigitType> DigitTypes;
/**
* @brief Style of the svg digit
*/
enum DigitStyle {
/**
* Draw the off segments faintly like an LED display.
*/
LedStyle = 0x01,
/**
* Do not render the off segments, as in an monochrome LCD display.
*/
LcdStyle = 0x02
};
/** @brief Q_DECLARE_FLAGS macro confuses doxygen, so create typedef's manually */
typedef QFlags<DigitStyle> DigitStyles;
/**
* @brief Invalidate current pixmap cache and rebuild according to @c CacheOption
* @returns nothing
*/
void refreshCache();
/**
* @brief Display the string
* @param display The string to display
*
* We skip and ignore any invalid characters passed in, where 'invalid' means any character
* that isn't already cached, can't be produced, or isn't in the svg file.
*
* We can display leading and trailing spaces, so pad the string passed in so that
* the digits occupy the value position you want.
*
* @returns a pixmap showing @c display.
*/
QPixmap display(const QString& display);
/**
* @brief Flash the display
* @param interval The interval between flashes, in milli-seconds
*
* @returns nothing
*/
void flash(int interval);
/**
* @overload
* @brief Flash the display with an interval of 800 milli-seconds
*
* @returns nothing
*/
void flash();
/**
* @brief Stop flashing the display
*
* @returns nothing
*/
void stopFlashing();
/**
* @brief Toggle highlighting the display
*
* @returns nothing
*/
void highlight();
//
// Setters & Accessors
//
/**
* @brief Sets whether the pixmap cache is dirty
*
* @param isDirty Is the pixmap cache dirty?
* @returns nothing
* @see isPixmapCacheDirty()
*/
void setPixmapCacheDirty(bool isDirty);
/**
* @brief Returns whether the pixmap cache is dirty
*
* @returns whether the pixmap cache is dirty
* @see setPixmapCacheDirty()
*/
bool isPixmapCacheDirty();
/**
* @brief Sets whether this digit is an LED or LCD
*
* @param style Is this digit and LED
* @returns nothing
* @see digitStyle()
*/
void setDigitStyle(const DigitStyle& style);
/**
* @overload
* @brief Sets whether this digit is an LED or LCD
*
* @param style Is this digit and LED
* @returns nothing
* @see digitStyle()
*/
void setDigitStyle(const QString& style);
/**
* @brief Returns whether this digit is an LED or LCD
*
* @returns whether this digit is an LED or LCD
* @see setDigitStyle()
*/
int digitStyle();
/**
* @brief Sets the number of digits
*
* @param numberOfDigits The number of digits
* @returns nothing
* @see numberOfDigits()
*/
void setNumberOfDigits(int numberOfDigits);
/**
* @brief Returns the number of digits
*
* @returns the number of digits
* @see setNumberOfDigits()
*/
int numberOfDigits();
/**
* @brief Sets the cache strategy
*
* @param option the cache strategy
* @returns nothing
* @see cacheOption()
*/
void setCacheOption(CacheOptions option);
/**
* @overload
* @brief Sets the cache strategy
*
* @param option the cache strategy
* @returns nothing
* @see cacheOption()
*/
void setCacheOption(const QString& option);
/**
* @brief Returns the cache strategy
*
* @returns the cache strategy
* @see setDigitType()
*/
int cacheOption();
/**
* @brief Sets the type of the digit, individual|seven|fourteen
*
* @param type the type of the digit, individual|seven|fourteen
* @returns nothing
* @see digitType()
*/
void setDigitType(DigitTypes type);
/**
* @overload
* @brief Sets the type of the digit, IndividualDigit|SevenSegmentDigit|FourteenSegmentDigit
*
* @param type the type of the digit, individual|seven|fourteen
* @returns nothing
* @see digitType()
*/
void setDigitType(const QString& type);
/**
* @brief Returns the type of the digit, individual|seven|fourteen
*
* @returns the type of the digit, individual|seven|fourteen
* @see setDigitType()
*/
int digitType();
/**
* @brief Sets the foreground color
*
* @param foregroundColor The color for the foreground
* @returns nothing
* @see foregroundColor(), backgroundColor(), setBackgroundColor()
*/
void setForegroundColor(const QColor& foregroundColor);
/**
* @brief Returns the foreground color
*
* @returns the foreground color
* @see setForegroundColor(), backgroundColor(), setBackgroundColor()
*/
QColor foregroundColor();
/**
* @brief Sets the background color
*
* @param backgroundColor The color for the background
* @returns nothing
* @see backgroundColor(), foregroundColor(), setForegroundColor()
*/
void setBackgroundColor(const QColor& backgroundColor);
/**
* @brief Returns the background color
*
* @returns the background color
* @see setBackgroundColor(), foregroundColor(), setForegroundColor()
*/
QColor backgroundColor();
/**
* @brief Sets the foreground highlight color
*
* @param foregroundHighlightColor The color for the foreground highlight
* @returns nothing
* @see foregroundHighlightColor(), backgroundHighlightColor(), setBackgroundHighlightColor()
*/
void setForegroundHighlightColor(const QColor& foregroundHighlightColor);
/**
* @brief Returns the foreground highlight color
*
* @returns the foreground highlight color
* @see setForegroundHighlightColor(), backgroundHighlightColor(), setBackgroundHighlightColor()
*/
QColor foregroundHighlightColor();
/**
* @brief Sets the background highlight color
*
* @param backgroundHighlightColor The color for the background highlight
* @returns nothing
* @see backgroundHighlightColor(), foregroundHighlightColor(), setForegroundHighlightColor()
*/
void setBackgroundHighlightColor(const QColor& backgroundHighlightColor);
/**
* @brief Returns the background highlight color
*
* @returns the background highlight color
* @see setBackgroundHighlightColor(), foregroundHighlightColor(), setForegroundHighlightColor()
*/
QColor backgroundHighlightColor();
/**
* @brief Sets the factor to scale the x-axis by.
*
* @param scale The factor to scale the x-axis by.
* @returns nothing
* @see scaleX(), scaleY(), setScaleY()
*/
void setScaleX(double scale);
/**
* @brief Returns the factor to scale the x-axis by.
*
* @returns factor to scale the x-axis by.
* @see setScaleX(), scaleY(), setScaleY()
*/
double scaleX();
/**
* @brief Sets the factor to scale the y-axis by.
*
* @param scale The factor to scale the y-axis by.
* @returns nothing
* @see scaleY(), scaleX(), setScaleX()
*/
void setScaleY(double scale);
/**
* @brief Returns the factor to scale the y-axis by.
*
* @returns factor to scale the y-axis by.
* @see setScaleY(), scaleX(), setScaleX()
*/
double scaleY();
/**
* @brief Sets the factor to skew the x-axis by.
*
* @param skew The factor to skew the x-axis by.
* @returns nothing
* @see skewX(), skewY(), setSkewY()
*/
void setSkewX(double skew);
/**
* @brief Returns the factor to skew the x-axis by.
*
* @returns factor to skew the x-axis by.
* @see setSkewX(), skewY(), setSkewY()
*/
double skewX();
/**
* @brief Sets the factor to skew the y-axis by.
*
* @param skew The factor to skew the y-axis by.
* @returns nothing
* @see skewY(), skewX(), setSkewX()
*/
void setSkewY(double skew);
/**
* @brief Returns the factor to skew the y-axis by.
*
* @returns factor to skew the y-axis by.
* @see setSkewY(), skewX(), setSkewX()
*/
double skewY();
/**
* @brief Sets the alpha channel level for "off" segments of LED's
*
* @param alphaLevel the alpha channel level
* @returns nothing
* @see ledOffSegmentAlphaLevel()
*/
void setLedOffSegmentAlphaLevel(int alphaLevel);
/**
* @brief Returns the alpha channel level for "off" segments of LED's
*
* @returns the alpha channel level
* @see setLedOffSegmentAlphaLevel()
*/
int ledOffSegmentAlphaLevel();
/**
* @brief Sets the bitmask to render
*
* @param mask The bitmask to set.
* @returns nothing
* @see bitmask()
*/
void setBitmask(ulong mask);
/**
* @brief Returns the bitmask to render.
*
* @returns the bitmask to render.
* @see setBitmask()
*/
ulong bitmask();
/**
* @brief Sets the digit to render
*
* @param digit The digit to set.
* @returns nothing
* @see digit()
*/
void setDigit(const QString& digit);
/**
* @brief Returns the digit to render.
*
* @returns the digit to render.
* @see setDigit()
*/
QString digit();
/**
* @brief Sets elementId of the digit to render
*
* @param elementId The elementId of the digit to set.
* @returns nothing
* @see elementId()
*/
void setElementId(const QString& elementId);
/**
* @brief Returns the elementId of the digit to render.
*
* @returns the elementId of the digit to render.
* @see setElementId()
*/
QString elementId();
/**
* @brief Sets the horizontal spacing in pixels between the digits
*
* The spacing in pixels to use when scaleX == 1. Letter-spacing is scaled the same as
* the digits themselves.
*
* @param spacing The horizontal spacing in pixels between the digits
* @returns nothing
* @see letterSpacing()
*/
void setLetterSpacing(const int spacing);
/**
* @brief Returns the horizontal spacing in pixels between the digits.
*
* @returns the horizontal spacing in pixels between the digits.
* @see setLetterSpacing()
*/
int letterSpacing();
/**
* @brief Sets the padding in pixels between the top of the digits and the top of the display.
*
* The padding in pixels to use when scaleX == 1. padding-top is scaled the same as
* the digits themselves.
*
* @param padding The padding in pixels between the top of the digits and the top of the display
* @returns nothing
* @see paddingTop(), setPadding()
*/
void setPaddingTop(const int padding);
/**
* @brief Returns the padding in pixels between the top of the digits and the top of the display.
*
* @returns the padding in pixels between the top of the digits and the top of the display.
* @see setPaddingTop()
*/
int paddingTop();
/**
* @brief Sets the padding in pixels between the right-most digit and the right edge of the display.
*
* The padding in pixels to use when scaleX == 1. padding-right is scaled the same as
* the digits themselves.
*
* @param padding The padding in pixels between the right-most digit and the right edge of the display
* @returns nothing
* @see paddingRight(), setPadding()
*/
void setPaddingRight(const int padding);
/**
* @brief Returns the padding in pixels between the right-most digit and the right edge of the display.
*
* @returns the padding in pixels between the right-most digit and the right edge of the display
* @see setPaddingRight()
*/
int paddingRight();
/**
* @brief Sets the padding in pixels between the bottom of the digits and the bottom of the display.
*
* The padding in pixels to use when scaleX == 1. padding-bottom is scaled the same as
* the digits themselves.
*
* @param padding The padding in pixels between the bottom of the digits and the bottom of the display
* @returns nothing
* @see paddingBottom(), setPadding()
*/
void setPaddingBottom(const int padding);
/**
* @brief Returns the padding in pixels between the bottom of the digits and the bottom of the display.
*
* @returns the padding in pixels between the bottom of the digits and the bottom of the display
* @see setPaddingBottom()
*/
int paddingBottom();
/**
* @brief Sets the padding in pixels between the leftmost digit and the left edge of the display.
*
* The padding in pixels to use when scaleX == 1. padding-left is scaled the same as
* the digits themselves.
*
* @param padding The padding in pixels between the leftmost digit and the left edge of the display
* @returns nothing
* @see paddingLeft(), setPadding()
*/
void setPaddingLeft(const int padding);
/**
* @brief Returns the padding in pixels between the leftmost digit and the left edge of the display.
*
* @returns the padding in pixels between the leftmost digit and the left edge of the display
* @see setPaddingLeft()
*/
int paddingLeft();
/**
* @brief Sets the padding in pixels.
*
* The padding in pixels to use when scaleX == 1. padding is scaled the same as
* the digits themselves.
*
* @param paddingTop The padding-top in pixels
* @param paddingRight The padding-right in pixels
* @param paddingBottom The padding-bottom in pixels
* @param paddingLeft The padding-left in pixels
* @returns nothing
* @see setPaddingTop(), setPaddingRight(), setPaddingBottom(), setPaddingLeft()
*/
void setPadding(const int paddingTop, const int paddingRight,
const int paddingBottom, const int paddingLeft);
//
// Properties
//
private:
/**
* @brief d-pointer
*/
KGameSvgDigitsPrivate * const d;
Q_SIGNALS:
/**
* Use this signal to change the content of the display
*/
void signalDisplayDirty();
private Q_SLOTS:
void updateFlash();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KGameSvgDigits::CacheOptions)
Q_DECLARE_OPERATORS_FOR_FLAGS(KGameSvgDigits::DigitTypes)
Q_DECLARE_OPERATORS_FOR_FLAGS(KGameSvgDigits::DigitStyles)
#endif // _KGAMESVGDIGITS_H_
|