ui: reuse resource when it is reusable
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 25 Oct 2016 02:27:12 +0000 (11:27 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 2 Nov 2016 05:42:29 +0000 (14:42 +0900)
Some resources are unique and reusable. So we do not "free" and
"new" them repeatedly.

Change-Id: I2c1c0c15b9162a9f0eed49ed209e7073a102d821
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/ui/displaybase.cpp
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/sdbhelper.cpp
tizen/src/ui/menu/sdbhelperthread.cpp
tizen/src/ui/menu/sdbhelperthread.h
tizen/src/ui/movingwidget.cpp

index 80b8b9b..1daff06 100644 (file)
@@ -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;
index 0493610..54f441d 100644 (file)
@@ -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");
 }
index b83ff7e..cd90e73 100644 (file)
@@ -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);
index 264847c..0c0c348 100644 (file)
@@ -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();
index 88370a4..f8518de 100644 (file)
@@ -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;
index 742966f..c1da058 100644 (file)
@@ -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"
index 2c0389e..dec4171 100644 (file)
@@ -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);
 }
index 5cdfcfc..162ce18 100644 (file)
@@ -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);
index e3daff4..669da8f 100644 (file)
@@ -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();