-rw-r--r-- | noncore/graphics/drawpad/importdialog.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/noncore/graphics/drawpad/importdialog.cpp b/noncore/graphics/drawpad/importdialog.cpp index 0783ed8..1c447cb 100644 --- a/noncore/graphics/drawpad/importdialog.cpp +++ b/noncore/graphics/drawpad/importdialog.cpp | |||
@@ -22,90 +22,92 @@ | |||
22 | #include <qlayout.h> | 22 | #include <qlayout.h> |
23 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
24 | 24 | ||
25 | ImportDialog::ImportDialog(QWidget* parent, const char* name) | 25 | ImportDialog::ImportDialog(QWidget* parent, const char* name) |
26 | : QDialog(parent, name, true) | 26 | : QDialog(parent, name, true) |
27 | { | 27 | { |
28 | setCaption(tr("DrawPad - Import")); | 28 | setCaption(tr("DrawPad - Import")); |
29 | 29 | ||
30 | 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())); | 31 | connect(m_pFileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(fileChanged())); |
32 | m_pFileSelector->setNewVisible(false); | 32 | m_pFileSelector->setNewVisible(false); |
33 | m_pFileSelector->setCloseVisible(false); | 33 | m_pFileSelector->setCloseVisible(false); |
34 | 34 | ||
35 | m_pPreviewLabel = new QLabel(this); | 35 | m_pPreviewLabel = new QLabel(this); |
36 | m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 36 | m_pPreviewLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
37 | m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); | 37 | m_pPreviewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); |
38 | m_pPreviewLabel->setFixedSize(114, 114); | 38 | m_pPreviewLabel->setFixedSize(114, 114); |
39 | m_pPreviewLabel->setBackgroundMode(QWidget::PaletteMid); | 39 | m_pPreviewLabel->setBackgroundMode(QWidget::PaletteMid); |
40 | 40 | ||
41 | m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this); | 41 | m_pAutomaticPreviewCheckBox = new QCheckBox(tr("Automatic preview"), this); |
42 | m_pAutomaticPreviewCheckBox->setChecked(true); | 42 | m_pAutomaticPreviewCheckBox->setChecked(true); |
43 | 43 | ||
44 | QPushButton* previewPushButton = new QPushButton(tr("Preview"), this); | 44 | QPushButton* previewPushButton = new QPushButton(tr("Preview"), this); |
45 | connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview())); | 45 | connect(previewPushButton, SIGNAL(clicked()), this, SLOT(preview())); |
46 | 46 | ||
47 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); | 47 | QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); |
48 | QHBoxLayout* previewLayout = new QHBoxLayout(4); | 48 | QHBoxLayout* previewLayout = new QHBoxLayout(4); |
49 | QVBoxLayout* previewSecondLayout = new QVBoxLayout(4); | 49 | QVBoxLayout* previewSecondLayout = new QVBoxLayout(4); |
50 | 50 | ||
51 | previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox); | 51 | previewSecondLayout->addWidget(m_pAutomaticPreviewCheckBox); |
52 | previewSecondLayout->addWidget(previewPushButton); | 52 | previewSecondLayout->addWidget(previewPushButton); |
53 | previewSecondLayout->addStretch(); | 53 | previewSecondLayout->addStretch(); |
54 | 54 | ||
55 | previewLayout->addWidget(m_pPreviewLabel); | 55 | previewLayout->addWidget(m_pPreviewLabel); |
56 | previewLayout->addLayout(previewSecondLayout); | 56 | previewLayout->addLayout(previewSecondLayout); |
57 | 57 | ||
58 | mainLayout->addWidget(m_pFileSelector); | 58 | mainLayout->addWidget(m_pFileSelector); |
59 | mainLayout->addLayout(previewLayout); | 59 | mainLayout->addLayout(previewLayout); |
60 | 60 | ||
61 | preview(); | 61 | preview(); |
62 | } | 62 | } |
63 | 63 | ||
64 | ImportDialog::~ImportDialog() | 64 | ImportDialog::~ImportDialog() |
65 | { | 65 | { |
66 | } | 66 | } |
67 | 67 | ||
68 | const DocLnk* ImportDialog::selected() | 68 | const DocLnk* ImportDialog::selected() |
69 | { | 69 | { |
70 | return m_pFileSelector->selected(); | 70 | // FIXME change from pointer to reference -zecke |
71 | DocLnk *lnk = new DocLnk( m_pFileSelector->selectedDocument() ); | ||
72 | return lnk; | ||
71 | } | 73 | } |
72 | 74 | ||
73 | void ImportDialog::fileChanged() | 75 | void ImportDialog::fileChanged() |
74 | { | 76 | { |
75 | if (m_pAutomaticPreviewCheckBox->isChecked()) { | 77 | if (m_pAutomaticPreviewCheckBox->isChecked()) { |
76 | preview(); | 78 | preview(); |
77 | } | 79 | } |
78 | } | 80 | } |
79 | 81 | ||
80 | void ImportDialog::preview() | 82 | void ImportDialog::preview() |
81 | { | 83 | { |
82 | const DocLnk* docLnk = m_pFileSelector->selected(); | 84 | const DocLnk* docLnk = selected(); |
83 | 85 | ||
84 | if (docLnk) { | 86 | if (docLnk) { |
85 | QImage image(docLnk->file()); | 87 | QImage image(docLnk->file()); |
86 | 88 | ||
87 | int previewWidth = m_pPreviewLabel->contentsRect().width(); | 89 | int previewWidth = m_pPreviewLabel->contentsRect().width(); |
88 | int previewHeight = m_pPreviewLabel->contentsRect().height(); | 90 | int previewHeight = m_pPreviewLabel->contentsRect().height(); |
89 | 91 | ||
90 | float widthScale = 1.0; | 92 | float widthScale = 1.0; |
91 | float heightScale = 1.0; | 93 | float heightScale = 1.0; |
92 | 94 | ||
93 | if (previewWidth < image.width()) { | 95 | if (previewWidth < image.width()) { |
94 | widthScale = (float)previewWidth / float(image.width()); | 96 | widthScale = (float)previewWidth / float(image.width()); |
95 | } | 97 | } |
96 | 98 | ||
97 | if (previewHeight < image.height()) { | 99 | if (previewHeight < image.height()) { |
98 | heightScale = (float)previewHeight / float(image.height()); | 100 | heightScale = (float)previewHeight / float(image.height()); |
99 | } | 101 | } |
100 | 102 | ||
101 | float scale = (widthScale < heightScale ? widthScale : heightScale); | 103 | float scale = (widthScale < heightScale ? widthScale : heightScale); |
102 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); | 104 | QImage previewImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); |
103 | 105 | ||
104 | QPixmap previewPixmap; | 106 | QPixmap previewPixmap; |
105 | previewPixmap.convertFromImage(previewImage); | 107 | previewPixmap.convertFromImage(previewImage); |
106 | 108 | ||
107 | m_pPreviewLabel->setPixmap(previewPixmap); | 109 | m_pPreviewLabel->setPixmap(previewPixmap); |
108 | 110 | ||
109 | delete docLnk; | 111 | delete docLnk; |
110 | } | 112 | } |
111 | } | 113 | } |