Skip to content

Commit 7eb7cfd

Browse files
committed
Bug 586722 - Incubator qt embedding should switch to QGraphicsWidgets. r=romaxa
1 parent 2588d2a commit 7eb7cfd

File tree

4 files changed

+107
-89
lines changed

4 files changed

+107
-89
lines changed

qt/QMozView.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ void QMozViewListener::OnConsoleMessage(const char * message)
123123
emit pQMozView->consoleMessage(qt_message);
124124
}
125125

126-
QMozView::QMozView(QWidget *parent, unsigned int flags) :
127-
QWidget(parent),
126+
QMozView::QMozView(QGraphicsWidget *parent, unsigned int flags) :
127+
QGraphicsWidget(parent),
128128
mPrivate(new Private(this))
129129
{
130130
#if defined Q_OS_WIN
@@ -140,7 +140,7 @@ QMozView::~QMozView()
140140
delete mPrivate;
141141
}
142142

143-
void QMozView::resizeEvent(QResizeEvent* event)
143+
void QMozView::resizeEvent(QGraphicsSceneResizeEvent* event)
144144
{
145145
Q_UNUSED(event);
146146
mPrivate->mozView.SetPositionAndSize(0, 0, size().width(), size().height());

qt/QMozView.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@
4444
#include "QMozEmbedExport.h"
4545

4646
#include <QtGui/QWidget>
47+
#include <QtGui/QGraphicsWidget>
4748

4849
class QMozViewListener;
4950
class nsIInterfaceRequestor;
5051

51-
class Q_MOZEMBED_EXPORT QMozView : public QWidget
52+
class Q_MOZEMBED_EXPORT QMozView : public QGraphicsWidget
5253
{
5354
Q_OBJECT
5455

5556
public:
56-
explicit QMozView(QWidget *parent = 0, unsigned int flags = 0);
57+
explicit QMozView(QGraphicsWidget *parent = 0, unsigned int flags = 0);
5758
virtual ~QMozView();
5859

5960
void loadUri(const QString& uri);
@@ -75,7 +76,7 @@ class Q_MOZEMBED_EXPORT QMozView : public QWidget
7576
void exitModal();
7677

7778
protected:
78-
virtual void resizeEvent(QResizeEvent*);
79+
virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
7980

8081
virtual QMozView* openWindow(unsigned int flags);
8182

qt/test/test.cpp

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* Contributor(s):
2222
* Anton Rogaynis <[email protected]>
23+
* Tatiana Meshkova <[email protected]>
2324
*
2425
* Alternatively, the contents of this file may be used under the terms of
2526
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -36,90 +37,75 @@
3637
* ***** END LICENSE BLOCK ***** */
3738

3839
#include <QApplication>
39-
#include <QWidget>
40-
#include <QVBoxLayout>
41-
#include <QLineEdit>
42-
#include <QLabel>
43-
#include <QUrl>
4440
#include <QDebug>
41+
#include <QPushButton>
42+
#include <QGraphicsProxyWidget>
4543

4644
#include "test.h"
47-
#include "QMozApp.h"
4845

49-
MyQMozView::MyQMozView(QWidget *parent, unsigned int flags)
50-
: QMozView(parent, flags)
51-
{}
52-
53-
QMozView* MyQMozView::openWindow(unsigned int flags)
46+
MyQGraphicsView::MyQGraphicsView(QGraphicsScene* scene, QWidget* parent)
47+
: QGraphicsView(scene, parent)
5448
{
55-
MyBrowser* newBrowser = new MyBrowser(0, flags);
56-
newBrowser->resize(400, 400);
57-
newBrowser->show();
58-
newBrowser->setAttribute(Qt::WA_DeleteOnClose);
59-
return newBrowser->getQMozView();
60-
}
49+
setAlignment(Qt::AlignLeft | Qt::AlignTop);
50+
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
51+
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
6152

62-
MyBrowser::MyBrowser(QWidget *parent, unsigned int flags)
63-
: QDialog(parent)
64-
{
65-
QVBoxLayout* layout = new QVBoxLayout(this);
53+
mLayout = new QGraphicsGridLayout;
6654

67-
location = new QLineEdit(this);
68-
layout->addWidget(location);
55+
mTitle = new MyTextWidget("title");
56+
mLayout->addItem(mTitle, 0, 0, 1, 2);
57+
mLayout->setRowMaximumHeight(0, 20);
6958

70-
mozView = new MyQMozView(this, flags);
71-
layout->addWidget(mozView, 1);
59+
mLocation = new MyTextWidget("location");
60+
mLayout->addItem(mLocation, 1, 0, 1, 2);
61+
mLayout->setRowMaximumHeight(1, 20);
7262

73-
status = new QLabel(this);
74-
layout->addWidget(status);
63+
mForm = new QGraphicsWidget;
64+
mForm->setLayout(mLayout);
65+
scene->addItem(mForm);
7566

76-
connect(mozView, SIGNAL(locationChanged(const QString&)),
77-
location, SLOT(setText(const QString&)));
67+
mozView = new QMozView(mForm);
68+
mLayout->addItem(mozView, 2, 0, 1, 2);
7869

79-
connect(mozView, SIGNAL(titleChanged(const QString&)),
80-
this, SLOT(setWindowTitle(const QString&)));
70+
mStatus = new MyTextWidget("status");
71+
mLayout->addItem(mStatus, 3, 0);
72+
mLayout->setRowMaximumHeight(3, 20);
8173

82-
connect(mozView, SIGNAL(statusChanged(const QString&)),
83-
status, SLOT(setText(const QString&)));
74+
QWidget* exitButton = new QPushButton("Exit");
75+
mLayout->addItem(scene->addWidget(exitButton), 3, 1);
76+
mLayout->setColumnMaximumWidth(1, 50);
8477

85-
connect(mozView, SIGNAL(startModal()),
86-
this, SLOT(startModal()));
78+
connect(mozView, SIGNAL(locationChanged(const QString&)),
79+
mLocation, SLOT(setText(const QString&)));
8780

88-
connect(mozView, SIGNAL(exitModal()),
89-
this, SLOT(exitModal()));
81+
connect(mozView, SIGNAL(titleChanged(const QString&)),
82+
mTitle, SLOT(setText(const QString&)));
9083

91-
connect(location, SIGNAL(returnPressed()),
92-
this, SLOT(go()));
84+
connect(mozView, SIGNAL(statusChanged(const QString&)),
85+
mStatus, SLOT(setText(const QString&)));
9386

94-
connect(mozView, SIGNAL(consoleMessage(const QString &)),
95-
this, SLOT(consoleMessage(const QString &)));
96-
}
87+
connect(mozView, SIGNAL(consoleMessage(const QString&)),
88+
this, SLOT(consoleMessage(const QString&)));
9789

98-
void MyBrowser::loadUri(const QString& uri)
99-
{
100-
location->setText(uri);
101-
mozView->loadUri(uri);
90+
connect(exitButton, SIGNAL(clicked()), this, SLOT(close()));
10291
}
10392

104-
void MyBrowser::go()
93+
MyQGraphicsView::~MyQGraphicsView()
10594
{
106-
mozView->loadUri(location->text());
10795
}
10896

109-
void MyBrowser::startModal()
97+
void MyQGraphicsView::resizeEvent(QResizeEvent* event)
11098
{
111-
hide();
112-
exec();
99+
mForm->resize(event->size());
100+
QGraphicsView::resizeEvent(event);
113101
}
114102

115-
void MyBrowser::exitModal()
103+
void MyQGraphicsView::loadUri(const QString& uri)
116104
{
117-
done(0);
118-
// have to delete mozView now to avoid JS context assertions
119-
delete mozView;
105+
mozView->loadUri(uri);
120106
}
121107

122-
void MyBrowser::consoleMessage(const QString& message)
108+
void MyQGraphicsView::consoleMessage(const QString& message)
123109
{
124110
qDebug() << "CONSOLE:" << message;
125111
}
@@ -128,15 +114,14 @@ int main(int argc, char *argv[])
128114
{
129115
QApplication app(argc, argv);
130116

131-
MyBrowser window;
132-
133-
window.resize(400, 400);
134-
window.show();
135-
117+
QGraphicsScene scene;
118+
MyQGraphicsView view(&scene);
136119
if(argc > 1)
137-
window.loadUri(argv[argc - 1]);
120+
view.loadUri(argv[argc - 1]);
138121
else
139-
window.loadUri("http://mozilla.org");
122+
view.loadUri("http://mozilla.org");
123+
124+
view.showFullScreen();
140125

141126
return app.exec();
142127
}

qt/test/test.h

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* Contributor(s):
2222
* Anton Rogaynis <[email protected]>
23+
* Tatiana Meshkova <[email protected]>
2324
*
2425
* Alternatively, the contents of this file may be used under the terms of
2526
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -38,38 +39,69 @@
3839
#ifndef __test_h_
3940
#define __test_h_
4041

41-
#include <QDialog>
42-
#include "QMozView.h"
42+
#include <QGraphicsView>
43+
#include <QGraphicsWidget>
44+
#include <QGraphicsGridLayout>
4345

44-
class QUrl;
45-
class QLineEdit;
46-
class QLabel;
46+
#include "QMozView.h"
47+
#include "QMozApp.h"
4748

48-
class MyQMozView : public QMozView
49+
class MyTextWidget : public QGraphicsWidget
4950
{
51+
Q_OBJECT
52+
5053
public:
51-
MyQMozView(QWidget *parent = 0, unsigned int flags = 0);
54+
MyTextWidget(const QString& aText, QGraphicsItem* parent = 0)
55+
: QGraphicsWidget(parent)
56+
, text(aText)
57+
{
58+
}
59+
5260
protected:
53-
QMozView* openWindow(unsigned int flags);
61+
void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
62+
{
63+
if (text.isEmpty())
64+
return;
65+
66+
painter->drawText(boundingRect(), text);
67+
}
68+
69+
private slots:
70+
void setText(const QString& aText)
71+
{
72+
text = aText;
73+
update();
74+
}
75+
76+
private:
77+
QString text;
78+
5479
};
5580

56-
class MyBrowser : public QDialog
81+
class MyQGraphicsView : public QGraphicsView
5782
{
58-
Q_OBJECT
83+
Q_OBJECT
84+
5985
public:
60-
MyBrowser(QWidget *parent = 0, unsigned int flags = 0);
61-
QMozView* getQMozView() {return mozView;}
86+
MyQGraphicsView(QGraphicsScene* scene, QWidget* parent = 0);
87+
~MyQGraphicsView();
88+
6289
void loadUri(const QString& uri);
63-
public slots:
64-
void go();
65-
void startModal();
66-
void exitModal();
67-
void consoleMessage(const QString &);
90+
91+
protected:
92+
void resizeEvent(QResizeEvent* event);
93+
94+
private slots:
95+
void consoleMessage(const QString& message);
6896

6997
private:
70-
QLineEdit* location;
71-
MyQMozView* mozView;
72-
QLabel* status;
98+
QGraphicsWidget* mForm;
99+
QGraphicsGridLayout* mLayout;
100+
QMozView* mozView;
101+
102+
MyTextWidget* mTitle;
103+
MyTextWidget* mLocation;
104+
MyTextWidget* mStatus;
73105
};
74106

75107
#endif /* __test_h_ */

0 commit comments

Comments
 (0)