summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/tools/designer/examples/richedit/richedit.ui.h
blob: e99a3ab6922d37127454839e1a6ef39857dadd35 (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
void EditorForm::init()
{
    textEdit->setFocus();  
 
    TQFontDatabase fonts;
    fontComboBox->insertStringList( fonts.families() );
    TQString font = textEdit->family();
    font = font.lower();
    for ( int i = 0 ; i < fontComboBox->count(); i++ ) {
	if ( font == fontComboBox->text( i ) ) {
	    fontComboBox->setCurrentItem( i );
	    break;
	}
    }
}

void EditorForm::fileExit()
{
    if ( saveAndContinue( "Exit" ) )
	tqApp->exit();
}

void EditorForm::fileNew()
{
    if ( saveAndContinue( "New" ) )
    	textEdit->clear();
}

void EditorForm::fileOpen()
{
    if ( saveAndContinue( "Open" ) ) {
    	TQString fn( TQFileDialog::getOpenFileName( 
			TQString(), 
			"Rich Text Files (*.htm*)", this ) );   
	if ( !fn.isEmpty() ) {
	    fileName = fn;
	    TQFile file( fileName );
	    if ( file.open( IO_ReadOnly ) ) {
		TQTextStream ts( &file );
		textEdit->setText( ts.read() );
	    }
	}
    }
}

void EditorForm::fileSave()
{
    if ( fileName.isEmpty() ) {
	fileSaveAs();
    } else {
	TQFile f( fileName );
	if ( f.open( IO_WriteOnly ) ) {
	    TQTextStream ts( &f );
	    ts << textEdit->text();
	    textEdit->setModified( FALSE );
	}
    }
}

void EditorForm::fileSaveAs()
{
    TQString fn = TQFileDialog::getSaveFileName( 
    				"", "Rich Text Files (*.htm*)", this );
    if ( !fn.isEmpty() ) {
	fileName = fn;
	fileSave();
    }
}

void EditorForm::helpAbout()
{
    
}

void EditorForm::helpContents()
{
    
}

void EditorForm::helpIndex()
{
    
}

void EditorForm::changeAlignment(TQAction * align)
{
    if ( align == leftAlignAction ) 
	textEdit->tqsetAlignment( TQt::AlignLeft );
    else if ( align == rightAlignAction )
	textEdit->tqsetAlignment( TQt::AlignRight );
    else if ( align == centerAlignAction )
	textEdit->tqsetAlignment( TQt::AlignCenter );
}

int EditorForm::saveAndContinue(const TQString & action)
{
    int continueAction = 1;
    
    if ( textEdit->isModified() ) {  
	switch( TQMessageBox::information(     
		this, "Rich Edit",   
		"The document contains unsaved changes.\n"   
		"Do you want to save the changes?",   
		"&Save", "&Don't Save", "&Cancel " + action,   
		0, // Enter == button 0   
		2 ) ) { // Escape == button 2   
	case 0: // Save; continue  
     		fileSave();  
        	break;   
    	case 1: // Do not save; continue
        	break;   
    	case 2: // Cancel
		continueAction = 0;
        	break;  
    	}	  
    }  
    
    return continueAction;
}