diff 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
line wrap: on
line diff
--- a/widgets/ImageDialog.cpp	Thu Oct 04 16:34:11 2007 +0000
+++ b/widgets/ImageDialog.cpp	Fri Oct 05 13:27:21 2007 +0000
@@ -21,6 +21,8 @@
 #include <QDialogButtonBox>
 #include <QPushButton>
 #include <QGroupBox>
+#include <QDesktopWidget>
+#include <QApplication>
 
 #include "data/fileio/FileFinder.h"
 
@@ -53,8 +55,9 @@
     subgrid->addWidget(new QLabel(tr("File:")), row, 0);
 
     m_imageEdit = new QLineEdit;
-    m_imageEdit->setReadOnly(true);
     subgrid->addWidget(m_imageEdit, row, 1, 1, 1);
+    connect(m_imageEdit, SIGNAL(textEdited(const QString &)),
+            this, SLOT(imageEditEdited(const QString &)));
 
     QPushButton *browse = new QPushButton(tr("Browse..."));
     connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked()));
@@ -73,6 +76,10 @@
 
     m_imagePreview->setMinimumSize(QSize(100, 100));
 
+    QDesktopWidget *desktop = QApplication::desktop();
+    m_imagePreview->setMaximumSize(QSize((desktop->width() * 2) / 3,
+                                         (desktop->height() * 2) / 3));
+
     grid->addWidget(databox, 0, 0);
     grid->addWidget(previewbox, 1, 0);
 
@@ -133,12 +140,20 @@
 }
 
 void
+ImageDialog::imageEditEdited(const QString &)
+{
+    updatePreview();
+}
+
+void
 ImageDialog::updatePreview()
 {
     if (!m_imagePreview) return;
 
     QString img = m_imageEdit->text();
 
+    m_okButton->setEnabled(img != "");
+
     if (img != m_loadedImageFile) {
         m_loadedImage = QPixmap(img);
         m_loadedImageFile = img;
@@ -150,13 +165,11 @@
 
     if (m_loadedImage.isNull()) {
         m_imagePreview->setPixmap(QPixmap());
-        m_okButton->setEnabled(false);
     } else {
         m_imagePreview->setPixmap(m_loadedImage.scaled
                                   (sz,
                                    Qt::KeepAspectRatio,
                                    Qt::SmoothTransformation));
-        m_okButton->setEnabled(true);
     }
 }