ColorChooser.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* ColorChooser.h - declaration and definition of ColorChooser class.
  2. *
  3. * Copyright (c) 2019 CYBERDEViLNL <cyberdevilnl/at/protonmail/dot/ch>
  4. *
  5. * This file is part of LMMS - https://lmms.io
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this program (see COPYING); if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #include <QApplication>
  24. #include <QColor>
  25. #include <QColorDialog>
  26. #include <QKeyEvent>
  27. #include <QVector>
  28. class ColorChooser: public QColorDialog
  29. {
  30. public:
  31. ColorChooser(const QColor &initial, QWidget *parent): QColorDialog(initial, parent) {};
  32. ColorChooser(QWidget *parent): QColorDialog(parent) {};
  33. //! For getting a color without having to initialise a color dialog
  34. ColorChooser() {};
  35. enum class Palette {Default, Track, Mixer};
  36. //! Set global palette via array, checking bounds
  37. void setPalette (QVector<QColor>);
  38. //! Set global paletter via enum
  39. void setPalette (Palette);
  40. //! Set palette via enum, return self pointer for chaining
  41. ColorChooser* withPalette (Palette);
  42. //! Return a certain palette
  43. static QVector<QColor> getPalette (Palette);
  44. protected:
  45. //! Forward key events to the parent to prevent stuck notes when the dialog gets focus
  46. void keyReleaseEvent(QKeyEvent *event) override
  47. {
  48. QKeyEvent ke(*event);
  49. QApplication::sendEvent(parentWidget(), &ke);
  50. }
  51. private:
  52. //! Copy the current QColorDialog palette into an array
  53. static QVector<QColor> defaultPalette();
  54. //! Generate a nice palette, with adjustable value
  55. static QVector<QColor> nicePalette (int);
  56. };