Mercurial > hg > svgui
comparison widgets/ImageDialog.cpp @ 305:013a37723c0a
* Add support for remote files to image layer
author | Chris Cannam |
---|---|
date | Fri, 05 Oct 2007 15:52:52 +0000 |
parents | 4b7e8da8f069 |
children | e251c3599ea8 |
comparison
equal
deleted
inserted
replaced
304:4b7e8da8f069 | 305:013a37723c0a |
---|---|
21 #include <QDialogButtonBox> | 21 #include <QDialogButtonBox> |
22 #include <QPushButton> | 22 #include <QPushButton> |
23 #include <QGroupBox> | 23 #include <QGroupBox> |
24 #include <QDesktopWidget> | 24 #include <QDesktopWidget> |
25 #include <QApplication> | 25 #include <QApplication> |
26 | 26 #include <QUrl> |
27 #include <QMessageBox> | |
28 | |
29 #include "data/fileio/RemoteFile.h" | |
27 #include "data/fileio/FileFinder.h" | 30 #include "data/fileio/FileFinder.h" |
31 | |
32 #include <iostream> | |
28 | 33 |
29 ImageDialog::ImageDialog(QString title, | 34 ImageDialog::ImageDialog(QString title, |
30 QString image, | 35 QString image, |
31 QString label, | 36 QString label, |
32 QWidget *parent) : | 37 QWidget *parent) : |
33 QDialog(parent), | 38 QDialog(parent), |
34 m_imagePreview(0) | 39 m_imagePreview(0), |
40 m_remoteFile(0) | |
35 { | 41 { |
36 setWindowTitle(title); | 42 setWindowTitle(title); |
37 | 43 |
38 QGridLayout *grid = new QGridLayout; | 44 QGridLayout *grid = new QGridLayout; |
39 setLayout(grid); | 45 setLayout(grid); |
50 m_labelEdit = new QLineEdit; | 56 m_labelEdit = new QLineEdit; |
51 subgrid->addWidget(m_labelEdit, row, 1, 1, 2); | 57 subgrid->addWidget(m_labelEdit, row, 1, 1, 2); |
52 | 58 |
53 ++row; | 59 ++row; |
54 | 60 |
55 subgrid->addWidget(new QLabel(tr("File:")), row, 0); | 61 subgrid->addWidget(new QLabel(tr("File or URL:")), row, 0); |
56 | 62 |
57 m_imageEdit = new QLineEdit; | 63 m_imageEdit = new QLineEdit; |
58 subgrid->addWidget(m_imageEdit, row, 1, 1, 1); | 64 subgrid->addWidget(m_imageEdit, row, 1, 1, 1); |
65 | |
59 connect(m_imageEdit, SIGNAL(textEdited(const QString &)), | 66 connect(m_imageEdit, SIGNAL(textEdited(const QString &)), |
60 this, SLOT(imageEditEdited(const QString &))); | 67 this, SLOT(imageEditEdited(const QString &))); |
68 connect(m_imageEdit, SIGNAL(editingFinished()), | |
69 this, SLOT(imageEditEdited())); | |
61 | 70 |
62 QPushButton *browse = new QPushButton(tr("Browse...")); | 71 QPushButton *browse = new QPushButton(tr("Browse...")); |
63 connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked())); | 72 connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked())); |
64 subgrid->addWidget(browse, row, 2, 1, 1); | 73 subgrid->addWidget(browse, row, 2, 1, 1); |
65 | 74 |
98 if (label != "") setLabel(label); | 107 if (label != "") setLabel(label); |
99 } | 108 } |
100 | 109 |
101 ImageDialog::~ImageDialog() | 110 ImageDialog::~ImageDialog() |
102 { | 111 { |
112 delete m_remoteFile; | |
103 } | 113 } |
104 | 114 |
105 QString | 115 QString |
106 ImageDialog::getImage() | 116 ImageDialog::getImage() |
107 { | 117 { |
138 { | 148 { |
139 updatePreview(); | 149 updatePreview(); |
140 } | 150 } |
141 | 151 |
142 void | 152 void |
143 ImageDialog::imageEditEdited(const QString &) | 153 ImageDialog::imageEditEdited(const QString &s) |
154 { | |
155 if (s.startsWith("http:") || s.startsWith("ftp:")) { | |
156 return; | |
157 } | |
158 updatePreview(); | |
159 } | |
160 | |
161 void | |
162 ImageDialog::imageEditEdited() | |
144 { | 163 { |
145 updatePreview(); | 164 updatePreview(); |
146 } | 165 } |
147 | 166 |
148 void | 167 void |
153 QString img = m_imageEdit->text(); | 172 QString img = m_imageEdit->text(); |
154 | 173 |
155 m_okButton->setEnabled(img != ""); | 174 m_okButton->setEnabled(img != ""); |
156 | 175 |
157 if (img != m_loadedImageFile) { | 176 if (img != m_loadedImageFile) { |
158 m_loadedImage = QPixmap(img); | 177 |
178 QString fileName = img; | |
179 delete m_remoteFile; | |
180 m_remoteFile = 0; | |
181 | |
182 if (RemoteFile::isRemote(fileName)) { | |
183 QUrl url(fileName); | |
184 if (!RemoteFile::canHandleScheme(url)) { | |
185 QMessageBox::critical(this, tr("Unsupported scheme in URL"), | |
186 tr("The URL scheme \"%1\" is not supported") | |
187 .arg(url.scheme())); | |
188 } else { | |
189 m_remoteFile = new RemoteFile(url); | |
190 m_remoteFile->wait(); | |
191 if (!m_remoteFile->isOK()) { | |
192 QMessageBox::critical(this, tr("File download failed"), | |
193 tr("Failed to download URL \"%1\": %2") | |
194 .arg(url.toString()).arg(m_remoteFile->getErrorString())); | |
195 delete m_remoteFile; | |
196 m_remoteFile = 0; | |
197 } else { | |
198 fileName = m_remoteFile->getLocalFilename(); | |
199 } | |
200 } | |
201 } | |
202 | |
203 // std::cerr << "image filename: \"" << fileName.toStdString() << "\"" << std::endl; | |
204 | |
205 m_loadedImage = QPixmap(fileName); | |
159 m_loadedImageFile = img; | 206 m_loadedImageFile = img; |
160 } | 207 } |
161 | 208 |
162 QSize sz(m_imagePreview->size()); | 209 QSize sz(m_imagePreview->size()); |
163 int m = m_imagePreview->margin() * 2; | 210 int m = m_imagePreview->margin() * 2; |