src/hbcore/inputfw/hbinputfocusobject.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    35 
    35 
    36 #include "hbinputmethod.h"
    36 #include "hbinputmethod.h"
    37 #include "hbinputeditorinterface.h"
    37 #include "hbinputeditorinterface.h"
    38 #include "hbinputvkbhost.h"
    38 #include "hbinputvkbhost.h"
    39 #include "hbinputstandardfilters.h"
    39 #include "hbinputstandardfilters.h"
       
    40 #include "hbdeviceprofile.h"
    40 #include "hbinpututils.h"
    41 #include "hbinpututils.h"
    41 #include "hbnamespace_p.h"
    42 #include "hbnamespace_p.h"
       
    43 #include "hbmainwindow.h"
    42 #include "hbevent.h"
    44 #include "hbevent.h"
       
    45 #include "hbwidget.h"
       
    46 #include "hbinputmainwindow_p.h"
       
    47 
    43 /*!
    48 /*!
    44 @alpha
    49 @alpha
    45 @hbcore
    50 @hbcore
    46 \class HbInputFocusObject
    51 \class HbInputFocusObject
    47 \brief A helper class for accessing editor widget in abstract way.
    52 \brief A helper class for accessing editor widget in abstract way.
    73             textEdit->ensureCursorVisible();
    78             textEdit->ensureCursorVisible();
    74         }
    79         }
    75     }
    80     }
    76 }
    81 }
    77 
    82 
    78 
       
    79 class HbInputFocusObjectPrivate
    83 class HbInputFocusObjectPrivate
    80 {
    84 {
       
    85     Q_DECLARE_PUBLIC(HbInputFocusObject)
       
    86 
    81 public:
    87 public:
    82     HbInputFocusObjectPrivate(QObject *focusedObject)
    88     HbInputFocusObjectPrivate(QObject *focusedObject)
    83         : mFocusedObject(focusedObject),
    89         : mFocusedObject(focusedObject),
    84           mEditorInterface(focusedObject)
    90           mEditorInterface(focusedObject)
    85     {}
    91     {}
    86 
    92 
       
    93     HbMainWindow *mainWindow() const;    
       
    94 
    87 public:
    95 public:
       
    96     HbInputFocusObject *q_ptr;
    88     QPointer<QObject> mFocusedObject;
    97     QPointer<QObject> mFocusedObject;
    89     HbEditorInterface mEditorInterface;
    98     HbEditorInterface mEditorInterface;
    90     QString mPreEditString;
    99     QString mPreEditString;
    91 };
   100 };
    92 
   101 
       
   102 HbMainWindow *HbInputFocusObjectPrivate::mainWindow() const
       
   103 {
       
   104     QWidget *qWidgetObject = qobject_cast<QWidget *>(mFocusedObject);
       
   105     QGraphicsObject *graphicsObject = 0;
       
   106 
       
   107     // check for graphics view related widgets.
       
   108     if (qWidgetObject) {
       
   109         if (qWidgetObject->graphicsProxyWidget()) {
       
   110             graphicsObject = qWidgetObject->graphicsProxyWidget();
       
   111         } else {
       
   112             return HbInputMainWindow::instance();
       
   113         }
       
   114     } else {
       
   115         graphicsObject = qobject_cast<QGraphicsObject *>(mFocusedObject);
       
   116     }
       
   117 
       
   118     if (graphicsObject) {
       
   119         if (graphicsObject->scene()) {
       
   120             QList<QGraphicsView*> views = graphicsObject->scene()->views();
       
   121             foreach (QGraphicsView *view, views) {
       
   122                 HbMainWindow *mainWindow = qobject_cast<HbMainWindow*>(view);
       
   123                 if (mainWindow) {
       
   124                     return mainWindow;
       
   125                 }
       
   126             }
       
   127             // not a HbMainWindow.
       
   128             return HbInputMainWindow::instance();
       
   129         }
       
   130     }
       
   131 
       
   132     return 0;
       
   133 }
    93 
   134 
    94 /// @endcond
   135 /// @endcond
    95 
   136 
    96 HbInputFocusObject::HbInputFocusObject(QObject *focusedObject)
   137 HbInputFocusObject::HbInputFocusObject(QObject *focusedObject)
    97     : d_ptr(new HbInputFocusObjectPrivate(focusedObject))
   138     : d_ptr(new HbInputFocusObjectPrivate(focusedObject))
    98 {
   139 {
       
   140     Q_D(HbInputFocusObject);
       
   141     d->q_ptr = this;
       
   142 
    99     if (focusedObject) {
   143     if (focusedObject) {
   100         HbEvent *event = new HbEvent(HbEvent::InputMethodFocusIn);
   144         HbEvent *event = new HbEvent(HbEvent::InputMethodFocusIn);
   101         QCoreApplication::sendEvent(focusedObject, event);
   145         QCoreApplication::sendEvent(focusedObject, event);
   102         delete event;
   146         delete event;
   103     }
   147 
   104 }
   148         HbMainWindow *mainWindow = d->mainWindow();
   105 
   149         if (mainWindow) {
       
   150             connect(mainWindow, SIGNAL(aboutToChangeOrientation()), this, SIGNAL(aboutToChangeOrientation()));
       
   151             connect(mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SIGNAL(orientationChanged()));
       
   152         }
       
   153     }
       
   154 }
   106 
   155 
   107 HbInputFocusObject::~HbInputFocusObject()
   156 HbInputFocusObject::~HbInputFocusObject()
   108 {
   157 {
   109     Q_D(HbInputFocusObject);
   158     Q_D(HbInputFocusObject);
   110 
   159 
   173                 QApplication::sendEvent(ic->focusWidget(), &event);
   222                 QApplication::sendEvent(ic->focusWidget(), &event);
   174             }
   223             }
   175         }
   224         }
   176     }
   225     }
   177 }
   226 }
   178 
       
   179 
   227 
   180 /*!
   228 /*!
   181 Posts given event to focused editor in an asynchronous manner.
   229 Posts given event to focused editor in an asynchronous manner.
   182 */
   230 */
   183 void HbInputFocusObject::postEvent(QEvent &event)
   231 void HbInputFocusObject::postEvent(QEvent &event)
   701             widget->setFocus();
   749             widget->setFocus();
   702         }
   750         }
   703     }
   751     }
   704 }
   752 }
   705 
   753 
       
   754 /*!
       
   755 Returns the screen orientation in editor widget's context. For widgets
       
   756 living in HbMainWindow, it is main window's orientation. For everything
       
   757 else, it is device profile's screen orientation.
       
   758 */
       
   759 Qt::Orientation HbInputFocusObject::orientation() const
       
   760 {
       
   761     Q_D(const HbInputFocusObject);
       
   762 
       
   763     HbMainWindow *mainWindow = d->mainWindow();
       
   764     if (mainWindow) {
       
   765         return mainWindow->orientation();
       
   766     }
       
   767 
       
   768     return HbDeviceProfile::current().orientation();
       
   769 }
       
   770 
       
   771 #include "moc_hbinputfocusobject.cpp"
       
   772 
   706 // End of file
   773 // End of file
   707