File indexing completed on 2024-05-19 04:23:11

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #ifndef KP_COLOR_TOOLBAR_H
0030 #define KP_COLOR_TOOLBAR_H
0031 
0032 
0033 #include <QDockWidget>
0034 #include <QCloseEvent>
0035 
0036 #include "imagelib/kpColor.h"
0037 
0038 
0039 class QBoxLayout;
0040 
0041 class kpColorCells;
0042 class kpColorPalette;
0043 class kpColorSimilarityToolBarItem;
0044 class kpDualColorButton;
0045 
0046 
0047 // COMPAT: Vertical orientation and undocking were broken by the Qt4 port
0048 //         so kpMainWindow::init() keeps this tool bar in a constant position for
0049 //         the time being.  To help make this workaround possible, we use QDockWidget,
0050 //         instead of KToolBar, to prevent XMLGUI from managing the tool
0051 //         bar position.  This also allows us to use QMainWindow::setCorner().
0052 //
0053 //         A nice must-have side-effect is that we are now resizeable, which
0054 //         is good for configurable (and potentially large) color collections.
0055 //         So we should probably keep it as a QDockWidget in the long-term
0056 //         and once we fix orientation and undocking, we should put XMLGUI
0057 //         support back in, somehow (create a "KDockWidget" class?).
0058 class kpColorToolBar : public QDockWidget
0059 {
0060 Q_OBJECT
0061 
0062 public:
0063     kpColorToolBar (const QString &label, QWidget *parent);
0064 
0065     kpColorCells *colorCells () const;
0066 
0067     kpColor color (int which) const;
0068     void setColor (int which, const kpColor &color);
0069 
0070     kpColor foregroundColor () const;
0071     kpColor backgroundColor () const;
0072 
0073     double colorSimilarity () const;
0074     void setColorSimilarity (double similarity);
0075     int processedColorSimilarity () const;
0076 
0077     void openColorSimilarityDialog ();
0078     void flashColorSimilarityToolBarItem ();
0079 
0080 Q_SIGNALS:
0081     // If you connect to this signal, ignore the following
0082     // foregroundColorChanged() and backgroundColorChanged() signals
0083     void colorsSwapped (const kpColor &newForegroundColor,
0084                         const kpColor &newBackgroundColor);
0085 
0086     void foregroundColorChanged (const kpColor &color);
0087     void backgroundColorChanged (const kpColor &color);
0088     void colorSimilarityChanged (double similarity, int processedSimilarity);
0089 
0090 public:
0091     // (only valid in slots connected to foregroundColorChanged())
0092     kpColor oldForegroundColor () const;
0093     // (only valid in slots connected to backgroundColorChanged())
0094     kpColor oldBackgroundColor () const;
0095 
0096     // (only valid in slots connected to colorSimilarityChanged())
0097     double oldColorSimilarity () const;
0098 
0099     QList<QAction *> customContextMenuActions() const;
0100     void setCustomContextMenuActions(QList<QAction *> customContextMenuActions);
0101 
0102 public Q_SLOTS:
0103     void setForegroundColor (const kpColor &color);
0104     void setBackgroundColor (const kpColor &color);
0105 
0106 private Q_SLOTS:
0107     void updateNameOrUrlLabel ();
0108 
0109 protected:
0110     // Eat color drops (which are usually accidental drags from one of our
0111     // child widgets) to prevent them from being pasted as text in the
0112     // main window (by kpMainWindow::dropEvent()).
0113     void dragEnterEvent (QDragEnterEvent *e) override;
0114     void dragMoveEvent (QDragMoveEvent *e) override;
0115 
0116     void closeEvent(QCloseEvent *event) override { event->ignore(); }
0117     void contextMenuEvent(QContextMenuEvent *event) override;
0118 
0119 private:
0120     void adjustToOrientation (Qt::Orientation o);
0121     bool isLocked() const;
0122     void setLocked(bool lock);
0123 
0124     QBoxLayout *m_boxLayout;
0125     QList<QAction *> m_customContextMenuActions;
0126     kpDualColorButton *m_dualColorButton;
0127     kpColorPalette *m_colorPalette;
0128     kpColorSimilarityToolBarItem *m_colorSimilarityToolBarItem;
0129     bool m_locked = true;
0130 };
0131 
0132 
0133 #endif  // KP_COLOR_TOOLBAR_H