File: optionslayer.cpp

package info (click to toggle)
soundkonverter 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,976 kB
  • ctags: 2,604
  • sloc: cpp: 30,890; sh: 59; xml: 50; makefile: 8
file content (167 lines) | stat: -rw-r--r-- 4,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

#include "optionslayer.h"
#include "options.h"
#include "config.h"

#include <QApplication>
#include <QLayout>
#include <QFrame>

#include <KLocale>

#include <KPushButton>
#include <KIcon>
#include <KMessageBox>
#include <KApplication>


OptionsLayer::OptionsLayer( Config *config, QWidget *parent )
    : QWidget( parent )
{
    const int fontHeight = QFontMetrics(QApplication::font()).boundingRect("M").size().height();

    QGridLayout *gridLayout = new QGridLayout( this );
    gridLayout->setContentsMargins( 2*fontHeight, 2*fontHeight, 2*fontHeight, 2*fontHeight );

    frame = new QFrame( this );
    gridLayout->addWidget( frame, 0, 0 );
    frame->setFrameShape( QFrame::StyledPanel );
    frame->setFrameShadow( QFrame::Raised );
    frame->setAutoFillBackground( true );
    QPalette palette = frame->palette();
    QBrush brush = palette.window();
    QBrush oldBrush = brush;
//     brush.setColor( QColor(230,236,238) ); // 223,230,231
//     brush.setColor( QColor(223,230,231) );
    palette.setBrush( QPalette::Window, brush );
    frame->setPalette( palette );


    QVBoxLayout *frameLayout = new QVBoxLayout( frame );

    options = new Options( config, i18n("Select your desired output options and click on \"Ok\"."), this );
    frameLayout->addWidget( options );


    QHBoxLayout *buttonBox = new QHBoxLayout();
    frameLayout->addLayout( buttonBox );
    buttonBox->addStretch();
    pOk = new KPushButton( KIcon("dialog-ok"), i18n("Ok"), this );
    buttonBox->addWidget( pOk );
    connect( pOk, SIGNAL(clicked()), this, SLOT(ok()) );
    pCancel = new KPushButton( KIcon("dialog-cancel"), i18n("Cancel"), this );
    buttonBox->addWidget( pCancel );
    connect( pCancel, SIGNAL(clicked()), this, SLOT(abort()) );

    palette = options->palette();
    brush = palette.window();
    palette.setBrush( QPalette::Window, brush );
    options->setPalette( palette );

    setAutoFillBackground( true );

    connect( &fadeTimer, SIGNAL(timeout()), this, SLOT(fadeAnim()) );
    fadeAlpha = 0.0f;
}

OptionsLayer::~OptionsLayer()
{}

void OptionsLayer::fadeIn()
{
    pOk->setDisabled( false );
    pCancel->setDisabled( false );

    fadeTimer.start( 50 );
    fadeMode = 1;
    QPalette newPalette = palette();
    newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 0 ) );
    setPalette( newPalette );
    newPalette = frame->palette();
    newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 0 ) );
    frame->setPalette( newPalette );
    frame->hide();
    show();
}

void OptionsLayer::fadeOut()
{
    urls.clear();

    fadeTimer.start( 50 );
    fadeMode = 2;
    frame->hide();
}

void OptionsLayer::fadeAnim()
{
    if( fadeMode == 1 ) fadeAlpha += 255.0f/50.0f*8.0f;
    else if( fadeMode == 2 ) fadeAlpha -= 255.0f/50.0f*8.0f;

    if( fadeAlpha <= 0.0f ) { fadeAlpha = 0.0f; fadeMode = 0; hide(); }
    else if( fadeAlpha >= 255.0f ) { fadeAlpha = 255.0f; fadeMode = 0; frame->show(); }
    else { fadeTimer.start( 50 ); }

    QPalette newPalette = palette();
    newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 192.0f/255.0f*fadeAlpha ) );
    setPalette( newPalette );

    newPalette = frame->palette();
    newPalette.setBrush( QPalette::Window, brushSetAlpha( newPalette.window(), 230.0f/255.0f*fadeAlpha ) );
    frame->setPalette( newPalette );
}

void OptionsLayer::addUrls( const KUrl::List& _urls )
{
    urls += _urls;
}

void OptionsLayer::abort()
{
    fadeOut();
}

void OptionsLayer::ok()
{
    ConversionOptions *conversionOptions = options->currentConversionOptions();
    if( conversionOptions )
    {
        options->accepted();
        pOk->setDisabled( true );
        pCancel->setDisabled( true );
        kapp->processEvents();
        emit done( urls, conversionOptions, command );
        emit saveFileList();
        fadeOut();
    }
    else
    {
        KMessageBox::error( this, i18n("No conversion options selected.") ); // possibly unneeded i18n string
    }
}

void OptionsLayer::setProfile( const QString& profile )
{
    options->setProfile( profile );
}

void OptionsLayer::setFormat( const QString& format )
{
    options->setFormat( format );
}

void OptionsLayer::setOutputDirectory( const QString& directory )
{
    options->setOutputDirectory( directory );
}

void OptionsLayer::setCommand( const QString& _command )
{
    command = _command;
}

void OptionsLayer::setCurrentConversionOptions( const ConversionOptions *conversionOptions )
{
    options->setCurrentConversionOptions( conversionOptions );
}