summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/drawpad.h2
-rw-r--r--noncore/graphics/drawpad/importdialog.cpp70
-rw-r--r--noncore/graphics/drawpad/importdialog.h9
3 files changed, 80 insertions, 1 deletions
diff --git a/noncore/graphics/drawpad/drawpad.h b/noncore/graphics/drawpad/drawpad.h
index fbe67b8..62a73c9 100644
--- a/noncore/graphics/drawpad/drawpad.h
+++ b/noncore/graphics/drawpad/drawpad.h
@@ -13,18 +13,18 @@
#ifndef DRAWPAD_H
#define DRAWPAD_H
#include <qmainwindow.h>
#include <qpen.h>
-class Tool;
class DrawPadCanvas;
+class Tool;
class QAction;
class QColor;
class QToolButton;
class QWidgetStack;
class DrawPad : public QMainWindow
{
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
@@ -11,31 +11,101 @@
* *
***************************************************************************/
#include "importdialog.h"
#include <qpe/applnk.h>
#include <qpe/fileselector.h>
+#include <qcheckbox.h>
+#include <qimage.h>
+#include <qlabel.h>
#include <qlayout.h>
+#include <qpushbutton.h>
ImportDialog::ImportDialog(QWidget* parent, const char* name)
: QDialog(parent, name, true)
{
setCaption(tr("Import"));
m_pFileSelector = new FileSelector("image/*", this, "fileselector");
+ connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged()));
m_pFileSelector->setNewVisible(false);
m_pFileSelector->setCloseVisible(false);
+ 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();
}
ImportDialog::~ImportDialog()
{
}
const DocLnk* ImportDialog::selected()
{
return m_pFileSelector->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;
+ }
+}
diff --git a/noncore/graphics/drawpad/importdialog.h b/noncore/graphics/drawpad/importdialog.h
index 1c67145..ef51d7c 100644
--- a/noncore/graphics/drawpad/importdialog.h
+++ b/noncore/graphics/drawpad/importdialog.h
@@ -14,23 +14,32 @@
#ifndef IMPORTDIALOG_H
#define IMPORTDIALOG_H
#include <qdialog.h>
class DocLnk;
class FileSelector;
+class QCheckBox;
+class QLabel;
+
class ImportDialog : public QDialog
{
Q_OBJECT
public:
ImportDialog(QWidget* parent = 0, const char* name = 0);
~ImportDialog();
const DocLnk* selected();
+private slots:
+ void fileChanged();
+ void preview();
+
private:
FileSelector* m_pFileSelector;
+ QLabel* m_pPreviewLabel;
+ QCheckBox* m_pAutomaticPreviewCheckBox;
};
#endif // IMPORTDIALOG_H