-rw-r--r-- | noncore/graphics/drawpad/drawpad.h | 2 | ||||
-rw-r--r-- | noncore/graphics/drawpad/importdialog.cpp | 70 | ||||
-rw-r--r-- | noncore/graphics/drawpad/importdialog.h | 9 |
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 @@ | |||
13 | 13 | ||
14 | #ifndef DRAWPAD_H | 14 | #ifndef DRAWPAD_H |
15 | #define DRAWPAD_H | 15 | #define DRAWPAD_H |
16 | 16 | ||
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | 18 | ||
19 | #include <qpen.h> | 19 | #include <qpen.h> |
20 | 20 | ||
21 | class Tool; | ||
22 | class DrawPadCanvas; | 21 | class DrawPadCanvas; |
22 | class Tool; | ||
23 | 23 | ||
24 | class QAction; | 24 | class QAction; |
25 | class QColor; | 25 | class QColor; |
26 | class QToolButton; | 26 | class QToolButton; |
27 | class QWidgetStack; | 27 | class QWidgetStack; |
28 | 28 | ||
29 | class DrawPad : public QMainWindow | 29 | class DrawPad : public QMainWindow |
30 | { | 30 | { |
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 @@ | |||
11 | * * | 11 | * * |
12 | ***************************************************************************/ | 12 | ***************************************************************************/ |
13 | 13 | ||
14 | #include "importdialog.h" | 14 | #include "importdialog.h" |
15 | 15 | ||
16 | #include <qpe/applnk.h> | 16 | #include <qpe/applnk.h> |
17 | #include <qpe/fileselector.h> | 17 | #include <qpe/fileselector.h> |
18 | 18 | ||
19 | #include <qcheckbox.h> | ||
20 | #include <qimage.h> | ||
21 | #include <qlabel.h> | ||
19 | #include <qlayout.h> | 22 | #include <qlayout.h> |
23 | #include <qpushbutton.h> | ||
20 | 24 | ||
21 | ImportDialog::ImportDialog(QWidget* parent, const char* name) | 25 | ImportDialog::ImportDialog(QWidget* parent, const char* name) |
22 | : QDialog(parent, name, true) | 26 | : QDialog(parent, name, true) |
23 | { | 27 | { |
24 | setCaption(tr("Import")); | 28 | setCaption(tr("Import")); |
25 | 29 | ||
26 | m_pFileSelector = new FileSelector("image/*", this, "fileselector"); | 30 | m_pFileSelector = new FileSelector("image/*", this, "fileselector"); |
31 | connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged())); | ||
27 | m_pFileSelector->setNewVisible(false); | 32 | m_pFileSelector->setNewVisible(false); |
28 | m_pFileSelector->setCloseVisible(false); | 33 | m_pFileSelector->setCloseVisible(false); |
29 | 34 | ||
35 | m_pPreviewLabel = new QLabel(this); | ||
36 | m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); | ||
37 | m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); | ||
38 | m_pPreviewLabel->setFixedSize(114, 114); | ||
39 | m_pPreviewLabel->setBackgroundMode(QWidget:: PaletteMid); | ||
40 | |||
41 | m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this); | ||
42 | m_pAutomaticPreviewCheckBox->setChecked(true); | ||
43 | |||
44 | QPushButton* previewPushButton = new QPushButton(tr("Preview"), this); | ||
45 | connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview())); | ||
46 | |||
30 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 47 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
48 | QHBoxLayout* previewLayout = new QHBoxLayout(4); | ||
49 | QVBoxLayout* previewSecondLayout = new QVBoxLayout(4); | ||
50 | |||
51 | previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox); | ||
52 | previewSecondLayout->addWidget(previewPushButton); | ||
53 | previewSecondLayout->addStretch(); | ||
54 | |||
55 | previewLayout->addWidget(m_pPreviewLabel); | ||
56 | previewLayout->addLayout(previewSecondLayout); | ||
57 | |||
31 | mainLayout->addWidget(m_pFileSelector); | 58 | mainLayout->addWidget(m_pFileSelector); |
59 | mainLayout->addLayout(previewLayout); | ||
60 | |||
61 | preview(); | ||
32 | } | 62 | } |
33 | 63 | ||
34 | ImportDialog::~ImportDialog() | 64 | ImportDialog::~ImportDialog() |
35 | { | 65 | { |
36 | } | 66 | } |
37 | 67 | ||
38 | const DocLnk* ImportDialog::selected() | 68 | const DocLnk* ImportDialog::selected() |
39 | { | 69 | { |
40 | return m_pFileSelector->selected(); | 70 | return m_pFileSelector->selected(); |
41 | } | 71 | } |
72 | |||
73 | void ImportDialog::fileChanged() | ||
74 | { | ||
75 | if (m_pAutomaticPreviewCheckBox->isChecked()) { | ||
76 | preview(); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | void ImportDialog::preview() | ||
81 | { | ||
82 | const DocLnk* docLnk = m_pFileSelector->selected(); | ||
83 | |||
84 | if (docLnk) { | ||
85 | QImage image(docLnk->file()); | ||
86 | |||
87 | int previewWidth = m_pPreviewLabel->contentsRect().width(); | ||
88 | int previewHeight = m_pPreviewLabel->contentsRect().height(); | ||
89 | |||
90 | float widthScale = 1.0; | ||
91 | float heightScale = 1.0; | ||
92 | |||
93 | if (previewWidth < image.width()) { | ||
94 | widthScale = (float)previewWidth / float(image.width()); | ||
95 | } | ||
96 | |||
97 | if (previewHeight < image.height()) { | ||
98 | heightScale = (float)previewHeight / float(image.height()); | ||
99 | } | ||
100 | |||
101 | float scale = (widthScale < heightScale ? widthScale : heightScale); | ||
102 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | ||
103 | |||
104 | QPixmap previewPixmap; | ||
105 | previewPixmap.convertFromImage(previewImage); | ||
106 | |||
107 | m_pPreviewLabel->setPixmap(previewPixmap); | ||
108 | |||
109 | delete docLnk; | ||
110 | } | ||
111 | } | ||
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 @@ | |||
14 | #ifndef IMPORTDIALOG_H | 14 | #ifndef IMPORTDIALOG_H |
15 | #define IMPORTDIALOG_H | 15 | #define IMPORTDIALOG_H |
16 | 16 | ||
17 | #include <qdialog.h> | 17 | #include <qdialog.h> |
18 | 18 | ||
19 | class DocLnk; | 19 | class DocLnk; |
20 | class FileSelector; | 20 | class FileSelector; |
21 | 21 | ||
22 | class QCheckBox; | ||
23 | class QLabel; | ||
24 | |||
22 | class ImportDialog : public QDialog | 25 | class ImportDialog : public QDialog |
23 | { | 26 | { |
24 | Q_OBJECT | 27 | Q_OBJECT |
25 | 28 | ||
26 | public: | 29 | public: |
27 | ImportDialog(QWidget* parent = 0, const char* name = 0); | 30 | ImportDialog(QWidget* parent = 0, const char* name = 0); |
28 | ~ImportDialog(); | 31 | ~ImportDialog(); |
29 | 32 | ||
30 | const DocLnk* selected(); | 33 | const DocLnk* selected(); |
31 | 34 | ||
35 | private slots: | ||
36 | void fileChanged(); | ||
37 | void preview(); | ||
38 | |||
32 | private: | 39 | private: |
33 | FileSelector* m_pFileSelector; | 40 | FileSelector* m_pFileSelector; |
41 | QLabel* m_pPreviewLabel; | ||
42 | QCheckBox* m_pAutomaticPreviewCheckBox; | ||
34 | }; | 43 | }; |
35 | 44 | ||
36 | #endif // IMPORTDIALOG_H | 45 | #endif // IMPORTDIALOG_H |