• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kremotecontrol

  • sources
  • kde-4.12
  • kdeutils
  • kremotecontrol
  • kcmremotecontrol
editkeypressaction.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Michael Zanetti <mzanetti@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 
20 #include "editkeypressaction.h"
21 
22 EditKeypressAction::EditKeypressAction(KeypressAction *action, QWidget* parent, Qt::WFlags flags): QWidget(parent, flags) {
23  m_action = action;
24  ui.setupUi(this);
25  ui.pbAdd->setIcon(KIcon( QLatin1String( "list-add" )));
26  ui.pbRemove->setIcon(KIcon( QLatin1String( "list-remove" )));
27  ui.pbUp->setIcon(KIcon( QLatin1String( "arrow-up" )));
28  ui.pbDown->setIcon(KIcon( QLatin1String( "arrow-down" )));
29 
30  m_model = new KeySequenceListModel(this);
31  m_model->setList(action->keySequenceList());
32  ui.listView->setModel(m_model);
33 
34  ui.cbRepeat->setChecked(m_action->repeat());
35 
36  ui.keySequenceWidget->setCheckForConflictsAgainst(0);
37  ui.keySequenceWidget->setModifierlessAllowed(true);
38  ui.keySequenceWidget->setClearButtonShown(false);
39 
40  connect(ui.keySequenceWidget, SIGNAL(keySequenceChanged(QKeySequence)), SLOT(setKeySequence(QKeySequence)));
41  connect(ui.pbAdd, SIGNAL(clicked()), SLOT(keySequenceChanged()));
42  connect(ui.pbRemove, SIGNAL(clicked()), SLOT(keySequenceChanged()));
43  connect(ui.leKeySequence, SIGNAL(textChanged(QString)), SLOT(activateButtons()));
44  connect(ui.listView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(activateButtons()));
45 
46  activateButtons();
47 }
48 
49 EditKeypressAction::~EditKeypressAction() {
50 }
51 
52 bool EditKeypressAction::checkForComplete() const {
53  return ui.listView->model()->rowCount() > 0;
54 }
55 
56 void EditKeypressAction::applyChanges(){
57  m_action->setKeySequenceList(m_model->keySeqenceList());
58  m_action->setRepeat(ui.cbRepeat->isChecked());
59 }
60 
61 KeypressAction EditKeypressAction::action() const {
62  KeypressAction action;
63  action.setKeySequenceList(m_model->keySeqenceList());
64  action.setRepeat(ui.cbRepeat->isChecked());
65  return action;
66 }
67 
68 void EditKeypressAction::keySequenceChanged() {
69  activateButtons();
70  emit formComplete(!m_model->keySeqenceList().isEmpty());
71 }
72 
73 void EditKeypressAction::setKeySequence(const QKeySequence &seq) {
74  if(seq.isEmpty()) {
75  return;
76  }
77  ui.leKeySequence->setText(seq.toString(QKeySequence::NativeText));
78  ui.keySequenceWidget->clearKeySequence();
79 }
80 
81 KeySequenceItem::KeySequenceItem(const QKeySequence &seq) {
82  m_sequence = seq;
83 }
84 
85 void EditKeypressAction::on_pbAdd_clicked() {
86  m_model->appendRow(new KeySequenceItem(QKeySequence(ui.leKeySequence->text(), QKeySequence::NativeText)));
87  ui.leKeySequence->clear();
88 }
89 
90 void EditKeypressAction::on_pbRemove_clicked() {
91  int index = ui.listView->selectionModel()->currentIndex().row();
92  m_model->removeRow(index);
93 }
94 
95 void EditKeypressAction::on_pbUp_clicked() {
96  QModelIndex index = ui.listView->selectionModel()->currentIndex();
97  QKeySequence seq = m_model->data(index, Qt::UserRole).value<QKeySequence>();
98  m_model->removeRow(index.row());
99  m_model->insertRow(index.row() - 1, new KeySequenceItem(seq));
100  ui.listView->selectionModel()->setCurrentIndex(m_model->index(index.row() - 1, 0), QItemSelectionModel::ClearAndSelect);
101 }
102 
103 void EditKeypressAction::on_pbDown_clicked() {
104  QModelIndex index = ui.listView->selectionModel()->currentIndex();
105  QKeySequence seq = m_model->data(index, Qt::UserRole).value<QKeySequence>();
106  m_model->removeRow(index.row());
107  m_model->insertRow(index.row() + 1, new KeySequenceItem(seq));
108  ui.listView->selectionModel()->setCurrentIndex(m_model->index(index.row() + 1, 0), QItemSelectionModel::ClearAndSelect);
109 }
110 
111 void EditKeypressAction::activateButtons() {
112  QModelIndex index = ui.listView->selectionModel()->currentIndex();
113  ui.pbAdd->setEnabled(!QKeySequence(ui.leKeySequence->text(), QKeySequence::NativeText).isEmpty());
114  ui.pbRemove->setEnabled(index.isValid());
115  ui.pbUp->setEnabled(index.row() > 0);
116  ui.pbDown->setEnabled(index.isValid() && (index.row() + 1 < m_model->rowCount()));
117 }
118 
119 QVariant KeySequenceItem::data(int role) const {
120  if(role == Qt::DisplayRole) {
121  return m_sequence.toString(QKeySequence::PortableText);
122  }
123  if(role == Qt::UserRole) {
124  return m_sequence;
125  }
126  return QStandardItem::data(role);
127 }
128 
129 KeySequenceListModel::KeySequenceListModel(QObject *parent):
130  QStandardItemModel(parent)
131 {
132 
133 }
134 
135 void KeySequenceListModel::setList(QList<QKeySequence> list) {
136  foreach(const QKeySequence &seq, list) {
137  insertRow(rowCount(), new KeySequenceItem(seq));
138  }
139 }
140 
141 QList<QKeySequence> KeySequenceListModel::keySeqenceList() {
142  QList<QKeySequence> ret;
143  for(int i = 0; i < rowCount(); ++i) {
144  ret.append(item(i)->data(Qt::UserRole).value<QKeySequence>());
145  }
146  return ret;
147 }
KeySequenceItem::data
virtual QVariant data(int role=Qt::UserRole+1) const
Definition: editkeypressaction.cpp:119
EditKeypressAction::action
KeypressAction action() const
Definition: editkeypressaction.cpp:61
QWidget
KeySequenceListModel::keySeqenceList
QList< QKeySequence > keySeqenceList()
Definition: editkeypressaction.cpp:141
QStandardItemModel
KeypressAction
Definition: keypressaction.h:27
QObject
EditKeypressAction::formComplete
void formComplete(bool complete)
KeySequenceListModel
Definition: editkeypressaction.h:72
EditKeypressAction::checkForComplete
bool checkForComplete() const
Definition: editkeypressaction.cpp:52
Action::setRepeat
void setRepeat(bool repeat)
Definition: action.cpp:49
EditKeypressAction::EditKeypressAction
EditKeypressAction(KeypressAction *action, QWidget *parent=0, Qt::WFlags flags=0)
Definition: editkeypressaction.cpp:22
EditKeypressAction::applyChanges
void applyChanges()
Definition: editkeypressaction.cpp:56
EditKeypressAction::~EditKeypressAction
~EditKeypressAction()
Definition: editkeypressaction.cpp:49
KeySequenceItem::KeySequenceItem
KeySequenceItem(const QKeySequence &seq)
Definition: editkeypressaction.cpp:81
editkeypressaction.h
KeySequenceListModel::KeySequenceListModel
KeySequenceListModel(QObject *parent=0)
Definition: editkeypressaction.cpp:129
Action::repeat
bool repeat() const
Definition: action.cpp:45
KeySequenceItem
Definition: editkeypressaction.h:62
KeypressAction::setKeySequenceList
void setKeySequenceList(const QList< QKeySequence > &keySequenceList)
Definition: keypressaction.cpp:72
KeySequenceListModel::setList
void setList(QList< QKeySequence > list)
Definition: editkeypressaction.cpp:135
KeypressAction::keySequenceList
QList< QKeySequence > keySequenceList() const
Definition: keypressaction.cpp:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kremotecontrol

Skip menu "kremotecontrol"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal