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

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    Copyright (c) 2011 Martin Koller <kollix@aon.at>
0005    All rights reserved.
0006 
0007    Redistribution and use in source and binary forms, with or without
0008    modification, are permitted provided that the following conditions
0009    are met:
0010 
0011    1. Redistributions of source code must retain the above copyright
0012       notice, this list of conditions and the following disclaimer.
0013    2. Redistributions in binary form must reproduce the above copyright
0014       notice, this list of conditions and the following disclaimer in the
0015       documentation and/or other materials provided with the distribution.
0016 
0017    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0022    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0023    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0024    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0025    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0026    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027 */
0028 
0029 
0030 #ifndef KP_TOOL_TOOL_BAR_H
0031 #define KP_TOOL_TOOL_BAR_H
0032 
0033 
0034 #include <QList>
0035 
0036 #include <KToolBar>
0037 
0038 
0039 class QAbstractButton;
0040 class QBoxLayout;
0041 class QButtonGroup;
0042 class QGridLayout;
0043 class QWidget;
0044 
0045 class kpTool;
0046 class kpToolButton;
0047 
0048 class kpToolWidgetBase;
0049 class kpToolWidgetBrush;
0050 class kpToolWidgetEraserSize;
0051 class kpToolWidgetFillStyle;
0052 class kpToolWidgetLineWidth;
0053 class kpToolWidgetOpaqueOrTransparent;
0054 class kpToolWidgetSpraycanSize;
0055 
0056 class kpToolToolBar : public KToolBar
0057 {
0058 Q_OBJECT
0059 
0060 public:
0061     kpToolToolBar (const QString &name, int colsOrRows, QMainWindow *parent);
0062     ~kpToolToolBar () override;
0063 
0064     void registerTool(kpTool *tool);
0065     void unregisterTool(kpTool *tool);
0066 
0067     kpTool *tool () const;
0068     void selectTool (const kpTool *tool, bool reselectIfSameTool = false);
0069 
0070     kpTool *previousTool () const;
0071     void selectPreviousTool ();
0072 
0073     void hideAllToolWidgets ();
0074     // could this be cleaner (the tools have to access them individually somehow)?
0075     kpToolWidgetBrush *toolWidgetBrush () const { return m_toolWidgetBrush; }
0076     kpToolWidgetEraserSize *toolWidgetEraserSize () const { return m_toolWidgetEraserSize; }
0077     kpToolWidgetFillStyle *toolWidgetFillStyle () const { return m_toolWidgetFillStyle; }
0078     kpToolWidgetLineWidth *toolWidgetLineWidth () const { return m_toolWidgetLineWidth; }
0079     kpToolWidgetOpaqueOrTransparent *toolWidgetOpaqueOrTransparent () const { return m_toolWidgetOpaqueOrTransparent; }
0080     kpToolWidgetSpraycanSize *toolWidgetSpraycanSize () const { return m_toolWidgetSpraycanSize; }
0081 
0082     kpToolWidgetBase *shownToolWidget (int which) const;
0083 
0084 protected:
0085     bool event(QEvent *ev) override;
0086     void paintEvent(QPaintEvent *) override;
0087 
0088 Q_SIGNALS:
0089     void sigToolSelected (kpTool *tool);  // tool may be 0
0090     void toolWidgetOptionSelected ();
0091 
0092 private Q_SLOTS:
0093     void slotToolButtonClicked ();
0094 
0095     void slotToolActionActivated ();
0096 
0097     void adjustToOrientation(Qt::Orientation o);
0098     void slotIconSizeChanged(const QSize &);
0099     void slotToolButtonStyleChanged(Qt::ToolButtonStyle style);
0100 
0101 private:
0102     void addButton (QAbstractButton *button, Qt::Orientation o, int num);
0103     void adjustSizeConstraint();
0104 
0105     int m_vertCols;
0106 
0107     QButtonGroup *m_buttonGroup;
0108     QWidget *m_baseWidget;
0109     QBoxLayout *m_baseLayout;
0110     QGridLayout *m_toolLayout;
0111 
0112     kpToolWidgetBrush *m_toolWidgetBrush;
0113     kpToolWidgetEraserSize *m_toolWidgetEraserSize;
0114     kpToolWidgetFillStyle *m_toolWidgetFillStyle;
0115     kpToolWidgetLineWidth *m_toolWidgetLineWidth;
0116     kpToolWidgetOpaqueOrTransparent *m_toolWidgetOpaqueOrTransparent;
0117     kpToolWidgetSpraycanSize *m_toolWidgetSpraycanSize;
0118 
0119     QList<kpToolWidgetBase *> m_toolWidgets;
0120 
0121     QList<kpToolButton *> m_toolButtons;
0122 
0123     kpTool *m_previousTool, *m_currentTool;
0124 };
0125 
0126 
0127 #endif  // KP_TOOL_TOOL_BAR_H