From: SeokYeon Hwang Date: Tue, 25 Oct 2016 02:27:12 +0000 (+0900) Subject: ui: reuse resource when it is reusable X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~20^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a6e2d1eacbaef2421a559e5b98d09d5cbea1d42;p=sdk%2Femulator%2Fqemu.git ui: reuse resource when it is reusable Some resources are unique and reusable. So we do not "free" and "new" them repeatedly. Change-Id: I2c1c0c15b9162a9f0eed49ed209e7073a102d821 Signed-off-by: SeokYeon Hwang --- diff --git a/tizen/src/ui/displaybase.cpp b/tizen/src/ui/displaybase.cpp index 80b8b9b9e1..1daff0677c 100644 --- a/tizen/src/ui/displaybase.cpp +++ b/tizen/src/ui/displaybase.cpp @@ -110,21 +110,22 @@ void DisplayBase::showOffGuideImg() { offGuideShown = true; - offGuide = new QLabel(win); - offGuide->setAttribute(Qt::WA_DeleteOnClose); - offGuide->setStyleSheet( - "background-color: black; border-style: none;"); - offGuide->setAlignment(Qt::AlignCenter); - - offGuide->setGeometry(getGeometry()); - offGuide->setPixmap(offGuideImg.scaled( - getGeometry().width(), getGeometry().height(), - Qt::KeepAspectRatio, Qt::SmoothTransformation)); - - if (maskImage.size() != QSize(0, 0)) { - offGuide->setMask(maskImage.scaled( - maskImage.width() * scaleFactor, - maskImage.height() * scaleFactor).mask()); + if (!offGuide) { + offGuide = new QLabel(win); + offGuide->setStyleSheet( + "background-color: black; border-style: none;"); + offGuide->setAlignment(Qt::AlignCenter); + + offGuide->setGeometry(getGeometry()); + offGuide->setPixmap(offGuideImg.scaled( + getGeometry().width(), getGeometry().height(), + Qt::KeepAspectRatio, Qt::SmoothTransformation)); + + if (maskImage.size() != QSize(0, 0)) { + offGuide->setMask(maskImage.scaled( + maskImage.width() * scaleFactor, + maskImage.height() * scaleFactor).mask()); + } } offGuide->show(); @@ -134,7 +135,6 @@ void DisplayBase::hideOffGuideImg() { if (offGuide != NULL) { offGuide->close(); - offGuide = NULL; } offGuideShown = false; diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index 04936100a4..54f441d46b 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -67,6 +67,8 @@ MainWindow::MainWindow(UiInformation *uiInfo, QWidget *parent) : this->captureRequestData = NULL; this->movingWidget = NULL; + this->isMovingMode = false; + /* windowing */ setWindowTitle(EMULATOR_TITLE); setWindowIcon(QIcon(":/icons/emulator_icon.ico")); @@ -561,12 +563,17 @@ void MainWindow::turnOnMovingMode() { qDebug("enter the moving mode"); + if (isMovingMode) { + return; + } + getDisplay()->turnOnMovingMode(); - if (isMovingMode() == false) { + if (movingWidget == NULL) { movingWidget = new MovingWidget(this); } + isMovingMode = true; movingWidget->show(); } @@ -574,17 +581,14 @@ void MainWindow::turnOffMovingMode() { qDebug("leave the moving mode"); - getDisplay()->turnOffMovingMode(); - - if (isMovingMode() == true) { - movingWidget->close(); - movingWidget = NULL; + if (!isMovingMode) { + return; } -} -bool MainWindow::isMovingMode() -{ - return (movingWidget != NULL); + getDisplay()->turnOffMovingMode(); + + movingWidget->close(); + isMovingMode = false; } /* override */ @@ -604,17 +608,29 @@ void MainWindow::closeEvent(QCloseEvent *event) } } -MainWindow::~MainWindow() +QMessageBox *MainWindow::showMsgBox( + QMessageBox::Icon iconType, const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) { - qDebug("destroy main window"); + qWarning() << text; - if (popupMenu) { - delete popupMenu; - popupMenu = NULL; + QMessageBox *msgBox = new QMessageBox(iconType, + EMULATOR_TITLE, text, buttons, this); + if (defaultButton != QMessageBox::NoButton) { + msgBox->setDefaultButton(defaultButton); } + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->show(); /* non-blocking */ - if (rotary != NULL) { - delete rotary; - rotary = NULL; - } +#ifdef CONFIG_LINUX + popupMenu->slotOnTop(getUiState()->isOnTop()); +#endif + + return msgBox; +} + +MainWindow::~MainWindow() +{ + qDebug("destroy main window"); } diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index b83ff7ea65..cd90e7395f 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -53,6 +53,8 @@ class MainWindow : public QWidget Q_OBJECT public: + bool isMovingMode; + explicit MainWindow(UiInformation *uiInfo, QWidget *parent = 0); ~MainWindow(); @@ -64,6 +66,9 @@ public: DisplayBase *getDisplay(); KeyboardShortcut *getKeyboardShortcut(); QLabel *getScreenWidget(); + QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text, + QMessageBox::StandardButtons buttons = QMessageBox::NoButton, + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); void updateDisplayTransform(); void switchForm(int angle); @@ -84,7 +89,6 @@ public: void turnOnMovingMode(); void turnOffMovingMode(); - bool isMovingMode(); public slots: void slotContextMenu(const QPoint &pos); diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 264847c4e3..0c0c348f9d 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -925,12 +925,12 @@ void ContextMenu::slotShell() QFileInfo sdbFileInfo(sdbPath); if (sdbFileInfo.exists() == false) { - showMsgBox(QMessageBox::Warning, MSG_SDB_NOT_EXIST + sdbPath); + parent->showMsgBox(QMessageBox::Warning, MSG_SDB_NOT_EXIST + sdbPath); return; } if (!is_sdb_daemon_initialized()) { - showMsgBox(QMessageBox::Warning, MSG_SDB_NOT_READY); + parent->showMsgBox(QMessageBox::Warning, MSG_SDB_NOT_READY); return; } @@ -971,7 +971,7 @@ void ContextMenu::launchControlPanel(QString& command, try { QProcess::startDetached(command, arguments, workingDir); } catch (QString &error) { - showMsgBox(QMessageBox::Warning, MSG_INVALID_ECP_OPEN + error); + parent->showMsgBox(QMessageBox::Warning, MSG_INVALID_ECP_OPEN + error); return; } #else @@ -997,7 +997,7 @@ void ContextMenu::launchControlPanel(QString& command, QString error = QString::number(GetLastError()); qWarning() << qPrintable(QString("error occured during launching \ ECP: ") + error); - showMsgBox(QMessageBox::Warning, MSG_INVALID_ECP_OPEN + error); + parent->showMsgBox(QMessageBox::Warning, MSG_INVALID_ECP_OPEN + error); } CloseHandle(pinfo.hThread); @@ -1069,7 +1069,7 @@ void ContextMenu::slotControlPanel() command = QString::fromLocal8Bit(path); } else { // can not enter here... - showMsgBox(QMessageBox::Warning, MSG_INVALID_JAVA_PATH); + parent->showMsgBox(QMessageBox::Warning, MSG_INVALID_JAVA_PATH); return; } @@ -1096,7 +1096,7 @@ void ContextMenu::slotControlPanel() } // we can not launch ControlPanel - showMsgBox(QMessageBox::Warning, MSG_ECP_NOT_EXIST); + parent->showMsgBox(QMessageBox::Warning, MSG_ECP_NOT_EXIST); return; } @@ -1212,37 +1212,10 @@ QSignalMapper *ContextMenu::getControllerMapper() return controllerMapper; } -QMessageBox *ContextMenu::showMsgBox( - QMessageBox::Icon iconType, const QString &text, - QMessageBox::StandardButtons buttons, - QMessageBox::StandardButton defaultButton) -{ - qWarning() << text; - - QMessageBox *msgBox = new QMessageBox(iconType, - EMULATOR_TITLE, text, buttons, parent); - if (defaultButton != QMessageBox::NoButton) { - msgBox->setDefaultButton(defaultButton); - } - msgBox->setAttribute(Qt::WA_DeleteOnClose); - msgBox->show(); /* non-blocking */ - -#ifdef CONFIG_LINUX - slotOnTop(parent->getUiState()->isOnTop()); -#endif - - return msgBox; -} - ContextMenu::~ContextMenu() { qDebug("destroy menu"); - if (infoDialog) { - delete infoDialog; - infoDialog = NULL; - } - delete sdbHelper; longPressTimer->stop(); diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index 88370a483d..f8518de322 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -128,10 +128,6 @@ private: const QString &text, QShortcut *shortcut, const char *slot); void attachShortcut(QAction *action, QShortcut *shortcut, const char *slot); - QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text, - QMessageBox::StandardButtons buttons = QMessageBox::NoButton, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); - MainWindow *parent; QString vmName; DetailedInfoDialog *infoDialog; diff --git a/tizen/src/ui/menu/sdbhelper.cpp b/tizen/src/ui/menu/sdbhelper.cpp index 742966ffb2..c1da058892 100644 --- a/tizen/src/ui/menu/sdbhelper.cpp +++ b/tizen/src/ui/menu/sdbhelper.cpp @@ -30,6 +30,7 @@ #include "config-host.h" #include "mainwindow.h" +#include "displaybase.h" #include "sdbhelper.h" #include "sdbhelperthread.h" #include "resource/ui_strings.h" diff --git a/tizen/src/ui/menu/sdbhelperthread.cpp b/tizen/src/ui/menu/sdbhelperthread.cpp index 2c0389ec6f..dec4171205 100644 --- a/tizen/src/ui/menu/sdbhelperthread.cpp +++ b/tizen/src/ui/menu/sdbhelperthread.cpp @@ -28,6 +28,7 @@ */ #include "sdbhelperthread.h" +#include "mainwindow.h" #include "sdbhelper.h" #include "displaybase.h" #include "resource/ui_strings.h" @@ -82,24 +83,5 @@ void SdbHelperThread::handleErrorOccured(QString errString, int exitCode) { qDebug() << "exitcode: " << exitCode; //FIXME: (sdb) cannot returns exit code like "no space left" - showMsgBox(QMessageBox::Warning, MSG_SDB_FAILED_PROCESSING + errString); -} - -QMessageBox *SdbHelperThread::showMsgBox( - QMessageBox::Icon iconType, const QString &text, - QMessageBox::StandardButtons buttons, - QMessageBox::StandardButton defaultButton) -{ - qWarning() << text; - - QMessageBox *msgBox = new QMessageBox(iconType, - EMULATOR_TITLE, text, buttons, (QWidget *)parent->getMainWindow()); - if (defaultButton != QMessageBox::NoButton) { - msgBox->setDefaultButton(defaultButton); - } - msgBox->setAttribute(Qt::WA_DeleteOnClose); - msgBox->setModal(false); - msgBox->show(); /* non-blocking */ - - return msgBox; + ((MainWindow *)parent->getMainWindow())->showMsgBox(QMessageBox::Warning, MSG_SDB_FAILED_PROCESSING + errString); } diff --git a/tizen/src/ui/menu/sdbhelperthread.h b/tizen/src/ui/menu/sdbhelperthread.h index 5cdfcfc389..162ce1813a 100644 --- a/tizen/src/ui/menu/sdbhelperthread.h +++ b/tizen/src/ui/menu/sdbhelperthread.h @@ -53,9 +53,6 @@ private: int command; QString errorMsg; QString outMsg; - QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text, - QMessageBox::StandardButtons buttons = QMessageBox::NoButton, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); signals: void errorOccured(QString errString, int exitCode); diff --git a/tizen/src/ui/movingwidget.cpp b/tizen/src/ui/movingwidget.cpp index e3daff486a..669da8fe36 100644 --- a/tizen/src/ui/movingwidget.cpp +++ b/tizen/src/ui/movingwidget.cpp @@ -43,7 +43,6 @@ MovingWidget::MovingWidget(QWidget *parent) : QWidget(parent) setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_DeleteOnClose); resize(win->size()); qDebug() << "moving widget size:" << win->size();