1 /***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 3 of the License, or *
6 * (at your option) any later version. *
7 * *
8 ***************************************************************************/
9
10 #include "SettingsUC.h"
11 #include "UCModel.h"
12
13 #include <QItemSelectionModel>
14
15 #include <dcpp/FavoriteManager.h>
16
SettingsUC(QWidget * parent)17 SettingsUC::SettingsUC(QWidget *parent) :
18 QWidget(parent)
19 {
20 setupUi(this);
21
22 model = new UCModel(this);
23 model->loadUC();
24
25 treeView->setModel(model);
26
27 connect(pushButton_ADD, SIGNAL(clicked()), model, SLOT(newUC()));
28 connect(pushButton_REM, SIGNAL(clicked()), this, SLOT(slotRemClicked()));
29 connect(pushButton_CH, SIGNAL(clicked()), this, SLOT(slotChangeClicked()));
30 connect(pushButton_UP, SIGNAL(clicked()), this, SLOT(slotUpClicked()));
31 connect(pushButton_DOWN,SIGNAL(clicked()), this, SLOT(slotDownClicked()));
32 connect(this, SIGNAL(remUC(QModelIndex)), model, SLOT(remUC(QModelIndex)));
33 connect(this, SIGNAL(changeUC(QModelIndex)), model, SLOT(changeUC(QModelIndex)));
34 connect(this, SIGNAL(upUC(QModelIndex)), model, SLOT(moveUp(QModelIndex)));
35 connect(this, SIGNAL(downUC(QModelIndex)), model, SLOT(moveDown(QModelIndex)));
36 connect(model, SIGNAL(selectIndex(QModelIndex)), this, SLOT(slotSelect(QModelIndex)));
37 }
38
~SettingsUC()39 SettingsUC::~SettingsUC(){
40 model->deleteLater();
41 }
42
ok()43 void SettingsUC::ok(){
44
45 }
46
selectedIndex()47 QModelIndex SettingsUC::selectedIndex(){
48 QItemSelectionModel *s_m = treeView->selectionModel();
49 QModelIndexList list = s_m->selectedRows(0);
50
51 if (!list.isEmpty())
52 return list.at(0);
53 else
54 return QModelIndex();
55 }
56
slotRemClicked()57 void SettingsUC::slotRemClicked(){
58 emit remUC(selectedIndex());
59 }
60
slotChangeClicked()61 void SettingsUC::slotChangeClicked(){
62 emit changeUC(selectedIndex());
63 }
64
slotUpClicked()65 void SettingsUC::slotUpClicked(){
66 emit upUC(selectedIndex());
67 }
68
slotDownClicked()69 void SettingsUC::slotDownClicked(){
70 emit downUC(selectedIndex());
71 }
72
slotSelect(const QModelIndex & i)73 void SettingsUC::slotSelect(const QModelIndex &i){
74 QItemSelectionModel *s_m = treeView->selectionModel();
75
76 s_m->select(i, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
77 }
78