umbrello API Documentation

kplayerslideraction.cpp

00001 /***************************************************************************
00002     begin                : Sat Jan 11 2003
00003     copyright            : (C) 2003 by kiriuja
00004     email                : kplayer-dev@en-directo.net
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 /* Taken from kplayer CVS 2003-09-21 (kplayer > 0.3.1) by Jonathan Riddell
00017  * Changes from kplayer original marked by CHANGED
00018  */
00019 
00020 #include <kapplication.h>
00021 #include <ktoolbar.h>
00022 #include <ktoolbarbutton.h>
00023 #include <qtooltip.h>
00024 #include <qwhatsthis.h>
00025 
00026 #include <kdebug.h>
00027 
00028 //CHANGED #include "kplayersettings.h"
00029 #include "kplayerslideraction.h"
00030 #include "kplayerslideraction.moc"
00031 
00032 void KPlayerPopupFrame::keyPressEvent (QKeyEvent* ev)
00033 {
00034     switch ( ev -> key() )
00035     {
00036     case Qt::Key_Alt:
00037     case Qt::Key_Tab:
00038     case Qt::Key_Escape:
00039     case Qt::Key_Return:
00040     case Qt::Key_Enter:
00041         close();
00042     }
00043 }
00044 
00045 /*void KPlayerPopupFrame::closeEvent (QCloseEvent* ev)
00046 {
00047   QFrame::closeEvent (ev);
00048 }
00049 
00050 void KPlayerPopupFrame::mousePressEvent (QMouseEvent* ev)
00051 {
00052   QFrame::mousePressEvent (ev);
00053 //if ( ! rect().contains (ev -> pos()) )
00054 //  m_outside_mouse_press = true;
00055 }
00056 
00057 void KPlayerPopupFrame::mouseReleaseEvent (QMouseEvent* ev)
00058 {
00059   QFrame::mouseReleaseEvent (ev);
00060   if ( m_outside_mouse_press )
00061   {
00062     m_outside_mouse_press = false;
00063     if ( ! rect().contains (ev -> pos()) )
00064       close();
00065   }
00066 }*/
00067 
00068 KPlayerPopupSliderAction::KPlayerPopupSliderAction (const QString& text,
00069         const QString& pix, const KShortcut& shortcut, const QObject* receiver,
00070         const char* slot, QObject* parent, const char* name)
00071         : KAction (text, pix, shortcut, parent, name)
00072 {
00073     m_frame = new KPlayerPopupFrame;
00074     m_frame -> setFrameStyle (QFrame::PopupPanel | QFrame::Raised);
00075     m_frame -> setLineWidth (2);
00076     m_slider = new KPlayerSlider (Qt::Vertical, m_frame);
00077     m_frame -> resize (36, m_slider -> sizeHint().height() + 4);
00078     m_slider -> setGeometry (m_frame -> contentsRect());
00079     //CHANGED  kdDebug() << "Popup slider size " << m_slider -> width() << "x" << m_slider -> height() << "\n";
00080     connect (m_slider, SIGNAL (changed (int)), receiver, slot);
00081 }
00082 
00083 KPlayerPopupSliderAction::~KPlayerPopupSliderAction()
00084 {
00085     delete m_frame;
00086     m_frame = 0;
00087 }
00088 
00089 /*int KPlayerPopupSliderAction::plug (QWidget* widget, int index)
00090 {
00091   Q_ASSERT (m_slider);
00092   Q_ASSERT (widget);
00093   Q_ASSERT (! isPlugged());
00094   if ( ! m_slider || ! widget || isPlugged() )
00095     return -1;
00096   Q_ASSERT (widget -> inherits ("KToolBar"));
00097   if ( ! widget -> inherits ("KToolBar") )
00098     return -1;
00099   int retval = KAction::plug (widget, index);
00100 //  if ( retval >= 0 )
00101 //    m_slider -> reparent (widget, QPoint());
00102   return retval;
00103 }
00104 
00105 void KPlayerPopupSliderAction::unplug (QWidget* widget)
00106 {
00107   Q_ASSERT (m_slider);
00108   Q_ASSERT (widget);
00109   Q_ASSERT (isPlugged());
00110   Q_ASSERT (widget -> inherits ("KToolBar"));
00111   if ( ! m_slider || ! widget || ! isPlugged() || ! widget -> inherits ("KToolBar") )
00112     return;
00113 //m_slider -> reparent (0, QPoint());
00114   KAction::unplug (widget);
00115 }*/
00116 
00117 void KPlayerPopupSliderAction::slotActivated (void)
00118 {
00119     KAction::slotActivated();
00120     QWidget* button = 0;
00121     if ( sender() )
00122     {
00123         //CHANGED    kdDebug() << "Sender class name: " << sender() -> className() << "\n";
00124         if ( sender() -> inherits ("KToolBarButton") )
00125             button = (QWidget*) sender();
00126         else if ( sender() -> inherits ("KToolBar") )
00127         {
00128             KToolBar* toolbar = (KToolBar*) sender();
00129             int index = findContainer (toolbar);
00130             if ( index >= 0 )
00131                 button = toolbar -> getButton (itemId (index));
00132         }
00133     }
00134     QPoint point;
00135     if ( button )
00136         point = button -> mapToGlobal (QPoint (0, button -> height()));
00137     else
00138     {
00139         point = QCursor::pos() - QPoint (m_frame -> width() / 2, m_frame -> height() / 2);
00140         if ( point.x() + m_frame -> width() > QApplication::desktop() -> width() )
00141             point.setX (QApplication::desktop() -> width() - m_frame -> width());
00142         if ( point.y() + m_frame -> height() > QApplication::desktop() -> height() )
00143             point.setY (QApplication::desktop() -> height() - m_frame -> height());
00144         if ( point.x() < 0 )
00145             point.setX (0);
00146         if ( point.y() < 0 )
00147             point.setY (0);
00148     }
00149     //CHANGED  kdDebug() << "Point: " << point.x() << "x" << point.y() << "\n";
00150     m_frame -> move (point);
00151     /*if ( kapp && kapp -> activeWindow() )
00152       {
00153         QMouseEvent me (QEvent::MouseButtonRelease, QPoint(0,0), QPoint(0,0), QMouseEvent::LeftButton, QMouseEvent::NoButton);
00154         QApplication::sendEvent (kapp -> activeWindow(), &me);
00155       }*/
00156     m_frame -> show();
00157     m_slider -> setFocus();
00158 }
00159 
00160 KPlayerSliderAction::KPlayerSliderAction (const QString& text, const KShortcut& cut,
00161         const QObject* receiver, const char* slot, KActionCollection* parent, const char* name)
00162         : KWidgetAction (new KPlayerSlider (Qt::Horizontal, 0, name), text, cut, receiver, slot, parent, name)
00163         //: KAction (text, 0, parent, name)
00164 {
00165     setAutoSized (true);
00166     connect (slider(), SIGNAL (changed (int)), receiver, slot);
00167 }
00168 
00169 KPlayerSliderAction::~KPlayerSliderAction()
00170 {
00171 }
00172 
00173 int KPlayerSliderAction::plug (QWidget* widget, int index)
00174 {
00175     //Q_ASSERT (widget);
00176     //Q_ASSERT (! isPlugged());
00177     //Q_ASSERT (slider());
00178     //if ( ! slider() || ! widget || isPlugged() )
00179     //  return -1;
00180     //Q_ASSERT (widget -> inherits ("KToolBar"));
00181     //if ( ! widget -> inherits ("KToolBar") )
00182     //  return -1;
00183     //if ( kapp && ! kapp -> authorizeKAction (name()) )
00184     //  return -1;
00185     int result = KWidgetAction::plug (widget, index);
00186     if ( result < 0 )
00187         return result;
00188     KToolBar* toolbar = (KToolBar*) widget;
00189     //int id = getToolButtonID();
00190     //kdDebug() << "Orientation: " << toolbar -> orientation() << "\n";
00191     //m_slider -> reparent (toolbar, QPoint());
00192     //toolbar -> insertWidget (id, 0, m_slider, index);
00193     //toolbar -> setItemAutoSized (id, true);
00194     //QWhatsThis::remove (m_slider);
00195     //if ( ! whatsThis().isEmpty() )
00196     //  QWhatsThis::add (m_slider, whatsThis());
00197     //if ( ! text().isEmpty() )
00198     //  QToolTip::add (m_slider, text());
00199     //addContainer (toolbar, id);
00200     //setupToolbar (toolbar -> orientation(), toolbar);
00201     orientationChanged (toolbar -> orientation());
00202     connect (toolbar, SIGNAL (orientationChanged (Orientation)), this, SLOT (orientationChanged (Orientation)));
00203     //connect (toolbar, SIGNAL (destroyed()), this, SLOT (toolbarDestroyed()));
00204     //if ( parentCollection() )
00205     //  parentCollection() -> connectHighlight (toolbar, this);
00206     //return containerCount() - 1;
00207     return result;
00208 }
00209 
00210 void KPlayerSliderAction::unplug (QWidget* widget)
00211 {
00212     //Q_ASSERT (m_slider);
00213     //Q_ASSERT (isPlugged());
00214     //Q_ASSERT (widget -> inherits ("KToolBar"));
00215     KWidgetAction::unplug (widget);
00216     if ( ! slider() || ! isPlugged() || widget != slider() -> parent() )
00217         return;
00218     //KToolBar* toolbar = (KToolBar*) widget;
00219     disconnect (widget, SIGNAL (orientationChanged (Orientation)), this, SLOT (orientationChanged (Orientation)));
00220     //disconnect (toolbar, SIGNAL (destroyed()), this, SLOT (toolbarDestroyed()));
00221     //m_slider -> reparent (0, QPoint());
00222     /*int index = findContainer (toolbar);
00223       if ( index == -1 )
00224         return;
00225       bar -> removeItem (menuId (index));
00226       removeContainer (index);*/
00227 }
00228 
00229 /*void KPlayerSliderAction::setupToolbar (Orientation orientation, KToolBar* toolbar)
00230 {
00231     if ( orientation == Qt::Horizontal )
00232     {
00233 //      toolbar -> setMinimumWidth (300);
00234 //      toolbar -> setMinimumHeight (0);
00235       toolbar -> setFixedExtentWidth (300);
00236       toolbar -> setFixedExtentHeight (-1);
00237 //      toolbar -> setHorizontallyStretchable (true);
00238 //      toolbar -> setVerticallyStretchable (false);
00239     }
00240     else
00241     {
00242 //      toolbar -> setMinimumWidth (0);
00243 //      toolbar -> setMinimumHeight (300);
00244       toolbar -> setFixedExtentWidth (-1);
00245       toolbar -> setFixedExtentHeight (300);
00246 //      toolbar -> setHorizontallyStretchable (false);
00247 //      toolbar -> setVerticallyStretchable (true);
00248     }
00249 }*/
00250 
00251 void KPlayerSliderAction::orientationChanged (Qt::Orientation orientation)
00252 {
00253     //if ( sender() && sender() -> inherits ("KToolBar") )
00254     //  setupToolbar (orientation, (KToolBar*) sender());
00255     //Q_ASSERT (m_slider);
00256     //Q_ASSERT (isPlugged());
00257     if ( slider() )
00258         slider() -> setOrientation (orientation);
00259 }
00260 
00261 /*void KPlayerSliderAction::toolbarDestroyed (void)
00262 {
00263   if ( m_slider )
00264     m_slider -> reparent (0, QPoint());
00265 }*/
00266 
00267 KPlayerSlider::KPlayerSlider (Qt::Orientation orientation, QWidget* parent, const char* name)
00268 //CHANGED  : QSlider (orientation, parent, name)
00269         : QSlider (300, 2200, 400, 1000, orientation, parent, name)
00270 {
00271     m_changing_orientation = false;
00272     setTickmarks (QSlider::Both);
00273     connect (this, SIGNAL (valueChanged (int)), this, SLOT (sliderValueChanged (int)));
00274 }
00275 
00276 KPlayerSlider::~KPlayerSlider()
00277 {
00278     //CHANGED  kdDebug() << "KPlayerSlider destroyed\n";
00279 }
00280 
00281 QSize KPlayerSlider::sizeHint() const
00282 {
00283     QSize hint = QSlider::sizeHint();
00284     //CHANGED int length = kPlayerSettings() -> preferredSliderLength();
00285     int length = 200;
00286     if ( orientation() == Qt::Horizontal )
00287     {
00288         if ( hint.width() < length )
00289             hint.setWidth (length);
00290     }
00291     else
00292     {
00293         if ( hint.height() < length )
00294             hint.setHeight (length);
00295     }
00296     return hint;
00297 }
00298 
00299 QSize KPlayerSlider::minimumSizeHint() const
00300 {
00301     //kdDebug() << "KPlayerSlider minimum size hint\n";
00302     QSize hint = QSlider::minimumSizeHint();
00303     //CHANGED  int length = kPlayerSettings() -> minimumSliderLength();
00304     int length = 200;
00305     if ( orientation() == Qt::Horizontal )
00306     {
00307         if ( hint.width() < length )
00308             hint.setWidth (length);
00309     }
00310     else
00311     {
00312         if ( hint.height() < length )
00313             hint.setHeight (length);
00314     }
00315     return hint;
00316 }
00317 
00318 void KPlayerSlider::setOrientation (Qt::Orientation o)
00319 {
00320     if ( o == orientation() )
00321         return;
00322     m_changing_orientation = true;
00323     int minValue = QSlider::minValue();
00324     int maxValue = QSlider::maxValue();
00325     int value = QSlider::value();
00326     QSlider::setOrientation (o);
00327     QSlider::setMinValue (- maxValue);
00328     QSlider::setMaxValue (- minValue);
00329     QSlider::setValue (- value);
00330     m_changing_orientation = false;
00331 }
00332 
00333 int KPlayerSlider::minValue (void) const
00334 {
00335     if ( orientation() == Qt::Horizontal )
00336         return QSlider::minValue();
00337     return - QSlider::maxValue();
00338 }
00339 
00340 void KPlayerSlider::setMinValue (int minValue)
00341 {
00342     if ( orientation() == Qt::Horizontal )
00343         QSlider::setMinValue (minValue);
00344     else
00345         QSlider::setMaxValue (- minValue);
00346 }
00347 
00348 int KPlayerSlider::maxValue (void) const
00349 {
00350     if ( orientation() == Qt::Horizontal )
00351         return QSlider::maxValue();
00352     return - QSlider::minValue();
00353 }
00354 
00355 void KPlayerSlider::setMaxValue (int maxValue)
00356 {
00357     if ( orientation() == Qt::Horizontal )
00358         QSlider::setMaxValue (maxValue);
00359     else
00360         QSlider::setMinValue (- maxValue);
00361 }
00362 
00363 int KPlayerSlider::lineStep (void) const
00364 {
00365     return QSlider::lineStep();
00366 }
00367 
00368 void KPlayerSlider::setLineStep (int lineStep)
00369 {
00370     QSlider::setLineStep (lineStep);
00371 }
00372 
00373 int KPlayerSlider::pageStep (void) const
00374 {
00375     return QSlider::pageStep();
00376 }
00377 
00378 void KPlayerSlider::setPageStep (int pageStep)
00379 {
00380     QSlider::setPageStep (pageStep);
00381     setTickInterval (pageStep);
00382 }
00383 
00384 int KPlayerSlider::value (void) const
00385 {
00386     if ( orientation() == Qt::Horizontal )
00387         return QSlider::value();
00388     return - QSlider::value();
00389 }
00390 
00391 void KPlayerSlider::setValue (int value, int)
00392 {
00393     if ( orientation() == Qt::Horizontal )
00394         QSlider::setValue (value);
00395     else
00396         QSlider::setValue (- value);
00397 }
00398 
00399 void KPlayerSlider::setup (int minValue, int maxValue, int value, int pageStep, int lineStep)
00400 {
00401     setMinValue (minValue);
00402     setMaxValue (maxValue);
00403     setLineStep (lineStep);
00404     setPageStep (pageStep);
00405     setValue (value);
00406 }
00407 
00408 void KPlayerSlider::sliderValueChanged (int)
00409 {
00410     if ( ! m_changing_orientation )
00411         emit changed (value());
00412 }
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:58 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003