[education/rkward] rkward: Use KMessageWidget at a few more places

Thomas Friedrichsmeier null at kde.org
Thu Apr 28 20:50:43 BST 2022


Git commit ab8c806d2a2aae4fa62327112fc057599dd79f75 by Thomas Friedrichsmeier.
Committed on 28/04/2022 at 19:50.
Pushed by tfry into branch 'master'.

Use KMessageWidget at a few more places

M  +11   -4    rkward/dialogs/rkimportdialog.cpp
M  +16   -9    rkward/misc/rksaveobjectchooser.cpp
M  +3    -1    rkward/misc/rksaveobjectchooser.h

https://invent.kde.org/education/rkward/commit/ab8c806d2a2aae4fa62327112fc057599dd79f75

diff --git a/rkward/dialogs/rkimportdialog.cpp b/rkward/dialogs/rkimportdialog.cpp
index ed8fb5e2..5c1128b1 100644
--- a/rkward/dialogs/rkimportdialog.cpp
+++ b/rkward/dialogs/rkimportdialog.cpp
@@ -7,14 +7,15 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include "rkimportdialog.h"
 
-#include <KLocalizedString>
-
 #include <QLabel>
 #include <QVBoxLayout>
 #include <QGroupBox>
 #include <QRadioButton>
 #include <QButtonGroup>
 
+#include <KLocalizedString>
+#include <KMessageWidget>
+
 #include "../plugin/rkcomponentmap.h"
 #include "../plugin/rkcomponentcontext.h"
 #include "../misc/rkcommonfunctions.h"
@@ -52,7 +53,10 @@ RKImportDialog::RKImportDialog(const QString &context_id, QWidget *parent) : KAs
 	QVBoxLayout *layout = new QVBoxLayout(page);
 	layout->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("For certain formats, RKWard provides specialized import dialogs, and those generally provide the most options. Is the file you wish to import in one of the following formats?")));
 	if (filters.isEmpty()) {
-		layout->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("<b>Note:</b> RKWard comes with several import dialogs, but none seem to be loaded, at present. Check your settings.")));
+		auto w = new KMessageWidget(i18n("RKWard comes with several import dialogs, but none seem to be loaded, at present. Check your settings."));
+		w->setMessageType(KMessageWidget::Warning);
+		w->setWordWrap(true);
+		layout->addWidget(w);
 	}
 	QGroupBox *box = new QGroupBox();
 	layout->addWidget(box);
@@ -75,7 +79,10 @@ RKImportDialog::RKImportDialog(const QString &context_id, QWidget *parent) : KAs
 	layout = new QVBoxLayout(page);
 	layout->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("The 'rio' package offers generic support for importing many different file formats, but requires a number of additional R pacakges to be installed (you will be prompted for missing packages). Do you want to give that a try?")));
 	if (!rio_handle) {
-		layout->addWidget(RKCommonFunctions::wordWrappedLabel(i18n("<b>Note:</b> The generic import plugin (shipped with RKWard) is not presently loaded. Check your settings.")));
+		auto w = new KMessageWidget(i18n("The generic import plugin (shipped with RKWard) is not presently loaded. Check your settings."));
+		w->setMessageType(KMessageWidget::Warning);
+		w->setWordWrap(true);
+		layout->addWidget(w);
 	}
 	box = new QGroupBox();
 	layout->addWidget(box);
diff --git a/rkward/misc/rksaveobjectchooser.cpp b/rkward/misc/rksaveobjectchooser.cpp
index 1ca3939a..f9406bf4 100644
--- a/rkward/misc/rksaveobjectchooser.cpp
+++ b/rkward/misc/rksaveobjectchooser.cpp
@@ -1,6 +1,6 @@
 /*
 rksaveobjectchooser - This file is part of RKWard (https://rkward.kde.org). Created: Mon Nov 27 2006
-SPDX-FileCopyrightText: 2006-2010 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2006-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -17,6 +17,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <QDialogButtonBox>
 
 #include <KLocalizedString>
+#include <KMessageWidget>
 
 #include "../core/robjectlist.h"
 #include "../core/renvironmentobject.h"
@@ -50,9 +51,14 @@ RKSaveObjectChooser::RKSaveObjectChooser (QWidget *parent, const QString &initia
 	connect (name_edit, &QLineEdit::textChanged, this, &RKSaveObjectChooser::updateState);
 	layout->addWidget (name_edit);
 
-	overwrite_confirm = new QCheckBox (this);
-	connect (overwrite_confirm, &QCheckBox::stateChanged, this, &RKSaveObjectChooser::updateState);
-	layout->addWidget (overwrite_confirm);
+	overwrite_confirm = new QCheckBox(i18n("Overwrite"), this);
+	connect(overwrite_confirm, &QCheckBox::stateChanged, this, &RKSaveObjectChooser::updateState);
+	overwrite_warn = new KMessageWidget(i18n("The given object name already exists"));
+	overwrite_warn->setCloseButtonVisible(false);
+	hlayout = new QHBoxLayout();
+	hlayout->addWidget(overwrite_confirm);
+	hlayout->addWidget(overwrite_warn);
+	layout->addLayout(hlayout);
 
 	// initialize
 	setRootObject (0);
@@ -168,14 +174,15 @@ void RKSaveObjectChooser::updateState () {
 	new_name = root_object->makeChildName (new_name);	// make it the full name
 	if (current_object) {
 		object_exists = true;
-		overwrite_confirm->setText (i18n ("Overwrite? (The given object name already exists)"));
-		overwrite_confirm->setEnabled (true);
+		overwrite_confirm->setEnabled(true);
+		overwrite_warn->setMessageType(overwrite_confirm->isChecked() ? KMessageWidget::Information : KMessageWidget::Error);
+		overwrite_warn->animatedShow();
 		listenForObject (current_object);
 	} else {
 		object_exists = false;
-		overwrite_confirm->setText (i18n ("Overwrite?"));
-		overwrite_confirm->setEnabled (false);
-		overwrite_confirm->setChecked (false);
+		overwrite_confirm->setEnabled(false);
+		overwrite_confirm->setChecked(false);
+		overwrite_warn->hide();
 	}
 
 	if ((new_name != current_full_name) || (sender () == overwrite_confirm)) {
diff --git a/rkward/misc/rksaveobjectchooser.h b/rkward/misc/rksaveobjectchooser.h
index 2d365b25..7f072304 100644
--- a/rkward/misc/rksaveobjectchooser.h
+++ b/rkward/misc/rksaveobjectchooser.h
@@ -1,6 +1,6 @@
 /*
 rksaveobjectchooser - This file is part of the RKWard project. Created: Mon Nov 27 2006
-SPDX-FileCopyrightText: 2006-2007 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2006-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -15,6 +15,7 @@ class QLineEdit;
 class QCheckBox;
 class QPushButton;
 class QLabel;
+class KMessageWidget;
 
 /** Simple helper widget to select an R symbol name to write something to. */
 class RKSaveObjectChooser : public QWidget, public RObjectListener {
@@ -47,6 +48,7 @@ private:
 	QPushButton *root_button;
 	QLineEdit *name_edit;
 	QCheckBox *overwrite_confirm;
+	KMessageWidget *overwrite_warn;
 
 	QString current_full_name;
 };


More information about the rkward-tracker mailing list