-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcuts.cpp
150 lines (112 loc) · 4.66 KB
/
shortcuts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/******************************************************************************
* Cleps Video Player. Simply a media player, no more, no less. *
* Copyright (C) 2014 Eshton Robateau <eshtonrob@gmail.com> *
* *
* This program 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. *
* *
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************/
#include "shortcuts.h"
shortcuts::shortcuts(QWidget *parent) :
QWidget(parent)
{
model = new QStandardItemModel(5,3);
model->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Default Shortcut") << tr("Active Shortcut"));
data << tr("Play/Pause") << tr("Space") << tr("Next Media") << tr("N") << tr("Mute") << tr("M");
data << tr("Stop")<< tr("S") << tr("Previous Media") << tr("P");
defaultData();
scutTable = new QTableView(this);
scutTable->setModel(model);
scutTable->setSelectionMode(QAbstractItemView::SingleSelection);
scutTable->verticalHeader()->setVisible(false);
scutTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
scutTable->horizontalHeader()->setStretchLastSection(true);
scutTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
scutTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
scutTable->setAlternatingRowColors(true);
scutTable->setShowGrid(false);
QLabel *lbld = new QLabel(tr("<b>Media Shortcuts</b>"));
QPushButton *setNewCut = new QPushButton(tr("Change ShortCut"));
QPushButton *reset = new QPushButton(tr("Reset"));
QBoxLayout *hLay = new QHBoxLayout;
hLay->addStretch(1);
hLay->addWidget(setNewCut);
hLay->addWidget(reset);
QBoxLayout *vlay = new QVBoxLayout;
vlay->addWidget(lbld);
vlay->addWidget(scutTable);
vlay->addLayout(hLay);
setLayout(vlay);
connect(setNewCut,SIGNAL(clicked()),this,SLOT(keySequenceInput()));
connect(reset,SIGNAL(clicked()),this,SLOT(resetData()));
}
void shortcuts::defaultData()
{
QStringListIterator javaStyleIterator(data);
for(int row=0; row<5;++row){
for (int column = 0; column<2; ++column){
QStandardItem *item = new QStandardItem(javaStyleIterator.next());
model->setItem(row, column, item);
}
}
for(int i = 0; i<5;++i){
QStandardItem *item2 = new QStandardItem(QString(tr(" ")));
model->setItem(i, 2, item2);
}
}
void shortcuts::keySequenceInput()
{
QSettings settings;
edit = new shortcutEditor(this);
int row= -1;
QModelIndexList lst = scutTable->selectionModel()->selection().indexes();
if(lst.isEmpty()){
return;
}else{
row = lst.first().row();
edit->exec();
if(!seq.isEmpty()){
model->item(row, 2)->setText(seq.toString());
scutTable->setModel(model);
QString key = model->item(row,0)->text().toLower();
key.simplified();
key.replace(" ", "");
if(key.contains("play")){
settings.setValue("shortcut/play_pause", seq);
}else{
settings.setValue("shortcut/"+ key, seq);
}
}
}
}
void shortcuts::resetData()
{
defaultData();
scutTable->setModel(model);
QSettings settings;
for(int row=0; row<5;++row){
QString key = model->item(row,0)->text().toLower();
key = key.simplified();
key = key.replace(" ", "");
QString value = model->item(row,1)->text().toLower();
if(key.contains("play")){
settings.setValue("shortcut/play_pause", value);
}else{
settings.setValue("shortcut/"+ key, value);
}
}
this->parentWidget()->parentWidget()->close();
}
void shortcuts::readSequence(QKeySequence keySequence)
{
seq=keySequence;
}