diff options
author | Michele Calgaro <[email protected]> | 2020-06-13 22:45:28 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-06-13 22:45:28 +0900 |
commit | 5f44f7b187093ef290315b7f8766b540a31de35f (patch) | |
tree | 27ffb7b218199ca04f240c390c52426c65f45dce /src/app/adjustSizeButton.cpp | |
download | codeine-5f44f7b187093ef290315b7f8766b540a31de35f.tar.gz codeine-5f44f7b187093ef290315b7f8766b540a31de35f.zip |
Initial code import from debian snapshot
https://snapshot.debian.org/package/codeine/1.0.1-3.dfsg-3.1/
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/app/adjustSizeButton.cpp')
-rw-r--r-- | src/app/adjustSizeButton.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/app/adjustSizeButton.cpp b/src/app/adjustSizeButton.cpp new file mode 100644 index 0000000..041b01c --- /dev/null +++ b/src/app/adjustSizeButton.cpp @@ -0,0 +1,125 @@ +// (C) 2005 Max Howell ([email protected]) +// See COPYING file for licensing information + +#include "adjustSizeButton.h" +#include "extern.h" +#include <kpushbutton.h> +#include <qapplication.h> +#include <qevent.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpainter.h> +#include "theStream.h" +#include "xineEngine.h" //videoWindow() + + +QString i18n( const char *text ); + +namespace Codeine +{ + AdjustSizeButton::AdjustSizeButton( QWidget *parent ) + : QFrame( parent ) + , m_counter( 0 ) + , m_stage( 1 ) + , m_offset( 0 ) + { + parent->installEventFilter( this ); + + setPalette( QApplication::palette() ); //videoWindow has different palette + setFrameStyle( QFrame::Plain | QFrame::Box ); + + m_preferred = new KPushButton( KGuiItem( i18n("Preferred Scale"), "viewmag" ), this ); + connect( m_preferred, SIGNAL(clicked()), qApp->mainWidget(), SLOT(adjustSize()) ); + connect( m_preferred, SIGNAL(clicked()), SLOT(deleteLater()) ); + + m_oneToOne = new KPushButton( KGuiItem( i18n("Scale 100%"), "viewmag1" ), this ); + connect( m_oneToOne, SIGNAL(clicked()), (QObject*)videoWindow(), SLOT(resetZoom()) ); + connect( m_oneToOne, SIGNAL(clicked()), SLOT(deleteLater()) ); + + QBoxLayout *hbox = new QHBoxLayout( this, 8, 6 ); + QBoxLayout *vbox = new QVBoxLayout( hbox ); + vbox->addWidget( new QLabel( i18n( "<b>Adjust video scale?" ), this ) ); + vbox->addWidget( m_preferred ); + vbox->addWidget( m_oneToOne ); + hbox->addWidget( m_thingy = new QFrame( this ) ); + + m_thingy->setFixedWidth( fontMetrics().width( "X" ) ); + m_thingy->setFrameStyle( QFrame::Plain | QFrame::Box ); + m_thingy->setPaletteForegroundColor( paletteBackgroundColor().dark() ); + + QEvent e( QEvent::Resize ); + eventFilter( 0, &e ); + + adjustSize(); + show(); + + m_timerId = startTimer( 5 ); + } + + void + AdjustSizeButton::timerEvent( QTimerEvent* ) + { + QFrame *&h = m_thingy; + + switch( m_stage ) + { + case 1: //raise + move(); + m_offset++; + + if( m_offset > height() ) + killTimer( m_timerId ), + m_timerId = startTimer( 40 ), + m_stage = 2; + + break; + + case 2: //fill in pause timer bar + if( m_counter < h->height() - 3 ) + QPainter( h ).fillRect( 2, 2, h->width() - 4, m_counter, palette().active().highlight() ); + + if( !hasMouse() ) + m_counter++; + + if( m_counter > h->height() + 5 ) //pause for 360ms before lowering + m_stage = 3, + killTimer( m_timerId ), + m_timerId = startTimer( 6 ); + + break; + + case 3: //lower + if( hasMouse() ) { + m_stage = 1; + m_counter = 0; + m_thingy->repaint(); + break; } + + m_offset--; + move(); + + if( m_offset < 0 ) + deleteLater(); + } + } + + bool + AdjustSizeButton::eventFilter( QObject *o, QEvent *e ) + { + if( e->type() == QEvent::Resize ) { + const QSize preferredSize = TheStream::profile()->readSizeEntry( "Preferred Size" ); + const QSize defaultSize = TheStream::defaultVideoSize(); + const QSize parentSize = parentWidget()->size(); + + m_preferred->setEnabled( preferredSize.isValid() && parentSize != preferredSize && defaultSize != preferredSize ); + m_oneToOne->setEnabled( defaultSize != parentSize ); + + move(); + + if( !m_preferred->isEnabled() && !m_oneToOne->isEnabled() && m_counter == 0 ) + deleteLater(); + } + + return false; + } +} |