OSDN Git Service

kcolorchooser: drop it
[kde/kde-extraapps.git] / kmix / gui / viewbase.h
1 //-*-C++-*-
2 /*
3  * KMix -- KDE's full featured mini mixer
4  *
5  * Copyright Christian Esken <esken@kde.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (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 GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this program; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21 #ifndef ViewBase_h
22 #define ViewBase_h
23
24 // QT
25 #include <QWidget>
26 #include <QList>
27 #include <QPushButton>
28
29 // KDE
30 #include <KActionCollection>
31 class KIcon;
32 class KMenu;
33
34 class Mixer;
35 class MixDevice;
36
37 // KMix
38 #include "core/mixdevice.h"
39 #include "core/mixset.h"
40 #include "gui/guiprofile.h"
41 #include "gui/mixdevicewidget.h"
42
43 /**
44   * The ViewBase is a virtual base class, to be used for subclassing the real Mixer Views.
45   */
46 class ViewBase : public QWidget
47 {
48     Q_OBJECT
49
50 friend class KMixToolBox;  // the toolbox is everybodys friend :-)
51
52 public:
53
54    typedef uint ViewFlags;
55    enum ViewFlagsEnum {
56       // Regular flags
57       HasMenuBar     = 0x0001,
58       MenuBarVisible = 0x0002,
59       Horizontal     = 0x0004,
60       Vertical       = 0x0008
61    };
62    
63    typedef uint GUIComplexity;
64    enum
65    {
66      SIMPLE = 0,
67      EXTENDED = 1,
68      ALL = 2
69    };
70    
71     ViewBase(QWidget* parent, QString id, Qt::WFlags, ViewFlags vflags, QString guiProfileId, KActionCollection* actionCollection = 0);
72     virtual ~ViewBase();
73
74     void addMixer(Mixer *mixer);
75     
76     QString id() const;
77
78     // This method is called by ViewBase at the end of createDeviceWidgets(). The default
79     // implementation does nothing. Subclasses can override this method for doing final
80     // touches. This is very much like polish(), but called at an exactly well-known time.
81     // Also I do not want Views to interfere with polish()
82     virtual void constructionFinished() = 0;
83
84     /**
85      * Creates a suitable representation for the given MixDevice.
86      */
87     virtual QWidget* add(std::shared_ptr<MixDevice>) = 0;
88
89     // This method is called after a configuration update (show/hide controls, split/unsplit).
90     virtual void configurationUpdate() = 0;
91
92     void load(KConfig *config);
93     void save(KConfig *config);
94
95     /**
96      * Creates the widgets for all supported devices. The default implementation loops
97      * over the supported MixDevice's and calls add() for each of it.
98      */
99     virtual void createDeviceWidgets();
100
101     int visibleControls();
102     
103     bool isDynamic() const;
104
105     /**
106      * Popup stuff
107      */
108     virtual KMenu* getPopup();
109     virtual void popupReset();
110     virtual void showContextMenu();
111
112     virtual bool isValid() const;
113
114    void setIcons(bool on);
115    void setLabels(bool on);
116    void setTicks(bool on);
117    
118    GUIProfile* guiProfile() { return GUIProfile::find(_guiProfileId); };
119    GUIComplexity getGuiComplexity() { return guiComplexity; };
120    ProfControl* findMdw(const QString& id);
121    ProfControl* findMdw(const QString& mdwId, QString requestedGuiComplexityName);
122
123    
124    KActionCollection* actionCollection() { return _actions; };
125
126    QList<Mixer*>& getMixers() { return _mixers; };
127
128     /**
129      * Contains the widgets for the _mixSet. There is a 1:1 relationship, which means:
130      * _mdws[i] is the Widget for the MixDevice _mixSet[i] - please see ViewBase::createDeviceWidgets().
131      * Hint: !! The new ViewSurround class shows that a 1:1 relationship does not work in a general scenario.
132      *       I actually DID expect this. The solution is unclear yet, probably there will be a virtual mapper method.
133      */
134     QList<QWidget *> _mdws;
135
136 protected:
137     MixSet _mixSet;
138     QList<Mixer*> _mixers;
139     KMenu *_popMenu;
140     KActionCollection* _actions; // -<- application wide action collection
141
142     ViewFlags _vflags;
143     const QString _guiProfileId;
144     KActionCollection *_localActionColletion;
145
146     KIcon* configureIcon;
147
148     virtual void _setMixSet() = 0;
149     void resetMdws();
150     void updateGuiOptions();
151     QPushButton* createConfigureViewButton();
152
153     GUIComplexity guiComplexity;
154
155 public slots:
156    virtual void refreshVolumeLevels(); // TODO remove
157    virtual void configureView();
158    void toggleMenuBarSlot();
159
160 protected slots:
161    void mousePressEvent( QMouseEvent *e );
162
163 signals:
164    void toggleMenuBar();
165
166 private:
167    QString      m_viewId;
168    void updateMediaPlaybackIcons();
169
170 private slots:
171    void guiVisibilitySlot(MixDeviceWidget* source, bool enable);
172
173 };
174
175 #endif
176