18 #include <QGridLayout>
19 #include <QFileDialog>
33 void QgsPhotoWidgetWrapper::selectFileName()
37 QString fileName = QFileDialog::getOpenFileName( 0,
tr(
"Select a picture" ), QFileInfo( mLineEdit->text() ).absolutePath() );
38 if ( !fileName.isNull() )
39 mLineEdit->setText( QDir::toNativeSeparators( fileName ) );
43 void QgsPhotoWidgetWrapper::loadPixmap(
const QString &fileName )
47 mWebView->setUrl( fileName );
50 QPixmap pm( fileName );
51 if ( !pm.isNull() && mPhotoLabel )
54 if (
size.width() == 0 &&
size.height() > 0 )
56 size.setWidth(
size.height() * pm.size().width() / pm.size().height() );
58 else if (
size.width() > 0 &&
size.height() == 0 )
60 size.setHeight(
size.width() * pm.size().height() / pm.size().width() );
63 pm = pm.scaled(
size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
65 mPhotoLabel->setPixmap( pm );
66 mPhotoLabel->setMinimumSize(
size );
76 if ( mLineEdit->text() == QSettings().value(
"qgis/nullValue",
"NULL" ).toString() )
77 v = QVariant( QVariant::String );
79 v = mLineEdit->text();
87 QWidget* container =
new QWidget( parent );
88 QGridLayout* layout =
new QGridLayout( container );
90 QLabel* label =
new QLabel( parent );
91 label->setObjectName(
"PhotoLabel" );
92 QPushButton* pb =
new QPushButton(
tr(
"..." ), container );
93 pb->setObjectName(
"FileChooserButton" );
95 layout->addWidget( label, 0, 0, 1, 2 );
96 layout->addWidget( le, 1, 0 );
97 layout->addWidget( pb, 1, 1 );
99 container->setLayout( layout );
108 mLineEdit = qobject_cast<QLineEdit*>( editor );
109 mWebView = qobject_cast<QWebView*>( editor );
113 container = mLineEdit->parentWidget();
117 container = mWebView->parentWidget();
118 mLineEdit = container->findChild<QLineEdit*>();
123 mLineEdit = container->findChild<QLineEdit*>();
126 mButton = container->findChild<QPushButton*>(
"FileChooserButton" );
128 mButton = container->findChild<QPushButton*>();
130 mPhotoLabel = container->findChild<QLabel*>(
"PhotoLabel" );
132 mPhotoLabel = container->findChild<QLabel*>();
135 connect( mButton, SIGNAL( clicked() ),
this, SLOT( selectFileName() ) );
146 connect( mLineEdit, SIGNAL( textChanged( QString ) ),
this, SLOT(
valueChanged( QString ) ) );
147 connect( mLineEdit, SIGNAL( textChanged( QString ) ),
this, SLOT( loadPixmap( QString ) ) );
155 if ( value.isNull() )
156 mLineEdit->setText( QSettings().
value(
"qgis/nullValue",
"NULL" ).toString() );
158 mLineEdit->setText( value.toString() );
162 loadPixmap( value.toString() );
169 mLineEdit->setEnabled( enabled );
172 mButton->setEnabled( enabled );