Mercurial > hg > svgui
comparison widgets/ImageDialog.cpp @ 303:46faec7aae12
* Phase 1 of an image layer.
author | Chris Cannam |
---|---|
date | Thu, 04 Oct 2007 16:34:11 +0000 |
parents | |
children | 4b7e8da8f069 |
comparison
equal
deleted
inserted
replaced
302:e9549ea3f825 | 303:46faec7aae12 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2007 QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "ImageDialog.h" | |
17 | |
18 #include <QLineEdit> | |
19 #include <QGridLayout> | |
20 #include <QLabel> | |
21 #include <QDialogButtonBox> | |
22 #include <QPushButton> | |
23 #include <QGroupBox> | |
24 | |
25 #include "data/fileio/FileFinder.h" | |
26 | |
27 ImageDialog::ImageDialog(QString title, | |
28 QString image, | |
29 QString label, | |
30 QWidget *parent) : | |
31 QDialog(parent), | |
32 m_imagePreview(0) | |
33 { | |
34 setWindowTitle(title); | |
35 | |
36 QGridLayout *grid = new QGridLayout; | |
37 setLayout(grid); | |
38 | |
39 QGroupBox *databox = new QGroupBox(tr("Image")); | |
40 | |
41 QGridLayout *subgrid = new QGridLayout; | |
42 databox->setLayout(subgrid); | |
43 | |
44 int row = 0; | |
45 | |
46 subgrid->addWidget(new QLabel(tr("Label:")), row, 0); | |
47 | |
48 m_labelEdit = new QLineEdit; | |
49 subgrid->addWidget(m_labelEdit, row, 1, 1, 2); | |
50 | |
51 ++row; | |
52 | |
53 subgrid->addWidget(new QLabel(tr("File:")), row, 0); | |
54 | |
55 m_imageEdit = new QLineEdit; | |
56 m_imageEdit->setReadOnly(true); | |
57 subgrid->addWidget(m_imageEdit, row, 1, 1, 1); | |
58 | |
59 QPushButton *browse = new QPushButton(tr("Browse...")); | |
60 connect(browse, SIGNAL(clicked()), this, SLOT(browseClicked())); | |
61 subgrid->addWidget(browse, row, 2, 1, 1); | |
62 | |
63 ++row; | |
64 | |
65 QGroupBox *previewbox = new QGroupBox(tr("Preview")); | |
66 | |
67 subgrid = new QGridLayout; | |
68 previewbox->setLayout(subgrid); | |
69 | |
70 m_imagePreview = new QLabel; | |
71 m_imagePreview->setAlignment(Qt::AlignCenter); | |
72 subgrid->addWidget(m_imagePreview, 0, 0); | |
73 | |
74 m_imagePreview->setMinimumSize(QSize(100, 100)); | |
75 | |
76 grid->addWidget(databox, 0, 0); | |
77 grid->addWidget(previewbox, 1, 0); | |
78 | |
79 grid->setRowStretch(1, 10); | |
80 | |
81 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | |
82 QDialogButtonBox::Cancel); | |
83 grid->addWidget(bb, 2, 0, 1, 1); | |
84 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | |
85 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | |
86 | |
87 m_okButton = bb->button(QDialogButtonBox::Ok); | |
88 m_okButton->setEnabled(false); | |
89 | |
90 if (image != "") setImage(image); | |
91 if (label != "") setLabel(label); | |
92 } | |
93 | |
94 ImageDialog::~ImageDialog() | |
95 { | |
96 } | |
97 | |
98 QString | |
99 ImageDialog::getImage() | |
100 { | |
101 return m_loadedImageFile; | |
102 } | |
103 | |
104 QPixmap | |
105 ImageDialog::getPixmap() | |
106 { | |
107 return m_loadedImage; | |
108 } | |
109 | |
110 QString | |
111 ImageDialog::getLabel() | |
112 { | |
113 return m_labelEdit->text(); | |
114 } | |
115 | |
116 void | |
117 ImageDialog::setImage(QString image) | |
118 { | |
119 m_imageEdit->setText(image); | |
120 updatePreview(); | |
121 } | |
122 | |
123 void | |
124 ImageDialog::setLabel(QString label) | |
125 { | |
126 m_labelEdit->setText(label); | |
127 } | |
128 | |
129 void | |
130 ImageDialog::resizeEvent(QResizeEvent *) | |
131 { | |
132 updatePreview(); | |
133 } | |
134 | |
135 void | |
136 ImageDialog::updatePreview() | |
137 { | |
138 if (!m_imagePreview) return; | |
139 | |
140 QString img = m_imageEdit->text(); | |
141 | |
142 if (img != m_loadedImageFile) { | |
143 m_loadedImage = QPixmap(img); | |
144 m_loadedImageFile = img; | |
145 } | |
146 | |
147 QSize sz(m_imagePreview->size()); | |
148 int m = m_imagePreview->margin() * 2; | |
149 sz -= QSize(m, m); | |
150 | |
151 if (m_loadedImage.isNull()) { | |
152 m_imagePreview->setPixmap(QPixmap()); | |
153 m_okButton->setEnabled(false); | |
154 } else { | |
155 m_imagePreview->setPixmap(m_loadedImage.scaled | |
156 (sz, | |
157 Qt::KeepAspectRatio, | |
158 Qt::SmoothTransformation)); | |
159 m_okButton->setEnabled(true); | |
160 } | |
161 } | |
162 | |
163 void | |
164 ImageDialog::browseClicked() | |
165 { | |
166 QString file = | |
167 FileFinder::getInstance()->getOpenFileName(FileFinder::ImageFile); | |
168 | |
169 if (file != "") { | |
170 setImage(file); | |
171 emit imageChanged(file); | |
172 } | |
173 } | |
174 | |
175 | |
176 |