~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to aktion/principal.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <qdir.h>
 
2
 
 
3
#include "principal.h"
 
4
 
 
5
#include <iostream.h>
 
6
#include <kconfig.h>
 
7
 
 
8
#include <kglobal.h>
 
9
#include <kiconloader.h>
 
10
#include <klocale.h>
 
11
#include <kapp.h>
 
12
#include <kmessagebox.h>
 
13
#include <kfiledialog.h>
 
14
#include <kstddirs.h>
 
15
#include <kseparator.h>
 
16
 
 
17
#include <qtoolbutton.h>
 
18
#include <qiconset.h>
 
19
#include <qlabel.h>
 
20
#include <qtooltip.h>
 
21
#include <qslider.h>
 
22
#include <qtimer.h>
 
23
#include <qlayout.h>
 
24
#include <qdropsite.h>
 
25
#include <qdragobject.h>
 
26
 
 
27
#ifdef XF86_VM
 
28
#include <unistd.h>
 
29
#include <aktionVm.h>
 
30
#endif
 
31
 
 
32
#include "kxanim.h"
 
33
#include "aktionConf.h"
 
34
 
 
35
#include <kwin.h>
 
36
 
 
37
Principal::Principal( const char *name)
 
38
        : KMainWindow(0, name, 0)
 
39
{
 
40
        setCaption("aKtion!");
 
41
 
 
42
        config=KGlobal::config();
 
43
 
 
44
        QWidget *mainwidget=new QWidget(this);
 
45
 
 
46
        setCentralWidget(mainwidget);
 
47
 
 
48
        setAcceptDrops(true);
 
49
 
 
50
        loader = KGlobal::iconLoader();
 
51
 
 
52
        timer = new QTimer(this, "timer");
 
53
 
 
54
        menu = new QPopupMenu(0L, "menu");
 
55
        menu->insertItem(i18n("Video information"),this,SLOT(click_info()) );
 
56
        menu->insertSeparator();
 
57
        menu->insertItem(SmallIconSet("fileopen"),
 
58
                         i18n("Open file..."),this,SLOT(click_open()) );
 
59
        menu->insertItem(SmallIconSet("configure"),
 
60
                         i18n("Setup..."),this,SLOT(click_config()) );
 
61
        menu->insertSeparator();
 
62
        menu->insertItem(SmallIconSet("original"),
 
63
                         i18n("Original size"),this,SLOT(click_original()) );
 
64
        menu->insertItem(SmallIconSet("half"),
 
65
                         i18n("Half size"),this,SLOT(click_half()) );
 
66
        menu->insertItem(SmallIconSet("double"),
 
67
                         i18n("Double size"),this,SLOT(click_double()) );
 
68
        menu->insertItem(SmallIconSet("ak_maximize"),
 
69
                         i18n("Maximized"),this,SLOT(maximize()) );
 
70
        menuItemFullScreen = menu->insertItem(SmallIconSet("fullscreen"),
 
71
                         i18n("Full screen"),this,SLOT(goFullScreen()) );
 
72
 
 
73
#ifdef XF86_VM
 
74
        videoMode=new aktionVm(mainwidget);
 
75
        inVmMode=false;
 
76
#endif
 
77
        videoContainer=new QWidget(mainwidget);
 
78
        videoContainer->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
 
79
        video = new KXAnim(videoContainer, "video");
 
80
 
 
81
        video->move(0,0);
 
82
        video->hide();
 
83
        video->setAutoResize(false);
 
84
 
 
85
        /* set the logo */
 
86
        logoWidget = new QLabel( mainwidget, "logo");
 
87
        logoWidget->setAutoResize(true);
 
88
        logoWidget->setPixmap( QPixmap(locate("data","aktion/toolbar/aktion_logo.png")) );
 
89
 
 
90
        line = new KSeparator( KSeparator::HLine, mainwidget);
 
91
 
 
92
        volumeSlider = new QSlider(mainwidget);
 
93
        volumeSlider->hide();
 
94
        volumeSlider->setOrientation(QSlider::Horizontal);
 
95
        volumeSlider->setRange(0,100);
 
96
        volumeSlider->setSteps(1,20);
 
97
        volumeSlider->setTickmarks( QSlider::Right );
 
98
        volumeSlider->setTickInterval(10);
 
99
        volumeSlider->setTracking(true);
 
100
        volumeSlider->setMaximumWidth(120);
 
101
 
 
102
        QToolTip::add(volumeSlider,i18n("Volume"));
 
103
        config->setGroup("audio");
 
104
        volumeSlider->setValue(config->readNumEntry("audioInitialVolume"));
 
105
 
 
106
        if (config->readBoolEntry("showVolumeSlider")==true) volumeSlider->show();
 
107
 
 
108
 
 
109
        abrir = new QToolButton(mainwidget, "abrir");
 
110
        abrir->setIconSet(MainBarIconSet("fileopen"));
 
111
        QToolTip::add(abrir,i18n("Open file"));
 
112
 
 
113
        tocar = new QToolButton(mainwidget, "tocar");
 
114
        tocar->setIconSet(MainBarIconSet("1rightarrow"));
 
115
        QToolTip::add(tocar,i18n("Play"));
 
116
 
 
117
        parar = new QToolButton(mainwidget, "parar");
 
118
        parar->setIconSet(MainBarIconSet("player_stop"));
 
119
        QToolTip::add(parar,i18n("Stop"));
 
120
 
 
121
        avanzar = new QToolButton(mainwidget, "avanzar");
 
122
        avanzar->setIconSet(MainBarIconSet("2rightarrow"));
 
123
        avanzar->setAutoRepeat( true );
 
124
        QToolTip::add(avanzar,i18n("Forward"));
 
125
 
 
126
        retroceder = new QToolButton(mainwidget, "retroceder");
 
127
        retroceder->setIconSet(MainBarIconSet("2leftarrow"));
 
128
        retroceder->setAutoRepeat( true );
 
129
        QToolTip::add(retroceder,i18n("Backward"));
 
130
 
 
131
        ayuda = new QToolButton(mainwidget, "ayuda");
 
132
        ayuda->setIconSet(MainBarIconSet("help"));
 
133
        QToolTip::add(ayuda,i18n("Help"));
 
134
 
 
135
        configB = new QToolButton(mainwidget, "Setup");
 
136
        configB->setIconSet(MainBarIconSet("configure"));
 
137
        QToolTip::add(configB,i18n("Setup"));
 
138
 
 
139
        connect(abrir,SIGNAL(clicked()),
 
140
                 this,SLOT(click_open()) );
 
141
        connect(ayuda,SIGNAL(clicked()),
 
142
                 this,SLOT(click_ayuda()) );
 
143
        connect(configB,SIGNAL(clicked()),
 
144
                this,SLOT(click_config()) );
 
145
        connect(tocar,SIGNAL(clicked()),
 
146
                this,SLOT(click_play()) );
 
147
        connect(parar,SIGNAL(clicked()),
 
148
                 this,SLOT(click_stop()));
 
149
        connect(avanzar,SIGNAL(clicked()),
 
150
                 this,SLOT(click_forward()));
 
151
        connect(retroceder,SIGNAL(clicked()),
 
152
                 this,SLOT(click_backward()));
 
153
        connect(video,SIGNAL(stopped()),
 
154
                 this,SLOT(waitForKXanimExit()) );
 
155
        connect(video,SIGNAL(mouseClick(QMouseEvent *)),
 
156
                 this,SLOT(receiveMouseClick(QMouseEvent *)) );
 
157
        connect(volumeSlider,SIGNAL(valueChanged(int)),
 
158
                 this,SLOT(volumeSliderMoved(int)) );
 
159
        connect(timer,SIGNAL(timeout()),
 
160
                 this,SLOT(checkStates()) );
 
161
 
 
162
        config->setGroup("others");
 
163
        lastDir=config->readEntry("initialDirectory");
 
164
        if (!QDir(lastDir).exists())
 
165
        {
 
166
           KMessageBox::information(0L,
 
167
                                    i18n("Invalid initial directory"),
 
168
                                    i18n("aktion error!"));
 
169
           lastDir="";
 
170
        }
 
171
 
 
172
        /* switch the buttons to the 'disabled' mode */
 
173
        toggleButtons(false);
 
174
 
 
175
        whatToDo=NOTHING;
 
176
        parametersChanged=false;
 
177
        isNewVideo=false;
 
178
        fileName="";
 
179
        externalChange=false;
 
180
        inFullScreen=false;
 
181
 
 
182
 
 
183
        QVBoxLayout *lv=new QVBoxLayout( mainwidget );
 
184
 
 
185
        lv->addWidget(videoContainer);
 
186
        lv->addWidget( logoWidget );
 
187
 
 
188
        lv->addWidget( line );
 
189
        QHBoxLayout *lh2=new QHBoxLayout( lv );
 
190
        lh2->addStretch(1);
 
191
        lh2->addWidget( volumeSlider );
 
192
        QHBoxLayout *lh=new QHBoxLayout( lv );
 
193
        lh->addWidget( abrir );
 
194
        lh->addWidget( tocar );
 
195
        lh->addWidget( parar );
 
196
        lh->addWidget( retroceder );
 
197
        lh->addWidget( avanzar );
 
198
        lh->addStretch(1);
 
199
        lh->addWidget( configB );
 
200
        lh->addWidget( ayuda );
 
201
 
 
202
}
 
203
 
 
204
Principal::~Principal()
 
205
{
 
206
}
 
207
 
 
208
void Principal::toggleButtons(bool state)
 
209
{
 
210
   tocar->setEnabled(state);
 
211
   parar->setEnabled(state);
 
212
   avanzar->setEnabled(state);
 
213
   retroceder->setEnabled(state);
 
214
}
 
215
 
 
216
void Principal::click_original() { changeSize(1.0); };
 
217
void Principal::click_half()     { changeSize(0.5); };
 
218
void Principal::click_double()   { changeSize(2.0); };
 
219
 
 
220
void Principal::changeSize(float zoom)
 
221
{
 
222
   /* resize the window according to a zoom factor */
 
223
   float zH, zW;
 
224
 
 
225
   if (inFullScreen) {
 
226
      undoFullScreen();
 
227
      KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
 
228
   }
 
229
 
 
230
   zH=(float)video->getVideoHeight()*zoom;
 
231
   zW=(float)video->getVideoWidth()*zoom;
 
232
 
 
233
   resize(zW,zH+volumeSlider->height()+tocar->height()+line->height()+15);
 
234
}
 
235
 
 
236
void Principal::maximize()
 
237
{
 
238
   /* maximizes the window */
 
239
 
 
240
    // KWM is dead, I hope this works as a replacement
 
241
    KWin::Info info = KWin::info( winId() ); // doesn't this look funny? :)
 
242
    KWin::setState( winId(), info.state | NET::MaxVert | NET::MaxHoriz );
 
243
 
 
244
#if 0
 
245
   QRect with_frame, no_frame, result;
 
246
 
 
247
   with_frame = KWM::geometry(winId(),true);
 
248
   no_frame   = KWM::geometry(winId(),false);
 
249
   result     = KWM::windowRegion( KWM::currentDesktop() );
 
250
 
 
251
   result.setWidth( result.width() - (with_frame.width() - no_frame.width()) );
 
252
   result.setHeight( result.height() - (with_frame.height() - no_frame.height()) );
 
253
   setGeometry( result );
 
254
#endif
 
255
}
 
256
 
 
257
void Principal::changeInitialSize()
 
258
{
 
259
   /* this procedure sets the window size just after a video
 
260
      has been opened */
 
261
   config->setGroup("scaling");
 
262
   switch (config->readNumEntry("scale"))
 
263
   {
 
264
      case 0: changeSize(1.0); break;
 
265
      case 1: changeSize(0.5); break;
 
266
      case 2: changeSize(2.0); break;
 
267
      case 3: maximize(); break;
 
268
      case 4: goFullScreen(); break;
 
269
   }
 
270
}
 
271
 
 
272
void Principal::waitForKXanimExit()
 
273
{
 
274
    /* the kxanim's stopped signal activates this slot every time the video
 
275
       is stopped. I use the whatToDo switch to know "what to do now that
 
276
       kxanim is stopped". This is the most secure way to manage the things,
 
277
       but not the cleaner, though.
 
278
    */
 
279
    tocar->setIconSet(MainBarIconSet("1rightarrow"));
 
280
 
 
281
    switch (whatToDo)
 
282
    {
 
283
        case NOTHING          : if (inFullScreen)
 
284
                                {
 
285
                                   undoFullScreen();
 
286
                                };
 
287
                                break;
 
288
        case CLOSE_THE_APP    : kapp->quit(); break;
 
289
        case NEW_VIDEO        : click_open(); break;
 
290
        case CONTINUE_LOADING : continueLoading(); break;
 
291
        case CHANGE_EXECUTABLE: executableChanged(); break;
 
292
    }
 
293
}
 
294
 
 
295
bool Principal::queryExit()
 
296
{
 
297
        whatToDo = CLOSE_THE_APP;
 
298
        if (video->isActive())
 
299
        {
 
300
            video->stop();
 
301
            return false; // wait for signal
 
302
        }
 
303
        else
 
304
           return true;
 
305
}
 
306
 
 
307
void Principal::click_open()
 
308
{
 
309
    /* the idea behind this method is not very simple:
 
310
       if fileName is empty then: get a file name!
 
311
       if the video is active (here comes the hard part!):
 
312
           set 'what to do' to NEW_VIDEO, stop the video and wait that the
 
313
           waitForKXanimExit slot gets activated...
 
314
       else
 
315
           ok, now that the video is REALLY inactive, we can play with it...!
 
316
           set the video file and wait until KXAnim finishes reading info...
 
317
           (continues on continueLoading() )
 
318
    */
 
319
    KURL url;
 
320
 
 
321
    if ( fileName.isEmpty() )
 
322
    {
 
323
       url=KFileDialog::getOpenURL(lastDir, i18n("*.avi *.AVI *.mov *.MOV *.mpg *.MPG *.mpeg *.MPEG *.flc *.FLC *.fli *.FLI|All video formats\n"
 
324
                                                     "*.avi *.AVI|AVI files (*.avi)\n"
 
325
                                                     "*.mov *.MOV|QuickTime files (*.mov)\n"
 
326
                                                     "*.mpg *.MPG *.mpeg *.MPEG|MPG Files (*.mpg)\n"
 
327
                                                     "*.fli *.FLI *.flc *.FLC|FLI/FLC Files (*.fli *.flc)\n"
 
328
                                                     "*|All Files (*)\n")
 
329
                                              ,0L,i18n("Select a movie"));
 
330
      if (url.isEmpty()) return;
 
331
    }
 
332
    else
 
333
    {
 
334
        url.setPath(fileName);
 
335
    }
 
336
 
 
337
    if( url.isLocalFile() )
 
338
    {
 
339
        fileName = url.path();
 
340
    }
 
341
    else
 
342
    {
 
343
        KMessageBox::sorry( 0L, i18n("Only local files are currently supported." ) );
 
344
        fileName = "";
 
345
    }
 
346
 
 
347
    if (video->isActive() && !fileName.isEmpty() )
 
348
    {
 
349
        whatToDo=NEW_VIDEO;
 
350
        video->stop();
 
351
    }
 
352
    else
 
353
        if (!fileName.isEmpty())
 
354
        {
 
355
          /* remove the logo picture */
 
356
          if (logoWidget != 0L)
 
357
          {
 
358
            delete logoWidget;
 
359
            logoWidget = 0L;
 
360
            video->show();
 
361
          }
 
362
 
 
363
          whatToDo=CONTINUE_LOADING;
 
364
          kapp->setOverrideCursor( waitCursor );
 
365
          setParameters();
 
366
          parametersChanged=false;
 
367
          video->setFile(fileName);
 
368
        }
 
369
}
 
370
 
 
371
void Principal::continueLoading()
 
372
{
 
373
   QString title;
 
374
   int pos;
 
375
 
 
376
   whatToDo=NOTHING;
 
377
   if (video->getErrorCode()==0)
 
378
   {
 
379
       /* Everything seems to be fine... */
 
380
       /* enable the buttons */
 
381
       toggleButtons(true);
 
382
       pos=fileName.findRev('/');
 
383
       title=fileName.mid(pos+1,fileName.length()-(pos+1));
 
384
       // title+=" - aKtion!";
 
385
       // preserve the caption for future use (in fullscreen)
 
386
       saveCaption = title;
 
387
       setCaption( title );
 
388
       lastDir=fileName.mid(0,pos+1);
 
389
       isNewVideo=true;
 
390
 
 
391
       theCapturer.resetCounter();
 
392
       config->setGroup("capture");
 
393
       theCapturer.setParameters(config->readEntry("outputDir"),fileName,
 
394
                                 config->readEntry("outputFormat"));
 
395
 
 
396
       kapp->restoreOverrideCursor();
 
397
       changeInitialSize();
 
398
       click_play();
 
399
   }
 
400
   else
 
401
   {
 
402
       /* something is wrong... */
 
403
       /* disable buttons */
 
404
       toggleButtons(false);
 
405
       kapp->restoreOverrideCursor();
 
406
       KMessageBox::sorry(0L,video->getErrorString());
 
407
   }
 
408
   fileName="";
 
409
}
 
410
 
 
411
void Principal::dragEnterEvent( QDragEnterEvent *event )
 
412
{
 
413
  event->accept( QUriDrag::canDecode(event) );
 
414
}
 
415
 
 
416
void Principal::dropEvent( QDropEvent *event )
 
417
{
 
418
    if ( QUriDrag::canDecode(event) )
 
419
    {
 
420
        QStrList  urls;
 
421
        if ( QUriDrag::decode(event, urls) )
 
422
        {
 
423
            char *urlStr=urls.first();
 
424
            KURL url(urlStr);
 
425
            fileName = url.path();
 
426
            click_open() ;
 
427
        }
 
428
    }
 
429
}
 
430
 
 
431
void Principal::click_ayuda()
 
432
{
 
433
    kapp->invokeHelp();
 
434
}
 
435
 
 
436
void Principal::click_play()
 
437
{
 
438
    /* maube do we need to resize the whole application? */
 
439
    if (parametersChanged==true && video->isActive()==false)
 
440
    {
 
441
       setParameters();
 
442
       parametersChanged=false;
 
443
    }
 
444
    /* autoplay or not */
 
445
    config->setGroup("others");
 
446
    if (isNewVideo==true && config->readBoolEntry("autoplay")==false)
 
447
    {
 
448
       video->setPauseAt(0);
 
449
    }
 
450
    else video->setPauseAt(-1);
 
451
    isNewVideo=false;
 
452
 
 
453
    /* set the play button pixmap */
 
454
    if (video->isPlaying()==true)
 
455
       tocar->setIconSet(MainBarIconSet("1rightarrow"));
 
456
    else
 
457
       tocar->setIconSet(MainBarIconSet("player_pause"));
 
458
 
 
459
    // timer->start(100);
 
460
    //updateGeometry();
 
461
    video->play();
 
462
}
 
463
 
 
464
void Principal::click_forward()
 
465
{
 
466
   if (video->isPlaying()==true)
 
467
      tocar->setIconSet(MainBarIconSet("1rightarrow"));
 
468
   video->stepForward();
 
469
}
 
470
 
 
471
void Principal::click_backward()
 
472
{
 
473
   if (video->isPlaying()==true)
 
474
      tocar->setIconSet(MainBarIconSet("1rightarrow"));
 
475
   video->stepBack();
 
476
}
 
477
 
 
478
void Principal::click_stop()
 
479
{
 
480
   video->stop();
 
481
}
 
482
 
 
483
void Principal::click_config()
 
484
{
 
485
   QString oldExecutable, newExecutable;
 
486
 
 
487
   config->setGroup("others");
 
488
   oldExecutable=config->readEntry("executable");
 
489
 
 
490
   Setup dialogo(0L, "setup");
 
491
   if (dialogo.exec()==1)
 
492
   {
 
493
      parametersChanged=true;
 
494
 
 
495
      config->setGroup("capture");
 
496
      theCapturer.setParameters(config->readEntry("outputDir"),fileName,
 
497
                                config->readEntry("outputFormat"));
 
498
 
 
499
      config->setGroup("others");
 
500
      newExecutable=config->readEntry("executable");
 
501
 
 
502
      if (oldExecutable!=newExecutable)
 
503
         executableChanged();
 
504
   }
 
505
}
 
506
 
 
507
void Principal::setParameters()
 
508
{
 
509
    config->setGroup("audio");
 
510
    video->setAudio(config->readBoolEntry("enable"));
 
511
    video->setAudioSync(config->readBoolEntry("audioSync"));
 
512
    video->setInitialVolume(volumeSlider->value());
 
513
 
 
514
    config->setGroup("color");
 
515
    video->setColorAhead(config->readNumEntry("colorAhead"));
 
516
    switch (config->readNumEntry("colorMapping"))
 
517
    {
 
518
       case 0: video->setColorMapping(KXAnim::static332); break;
 
519
       case 1: video->setColorMapping(KXAnim::lookupTable); break;
 
520
       case 2: video->setColorMapping(KXAnim::grayScale); break;
 
521
       case 3: video->setColorMapping(KXAnim::none); break;
 
522
    }
 
523
    video->setGammaDisplay(float(config->readDoubleNumEntry("gammaDisp")));
 
524
 
 
525
    config->setGroup("scaling");
 
526
    /* I always wants "resinzing on the fly"
 
527
 
 
528
    video->setResizing(true);
 
529
    is not necessary 'cause it's true by default.
 
530
    */
 
531
 
 
532
//    video->setScaleFactor( float(config->readNumEntry("dispFactor"))/100 );
 
533
//    video->setScaleFactorB( float(config->readNumEntry("bufFactor"))/100);
 
534
 
 
535
    config->setGroup("others");
 
536
    video->setLoading(config->readNumEntry("loading"));
 
537
    video->setX11Shared(config->readBoolEntry("x11shared"));
 
538
    video->setMultiBuffer(config->readBoolEntry("multiBuffer"));
 
539
    video->setUsePixmap(config->readBoolEntry("pixmap"));
 
540
/*
 
541
    switch (config->readNumEntry("visualClass"))
 
542
    {
 
543
       case 0: video->setX11VisualClass("default"); break;
 
544
       case 1: video->setX11VisualClass("staticgray"); break;
 
545
       case 2: video->setX11VisualClass("grayscale"); break;
 
546
       case 3: video->setX11VisualClass("staticcolor"); break;
 
547
       case 4: video->setX11VisualClass("pseudocolor"); break;
 
548
       case 5: video->setX11VisualClass("truecolor"); break;
 
549
       case 6: video->setX11VisualClass("directcolor"); break;
 
550
    }
 
551
*/
 
552
    video->setLoop(config->readBoolEntry("loop"));
 
553
    video->setExtraParameters( config->readEntry("extras").ascii());
 
554
    video->setExecutable( QFile::encodeName(config->readEntry("executable")) );
 
555
}
 
556
 
 
557
void Principal::keyPressEvent( QKeyEvent *key)
 
558
{
 
559
   switch(key->key())
 
560
   {
 
561
      case Key_Space : click_play(); break;
 
562
      case Key_Period: click_forward(); break;
 
563
      case Key_Comma : click_backward(); break;
 
564
      case Key_Enter : click_open(); break;
 
565
      case Key_3     : if(volumeSlider->value() <= 99)
 
566
                       {
 
567
                          externalChange=true;
 
568
                          volumeSlider->setValue( volumeSlider->value() + 1);
 
569
                          externalChange=false;
 
570
                          video->volumeIncrement();
 
571
                       }
 
572
                       break;
 
573
      case Key_2     : if(volumeSlider->value() >= 1)
 
574
                       {
 
575
                          externalChange=true;
 
576
                          volumeSlider->setValue( volumeSlider->value() - 1);
 
577
                          externalChange=false;
 
578
                          video->volumeDecrement();
 
579
                       }
 
580
                       break;
 
581
      case Key_F1    : click_ayuda(); break;
 
582
      case Key_Escape: this->close(); break;
 
583
      case Key_C     : theCapturer.captureWidget(video); break;
 
584
      default        : if (inFullScreen)
 
585
                       {
 
586
                          undoFullScreen();
 
587
                          /* restore the geometry */
 
588
                          // KWM::setGeometry( winId(), oldGeometry);
 
589
                          KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
 
590
                       }
 
591
                       break;
 
592
   }
 
593
   key->accept();
 
594
}
 
595
 
 
596
void Principal::receiveMouseClick( QMouseEvent *mouse)
 
597
{
 
598
   if (mouse->button()==RightButton)
 
599
   {
 
600
      menu->move(this->x()+mouse->x(),this->y()+mouse->y());
 
601
      menu->show();
 
602
   }
 
603
   else
 
604
   {
 
605
     if (mouse->button()==LeftButton && inFullScreen)
 
606
     {
 
607
        undoFullScreen();
 
608
        // KWM::setGeometry( winId(), oldGeometry);
 
609
        KWin::clearState( winId(), NET::MaxHoriz | NET::MaxVert );
 
610
     }
 
611
   }
 
612
}
 
613
 
 
614
void Principal::loadFile( const char *name)
 
615
{
 
616
   fileName=name;
 
617
   click_open();
 
618
}
 
619
 
 
620
void Principal::click_info()
 
621
{
 
622
   QString codec(video->getVideoCodec());
 
623
 
 
624
   QString s;
 
625
   s = i18n("File: %1\n"
 
626
             "%2\n"
 
627
             "%3x%4\n"
 
628
             "%5 frames - %6 fps")
 
629
             .arg(caption())
 
630
             .arg(codec)
 
631
             .arg(video->getVideoWidth())
 
632
             .arg(video->getVideoHeight())
 
633
             .arg(video->getVideoFrames())
 
634
             .arg(KGlobal::locale()->formatNumber(video->getVideoSpeed(), 2));
 
635
   KMessageBox::information(this, s, "aktion!");
 
636
}
 
637
 
 
638
void Principal::volumeSliderMoved(int v)
 
639
{
 
640
   if (!externalChange)
 
641
       video->setVolume(v);
 
642
}
 
643
 
 
644
void Principal::resizeEvent( QResizeEvent *)
 
645
{
 
646
   int w=videoContainer->width();
 
647
   int h=videoContainer->height();
 
648
   float video_ar, space_ar, scaled;
 
649
   int videoW, videoH;
 
650
 
 
651
   if (inFullScreen==false)
 
652
   {
 
653
        config->setGroup("audio");
 
654
        if (config->readBoolEntry("showVolumeSlider")==true)
 
655
        {
 
656
           volumeSlider->show();
 
657
        }
 
658
        else
 
659
        {
 
660
           volumeSlider->hide();
 
661
        }
 
662
   }
 
663
 
 
664
   /* Here comes the resizing-moving process for the video widget.
 
665
      It'll maintain his aspect ratio. Steps are:
 
666
      .The available space for the video is defined w and h.
 
667
      .Resize the video widget as much as possible:
 
668
        .Calculate video and left space aspect ratio.
 
669
        .If video aspect ratio is smaller:
 
670
           expand in height
 
671
         else
 
672
           .If video aspect ratio is bigger
 
673
              expand in width
 
674
            else
 
675
              expand all
 
676
   */
 
677
 
 
678
   videoW=video->getVideoWidth();
 
679
   if (videoW==0) videoW=1;
 
680
   videoH=video->getVideoHeight();
 
681
   if (videoH==0) videoH=1;
 
682
 
 
683
   video_ar=(float)videoW/(float)videoH; // video aspect ratio
 
684
   space_ar=(float)w/(float)h;           // available space aspect ratio
 
685
 
 
686
   if (video_ar<space_ar)
 
687
   {
 
688
      scaled=(float)videoW*( (float)h/(float)videoH );
 
689
      video->resize( (int)scaled,h);
 
690
      scaled=((float)w - scaled) /2;
 
691
      video->move( (int)scaled, 0);
 
692
 
 
693
   }
 
694
   else
 
695
   {
 
696
      if (video_ar>space_ar)
 
697
      {
 
698
         scaled=(float)videoH*( (float)w/(float)videoW );
 
699
         video->resize(w, (int)scaled);
 
700
         scaled=((float)h - scaled) /2;
 
701
         video->move(0, (int)scaled);
 
702
      }
 
703
      else
 
704
      {
 
705
         video->resize(w,h);
 
706
         video->move(0,0);
 
707
      }
 
708
   }
 
709
 
 
710
}
 
711
 
 
712
 
 
713
void Principal::checkStates()
 
714
{
 
715
//   cout<<video->iconText()<<endl;
 
716
}
 
717
 
 
718
void Principal::goFullScreen()
 
719
{
 
720
   int sizeW=0, sizeH=0;
 
721
 
 
722
   /* change the popup menu */
 
723
   menu->setItemEnabled(menuItemFullScreen,false);
 
724
 
 
725
   /* Hide all widgets (except the video widget) */
 
726
   parar->hide();
 
727
   tocar->hide();
 
728
   abrir->hide();
 
729
   avanzar->hide();
 
730
   retroceder->hide();
 
731
   ayuda->hide();
 
732
   configB->hide();
 
733
   line->hide();
 
734
   volumeSlider->hide();
 
735
 
 
736
#ifdef XF86_VM
 
737
   bool vmExtensionsOk=false;
 
738
   inVmMode=false;
 
739
 
 
740
   config->setGroup("scaling");
 
741
   if (config->readBoolEntry("usevm"))
 
742
   {
 
743
      if (true)//geteuid()==0)
 
744
      {
 
745
         sizeW=video->getVideoWidth();
 
746
         sizeH=video->getVideoHeight();
 
747
         vmExtensionsOk=videoMode->setVideoMode(&sizeW,&sizeH);
 
748
         if (vmExtensionsOk)
 
749
            inVmMode=true;
 
750
      }
 
751
      else
 
752
          KMessageBox::sorry(0L, i18n("You must be root to use the XFree86-VidMode extensions\n"
 
753
                                      "Switching to normal full-screen..."));
 
754
   }
 
755
 
 
756
   if (!vmExtensionsOk)
 
757
   {
 
758
#endif
 
759
      /* Make the window FULL SCREEN in the traditional way */
 
760
      sizeW = QApplication::desktop()->width();
 
761
      sizeH = QApplication::desktop()->height();
 
762
#ifdef XF86_VM
 
763
   }
 
764
#endif
 
765
 
 
766
   inFullScreen = true;
 
767
 
 
768
   config->setGroup("scaling");
 
769
   if (config->readBoolEntry("grabmouse"))
 
770
   {
 
771
      kapp->setOverrideCursor( blankCursor );
 
772
      QCursor::setPos(0,0);
 
773
   }
 
774
 
 
775
   /* Save the window's background color and geometry */
 
776
   saveBackground = backgroundColor();
 
777
   videoContainer->setBackgroundColor( black );
 
778
 
 
779
   showFullScreen();
 
780
   this->setCaption(saveCaption);
 
781
 
 
782
   setGeometry( 0, 0, sizeW, sizeH );
 
783
}
 
784
 
 
785
void Principal::undoFullScreen()
 
786
{
 
787
#ifdef XF86_VM
 
788
   if (inVmMode)
 
789
   {
 
790
      videoMode->resetVideoMode();
 
791
      inVmMode=false;
 
792
   }
 
793
#endif
 
794
 
 
795
   /* change the popup menu */
 
796
   menu->setItemEnabled(menuItemFullScreen,true);
 
797
 
 
798
   /* Show all widgets  */
 
799
   parar->show();
 
800
   tocar->show();
 
801
   abrir->show();
 
802
   avanzar->show();
 
803
   retroceder->show();
 
804
   ayuda->show();
 
805
   configB->show();
 
806
   line->show();
 
807
 
 
808
   /* Restore background color */
 
809
   videoContainer->setBackgroundColor( saveBackground );
 
810
 
 
811
   inFullScreen = false;
 
812
 
 
813
   config->setGroup("scaling");
 
814
   if (config->readBoolEntry("grabmouse"))
 
815
      kapp->restoreOverrideCursor();
 
816
 
 
817
//   KWM::setDecoration( winId(), KWM::normalDecoration );
 
818
 
 
819
//   QPoint p;
 
820
//   p.setX(50);
 
821
//   p.setY(50);
 
822
//   reparent(0,0,p,true);//WStyle_Customize | WStyle_NormalBorder | WType_TopLevel, p, false);
 
823
//   KWin::setType(winId(), NET::Normal);
 
824
//   KWin::clearState(winId(), NET::StaysOnTop);
 
825
 
 
826
   showNormal();
 
827
   this->setCaption(saveCaption);
 
828
}
 
829
 
 
830
void Principal::executableChanged()
 
831
{
 
832
   if (video->isActive())
 
833
   {
 
834
      whatToDo=CHANGE_EXECUTABLE;
 
835
      video->stop();
 
836
   }
 
837
   else
 
838
   {
 
839
      whatToDo=NOTHING;
 
840
      fileName=video->getVideoFileName();
 
841
      if (!fileName.isEmpty())
 
842
         click_open();
 
843
   }
 
844
}
 
845
#include "principal.moc"