summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmlibraryhandleedit.cpp
blob: e991af6e3bd3e55369c38ec24fd4a3974d2a1ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Luis Carvalho
    email                : lpassos@oninetspeed.pt
**************************************************************************

**************************************************************************
*                                                                        *
*  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.                                   *
*                                                                        *
**************************************************************************/

#include "pmlibraryhandleedit.h"

#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqlineedit.h>
#include <tqtextedit.h>
#include <tqvbox.h>
#include <tqlayout.h>
#include <tqlabel.h>

#include <klocale.h>
#include <kconfig.h>
#include <kmessagebox.h>
#include <kfiledialog.h>

#include "pmlineedits.h"
#include "pmdialogeditbase.h"
#include "pmlibraryhandle.h"

TQSize PMLibraryHandleEdit::s_size = TQSize( 600, 400 );

PMLibraryHandleEdit::PMLibraryHandleEdit( PMLibraryHandle* lib, TQWidget* parent, const char* name )
      : KDialogBase( parent, name, true, i18n( "Create Library" ),
                     Ok | Cancel, Ok )
{
   m_pLibrary = lib;

   resize( s_size );
   TQWidget* page = new TQWidget( this );
   setMainWidget( page );
   TQVBoxLayout* vl = new TQVBoxLayout( page, KDialog::spacingHint( ) );

   TQGridLayout* grid = new TQGridLayout( vl, 5, 2 );
   TQLabel* lbl = new TQLabel( i18n( "Name: " ), page );
   m_pNameEdit = new TQLineEdit( page );
   grid->addWidget( lbl, 0, 0 );
   grid->addWidget( m_pNameEdit, 0, 1 );

   lbl = new TQLabel( i18n( "Author: " ), page );
   m_pAuthorEdit = new TQLineEdit( page );
   grid->addWidget( lbl, 1, 0 );
   grid->addWidget( m_pAuthorEdit, 1, 1 );

   lbl = new TQLabel( i18n( "Description: " ), page );
   m_pDescriptionEdit = new TQTextEdit( page );
   m_pDescriptionEdit->setMaximumHeight( 120 );
   grid->addWidget( lbl, 2, 0 );
   grid->addMultiCellWidget( m_pDescriptionEdit, 2, 3, 1, 1 );
   grid->setRowStretch( 3, 1 );
   
   m_pReadOnlyEdit = new TQCheckBox( i18n( "Allow changes to the library?" ), page );
   grid->addMultiCellWidget( m_pReadOnlyEdit, 4, 4, 0, 1 );

   // Load the fields with values
   m_pNameEdit->setText( lib->name( ) );
   m_pDescriptionEdit->setText( lib->description( ) );
   m_pAuthorEdit->setText( lib->author( ) );
   m_pReadOnlyEdit->setChecked( !lib->isReadOnly( ) ); 
   
   // Setup the signals
   connect( m_pNameEdit, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotEditsChanged( const TQString& ) ) );
   connect( m_pAuthorEdit, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotEditsChanged( const TQString& ) ) );
   connect( m_pDescriptionEdit, TQT_SIGNAL( textChanged( ) ), TQT_SLOT( slotDescriptionChanged( ) ) );
   connect( m_pReadOnlyEdit, TQT_SIGNAL( clicked( ) ), TQT_SLOT( slotReadOnlyChanged( ) ) );

   // On startup you can only cancel
   enableButtonOK( false );
}

void PMLibraryHandleEdit::slotReadOnlyChanged( )
{
   enableButtonOK( true );
}

void PMLibraryHandleEdit::slotEditsChanged( const TQString& /*str*/ )
{
   enableButtonOK( true );
}

void PMLibraryHandleEdit::slotDescriptionChanged( )
{
   enableButtonOK( true );
}

void PMLibraryHandleEdit::saveConfig( KConfig* cfg )
{
   cfg->setGroup( "Appearance" );
   cfg->writeEntry( "LibraryHandleEditSize", s_size );
}

void PMLibraryHandleEdit::restoreConfig( KConfig* cfg )
{
   cfg->setGroup( "Appearance" );

   TQSize defaultSize( 300, 200 );
   s_size = cfg->readSizeEntry( "LibraryHandleEditSize", &defaultSize );
}

void PMLibraryHandleEdit::resizeEvent( TQResizeEvent* ev )
{
   s_size = ev->size( );
}

void PMLibraryHandleEdit::slotOk( )
{
   m_pLibrary->setName( m_pNameEdit->text( ) );
   m_pLibrary->setAuthor( m_pAuthorEdit->text( ) );
   m_pLibrary->setDescription( m_pDescriptionEdit->text( ) );
   m_pLibrary->setReadOnly( !m_pReadOnlyEdit->isChecked( ) );
   
   accept( );
}

#include "pmlibraryhandleedit.moc"