edittype.cc 4.24 KB
Newer Older
1
/*
2 3
   This file is part of Kig, a KDE program for Interactive Geometry...
   Copyright (C) 2004  Dominique Devriese <devriese@kde.org>
4
   Copyright (C) 2004  Pino Toscano <toscano.pino@tiscali.it>
5 6 7 8 9 10 11 12 13 14 15 16 17

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
19
   USA
20
*/
21 22 23

#include "edittype.h"

24
#include "ui_edittypewidget.h"
25

26 27 28
#include <kicondialog.h>
#include <klineedit.h>
#include <klocale.h>
29
#include <kmessagebox.h>
30
#include <KHelpClient>
David Narváez's avatar
David Narváez committed
31 32 33 34
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QPushButton>
#include <QVBoxLayout>
35

36 37
EditType::EditType( QWidget* parent, const QString& name, const QString& desc,
                    const QString& icon )
David Narváez's avatar
David Narváez committed
38
  : QDialog( parent ),
39
    mname( name ), mdesc( desc ), micon( icon )
40
{
David Narváez's avatar
David Narváez committed
41 42 43 44 45 46 47 48 49 50 51 52 53
  setWindowTitle( i18n( "Edit Type" ) );
  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help);
  QWidget *mainWidget = new QWidget(this);
  QVBoxLayout *mainLayout = new QVBoxLayout;
  setLayout(mainLayout);
  mainLayout->addWidget(mainWidget);
  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  //PORTING SCRIPT: WARNING mainLayout->addWidget(buttonBox) must be last item in layout. Please move it.
  mainLayout->addWidget(buttonBox);
Pino Toscano's avatar
Pino Toscano committed
54

55
  QWidget* base = new QWidget( this );
David Narváez's avatar
David Narváez committed
56
//PORTING: Verify that widget was added to mainLayout   setMainWidget( base );
57 58 59 60 61 62 63 64 65 66 67 68
  medittypewidget = new Ui_EditTypeWidget();
  medittypewidget->setupUi( base );
  base->layout()->setMargin( 0 );

  medittypewidget->editName->setText( mname );
  medittypewidget->editName->setWhatsThis(
        i18n( "Here you can edit the name of the current macro type." ) );
  medittypewidget->editDescription->setText( mdesc );
  medittypewidget->editDescription->setWhatsThis(
        i18n( "Here you can edit the description of the current macro type. "
              "This field is optional, so you can also leave this empty: if "
              "you do so, then your macro type will have no description." ) );
69
  medittypewidget->typeIcon->setIcon( !micon.isEmpty() ? micon : "system-run" );
70 71 72
  medittypewidget->typeIcon->setWhatsThis(
        i18n( "Use this button to change the icon of the current macro type." ) );

Pino Toscano's avatar
Pino Toscano committed
73
  connect( this, SIGNAL( helpClicked() ), this, SLOT( slotHelp() ) );
David Narváez's avatar
David Narváez committed
74 75
  connect(okButton, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
  connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL( clicked() ), this, SLOT( slotCancel() ) );
Pino Toscano's avatar
Pino Toscano committed
76

77
  resize( 450, 150 );
78 79 80 81
}

EditType::~EditType()
{
82
  delete medittypewidget;
83 84
}

85
void EditType::slotHelp()
86
{
87
  KHelpClient::invokeHelp( "working-with-types", "kig" );
88 89
}

90
void EditType::slotOk()
91
{
92
  QString tmp = medittypewidget->editName->text();
93 94 95 96 97 98
  if ( tmp.isEmpty() )
  {
    KMessageBox::information( this, i18n( "The name of the macro can not be empty." ) );
    return;
  }

99 100 101 102 103 104 105 106
  bool namechanged = false;
  bool descchanged = false;
  bool iconchanged = false;
  if ( tmp != mname )
  {
    mname = tmp;
    namechanged = true;
  }
107
  tmp = medittypewidget->editDescription->text();
108 109 110 111 112
  if ( tmp != mdesc )
  {
    mdesc = tmp;
    descchanged = true;
  }
113
  tmp = medittypewidget->typeIcon->icon();
114 115 116 117 118 119 120 121
  if ( tmp != micon )
  {
    micon = tmp;
    iconchanged = true;
  }
  done( namechanged || descchanged || iconchanged );
}

122
void EditType::slotCancel()
123
{
124
  done( 0 );
125 126
}

Pino Toscano's avatar
Pino Toscano committed
127
QString EditType::name() const
128 129 130 131
{
  return mname;
}

Pino Toscano's avatar
Pino Toscano committed
132
QString EditType::description() const
133 134 135 136
{
  return mdesc;
}

Pino Toscano's avatar
Pino Toscano committed
137
QString EditType::icon() const
138 139 140
{
  return micon;
}