Changeset View
Changeset View
Standalone View
Standalone View
krusader/Dialogs/kurllistrequester.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 42 | { | |||
---|---|---|---|---|---|
44 | 44 | | |||
45 | QGridLayout *urlListRequesterGrid = new QGridLayout(this); | 45 | QGridLayout *urlListRequesterGrid = new QGridLayout(this); | ||
46 | urlListRequesterGrid->setSpacing(0); | 46 | urlListRequesterGrid->setSpacing(0); | ||
47 | urlListRequesterGrid->setContentsMargins(0, 0, 0, 0); | 47 | urlListRequesterGrid->setContentsMargins(0, 0, 0, 0); | ||
48 | 48 | | |||
49 | urlLineEdit = new KLineEdit(this); | 49 | urlLineEdit = new KLineEdit(this); | ||
50 | urlListRequesterGrid->addWidget(urlLineEdit, 0, 0); | 50 | urlListRequesterGrid->addWidget(urlLineEdit, 0, 0); | ||
51 | 51 | | |||
52 | urlListBox = new KrListWidget(this); | | |||
53 | urlListBox->setSelectionMode(QAbstractItemView::ExtendedSelection); | | |||
54 | urlListRequesterGrid->addWidget(urlListBox, 1, 0, 1, 3); | | |||
55 | | ||||
56 | urlAddBtn = new QToolButton(this); | 52 | urlAddBtn = new QToolButton(this); | ||
57 | urlAddBtn->setText(""); | 53 | urlAddBtn->setText(""); | ||
58 | urlAddBtn->setIcon(Icon("arrow-down")); | 54 | urlAddBtn->setIcon(Icon("arrow-down")); | ||
59 | urlListRequesterGrid->addWidget(urlAddBtn, 0, 1); | 55 | urlListRequesterGrid->addWidget(urlAddBtn, 0, 1); | ||
60 | 56 | | |||
61 | urlBrowseBtn = new QToolButton(this); | 57 | urlBrowseBtn = new QToolButton(this); | ||
62 | urlBrowseBtn->setText(""); | 58 | urlBrowseBtn->setText(""); | ||
63 | urlBrowseBtn->setIcon(Icon("folder")); | 59 | urlBrowseBtn->setIcon(Icon("folder")); | ||
64 | urlListRequesterGrid->addWidget(urlBrowseBtn, 0, 2); | 60 | urlListRequesterGrid->addWidget(urlBrowseBtn, 0, 2); | ||
65 | 61 | | |||
62 | urlListBox = new KrListWidget(this); | ||||
63 | urlListBox->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||||
64 | urlListRequesterGrid->addWidget(urlListBox, 1, 0, 1, 3); | ||||
65 | | ||||
66 | // add shell completion | 66 | // add shell completion | ||
67 | 67 | | |||
68 | completion.setMode(KUrlCompletion::FileCompletion); | 68 | completion.setMode(KUrlCompletion::FileCompletion); | ||
69 | urlLineEdit->setCompletionObject(&completion); | 69 | urlLineEdit->setCompletionObject(&completion); | ||
70 | 70 | | |||
71 | // connection table | 71 | // connection table | ||
72 | 72 | | |||
73 | connect(urlAddBtn, SIGNAL(clicked()), this, SLOT(slotAdd())); | 73 | connect(urlAddBtn, &QToolButton::clicked, this, &KURLListRequester::slotAdd); | ||
74 | connect(urlBrowseBtn, SIGNAL(clicked()), this, SLOT(slotBrowse())); | 74 | connect(urlBrowseBtn, &QToolButton::clicked, this, &KURLListRequester::slotBrowse); | ||
75 | connect(urlLineEdit, SIGNAL(returnPressed(QString)), this, SLOT(slotAdd())); | 75 | connect(urlLineEdit, &KLineEdit::returnPressed, this, &KURLListRequester::slotAdd); | ||
76 | connect(urlListBox, SIGNAL(itemRightClicked(QListWidgetItem*,QPoint)), this, | 76 | connect(urlListBox, &KrListWidget::itemRightClicked, this, &KURLListRequester::slotRightClicked); | ||
77 | SLOT(slotRightClicked(QListWidgetItem*,QPoint))); | 77 | connect(urlLineEdit, &KLineEdit::textChanged, this, &KURLListRequester::changed); | ||
78 | connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); | | |||
79 | } | 78 | } | ||
80 | 79 | | |||
81 | void KURLListRequester::slotAdd() | 80 | void KURLListRequester::slotAdd() | ||
82 | { | 81 | { | ||
83 | QString text = urlLineEdit->text().simplified(); | 82 | QString text = urlLineEdit->text().simplified(); | ||
84 | if (text.length()) { | 83 | if (text.length()) { | ||
85 | QString error; | 84 | QString error; | ||
86 | emit checkValidity(text, error); | 85 | emit checkValidity(text, error); | ||
Show All 33 Lines | 115 | if (e->key() == Qt::Key_Delete) { | |||
120 | } | 119 | } | ||
121 | } | 120 | } | ||
122 | 121 | | |||
123 | QWidget::keyPressEvent(e); | 122 | QWidget::keyPressEvent(e); | ||
124 | } | 123 | } | ||
125 | 124 | | |||
126 | void KURLListRequester::deleteSelectedItems() | 125 | void KURLListRequester::deleteSelectedItems() | ||
127 | { | 126 | { | ||
128 | QList<QListWidgetItem *> delList = urlListBox->selectedItems(); | 127 | QList<QListWidgetItem *> selectedItems = urlListBox->selectedItems(); | ||
129 | for (int i = 0; i != delList.count(); i++) | 128 | for (QListWidgetItem *item : selectedItems) | ||
130 | delete delList[ i ]; | 129 | delete item; | ||
131 | emit changed(); | 130 | emit changed(); | ||
132 | } | 131 | } | ||
133 | 132 | | |||
134 | void KURLListRequester::slotRightClicked(QListWidgetItem *item, const QPoint &pos) | 133 | void KURLListRequester::slotRightClicked(QListWidgetItem *item, const QPoint &pos) | ||
135 | { | 134 | { | ||
136 | if (item == 0) | 135 | if (item == 0) | ||
137 | return; | 136 | return; | ||
138 | 137 | | |||
139 | QMenu popupMenu(this); | 138 | QMenu popupMenu(this); | ||
140 | QAction * menuAction = popupMenu.addAction(i18n("Delete")); | 139 | QAction * menuAction = popupMenu.addAction(i18n("Delete")); | ||
141 | 140 | | |||
142 | if (menuAction == popupMenu.exec(pos)) { | 141 | if (menuAction == popupMenu.exec(pos)) { | ||
143 | if (item->isSelected()) | 142 | if (item->isSelected()) | ||
144 | deleteSelectedItems(); | 143 | deleteSelectedItems(); | ||
145 | else { | 144 | else { | ||
146 | delete item; | 145 | delete item; | ||
147 | emit changed(); | 146 | emit changed(); | ||
148 | } | 147 | } | ||
149 | } | 148 | } | ||
150 | } | 149 | } | ||
151 | 150 | | |||
152 | QList<QUrl> KURLListRequester::urlList() | 151 | QList<QUrl> KURLListRequester::urlList() | ||
153 | { | 152 | { | ||
154 | QList<QUrl> urls; | 153 | QStringList lines; | ||
155 | 154 | | |||
156 | QString text = urlLineEdit->text().simplified(); | 155 | const QString lineEditText = urlLineEdit->text().simplified(); | ||
157 | if (!text.isEmpty()) { | 156 | if (!lineEditText.isEmpty()) { | ||
158 | QString error; | 157 | lines.append(lineEditText); | ||
159 | emit checkValidity(text, error); | | |||
160 | if (error.isNull()) | | |||
161 | urls.append(QUrl::fromUserInput(text, QString(), QUrl::AssumeLocalFile)); | | |||
162 | } | 158 | } | ||
163 | 159 | | |||
164 | for (int i = 0; i != urlListBox->count(); i++) { | 160 | for (int i = 0; i != urlListBox->count(); i++) { | ||
165 | QListWidgetItem *item = urlListBox->item(i); | 161 | QListWidgetItem *item = urlListBox->item(i); | ||
162 | lines.append(item->text().simplified()); | ||||
163 | } | ||||
166 | 164 | | |||
167 | QString text = item->text().simplified(); | 165 | QList<QUrl> urls; | ||
168 | 166 | for (QString text : lines) { | |||
169 | QString error; | 167 | QString error; | ||
170 | emit checkValidity(text, error); | 168 | emit checkValidity(text, error); | ||
171 | if (error.isNull()) | 169 | if (error.isNull()) | ||
172 | urls.append(QUrl::fromUserInput(text, QString(), QUrl::AssumeLocalFile)); | 170 | urls.append(QUrl::fromUserInput(text, QString(), QUrl::AssumeLocalFile)); | ||
173 | } | 171 | } | ||
174 | 172 | | |||
175 | return urls; | 173 | return urls; | ||
176 | } | 174 | } | ||
177 | 175 | | |||
178 | void KURLListRequester::setUrlList(QList<QUrl> urlList) | 176 | void KURLListRequester::setUrlList(const QList<QUrl> &urlList) | ||
179 | { | 177 | { | ||
180 | urlLineEdit->clear(); | 178 | urlLineEdit->clear(); | ||
181 | urlListBox->clear(); | 179 | urlListBox->clear(); | ||
182 | 180 | | |||
183 | QList<QUrl>::iterator it; | 181 | for (const QUrl url : urlList) { | ||
184 | 182 | urlListBox->addItem(url.toDisplayString(QUrl::PreferLocalFile)); | |||
185 | for (it = urlList.begin(); it != urlList.end(); ++it) | 183 | } | ||
186 | urlListBox->addItem(it->toDisplayString(QUrl::PreferLocalFile)); | | |||
187 | 184 | | |||
188 | emit changed(); | 185 | emit changed(); | ||
189 | } | 186 | } | ||
190 | 187 | |