2008-04-19 15:31:50 +00:00
|
|
|
#ifndef MOZQWIDGET_H
|
|
|
|
#define MOZQWIDGET_H
|
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
2010-03-04 21:51:42 +00:00
|
|
|
#include "nsIWidget.h"
|
2010-04-02 14:08:30 +00:00
|
|
|
#include "prenv.h"
|
2010-03-04 21:51:42 +00:00
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
class QEvent;
|
2010-02-16 18:14:20 +00:00
|
|
|
class QPixmap;
|
|
|
|
class QWidget;
|
|
|
|
|
2008-04-19 15:37:51 +00:00
|
|
|
class nsWindow;
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
class MozQWidget : public QGraphicsWidget
|
2008-04-19 15:31:50 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2010-02-16 18:14:20 +00:00
|
|
|
MozQWidget(nsWindow* aReceiver, QGraphicsItem *aParent);
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2009-03-27 11:35:27 +00:00
|
|
|
~MozQWidget();
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
/**
|
|
|
|
* Mozilla helper.
|
|
|
|
*/
|
|
|
|
void setModal(bool);
|
2008-04-19 15:37:55 +00:00
|
|
|
bool SetCursor(nsCursor aCursor);
|
2008-04-20 08:16:40 +00:00
|
|
|
void dropReceiver() { mReceiver = 0x0; };
|
|
|
|
nsWindow* getReceiver() { return mReceiver; };
|
2008-04-19 15:31:50 +00:00
|
|
|
|
2010-02-25 18:58:19 +00:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery aQuery) const;
|
|
|
|
|
2010-03-12 22:07:32 +00:00
|
|
|
/**
|
|
|
|
* VirtualKeyboardIntegration
|
|
|
|
*/
|
|
|
|
void showVKB();
|
|
|
|
void hideVKB();
|
|
|
|
bool isVKBOpen();
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
protected:
|
2010-02-16 18:14:20 +00:00
|
|
|
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* aEvent);
|
|
|
|
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void dropEvent(QGraphicsSceneDragDropEvent* aEvent);
|
|
|
|
virtual void focusInEvent(QFocusEvent* aEvent);
|
|
|
|
virtual void focusOutEvent(QFocusEvent* aEvent);
|
|
|
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* aEvent);
|
|
|
|
virtual void keyPressEvent(QKeyEvent* aEvent);
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent* aEvent);
|
|
|
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* aEvent);
|
|
|
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* aEvent);
|
2010-03-12 22:06:17 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
virtual void wheelEvent(QGraphicsSceneWheelEvent* aEvent);
|
|
|
|
virtual void paint(QPainter* aPainter, const QStyleOptionGraphicsItem* aOption, QWidget* aWidget = 0);
|
|
|
|
virtual void resizeEvent(QGraphicsSceneResizeEvent* aEvent);
|
|
|
|
virtual void closeEvent(QCloseEvent* aEvent);
|
|
|
|
virtual void hideEvent(QHideEvent* aEvent);
|
|
|
|
virtual void showEvent(QShowEvent* aEvent);
|
2010-03-12 22:11:42 +00:00
|
|
|
virtual bool event(QEvent* aEvent);
|
2010-03-12 22:06:17 +00:00
|
|
|
|
2010-02-16 18:14:20 +00:00
|
|
|
bool SetCursor(const QPixmap& aPixmap, int, int);
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
private:
|
2008-04-19 15:37:51 +00:00
|
|
|
nsWindow *mReceiver;
|
2008-04-19 15:31:50 +00:00
|
|
|
};
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
class MozQGraphicsViewEvents
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
MozQGraphicsViewEvents(QGraphicsView* aView, MozQWidget* aTopLevel)
|
|
|
|
: mTopLevelWidget(aTopLevel)
|
|
|
|
, mView(aView)
|
|
|
|
{ }
|
2010-02-25 18:58:19 +00:00
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
void handleEvent(QEvent* aEvent)
|
2010-02-25 18:58:19 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-02-25 18:58:19 +00:00
|
|
|
if (aEvent->type() == QEvent::WindowActivate) {
|
|
|
|
if (mTopLevelWidget)
|
|
|
|
mTopLevelWidget->activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->type() == QEvent::WindowDeactivate) {
|
|
|
|
if (mTopLevelWidget)
|
|
|
|
mTopLevelWidget->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
void handleResizeEvent(QResizeEvent* aEvent)
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-02-16 18:14:20 +00:00
|
|
|
if (mTopLevelWidget) {
|
|
|
|
// transfer new size to graphics widget
|
2010-03-12 22:06:17 +00:00
|
|
|
mTopLevelWidget->setGeometry(0.0, 0.0,
|
2010-02-16 18:14:20 +00:00
|
|
|
static_cast<qreal>(aEvent->size().width()),
|
|
|
|
static_cast<qreal>(aEvent->size().height()));
|
2010-02-25 20:45:37 +00:00
|
|
|
// resize scene rect to vieport size,
|
|
|
|
// to avoid extra scrolling from QAbstractScrollable
|
2010-03-12 22:06:17 +00:00
|
|
|
if (mView)
|
|
|
|
mView->setSceneRect(mView->viewport()->rect());
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-12 22:06:17 +00:00
|
|
|
bool handleCloseEvent(QCloseEvent* aEvent)
|
2010-02-16 18:14:20 +00:00
|
|
|
{
|
2010-03-12 22:06:17 +00:00
|
|
|
if (!aEvent)
|
|
|
|
return false;
|
2010-02-16 18:14:20 +00:00
|
|
|
if (mTopLevelWidget) {
|
|
|
|
// close graphics widget instead, this view will be discarded
|
|
|
|
// automatically
|
|
|
|
QApplication::postEvent(mTopLevelWidget, new QCloseEvent(*aEvent));
|
|
|
|
aEvent->ignore();
|
2010-03-12 22:06:17 +00:00
|
|
|
return true;
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
2010-03-12 22:06:17 +00:00
|
|
|
|
|
|
|
return false;
|
2010-02-16 18:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQWidget* mTopLevelWidget;
|
2010-03-12 22:06:17 +00:00
|
|
|
QGraphicsView* mView;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a helper class to synchronize the QGraphicsView window with
|
|
|
|
its contained QGraphicsWidget for things like resizing and closing
|
|
|
|
by the user.
|
|
|
|
*/
|
|
|
|
class MozQGraphicsView : public QGraphicsView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MozQGraphicsView(MozQWidget* aTopLevel, QWidget * aParent = nsnull)
|
|
|
|
: QGraphicsView (new QGraphicsScene(), aParent)
|
|
|
|
, mEventHandler(this, aTopLevel)
|
2010-06-24 10:07:57 +00:00
|
|
|
, mTopLevelWidget(aTopLevel)
|
2010-03-12 22:06:17 +00:00
|
|
|
{
|
|
|
|
scene()->addItem(aTopLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual bool event(QEvent* aEvent)
|
|
|
|
{
|
|
|
|
mEventHandler.handleEvent(aEvent);
|
|
|
|
return QGraphicsView::event(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void resizeEvent(QResizeEvent* aEvent)
|
|
|
|
{
|
|
|
|
mEventHandler.handleResizeEvent(aEvent);
|
|
|
|
QGraphicsView::resizeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void closeEvent (QCloseEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mEventHandler.handleCloseEvent(aEvent))
|
|
|
|
QGraphicsView::closeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQGraphicsViewEvents mEventHandler;
|
2010-06-24 10:07:57 +00:00
|
|
|
MozQWidget* mTopLevelWidget;
|
2010-02-16 18:14:20 +00:00
|
|
|
};
|
|
|
|
|
2008-04-19 15:31:50 +00:00
|
|
|
#endif
|