Mercurial > hg > easyhg
comparison multichoicedialog.cpp @ 72:121cb1032717
* Bit more work on Open dialog
author | Chris Cannam |
---|---|
date | Thu, 18 Nov 2010 17:36:53 +0000 |
parents | 6d5a5571caec |
children | 10eb97683aa9 |
comparison
equal
deleted
inserted
replaced
71:eaabc54de103 | 72:121cb1032717 |
---|---|
25 #include <QToolButton> | 25 #include <QToolButton> |
26 #include <QPushButton> | 26 #include <QPushButton> |
27 #include <QFont> | 27 #include <QFont> |
28 #include <QDir> | 28 #include <QDir> |
29 #include <QFileDialog> | 29 #include <QFileDialog> |
30 #include <QUrl> | |
30 | 31 |
31 MultiChoiceDialog::MultiChoiceDialog(QString title, QString heading, QWidget *parent) : | 32 MultiChoiceDialog::MultiChoiceDialog(QString title, QString heading, QWidget *parent) : |
32 QDialog(parent) | 33 QDialog(parent) |
33 { | 34 { |
34 setModal(true); | 35 setModal(true); |
49 | 50 |
50 QFont f = m_descriptionLabel->font(); | 51 QFont f = m_descriptionLabel->font(); |
51 f.setPointSize(f.pointSize() * 0.9); | 52 f.setPointSize(f.pointSize() * 0.9); |
52 m_descriptionLabel->setFont(f); | 53 m_descriptionLabel->setFont(f); |
53 | 54 |
54 m_argLabel = new QLabel(); | 55 m_urlLabel = new QLabel(tr("URL:")); |
55 outer->addWidget(m_argLabel, 3, 0); | 56 outer->addWidget(m_urlLabel, 3, 0); |
56 | 57 |
57 m_argEdit = new QComboBox(); | 58 m_urlCombo = new QComboBox(); |
58 m_argEdit->setEditable(true); | 59 m_urlCombo->setEditable(true); |
59 outer->addWidget(m_argEdit, 3, 1); | 60 connect(m_urlCombo, SIGNAL(editTextChanged(const QString &)), |
61 this, SLOT(urlChanged(const QString &))); | |
62 outer->addWidget(m_urlCombo, 3, 1, 1, 2); | |
63 | |
64 m_fileLabel = new QLabel(tr("File:")); | |
65 outer->addWidget(m_fileLabel, 4, 0); | |
66 | |
67 m_fileCombo = new QComboBox(); | |
68 m_fileCombo->setEditable(true); | |
69 outer->addWidget(m_fileCombo, 4, 1); | |
60 outer->setColumnStretch(1, 20); | 70 outer->setColumnStretch(1, 20); |
61 | 71 |
62 m_browseButton = new QPushButton(tr("Browse...")); | 72 m_browseButton = new QPushButton(tr("Browse...")); |
63 outer->addWidget(m_browseButton, 3, 2); | 73 outer->addWidget(m_browseButton, 4, 2); |
64 connect(m_browseButton, SIGNAL(clicked()), this, SLOT(browse())); | 74 connect(m_browseButton, SIGNAL(clicked()), this, SLOT(browse())); |
65 | 75 |
66 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | | 76 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | |
67 QDialogButtonBox::Cancel); | 77 QDialogButtonBox::Cancel); |
68 connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); | 78 connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); |
69 connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); | 79 connect(bbox, SIGNAL(rejected()), this, SLOT(reject())); |
70 outer->addWidget(bbox, 4, 0, 1, 3); | 80 outer->addWidget(bbox, 5, 0, 1, 3); |
71 | 81 |
72 setMinimumWidth(480); | 82 setMinimumWidth(480); |
73 } | 83 } |
74 | 84 |
75 QString | 85 QString |
86 } | 96 } |
87 | 97 |
88 QString | 98 QString |
89 MultiChoiceDialog::getArgument() | 99 MultiChoiceDialog::getArgument() |
90 { | 100 { |
91 return m_argEdit->currentText(); | 101 if (m_argTypes[m_currentChoice] == UrlArg || |
92 } | 102 m_argTypes[m_currentChoice] == UrlToDirectoryArg) { |
93 | 103 return m_urlCombo->currentText(); |
94 void | 104 } else { |
95 MultiChoiceDialog::addRecentArgument(QString id, QString arg) | 105 return m_fileCombo->currentText(); |
96 { | 106 } |
97 RecentFiles(QString("Recent-%1").arg(id)).addFile(arg); | 107 } |
108 | |
109 QString | |
110 MultiChoiceDialog::getAdditionalArgument() | |
111 { | |
112 if (m_argTypes[m_currentChoice] == UrlToDirectoryArg) { | |
113 return m_fileCombo->currentText(); | |
114 } else { | |
115 return ""; | |
116 } | |
117 } | |
118 | |
119 void | |
120 MultiChoiceDialog::addRecentArgument(QString id, QString arg, | |
121 bool additionalArgument) | |
122 { | |
123 if (additionalArgument) { | |
124 RecentFiles(QString("Recent-%1-add").arg(id)).addFile(arg); | |
125 } else { | |
126 RecentFiles(QString("Recent-%1").arg(id)).addFile(arg); | |
127 } | |
98 } | 128 } |
99 | 129 |
100 void | 130 void |
101 MultiChoiceDialog::addChoice(QString id, QString text, | 131 MultiChoiceDialog::addChoice(QString id, QString text, |
102 QString description, ArgType arg) | 132 QString description, ArgType arg) |
140 #endif | 170 #endif |
141 } | 171 } |
142 | 172 |
143 QString path = origin; | 173 QString path = origin; |
144 | 174 |
145 if (m_argTypes[m_currentChoice] == DirectoryArg) { | 175 if (m_argTypes[m_currentChoice] == DirectoryArg || |
176 m_argTypes[m_currentChoice] == UrlToDirectoryArg) { | |
146 | 177 |
147 path = QFileDialog::getExistingDirectory | 178 path = QFileDialog::getExistingDirectory |
148 (this, tr("Open Directory"), origin, | 179 (this, tr("Open Directory"), origin, |
149 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); | 180 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); |
150 if (path != QString()) { | 181 if (path != QString()) { |
151 m_argEdit->lineEdit()->setText(path + QDir::separator()); | 182 m_fileCombo->lineEdit()->setText(path + QDir::separator()); |
152 } | 183 } |
153 | 184 |
154 } else { | 185 } else { |
155 | 186 |
156 path = QFileDialog::getOpenFileName | 187 path = QFileDialog::getOpenFileName |
157 (this, tr("Open File"), origin); | 188 (this, tr("Open File"), origin); |
158 if (path != QString()) { | 189 if (path != QString()) { |
159 m_argEdit->lineEdit()->setText(path); | 190 m_fileCombo->lineEdit()->setText(path); |
160 } | 191 } |
161 } | 192 } |
193 } | |
194 | |
195 void | |
196 MultiChoiceDialog::urlChanged(const QString &s) | |
197 { | |
198 if (m_argTypes[m_currentChoice] != UrlToDirectoryArg) { | |
199 return; | |
200 } | |
201 QDir dirPath(m_fileCombo->currentText()); | |
202 if (!dirPath.exists()) { | |
203 if (!dirPath.cdUp()) return; | |
204 } | |
205 QString url = m_urlCombo->currentText(); | |
206 if (QRegExp("^\\w+://").indexIn(url) < 0) { | |
207 return; | |
208 } | |
209 QString urlDirName = url; | |
210 urlDirName.replace(QRegExp("^.*//.*/"), ""); | |
211 if (urlDirName == "" || urlDirName == url) { | |
212 return; | |
213 } | |
214 m_fileCombo->lineEdit()->setText(dirPath.filePath(urlDirName)); | |
162 } | 215 } |
163 | 216 |
164 void | 217 void |
165 MultiChoiceDialog::choiceChanged() | 218 MultiChoiceDialog::choiceChanged() |
166 { | 219 { |
192 } | 245 } |
193 } | 246 } |
194 | 247 |
195 m_descriptionLabel->setText(m_descriptions[id]); | 248 m_descriptionLabel->setText(m_descriptions[id]); |
196 | 249 |
250 m_fileLabel->hide(); | |
251 m_fileCombo->hide(); | |
252 m_browseButton->hide(); | |
253 m_urlLabel->hide(); | |
254 m_urlCombo->hide(); | |
255 | |
256 QSharedPointer<RecentFiles> rf = m_recentFiles[id]; | |
257 m_fileCombo->clear(); | |
258 m_urlCombo->clear(); | |
259 | |
197 switch (m_argTypes[id]) { | 260 switch (m_argTypes[id]) { |
198 | 261 |
199 case NoArg: | 262 case NoArg: |
200 m_argLabel->hide(); | |
201 m_argEdit->hide(); | |
202 m_browseButton->hide(); | |
203 break; | 263 break; |
204 | 264 |
205 case FileArg: | 265 case FileArg: |
206 m_argLabel->setText(tr("File:")); | 266 m_fileLabel->setText(tr("File:")); |
207 m_argLabel->show(); | 267 m_fileLabel->show(); |
208 m_argEdit->show(); | 268 m_fileCombo->show(); |
269 m_fileCombo->addItems(rf->getRecent()); | |
209 m_browseButton->show(); | 270 m_browseButton->show(); |
210 break; | 271 break; |
211 | 272 |
212 case DirectoryArg: | 273 case DirectoryArg: |
213 m_argLabel->setText(tr("Folder:")); | 274 m_fileLabel->setText(tr("Folder:")); |
214 m_argLabel->show(); | 275 m_fileLabel->show(); |
215 m_argEdit->show(); | 276 m_fileCombo->show(); |
277 m_fileCombo->addItems(rf->getRecent()); | |
216 m_browseButton->show(); | 278 m_browseButton->show(); |
217 break; | 279 break; |
218 | 280 |
219 case UrlArg: | 281 case UrlArg: |
220 m_argLabel->setText(tr("URL:")); | 282 m_urlLabel->show(); |
221 m_argLabel->show(); | 283 m_urlCombo->show(); |
222 m_argEdit->show(); | 284 break; |
223 m_browseButton->hide(); | 285 |
224 break; | 286 case UrlToDirectoryArg: |
225 | 287 m_urlLabel->show(); |
226 case FileOrUrlArg: | 288 m_urlCombo->show(); |
227 m_argLabel->setText(tr("File or URL:")); | 289 m_urlCombo->addItems(rf->getRecent()); |
228 m_argLabel->show(); | 290 m_fileLabel->setText(tr("Folder:")); |
229 m_argEdit->show(); | 291 m_fileLabel->show(); |
292 m_fileCombo->show(); | |
293 m_fileCombo->lineEdit()->setText(QDir::homePath()); | |
230 m_browseButton->show(); | 294 m_browseButton->show(); |
231 break; | 295 break; |
232 } | 296 } |
233 | 297 |
234 if (m_argTypes[id] != NoArg) { | |
235 QSharedPointer<RecentFiles> rf = m_recentFiles[id]; | |
236 m_argEdit->clear(); | |
237 m_argEdit->addItems(rf->getRecent()); | |
238 } | |
239 | |
240 adjustSize(); | 298 adjustSize(); |
241 } | 299 } |
242 | 300 |
243 | 301 |