diff options
author | Maia Kozheva <sikon@ubuntu.com> | 2009-11-20 18:22:19 +0600 |
---|---|---|
committer | Maia Kozheva <sikon@ubuntu.com> | 2009-11-20 18:22:19 +0600 |
commit | 263b32f108c15cd1c55a8f4eb4704fac6553f1ac (patch) | |
tree | 1c49e7848aa2d3d64a9d9b96b8852cb1884da2f7 /src/mpcgui |
Imported Upstream version 0.6.8
Diffstat (limited to 'src/mpcgui')
-rw-r--r-- | src/mpcgui/mpc_mono.png | bin | 0 -> 1599 bytes | |||
-rw-r--r-- | src/mpcgui/mpc_stereo.png | bin | 0 -> 1830 bytes | |||
-rw-r--r-- | src/mpcgui/mpc_toolbar.png | bin | 0 -> 2092 bytes | |||
-rw-r--r-- | src/mpcgui/mpcgui.cpp | 472 | ||||
-rw-r--r-- | src/mpcgui/mpcgui.h | 101 | ||||
-rw-r--r-- | src/mpcgui/mpcstyles.cpp | 239 | ||||
-rw-r--r-- | src/mpcgui/mpcstyles.h | 58 |
7 files changed, 870 insertions, 0 deletions
diff --git a/src/mpcgui/mpc_mono.png b/src/mpcgui/mpc_mono.png Binary files differnew file mode 100644 index 0000000..9a11dad --- /dev/null +++ b/src/mpcgui/mpc_mono.png diff --git a/src/mpcgui/mpc_stereo.png b/src/mpcgui/mpc_stereo.png Binary files differnew file mode 100644 index 0000000..08fd16c --- /dev/null +++ b/src/mpcgui/mpc_stereo.png diff --git a/src/mpcgui/mpc_toolbar.png b/src/mpcgui/mpc_toolbar.png Binary files differnew file mode 100644 index 0000000..fad457b --- /dev/null +++ b/src/mpcgui/mpc_toolbar.png diff --git a/src/mpcgui/mpcgui.cpp b/src/mpcgui/mpcgui.cpp new file mode 100644 index 0000000..5bb0a09 --- /dev/null +++ b/src/mpcgui/mpcgui.cpp @@ -0,0 +1,472 @@ +/* Mpcgui for SMPlayer. + Copyright (C) 2008 matt_ <matt@endboss.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "mpcgui.h" +#include "mpcstyles.h" +#include "widgetactions.h" +#include "floatingwidget.h" +#include "myaction.h" +#include "mplayerwindow.h" +#include "global.h" +#include "helper.h" +#include "toolbareditor.h" +#include "desktopinfo.h" +#include "colorutils.h" + +#include <QToolBar> +#include <QStatusBar> +#include <QLabel> +#include <QSlider> +#include <QApplication> + +using namespace Global; + + +MpcGui::MpcGui( QWidget * parent, Qt::WindowFlags flags ) + : BaseGuiPlus( parent, flags ) +{ + createActions(); + createControlWidget(); + createStatusBar(); + + connect( this, SIGNAL(cursorNearBottom(QPoint)), + this, SLOT(showFloatingControl(QPoint)) ); + + connect( this, SIGNAL(cursorFarEdges()), + this, SLOT(hideFloatingControl()) ); + + retranslateStrings(); + + loadConfig(); + + if (pref->compact_mode) { + controlwidget->hide(); + timeslidewidget->hide(); + } +} + +MpcGui::~MpcGui() { + saveConfig(); +} + +void MpcGui::createActions() { + timeslider_action = createTimeSliderAction(this); + timeslider_action->disable(); + timeslider_action->setCustomStyle( new MpcTimeSlideStyle() ); + +#if USE_VOLUME_BAR + volumeslider_action = createVolumeSliderAction(this); + volumeslider_action->disable(); + volumeslider_action->setCustomStyle( new MpcVolumeSlideStyle() ); + volumeslider_action->setFixedSize( QSize(50,18) ); + volumeslider_action->setTickPosition( QSlider::NoTicks ); +#endif + + time_label_action = new TimeLabelAction(this); + time_label_action->setObjectName("timelabel_action"); + + connect( this, SIGNAL(timeChanged(QString)), + time_label_action, SLOT(setText(QString)) ); +} + + +void MpcGui::createControlWidget() { + controlwidget = new QToolBar( this ); + controlwidget->setObjectName("controlwidget"); + controlwidget->setMovable(false); + controlwidget->setAllowedAreas(Qt::BottomToolBarArea); + controlwidget->addAction(playAct); + controlwidget->addAction(pauseAct); + controlwidget->addAction(stopAct); + controlwidget->addSeparator(); + controlwidget->addAction(rewind3Act); + controlwidget->addAction(rewind1Act); + controlwidget->addAction(forward1Act); + controlwidget->addAction(forward3Act); + controlwidget->addSeparator(); + controlwidget->addAction(frameStepAct); + controlwidget->addSeparator(); + + QLabel* pLabel = new QLabel(this); + pLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); + controlwidget->addWidget(pLabel); + + controlwidget->addAction(muteAct); + controlwidget->addAction(volumeslider_action); + + timeslidewidget = new QToolBar( this ); + timeslidewidget->setObjectName("timeslidewidget"); + timeslidewidget->addAction(timeslider_action); + timeslidewidget->setMovable(false); + + QColor SliderColor = palette().color(QPalette::Window); + QColor SliderBorderColor = palette().color(QPalette::Dark); + setIconSize( QSize( 16 , 16 ) ); + + addToolBar(Qt::BottomToolBarArea, controlwidget); + addToolBarBreak(Qt::BottomToolBarArea); + addToolBar(Qt::BottomToolBarArea, timeslidewidget); + + controlwidget->setStyle(new MpcToolbarStyle() ); + timeslidewidget->setStyle(new MpcToolbarStyle() ); + + statusBar()->show(); +} + +void MpcGui::retranslateStrings() { + BaseGuiPlus::retranslateStrings(); + + controlwidget->setWindowTitle( tr("Control bar") ); + + setupIcons(); +} + +#if AUTODISABLE_ACTIONS +void MpcGui::enableActionsOnPlaying() { + BaseGuiPlus::enableActionsOnPlaying(); + + timeslider_action->enable(); +#if USE_VOLUME_BAR + volumeslider_action->enable(); +#endif +} + +void MpcGui::disableActionsOnStop() { + BaseGuiPlus::disableActionsOnStop(); + + timeslider_action->disable(); +#if USE_VOLUME_BAR + volumeslider_action->disable(); +#endif +} +#endif // AUTODISABLE_ACTIONS + +void MpcGui::aboutToEnterFullscreen() { + BaseGuiPlus::aboutToEnterFullscreen(); + + if (!pref->compact_mode) { + controlwidget->hide(); + timeslidewidget->hide(); + statusBar()->hide(); + } +} + +void MpcGui::aboutToExitFullscreen() { + BaseGuiPlus::aboutToExitFullscreen(); + + if (!pref->compact_mode) { + controlwidget->show(); + statusBar()->show(); + timeslidewidget->show(); + } +} + +void MpcGui::aboutToEnterCompactMode() { + BaseGuiPlus::aboutToEnterCompactMode(); + + controlwidget->hide(); + timeslidewidget->hide(); + statusBar()->hide(); +} + +void MpcGui::aboutToExitCompactMode() { + BaseGuiPlus::aboutToExitCompactMode(); + + statusBar()->show(); + controlwidget->show(); + timeslidewidget->show(); +} + +void MpcGui::showFloatingControl(QPoint /*p*/) { +} + +void MpcGui::hideFloatingControl() { +} + +#if USE_mpcMUMSIZE +QSize MpcGui::mpcmumSizeHint() const { + return QSize(controlwidget->sizeHint().width(), 0); +} +#endif + + +void MpcGui::saveConfig() { + QSettings * set = settings; + + set->beginGroup( "mpc_gui"); + + if (pref->save_window_size_on_exit) { + qDebug("MpcGui::saveConfig: w: %d h: %d", width(), height()); + set->setValue( "pos", pos() ); + set->setValue( "size", size() ); + } + + set->setValue( "toolbars_state", saveState(Helper::qtVersion()) ); + +/* +#if USE_CONFIGURABLE_TOOLBARS + set->beginGroup( "actions" ); + set->setValue("controlwidget", ToolbarEditor::save(controlwidget) ); + set->endGroup(); +#endif +*/ + + set->endGroup(); +} + +void MpcGui::loadConfig() { + QSettings * set = settings; + + set->beginGroup( "mpc_gui"); + + if (pref->save_window_size_on_exit) { + QPoint p = set->value("pos", pos()).toPoint(); + QSize s = set->value("size", size()).toSize(); + + if ( (s.height() < 200) && (!pref->use_mplayer_window) ) { + s = pref->default_size; + } + + move(p); + resize(s); + + if (!DesktopInfo::isInsideScreen(this)) { + move(0,0); + qWarning("MpcGui::loadConfig: window is outside of the screen, moved to 0x0"); + } + } + + restoreState( set->value( "toolbars_state" ).toByteArray(), Helper::qtVersion() ); + + set->endGroup(); +} + +void MpcGui::setupIcons() { + playAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) ); + playOrPauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(0,0,16,16) ); + pauseAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) ); + pauseAndStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(16,0,16,16) ); + stopAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(32,0,16,16) ); + rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) ); + rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) ); + frameStepAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(144,0,16,16) ); + muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) ); + + pauseAct->setCheckable(true); + playAct->setCheckable(true); + stopAct->setCheckable(true); + connect( muteAct, SIGNAL(toggled(bool)), + this, SLOT(muteIconChange(bool)) ); + + connect( core , SIGNAL(mediaInfoChanged()), + this, SLOT(updateAudioChannels()) ); + + connect( core , SIGNAL(stateChanged(Core::State)), + this, SLOT(iconChange(Core::State)) ); +} + +void MpcGui::iconChange(Core::State state) { + playAct->blockSignals(true); + pauseAct->blockSignals(true); + stopAct->blockSignals(true); + + if( state == Core::Paused ) + { + playAct->setChecked(false); + pauseAct->setChecked(true); + stopAct->setChecked(false); + } + if( state == Core::Playing ) + { + playAct->setChecked(true); + pauseAct->setChecked(false); + stopAct->setChecked(false); + } + if( state == Core::Stopped ) + { + playAct->setChecked(false); + pauseAct->setChecked(false); + stopAct->setChecked(false); + } + + playAct->blockSignals(false); + pauseAct->blockSignals(false); + stopAct->blockSignals(false); +} + +void MpcGui::muteIconChange(bool b) { + if( sender() == muteAct ) + { + if(!b) { + muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(192,0,16,16) ); + } else { + muteAct->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(208,0,16,16) ); + } + } + +} + + +void MpcGui::createStatusBar() { + + // remove frames around statusbar items + statusBar()->setStyleSheet("QStatusBar::item { border: 0px solid black }; "); + + // emulate mono/stereo display from mpc + audiochannel_display = new QLabel( statusBar() ); + audiochannel_display->setContentsMargins(0,0,0,0); + audiochannel_display->setAlignment(Qt::AlignRight); + audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") ); + audiochannel_display->setMinimumSize(audiochannel_display->sizeHint()); + audiochannel_display->setMaximumSize(audiochannel_display->sizeHint()); + audiochannel_display->setPixmap( QPixmap("") ); + + time_display = new QLabel( statusBar() ); + time_display->setAlignment(Qt::AlignRight); + time_display->setText(" 88:88:88 / 88:88:88 "); + time_display->setMinimumSize(time_display->sizeHint()); + time_display->setContentsMargins(15,2,1,1); + + frame_display = new QLabel( statusBar() ); + frame_display->setAlignment(Qt::AlignRight); + frame_display->setText("88888888"); + frame_display->setMinimumSize(frame_display->sizeHint()); + frame_display->setContentsMargins(15,2,1,1); + + statusBar()->setAutoFillBackground(TRUE); + + ColorUtils::setBackgroundColor( statusBar(), QColor(0,0,0) ); + ColorUtils::setForegroundColor( statusBar(), QColor(255,255,255) ); + ColorUtils::setBackgroundColor( time_display, QColor(0,0,0) ); + ColorUtils::setForegroundColor( time_display, QColor(255,255,255) ); + ColorUtils::setBackgroundColor( frame_display, QColor(0,0,0) ); + ColorUtils::setForegroundColor( frame_display, QColor(255,255,255) ); + ColorUtils::setBackgroundColor( audiochannel_display, QColor(0,0,0) ); + ColorUtils::setForegroundColor( audiochannel_display, QColor(255,255,255) ); + statusBar()->setSizeGripEnabled(FALSE); + + + + statusBar()->addPermanentWidget( frame_display, 0 ); + frame_display->setText( "0" ); + + statusBar()->addPermanentWidget( time_display, 0 ); + time_display->setText(" 00:00:00 / 00:00:00 "); + + statusBar()->addPermanentWidget( audiochannel_display, 0 ); + + time_display->show(); + frame_display->hide(); + + connect( this, SIGNAL(timeChanged(QString)), + this, SLOT(displayTime(QString)) ); + + connect( this, SIGNAL(frameChanged(int)), + this, SLOT(displayFrame(int)) ); + + connect( this, SIGNAL(cursorNearBottom(QPoint)), + this, SLOT(showFullscreenControls()) ); + + connect( this, SIGNAL(cursorFarEdges()), + this, SLOT(hideFullscreenControls()) ); +} + +void MpcGui::displayTime(QString text) { + time_display->setText( text ); + time_label_action->setText(text ); +} + +void MpcGui::displayFrame(int frame) { + if (frame_display->isVisible()) { + frame_display->setNum( frame ); + } +} + +void MpcGui::updateAudioChannels() { + if( core->mdat.audio_nch == 1 ) { + audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_mono.png") ); + } + else { + audiochannel_display->setPixmap( QPixmap(":/mpcgui/mpc_stereo.png") ); + } +} + +void MpcGui::showFullscreenControls() { + + if(pref->fullscreen && controlwidget->isHidden() && timeslidewidget->isHidden() && + !pref->compact_mode ) + { + controlwidget->show(); + timeslidewidget->show(); + statusBar()->show(); + } +} + +void MpcGui::hideFullscreenControls() { + + if(pref->fullscreen && controlwidget->isVisible() && timeslidewidget->isVisible() ) + { + controlwidget->hide(); + timeslidewidget->hide(); + statusBar()->hide(); + } +} + +void MpcGui::setJumpTexts() { + rewind1Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking1)) ); + rewind2Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking2)) ); + rewind3Act->change( tr("-%1").arg(Helper::timeForJumps(pref->seeking3)) ); + + forward1Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking1)) ); + forward2Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking2)) ); + forward3Act->change( tr("+%1").arg(Helper::timeForJumps(pref->seeking3)) ); + + if (qApp->isLeftToRight()) { + rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) ); + + forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) ); + + } else { + rewind1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + rewind2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(96,0,16,16) ); + rewind3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(112,0,16,16) ); + + forward1Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + forward2Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(80,0,16,16) ); + forward3Act->setIcon( QPixmap(":/mpcgui/mpc_toolbar.png").copy(64,0,16,16) ); + } +} + +void MpcGui::updateWidgets() { + + BaseGui::updateWidgets(); + + // Frame counter + frame_display->setVisible( pref->show_frame_counter ); +} + +#include "moc_mpcgui.cpp" + diff --git a/src/mpcgui/mpcgui.h b/src/mpcgui/mpcgui.h new file mode 100644 index 0000000..78ce271 --- /dev/null +++ b/src/mpcgui/mpcgui.h @@ -0,0 +1,101 @@ +/* Mpcgui for SMPlayer. + Copyright (C) 2008 matt_ <matt@endboss.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _MPC_GUI_H_ +#define _MPC_GUI_H_ + +#include "baseguiplus.h" +#include "guiconfig.h" + +#define USE_VOLUME_BAR 1 + +class TimeSliderAction; +class VolumeSliderAction; +class TimeLabelAction; +class FloatingWidget; +class QToolBar; + +class MpcGui : public BaseGuiPlus +{ + Q_OBJECT + +public: + MpcGui( QWidget* parent = 0, Qt::WindowFlags flags = 0 ); + ~MpcGui(); + +#if USE_MPCMUMSIZE + virtual QSize mpcmumSizeHint () const; +#endif + +protected slots: + void showFloatingControl(QPoint p); + void hideFloatingControl(); + void muteIconChange(bool b); + void iconChange(Core::State state); + void updateAudioChannels(); + + void displayTime(QString text); + void displayFrame(int frame); + void showFullscreenControls(); + void hideFullscreenControls(); + void setJumpTexts(); + void updateWidgets(); + + // Reimplemented: +#if AUTODISABLE_ACTIONS + virtual void enableActionsOnPlaying(); + virtual void disableActionsOnStop(); +#endif + +protected: + virtual void retranslateStrings(); + + void createActions(); + void createControlWidget(); + void createFloatingControl(); + void createStatusBar(); + + void setupIcons(); + + void loadConfig(); + void saveConfig(); + + // Reimplemented + virtual void aboutToEnterFullscreen(); + virtual void aboutToExitFullscreen(); + virtual void aboutToEnterCompactMode(); + virtual void aboutToExitCompactMode(); + +protected: + QToolBar* controlwidget; + QToolBar* timeslidewidget; + + QLabel * audiochannel_display; + QLabel * time_display; + QLabel * frame_display; + + FloatingWidget * floating_control; + + TimeSliderAction * timeslider_action; +#if USE_VOLUME_BAR + VolumeSliderAction * volumeslider_action; +#endif + TimeLabelAction * time_label_action; +}; + +#endif diff --git a/src/mpcgui/mpcstyles.cpp b/src/mpcgui/mpcstyles.cpp new file mode 100644 index 0000000..f24b97e --- /dev/null +++ b/src/mpcgui/mpcstyles.cpp @@ -0,0 +1,239 @@ +/* Mpcgui for SMPlayer. + Copyright (C) 2008 matt_ <matt@endboss.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "mpcstyles.h" + +#include <QWindowsStyle> +#include <QStyleOptionToolBar> +#include <QSlider> +#include <QPainter> + + +void +MpcToolbarStyle::drawControl(ControlElement control, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const +{ + if(control == CE_ToolBar) + { + if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) { + QRect rect = option->rect; + + if( toolbar->toolBarArea == Qt::BottomToolBarArea && + toolbar->positionOfLine == QStyleOptionToolBar::End ) + { + painter->setPen(QPen(option->palette.light().color())); + painter->drawLine(rect.topLeft().x(), + rect.topLeft().y(), + rect.topRight().x(), + rect.topRight().y()); + + painter->setPen(QPen(option->palette.light().color())); + painter->drawLine(rect.topLeft().x(), + rect.topLeft().y(), + rect.bottomLeft().x(), + rect.bottomLeft().y()); + + painter->setPen(QPen(option->palette.dark().color())); + painter->drawLine(rect.topRight().x(), + rect.topRight().y(), + rect.bottomRight().x(), + rect.bottomRight().y()); + + } + else if( toolbar->toolBarArea == Qt::BottomToolBarArea && + toolbar->positionOfLine == QStyleOptionToolBar::Beginning ) + { + painter->setPen(QPen(option->palette.light().color())); + painter->drawLine(rect.topLeft().x(), + rect.topLeft().y(), + rect.bottomLeft().x(), + rect.bottomLeft().y()); + + painter->setPen(QPen(option->palette.dark().color())); + painter->drawLine(rect.topRight().x(), + rect.topRight().y(), + rect.bottomRight().x(), + rect.bottomRight().y()); + + painter->setPen(QPen(option->palette.dark().color())); + painter->drawLine(rect.bottomLeft().x(), + rect.bottomLeft().y(), + rect.bottomRight().x(), + rect.bottomRight().y()); + } + else + { + QWindowsStyle::drawControl(control,toolbar, painter, widget); + } + } + } + else + { + QWindowsStyle::drawControl(control,option, painter, widget); + } +} + +// draw custom slider + handle for volume widget +void MpcVolumeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + QPainter *p, const QWidget *widget) const +{ + if( cc == CC_Slider ) + { + if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { + QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); + QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); + + if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { + + p->setPen(slider->palette.shadow().color()); + if (slider->orientation == Qt::Horizontal) { + static QPoint points[3] = { + QPoint(groove.x() , groove.y() + slider->rect.height() ), + QPoint(groove.x() + groove.width() -2 , groove.y() + slider->rect.height() ), + QPoint(groove.x() + groove.width() -2 , groove.y() ), + }; + QPen oldPen = p->pen(); + + p->setPen(slider->palette.dark().color()); + p->drawLine(QPoint(points[0].x(), points[0].y() -2 ),QPoint(points[2].x(), points[2].y())); + + QPoint b[3] = { QPoint(points[0].x(),points[0].y()-1), QPoint(points[1].x()-1, points[1].y()-1), QPoint(points[2].x()-1,points[2].y()) }; + p->setPen(slider->palette.light().color()); + p->drawPolyline(b, 3); + p->setPen(oldPen); + } + } + + + if (slider->subControls & SC_SliderTickmarks) { + QStyleOptionSlider tmpSlider = *slider; + tmpSlider.subControls = SC_SliderTickmarks; + QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget); + } + + if (slider->subControls & SC_SliderHandle) { + const QColor c0 = slider->palette.shadow().color(); + const QColor c1 = slider->palette.dark().color(); + // const QColor c2 = g.button(); + const QColor c3 = slider->palette.midlight().color(); + const QColor c4 = slider->palette.light().color(); + QBrush handleBrush; + + if (slider->state & State_Enabled) { + handleBrush = slider->palette.color(QPalette::Button); + } else { + handleBrush = QBrush(slider->palette.color(QPalette::Button), + Qt::Dense4Pattern); + } + + + int x = handle.x() , y = handle.y(), + wi = handle.width() - 2, he = slider->rect.height(); + + if (slider->state & State_HasFocus) { + QStyleOptionFocusRect fropt; + fropt.QStyleOption::operator=(*slider); + fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget); + drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); + } + + Qt::BGMode oldMode = p->backgroundMode(); + p->setBackgroundMode(Qt::OpaqueMode); + qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false, + &handleBrush); + p->setBackgroundMode(oldMode); + + } + } + } + else + { + QWindowsStyle::drawComplexControl(cc,opt,p,widget); + } +} + +// draw custom slider + handle for timeslide widget +void MpcTimeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + QPainter *p, const QWidget *widget) const +{ + if( cc == CC_Slider ) + { + if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { + QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget); + QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget); + + if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { + if (slider->orientation == Qt::Horizontal) { + int x = groove.x() + 2; + int y = slider->rect.height() / 2 - 4; + int w = groove.width() - 4; + int h = 7; + qDrawShadeRect (p,x,y,w,h, slider->palette, true,1,0, + &slider->palette.brush(QPalette::Light)); + } + } + + + if (slider->subControls & SC_SliderTickmarks) { + QStyleOptionSlider tmpSlider = *slider; + tmpSlider.subControls = SC_SliderTickmarks; + QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget); + } + + if (slider->subControls & SC_SliderHandle) { + const QColor c0 = slider->palette.shadow().color(); + const QColor c1 = slider->palette.dark().color(); + // const QColor c2 = g.button(); + const QColor c3 = slider->palette.midlight().color(); + const QColor c4 = slider->palette.light().color(); + QBrush handleBrush; + + if (slider->state & State_Enabled) { + handleBrush = slider->palette.color(QPalette::Button); + } else { + handleBrush = QBrush(slider->palette.color(QPalette::Button), + Qt::Dense4Pattern); + } + + + int x = handle.x() , y = handle.y() + 1, + wi = 13, he = 14; + + if (slider->state & State_HasFocus) { + QStyleOptionFocusRect fropt; + fropt.QStyleOption::operator=(*slider); + fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget); + drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); + } + + Qt::BGMode oldMode = p->backgroundMode(); + p->setBackgroundMode(Qt::OpaqueMode); + qDrawWinPanel(p, QRect(x, y, wi, he), slider->palette, false, + &handleBrush); + qDrawShadeRect (p, QRect(x+2,y+3, wi-4, he-6), slider->palette, true,1,0, + &slider->palette.brush(QPalette::Light)); + p->setBackgroundMode(oldMode); + } + } + } + else + { + QWindowsStyle::drawComplexControl(cc,opt,p,widget); + } +} + diff --git a/src/mpcgui/mpcstyles.h b/src/mpcgui/mpcstyles.h new file mode 100644 index 0000000..a3079f1 --- /dev/null +++ b/src/mpcgui/mpcstyles.h @@ -0,0 +1,58 @@ +/* Mpcgui for SMPlayer. + Copyright (C) 2008 matt_ <matt@endboss.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _MPC_STYLES_H_ +#define _MPC_STYLES_H_ + +#include <QWindowsStyle> +#include <QStyleOptionToolBar> + +enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; + +class MpcToolbarStyle : public QWindowsStyle +{ + Q_OBJECT + +public: + MpcToolbarStyle() {}; + void drawControl(ControlElement control, const QStyleOption *option, + QPainter *painter, const QWidget *widget) const; +}; + +class MpcTimeSlideStyle : public QWindowsStyle +{ + Q_OBJECT + +public: + MpcTimeSlideStyle() {}; + void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + QPainter *p, const QWidget *widget) const; +}; + +class MpcVolumeSlideStyle : public QWindowsStyle +{ + Q_OBJECT + +public: + MpcVolumeSlideStyle() {}; + void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + QPainter *p, const QWidget *widget) const; +}; + + +#endif |