Commit 8d8f41a0 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin

popupwidget: memory optimization for qmlPopUpWidget and popUpWidget

Change-Id: Ie0bd666eb5e05ccc21bd1cbcfa59952b8d0a2989
parent ae95e721
......@@ -50,9 +50,10 @@ void
AboutDialog::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
auto cp = getContainer()->parentWidget();
if (auto mainWindow = qobject_cast<MainWindow*>(cp)) {
mainWindow->darken();
if (auto cp = getContainer().toStrongRef()) {
if (auto mainWindow = qobject_cast<MainWindow*>(cp->parentWidget())) {
mainWindow->darken();
}
}
}
......@@ -60,9 +61,10 @@ void
AboutDialog::hideEvent(QHideEvent* event)
{
QWidget::hideEvent(event);
auto cp = getContainer()->parentWidget();
if (auto mainWindow = qobject_cast<MainWindow*>(cp)) {
mainWindow->lighten();
if (auto cp = getContainer().toStrongRef()) {
if (auto mainWindow = qobject_cast<MainWindow*>(cp->parentWidget())) {
mainWindow->lighten();
}
}
}
......@@ -77,7 +79,9 @@ AboutDialog::on_changelogButton_clicked()
void
AboutDialog::on_closeAboutDialogButton_clicked()
{
getContainer()->accept();
if (auto cp = getContainer().toStrongRef()) {
cp->accept();
}
}
void
......
......@@ -227,8 +227,8 @@ CallWidget::CallWidget(QWidget* parent) :
connect(ui->changelogButton, &QAbstractButton::clicked,
[this] {
auto aboutDialog = std::make_unique<AboutDialog>(&MainWindow::instance());
aboutDialog->getContainer()->exec();
AboutDialog aboutDialog (&MainWindow::instance());
aboutDialog.getContainer().toStrongRef()->exec();
});
// set first view to welcome view
......@@ -422,7 +422,7 @@ CallWidget::setupSmartListContextMenu(const QPoint& pos)
connect(profileShowingAction, &QAction::triggered,
[conversation, this]() {
UserProfile userProfile(conversation, qobject_cast<MainWindow*>(this->parent()->parent()->parent()));
userProfile.getContainer()->exec();
userProfile.getContainer().toStrongRef()->exec();
});
}
smartListModel_->isContextMenuOpen = true;
......@@ -1599,13 +1599,13 @@ CallWidget::registerShortCuts()
connect(shortcutsTableSC, &QShortcut::activated,
[this] {
QUrl qmlSource{ QStringLiteral("qrc:/src/KeyBoardShortcutTable.qml") };
QmlPopupWidget* qmlKeyboardShortcuts = new QmlPopupWidget(qmlSource, qobject_cast<MainWindow*>(parent()->parent()->parent()));
qmlKeyboardShortcuts->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
qmlKeyboardShortcuts->setAttribute(Qt::WA_AlwaysStackOnTop);
qmlKeyboardShortcuts->setClearColor(Qt::transparent);
qmlKeyboardShortcuts->setMinimumWidth(qmlKeyboardShortcuts->rootObject()->property("minWidth").toInt());
qmlKeyboardShortcuts->setMinimumHeight(qmlKeyboardShortcuts->rootObject()->property("minHeight").toInt());
qmlKeyboardShortcuts->getContainer()->exec();
QmlPopupWidget qmlKeyboardShortcuts(qmlSource, qobject_cast<MainWindow*>(parent()->parent()->parent()));
qmlKeyboardShortcuts.setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
qmlKeyboardShortcuts.setAttribute(Qt::WA_AlwaysStackOnTop);
qmlKeyboardShortcuts.setClearColor(Qt::transparent);
qmlKeyboardShortcuts.setMinimumWidth(qmlKeyboardShortcuts.rootObject()->property("minWidth").toInt());
qmlKeyboardShortcuts.setMinimumHeight(qmlKeyboardShortcuts.rootObject()->property("minHeight").toInt());
qmlKeyboardShortcuts.getContainer().toStrongRef()->exec();
});
connect(navigateToMediaSettingsSC, &QShortcut::activated,
......
......@@ -242,7 +242,7 @@ bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, long* r
if (msg->wParam == IDM_ABOUTBOX) {
*result = 0;
AboutDialog aboutDialog(this);
aboutDialog.getContainer()->exec();
aboutDialog.getContainer().toStrongRef()->exec();
return true;
}
if (msg->wParam == IDM_SHORTCUTSBOX) {
......@@ -445,13 +445,13 @@ void MainWindow::slotAccountListChanged()
void
MainWindow::generateQmlDialog(const QUrl& qmlSource)
{
QScopedPointer<QmlPopupWidget> qmlKeyboardShortcuts (new QmlPopupWidget(qmlSource, this));
QmlPopupWidget qmlKeyboardShortcuts(qmlSource, this);
qmlKeyboardShortcuts->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
qmlKeyboardShortcuts->setAttribute(Qt::WA_AlwaysStackOnTop);
qmlKeyboardShortcuts->setClearColor(Qt::transparent);
qmlKeyboardShortcuts->setMinimumWidth(qmlKeyboardShortcuts->rootObject()->property("minWidth").toInt());
qmlKeyboardShortcuts->setMinimumHeight(qmlKeyboardShortcuts->rootObject()->property("minHeight").toInt());
qmlKeyboardShortcuts.setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
qmlKeyboardShortcuts.setAttribute(Qt::WA_AlwaysStackOnTop);
qmlKeyboardShortcuts.setClearColor(Qt::transparent);
qmlKeyboardShortcuts.setMinimumWidth(qmlKeyboardShortcuts.rootObject()->property("minWidth").toInt());
qmlKeyboardShortcuts.setMinimumHeight(qmlKeyboardShortcuts.rootObject()->property("minHeight").toInt());
qmlKeyboardShortcuts->getContainer()->exec();
qmlKeyboardShortcuts.getContainer().toStrongRef()->exec();
}
\ No newline at end of file
......@@ -129,9 +129,6 @@ MessageWebView::MessageWebView(QWidget *parent)
fullScreenWebWidget_.reset();
}
});
recordWidget_ = new RecordWidget(this);
recordWidget_->getContainer()->hide();
}
MessageWebView::~MessageWebView()
......@@ -280,10 +277,13 @@ MessageWebView::openAudioRecorder(int spikePosX, int spikePosY)
}
// spikePosX, spikePosY are positions relative to Document
auto pointOfAudioButton = mapToGlobal(QPoint(spikePosX, spikePosY));
recordWidget_->getContainer()->move(
pointOfAudioButton.x() - recordWidget_->width() / 2,
pointOfAudioButton.y() - recordWidget_->height() - recordWidgetMargin_);
recordWidget_->openRecorder(true);
RecordWidget recordWidget(this);
if (auto container = recordWidget.getContainer().toStrongRef()) {
container->move(pointOfAudioButton.x() - recordWidget.width() / 2,
pointOfAudioButton.y() - recordWidget.height() - recordWidgetMargin_);
}
recordWidget.openRecorder(true);
}
void
......@@ -296,10 +296,13 @@ MessageWebView::openVideoRecorder(int spikePosX, int spikePosY)
}
// spikePosX, spikePosY are positions relative to Document
auto pointOfVideoButton = mapToGlobal(QPoint(spikePosX, spikePosY));
recordWidget_->getContainer()->move(
pointOfVideoButton.x() - recordWidget_->width() / 2,
pointOfVideoButton.y() - recordWidget_->height() - recordWidgetMargin_);
recordWidget_->openRecorder(false);
RecordWidget recordWidget(this);
if (auto container = recordWidget.getContainer().toStrongRef()) {
container->move(pointOfVideoButton.x() - recordWidget.width() / 2,
pointOfVideoButton.y() - recordWidget.height() - recordWidgetMargin_);
}
recordWidget.openRecorder(false);
}
void
......
......@@ -136,7 +136,6 @@ private:
PrivateBridging* jsBridge_;
QLabel* dragDroplabel_;
bool textSelected_;
RecordWidget* recordWidget_;
/*TODO: Generatic Popup Dialog setGeometry function corrsponding to spike alignment*/
const quint16 recordWidgetMargin_{ 15 };
......
......@@ -26,18 +26,21 @@
PreviewWidget::PreviewWidget(QWidget * parent)
: VideoWidgetBase(Qt::transparent, parent)
{
connect(LRCInstance::renderer(), &RenderManager::previewFrameUpdated,
previewFrameUpdatedConnection_ = connect(LRCInstance::renderer(), &RenderManager::previewFrameUpdated,
[this]() {
repaint();
});
connect(LRCInstance::renderer(), &RenderManager::previewRenderingStopped,
previewRenderingStopped_ = connect(LRCInstance::renderer(), &RenderManager::previewRenderingStopped,
[this]() {
repaint();
});
}
PreviewWidget::~PreviewWidget()
{}
{
disconnect(previewFrameUpdatedConnection_);
disconnect(previewRenderingStopped_);
}
void
PreviewWidget::paintBackground(QPainter* painter)
......
......@@ -37,6 +37,10 @@ protected:
virtual void paintEvent(QPaintEvent* e) override;
virtual void paintBackground(QPainter* painter) override;
private:
QMetaObject::Connection previewFrameUpdatedConnection_;
QMetaObject::Connection previewRenderingStopped_;
};
// A rounded image for photobooths
......
......@@ -207,7 +207,9 @@ RecordOverlay::on_recordOverlaySendBtn_pressed()
if(recordWidget_->sendRecording()) {
setRecorderState(RecorderState::aboutToRecord);
// define what to do when the record is sent out
recordWidget_->getContainer()->accept();
if (auto container = recordWidget_->getContainer().toStrongRef()) {
container->accept();
}
}
}
......
......@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "recordwidget.h"
#include "ui_recordwidget.h"
......@@ -30,13 +31,19 @@ RecordWidget::RecordWidget(QWidget *parent) :
ui(new Ui::RecordWidget)
{
ui->setupUi(this);
recordOverlay_ = new RecordOverlay(this);
previewWidget_ = new VideoRecordPreviewWidget(this);
recordOverlay_ = QSharedPointer<RecordOverlay>(new RecordOverlay(this));
previewWidget_ = QSharedPointer<VideoRecordPreviewWidget>(new VideoRecordPreviewWidget(this));
recordOverlay_->setDrawRoundedCorner(true);
}
RecordWidget::~RecordWidget()
{}
{
LRCInstance::avModel().stopLocalRecorder(recordedFilePath_.toStdString());
Utils::forceDeleteAsync(recordedFilePath_);
if (!isAudio_) {
LRCInstance::avModel().stopPreview();
}
}
bool
RecordWidget::startRecording()
......@@ -118,7 +125,7 @@ RecordWidget::openRecorder(bool isAudio)
if(!isAudio_) {
LRCInstance::avModel().startPreview();
}
widgetContainer_->show();
widgetContainer_->exec();
}
bool
......@@ -133,18 +140,5 @@ void RecordWidget::resizeEvent(QResizeEvent* event)
recordOverlay_->resize(this->size());
previewWidget_->resize(this->size());
previewWidget_->stackUnder(recordOverlay_);
}
void
RecordWidget::hideEvent(QHideEvent* event)
{
Q_UNUSED(event);
LRCInstance::avModel().stopLocalRecorder(recordedFilePath_.toStdString());
Utils::forceDeleteAsync(recordedFilePath_);
if(!isAudio_) {
LRCInstance::avModel().stopPreview();
previewWidget_->toPaintingBackground(true);
previewWidget_->toDrawLastFrame(false);
}
previewWidget_->stackUnder(recordOverlay_.data());
}
......@@ -48,13 +48,12 @@ public:
protected:
void resizeEvent(QResizeEvent* event) override;
void hideEvent(QHideEvent* event) override;
private:
Ui::RecordWidget* ui;
VideoRecordPreviewWidget* previewWidget_;
RecordOverlay* recordOverlay_;
QSharedPointer<VideoRecordPreviewWidget> previewWidget_;
QSharedPointer<RecordOverlay> recordOverlay_;
bool isAudio_ = true;
QString recordedFilePath_;
......
This diff is collapsed.
......@@ -19,6 +19,7 @@
#pragma once
#include "widgethelpers.h"
#include "smartlistmodel.h"
#include "api/conversationmodel.h"
......@@ -30,6 +31,7 @@
class ContactPicker;
class SIPInputPanelWidget;
class OverlayButton;
namespace Ui {
class VideoOverlay;
......@@ -56,6 +58,9 @@ signals:
void holdStateChanged(bool state);
void videoMuteStateChanged(bool state);
private:
void contactPickerPopup(SmartListModel::Type type, OverlayButton* locateButton);
private slots:
void setTime();
void on_hangupButton_clicked();
......@@ -79,9 +84,9 @@ private:
std::string accountId_;
std::string convUid_;
ContactPicker* contactPicker_;
SIPInputPanelWidget* sipInputPanel_;
QTimer* oneSecondTimer_;
QString currentBestCalleeDisplayName_ { "" };
bool popUpShown_ { false };
quint16 popupMargin_{ 16 };
};
......@@ -203,9 +203,10 @@ void
QmlPopupWidget::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
auto cp = getContainer()->parentWidget();
if (auto mainWindow = qobject_cast<MainWindow*>(cp)) {
mainWindow->darken();
if (auto cp = getContainer().toStrongRef()) {
if (auto mainWindow = qobject_cast<MainWindow*>(cp->parentWidget())) {
mainWindow->darken();
}
}
}
......@@ -213,8 +214,9 @@ void
QmlPopupWidget::hideEvent(QHideEvent* event)
{
QWidget::hideEvent(event);
auto cp = getContainer()->parentWidget();
if (auto mainWindow = qobject_cast<MainWindow*>(cp)) {
mainWindow->lighten();
if (auto cp = getContainer().toStrongRef()) {
if (auto mainWindow = qobject_cast<MainWindow*>(cp->parentWidget())) {
mainWindow->lighten();
}
}
}
\ No newline at end of file
......@@ -136,16 +136,16 @@ public:
QColor spikeColor = Qt::white,
PopupDialog::SpikeLabelAlignment spikeAlignment = PopupDialog::SpikeLabelAlignment::AlignLeft)
: QWidget(parent) {
widgetContainer_ = new PopupDialog(parent, spikeColor, spikeAlignment);
setParent(widgetContainer_);
widgetContainer_ = QSharedPointer<PopupDialog>(new PopupDialog(parent, spikeColor, spikeAlignment));
setParent(widgetContainer_.data());
widgetContainer_->insertWidget(this);
}
virtual ~PopupWidget() {}
virtual ~PopupWidget() { setParent(nullptr); }
PopupDialog *getContainer() { return widgetContainer_; }
QWeakPointer<PopupDialog> getContainer() { return widgetContainer_.toWeakRef(); }
protected:
PopupDialog *widgetContainer_;
QSharedPointer<PopupDialog> widgetContainer_;
};
......@@ -160,20 +160,20 @@ public:
PopupDialog::SpikeLabelAlignment spikeAlignment = PopupDialog::SpikeLabelAlignment::None)
: QQuickWidget(source, parent) {
widgetContainer_ = new PopupDialog(parent, spikeColor, spikeAlignment);
widgetContainer_ = QSharedPointer<PopupDialog>(new PopupDialog(parent, spikeColor, spikeAlignment));
setMouseTracking(true);
setParent(widgetContainer_);
setParent(widgetContainer_.data());
widgetContainer_->insertWidget(this);
}
virtual ~QmlPopupWidget() {}
virtual ~QmlPopupWidget() { setParent(nullptr); }
PopupDialog* getContainer() { return widgetContainer_; }
QWeakPointer<PopupDialog> getContainer() { return widgetContainer_.toWeakRef(); }
protected:
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
PopupDialog* widgetContainer_;
QSharedPointer<PopupDialog> widgetContainer_;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment