summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmtextedit.cpp
blob: 16f8501d8d9d28058accf16a70ecf52092f737c9 (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
132
133
134
135
136
137
138
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2002 by Andreas Zehender
    email                : [email protected]
**************************************************************************

**************************************************************************
*                                                                        *
*  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 "pmtextedit.h"
#include "pmtext.h"
#include "pmvectoredit.h"
#include "pmlineedits.h"

#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kfiledialog.h>

PMTextEdit::PMTextEdit( QWidget* parent, const char* name )
      : Base( parent, name )
{
   m_pDisplayedObject = 0;
}

void PMTextEdit::createTopWidgets( )
{
   Base::createTopWidgets( );
   
   QHBoxLayout* hl = new QHBoxLayout( topLayout( ) );
   hl->addWidget( new QLabel( i18n( "Font:" ), this ) );
   m_pFont = new QLineEdit( this );
   hl->addWidget( m_pFont );
   m_pChooseFont = new QPushButton( this );
   m_pChooseFont->setPixmap( SmallIcon( "fileopen" ) );
   hl->addWidget( m_pChooseFont );

   hl = new QHBoxLayout( topLayout( ) );
   hl->addWidget( new QLabel( i18n( "Text:" ), this ) );
   m_pText = new QLineEdit( this );
   hl->addWidget( m_pText );

   hl = new QHBoxLayout( topLayout( ) );
   hl->addWidget( new QLabel( i18n( "Thickness:" ), this ) );
   m_pThickness = new PMFloatEdit( this );
   hl->addWidget( m_pThickness );
   hl->addStretch( 1 );

   hl = new QHBoxLayout( topLayout( ) );
   hl->addWidget( new QLabel( i18n( "Offset:" ), this ) );
   m_pOffset = new PMVectorEdit( "x", "y", this );
   hl->addWidget( m_pOffset );
   
   connect( m_pFont, SIGNAL( textChanged( const QString& ) ),
            SLOT( slotTextChanged( const QString& ) ) );
   connect( m_pChooseFont, SIGNAL( clicked( ) ),
            SLOT( slotChooseFont( ) ) );
   connect( m_pText, SIGNAL( textChanged( const QString& ) ),
            SLOT( slotTextChanged( const QString& ) ) );
   connect( m_pThickness, SIGNAL( dataChanged( ) ),
            SIGNAL( dataChanged( ) ) );
   connect( m_pOffset, SIGNAL( dataChanged( ) ),
            SIGNAL( dataChanged( ) ) );
}

void PMTextEdit::displayObject( PMObject* o )
{
   if( o->isA( "Text" ) )
   {
      bool readOnly = o->isReadOnly( );
      m_pDisplayedObject = ( PMText* ) o;

      m_pFont->setText( m_pDisplayedObject->font( ) );
      m_pText->setText( m_pDisplayedObject->text( ) );
      m_pThickness->setValue( m_pDisplayedObject->thickness( ) );
      m_pOffset->setVector( m_pDisplayedObject->offset( ) );

      m_pFont->setReadOnly( readOnly );
      m_pChooseFont->setEnabled( !readOnly );
      m_pText->setReadOnly( readOnly );
      m_pThickness->setReadOnly( readOnly );
      m_pOffset->setReadOnly( readOnly );
      
      Base::displayObject( o );
   }
   else
      kdError( PMArea ) << "PMTextEdit: Can't display object\n";
}

void PMTextEdit::saveContents( )
{
   if( m_pDisplayedObject )
   {
      Base::saveContents( );
      m_pDisplayedObject->setFont( m_pFont->text( ) );
      m_pDisplayedObject->setText( m_pText->text( ) );
      m_pDisplayedObject->setThickness( m_pThickness->value( ) );
      m_pDisplayedObject->setOffset( m_pOffset->vector( ) );
   }
}

bool PMTextEdit::isDataValid( )
{
   if( m_pThickness->isDataValid( ) )
      if( m_pOffset->isDataValid( ) )
         return Base::isDataValid( );
   return false;
}

void PMTextEdit::slotTextChanged( const QString& )
{
   emit dataChanged( );
}

void PMTextEdit::slotChooseFont( )
{
   QString str = KFileDialog::getOpenFileName( QString::null, QString::null );

   if( !str.isEmpty() )
   {
      m_pFont->setText( str );
      emit dataChanged( );
   }   
}

#include "pmtextedit.moc"