~ubuntu-branches/ubuntu/wily/smplayer/wily

« back to all changes in this revision

Viewing changes to src/corelib/mplayerwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-0h2hfwpwlu9opbv2
* New upstream release. (Closes: #523791)
  - Reworked subtitle font preferences. (Closes: #503295)
  - No longer installs qt_fr.qm. (Closes: #486314)
* debian/control:
  - Bumped Standards-Version to 3.8.1.
  - Changed maintainer name (still the same person and GPG key).
  - Changed section to video.
  - Build-depend on zlib1g-dev for findsubtitles.
  - Require Qt >= 4.3 per readme.
  - Added ${misc:Depends}.
  - Make smplayer-translations depend on smplayer and smplayer recommend
    smplayer-translations, not the other way round. (Closes: #489375)
* debian/copyright:
  - Significantly expanded per-file with new upstream authors.
* debian/rules:
  - Make make use correct uic in install.
  - Clean svn_revision.
  - Removed get-orig-source - not needed with uscan --repack.
* debian/patches/01_gl_translation.patch:
  - Added patch to fix lrelease error on smplayer_gl.ts.
* Added debian/README.source for simple-patchsys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  smplayer, GUI front-end for mplayer.
2
 
    Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
3
 
 
4
 
    This program is free software; you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program; if not, write to the Free Software
16
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
*/
18
 
 
19
 
#include "mplayerwindow.h"
20
 
#include "global.h"
21
 
#include "desktopinfo.h"
22
 
#include "helper.h"
23
 
 
24
 
#ifndef MINILIB
25
 
#include "images.h"
26
 
#endif
27
 
 
28
 
#include <QLabel>
29
 
#include <QTimer>
30
 
#include <QCursor>
31
 
#include <QEvent>
32
 
#include <QLayout>
33
 
#include <QPixmap>
34
 
#include <QPainter>
35
 
 
36
 
Screen::Screen(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f ) 
37
 
{
38
 
        setMouseTracking(TRUE);
39
 
        setFocusPolicy( Qt::NoFocus );
40
 
        setMinimumSize( QSize(0,0) );
41
 
 
42
 
        cursor_pos = QPoint(0,0);
43
 
        last_cursor_pos = QPoint(0,0);
44
 
 
45
 
        QTimer *timer = new QTimer(this);
46
 
        connect( timer, SIGNAL(timeout()), this, SLOT(checkMousePos()) );
47
 
        timer->start(2000);
48
 
 
49
 
        // Change attributes
50
 
        setAttribute(Qt::WA_NoSystemBackground);
51
 
        //setAttribute(Qt::WA_StaticContents);
52
 
    //setAttribute( Qt::WA_OpaquePaintEvent );
53
 
        setAttribute(Qt::WA_PaintOnScreen);
54
 
        setAttribute(Qt::WA_PaintUnclipped);
55
 
        //setAttribute(Qt::WA_PaintOutsidePaintEvent);
56
 
}
57
 
 
58
 
Screen::~Screen() {
59
 
}
60
 
 
61
 
void Screen::paintEvent( QPaintEvent * e ) {
62
 
        //qDebug("Screen::paintEvent");
63
 
        QPainter painter(this);
64
 
        painter.eraseRect( e->rect() );
65
 
        //painter.fillRect( e->rect(), QColor(255,0,0) );
66
 
}
67
 
 
68
 
 
69
 
void Screen::checkMousePos() {
70
 
        //qDebug("Screen::checkMousePos");
71
 
        
72
 
        if ( cursor_pos == last_cursor_pos ) {
73
 
                //qDebug(" same pos");
74
 
                if (cursor().shape() != Qt::BlankCursor) {
75
 
                        //qDebug(" hiding mouse cursor");
76
 
                        setCursor(QCursor(Qt::BlankCursor));
77
 
                }
78
 
        } else {
79
 
                last_cursor_pos = cursor_pos;
80
 
        }
81
 
}
82
 
 
83
 
void Screen::mouseMoveEvent( QMouseEvent * e ) {
84
 
        //qDebug("Screen::mouseMoveEvent");
85
 
        //qDebug(" pos: x: %d y: %d", e->pos().x(), e->pos().y() );
86
 
        cursor_pos = e->pos();
87
 
 
88
 
        if (cursor().shape() != Qt::ArrowCursor) {
89
 
                //qDebug(" showing mouse cursor" );
90
 
                setCursor(QCursor(Qt::ArrowCursor));
91
 
        }
92
 
}
93
 
 
94
 
/* ---------------------------------------------------------------------- */
95
 
 
96
 
MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f) 
97
 
        : Screen(parent, f) 
98
 
{
99
 
        allow_clearing = true;
100
 
        playing = false;
101
 
}
102
 
 
103
 
MplayerLayer::~MplayerLayer() {
104
 
}
105
 
 
106
 
void MplayerLayer::allowClearingBackground(bool b) {
107
 
        qDebug("MplayerLayer::allowClearingBackground: %d", b);
108
 
        allow_clearing = b;
109
 
}
110
 
 
111
 
void MplayerLayer::paintEvent( QPaintEvent * e ) {
112
 
        //qDebug("MplayerLayer::paintEvent: allow_clearing: %d", allow_clearing);
113
 
        if (allow_clearing || !playing) {
114
 
                //qDebug("MplayerLayer::paintEvent: painting");
115
 
                Screen::paintEvent(e);
116
 
        }
117
 
}
118
 
 
119
 
void MplayerLayer::playingStarted() {
120
 
        qDebug("MplayerLayer::playingStarted");
121
 
        repaint();
122
 
        playing = true;
123
 
}
124
 
 
125
 
void MplayerLayer::playingStopped() {
126
 
        qDebug("MplayerLayer::playingStopped");
127
 
        playing = false;
128
 
        repaint();
129
 
}
130
 
 
131
 
/* ---------------------------------------------------------------------- */
132
 
 
133
 
MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f) 
134
 
        : Screen(parent, f) , allow_video_movement(false)
135
 
{
136
 
        offset_x = 0;
137
 
        offset_y = 0;
138
 
        zoom_factor = 1.0;
139
 
 
140
 
        setAutoFillBackground(true);
141
 
        Helper::setBackgroundColor( this, QColor(0,0,0) );
142
 
 
143
 
        mplayerlayer = new MplayerLayer( this );
144
 
        mplayerlayer->setAutoFillBackground(TRUE);
145
 
 
146
 
        logo = new QLabel( mplayerlayer );
147
 
        logo->setAutoFillBackground(TRUE);
148
 
        logo->setAttribute(Qt::WA_PaintOnScreen); // Otherwise the logo is not visible in Qt 4.4
149
 
        Helper::setBackgroundColor( logo, QColor(0,0,0) );
150
 
 
151
 
        QVBoxLayout * mplayerlayerLayout = new QVBoxLayout( mplayerlayer );
152
 
        mplayerlayerLayout->addWidget( logo, 0, Qt::AlignHCenter | Qt::AlignVCenter );
153
 
 
154
 
    aspect = (double) 4 / 3;
155
 
        monitoraspect = 0;
156
 
 
157
 
        setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Expanding );
158
 
        setFocusPolicy( Qt::StrongFocus );
159
 
 
160
 
        installEventFilter(this);
161
 
        mplayerlayer->installEventFilter(this);
162
 
        //logo->installEventFilter(this);
163
 
 
164
 
        retranslateStrings();
165
 
}
166
 
 
167
 
MplayerWindow::~MplayerWindow() {
168
 
}
169
 
 
170
 
#if USE_COLORKEY
171
 
void MplayerWindow::setColorKey( QColor c ) {
172
 
        Helper::setBackgroundColor( mplayerlayer, c );
173
 
}
174
 
#endif
175
 
 
176
 
void MplayerWindow::retranslateStrings() {
177
 
        //qDebug("MplayerWindow::retranslateStrings");
178
 
#ifndef MINILIB
179
 
        logo->setPixmap( Images::icon("background") );
180
 
#endif
181
 
}
182
 
 
183
 
void MplayerWindow::showLogo( bool b)
184
 
{
185
 
        if (b) logo->show(); else logo->hide();
186
 
}
187
 
 
188
 
/*
189
 
void MplayerWindow::changePolicy() {
190
 
        setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Preferred  );
191
 
}
192
 
*/
193
 
 
194
 
void MplayerWindow::setResolution( int w, int h)
195
 
{
196
 
    video_width = w;
197
 
    video_height = h;
198
 
    
199
 
    //mplayerlayer->move(1,1);
200
 
    updateVideoWindow();
201
 
}
202
 
 
203
 
 
204
 
void MplayerWindow::resizeEvent( QResizeEvent * /* e */)
205
 
{
206
 
   /*qDebug("MplayerWindow::resizeEvent: %d, %d",
207
 
           e->size().width(), e->size().height() );*/
208
 
 
209
 
        offset_x = 0;
210
 
        offset_y = 0;
211
 
 
212
 
    updateVideoWindow();
213
 
        setZoom(zoom_factor);
214
 
}
215
 
 
216
 
 
217
 
void MplayerWindow::setMonitorAspect(double asp) {
218
 
        monitoraspect = asp;
219
 
}
220
 
 
221
 
void MplayerWindow::setAspect( double asp) {
222
 
    aspect = asp;
223
 
        if (monitoraspect!=0) {
224
 
                aspect = aspect / monitoraspect * DesktopInfo::desktop_aspectRatio(this);
225
 
        }
226
 
        updateVideoWindow();
227
 
}
228
 
 
229
 
 
230
 
void MplayerWindow::updateVideoWindow()
231
 
{
232
 
        /*
233
 
        mplayerlayer->resize(size());
234
 
        return;
235
 
        */
236
 
 
237
 
        //qDebug("MplayerWindow::updateVideoWindow");
238
 
 
239
 
    //qDebug("aspect= %f", aspect);
240
 
    
241
 
    int w_width = size().width();
242
 
    int w_height = size().height();
243
 
    
244
 
    int pos1_w = w_width;
245
 
    int pos1_h = w_width / aspect + 0.5;
246
 
    
247
 
    int pos2_h = w_height;
248
 
    int pos2_w = w_height * aspect + 0.5;
249
 
    
250
 
    //qDebug("pos1_w: %d, pos1_h: %d", pos1_w, pos1_h);
251
 
    //qDebug("pos2_w: %d, pos2_h: %d", pos2_w, pos2_h);
252
 
    
253
 
    int w,h;
254
 
    int x=0;
255
 
    int y=0;
256
 
    
257
 
    if (pos1_h <= w_height) {
258
 
        //qDebug("Pos1!");
259
 
                w = pos1_w;
260
 
                h = pos1_h;
261
 
        
262
 
                y = (w_height - h) /2;
263
 
    } else {
264
 
        //qDebug("Pos2!");
265
 
                w = pos2_w;
266
 
                h = pos2_h;
267
 
        
268
 
                x = (w_width - w) /2;
269
 
    }
270
 
 
271
 
    mplayerlayer->move(x,y);
272
 
    mplayerlayer->resize(w, h);
273
 
 
274
 
        orig_x = x;
275
 
        orig_y = y;
276
 
        orig_width = w;
277
 
        orig_height = h;
278
 
    
279
 
    //qDebug( "w_width: %d, w_height: %d", w_width, w_height);
280
 
    //qDebug("w: %d, h: %d", w,h);
281
 
}
282
 
 
283
 
 
284
 
void MplayerWindow::mouseReleaseEvent( QMouseEvent * e) {
285
 
    qDebug( "MplayerWindow::mouseReleaseEvent" );
286
 
 
287
 
        if (e->button() == Qt::LeftButton) {
288
 
                e->accept();
289
 
                emit leftClicked();
290
 
        }
291
 
        else
292
 
        if (e->button() == Qt::MidButton) {
293
 
                e->accept();
294
 
                emit middleClicked();
295
 
        }
296
 
        else
297
 
        if (e->button() == Qt::XButton1) {
298
 
                e->accept();
299
 
                emit xbutton1Clicked();
300
 
        }
301
 
        else
302
 
        if (e->button() == Qt::XButton2) {
303
 
                e->accept();
304
 
                emit xbutton2Clicked();
305
 
        }
306
 
        else
307
 
    if (e->button() == Qt::RightButton) {
308
 
                e->accept();
309
 
                //emit rightButtonReleased( e->globalPos() );
310
 
                emit rightClicked();
311
 
    } 
312
 
        else {
313
 
                e->ignore();
314
 
        }
315
 
}
316
 
 
317
 
void MplayerWindow::mouseDoubleClickEvent( QMouseEvent * e ) {
318
 
        if (e->button() == Qt::LeftButton) {
319
 
                e->accept();
320
 
                emit doubleClicked();
321
 
        } else {
322
 
                e->ignore();
323
 
        }
324
 
}
325
 
 
326
 
void MplayerWindow::wheelEvent( QWheelEvent * e ) {
327
 
    qDebug("MplayerWindow::wheelEvent: delta: %d", e->delta());
328
 
    e->accept();
329
 
 
330
 
        if (e->orientation() == Qt::Vertical) {
331
 
            if (e->delta() >= 0)
332
 
                emit wheelUp();
333
 
            else
334
 
                emit wheelDown();
335
 
        } else {
336
 
                qDebug("MplayerWindow::wheelEvent: horizontal event received, doing nothing");
337
 
        }
338
 
}
339
 
 
340
 
bool MplayerWindow::eventFilter( QObject * /*watched*/, QEvent * event ) {
341
 
        //qDebug("MplayerWindow::eventFilter");
342
 
 
343
 
        if ( (event->type() == QEvent::MouseMove) || 
344
 
         (event->type() == QEvent::MouseButtonRelease) ) 
345
 
        {
346
 
                QMouseEvent *mouse_event = static_cast<QMouseEvent *>(event);
347
 
                mouse_position = mouse_event->pos();
348
 
                //qDebug("pos: %d %d", mouse_position.x(), mouse_position.y());
349
 
 
350
 
                if (event->type() == QEvent::MouseMove) {
351
 
                        emit mouseMoved(mouse_event->pos());
352
 
                }
353
 
        }
354
 
 
355
 
        return false;
356
 
}
357
 
 
358
 
QSize MplayerWindow::sizeHint() const {
359
 
        //qDebug("MplayerWindow::sizeHint");
360
 
        return QSize( video_width, video_height );
361
 
}
362
 
 
363
 
QSize MplayerWindow::minimumSizeHint () const {
364
 
        return QSize(0,0);
365
 
}
366
 
 
367
 
void MplayerWindow::setOffsetX( int d) {
368
 
        offset_x = d;
369
 
        mplayerlayer->move( orig_x + offset_x, mplayerlayer->y() );
370
 
}
371
 
 
372
 
int MplayerWindow::offsetX() { return offset_x; }
373
 
 
374
 
void MplayerWindow::setOffsetY( int d) {
375
 
        offset_y = d;
376
 
        mplayerlayer->move( mplayerlayer->x(), orig_y + offset_y );
377
 
}
378
 
 
379
 
int MplayerWindow::offsetY() { return offset_y; }
380
 
 
381
 
void MplayerWindow::setZoom( double d) {
382
 
        zoom_factor = d;
383
 
        offset_x = 0;
384
 
        offset_y = 0;
385
 
 
386
 
        int x = orig_x;
387
 
        int y = orig_y;
388
 
        int w = orig_width;
389
 
        int h = orig_height;
390
 
 
391
 
        if (zoom_factor != 1.0) {
392
 
                w = w * zoom_factor;
393
 
                h = h * zoom_factor;
394
 
 
395
 
                // Center
396
 
                x = (width() - w) / 2;
397
 
                y = (height() -h) / 2;
398
 
        }
399
 
 
400
 
        mplayerlayer->move(x,y);
401
 
        mplayerlayer->resize(w,h);
402
 
}
403
 
 
404
 
double MplayerWindow::zoom() { return zoom_factor; }
405
 
 
406
 
void MplayerWindow::moveLayer( int offset_x, int offset_y ) {
407
 
        int x = mplayerlayer->x();
408
 
        int y = mplayerlayer->y();
409
 
 
410
 
        mplayerlayer->move( x + offset_x, y + offset_y );
411
 
}
412
 
 
413
 
void MplayerWindow::moveLeft() {
414
 
        if ((allow_video_movement) || (mplayerlayer->x()+mplayerlayer->width() > width() ))
415
 
                moveLayer( -16, 0 );
416
 
}
417
 
 
418
 
void MplayerWindow::moveRight() {
419
 
        if ((allow_video_movement) || ( mplayerlayer->x() < 0 ))
420
 
                moveLayer( +16, 0 );
421
 
}
422
 
 
423
 
void MplayerWindow::moveUp() {
424
 
        if ((allow_video_movement) || (mplayerlayer->y()+mplayerlayer->height() > height() ))
425
 
                moveLayer( 0, -16 );
426
 
}
427
 
 
428
 
void MplayerWindow::moveDown() {
429
 
        if ((allow_video_movement) || ( mplayerlayer->y() < 0 ))
430
 
                moveLayer( 0, +16 );
431
 
}
432
 
 
433
 
void MplayerWindow::incZoom() {
434
 
        setZoom( zoom_factor + ZOOM_STEP );
435
 
}
436
 
 
437
 
void MplayerWindow::decZoom() {
438
 
        double zoom = zoom_factor - ZOOM_STEP;
439
 
        if (zoom < ZOOM_MIN) zoom = ZOOM_MIN;
440
 
        setZoom( zoom );
441
 
}
442
 
 
443
 
// Language change stuff
444
 
void MplayerWindow::changeEvent(QEvent *e) {
445
 
        if (e->type() == QEvent::LanguageChange) {
446
 
                retranslateStrings();
447
 
        } else {
448
 
                QWidget::changeEvent(e);
449
 
        }
450
 
}
451
 
 
452
 
#include "moc_mplayerwindow.cpp"