This repository has been archived by the owner on Aug 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,335 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
R3 Clear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
/* | ||
* Imp: Copyright 2016, 2017 Jesse Litton ([email protected]) | ||
* | ||
* This file is part of Imp. | ||
* | ||
* Imp is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Imp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Imp. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <QComboBox> | ||
#include "alarmmodel.h" | ||
|
||
AlarmModel::AlarmModel(QObject *parent) | ||
: QAbstractTableModel(parent) | ||
{ | ||
} | ||
|
||
QVariant AlarmModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
{ | ||
if (role == Qt::DisplayRole) | ||
{ | ||
if (orientation == Qt::Horizontal) { | ||
switch (section) | ||
{ | ||
case 0: | ||
return QString("Jumps"); | ||
case 1: | ||
return QString("Alarm"); | ||
case 2: | ||
return QString("Volume"); | ||
case 3: | ||
return QString("Play"); | ||
} | ||
} | ||
else | ||
{ | ||
return section + 1; | ||
} | ||
} | ||
return QVariant(); | ||
} | ||
|
||
int AlarmModel::rowCount(const QModelIndex& /*&parent*/) const | ||
{ | ||
return alarms.count(); | ||
} | ||
|
||
int AlarmModel::columnCount(const QModelIndex& /*&parent*/) const | ||
{ | ||
return 4; | ||
} | ||
|
||
QVariant AlarmModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid()) | ||
return QVariant(); | ||
|
||
switch(role) | ||
{ | ||
case Qt::TextAlignmentRole: | ||
switch(index.column()) | ||
{ | ||
case 0: | ||
return Qt::AlignRight; | ||
default: | ||
return Qt::AlignHCenter; | ||
} | ||
break; | ||
|
||
case Qt::DisplayRole: | ||
case Qt::EditRole: | ||
if (index.row() < alarms.count()) | ||
{ | ||
switch (index.column()) | ||
{ | ||
case 0: | ||
return alarms[index.row()].jumps; | ||
case 1: | ||
return alarms[index.row()].file; | ||
case 2: | ||
return alarms[index.row()].volume; | ||
default: | ||
break; | ||
} | ||
} | ||
break; | ||
|
||
case Qt::CheckStateRole: | ||
if (index.row() < alarms.count()) | ||
{ | ||
switch (index.column()) | ||
{ | ||
default: | ||
break; | ||
} | ||
} | ||
break; | ||
|
||
case Qt::ToolTipRole: | ||
switch (index.column()) | ||
{ | ||
case 0: | ||
return QString("Number of jumps away"); | ||
case 1: | ||
return QString("Sound file to play on alarm"); | ||
case 2: | ||
return QString("Volume level of the alarm"); | ||
case 3: | ||
return QString("Test the sound/volume"); | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
bool AlarmModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
{ | ||
if (role == Qt::EditRole) | ||
{ | ||
switch (index.column()) | ||
{ | ||
case 0: | ||
alarms[index.row()].jumps = value.toInt(); | ||
break; | ||
case 1: | ||
alarms[index.row()].file = value.toString(); | ||
break; | ||
case 2: | ||
alarms[index.row()].volume = value.toFloat(); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
emit dataChanged(index, index, QVector<int>() << role); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
Qt::ItemFlags AlarmModel::flags(const QModelIndex &index) const | ||
{ | ||
if (!index.isValid()) | ||
return Qt::NoItemFlags; | ||
|
||
if (index.column() == 0 || index.column() == 3) | ||
{ | ||
return Qt::ItemIsEnabled | QAbstractTableModel::flags(index); | ||
} | ||
else | ||
{ | ||
return Qt::ItemIsEditable | QAbstractTableModel::flags(index); | ||
} | ||
} | ||
|
||
bool AlarmModel::insertRows(int row, int count, const QModelIndex &parent) | ||
{ | ||
if(row < 0) | ||
row = alarms.count(); | ||
|
||
beginInsertRows(parent, row, row + count - 1); | ||
|
||
alarms.insert(row, Alarm{(uint)row, "red-alert.wav", 1.0}); | ||
for(int i = 0; i < alarms.count(); i++) | ||
{ | ||
alarms[i].jumps = i; | ||
} | ||
|
||
endInsertRows(); | ||
return true; | ||
} | ||
|
||
bool AlarmModel::removeRows(int row, int count, const QModelIndex &parent) | ||
{ | ||
if(row < 0) | ||
row = alarms.count() - 1; | ||
|
||
beginRemoveRows(parent, row, row + count - 1); | ||
if(row == 0 && count == alarms.count()) | ||
{ | ||
alarms.clear(); | ||
} | ||
else | ||
{ | ||
for(int i = 0; i < count; i++) | ||
{ | ||
alarms.removeAt(row); | ||
} | ||
} | ||
|
||
for(int i = 0; i < alarms.count(); i++) | ||
{ | ||
alarms[i].jumps = i; | ||
} | ||
|
||
endRemoveRows(); | ||
|
||
return true; | ||
} | ||
|
||
void AlarmModel::insertAlarm(QString filename, float volume) | ||
{ | ||
beginInsertRows(QModelIndex(), alarms.count(), alarms.count()); | ||
|
||
alarms.insert(alarms.count(), Alarm{(uint)alarms.count(), filename, volume}); | ||
|
||
endInsertRows(); | ||
} | ||
|
||
QList<Alarm> AlarmModel::getAlarms() | ||
{ | ||
return alarms; | ||
} | ||
|
||
void AlarmModel::setAlarms(QList<Alarm> newAlarms) | ||
{ | ||
if(newAlarms.count() <= 0) | ||
return; | ||
|
||
beginRemoveRows(QModelIndex(), 0, alarms.count()-1); | ||
alarms.clear(); | ||
endRemoveRows(); | ||
beginInsertRows(QModelIndex(), 0, newAlarms.count()-1); | ||
alarms = newAlarms; | ||
endInsertRows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Imp: Copyright 2016, 2017 Jesse Litton ([email protected]) | ||
* | ||
* This file is part of Imp. | ||
* | ||
* Imp is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Imp is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Imp. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef ALARMMODEL_H | ||
#define ALARMMODEL_H | ||
|
||
#include <QComboBox> | ||
#include <QAbstractTableModel> | ||
|
||
struct Alarm | ||
{ | ||
uint jumps; | ||
QString file; | ||
float volume; | ||
}; | ||
|
||
class AlarmModel : public QAbstractTableModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit AlarmModel(QObject *parent = 0); | ||
|
||
const Alarm& at(int distance) {return alarms[distance];} | ||
int count() {return alarms.count();} | ||
|
||
// Header: | ||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | ||
|
||
// Basic functionality: | ||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||
|
||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
|
||
// Editable: | ||
bool setData(const QModelIndex &index, const QVariant &value, | ||
int role = Qt::EditRole) override; | ||
|
||
Qt::ItemFlags flags(const QModelIndex& index) const override; | ||
|
||
// Add data: | ||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; | ||
|
||
// Remove data: | ||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; | ||
|
||
void insertAlarm(QString filename, float volume); | ||
//void removeAlarm(const QModelIndexList indexList); | ||
QList<Alarm> getAlarms(); | ||
void setAlarms(QList<Alarm> newAlarms); | ||
|
||
QList<QComboBox> alarmCombos; | ||
|
||
private: | ||
QList<Alarm> alarms; | ||
}; | ||
|
||
#endif // AlarmModel_H |
Oops, something went wrong.