2008-04-19 08:31:50 -07:00
|
|
|
#ifndef MOZQWIDGET_H
|
|
|
|
#define MOZQWIDGET_H
|
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QGraphicsView>
|
|
|
|
#include <QtGui/QGraphicsWidget>
|
|
|
|
|
2010-03-04 13:51:42 -08:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
class QEvent;
|
2010-02-16 10:14:20 -08:00
|
|
|
class QPixmap;
|
|
|
|
class QWidget;
|
|
|
|
|
2008-04-19 08:37:51 -07:00
|
|
|
class nsWindow;
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
class MozQWidget : public QGraphicsWidget
|
2008-04-19 08:31:50 -07:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2010-02-16 10:14:20 -08:00
|
|
|
MozQWidget(nsWindow* aReceiver, QGraphicsItem *aParent);
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2009-03-27 04:35:27 -07:00
|
|
|
~MozQWidget();
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
/**
|
|
|
|
* Mozilla helper.
|
|
|
|
*/
|
|
|
|
void setModal(bool);
|
2008-04-19 08:37:55 -07:00
|
|
|
bool SetCursor(nsCursor aCursor);
|
2008-04-20 01:16:40 -07:00
|
|
|
void dropReceiver() { mReceiver = 0x0; };
|
|
|
|
nsWindow* getReceiver() { return mReceiver; };
|
2008-04-19 08:31:50 -07:00
|
|
|
|
2010-02-25 10:58:19 -08:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery aQuery) const;
|
|
|
|
|
2010-03-12 14:07:32 -08:00
|
|
|
/**
|
|
|
|
* VirtualKeyboardIntegration
|
|
|
|
*/
|
|
|
|
void showVKB();
|
|
|
|
void hideVKB();
|
|
|
|
bool isVKBOpen();
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
protected:
|
2010-02-16 10:14:20 -08: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 14:06:17 -08:00
|
|
|
|
2010-02-16 10:14:20 -08: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 14:06:17 -08:00
|
|
|
|
2010-02-16 10:14:20 -08:00
|
|
|
bool SetCursor(const QPixmap& aPixmap, int, int);
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
private:
|
2008-04-19 08:37:51 -07:00
|
|
|
nsWindow *mReceiver;
|
2008-04-19 08:31:50 -07:00
|
|
|
};
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
class MozQGraphicsViewEvents
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
MozQGraphicsViewEvents(QGraphicsView* aView, MozQWidget* aTopLevel)
|
|
|
|
: mTopLevelWidget(aTopLevel)
|
|
|
|
, mView(aView)
|
|
|
|
{ }
|
2010-02-25 10:58:19 -08:00
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
void handleEvent(QEvent* aEvent)
|
2010-02-25 10:58:19 -08:00
|
|
|
{
|
2010-03-12 14:06:17 -08:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-02-25 10:58:19 -08:00
|
|
|
if (aEvent->type() == QEvent::WindowActivate) {
|
|
|
|
if (mTopLevelWidget)
|
|
|
|
mTopLevelWidget->activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->type() == QEvent::WindowDeactivate) {
|
|
|
|
if (mTopLevelWidget)
|
|
|
|
mTopLevelWidget->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
void handleResizeEvent(QResizeEvent* aEvent)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2010-03-12 14:06:17 -08:00
|
|
|
if (!aEvent)
|
|
|
|
return;
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mTopLevelWidget) {
|
|
|
|
// transfer new size to graphics widget
|
2010-03-12 14:06:17 -08:00
|
|
|
mTopLevelWidget->setGeometry(0.0, 0.0,
|
2010-02-16 10:14:20 -08:00
|
|
|
static_cast<qreal>(aEvent->size().width()),
|
|
|
|
static_cast<qreal>(aEvent->size().height()));
|
2010-02-25 12:45:37 -08:00
|
|
|
// resize scene rect to vieport size,
|
|
|
|
// to avoid extra scrolling from QAbstractScrollable
|
2010-03-12 14:06:17 -08:00
|
|
|
if (mView)
|
|
|
|
mView->setSceneRect(mView->viewport()->rect());
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-12 14:06:17 -08:00
|
|
|
bool handleCloseEvent(QCloseEvent* aEvent)
|
2010-02-16 10:14:20 -08:00
|
|
|
{
|
2010-03-12 14:06:17 -08:00
|
|
|
if (!aEvent)
|
|
|
|
return false;
|
2010-02-16 10:14:20 -08:00
|
|
|
if (mTopLevelWidget) {
|
|
|
|
// close graphics widget instead, this view will be discarded
|
|
|
|
// automatically
|
|
|
|
QApplication::postEvent(mTopLevelWidget, new QCloseEvent(*aEvent));
|
|
|
|
aEvent->ignore();
|
2010-03-12 14:06:17 -08:00
|
|
|
return true;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
2010-03-12 14:06:17 -08:00
|
|
|
|
|
|
|
return false;
|
2010-02-16 10:14:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MozQWidget* mTopLevelWidget;
|
2010-03-12 14:06:17 -08: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)
|
|
|
|
{
|
|
|
|
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-02-16 10:14:20 -08:00
|
|
|
};
|
|
|
|
|
2008-04-19 08:31:50 -07:00
|
|
|
#endif
|