| 1 |
#ifndef PLAYERCONTROL_H |
| 2 |
#define PLAYERCONTROL_H |
| 3 |
|
| 4 |
#include <qwidget.h> |
| 5 |
#include <qpixmap.h> |
| 6 |
#include <qevent.h> |
| 7 |
|
| 8 |
#include "aviplay.h" |
| 9 |
#include "playerwidget.h" |
| 10 |
#include "renderer.h" |
| 11 |
#include "avm_locker.h" |
| 12 |
|
| 13 |
class ConfigDialog; |
| 14 |
class QLabel; |
| 15 |
class QMessageBox; |
| 16 |
class QPixmap; |
| 17 |
class QPopupMenu; |
| 18 |
class QProgressBar; |
| 19 |
class QPushButton; |
| 20 |
class QSlider; |
| 21 |
class QTimer; |
| 22 |
|
| 23 |
class Q3PopupMenu; |
| 24 |
|
| 25 |
#define Q_MenuEvent QEvent::User |
| 26 |
#define Q_MyCloseEvent QEvent::Type(QEvent::User+2) |
| 27 |
#define Q_MyResizeEvent QEvent::Type(QEvent::User+3) |
| 28 |
#define Q_MyRefreshEvent QEvent::Type(QEvent::User+4) |
| 29 |
#define Q_MyPosEvent QEvent::Type(QEvent::User+5) |
| 30 |
#define Q_MyOpenEvent QEvent::Type(QEvent::User+6) |
| 31 |
#define Q_MyAboutEvent QEvent::Type(QEvent::User+7) |
| 32 |
#define Q_MyConfigEvent QEvent::Type(QEvent::User+8) |
| 33 |
|
| 34 |
struct AviPlayerInitParams |
| 35 |
{ |
| 36 |
QString acodec; |
| 37 |
QString vcodec; |
| 38 |
QString subname; |
| 39 |
avm::vector<avm::string> urls; |
| 40 |
double seek; |
| 41 |
unsigned idx; |
| 42 |
int x; |
| 43 |
int y; |
| 44 |
int width; |
| 45 |
int height; |
| 46 |
int quality; |
| 47 |
bool fullscreen; |
| 48 |
bool maximize; |
| 49 |
bool nogui; |
| 50 |
bool quiet; |
| 51 |
bool autoq; |
| 52 |
|
| 53 |
AviPlayerInitParams() |
| 54 |
: seek(0.), idx(0), x(0), y(0), width(0), height(0), quality(0), fullscreen(false), |
| 55 |
maximize(false), nogui(false), quiet(false), autoq(false) {} |
| 56 |
}; |
| 57 |
|
| 58 |
class QMyResizeEvent : public QEvent |
| 59 |
{ |
| 60 |
public: |
| 61 |
int m_x, m_y; |
| 62 |
QMyResizeEvent(int x, int y) |
| 63 |
:QEvent(Q_MyResizeEvent), m_x(x), m_y(y) {} |
| 64 |
}; |
| 65 |
|
| 66 |
class PlayerControl; |
| 67 |
class QButton; |
| 68 |
|
| 69 |
class QPlayerWidget : public QWidget |
| 70 |
{ |
| 71 |
PlayerControl* m_pControl; |
| 72 |
public: |
| 73 |
QPlayerWidget(PlayerControl* c); |
| 74 |
virtual bool event(QEvent* e); |
| 75 |
|
| 76 |
QSlider* m_pScroller; |
| 77 |
QSlider* vbar; |
| 78 |
QProgressBar* pbar; |
| 79 |
QLabel* m_pLStatus; |
| 80 |
QLabel* m_pLTime; |
| 81 |
QButton* b_about; |
| 82 |
QButton* b_mute; |
| 83 |
QButton* b_open; |
| 84 |
QButton* b_pause; |
| 85 |
QButton* b_play; |
| 86 |
QButton* b_stop; |
| 87 |
}; |
| 88 |
|
| 89 |
class PlayerControl : public QObject, public PlayerWidget |
| 90 |
{ |
| 91 |
friend class QPlayerWidget; |
| 92 |
|
| 93 |
Q_OBJECT; |
| 94 |
|
| 95 |
enum { |
| 96 |
RATIO_ORIG, |
| 97 |
RATIO_16_9, |
| 98 |
RATIO_4_3, |
| 99 |
ZOOM_PLUS, |
| 100 |
ZOOM_MINUS, |
| 101 |
CROP_TOP, |
| 102 |
CROP_BOTTOM, |
| 103 |
CROP_LEFT, |
| 104 |
CROP_RIGHT, |
| 105 |
CROP_4_3, |
| 106 |
CROP_16_9, |
| 107 |
CROP_16_10, |
| 108 |
}; |
| 109 |
|
| 110 |
public: |
| 111 |
PlayerControl(); |
| 112 |
~PlayerControl(); |
| 113 |
int initPlayer(AviPlayerInitParams& avip); |
| 114 |
bool isValid() { return (player) ? true : false; } |
| 115 |
bool isStopped() { return (player) ? player->IsStopped() : true; } |
| 116 |
bool isPlaying() { return (player) ? player->IsPlaying() : false; } |
| 117 |
bool isPaused() { return (player) ? player->IsPaused() : false; } |
| 118 |
void decoderConfig(int); |
| 119 |
void endPlayer(); |
| 120 |
void ratio(int); |
| 121 |
void setDisplayFramePos(bool b) { m_bDisplayFramePos = b; } |
| 122 |
void sendKeyEvent(int qtkey, int qtascii = 0, int qtstate = 0); |
| 123 |
void sendRefresh(); |
| 124 |
void updatePosDisplay(double timepos); |
| 125 |
void zoom(float scale); |
| 126 |
void zoom_mode(int); |
| 127 |
void setRatio(int& x, int& y, int& w, int& h, int rw, int rh) |
| 128 |
{ |
| 129 |
if (rh * w >= rw * h) |
| 130 |
{ |
| 131 |
int n = rw * h / rh; x = (w - n) / 2; |
| 132 |
if (x < 8) { x = 0; n = w; } |
| 133 |
w = n; |
| 134 |
} |
| 135 |
else |
| 136 |
{ |
| 137 |
int n = rh * w / rw; y = (h - n) / 2; |
| 138 |
if (y < 8) { y = 0; n = h; } |
| 139 |
h = n; |
| 140 |
} |
| 141 |
} |
| 142 |
void zoomWH(int width, int height, int original_w, int original_h); |
| 143 |
double getTime() { return (player) ? player->GetTime() : 0.; } |
| 144 |
avm::IAviPlayer2* getPlayer() { return player; } |
| 145 |
QWidget* getWidget() { return m_pMW; } |
| 146 |
|
| 147 |
|
| 148 |
virtual void PW_showconf_func() {return showconfSlot();} |
| 149 |
virtual void PW_stop_func() { return stopSlot(); } |
| 150 |
virtual void PW_middle_button() {return middle_button();} |
| 151 |
virtual void PW_pause_func() { return pauseSlot(); } |
| 152 |
virtual void PW_play_func() { return playSlot(); } |
| 153 |
virtual void PW_quit_func() { return sendEvent(Q_MyCloseEvent); } |
| 154 |
virtual void PW_menu_slot() { return sendEvent(Q_MenuEvent); } |
| 155 |
virtual void PW_fullscreen() { return sendFullscreen(); } |
| 156 |
virtual void PW_key_func(int sym, int mod) { return keySlot(sym, mod); } |
| 157 |
virtual void PW_resize(int w, int h) { return sendQt(new QMyResizeEvent(w, h)); } |
| 158 |
virtual void PW_refresh() { return sendEvent(Q_MyRefreshEvent); } |
| 159 |
virtual void PW_maximize_func() { return sendMaximize(); } |
| 160 |
|
| 161 |
public slots: |
| 162 |
void aboutSlot(); |
| 163 |
void changedSlot(int); |
| 164 |
void fullscreen(); |
| 165 |
void keySlot(int sym, int mod); |
| 166 |
void maximize(); |
| 167 |
void maximizeMode(int); |
| 168 |
void menuSlot(); |
| 169 |
void middle_button(); |
| 170 |
void movedSlot(int); |
| 171 |
void muteChanged(); |
| 172 |
void nextPage(); |
| 173 |
void openSlot(); |
| 174 |
void openaudSlot(); |
| 175 |
void openpopupSlot(); |
| 176 |
void opensubSlot(); |
| 177 |
void pauseSlot(); |
| 178 |
void playSlot(); |
| 179 |
void prevPage(); |
| 180 |
void ratio_16_9() { ratio(RATIO_16_9); } |
| 181 |
void ratio_4_3() { ratio(RATIO_4_3); } |
| 182 |
void ratio_orig() { ratio(RATIO_ORIG); } |
| 183 |
void refresh(); |
| 184 |
void reseekSlot(); |
| 185 |
void resizePlayer(int, int); |
| 186 |
void sendConfig() { sendEvent(Q_MyConfigEvent); } |
| 187 |
void sendEvent(QEvent ev) { sendQt(new QEvent(ev)); } |
| 188 |
void sendFullscreen() { sendKeyEvent(Qt::Key_F, 'F'); } |
| 189 |
void sendMaximize() { sendKeyEvent(Qt::Key_M, 'M'); } |
| 190 |
void sendQt(QEvent* ev); |
| 191 |
void showconfSlot(); |
| 192 |
void sliderSlot() { m_bIsTracking = 1; } |
| 193 |
void stopSlot(); |
| 194 |
void updatePos(); |
| 195 |
void volumeChanged(int); |
| 196 |
void zoom_0_5x() { zoom(0.5); } |
| 197 |
void zoom_1x() { zoom(1.0); } |
| 198 |
void zoom_2x() { zoom(2.0); } |
| 199 |
void zoom_plus() { zoom_mode(ZOOM_PLUS); } |
| 200 |
void zoom_minus() { zoom_mode(ZOOM_MINUS); } |
| 201 |
void crop_top() { zoom_mode(CROP_TOP); } |
| 202 |
void crop_bottom() { zoom_mode(CROP_BOTTOM); } |
| 203 |
void crop_left() { zoom_mode(CROP_LEFT); } |
| 204 |
void crop_right() { zoom_mode(CROP_RIGHT); } |
| 205 |
void crop_16_9() { zoom_mode(CROP_16_9); } |
| 206 |
void crop_16_10() { zoom_mode(CROP_16_10); } |
| 207 |
void crop_4_3() { zoom_mode(CROP_4_3); } |
| 208 |
|
| 209 |
void remote_command(); |
| 210 |
|
| 211 |
void help(); |
| 212 |
void about(); |
| 213 |
void aboutMovie(); |
| 214 |
void audioDecoderConfig() { decoderConfig(player->AUDIO_CODECS); } |
| 215 |
void videoDecoderConfig() { decoderConfig(player->VIDEO_CODECS); } |
| 216 |
void rendererConfig(); |
| 217 |
void dropEvent(QDropEvent*); |
| 218 |
void dragEnterEvent(QDragEnterEvent* event); |
| 219 |
void starterSlot(); |
| 220 |
|
| 221 |
void keyPressEvent(QKeyEvent *); |
| 222 |
void mouseDoubleClickEvent(QMouseEvent*); |
| 223 |
void readConfig(); |
| 224 |
|
| 225 |
void hideSlot(); |
| 226 |
void showSlot(); |
| 227 |
|
| 228 |
protected: |
| 229 |
|
| 230 |
|
| 231 |
QPlayerWidget* m_pMW; |
| 232 |
#ifndef Qt3 |
| 233 |
QPopupMenu* popup; |
| 234 |
QPopupMenu* modes; |
| 235 |
QPopupMenu* m_pAboutPopup; |
| 236 |
QPopupMenu* m_pOpenPopup; |
| 237 |
#else |
| 238 |
Q3PopupMenu* popup; |
| 239 |
Q3PopupMenu* modes; |
| 240 |
Q3PopupMenu* m_pAboutPopup; |
| 241 |
Q3PopupMenu* m_pOpenPopup; |
| 242 |
#endif |
| 243 |
QString m_Theme; |
| 244 |
|
| 245 |
|
| 246 |
avm::IAviPlayer2* player; |
| 247 |
avm::PthreadMutex m_Mutex; |
| 248 |
avm::PthreadMutex m_Dialog; |
| 249 |
ConfigDialog* dlg; |
| 250 |
QTimer* m_pTimer; |
| 251 |
QTimer* m_TimerStarter; |
| 252 |
QString m_Filename; |
| 253 |
QString m_Subname; |
| 254 |
double m_dStartTime; |
| 255 |
double m_dLengthTime; |
| 256 |
int last_slider; |
| 257 |
int m_iLastVolume; |
| 258 |
int m_iResizeCount; |
| 259 |
|
| 260 |
AviPlayerInitParams apip; |
| 261 |
|
| 262 |
bool m_bSettingScroller; |
| 263 |
bool m_bKeyProcessed; |
| 264 |
bool m_bDisplayFramePos; |
| 265 |
bool m_bIsTracking; |
| 266 |
bool m_bInReseek; |
| 267 |
|
| 268 |
bool m_bUnpause; |
| 269 |
}; |
| 270 |
|
| 271 |
#endif |