From 609163c13cc4c60fa1e6687b83ca9daae0d08681 Mon Sep 17 00:00:00 2001
From: con <qtc-committer@nokia.com>
Date: Wed, 31 Mar 2010 16:21:12 +0200
Subject: [PATCH] Make it possible to react on close button of info bar, and
 use it for Qt Quick Designer.

---
 .../editormanager/editormanager.cpp           |  5 ++--
 .../coreplugin/editormanager/editormanager.h  |  3 ++-
 .../coreplugin/editormanager/editorview.cpp   | 25 ++++++++++++-------
 .../coreplugin/editormanager/editorview.h     |  4 ++-
 .../qmljseditor/qmljseditorfactory.cpp        | 23 +++++++++--------
 src/plugins/qmljseditor/qmljseditorfactory.h  |  1 +
 6 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 048e8a57c5c..e59c376efef 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1770,9 +1770,10 @@ void EditorManager::revertToSaved()
 void EditorManager::showEditorInfoBar(const QString &id,
                                       const QString &infoText,
                                       const QString &buttonText,
-                                      QObject *object, const char *member)
+                                      QObject *object, const char *buttonPressMember,
+                                      const char *cancelButtonPressMember)
 {
-    currentEditorView()->showEditorInfoBar(id, infoText, buttonText, object, member);
+    currentEditorView()->showEditorInfoBar(id, infoText, buttonText, object, buttonPressMember, cancelButtonPressMember);
 }
 
 
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index a762364f6cc..c14860618ea 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -166,7 +166,8 @@ public:
     void showEditorInfoBar(const QString &id,
                            const QString &infoText,
                            const QString &buttonText = QString(),
-                           QObject *object = 0, const char *member = 0);
+                           QObject *object = 0, const char *buttonPressMember = 0,
+                           const char *cancelButtonPressMember = 0);
 
     void hideEditorInfoBar(const QString &id);
 
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index 24cbd1fe51b..48363270cce 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -112,13 +112,12 @@ EditorView::EditorView(QWidget *parent) :
         m_infoWidgetButton->setText(tr("Placeholder"));
         hbox->addWidget(m_infoWidgetButton);
 
-        QToolButton *closeButton = new QToolButton;
-        closeButton->setAutoRaise(true);
-        closeButton->setIcon(QIcon(":/core/images/clear.png"));
-        closeButton->setToolTip(tr("Close"));
-        connect(closeButton, SIGNAL(clicked()), m_infoWidget, SLOT(hide()));
+        m_infoWidgetCloseButton = new QToolButton;
+        m_infoWidgetCloseButton->setAutoRaise(true);
+        m_infoWidgetCloseButton->setIcon(QIcon(":/core/images/clear.png"));
+        m_infoWidgetCloseButton->setToolTip(tr("Close"));
 
-        hbox->addWidget(closeButton);
+        hbox->addWidget(m_infoWidgetCloseButton);
 
         m_infoWidget->setVisible(false);
         tl->addWidget(m_infoWidget);
@@ -173,14 +172,22 @@ void EditorView::closeView()
 void EditorView::showEditorInfoBar(const QString &id,
                                    const QString &infoText,
                                    const QString &buttonText,
-                                   QObject *object, const char *member)
+                                   QObject *object, const char *buttonPressMember,
+                                   const char *cancelButtonPressMember)
 {
     m_infoWidgetId = id;
     m_infoWidgetLabel->setText(infoText);
     m_infoWidgetButton->setText(buttonText);
+
     m_infoWidgetButton->disconnect();
-    if (object && member)
-        connect(m_infoWidgetButton, SIGNAL(clicked()), object, member);
+    if (object && buttonPressMember)
+        connect(m_infoWidgetButton, SIGNAL(clicked()), object, buttonPressMember);
+
+    m_infoWidgetCloseButton->disconnect();
+    if (object && cancelButtonPressMember)
+        connect(m_infoWidgetCloseButton, SIGNAL(clicked()), object, cancelButtonPressMember);
+    connect(m_infoWidgetCloseButton, SIGNAL(clicked()), m_infoWidget, SLOT(hide()));
+
     m_infoWidget->setVisible(true);
     m_editorForInfoWidget = currentEditor();
 }
diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h
index 8bc153d692c..e483e3da2db 100644
--- a/src/plugins/coreplugin/editormanager/editorview.h
+++ b/src/plugins/coreplugin/editormanager/editorview.h
@@ -84,7 +84,8 @@ public:
     void showEditorInfoBar(const QString &id,
                            const QString &infoText,
                            const QString &buttonText,
-                           QObject *object, const char *member);
+                           QObject *object, const char *buttonPressMember,
+                           const char *cancelButtonPressMember = 0);
     void hideEditorInfoBar(const QString &id);
 
     void showEditorStatusBar(const QString &id,
@@ -109,6 +110,7 @@ private:
     QFrame *m_infoWidget;
     QLabel *m_infoWidgetLabel;
     QToolButton *m_infoWidgetButton;
+    QToolButton *m_infoWidgetCloseButton;
     IEditor *m_editorForInfoWidget;
     QString m_statusWidgetId;
     QFrame *m_statusHLine;
diff --git a/src/plugins/qmljseditor/qmljseditorfactory.cpp b/src/plugins/qmljseditor/qmljseditorfactory.cpp
index 4a053fa0e62..99bea71fb0e 100644
--- a/src/plugins/qmljseditor/qmljseditorfactory.cpp
+++ b/src/plugins/qmljseditor/qmljseditorfactory.cpp
@@ -139,7 +139,9 @@ void QmlJSEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
     if (qobject_cast<QmlJSEditorEditable *>(editor)) {
         Core::EditorManager::instance()->showEditorInfoBar(QMLDESIGNER_INFO_BAR,
             tr("Do you want to enable the experimental Qt Quick Designer?"),
-            tr("Enable Qt Quick Designer"), this, SLOT(activateQmlDesigner()));
+            tr("Enable Qt Quick Designer"), this,
+            SLOT(activateQmlDesigner()),
+            SLOT(neverAskAgainAboutQmlDesigner()));
     } else {
         Core::EditorManager::instance()->hideEditorInfoBar(QMLDESIGNER_INFO_BAR);
     }
@@ -161,7 +163,6 @@ void QmlJSEditorFactory::activateQmlDesigner()
                        "To disable Qt Quick Designer again, visit the menu '%1' and disable 'QmlDesigner'.").arg(menu));
     message.setIcon(QMessageBox::Question);
     QPushButton *enable = message.addButton(tr("Enable Qt Quick Designer"), QMessageBox::AcceptRole);
-    QPushButton *dontNag = message.addButton(tr("Never ask me again"), QMessageBox::ActionRole);
     message.addButton(tr("Cancel"), QMessageBox::RejectRole);
     message.exec();
     if (message.clickedButton() == enable) {
@@ -178,13 +179,15 @@ void QmlJSEditorFactory::activateQmlDesigner()
                 return;
             }
         }
-    } else if (message.clickedButton() == dontNag) {
-        QSettings *settings = Core::ICore::instance()->settings();
-        settings->beginGroup(QLatin1String(KEY_QMLGROUP));
-        settings->setValue(QLatin1String(KEY_NAGABOUTDESIGNER), false);
-        settings->endGroup();
-        disconnect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-                 this, SLOT(updateEditorInfoBar(Core::IEditor*)));
-        Core::EditorManager::instance()->hideEditorInfoBar(QMLDESIGNER_INFO_BAR);
     }
 }
+
+void QmlJSEditorFactory::neverAskAgainAboutQmlDesigner()
+{
+    QSettings *settings = Core::ICore::instance()->settings();
+    settings->beginGroup(QLatin1String(KEY_QMLGROUP));
+    settings->setValue(QLatin1String(KEY_NAGABOUTDESIGNER), false);
+    settings->endGroup();
+    disconnect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
+             this, SLOT(updateEditorInfoBar(Core::IEditor*)));
+}
diff --git a/src/plugins/qmljseditor/qmljseditorfactory.h b/src/plugins/qmljseditor/qmljseditorfactory.h
index 5527a93c8c1..8bdf55d55b0 100644
--- a/src/plugins/qmljseditor/qmljseditorfactory.h
+++ b/src/plugins/qmljseditor/qmljseditorfactory.h
@@ -60,6 +60,7 @@ public:
 
 private slots:
     void activateQmlDesigner();
+    void neverAskAgainAboutQmlDesigner();
     void updateEditorInfoBar(Core::IEditor *editor);
 
 private:
-- 
GitLab