28 #include <QFileDialog>
29 #include <QGraphicsPixmapItem>
31 #include <QMessageBox>
32 #include <QPushButton>
49 void BackgroundDialog::BrowseImage()
51 QString lastFile = m_file_path->text().isEmpty() ? QDir::homePath() : QFileInfo(m_file_path->text()).absolutePath();
53 QString filePath = QFileDialog::getOpenFileName(
this,
"Select the background image file to load", lastFile,
"Images (*.png *.xpm *.jpg *.bmp);;All files (*.*)",
nullptr, QFileDialog::DontUseNativeDialog | QFileDialog::ReadOnly);
55 if (!filePath.isEmpty() && filePath != m_file_path->text()) {
56 if (m_pixmap.load(filePath)) {
57 m_item->setPixmap(m_pixmap);
58 UpdateTransformation();
59 m_file_path->setText(filePath);
60 m_visible->setEnabled(
true);
61 m_visible->setChecked(
true);
62 m_transformation->setEnabled(
true);
64 QMessageBox::critical(
this,
"Error",
"Couldn't load the image", QMessageBox::Ok);
65 m_visible->setEnabled(
false);
66 m_transformation->setEnabled(
false);
71 void BackgroundDialog::UpdateVisibility(
bool visible)
73 m_item->setVisible(visible);
74 m_transformation->setEnabled(visible);
77 void BackgroundDialog::UpdateTransformation()
79 QTransform transformation;
81 QPointF center = m_item->boundingRect().center();
84 transformation.rotate(m_transformation->
GetRotation());
87 transformation.translate(-center.x(), -center.y());
89 m_item->setTransform(transformation);
92 void BackgroundDialog::SetupGui()
94 setWindowTitle(
"Set background image");
98 QVBoxLayout *layout =
new QVBoxLayout();
101 QHBoxLayout *fileLayout =
new QHBoxLayout();
103 m_file_path =
new QLineEdit();
104 m_file_path->setReadOnly(
true);
105 fileLayout->addWidget(m_file_path);
107 QPushButton *browseButton =
new QPushButton(
"Browse...");
108 connect(browseButton, SIGNAL(clicked()),
this, SLOT(BrowseImage()));
109 fileLayout->addWidget(browseButton);
111 layout->addLayout(fileLayout);
115 m_visible =
new QCheckBox(
"Display image");
116 m_visible->setEnabled(
false);
117 m_visible->setChecked(
false);
118 connect(m_visible, SIGNAL(toggled(
bool)),
this, SLOT(UpdateVisibility(
bool)));
119 layout->addWidget(m_visible);
123 m_transformation =
new TransformationWidget(10, 3 * std::max(m_item->boundingRect().width(), 200.0), 3 * std::max(m_item->boundingRect().height(), 200.0));
124 m_transformation->setEnabled(
false);
125 connect(m_transformation, SIGNAL(TransformationChanged()),
this, SLOT(UpdateTransformation()));
126 layout->addWidget(m_transformation);
Namespace for SimPT tissue editor package.
BackgroundDialog(QGraphicsPixmapItem *item, QWidget *parent=nullptr)
Constructor.
virtual ~BackgroundDialog()
Destructor.
double GetTranslationY()
Gets the y translation of the transformation.
Interface for TransformationWidget.
int GetRotation()
Gets the rotation of the transformation.
double GetScalingX()
Gets the x scaling of the transformation.
double GetTranslationX()
Gets the x translation of the transformation.
double GetScalingY()
Gets the y scaling of the transformation.
Interface for BackgroundDialog.
see the online Qt documentation
see the online Qt documentation