ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KbProfileDialog Class Reference

#include <src/ckb/kbprofiledialog.h>

+ Inheritance diagram for KbProfileDialog:
+ Collaboration diagram for KbProfileDialog:

Public Member Functions

 KbProfileDialog (KbWidget *parent=0)
 
 ~KbProfileDialog ()
 

Private Slots

void profileList_reordered ()
 
void on_profileList_currentItemChanged (QListWidgetItem *current, QListWidgetItem *previous)
 
void on_profileList_itemClicked (QListWidgetItem *item)
 
void on_profileList_itemChanged (QListWidgetItem *item)
 
void on_profileList_customContextMenuRequested (const QPoint &pos)
 

Private Member Functions

void repopulate ()
 
void addNewProfileItem ()
 

Private Attributes

Ui::KbProfileDialogui
 
Kbdevice
 

Static Private Attributes

static const int GUID = Qt::UserRole
 
static const int NEW_FLAG = Qt::UserRole + 1
 

Detailed Description

Definition at line 11 of file kbprofiledialog.h.

Constructor & Destructor Documentation

KbProfileDialog::KbProfileDialog ( KbWidget parent = 0)
explicit

Definition at line 5 of file kbprofiledialog.cpp.

References Ui_KbProfileDialog::profileList, profileList_reordered(), repopulate(), Ui_KbProfileDialog::setupUi(), and ui.

5  :
6  QDialog(parent),
7  ui(new Ui::KbProfileDialog), device(parent->device)
8 {
9  ui->setupUi(this);
10  connect(ui->profileList, SIGNAL(orderChanged()), this, SLOT(profileList_reordered()));
11 
12  // Populate profile list
13  repopulate();
14 }
RListWidget * profileList
Ui::KbProfileDialog * ui
void profileList_reordered()
Kb * device
Definition: kbwidget.h:24
void setupUi(QDialog *KbProfileDialog)

+ Here is the call graph for this function:

KbProfileDialog::~KbProfileDialog ( )

Definition at line 16 of file kbprofiledialog.cpp.

References ui.

16  {
17  delete ui;
18 }
Ui::KbProfileDialog * ui

Member Function Documentation

void KbProfileDialog::addNewProfileItem ( )
private

Definition at line 66 of file kbprofiledialog.cpp.

References NEW_FLAG, Ui_KbProfileDialog::profileList, and ui.

Referenced by on_profileList_itemClicked(), and repopulate().

66  {
67  // Add an item for creating a new profile. Make it editable but not dragable.
68  QListWidgetItem* item = new QListWidgetItem("New profile...", ui->profileList);
69  item->setFlags((item->flags() | Qt::ItemIsEditable) & ~Qt::ItemIsDragEnabled & ~Qt::ItemIsDropEnabled);
70  item->setData(NEW_FLAG, 1);
71  QFont font = item->font();
72  font.setItalic(true);
73  item->setFont(font);
74  item->setIcon(QIcon(":/img/icon_plus.png"));
75  ui->profileList->addItem(item);
76 }
RListWidget * profileList
Ui::KbProfileDialog * ui
static const int NEW_FLAG

+ Here is the caller graph for this function:

void KbProfileDialog::on_profileList_currentItemChanged ( QListWidgetItem *  current,
QListWidgetItem *  previous 
)
privateslot

Definition at line 39 of file kbprofiledialog.cpp.

References device, Kb::find(), GUID, and Kb::setCurrentProfile().

39  {
40  if(!current)
41  return;
42  KbProfile* profile = device->find(current->data(GUID).toUuid());
43  if(!profile)
44  return;
45  device->setCurrentProfile(profile);
46 }
rgb * current
Definition: main.c:46
void setCurrentProfile(KbProfile *profile, bool spontaneous=true)
Definition: kb.cpp:760
static const int GUID
KbProfile * find(const QUuid &id)
Definition: kb.h:62

+ Here is the call graph for this function:

void KbProfileDialog::on_profileList_customContextMenuRequested ( const QPoint &  pos)
privateslot

Definition at line 109 of file kbprofiledialog.cpp.

References Kb::currentProfile(), device, Kb::find(), UsbId::guid, GUID, Kb::hwProfile(), Kb::hwSave(), KbProfile::id(), Kb::indexOf(), NEW_FLAG, KbProfile::newId(), Kb::newProfile(), Ui_KbProfileDialog::profileList, Kb::profiles(), KbProfile::removeAll(), repopulate(), Kb::setCurrentProfile(), and ui.

109  {
110  QListWidgetItem* item = ui->profileList->itemAt(pos);
111  KbProfile* currentProfile = device->currentProfile();
112  if(!item || !currentProfile || item->data(GUID).toUuid() != currentProfile->id().guid)
113  return;
114  int index = device->indexOf(currentProfile);
115  QList<KbProfile*> profiles = device->profiles();
116 
117  QMenu menu(this);
118  QAction* rename = new QAction("Rename...", this);
119  QAction* duplicate = new QAction("Duplicate", this);
120  QAction* del = new QAction("Delete", this);
121  bool canDelete = (profiles.count() > 1);
122  if(!canDelete)
123  // Can't delete the last profile on the device
124  del->setEnabled(false);
125  QAction* hwsave = new QAction("Save to Hardware", this);
126  QAction* moveup = new QAction("Move Up", this);
127  if(index == 0)
128  moveup->setEnabled(false);
129  QAction* movedown = new QAction("Move Down", this);
130  if(index >= profiles.count() - 1)
131  movedown->setEnabled(false);
132  menu.addAction(rename);
133  menu.addAction(duplicate);
134  menu.addAction(del);
135  menu.addSeparator();
136  menu.addAction(hwsave);
137  menu.addSeparator();
138  menu.addAction(moveup);
139  menu.addAction(movedown);
140  QAction* result = menu.exec(QCursor::pos());
141  if(result == rename){
142  ui->profileList->editItem(item);
143  } else if(result == duplicate){
144  KbProfile* newProfile = device->newProfile(currentProfile);
145  newProfile->newId();
146  profiles.insert(index + 1, newProfile);
147  device->profiles(profiles);
148  device->setCurrentProfile(newProfile);
149  } else if(result == del){
150  if(!canDelete)
151  return;
152  profiles.removeAll(currentProfile);
153  device->profiles(profiles);
154  currentProfile->deleteLater();
155  // Select next profile
156  if(index < profiles.count())
157  device->setCurrentProfile(profiles.at(index));
158  else
159  device->setCurrentProfile(profiles.last());
160  } else if(result == hwsave){
161  device->hwSave();
162  // Refresh item icons
163  int count = ui->profileList->count();
164  for(int i = 0; i < count; i++){
165  QListWidgetItem* item = ui->profileList->item(i);
166  if(item->data(NEW_FLAG).toUInt() == 1)
167  continue;
168  KbProfile* profile = device->find(item->data(GUID).toUuid());
169  item->setIcon(QIcon((profile == device->hwProfile()) ? ":/img/icon_profile_hardware.png" : ":/img/icon_profile.png"));
170  }
171  } else if(result == moveup){
172  profiles.removeAll(currentProfile);
173  profiles.insert(index - 1, currentProfile);
174  device->profiles(profiles);
175  } else if(result == movedown){
176  profiles.removeAll(currentProfile);
177  profiles.insert(index + 1, currentProfile);
178  device->profiles(profiles);
179  }
180  repopulate();
181 }
QUuid guid
Definition: kbmode.h:12
RListWidget * profileList
Ui::KbProfileDialog * ui
static const int NEW_FLAG
KbProfile * currentProfile()
Definition: kb.h:56
int indexOf(KbProfile *profile)
Definition: kb.h:61
void setCurrentProfile(KbProfile *profile, bool spontaneous=true)
Definition: kb.cpp:760
UsbId & id()
Definition: kbprofile.h:30
void hwSave()
Definition: kb.cpp:297
KbProfile * hwProfile()
Definition: kb.h:46
const QList< KbProfile * > & profiles() const
Definition: kb.h:58
void removeAll(KbMode *mode)
Definition: kbprofile.h:46
static const int GUID
KbProfile * find(const QUuid &id)
Definition: kb.h:62
void newId()
Definition: kbprofile.cpp:78
KbProfile * newProfile()
Definition: kb.h:77

+ Here is the call graph for this function:

void KbProfileDialog::on_profileList_itemChanged ( QListWidgetItem *  item)
privateslot

Definition at line 100 of file kbprofiledialog.cpp.

References Kb::currentProfile(), device, UsbId::guid, GUID, KbProfile::id(), and KbProfile::name().

100  {
101  KbProfile* currentProfile = device->currentProfile();
102  if(!item || !currentProfile || item->data(GUID).toUuid() != currentProfile->id().guid)
103  return;
104  currentProfile->name(item->text());
105  // Set the text to the actual name (trimmed, "" replaced with "Unnamed")
106  item->setText(currentProfile->name());
107 }
QUuid guid
Definition: kbmode.h:12
KbProfile * currentProfile()
Definition: kb.h:56
UsbId & id()
Definition: kbprofile.h:30
static const int GUID
QString name() const
Definition: kbprofile.h:28

+ Here is the call graph for this function:

void KbProfileDialog::on_profileList_itemClicked ( QListWidgetItem *  item)
privateslot

Definition at line 78 of file kbprofiledialog.cpp.

References addNewProfileItem(), Kb::appendProfile(), device, UsbId::guid, GUID, KbProfile::id(), NEW_FLAG, Kb::newProfile(), Ui_KbProfileDialog::profileList, Kb::setCurrentProfile(), and ui.

78  {
79  QUuid guid = item->data(GUID).toUuid();
80  if(guid.isNull() && item->data(NEW_FLAG).toInt() == 1){
81  // New profile
82  item->setText("");
83  ui->profileList->editItem(item);
84  item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
85  QFont font = item->font();
86  font.setItalic(false);
87  item->setFont(font);
88  item->setIcon(QIcon(":/img/icon_profile.png"));
89  // Add the new profile and assign it to this item
90  KbProfile* newProfile = device->newProfile();
91  device->appendProfile(newProfile);
92  item->setData(GUID, newProfile->id().guid);
93  item->setData(NEW_FLAG, 0);
94  device->setCurrentProfile(newProfile);
95  // Create another "new profile" item to replace this one
97  }
98 }
QUuid guid
Definition: kbmode.h:12
RListWidget * profileList
Ui::KbProfileDialog * ui
static const int NEW_FLAG
void setCurrentProfile(KbProfile *profile, bool spontaneous=true)
Definition: kb.cpp:760
UsbId & id()
Definition: kbprofile.h:30
void appendProfile(KbProfile *newProfile)
Definition: kb.h:60
static const int GUID
KbProfile * newProfile()
Definition: kb.h:77

+ Here is the call graph for this function:

void KbProfileDialog::profileList_reordered ( )
privateslot

Definition at line 20 of file kbprofiledialog.cpp.

References KbProfile::append(), device, Kb::find(), GUID, Ui_KbProfileDialog::profileList, Kb::profiles(), and ui.

Referenced by KbProfileDialog().

20  {
21  // Rebuild profile list from items
22  QList<KbProfile*> newProfiles;
23  int count = ui->profileList->count();
24  for(int i = 0; i < count; i++){
25  QListWidgetItem* item = ui->profileList->item(i);
26  KbProfile* profile = device->find(item->data(GUID).toUuid());
27  if(profile && !newProfiles.contains(profile))
28  newProfiles.append(profile);
29  item->setFlags(item->flags() | Qt::ItemIsEditable);
30  }
31  // Add any missing profiles at the end of the list
32  foreach(KbProfile* profile, device->profiles()){
33  if(!newProfiles.contains(profile))
34  newProfiles.append(profile);
35  }
36  device->profiles(newProfiles);
37 }
RListWidget * profileList
Ui::KbProfileDialog * ui
void append(KbMode *newMode)
Definition: kbprofile.h:44
const QList< KbProfile * > & profiles() const
Definition: kb.h:58
static const int GUID
KbProfile * find(const QUuid &id)
Definition: kb.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbProfileDialog::repopulate ( )
private

Definition at line 48 of file kbprofiledialog.cpp.

References addNewProfileItem(), current, Kb::currentProfile(), device, UsbId::guid, GUID, Kb::hwProfile(), KbProfile::id(), KbProfile::name(), Ui_KbProfileDialog::profileList, Kb::profiles(), and ui.

Referenced by KbProfileDialog(), and on_profileList_customContextMenuRequested().

48  {
49  ui->profileList->clear();
50  QListWidgetItem* current = 0;
51  foreach(KbProfile* profile, device->profiles()){
52  QListWidgetItem* item = new QListWidgetItem(QIcon((profile == device->hwProfile()) ? ":/img/icon_profile_hardware.png" : ":/img/icon_profile.png"), profile->name(), ui->profileList);
53  item->setData(GUID, profile->id().guid);
54  item->setFlags(item->flags() | Qt::ItemIsEditable);
55  if(profile == device->currentProfile()){
56  item->setSelected(true);
57  current = item;
58  }
59  ui->profileList->addItem(item);
60  }
61  if(current)
62  ui->profileList->setCurrentItem(current);
64 }
QUuid guid
Definition: kbmode.h:12
rgb * current
Definition: main.c:46
RListWidget * profileList
Ui::KbProfileDialog * ui
KbProfile * currentProfile()
Definition: kb.h:56
UsbId & id()
Definition: kbprofile.h:30
KbProfile * hwProfile()
Definition: kb.h:46
const QList< KbProfile * > & profiles() const
Definition: kb.h:58
static const int GUID
QString name() const
Definition: kbprofile.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

const int KbProfileDialog::NEW_FLAG = Qt::UserRole + 1
staticprivate

The documentation for this class was generated from the following files: