1 /*
2 This file is part of Kig, a KDE program for Interactive Geometry...
3 SPDX-FileCopyrightText: 2004 Dominique Devriese <devriese@kde.org>
4 SPDX-FileCopyrightText: 2004 Pino Toscano <toscano.pino@tiscali.it>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "edittype.h"
10
11 #include "ui_edittypewidget.h"
12
13 #include <KIconDialog>
14 #include <KLineEdit>
15 #include <KMessageBox>
16 #include <KHelpClient>
17 #include <QDialogButtonBox>
18 #include <KConfigGroup>
19 #include <QPushButton>
20 #include <QVBoxLayout>
21
EditType(QWidget * parent,const QString & name,const QString & desc,const QString & icon)22 EditType::EditType( QWidget* parent, const QString& name, const QString& desc,
23 const QString& icon )
24 : QDialog( parent ),
25 mname( name ), mdesc( desc ), micon( icon )
26 {
27 setWindowTitle( i18nc("@title:window", "Edit Type") );
28 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help);
29 QWidget *mainWidget = new QWidget(this);
30 QVBoxLayout *mainLayout = new QVBoxLayout;
31 setLayout(mainLayout);
32 mainLayout->addWidget(mainWidget);
33 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
34 okButton->setDefault(true);
35 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
36 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
37 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
38 mainLayout->addWidget(buttonBox);
39
40 medittypewidget = new Ui_EditTypeWidget();
41 medittypewidget->setupUi( mainWidget );
42 mainWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
43
44 medittypewidget->editName->setText( mname );
45 medittypewidget->editName->setWhatsThis(
46 i18n( "Here you can edit the name of the current macro type." ) );
47 medittypewidget->editDescription->setText( mdesc );
48 medittypewidget->editDescription->setWhatsThis(
49 i18n( "Here you can edit the description of the current macro type. "
50 "This field is optional, so you can also leave this empty: if "
51 "you do so, then your macro type will have no description." ) );
52 medittypewidget->typeIcon->setIcon( !micon.isEmpty() ? micon : QStringLiteral("system-run") );
53 medittypewidget->typeIcon->setWhatsThis(
54 i18n( "Use this button to change the icon of the current macro type." ) );
55
56 connect( this, SIGNAL(helpClicked()), this, SLOT(slotHelp()) );
57 connect(okButton, &QAbstractButton::clicked, this, &EditType::slotOk );
58 connect(buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked, this, &EditType::slotCancel );
59 }
60
~EditType()61 EditType::~EditType()
62 {
63 delete medittypewidget;
64 }
65
slotHelp()66 void EditType::slotHelp()
67 {
68 KHelpClient::invokeHelp( QStringLiteral("working-with-types"), QStringLiteral("kig") );
69 }
70
slotOk()71 void EditType::slotOk()
72 {
73 QString tmp = medittypewidget->editName->text();
74 if ( tmp.isEmpty() )
75 {
76 KMessageBox::information( this, i18n( "The name of the macro can not be empty." ) );
77 return;
78 }
79
80 bool namechanged = false;
81 bool descchanged = false;
82 bool iconchanged = false;
83 if ( tmp != mname )
84 {
85 mname = tmp;
86 namechanged = true;
87 }
88 tmp = medittypewidget->editDescription->text();
89 if ( tmp != mdesc )
90 {
91 mdesc = tmp;
92 descchanged = true;
93 }
94 tmp = medittypewidget->typeIcon->icon();
95 if ( tmp != micon )
96 {
97 micon = tmp;
98 iconchanged = true;
99 }
100 done( namechanged || descchanged || iconchanged );
101 }
102
slotCancel()103 void EditType::slotCancel()
104 {
105 done( 0 );
106 }
107
name() const108 QString EditType::name() const
109 {
110 return mname;
111 }
112
description() const113 QString EditType::description() const
114 {
115 return mdesc;
116 }
117
icon() const118 QString EditType::icon() const
119 {
120 return micon;
121 }
122