comparison widgets/PluginPathConfigurator.cpp @ 1286:e327bbf4bf57 plugin-path-config

Up/down
author Chris Cannam
date Tue, 15 May 2018 11:18:07 +0100
parents abd52bd8d435
children 2dd7f764c3a6
comparison
equal deleted inserted replaced
1285:abd52bd8d435 1286:e327bbf4bf57
19 19
20 #include "IconLoader.h" 20 #include "IconLoader.h"
21 #include "WidgetScale.h" 21 #include "WidgetScale.h"
22 22
23 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) : 23 PluginPathConfigurator::PluginPathConfigurator(QWidget *parent) :
24 QFrame(parent) 24 QFrame(parent),
25 m_innerFrame(0)
25 { 26 {
26 setFrameStyle(StyledPanel | Sunken); 27 setFrameStyle(StyledPanel | Sunken);
27 m_layout = new QGridLayout; 28 m_layout = new QGridLayout;
28 setLayout(m_layout); 29 setLayout(m_layout);
29 populate();
30 } 30 }
31 31
32 PluginPathConfigurator::~PluginPathConfigurator() 32 PluginPathConfigurator::~PluginPathConfigurator()
33 { 33 {
34 } 34 }
42 } 42 }
43 43
44 void 44 void
45 PluginPathConfigurator::populate() 45 PluginPathConfigurator::populate()
46 { 46 {
47 QLabel *header = new QLabel; 47 delete m_innerFrame;
48 m_innerFrame = new QWidget;
49 m_layout->addWidget(m_innerFrame, 0, 0);
50
51 QGridLayout *innerLayout = new QGridLayout;
52 m_innerFrame->setLayout(innerLayout);
53
54 QLabel *header = new QLabel(m_innerFrame);
48 header->setText(QString("<b>%1</b>").arg(tr("Location"))); 55 header->setText(QString("<b>%1</b>").arg(tr("Location")));
49 m_layout->addWidget(header, 0, 3); 56 innerLayout->addWidget(header, 0, 3);
50 57
51 for (int i = 0; i < m_path.size(); ++i) { 58 for (int i = 0; i < m_path.size(); ++i) {
52 59
53 int col = 0; 60 int col = 0;
54 int row = i + 1; 61 int row = i + 1;
55 QString dir = m_path[i]; 62 QString dir = m_path[i];
56 63
57 if (i > 0) { 64 if (i > 0) {
58 QPushButton *up = new QPushButton; 65 QPushButton *up = new QPushButton(m_innerFrame);
66 up->setObjectName(QString("%1").arg(i));
59 up->setIcon(IconLoader().load("up")); 67 up->setIcon(IconLoader().load("up"));
60 up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); 68 up->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
61 connect(up, SIGNAL(clicked()), this, SLOT(upClicked())); 69 connect(up, SIGNAL(clicked()), this, SLOT(upClicked()));
62 m_layout->addWidget(up, row, col); 70 innerLayout->addWidget(up, row, col);
63 } 71 }
64 ++col; 72 ++col;
65 73
66 if (i + 1 < m_path.size()) { 74 if (i + 1 < m_path.size()) {
67 QPushButton *down = new QPushButton; 75 QPushButton *down = new QPushButton(m_innerFrame);
76 down->setObjectName(QString("%1").arg(i));
68 down->setIcon(IconLoader().load("down")); 77 down->setIcon(IconLoader().load("down"));
69 down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); 78 down->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
70 connect(down, SIGNAL(clicked()), this, SLOT(downClicked())); 79 connect(down, SIGNAL(clicked()), this, SLOT(downClicked()));
71 m_layout->addWidget(down, row, col); 80 innerLayout->addWidget(down, row, col);
72 } 81 }
73 ++col; 82 ++col;
74 83
75 QPushButton *del = new QPushButton; 84 QPushButton *del = new QPushButton(m_innerFrame);
85 del->setObjectName(QString("%1").arg(i));
76 del->setIcon(IconLoader().load("datadelete")); 86 del->setIcon(IconLoader().load("datadelete"));
77 del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16))); 87 del->setFixedSize(WidgetScale::scaleQSize(QSize(16, 16)));
78 connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked())); 88 connect(del, SIGNAL(clicked()), this, SLOT(deleteClicked()));
79 m_layout->addWidget(del, row, col); 89 innerLayout->addWidget(del, row, col);
80 ++col; 90 ++col;
81 91
82 QLabel *dirLabel = new QLabel; 92 QLabel *dirLabel = new QLabel(m_innerFrame);
93 dirLabel->setObjectName(QString("%1").arg(i));
83 dirLabel->setText(dir); 94 dirLabel->setText(dir);
84 m_layout->addWidget(dirLabel, row, col); 95 innerLayout->addWidget(dirLabel, row, col);
85 m_layout->setColumnStretch(col, 10); 96 innerLayout->setColumnStretch(col, 10);
86 ++col; 97 ++col;
87 } 98 }
88 } 99 }
89 100
90 void 101 void
91 PluginPathConfigurator::upClicked() 102 PluginPathConfigurator::upClicked()
92 { 103 {
93 //!!! 104 bool ok = false;
105 int n = sender()->objectName().toInt(&ok);
106 if (!ok) {
107 SVCERR << "upClicked: unable to find index" << endl;
108 return;
109 }
110 QStringList newPath;
111 for (int i = 0; i < m_path.size(); ++i) {
112 if (i + 1 == n) {
113 newPath.push_back(m_path[i+1]);
114 newPath.push_back(m_path[i]);
115 ++i;
116 } else {
117 newPath.push_back(m_path[i]);
118 }
119 }
120 m_path = newPath;
121 populate();
94 } 122 }
95 123
96 void 124 void
97 PluginPathConfigurator::downClicked() 125 PluginPathConfigurator::downClicked()
98 { 126 {
99 //!!!! 127 bool ok = false;
128 int n = sender()->objectName().toInt(&ok);
129 if (!ok) {
130 SVCERR << "downClicked: unable to find index" << endl;
131 return;
132 }
133 QStringList newPath;
134 for (int i = 0; i < m_path.size(); ++i) {
135 if (i == n) {
136 newPath.push_back(m_path[i+1]);
137 newPath.push_back(m_path[i]);
138 ++i;
139 } else {
140 newPath.push_back(m_path[i]);
141 }
142 }
143 m_path = newPath;
144 populate();
100 } 145 }
101 146
102 void 147 void
103 PluginPathConfigurator::deleteClicked() 148 PluginPathConfigurator::deleteClicked()
104 { 149 {
105 //!!! 150 bool ok = false;
151 int n = sender()->objectName().toInt(&ok);
152 if (!ok) {
153 SVCERR << "deleteClicked: unable to find index" << endl;
154 return;
155 }
156 QStringList newPath;
157 for (int i = 0; i < m_path.size(); ++i) {
158 if (i != n) {
159 newPath.push_back(m_path[i]);
160 }
161 }
162 m_path = newPath;
163 populate();
106 } 164 }