color_names.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * \file
  3. *
  4. * \author Mattia Basaglia
  5. *
  6. * \copyright Copyright (C) 2013-2020 Mattia Basaglia
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef COLOR_WIDGETS_COLOR_NAMES_HPP
  23. #define COLOR_WIDGETS_COLOR_NAMES_HPP
  24. #include <QColor>
  25. #include <QString>
  26. #include <QtColorWidgets/colorwidgets_global.hpp>
  27. namespace color_widgets {
  28. /**
  29. * \brief Convert a string into a color
  30. *
  31. * Supported string formats:
  32. * * Short hex strings #f00
  33. * * Long hex strings #ff0000
  34. * * Color names red
  35. * * Function-like rgb(255,0,0)
  36. *
  37. * Additional string formats supported only when \p alpha is true:
  38. * * Long hex strings #ff0000ff
  39. * * Function like rgba(255,0,0,255)
  40. */
  41. QCP_EXPORT QColor colorFromString(const QString& string, bool alpha = true);
  42. /**
  43. * \brief Convert a color into a string
  44. *
  45. * Format:
  46. * * If the color has full alpha: #ff0000
  47. * * If alpha is true and the color has non-full alpha: #ff000088
  48. */
  49. QCP_EXPORT QString stringFromColor(const QColor& color, bool alpha = true);
  50. } // namespace color_widgets
  51. #endif // COLOR_WIDGETS_COLOR_NAMES_HPP