00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
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
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
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 void KPlayerPopupSliderAction::slotActivated (void)
00118 {
00119 KAction::slotActivated();
00120 QWidget* button = 0;
00121 if ( sender() )
00122 {
00123
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
00150 m_frame -> move (point);
00151
00152
00153
00154
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
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
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 int result = KWidgetAction::plug (widget, index);
00186 if ( result < 0 )
00187 return result;
00188 KToolBar* toolbar = (KToolBar*) widget;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 orientationChanged (toolbar -> orientation());
00202 connect (toolbar, SIGNAL (orientationChanged (Orientation)), this, SLOT (orientationChanged (Orientation)));
00203
00204
00205
00206
00207 return result;
00208 }
00209
00210 void KPlayerSliderAction::unplug (QWidget* widget)
00211 {
00212
00213
00214
00215 KWidgetAction::unplug (widget);
00216 if ( ! slider() || ! isPlugged() || widget != slider() -> parent() )
00217 return;
00218
00219 disconnect (widget, SIGNAL (orientationChanged (Orientation)), this, SLOT (orientationChanged (Orientation)));
00220
00221
00222
00223
00224
00225
00226
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 void KPlayerSliderAction::orientationChanged (Qt::Orientation orientation)
00252 {
00253
00254
00255
00256
00257 if ( slider() )
00258 slider() -> setOrientation (orientation);
00259 }
00260
00261
00262
00263
00264
00265
00266
00267 KPlayerSlider::KPlayerSlider (Qt::Orientation orientation, QWidget* parent, const char* name)
00268
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
00279 }
00280
00281 QSize KPlayerSlider::sizeHint() const
00282 {
00283 QSize hint = QSlider::sizeHint();
00284
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
00302 QSize hint = QSlider::minimumSizeHint();
00303
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 }