[KLF Application][KLF Tools][KLF Backend][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 603 2011-02-26 23:14:55Z 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 public:
53  KLFColorClickSquare(QColor color = Qt::white, int size = 16, bool removable = true, QWidget *parent = 0);
54 
55  virtual QSize sizeHint() { return QSize(_size, _size); }
56 
57  QColor color() const { return _color; }
58 
59 signals:
60  void activated();
61  void colorActivated(const QColor& color);
62  void wantRemove();
63  void wantRemoveColor(const QColor& color);
64 
65 public slots:
66  void setColor(const QColor& col) { _color = col; }
67  void activate() {
68  emit activated();
69  emit colorActivated(_color);
70  }
71 
72 protected:
73  void paintEvent(QPaintEvent *event);
74  void keyPressEvent(QKeyEvent *event);
75  void mousePressEvent(QMouseEvent *event);
77 
78 private:
79  QColor _color;
80  int _size;
81  bool _removable;
82 
83 private slots:
84  void internalWantRemove();
85 };
86 
87 
88 // ------------------------------------------------------------------------------------
89 
134 {
135 protected:
137  int valueAFromNewColor(const QColor& color) const;
139  int valueBFromNewColor(const QColor& color) const;
141  inline int valueA() const { return valueAFromNewColor(_color); }
143  inline int valueB() const { return valueBFromNewColor(_color); }
145  inline int valueAMax() const { return valueMax(_colorcomponent); }
147  inline int valueBMax() const { return valueMax(_colorcomponent_b); }
148 
165  QColor colorFromValues(QColor color_base, int value_a, int value_b = -1);
166 
172  bool refreshColorFromInternalValues(int value_a, int value_b = -1);
173 
176  static int valueFromNewColor(const QColor& color, const QString& component);
177 
183  static int valueMax(const QString& component);
184 
187 
190  QString _colorcomponent, _colorcomponent_b;
191 };
192 
193 
194 // ------------------------------------------------------------------------------------
195 
219 {
220  Q_OBJECT
221 
222  Q_PROPERTY(QString colorComponent READ colorComponent WRITE setColorComponent)
223  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
224 public:
227 
229  QColor color() const { return _color; }
230 
231 signals:
232  void colorChanged(const QColor& color);
233 
234 public slots:
235  void setColorComponent(const QString& component);
236  void setColor(const QColor& color);
237 
238 private slots:
239  void internalChanged(int newvalue);
240 
241 };
242 
243 
244 // ------------------------------------------------------------------------------------
245 
265 {
266  Q_OBJECT
267  Q_PROPERTY(QString paneType READ paneType WRITE setPaneType);
268  Q_PROPERTY(QColor color READ color WRITE setColor USER true);
269 public:
270  KLFColorChooseWidgetPane(QWidget *parent = 0);
272 
273  QString paneType() const { return _colorcomponent + "+" + _colorcomponent_b; }
274  QColor color() const { return _color; }
275 
276 signals:
277  void colorChanged(const QColor& color);
278 
279 public slots:
280  void setColor(const QColor& newcolor);
281  void setPaneType(const QString& panetype);
282 
283 protected:
284  virtual void paintEvent(QPaintEvent *e);
285  virtual void mousePressEvent(QMouseEvent *e);
286  virtual void mouseMoveEvent(QMouseEvent *e);
287  virtual void wheelEvent(QWheelEvent *e);
288 
289 private:
290  QImage _img;
291 };
292 
293 
294 // ------------------------------------------------------------------------------------
295 
296 namespace Ui { class KLFColorChooseWidget; }
297 class QListWidgetItem;
298 
314 class KLF_EXPORT KLFColorChooseWidget : public QWidget
315 {
316  Q_OBJECT
317 
318  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
319  Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
320 public:
321  KLFColorChooseWidget(QWidget *parent = 0);
322  virtual ~KLFColorChooseWidget() { }
323 
324  QColor color() const { return _color; }
325 
326  bool alphaEnabled() const { return _alphaenabled; }
327 
328  static void ensureColorListsInstance();
329  static void setRecentCustomColors(QList<QColor> recentcolors, QList<QColor> customcolors);
330  static void addRecentColor(const QColor& col);
331  static QList<QColor> recentColors();
332  static QList<QColor> customColors();
333 
334 signals:
335  void colorChanged(const QColor& color);
336 
337 public slots:
338  void setColor(const QColor& color);
339  void setAlphaEnabled(bool alpha_enabled);
340  void setCurrentToCustomColor();
341 
342  void updatePalettes();
343 
344  void updatePaletteRecent();
345  void updatePaletteStandard();
346  void updatePaletteCustom();
347 
348 protected slots:
349  virtual void internalColorChanged(const QColor& newcolor);
350  virtual void internalColorNameSelected(QListWidgetItem *item);
351  virtual void internalColorNameSet(const QString& colorname);
352 
353 
354 private:
355  Ui::KLFColorChooseWidget *u;
356 
357  QColor _color;
358  bool _alphaenabled;
359 
360  QList<QObject*> _connectedColorChoosers;
361 
362  void fillPalette(KLFColorList *colorlist, QWidget *w);
363 
364  static KLFColorList *_recentcolors;
365  static KLFColorList *_standardcolors;
366  static KLFColorList *_customcolors;
367 };
368 
369 
370 // ------------------------------------------------------------------------------------
371 
372 
373 namespace Ui { class KLFColorDialog; }
374 
383 class KLF_EXPORT KLFColorDialog : public QDialog
384 {
385  Q_OBJECT
386 public:
389  KLFColorDialog(QWidget *parent = 0);
390  virtual ~KLFColorDialog();
391 
393  KLFColorChooseWidget *colorChooseWidget();
394 
401  static QColor getColor(QColor startwith = Qt::black, bool alphaenabled = true, QWidget *parent = 0);
402 
403 private:
404  Ui::KLFColorDialog *u;
405 };
406 
407 
408 
409 
410 // ------------------------------------------------------------------------------------
411 
412 class QStyle;
413 
414 class KLF_EXPORT KLFColorChooser : public QPushButton
415 {
416  Q_OBJECT
417 
418  Q_PROPERTY(QSize showSize READ showSize WRITE setShowSize)
419  Q_PROPERTY(bool allowDefaultState READ allowDefaultState WRITE setAllowDefaultState)
420  Q_PROPERTY(QString defaultStateString READ defaultStateString WRITE setDefaultStateString)
421  Q_PROPERTY(bool autoAddToList READ autoAddToList WRITE setAutoAddToList)
422  Q_PROPERTY(QColor color READ color WRITE setColor USER true)
423  Q_PROPERTY(float pixXAlignFactor READ pixXAlignFactor WRITE setPixXAlignFactor)
424  Q_PROPERTY(float pixYAlignFactor READ pixYAlignFactor WRITE setPixYAlignFactor)
425  Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
426 
427 public:
428  KLFColorChooser(QWidget *parent);
429  ~KLFColorChooser();
430 
431  QSize showSize() const { return _size; }
433 
437  bool allowDefaultState() const { return _allowdefaultstate; }
438  QString defaultStateString() const { return _defaultstatestring; }
439  bool autoAddToList() const { return _autoadd; }
440  QColor color() const;
441  float pixXAlignFactor() const { return _xalignfactor; }
442  float pixYAlignFactor() const { return _yalignfactor; }
444  bool alphaEnabled() const { return _alphaenabled; }
445 
446  virtual QSize sizeHint() const;
447 
450  static void setUserMaxColors(int maxcolors);
451 
452  static void setColorList(const QList<QColor>& colorlist);
453  static QList<QColor> colorList();
454 
455 signals:
456  void colorChanged(const QColor& newcolor);
457 
458 public slots:
462  void setColor(const QColor& color);
463  void setAllowDefaultState(bool allow);
464  void setDefaultStateString(const QString& str);
465  void setAutoAddToList(bool autoadd) { _autoadd = autoadd; }
466  void setShowSize(const QSize& size) { _size = size; }
467  void setPixXAlignFactor(float xalignfactor) { _xalignfactor = xalignfactor; }
468  void setPixYAlignFactor(float yalignfactor) { _yalignfactor = yalignfactor; }
469  void setAlphaEnabled(bool alpha_enabled);
471  void setDefaultColor();
472 
473  void requestColor();
474 
475 protected slots:
476  void setSenderPropertyColor();
477  void _makemenu();
478 
479 protected:
480  void paintEvent(QPaintEvent *event);
481 
482 private:
483  QColor _color;
484  QPixmap _pix;
485 
486  bool _allowdefaultstate;
487  QString _defaultstatestring;
488  bool _autoadd;
489  QSize _size;
490  float _xalignfactor, _yalignfactor;
491 
492  bool _alphaenabled;
493 
494  QMenu *mMenu;
495 
496  void _setpix();
497 
498  QPixmap colorPixmap(const QColor& color, const QSize& size);
499 
500  static KLFColorList *_colorlist;
501  static QStyle *mReplaceButtonStyle;
502 
503  static int staticUserMaxColors;
504 
505  static void ensureColorListInstance();
506 
507 };
508 
509 
510 #endif
virtual QSize sizeHint()
void setColor(const QColor &col)
float pixYAlignFactor() const
QColor color() const
void setPixYAlignFactor(float yalignfactor)
bool autoAddToList() const
QColor color() const
void setPixXAlignFactor(float xalignfactor)
A pane displaying a gradient of colors, controlling one or two (arbitrary) components of a color...
bool alphaEnabled() const
void setAutoAddToList(bool autoadd)
QString defaultStateString() const
paintEvent(QPaintEvent *event)
contextMenuEvent(QContextMenuEvent *event)
A Spin box editing a component of a color.
mousePressEvent(QMouseEvent *event)
mouseMoveEvent(QMouseEvent *event)
void setShowSize(const QSize &size)
QString colorComponent() const
wheelEvent(QWheelEvent *event)
QString paneType() const
Base utility class that stores and calculates specific components of a color that is being edited...
float pixXAlignFactor() const
bool alphaEnabled() const
TRUE if the user can also select opacity (alpha) with this widget.
bool allowDefaultState() const
Allow the "default color" state.
keyPressEvent(QKeyEvent *event)
A dialog to let the user select a color.

Generated by doxygen 1.8.6