/[svn]/qsampler/trunk/src/qsamplerDeviceStatusForm.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerDeviceStatusForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2042 - (hide annotations) (download)
Fri Jan 8 19:20:37 2010 UTC (10 years, 10 months ago) by capela
File size: 7075 byte(s)
- Fixed DeviceStatusForm compilation for Qt4 < 4.4.

1 schoenebeck 1698 // qsamplerDeviceStatusForm.cpp
2     //
3     /****************************************************************************
4     Copyright (C) 2008, Christian Schoenebeck
5 capela 2038 Copyright (C) 2010, rncbc aka Rui Nuno Capela. All rights reserved.
6 schoenebeck 1698
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     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
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21     *****************************************************************************/
22    
23     #include "qsamplerAbout.h"
24     #include "qsamplerDeviceStatusForm.h"
25 capela 2038
26 schoenebeck 1698 #include "qsamplerMainForm.h"
27    
28     #include <QGridLayout>
29    
30 capela 2042 #if QT_VERSION < 0x040500
31     namespace Qt {
32     const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
33     #if QT_VERSION < 0x040200
34     const WindowFlags CustomizeWindowHint = WindowFlags(0x02000000);
35     #endif
36     }
37     #endif
38 schoenebeck 1698
39 capela 2042
40 schoenebeck 1698 namespace QSampler {
41    
42 schoenebeck 1699 //-------------------------------------------------------------------------
43     // QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
44     //
45    
46 capela 2038 // MIDI activity pixmap common resources.
47     int MidiActivityLED::g_iMidiActivityRefCount = 0;
48     QPixmap *MidiActivityLED::g_pMidiActivityLedOn = NULL;
49     QPixmap *MidiActivityLED::g_pMidiActivityLedOff = NULL;
50    
51    
52     MidiActivityLED::MidiActivityLED ( QString sText, QWidget *pParent )
53     : QLabel(sText, pParent)
54     {
55     if (++g_iMidiActivityRefCount == 1) {
56     g_pMidiActivityLedOn = new QPixmap(":/icons/ledon1.png");
57     g_pMidiActivityLedOff = new QPixmap(":/icons/ledoff1.png");
58     }
59    
60     setPixmap(*g_pMidiActivityLedOff);
61     #ifndef CONFIG_EVENT_DEVICE_MIDI
62     setToolTip("MIDI Activity disabled");
63 schoenebeck 1698 #endif
64 capela 2038 m_timer.setSingleShot(true);
65    
66     QObject::connect(&m_timer,
67     SIGNAL(timeout()),
68     SLOT(midiActivityLedOff())
69 schoenebeck 1698 );
70     }
71    
72 capela 2038 MidiActivityLED::~MidiActivityLED (void)
73     {
74     if (--g_iMidiActivityRefCount == 0) {
75     if (g_pMidiActivityLedOn)
76     delete g_pMidiActivityLedOn;
77     g_pMidiActivityLedOn = NULL;
78     if (g_pMidiActivityLedOff)
79     delete g_pMidiActivityLedOff;
80     g_pMidiActivityLedOff = NULL;
81     }
82 schoenebeck 1698 }
83    
84 capela 2038
85     void MidiActivityLED::midiActivityLedOn (void)
86     {
87     setPixmap(*g_pMidiActivityLedOn);
88     m_timer.start(100);
89 schoenebeck 1698 }
90    
91 capela 2038
92     void MidiActivityLED::midiActivityLedOff (void)
93     {
94     setPixmap(*g_pMidiActivityLedOff);
95     }
96    
97    
98 schoenebeck 1699 //-------------------------------------------------------------------------
99     // QSampler::DeviceStatusForm -- Device status informations window.
100     //
101 schoenebeck 1698
102 capela 2038 std::map<int, DeviceStatusForm *> DeviceStatusForm::g_instances;
103 schoenebeck 1698
104 capela 2038
105 schoenebeck 1698 DeviceStatusForm::DeviceStatusForm (
106 capela 2038 int DeviceID, QWidget *pParent, Qt::WindowFlags wflags )
107     : QWidget(pParent, wflags)
108 schoenebeck 1698 {
109     m_pDevice = new Device(Device::Midi, DeviceID);
110    
111 capela 2038 setLayout(new QGridLayout(/*this*/));
112 schoenebeck 1699 updateGUIPorts(); // build the GUI
113 schoenebeck 1698
114     m_pVisibleAction = new QAction(this);
115     m_pVisibleAction->setCheckable(true);
116     m_pVisibleAction->setChecked(false);
117     m_pVisibleAction->setText(m_pDevice->deviceName());
118     m_pVisibleAction->setToolTip(
119     QString("MIDI Device ID: ") +
120     QString::number(m_pDevice->deviceID())
121     );
122 capela 2038
123     QObject::connect(m_pVisibleAction,
124     SIGNAL(toggled(bool)),
125     SLOT(setVisible(bool))
126 schoenebeck 1698 );
127    
128 capela 2038 setWindowTitle(tr("%1 Status").arg(m_pDevice->deviceName()));
129 schoenebeck 1698 }
130    
131 capela 2038
132     void DeviceStatusForm::updateGUIPorts (void)
133     {
134 schoenebeck 1699 // refresh device informations
135     m_pDevice->setDevice(m_pDevice->deviceType(), m_pDevice->deviceID());
136     DevicePortList ports = m_pDevice->ports();
137    
138     // clear the GUI
139 capela 2038 QGridLayout *pLayout = static_cast<QGridLayout *> (layout());
140 schoenebeck 1699 for (int i = pLayout->count() - 1; i >= 0; --i) {
141 capela 2038 QLayoutItem *pItem = pLayout->itemAt(i);
142     if (pItem) {
143     pLayout->removeItem(pItem);
144     if (pItem->widget())
145     delete pItem->widget();
146     delete pItem;
147     }
148 schoenebeck 1699 }
149    
150 capela 2038 m_midiActivityLEDs.clear();
151    
152 schoenebeck 1699 // rebuild the GUI
153     for (int i = 0; i < ports.size(); ++i) {
154 capela 2038 MidiActivityLED *pLED = new MidiActivityLED();
155     m_midiActivityLEDs.push_back(pLED);
156 capela 2039 pLayout->addWidget(pLED, i, 0);
157     QLabel *pLabel = new QLabel(
158     m_pDevice->deviceTypeName()
159     + ' ' + m_pDevice->driverName()
160     + ' ' + ports[i]->portName());
161     pLayout->addWidget(pLabel, i, 1, Qt::AlignLeft);
162 schoenebeck 1699 }
163     }
164    
165 capela 2038
166     DeviceStatusForm::~DeviceStatusForm (void)
167     {
168 schoenebeck 1698 if (m_pDevice) delete m_pDevice;
169     }
170    
171 capela 2038
172     QAction* DeviceStatusForm::visibleAction (void)
173     {
174 schoenebeck 1698 return m_pVisibleAction;
175     }
176    
177 capela 2038 void DeviceStatusForm::closeEvent ( QCloseEvent *pCloseEvent )
178     {
179 schoenebeck 1698 m_pVisibleAction->setChecked(false);
180 capela 2038
181     pCloseEvent->accept();
182 schoenebeck 1698 }
183    
184 capela 2038
185     void DeviceStatusForm::midiArrived ( int iPort )
186     {
187     if (uint(iPort) >= m_midiActivityLEDs.size())
188     return;
189    
190     m_midiActivityLEDs[iPort]->midiActivityLedOn();
191 schoenebeck 1698 }
192    
193 capela 2038
194     DeviceStatusForm *DeviceStatusForm::getInstance ( int iDeviceID )
195     {
196     std::map<int, DeviceStatusForm *>::iterator iter
197     = g_instances.find(iDeviceID);
198     return ((iter != g_instances.end()) ? iter->second : NULL);
199 schoenebeck 1698 }
200    
201 capela 2038
202     const std::map<int, DeviceStatusForm *>& DeviceStatusForm::getInstances (void)
203     {
204     return g_instances;
205 schoenebeck 1698 }
206    
207 capela 2038 void DeviceStatusForm::deleteAllInstances (void)
208     {
209     std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
210     for ( ; iter != g_instances.end(); ++iter) {
211 schoenebeck 1699 iter->second->hide();
212     delete iter->second;
213     }
214 capela 2038
215     g_instances.clear();
216 schoenebeck 1699 }
217    
218 capela 2038
219     void DeviceStatusForm::onDevicesChanged (void)
220     {
221 schoenebeck 1698 MainForm* pMainForm = MainForm::getInstance();
222     if (pMainForm && pMainForm->client()) {
223 capela 2038 std::set<int> deviceIDs
224     = Device::getDeviceIDs(pMainForm->client(), Device::Midi);
225 schoenebeck 1698 // hide and delete status forms whose device has been destroyed
226 capela 2038 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
227     for ( ; iter != g_instances.end(); ++iter) {
228 schoenebeck 1698 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
229     iter->second->hide();
230     delete iter->second;
231 capela 2038 g_instances.erase(iter);
232 schoenebeck 1698 }
233     }
234     // create status forms for new devices
235 capela 2038 std::set<int>::iterator it = deviceIDs.begin();
236 capela 2039 for ( ; it != deviceIDs.end(); ++it) {
237 capela 2038 if (g_instances.find(*it) == g_instances.end()) {
238     // What style do we create these forms?
239     Qt::WindowFlags wflags = Qt::Window
240     | Qt::CustomizeWindowHint
241     | Qt::WindowTitleHint
242     | Qt::WindowSystemMenuHint
243     | Qt::WindowMinMaxButtonsHint
244     | Qt::WindowCloseButtonHint;
245     Options *pOptions = pMainForm->options();
246     if (pOptions && pOptions->bKeepOnTop)
247     wflags |= Qt::Tool;
248     // Create the form, giving it the device id.
249     DeviceStatusForm *pStatusForm
250     = new DeviceStatusForm(*it, NULL, wflags);
251     g_instances[*it] = pStatusForm;
252 schoenebeck 1698 }
253     }
254     }
255     }
256    
257 capela 2038
258     void DeviceStatusForm::onDeviceChanged ( int iDeviceID )
259     {
260     DeviceStatusForm *pStatusForm
261     = DeviceStatusForm::getInstance(iDeviceID);
262     if (pStatusForm)
263     pStatusForm->updateGUIPorts();
264 schoenebeck 1699 }
265    
266 capela 2038
267 schoenebeck 1698 } // namespace QSampler
268    
269     // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC