src/hbwidgets/popups/hbzoomsliderpopup.cpp
changeset 0 16d8024aca5e
child 6 c3690ec91ef8
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbzoomslider_p.h"
       
    27 #include <hbzoomsliderpopup.h>
       
    28 #include <hbinstance.h>
       
    29 #include "hbsliderpopup_p.h"
       
    30 #include "hblayoutdirectionnotifier_p.h"
       
    31 #include <hbmessagebox.h>
       
    32 #include "hbdeviceprofile.h"
       
    33 
       
    34 /*!
       
    35     @beta
       
    36     @hbwidgets
       
    37     \class HbZoomSliderPopup
       
    38     \brief HbZoomSliderPopup widget provides a vertical zoom slider embedded in a popup.
       
    39 
       
    40     HbZoomSliderPopup is provided for convenience. HbZoomSliderPopup sets appropriate
       
    41     icons, properties and provides zoom slider specific functionality like a
       
    42     zoom level indicator label and appropriate elements out of the box.
       
    43     HbZoomSlider sets HbSlider::text  and consists of following
       
    44     slider elements by default:
       
    45     \li HbSlider::IncreaseElement
       
    46     \li HbSlider::TrackElement
       
    47     \li HbSlider::DecreaseElement
       
    48     \li HbSlider::TextElement
       
    49 
       
    50     \image html hbzoomslider.png A vertical zoom slider.
       
    51 
       
    52     The elements can be changed by calling HbSlider::setElements() later at any time.
       
    53 
       
    54     Orientation of HbZoomSliderPopup can not be changed. If orientation change is need, 
       
    55     then first create HbSlider and set needed elements.
       
    56 
       
    57     Example usage:
       
    58     \code
       
    59     HbZoomSliderPopup *slider = new HbZoomSliderPopup();
       
    60     connect(slider, SIGNAL(valueChanged(int)), receiver, SLOT(zoomSliderChanged(int)));
       
    61     \endcode
       
    62 
       
    63     
       
    64     Note:: position and size of these elements cant be change.
       
    65     use HbZoomSlider instead if you want to change position or size
       
    66 
       
    67     Note:: if setElement is called on this slider ,  application is reponsible for
       
    68     inconsitent UI.
       
    69 */
       
    70 
       
    71 /*!
       
    72     \reimp
       
    73     \fn int HbZoomSlider::type() const
       
    74  */
       
    75 
       
    76 /*
       
    77     internal
       
    78  */
       
    79 class HbZoomSliderPopupPrivate : public HbSliderPopupPrivate
       
    80 {
       
    81  Q_DECLARE_PUBLIC(HbZoomSliderPopup) 
       
    82 protected:
       
    83     virtual void createSlider();
       
    84 public:
       
    85     HbZoomSliderPopupPrivate();
       
    86     virtual ~HbZoomSliderPopupPrivate();
       
    87     void init();
       
    88   
       
    89 };
       
    90 
       
    91 /*
       
    92     internal
       
    93  */
       
    94 void HbZoomSliderPopupPrivate::init()
       
    95 {
       
    96     Q_Q(HbZoomSliderPopup);
       
    97     q->setTimeout(0);
       
    98 }
       
    99 
       
   100 
       
   101 
       
   102 /*
       
   103     internal
       
   104  */
       
   105 HbZoomSliderPopupPrivate::HbZoomSliderPopupPrivate() 
       
   106 {
       
   107  
       
   108 }
       
   109 
       
   110 /*
       
   111     reimp
       
   112  */
       
   113 void HbZoomSliderPopupPrivate::createSlider() 
       
   114 {
       
   115     slider = new HbZoomSlider();
       
   116 }
       
   117 
       
   118 /*
       
   119    internal
       
   120  */
       
   121 HbZoomSliderPopupPrivate::~HbZoomSliderPopupPrivate()
       
   122 {
       
   123 }
       
   124 
       
   125   
       
   126 /*!
       
   127     @beta
       
   128     Constructs a slider with \a parent.
       
   129 
       
   130     The orientation is \b Qt::Vertical and the slider contains only track element by default.
       
   131 
       
   132     \sa setOrientation(), setElements()
       
   133 */
       
   134 HbZoomSliderPopup::HbZoomSliderPopup() :
       
   135     HbSliderPopup(*new HbZoomSliderPopupPrivate, NULL)
       
   136 {
       
   137     Q_D(HbZoomSliderPopup);
       
   138     d->q_ptr = this;
       
   139     d->init();
       
   140 }
       
   141 
       
   142 /*!
       
   143     @beta
       
   144     \internal
       
   145  */
       
   146 HbZoomSliderPopup::HbZoomSliderPopup(HbZoomSliderPopupPrivate &dd, QGraphicsItem *parent) :
       
   147     HbSliderPopup(dd, parent)
       
   148 {
       
   149     dd.init();    
       
   150 }
       
   151 
       
   152 /*!
       
   153     Destructs the slider.
       
   154 */
       
   155 HbZoomSliderPopup::~HbZoomSliderPopup()
       
   156 {
       
   157 }
       
   158 
       
   159 /*!
       
   160     @beta
       
   161     Returns the default Zoom Level of the zoom slider if set by application
       
   162     otherwise returns minimum value. 
       
   163 
       
   164     \sa setDefaultZoomLevel()
       
   165 
       
   166 */
       
   167 int HbZoomSliderPopup::defaultZoomLevel( ) const
       
   168 {
       
   169     Q_D( const HbZoomSliderPopup);
       
   170     if( d->slider ) {
       
   171         HbZoomSlider *zoomSlider= static_cast<HbZoomSlider *> (d->slider);
       
   172         return(zoomSlider->defaultZoomLevel());
       
   173     }
       
   174     return 0;
       
   175 }
       
   176 
       
   177 /*!
       
   178     @beta
       
   179     sets the default Zoom Level of the zoom slider with \a value.
       
   180     if not set minimum() value will be used for default value.
       
   181 
       
   182     \sa defaultZoomLevel()
       
   183 */
       
   184 void HbZoomSliderPopup::setDefaultZoomLevel(int value)
       
   185 {
       
   186     Q_D(HbZoomSliderPopup);
       
   187     if( d->slider ) {
       
   188         HbZoomSlider *zoomSlider= static_cast<HbZoomSlider *> (d->slider);
       
   189         zoomSlider->setDefaultZoomLevel(value);
       
   190     }
       
   191 }
       
   192 
       
   193 
       
   194 
       
   195 /*!
       
   196     Reimplemented from QGraphicsItem::keyReleaseEvent().
       
   197  */
       
   198 void HbZoomSliderPopup::keyReleaseEvent(QKeyEvent *keyevent)
       
   199 {
       
   200    switch (keyevent->key()) {
       
   201     case Qt::Key_Enter:
       
   202     case Qt::Key_Return:
       
   203     case Qt::Key_Select:
       
   204          {
       
   205          HbMessageBox *note = new HbMessageBox( 
       
   206                 tr("Zoom Adjusted"), HbMessageBox::MessageTypeInformation);
       
   207          note->show();
       
   208         }
       
   209          hide();
       
   210     break;
       
   211     case Qt::Key_Left:
       
   212     case Qt::Key_Backspace:
       
   213     case Qt::Key_Back:
       
   214          hide();
       
   215          keyevent->accept();
       
   216          break;
       
   217     default:
       
   218         HbSliderPopup::keyReleaseEvent(keyevent);
       
   219          break;
       
   220     }
       
   221 }
       
   222 
       
   223 /*!
       
   224     Reimplemented from QGraphicsItem::keyPressEvent().
       
   225  */
       
   226 void HbZoomSliderPopup::keyPressEvent(QKeyEvent *keyevent)
       
   227 {
       
   228    switch (keyevent->key()) {
       
   229     case Qt::Key_Left:
       
   230     case Qt::Key_Right:
       
   231     case Qt::Key_Back:
       
   232     case Qt::Key_Backspace:
       
   233          hide();
       
   234          keyevent->accept();
       
   235          break;
       
   236     default:
       
   237         HbSliderPopup::keyPressEvent(keyevent);
       
   238          break;
       
   239     }
       
   240 }
       
   241 
       
   242 
       
   243 #include "moc_hbzoomsliderpopup.cpp"