Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

importdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   DrawPad - a drawing program for Opie Environment                      *
00004  *                                                                         *
00005  *   (C) 2002 by S. Prud'homme <prudhomme@laposte.net>                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "importdialog.h"
00015 
00016 #include <qpe/mimetype.h>
00017 
00018 #include <qcheckbox.h>
00019 #include <qimage.h>
00020 #include <qlabel.h>
00021 #include <qlayout.h>
00022 #include <qpushbutton.h>
00023 
00024 using namespace Opie::Ui;
00025 ImportDialog::ImportDialog(QWidget* parent, const char* name)
00026     : QDialog(parent, name, true)
00027 {
00028     setCaption(tr("DrawPad - Import"));
00029 
00030     MimeTypes types; types.insert( tr("All images"),"image/*" );
00031     m_pFileSelector = new OFileSelector(this,
00032                                         OFileSelector::FileSelector,
00033                                         OFileSelector::Normal,
00034                                         QString::null,
00035                                         QString::null, types );
00036     m_pFileSelector->setNameVisible( false );
00037     connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged()));
00038 
00039     m_pPreviewLabel = new QLabel(this);
00040     m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00041     m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
00042     m_pPreviewLabel->setFixedSize(114, 114);
00043     m_pPreviewLabel->setBackgroundMode(QWidget::PaletteMid);
00044 
00045     m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this);
00046     m_pAutomaticPreviewCheckBox->setChecked(true);
00047 
00048     QPushButton* previewPushButton = new QPushButton(tr("Preview"), this);
00049     connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview()));
00050 
00051     QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
00052     QHBoxLayout* previewLayout = new QHBoxLayout(4);
00053     QVBoxLayout* previewSecondLayout = new QVBoxLayout(4);
00054 
00055     previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox);
00056     previewSecondLayout->addWidget(previewPushButton);
00057     previewSecondLayout->addStretch();
00058 
00059     previewLayout->addWidget(m_pPreviewLabel);
00060     previewLayout->addLayout(previewSecondLayout);
00061 
00062     mainLayout->addWidget(m_pFileSelector);
00063     mainLayout->addLayout(previewLayout);
00064 
00065     preview();
00066 }
00067 
00068 ImportDialog::~ImportDialog()
00069 {
00070 }
00071 
00072 const DocLnk* ImportDialog::selected()
00073 {
00074     // FIXME change from pointer to reference -zecke
00075     DocLnk *lnk = new DocLnk( m_pFileSelector->selectedDocument() );
00076     return lnk;
00077 }
00078 
00079 void ImportDialog::fileChanged()
00080 {
00081     if (m_pAutomaticPreviewCheckBox->isChecked()) {
00082         preview();
00083     }
00084 }
00085 
00086 void ImportDialog::preview()
00087 {
00088     const DocLnk* docLnk = selected();
00089 
00090     if (docLnk) {
00091         QImage image(docLnk->file());
00092 
00093         int previewWidth = m_pPreviewLabel->contentsRect().width();
00094         int previewHeight = m_pPreviewLabel->contentsRect().height();
00095 
00096         float widthScale = 1.0;
00097         float heightScale = 1.0;
00098 
00099         if (previewWidth < image.width()) {
00100             widthScale = (float)previewWidth / float(image.width());
00101         }
00102 
00103         if (previewHeight < image.height()) {
00104             heightScale = (float)previewHeight / float(image.height());
00105         }
00106 
00107         float scale = (widthScale < heightScale ? widthScale : heightScale);
00108         QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
00109 
00110         QPixmap previewPixmap;
00111         previewPixmap.convertFromImage(previewImage);
00112 
00113         m_pPreviewLabel->setPixmap(previewPixmap);
00114 
00115         delete docLnk;
00116     }
00117 }

Generated on Sat Nov 5 16:17:29 2005 for OPIE by  doxygen 1.4.2