comparison widgets/ImageDialog.cpp @ 304:4b7e8da8f069

* More work on image layer display &c
author Chris Cannam
date Fri, 05 Oct 2007 13:27:21 +0000
parents 46faec7aae12
children 013a37723c0a
comparison
equal deleted inserted replaced
303:46faec7aae12 304:4b7e8da8f069
19 #include <QGridLayout> 19 #include <QGridLayout>
20 #include <QLabel> 20 #include <QLabel>
21 #include <QDialogButtonBox> 21 #include <QDialogButtonBox>
22 #include <QPushButton> 22 #include <QPushButton>
23 #include <QGroupBox> 23 #include <QGroupBox>
24 #include <QDesktopWidget>
25 #include <QApplication>
24 26
25 #include "data/fileio/FileFinder.h" 27 #include "data/fileio/FileFinder.h"
26 28
27 ImageDialog::ImageDialog(QString title, 29 ImageDialog::ImageDialog(QString title,
28 QString image, 30 QString image,
51 ++row; 53 ++row;
52 54
53 subgrid->addWidget(new QLabel(tr("File:")), row, 0); 55 subgrid->addWidget(new QLabel(tr("File:")), row, 0);
54 56
55 m_imageEdit = new QLineEdit; 57 m_imageEdit = new QLineEdit;
56 m_imageEdit->setReadOnly(true);
57 subgrid->addWidget(m_imageEdit, row, 1, 1, 1); 58 subgrid->addWidget(m_imageEdit, row, 1, 1, 1);
59 connect(m_imageEdit, SIGNAL(textEdited(const QString &)),
60 this, SLOT(imageEditEdited(const QString &)));
58 61
59 QPushButton *browse = new QPushButton(tr("Browse...")); 62 QPushButton *browse = new QPushButton(tr("Browse..."));
60 connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked())); 63 connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked()));
61 subgrid->addWidget(browse, row, 2, 1, 1); 64 subgrid->addWidget(browse, row, 2, 1, 1);
62 65
70 m_imagePreview = new QLabel; 73 m_imagePreview = new QLabel;
71 m_imagePreview->setAlignment(Qt::AlignCenter); 74 m_imagePreview->setAlignment(Qt::AlignCenter);
72 subgrid->addWidget(m_imagePreview, 0, 0); 75 subgrid->addWidget(m_imagePreview, 0, 0);
73 76
74 m_imagePreview->setMinimumSize(QSize(100, 100)); 77 m_imagePreview->setMinimumSize(QSize(100, 100));
78
79 QDesktopWidget *desktop = QApplication::desktop();
80 m_imagePreview->setMaximumSize(QSize((desktop->width() * 2) / 3,
81 (desktop->height() * 2) / 3));
75 82
76 grid->addWidget(databox, 0, 0); 83 grid->addWidget(databox, 0, 0);
77 grid->addWidget(previewbox, 1, 0); 84 grid->addWidget(previewbox, 1, 0);
78 85
79 grid->setRowStretch(1, 10); 86 grid->setRowStretch(1, 10);
131 { 138 {
132 updatePreview(); 139 updatePreview();
133 } 140 }
134 141
135 void 142 void
143 ImageDialog::imageEditEdited(const QString &)
144 {
145 updatePreview();
146 }
147
148 void
136 ImageDialog::updatePreview() 149 ImageDialog::updatePreview()
137 { 150 {
138 if (!m_imagePreview) return; 151 if (!m_imagePreview) return;
139 152
140 QString img = m_imageEdit->text(); 153 QString img = m_imageEdit->text();
154
155 m_okButton->setEnabled(img != "");
141 156
142 if (img != m_loadedImageFile) { 157 if (img != m_loadedImageFile) {
143 m_loadedImage = QPixmap(img); 158 m_loadedImage = QPixmap(img);
144 m_loadedImageFile = img; 159 m_loadedImageFile = img;
145 } 160 }
148 int m = m_imagePreview->margin() * 2; 163 int m = m_imagePreview->margin() * 2;
149 sz -= QSize(m, m); 164 sz -= QSize(m, m);
150 165
151 if (m_loadedImage.isNull()) { 166 if (m_loadedImage.isNull()) {
152 m_imagePreview->setPixmap(QPixmap()); 167 m_imagePreview->setPixmap(QPixmap());
153 m_okButton->setEnabled(false);
154 } else { 168 } else {
155 m_imagePreview->setPixmap(m_loadedImage.scaled 169 m_imagePreview->setPixmap(m_loadedImage.scaled
156 (sz, 170 (sz,
157 Qt::KeepAspectRatio, 171 Qt::KeepAspectRatio,
158 Qt::SmoothTransformation)); 172 Qt::SmoothTransformation));
159 m_okButton->setEnabled(true);
160 } 173 }
161 } 174 }
162 175
163 void 176 void
164 ImageDialog::browseClicked() 177 ImageDialog::browseClicked()