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
|
/***************************************************************************
* $Id$
**
* Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
* This file is part of an example program for Qt. This example
* program may be used, distributed and modified without limitation.
**
****************************************************************************/
import org.trinitydesktop.qt.*;
class MDIWindow extends TQMainWindow
{
private TQMultiLineEdit medit;
private TQMovie mmovie;
private String filename = "";
MDIWindow( TQWidget parent, String name, int wflags )
{
super( parent, name, wflags );
mmovie = null;
medit = new TQMultiLineEdit( this );
setFocusProxy( medit );
setCentralWidget( medit );
}
void load( String fn )
{
filename = fn;
TQFile f = new TQFile( filename );
if ( !f.open( TQIODevice.IO_ReadOnly ) )
return;
if(fn.indexOf(".gif") != -1) {
TQWidget tmp=new TQWidget(this);
setFocusProxy(tmp);
setCentralWidget(tmp);
medit.hide();
TQMovie qm=new TQMovie(fn);
// qm.setDisplayWidget(tmp);
tmp.setBackgroundMode(TQWidget.NoBackground);
tmp.show();
mmovie=qm;
} else {
mmovie = null;
TQTextStream t = new TQTextStream(f);
String s = t.read();
medit.setText( s );
f.close();
}
setCaption( filename );
emit("message", "Loaded document " + filename, 2000 );
}
void save()
{
if ( filename.equals("") ) {
saveAs();
return;
}
String text = medit.text();
TQFile f = new TQFile( filename );
if ( !f.open( TQIODevice.IO_WriteOnly ) ) {
emit("message", "Could not write to " + filename,
2000 );
return;
}
TQTextStream t = new TQTextStream( f );
t.writeRawBytes( text, text.length() );
f.close();
setCaption( filename );
emit("message", "File " + filename + " saved", 2000 );
}
void saveAs()
{
String fn = TQFileDialog.getSaveFileName( filename, "", this );
if ( !fn.equals("") ) {
filename = fn;
save();
} else {
emit("message", "Saving aborted", 2000 );
}
}
void print( TQPrinter printer)
{
int Margin = 10;
int pageNo = 1;
if ( printer.setup(this) ) { // printer dialog
emit("message", "Printing...", 0 );
TQPainter p = new TQPainter();
if ( !p.begin( printer ) )
return; // paint on printer
p.setFont( medit.font() );
int yPos = 0; // y position for each line
TQFontMetrics fm = p.fontMetrics();
TQPaintDeviceMetrics metrics = new TQPaintDeviceMetrics( printer ); // need width/height
// of printer surface
for( int i = 0 ; i < medit.numLines() ; i++ ) {
if ( Margin + yPos > metrics.height() - Margin ) {
String msg = "Printing (page ";
msg += (++pageNo);
msg += ")...";
emit("message", msg, 0 );
printer.newPage(); // no more room on this page
yPos = 0; // back to top of page
}
p.drawText( Margin, Margin + yPos,
metrics.width(), fm.lineSpacing(),
ExpandTabs | DontClip,
medit.textLine( i ) );
yPos = yPos + fm.lineSpacing();
}
p.end(); // send job to printer
emit("message", "Printing completed", 2000 );
} else {
emit("message", "Printing aborted", 2000 );
}
}
}
|