1 2 #include "optionslayer.h" 3 #include "options.h" 4 #include "config.h" 5 6 #include <QApplication> 7 #include <QLayout> 8 #include <QFrame> 9 10 #include <KLocale> 11 12 #include <KPushButton> 13 #include <KIcon> 14 #include <KMessageBox> 15 #include <KApplication> 16 17 18 OptionsLayer::OptionsLayer( Config *config, QWidget *parent ) 19 : QWidget( parent ) 20 { 21 const int fontHeight = QFontMetrics(QApplication::font()).boundingRect("M").size().height(); 22 23 QGridLayout *gridLayout = new QGridLayout( this ); 24 gridLayout->setContentsMargins( 2*fontHeight, 2*fontHeight, 2*fontHeight, 2*fontHeight ); 25 26 frame = new QFrame( this ); 27 gridLayout->addWidget( frame, 0, 0 ); 28 frame->setFrameShape( QFrame::StyledPanel ); 29 frame->setFrameShadow( QFrame::Raised ); 30 frame->setAutoFillBackground( true ); 31 QPalette palette = frame->palette(); 32 QBrush brush = palette.window(); 33 QBrush oldBrush = brush; 34 // brush.setColor( QColor(230,236,238) ); // 223,230,231 35 // brush.setColor( QColor(223,230,231) ); 36 palette.setBrush( QPalette::Window, brush ); 37 frame->setPalette( palette ); 38 39 40 QVBoxLayout *frameLayout = new QVBoxLayout( frame ); 41 42 options = new Options( config, i18n("Select your desired output options and click on \"Ok\"."), this ); 43 frameLayout->addWidget( options ); 44 45 46 QHBoxLayout *buttonBox = new QHBoxLayout(); 47 frameLayout->addLayout( buttonBox ); 48 buttonBox->addStretch(); 49 pOk = new KPushButton( KIcon("dialog-ok"), i18n("Ok"), this ); 50 buttonBox->addWidget( pOk ); 51 connect( pOk, SIGNAL(clicked()), this, SLOT(ok()) ); 52 pCancel = new KPushButton( KIcon("dialog-cancel"), i18n("Cancel"), this ); 53 buttonBox->addWidget( pCancel ); 54 connect( pCancel, SIGNAL(clicked()), this, SLOT(abort()) ); 55 56 palette = options->palette(); 57 brush = palette.window(); 58 palette.setBrush( QPalette::Window, brush ); 59 options->setPalette( palette ); 60 61 setAutoFillBackground( true ); 62 63 connect( &fadeTimer, SIGNAL(timeout()), this, SLOT(fadeAnim()) ); 64 fadeAlpha = 0.0f; 65 } 66 67 OptionsLayer::~OptionsLayer() 68 {} 69 70 void OptionsLayer::fadeIn() 71 { 72 pOk->setDisabled( false ); 73 pCancel->setDisabled( false ); 74 75 fadeTimer.start( 50 ); 76 fadeMode = 1; 77 QPalette newPalette = palette(); 78 newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 0 ) ); 79 setPalette( newPalette ); 80 newPalette = frame->palette(); 81 newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 0 ) ); 82 frame->setPalette( newPalette ); 83 frame->hide(); 84 show(); 85 } 86 87 void OptionsLayer::fadeOut() 88 { 89 urls.clear(); 90 91 fadeTimer.start( 50 ); 92 fadeMode = 2; 93 frame->hide(); 94 } 95 96 void OptionsLayer::fadeAnim() 97 { 98 if( fadeMode == 1 ) fadeAlpha += 255.0f/50.0f*8.0f; 99 else if( fadeMode == 2 ) fadeAlpha -= 255.0f/50.0f*8.0f; 100 101 if( fadeAlpha <= 0.0f ) { fadeAlpha = 0.0f; fadeMode = 0; hide(); } 102 else if( fadeAlpha >= 255.0f ) { fadeAlpha = 255.0f; fadeMode = 0; frame->show(); } 103 else { fadeTimer.start( 50 ); } 104 105 QPalette newPalette = palette(); 106 newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 192.0f/255.0f*fadeAlpha ) ); 107 setPalette( newPalette ); 108 109 newPalette = frame->palette(); 110 newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 230.0f/255.0f*fadeAlpha ) ); 111 frame->setPalette( newPalette ); 112 } 113 114 void OptionsLayer::addUrls( const QList<QUrl>& _urls ) 115 { 116 urls += _urls; 117 } 118 119 void OptionsLayer::abort() 120 { 121 fadeOut(); 122 } 123 124 void OptionsLayer::ok() 125 { 126 ConversionOptions *conversionOptions = options->currentConversionOptions(); 127 if( conversionOptions ) 128 { 129 options->accepted(); 130 pOk->setDisabled( true ); 131 pCancel->setDisabled( true ); 132 kapp->processEvents(); 133 emit done( urls, conversionOptions, command ); 134 emit saveFileList(); 135 fadeOut(); 136 } 137 else 138 { 139 KMessageBox::error( this, i18n("No conversion options selected.") ); // possibly unneeded i18n string 140 } 141 } 142 143 void OptionsLayer::setProfile( const QString& profile ) 144 { 145 options->setProfile( profile ); 146 } 147 148 void OptionsLayer::setFormat( const QString& format ) 149 { 150 options->setFormat( format ); 151 } 152 153 void OptionsLayer::setOutputDirectory( const QString& directory ) 154 { 155 options->setOutputDirectory( directory ); 156 } 157 158 void OptionsLayer::setCommand( const QString& _command ) 159 { 160 command = _command; 161 } 162 163 void OptionsLayer::setCurrentConversionOptions( const ConversionOptions *conversionOptions ) 164 { 165 options->setCurrentConversionOptions( conversionOptions ); 166 } 167 168