Class: QT4::UploadCoverDialog

Inherits:
BaseDialog
  • Object
show all
Defined in:
lib/wiki_lyrics/gui/gui-qt4.rb

Instance Attribute Summary

Attributes inherited from BaseDialog

#values

Instance Method Summary collapse

Methods inherited from BaseDialog

#accepted

Constructor Details

#initialize(values) ⇒ UploadCoverDialog

Returns a new instance of UploadCoverDialog.



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 590

def initialize( values )
	super( values )

	setWindowTitle( I18n.get( "gui.uploadcover.title", values["site_name"] ) )

	album_group = Qt::GroupBox.new( I18n.get( "gui.common.album" ), self )

	artist_label = Qt::Label.new( I18n.get( "gui.common.artist" ), album_group )
	@artist_lineedit = Qt::LineEdit.new( values["artist"], album_group )

	album_label = Qt::Label.new( I18n.get( "gui.common.album" ), album_group )
	@album_lineedit = Qt::LineEdit.new( values["album"], album_group )

	year_label = Qt::Label.new( I18n.get( "gui.common.year" ), album_group )
	@year_spinbox = Qt::SpinBox.new( album_group )
	@year_spinbox.setRange( 1900, Date.today().year() )
	@year_spinbox.setValue( values["year"] )

	image_group = Qt::GroupBox.new( I18n.get( "gui.common.image" ), self )

	image_label = Qt::Label.new( I18n.get( "gui.uploadcover.imagepath" ), image_group )
	@image_path_lineedit = Qt::LineEdit.new( values["image_path"], image_group )
	@image_path_lineedit.setText( values["image_path"] )

	@image_button = Qt::PushButton.new( "...", image_group )
	@image_button.setMaximumWidth( 40 )

	connect( @image_button, SIGNAL( "clicked()" ), self, SLOT( "browse_image()" ) )

	buttons = create_action_buttons()

	album_group_layout = Qt::GridLayout.new()
	album_group_layout.margin = 5
	album_group_layout.spacing = 4
	album_group_layout.setRowStretch( 3, 1 )
	album_group_layout.addWidget( artist_label, 0, 0 )
	album_group_layout.addWidget( @artist_lineedit, 0, 1 )
	album_group_layout.addWidget( album_label, 1, 0 )
	album_group_layout.addWidget( @album_lineedit, 1, 1 )
	album_group_layout.addWidget( year_label, 2, 0 )
	album_group_layout.addWidget( @year_spinbox, 2, 1 )
	album_group.setLayout( album_group_layout )

	image_group_layout = Qt::GridLayout.new()
	image_group_layout.margin = 5
	image_group_layout.spacing = 4
	image_group_layout.setRowStretch( 1, 1 )
	image_group_layout.addWidget( image_label, 0, 0 )
	image_group_layout.addWidget( @image_path_lineedit, 0, 1 )
	image_group_layout.addWidget( @image_button, 0, 2 )
	image_group.setLayout( image_group_layout )

	layout = Qt::VBoxLayout.new( self )
	layout.margin = 4
	layout.spacing = 4
	layout.addWidget( album_group )
	layout.addWidget( image_group )
	layout.addLayout( buttons )

	resize( 350, 100 )
end

Instance Method Details

#acceptObject



669
670
671
672
673
674
675
676
677
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 669

def accept()
	@values = {
		"artist"		=> @artist_lineedit.text(),
		"album"			=> @album_lineedit.text(),
		"year"			=> @year_spinbox.value(),
		"image_path"	=> @image_path_lineedit.text()
	}
	super()
end

#browse_imageObject



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/wiki_lyrics/gui/gui-qt4.rb', line 652

def browse_image()
	dirname = @image_path_lineedit.text().strip()
	dirname = QT4.empty_string?( dirname ) ? (ENV["HOME"] ? ENV["HOME"] : ".") : File.dirname( dirname )
	dialog = Qt::FileDialog.new()
	dialog.setWindowTitle( I18n.get( "gui.uploadcover.browseimage.title" ) )
	dialog.setFilters( [
		I18n.get( "gui.uploadcover.browseimage.images" ) + " (*.jpg *.JPG *.png *.PNG *.bmp *.BMP)",
		I18n.get( "gui.uploadcover.browseimage.allfiles" ) + " (*)"
	] )
	dialog.setDirectory( dirname )
	dialog.setFileMode( Qt::FileDialog::ExistingFile )
	 if dialog.exec() == Qt::Dialog::Accepted
      		image_path = dialog.selectedFiles()[0]
		@image_path_lineedit.setText( image_path.strip() ) if ! QT4.empty_string?( image_path )
	end
end