[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfcolorchooser.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfcolorchooser.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (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 *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfcolorchooser.h 953 2016-12-27 00:13:10Z phfaist $ */
23 
24 #ifndef KLFCOLORCHOOSER_H
25 #define KLFCOLORCHOOSER_H
26 
27 #include <QPushButton>
28 #include <QColor>
29 #include <QApplication>
30 #include <QList>
31 #include <QEvent>
32 #include <QWidget>
33 #include <QDialog>
34 #include <QSpinBox>
35 #include <QGridLayout>
36 #include <QPainter>
37 
38 #include <klfdefs.h>
39 
40 
41 class KLFColorList;
42 
43 
44 // ------------------------------------------------------------------------------------
45 
46 
47 class KLF_EXPORT KLFColorClickSquare : public QWidget
48 {
49  Q_OBJECT
50 
51  Q_PROPERTY(QColor color READ color WRITE setColor USER true) ;
52  Q_PROPERTY(int sqSize READ sqSize WRITE setSqSize) ;
53  Q_PROPERTY(bool removable READ removable WRITE setRemovable) ;
54 public:
55  KLFColorClickSquare(QColor color = Qt::white, int size = 16, bool removable = true, QWidget *parent = 0);
56  explicit KLFColorClickSquare(QWidget *parent);
57 
58  virtual QSize sizeHint() const { return QSize(_size, _size); }
59 
60  inline QColor color() const { return _color; }
61  inline int sqSize() const { return _size; }
62  inline bool removable() const { return _removable; }
63 
64 signals:
65  void activated();
66  void colorActivated(const QColor& color);
67  void wantRemove();
68  void wantRemoveColor(const QColor& color);
69 
70 public slots:
71  void setColor(const QColor& col) { _color = col; }
72  void activate() {
73  emit activated();
74  emit colorActivated(_color);
75  }
76  void setSqSize(int sqsize);
77  void setRemovable(bool removable);
78 
79 protected:
80  void paintEvent(QPaintEvent *event);
81  void resizeEvent(QResizeEvent *event);
82  void keyPressEvent(QKeyEvent *event);
83  void mousePressEvent(QMouseEvent *event);
84  void contextMenuEvent(QContextMenuEvent *event);
85 
86 private:
87  QColor _color;
88  int _size;
89  bool _removable;
90 
91  void initwidget();
92 
93 private slots:
94  void internalWantRemove();
95 };
96 
97 
98 // ------------------------------------------------------------------------------------
99 
144 {
145 protected:
147  int valueAFromNewColor(const QColor& color) const;
149  int valueBFromNewColor(const QColor& color) const;
151  inline int valueA() const { return valueAFromNewColor(_color); }
153  inline int valueB() const { return valueBFromNewColor(_color); }
155  inline int valueAMax() const { return valueMax(_colorcomponent); }
157  inline int valueBMax() const { return valueMax(_colorcomponent_b); }
158 
175  QColor colorFromValues(QColor color_base, int value_a, int value_b = -1);
176 
182  bool refreshColorFromInternalValues(int value_a, int value_b = -1);
183 
186  static int valueFromNewColor(const QColor& color, const QString& component);
187 
193  static int valueMax(const QString& component);
194 
197 
200  QString _colorcomponent, _colorcomponent_b;
201 };
202 
203 
204 // ------------------------------------------------------------------------------------
205 
229 {
230  Q_OBJECT
231 
232  Q_PROPERTY(QString colorComponent READ colorComponent WRITE setColorComponent)
233  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
234 public:
235  KLFColorComponentSpinBox(QWidget *parent);
237 
239  QColor color() const { return _color; }
240 
241 signals:
242  void colorChanged(const QColor& color);
243 
244 public slots:
245  void setColorComponent(const QString& component);
246  void setColor(const QColor& color);
247 
248 private slots:
249  void internalChanged(int newvalue);
250 
251 };
252 
253 
254 // ------------------------------------------------------------------------------------
255 
275 {
276  Q_OBJECT
277  Q_PROPERTY(QString paneType READ paneType WRITE setPaneType);
278  Q_PROPERTY(QColor color READ color WRITE setColor USER true);
279 public:
280  KLFColorChooseWidgetPane(QWidget *parent = 0);
282 
283  QString paneType() const { return _colorcomponent + "+" + _colorcomponent_b; }
284  QColor color() const { return _color; }
285 
286  QSize sizeHint() const;
287  QSize minimumSizeHint() const;
288 
289 signals:
290  void colorChanged(const QColor& color);
291 
292 public slots:
293  void setColor(const QColor& newcolor);
294  void setPaneType(const QString& panetype);
295 
296 protected:
297  virtual void paintEvent(QPaintEvent *e);
298  virtual void mousePressEvent(QMouseEvent *e);
299  virtual void mouseMoveEvent(QMouseEvent *e);
300  virtual void wheelEvent(QWheelEvent *e);
301  virtual void keyPressEvent(QKeyEvent *e);
302 
303 private:
304  QImage _img;
305 };
306 
307 
308 // ------------------------------------------------------------------------------------
309 
310 namespace Ui { class KLFColorChooseWidget; }
311 class QListWidgetItem;
312 
328 class KLF_EXPORT KLFColorChooseWidget : public QWidget
329 {
330  Q_OBJECT
331 
332  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
333  Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
334 public:
335  KLFColorChooseWidget(QWidget *parent = 0);
336  virtual ~KLFColorChooseWidget() { }
337 
338  QColor color() const { return _color; }
339 
340  bool alphaEnabled() const { return _alphaenabled; }
341 
342  static void ensureColorListsInstance();
343  static void setRecentCustomColors(QList<QColor> recentcolors, QList<QColor> customcolors);
344  static void addRecentColor(const QColor& col);
345  static QList<QColor> recentColors();
346  static QList<QColor> customColors();
347 
348 signals:
349  void colorChanged(const QColor& color);
350 
351 public slots:
352  void setColor(const QColor& color);
353  void setAlphaEnabled(bool alpha_enabled);
354  void setCurrentToCustomColor();
355 
356  void updatePalettes();
357 
358  void updatePaletteRecent();
359  void updatePaletteStandard();
360  void updatePaletteCustom();
361 
362 protected slots:
363  virtual void internalColorChanged(const QColor& newcolor);
364  virtual void internalColorNameSelected(QListWidgetItem *item);
365  virtual void internalColorNameSet(const QString& colorname);
366 
367 
368 private:
369  Ui::KLFColorChooseWidget *u;
370 
371  QColor _color;
372  bool _alphaenabled;
373 
374  QList<QObject*> _connectedColorChoosers;
375 
376  void fillPalette(KLFColorList *colorlist, QWidget *w);
377 
378  static KLFColorList *_recentcolors;
379  static KLFColorList *_standardcolors;
380  static KLFColorList *_customcolors;
381 };
382 
383 
384 // ------------------------------------------------------------------------------------
385 
386 
387 namespace Ui { class KLFColorDialog; }
388 
397 class KLF_EXPORT KLFColorDialog : public QDialog
398 {
399  Q_OBJECT
400 
401  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
402 public:
405  KLFColorDialog(QWidget *parent = 0);
406  virtual ~KLFColorDialog();
407 
409  KLFColorChooseWidget *colorChooseWidget();
410 
411  QColor color() const;
412 
419  static QColor getColor(QColor startwith = Qt::black, bool alphaenabled = true, QWidget *parent = 0);
420 
421 public slots:
422 
423  void setColor(const QColor& color);
424 
425 private:
426  Ui::KLFColorDialog *u;
427 
428 private slots:
429  void slotAccepted();
430 };
431 
432 
433 
434 
435 // ------------------------------------------------------------------------------------
436 
437 class QStyle;
438 class KLFRelativeFont;
439 
440 class KLF_EXPORT KLFColorChooser : public QPushButton
441 {
442  Q_OBJECT
443 
444  Q_PROPERTY(QSize showSize READ showSize WRITE setShowSize)
445  Q_PROPERTY(bool allowDefaultState READ allowDefaultState WRITE setAllowDefaultState)
446  Q_PROPERTY(QString defaultStateString READ defaultStateString WRITE setDefaultStateString)
447  Q_PROPERTY(bool autoAddToList READ autoAddToList WRITE setAutoAddToList)
448  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
449  Q_PROPERTY(float pixXAlignFactor READ pixXAlignFactor WRITE setPixXAlignFactor)
450  Q_PROPERTY(float pixYAlignFactor READ pixYAlignFactor WRITE setPixYAlignFactor)
451  Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
452 
453 public:
454  KLFColorChooser(QWidget *parent);
455  ~KLFColorChooser();
456 
457  QSize showSize() const { return _size; }
459 
463  bool allowDefaultState() const { return _allowdefaultstate; }
464  QString defaultStateString() const { return _defaultstatestring; }
465  bool autoAddToList() const { return _autoadd; }
466  QColor color() const;
467  float pixXAlignFactor() const { return _xalignfactor; }
468  float pixYAlignFactor() const { return _yalignfactor; }
470  bool alphaEnabled() const { return _alphaenabled; }
471 
472  virtual QSize sizeHint() const;
473 
476  static void setUserMaxColors(int maxcolors);
477 
478  static void setColorList(const QList<QColor>& colorlist);
479  static QList<QColor> colorList();
480 
481 signals:
482  void colorChanged(const QColor& newcolor);
483 
484 public slots:
488  void setColor(const QColor& color);
489  void setAllowDefaultState(bool allow);
490  void setDefaultStateString(const QString& str);
491  void setAutoAddToList(bool autoadd);
492  void setShowSize(const QSize& size);
493  void setPixXAlignFactor(float xalignfactor);
494  void setPixYAlignFactor(float yalignfactor);
495  void setAlphaEnabled(bool alpha_enabled);
497  void setDefaultColor();
498 
499  void requestColor();
500 
501 protected slots:
502  void setSenderPropertyColor();
503  void _makemenu();
504 
505 protected:
506  void paintEvent(QPaintEvent *event);
507 
508 private:
509  QColor _color;
510  QPixmap _pix;
511 
512  bool _allowdefaultstate;
513  QString _defaultstatestring;
514  bool _autoadd;
515  QSize _size;
516  float _xalignfactor, _yalignfactor;
517 
518  bool _alphaenabled;
519 
520  QMenu *mMenu;
521  KLFRelativeFont *menuRelFont;
522 
523  void _setpix();
524 
525  QPixmap colorPixmap(const QColor& color, const QSize& size);
526 
527  static KLFColorList *_colorlist;
528  static QStyle *mReplaceButtonStyle;
529 
530  static int staticUserMaxColors;
531 
532  static void ensureColorListInstance();
533 
534 };
535 
536 
537 #endif
bool removable() const
Base declarations for klatexformula and some utilities.
void setColor(const QColor &col)
float pixYAlignFactor() const
float pixXAlignFactor() const
bool alphaEnabled() const
#define KLF_EXPORT
Definition: klfdefs.h:41
A dialog to let the user select a color.
QColor color() const
QString defaultStateString() const
A pane displaying a gradient of colors, controlling one or two (arbitrary) components of a color...
bool allowDefaultState() const
Allow the "default color" state.
QColor color() const
virtual QSize sizeHint() const
QString colorComponent() const
A Spin box editing a component of a color.
bool autoAddToList() const
bool alphaEnabled() const
TRUE if the user can also select opacity (alpha) with this widget.
Base utility class that stores and calculates specific components of a color that is being edited...

Generated by doxygen 1.8.13