author | leseb <leseb> | 2002-03-29 22:02:09 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-29 22:02:09 (UTC) |
commit | be017d10da4ccd54b2b3ce030d2ccdc3d0825d62 (patch) (side-by-side diff) | |
tree | d41ddf0ce779d358a9a9bd78c4c32c8de36fce50 /noncore/graphics/drawpad/importdialog.cpp | |
parent | 1c3f2b3a329eac52d2a735d818cd70101376999f (diff) | |
download | opie-be017d10da4ccd54b2b3ce030d2ccdc3d0825d62.zip opie-be017d10da4ccd54b2b3ce030d2ccdc3d0825d62.tar.gz opie-be017d10da4ccd54b2b3ce030d2ccdc3d0825d62.tar.bz2 |
Add image preview in import dialog
Diffstat (limited to 'noncore/graphics/drawpad/importdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/drawpad/importdialog.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/importdialog.cpp b/noncore/graphics/drawpad/importdialog.cpp index 7722417..dc78bf3 100644 --- a/noncore/graphics/drawpad/importdialog.cpp +++ b/noncore/graphics/drawpad/importdialog.cpp @@ -18,3 +18,7 @@ +#include <qcheckbox.h> +#include <qimage.h> +#include <qlabel.h> #include <qlayout.h> +#include <qpushbutton.h> @@ -26,2 +30,3 @@ ImportDialog::ImportDialog(QWidget* parent, const char* name) m_pFileSelector = new FileSelector("image/*", this, "fileselector"); + connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged())); m_pFileSelector->setNewVisible(false); @@ -29,4 +34,29 @@ ImportDialog::ImportDialog(QWidget* parent, const char* name) + m_pPreviewLabel = new QLabel(this); + m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); + m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + m_pPreviewLabel->setFixedSize(114, 114); + m_pPreviewLabel->setBackgroundMode(QWidget:: PaletteMid); + + m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this); + m_pAutomaticPreviewCheckBox->setChecked(true); + + QPushButton* previewPushButton = new QPushButton(tr("Preview"), this); + connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview())); + QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); + QHBoxLayout* previewLayout = new QHBoxLayout(4); + QVBoxLayout* previewSecondLayout = new QVBoxLayout(4); + + previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox); + previewSecondLayout->addWidget(previewPushButton); + previewSecondLayout->addStretch(); + + previewLayout->addWidget(m_pPreviewLabel); + previewLayout->addLayout(previewSecondLayout); + mainLayout->addWidget(m_pFileSelector); + mainLayout->addLayout(previewLayout); + + preview(); } @@ -41 +71,41 @@ const DocLnk* ImportDialog::selected() } + +void ImportDialog::fileChanged() +{ + if (m_pAutomaticPreviewCheckBox->isChecked()) { + preview(); + } +} + +void ImportDialog::preview() +{ + const DocLnk* docLnk = m_pFileSelector->selected(); + + if (docLnk) { + QImage image(docLnk->file()); + + int previewWidth = m_pPreviewLabel->contentsRect().width(); + int previewHeight = m_pPreviewLabel->contentsRect().height(); + + float widthScale = 1.0; + float heightScale = 1.0; + + if (previewWidth < image.width()) { + widthScale = (float)previewWidth / float(image.width()); + } + + if (previewHeight < image.height()) { + heightScale = (float)previewHeight / float(image.height()); + } + + float scale = (widthScale < heightScale ? widthScale : heightScale); + QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); + + QPixmap previewPixmap; + previewPixmap.convertFromImage(previewImage); + + m_pPreviewLabel->setPixmap(previewPixmap); + + delete docLnk; + } +} |