File indexing completed on 2024-12-08 11:07:08
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef CIWIDGETMGR_H 0012 #define CIWIDGETMGR_H 0013 0014 #include <QIcon> 0015 #include <QMap> 0016 #include <QString> 0017 0018 #include "eventinfo.h" 0019 0020 class Button; 0021 class CNItem; 0022 class Slider; 0023 class KtlQCanvas; 0024 class Widget; 0025 0026 typedef QMap<QString, Widget *> WidgetMap; 0027 0028 /** 0029 This class handles the widgets (those things associated with CNItems that use QWidgets. 0030 This class is pretty much to maintain a tidy interface: the functions could just as well be 0031 all shoved in CNItem, but that gets messy. 0032 @author David Saxton 0033 */ 0034 class CIWidgetMgr 0035 { 0036 public: 0037 CIWidgetMgr(KtlQCanvas *canvas, CNItem *item); 0038 virtual ~CIWidgetMgr(); 0039 0040 /** 0041 * Set the top-left position from which mouse events are interpreted and the 0042 * widgets are drawn from. 0043 */ 0044 void setWidgetsPos(const QPoint &pos); 0045 /** 0046 * Returns a pointer to the widget with the given id, or nullptr if no such 0047 * widgets are found. 0048 */ 0049 Widget *widgetWithID(const QString &id) const; 0050 Button *button(const QString &id) const; 0051 Slider *slider(const QString &id) const; 0052 void setButtonState(const QString &id, int state); 0053 /** 0054 * Adds a slider with the given id and values to the position 0055 */ 0056 Slider *addSlider(const QString &id, int minValue, int maxValue, int pageStep, int value, Qt::Orientation orientation, const QRect &pos); 0057 /** 0058 * Essentially the same as addDisplayText, but displays a button with 0059 * text on it. The virtual functions buttonPressed( const QString &id ) and 0060 * buttonReleased( const QString &id ) are called as appropriate with button id 0061 */ 0062 Button *addButton(const QString &id, const QRect &pos, const QString &display, bool toggle = false); 0063 /** 0064 * Adds a button with a QIcon icon on it instead of text 0065 * @see void addButton( const QString &id, QRect pos, const QString &display ) 0066 */ 0067 Button *addButton(const QString &id, const QRect &pos, const QIcon &icon, bool toggle = false); 0068 /** 0069 * Removes the widget with the given id. 0070 */ 0071 void removeWidget(const QString &id); 0072 /** 0073 * Sets whether or not to draw the widgets (drawing widgets mucks up SVG 0074 * export). This function just calls either hide() or show() in each widget. 0075 */ 0076 void setDrawWidgets(bool draw); 0077 0078 bool mousePressEvent(const EventInfo &info); 0079 bool mouseReleaseEvent(const EventInfo &info); 0080 bool mouseDoubleClickEvent(const EventInfo &info); 0081 bool mouseMoveEvent(const EventInfo &info); 0082 bool wheelEvent(const EventInfo &info); 0083 void enterEvent(QEvent *); 0084 void leaveEvent(QEvent *); 0085 0086 virtual void buttonStateChanged(const QString & /*id*/, bool /*on*/) {}; 0087 virtual void sliderValueChanged(const QString & /*id*/, int /*value*/) {}; 0088 0089 int mgrX() const 0090 { 0091 return m_pos.x(); 0092 } 0093 int mgrY() const 0094 { 0095 return m_pos.y(); 0096 } 0097 /** 0098 * Draw the widgets using the given painter. This function isn't actually 0099 * used to draw the widgets on the canvas, as they are QCanvasItems 0100 * themselves, but allows other classes (e.g. ItemLibrary) to draw them 0101 * using a special painter. 0102 */ 0103 void drawWidgets(QPainter &p); 0104 0105 protected: 0106 WidgetMap m_widgetMap; 0107 QPoint m_pos; 0108 KtlQCanvas *p_canvas; 0109 CNItem *p_cnItem; 0110 }; 0111 0112 #endif