colortools.h 657 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef COLORTOOLS_H
  2. #define COLORTOOLS_H
  3. #include <QColor>
  4. #include <QDeclarativeItem>
  5. class ColorTools : public QDeclarativeItem {
  6. Q_OBJECT
  7. public:
  8. Q_INVOKABLE qreal hue(QColor color) {
  9. return color.hueF();
  10. }
  11. Q_INVOKABLE qreal saturation(QColor color) {
  12. return color.saturationF();
  13. }
  14. Q_INVOKABLE qreal lightness(QColor color) {
  15. return color.lightnessF();
  16. }
  17. Q_INVOKABLE qreal hue(qreal r, qreal g, qreal b) {
  18. qDebug() << "r: " << r << " g " << g << " b " << b;
  19. return QColor(r * 255, g * 255, b * 255).hueF();
  20. }
  21. };
  22. #endif // COLORTOOLS_H