[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klftools/klfcolorchooser.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfcolorchooser.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2011 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
00023 
00024 #ifndef KLFCOLORCHOOSER_H
00025 #define KLFCOLORCHOOSER_H
00026 
00027 #include <QPushButton>
00028 #include <QColor>
00029 #include <QApplication>
00030 #include <QList>
00031 #include <QEvent>
00032 #include <QWidget>
00033 #include <QDialog>
00034 #include <QSpinBox>
00035 #include <QGridLayout>
00036 #include <QPainter>
00037 
00038 #include <klfdefs.h>
00039 
00040 
00041 class KLFColorList;
00042 
00043 
00044 // ------------------------------------------------------------------------------------
00045 
00046 
00047 class KLF_EXPORT KLFColorClickSquare : public QWidget
00048 {
00049   Q_OBJECT
00050 
00051   Q_PROPERTY(QColor color READ color WRITE setColor USER true) ;
00052   Q_PROPERTY(int sqSize READ sqSize WRITE setSqSize) ;
00053   Q_PROPERTY(bool removable READ removable WRITE setRemovable) ;
00054 public:
00055   KLFColorClickSquare(QColor color = Qt::white, int size = 16, bool removable = true, QWidget *parent = 0);
00056   explicit KLFColorClickSquare(QWidget *parent);
00057 
00058   virtual QSize sizeHint() const { return QSize(_size, _size); }
00059 
00060   inline QColor color() const { return _color; }
00061   inline int sqSize() const { return _size; }
00062   inline bool removable() const { return _removable; }
00063   
00064 signals:
00065   void activated();
00066   void colorActivated(const QColor& color);
00067   void wantRemove();
00068   void wantRemoveColor(const QColor& color);
00069 
00070 public slots:
00071   void setColor(const QColor& col) { _color = col; }
00072   void activate() {
00073     emit activated();
00074     emit colorActivated(_color);
00075   }
00076   void setSqSize(int sqsize);
00077   void setRemovable(bool removable);
00078 
00079 protected:
00080   void paintEvent(QPaintEvent *event);
00081   void resizeEvent(QResizeEvent *event);
00082   void keyPressEvent(QKeyEvent *event);
00083   void mousePressEvent(QMouseEvent *event);
00084   void contextMenuEvent(QContextMenuEvent *event);
00085 
00086 private:
00087   QColor _color;
00088   int _size;
00089   bool _removable;
00090 
00091   void initwidget();
00092 
00093 private slots:
00094   void internalWantRemove();
00095 };
00096 
00097 
00098 // ------------------------------------------------------------------------------------
00099 
00143 class KLF_EXPORT KLFColorComponentsEditorBase
00144 {
00145 protected:
00147   int valueAFromNewColor(const QColor& color) const;
00149   int valueBFromNewColor(const QColor& color) const;
00151   inline int valueA() const { return valueAFromNewColor(_color); }
00153   inline int valueB() const { return valueBFromNewColor(_color); }
00155   inline int valueAMax() const { return valueMax(_colorcomponent); }
00157   inline int valueBMax() const { return valueMax(_colorcomponent_b); }
00158 
00175   QColor colorFromValues(QColor color_base, int value_a, int value_b = -1);
00176 
00182   bool refreshColorFromInternalValues(int value_a, int value_b = -1);
00183 
00186   static int valueFromNewColor(const QColor& color, const QString& component);
00187 
00193   static int valueMax(const QString& component);
00194 
00196   QColor _color;
00197 
00200   QString _colorcomponent, _colorcomponent_b;
00201 };
00202 
00203 
00204 // ------------------------------------------------------------------------------------
00205 
00228 class KLF_EXPORT KLFColorComponentSpinBox : public QSpinBox, public KLFColorComponentsEditorBase
00229 {
00230   Q_OBJECT
00231 
00232   Q_PROPERTY(QString colorComponent READ colorComponent WRITE setColorComponent)
00233   Q_PROPERTY(QColor color READ color WRITE setColor USER true)
00234 public:
00235   KLFColorComponentSpinBox(QWidget *parent);
00236   virtual ~KLFColorComponentSpinBox() { }
00237 
00238   QString colorComponent() const { return _colorcomponent; }
00239   QColor color() const { return _color; }
00240 
00241 signals:
00242   void colorChanged(const QColor& color);
00243 
00244 public slots:
00245   void setColorComponent(const QString& component);
00246   void setColor(const QColor& color);
00247 
00248 private slots:
00249   void internalChanged(int newvalue);
00250 
00251 };
00252 
00253 
00254 // ------------------------------------------------------------------------------------
00255 
00274 class KLF_EXPORT KLFColorChooseWidgetPane : public QWidget, public KLFColorComponentsEditorBase
00275 {
00276   Q_OBJECT
00277   Q_PROPERTY(QString paneType READ paneType WRITE setPaneType);
00278   Q_PROPERTY(QColor color READ color WRITE setColor USER true);
00279 public:
00280   KLFColorChooseWidgetPane(QWidget *parent = 0);
00281   virtual ~KLFColorChooseWidgetPane() { }
00282 
00283   QString paneType() const { return _colorcomponent + "+" + _colorcomponent_b; }
00284   QColor color() const { return _color; }
00285 
00286   QSize sizeHint() const;
00287   QSize minimumSizeHint() const;
00288 
00289 signals:
00290   void colorChanged(const QColor& color);
00291 
00292 public slots:
00293   void setColor(const QColor& newcolor);
00294   void setPaneType(const QString& panetype);
00295 
00296 protected:
00297   virtual void paintEvent(QPaintEvent *e);
00298   virtual void mousePressEvent(QMouseEvent *e);
00299   virtual void mouseMoveEvent(QMouseEvent *e);
00300   virtual void wheelEvent(QWheelEvent *e);
00301   virtual void keyPressEvent(QKeyEvent *e);
00302 
00303 private:
00304   QImage _img;
00305 };
00306 
00307 
00308 // ------------------------------------------------------------------------------------
00309 
00310 namespace Ui { class KLFColorChooseWidget; }
00311 class QListWidgetItem;
00312 
00328 class KLF_EXPORT KLFColorChooseWidget : public QWidget
00329 {
00330   Q_OBJECT
00331 
00332   Q_PROPERTY(QColor color READ color WRITE setColor USER true)
00333   Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
00334 public:
00335   KLFColorChooseWidget(QWidget *parent = 0);
00336   virtual ~KLFColorChooseWidget() { }
00337 
00338   QColor color() const { return _color; }
00339 
00340   bool alphaEnabled() const { return _alphaenabled; }
00341 
00342   static void ensureColorListsInstance();
00343   static void setRecentCustomColors(QList<QColor> recentcolors, QList<QColor> customcolors);
00344   static void addRecentColor(const QColor& col);
00345   static QList<QColor> recentColors();
00346   static QList<QColor> customColors();
00347 
00348 signals:
00349   void colorChanged(const QColor& color);
00350 
00351 public slots:
00352   void setColor(const QColor& color);
00353   void setAlphaEnabled(bool alpha_enabled);
00354   void setCurrentToCustomColor();
00355 
00356   void updatePalettes();
00357 
00358   void updatePaletteRecent();
00359   void updatePaletteStandard();
00360   void updatePaletteCustom();
00361 
00362 protected slots:
00363   virtual void internalColorChanged(const QColor& newcolor);
00364   virtual void internalColorNameSelected(QListWidgetItem *item);
00365   virtual void internalColorNameSet(const QString& colorname);
00366 
00367 
00368 private:
00369   Ui::KLFColorChooseWidget *u;
00370 
00371   QColor _color;
00372   bool _alphaenabled;
00373 
00374   QList<QObject*> _connectedColorChoosers;
00375 
00376   void fillPalette(KLFColorList *colorlist, QWidget *w);
00377 
00378   static KLFColorList *_recentcolors;
00379   static KLFColorList *_standardcolors;
00380   static KLFColorList *_customcolors;
00381 };
00382 
00383 
00384 // ------------------------------------------------------------------------------------
00385 
00386 
00387 namespace Ui { class KLFColorDialog; }
00388 
00397 class KLF_EXPORT KLFColorDialog : public QDialog
00398 {
00399   Q_OBJECT
00400 
00401   Q_PROPERTY(QColor color READ color WRITE setColor USER true)
00402 public:
00405   KLFColorDialog(QWidget *parent = 0);
00406   virtual ~KLFColorDialog();
00407 
00409   KLFColorChooseWidget *colorChooseWidget();
00410 
00411   QColor color() const;
00412 
00419   static QColor getColor(QColor startwith = Qt::black, bool alphaenabled = true, QWidget *parent = 0);
00420 
00421 public slots:
00422 
00423   void setColor(const QColor& color);
00424 
00425 private:
00426   Ui::KLFColorDialog *u;
00427 
00428 private slots:
00429   void slotAccepted();
00430 };
00431 
00432 
00433 
00434 
00435 // ------------------------------------------------------------------------------------
00436 
00437 class QStyle;
00438 class KLFRelativeFont;
00439 
00440 class KLF_EXPORT KLFColorChooser : public QPushButton
00441 {
00442   Q_OBJECT
00443 
00444   Q_PROPERTY(QSize showSize READ showSize WRITE setShowSize)
00445   Q_PROPERTY(bool allowDefaultState READ allowDefaultState WRITE setAllowDefaultState)
00446   Q_PROPERTY(QString defaultStateString READ defaultStateString WRITE setDefaultStateString)
00447   Q_PROPERTY(bool autoAddToList READ autoAddToList WRITE setAutoAddToList)
00448   Q_PROPERTY(QColor color READ color WRITE setColor USER true)
00449   Q_PROPERTY(float pixXAlignFactor READ pixXAlignFactor WRITE setPixXAlignFactor)
00450   Q_PROPERTY(float pixYAlignFactor READ pixYAlignFactor WRITE setPixYAlignFactor)
00451   Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled)
00452 
00453 public:
00454   KLFColorChooser(QWidget *parent);
00455   ~KLFColorChooser();
00456 
00457   QSize showSize() const { return _size; }
00459 
00463   bool allowDefaultState() const { return _allowdefaultstate; }
00464   QString defaultStateString() const { return _defaultstatestring; }
00465   bool autoAddToList() const { return _autoadd; }
00466   QColor color() const;
00467   float pixXAlignFactor() const { return _xalignfactor; }
00468   float pixYAlignFactor() const { return _yalignfactor; }
00470   bool alphaEnabled() const { return _alphaenabled; }
00471 
00472   virtual QSize sizeHint() const;
00473 
00476   static void setUserMaxColors(int maxcolors);
00477 
00478   static void setColorList(const QList<QColor>& colorlist);
00479   static QList<QColor> colorList();
00480 
00481 signals:
00482   void colorChanged(const QColor& newcolor);
00483 
00484 public slots:
00488   void setColor(const QColor& color);
00489   void setAllowDefaultState(bool allow);
00490   void setDefaultStateString(const QString& str);
00491   void setAutoAddToList(bool autoadd);
00492   void setShowSize(const QSize& size);
00493   void setPixXAlignFactor(float xalignfactor);
00494   void setPixYAlignFactor(float yalignfactor);
00495   void setAlphaEnabled(bool alpha_enabled);
00497   void setDefaultColor();
00498 
00499   void requestColor();
00500 
00501 protected slots:
00502   void setSenderPropertyColor();
00503   void _makemenu();
00504 
00505 protected:
00506   void paintEvent(QPaintEvent *event);
00507 
00508 private:
00509   QColor _color;
00510   QPixmap _pix;
00511 
00512   bool _allowdefaultstate;
00513   QString _defaultstatestring;
00514   bool _autoadd;
00515   QSize _size;
00516   float _xalignfactor, _yalignfactor;
00517 
00518   bool _alphaenabled;
00519 
00520   QMenu *mMenu;
00521   KLFRelativeFont *menuRelFont;
00522 
00523   void _setpix();
00524 
00525   QPixmap colorPixmap(const QColor& color, const QSize& size);
00526 
00527   static KLFColorList *_colorlist;
00528   static QStyle *mReplaceButtonStyle;
00529 
00530   static int staticUserMaxColors;
00531 
00532   static void ensureColorListInstance();
00533 
00534 };
00535 
00536 
00537 #endif

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net