File indexing completed on 2024-05-05 04:51:49

0001 /*
0002     SPDX-FileCopyrightText: 2009 Michal Malek <michalm@jabster.pl>
0003     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "k3bvolumenamewidget.h"
0009 #include "k3bdatadoc.h"
0010 #include "k3bisooptions.h"
0011 #include "k3bvalidators.h"
0012 
0013 #include <KLineEdit>
0014 #include <KLocalizedString>
0015 
0016 #include <QEvent>
0017 #include <QHBoxLayout>
0018 #include <QLabel>
0019 
0020 namespace K3b {
0021 
0022 class VolumeNameWidget::Private
0023 {
0024 public:
0025     DataDoc* doc;
0026     KLineEdit* volumeNameEdit;
0027 
0028     void fontChanged( const QFontMetrics& fontMetrics );
0029 };
0030 
0031 
0032 void VolumeNameWidget::Private::fontChanged( const QFontMetrics& fontMetrics )
0033 {
0034     volumeNameEdit->setMaximumWidth( fontMetrics.boundingRect('A').width()*50 );
0035 }
0036 
0037 
0038 VolumeNameWidget::VolumeNameWidget( DataDoc* doc, QWidget* parent )
0039     : QWidget( parent ),
0040       d( new Private )
0041 {
0042     d->doc = doc;
0043 
0044     d->volumeNameEdit = new KLineEdit( doc->isoOptions().volumeID(), this );
0045     d->volumeNameEdit->setValidator( new Latin1Validator( d->volumeNameEdit ) );
0046     d->volumeNameEdit->setClearButtonEnabled( true );
0047     d->fontChanged( fontMetrics() );
0048 
0049     QHBoxLayout* layout = new QHBoxLayout( this );
0050     layout->addWidget( new QLabel( i18n("Volume Name:"), this ), 1, Qt::AlignRight );
0051     layout->addWidget( d->volumeNameEdit, 2 );
0052     layout->setContentsMargins( 0, 0, 0, 0 );
0053 
0054     connect( d->volumeNameEdit, SIGNAL(textChanged(QString)),
0055              d->doc, SLOT(setVolumeID(QString)) );
0056     connect( d->doc, SIGNAL(changed()),
0057              this, SLOT(slotDocChanged()) );
0058 }
0059 
0060 
0061 VolumeNameWidget::~VolumeNameWidget()
0062 {
0063     delete d;
0064 }
0065 
0066 
0067 void VolumeNameWidget::changeEvent( QEvent* event )
0068 {
0069     if( event->type() == QEvent::FontChange ) {
0070         d->fontChanged( fontMetrics() );
0071     }
0072     QWidget::changeEvent( event );
0073 }
0074 
0075 
0076 void VolumeNameWidget::slotDocChanged()
0077 {
0078     // do not update the editor in case it changed the volume id itself
0079     if( d->doc->isoOptions().volumeID() != d->volumeNameEdit->text() )
0080         d->volumeNameEdit->setText( d->doc->isoOptions().volumeID() );
0081 }
0082 
0083 } // namespace K3b
0084 
0085 #include "moc_k3bvolumenamewidget.cpp"