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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2387 - (hide annotations) (download)
Sat Dec 29 00:21:11 2012 UTC (11 years, 3 months ago) by capela
File size: 5264 byte(s)
* Preparations for Qt5 migration. (TESTING)
1 schoenebeck 1667 // qsamplerFxSendList.cpp
2     //
3     /****************************************************************************
4 capela 2387 Copyright (C) 2010-2012, rncbc aka Rui Nuno Capela. All rights reserved.
5 schoenebeck 1667 Copyright (C) 2008, Christian Schoenebeck
6    
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 "qsamplerFxSendsModel.h"
25     #include "qsamplerFxSend.h"
26    
27     #include <QBrush>
28     #include <QIcon>
29     #include <QFont>
30    
31     namespace QSampler {
32    
33     FxSendsModel::FxSendsModel(int SamplerChannelID, QObject* pParent) : QAbstractListModel(pParent) {
34     m_SamplerChannelID = SamplerChannelID;
35     cleanRefresh();
36     }
37    
38     int FxSendsModel::rowCount(const QModelIndex& /*parent*/) const {
39     return m_FxSends.size();
40     }
41    
42     QVariant FxSendsModel::data(const QModelIndex& index, int role) const {
43     if (!index.isValid())
44     return QVariant();
45    
46     switch (role) {
47     case Qt::DisplayRole:
48     return m_FxSends[index.row()].name();
49     break;
50     case Qt::ToolTipRole:
51     if (m_FxSends[index.row()].deletion())
52     return QString(
53     "Scheduled for deletion. Click on 'Apply' to actually "
54     "destroy FX Send."
55     );
56     return (m_FxSends[index.row()].isNew()) ?
57     QString(
58     "New FX send. Click on 'Apply' to actually "
59     "perform creation."
60     ) :
61     QString("FX Send ID ") +
62     QString::number(m_FxSends[index.row()].id());
63     break;
64     case Qt::ForegroundRole:
65     if (m_FxSends[index.row()].deletion())
66     return QBrush(Qt::red);
67     if (m_FxSends[index.row()].isNew())
68     return QBrush(Qt::green);
69     break;
70     case Qt::DecorationRole:
71     if (m_FxSends[index.row()].deletion())
72 capela 2074 return QIcon(":/images/formRemove.png");
73 schoenebeck 1667 if (m_FxSends[index.row()].isNew())
74 capela 2074 return QIcon(":/images/itemNew.png");
75 schoenebeck 1667 if (m_FxSends[index.row()].isModified())
76 capela 2074 return QIcon(":/images/formEdit.png");
77     return QIcon(":/images/itemFile.png");
78 schoenebeck 1667 case Qt::FontRole: {
79     if (m_FxSends[index.row()].isModified()) {
80     QFont font;
81     font.setBold(true);
82     return font;
83     }
84     break;
85     }
86     default:
87     return QVariant();
88     }
89     return QVariant();
90     }
91    
92     bool FxSendsModel::setData(
93     const QModelIndex& index, const QVariant& value, int /*role*/)
94     {
95     if (!index.isValid())
96     return false;
97    
98     m_FxSends[index.row()].setName(value.toString());
99     emit dataChanged(index, index);
100     emit fxSendsDirtyChanged(true);
101    
102     return true;
103     }
104    
105     QVariant FxSendsModel::headerData(int section, Qt::Orientation /*orientation*/,
106     int role) const
107     {
108     if (role == Qt::DisplayRole && section == 0)
109     return QString("FX Send Name");
110     else
111     return QVariant();
112     }
113    
114     Qt::ItemFlags FxSendsModel::flags(const QModelIndex& /*index*/) const {
115     return Qt::ItemIsEditable | Qt::ItemIsEnabled;
116     }
117    
118     FxSend* FxSendsModel::addFxSend() {
119     #if CONFIG_FXSEND
120     FxSend fxSend(m_SamplerChannelID);
121     fxSend.setName("New FX Send");
122     m_FxSends.push_back(fxSend);
123     QModelIndex index = createIndex(m_FxSends.size() - 1, 0);
124 capela 2387 #if QT_VERSION < 0x050000
125 schoenebeck 1667 QAbstractListModel::reset();
126 capela 2387 #else
127     QAbstractListModel::beginResetModel();
128     QAbstractListModel::endResetModel();
129     #endif
130 schoenebeck 1667 emit fxSendsDirtyChanged(true);
131     return &m_FxSends.last();
132     #else // CONFIG_FXSEND
133     return NULL;
134     #endif // CONFIG_FXSEND
135     }
136    
137     FxSend* FxSendsModel::fxSend(const QModelIndex& index) {
138     if (!index.isValid())
139     return NULL;
140    
141     return &m_FxSends[index.row()];
142     }
143    
144     void FxSendsModel::removeFxSend(const QModelIndex& index) {
145     FxSend* pFxSend = fxSend(index);
146     if (!pFxSend) return;
147     pFxSend->setDeletion(true);
148 capela 2387 #if QT_VERSION < 0x050000
149 schoenebeck 1667 QAbstractListModel::reset();
150 capela 2387 #else
151     QAbstractListModel::beginResetModel();
152     QAbstractListModel::endResetModel();
153     #endif
154 schoenebeck 1667 emit fxSendsDirtyChanged(true);
155     }
156    
157     void FxSendsModel::cleanRefresh() {
158     m_FxSends.clear();
159     QList<int> sends = FxSend::allFxSendsOfSamplerChannel(m_SamplerChannelID);
160     for (int i = 0; i < sends.size(); ++i) {
161     const int iFxSendId = sends[i];
162     FxSend fxSend(m_SamplerChannelID, iFxSendId);
163     fxSend.getFromSampler();
164     m_FxSends.push_back(fxSend);
165     }
166 capela 2387 #if QT_VERSION < 0x050000
167 schoenebeck 1667 QAbstractListModel::reset();
168 capela 2387 #else
169     QAbstractListModel::beginResetModel();
170     QAbstractListModel::endResetModel();
171     #endif
172 schoenebeck 1667 emit fxSendsDirtyChanged(false);
173     }
174    
175 schoenebeck 1668 void FxSendsModel::onExternalModifiication(const QModelIndex& index) {
176     if (!index.isValid()) return;
177     emit dataChanged(index, index);
178     emit fxSendsDirtyChanged(true);
179     }
180    
181 schoenebeck 1667 void FxSendsModel::applyToSampler() {
182     for (int i = 0; i < m_FxSends.size(); ++i)
183     m_FxSends[i].applyToSampler();
184    
185     // make a clean refresh
186     // (throws out all FxSend objects marked for deletion)
187     cleanRefresh();
188     }
189    
190     } // namespace QSampler
191    
192     // end of qsamplerFxSendList.cpp

  ViewVC Help
Powered by ViewVC