diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /qtjava/javalib/examples/mdi | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtjava/javalib/examples/mdi')
-rw-r--r-- | qtjava/javalib/examples/mdi/ApplicationWindow.java | 290 | ||||
-rw-r--r-- | qtjava/javalib/examples/mdi/MDIWindow.java | 135 | ||||
-rw-r--r-- | qtjava/javalib/examples/mdi/Main.java | 27 | ||||
-rw-r--r-- | qtjava/javalib/examples/mdi/document.xpm | 25 |
4 files changed, 477 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/mdi/ApplicationWindow.java b/qtjava/javalib/examples/mdi/ApplicationWindow.java new file mode 100644 index 00000000..e74e6233 --- /dev/null +++ b/qtjava/javalib/examples/mdi/ApplicationWindow.java @@ -0,0 +1,290 @@ +/*************************************************************************** +* $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.kde.qt.*; +import java.util.ArrayList; + +class ApplicationWindow extends QMainWindow +{ + +private QPrinter printer; +private QWorkspace ws; +/* Keep a copy of ws.windowList(), so that the MDIWindow + widgets in it won't get garbage collected */ +private ArrayList windows; +private QToolBar fileTools; +private QPopupMenu windowsMenu; + + + +private String fileOpenText = "Click this button to open a <em>new file</em>. <br><br>" ++ "You can also select the <b>Open command</b> from the File menu."; +private String fileSaveText = "Click this button to save the file you are " ++ "editing. You will be prompted for a file name.\n\n" ++ "You can also select the Save command from the File menu.\n\n" ++ "Note that implementing this function is left as an exercise for the reader."; +private String filePrintText = "Click this button to print the file you " ++ "are editing.\n\n" ++ "You can also select the Print command from the File menu."; + +/* XPM */ +static String filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; + +/* XPM */ +static String fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; + +/* XPM */ +static String fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; + +ApplicationWindow() +{ + super( null, "example application main window", WDestructiveClose ); + int id; + + QPixmap openIcon, saveIcon; + + fileTools = new QToolBar( this, "file operations" ); + addToolBar( fileTools, tr( "File Operations" ), DockTop, true ); + + openIcon = new QPixmap( fileopen ); + QToolButton fileOpen + = new QToolButton( new QIconSet(openIcon), "Open File", "", + this, SLOT("load()"), fileTools, "open file" ); + + saveIcon = new QPixmap( filesave ); + QToolButton fileSave + = new QToolButton( new QIconSet(saveIcon), "Save File", "", + this, SLOT("save()"), fileTools, "save file" ); + + printer = new QPrinter(); + QPixmap printIcon; + + printIcon = new QPixmap( fileprint ); + QToolButton filePrint + = new QToolButton( new QIconSet(printIcon), "Print File", "", + this, SLOT("print()"), fileTools, "print file" ); + QWhatsThis.add( filePrint, filePrintText ); + + QWhatsThis.whatsThisButton( fileTools ); + + QWhatsThis.add( fileOpen, fileOpenText ); + QWhatsThis.add( fileSave, fileSaveText ); + + QPopupMenu file = new QPopupMenu( this ); + menuBar().insertItem( "&File", file ); + + file.insertItem( "&New", this, SLOT("newDoc()"), new QKeySequence(CTRL+Key_N) ); + + id = file.insertItem( new QIconSet(openIcon), "&Open...", + this, SLOT("load()"), new QKeySequence(CTRL+Key_O) ); + file.setWhatsThis( id, fileOpenText ); + + id = file.insertItem( new QIconSet(saveIcon), "&Save", + this, SLOT("save()"), new QKeySequence(CTRL+Key_S) ); + file.setWhatsThis( id, fileSaveText ); + id = file.insertItem( "Save &As...", this, SLOT("saveAs()") ); + file.setWhatsThis( id, fileSaveText ); + file.insertSeparator(); + id = file.insertItem( new QIconSet(printIcon), "&Print...", + this, SLOT("print()"), new QKeySequence(CTRL+Key_P) ); + file.setWhatsThis( id, filePrintText ); + file.insertSeparator(); + file.insertItem( "&Close", this, SLOT("closeWindow()"), new QKeySequence(CTRL+Key_W) ); + file.insertItem( "&Quit", qApp(), SLOT(" closeAllWindows()"), new QKeySequence(CTRL+Key_Q) ); + + windowsMenu = new QPopupMenu( this ); + windowsMenu.setCheckable( true ); + connect( windowsMenu, SIGNAL(" aboutToShow()"), + this, SLOT(" windowsMenuAboutToShow()") ); + menuBar().insertItem( "&Windows", windowsMenu ); + + menuBar().insertSeparator(); + QPopupMenu help = new QPopupMenu( this ); + menuBar().insertItem( "&Help", help ); + + help.insertItem( "&About", this, SLOT("about()"), new QKeySequence(Key_F1)); + help.insertItem( "About &Qt", this, SLOT("aboutQt()")); + help.insertSeparator(); + help.insertItem( "What's &This", this, SLOT("whatsThis()"), new QKeySequence(SHIFT+Key_F1)); + + QVBox vb = new QVBox( this ); + vb.setFrameStyle( QFrame.StyledPanel | QFrame.Sunken ); + ws = new QWorkspace( vb ); + ws.setScrollBarsEnabled( true ); + setCentralWidget( vb ); + + statusBar().message( "Ready", 2000 ); +} + + +MDIWindow newDoc() +{ + MDIWindow w = new MDIWindow( ws, null, WDestructiveClose ); + connect( w, SIGNAL("message(String,int)"), statusBar(), SLOT("message(String,int)") ); + w.setCaption("unnamed document"); + w.setIcon( new QPixmap("document.xpm") ); + // show the very first window in maximized mode + windows = ws.windowList(); + if ( windows.size() == 0 ) + w.showMaximized(); + else + w.show(); + return w; +} + +void load() +{ + String fn = QFileDialog.getOpenFileName( "", "", this ); + if ( !fn.equals("") ) { + MDIWindow w = newDoc(); + w.load( fn ); + } else { + statusBar().message( "Loading aborted", 2000 ); + } +} + +void save() +{ + MDIWindow m = (MDIWindow)ws.activeWindow(); + if ( m != null ) + m.save(); +} + + +void saveAs() +{ + MDIWindow m = (MDIWindow)ws.activeWindow(); + if ( m != null ) + m.saveAs(); +} + + +void print() +{ + MDIWindow m = (MDIWindow)ws.activeWindow(); + if ( m != null) + m.print( printer ); +} + + +void closeWindow() +{ + MDIWindow m = (MDIWindow)ws.activeWindow(); + if ( m != null ) + m.close(); +} + +void about() +{ + QMessageBox.about( this, "Qt Application Example", + "This example demonstrates simple use of\n " + + "Qt's Multiple Document Interface (MDI)."); +} + + +void aboutQt() +{ + QMessageBox.aboutQt( this, "Qt Application Example" ); +} + + +void windowsMenuAboutToShow() +{ + windowsMenu.clear(); + int cascadeId = windowsMenu.insertItem("&Cascade", ws, SLOT("cascade()") ); + int tileId = windowsMenu.insertItem("&Tile", ws, SLOT("tile()") ); + windows = ws.windowList(); + if ( windows.size() == 0 ) { + windowsMenu.setItemEnabled( cascadeId, false ); + windowsMenu.setItemEnabled( tileId, false ); + } + windowsMenu.insertSeparator(); + for ( int i = 0; i < windows.size(); ++i ) { + int id = windowsMenu.insertItem(((QWidget) windows.get(i)).caption(), + this, SLOT(" windowsMenuActivated( int )") ); + windowsMenu.setItemParameter( id, i ); + windowsMenu.setItemChecked( id, ws.activeWindow() == windows.get(i) ); + } +} + +void windowsMenuActivated( int id ) +{ + windows = ws.windowList(); + QWidget w = (QWidget) windows.get( id ); + if ( w != null ) + w.showNormal(); + w.setFocus(); +} + + +} + diff --git a/qtjava/javalib/examples/mdi/MDIWindow.java b/qtjava/javalib/examples/mdi/MDIWindow.java new file mode 100644 index 00000000..ef5efd64 --- /dev/null +++ b/qtjava/javalib/examples/mdi/MDIWindow.java @@ -0,0 +1,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.kde.qt.*; + + +class MDIWindow extends QMainWindow +{ + +private QMultiLineEdit medit; +private QMovie mmovie; +private String filename = ""; + +MDIWindow( QWidget parent, String name, int wflags ) +{ + super( parent, name, wflags ); + mmovie = null; + medit = new QMultiLineEdit( this ); + setFocusProxy( medit ); + setCentralWidget( medit ); +} + + +void load( String fn ) +{ + filename = fn; + QFile f = new QFile( filename ); + if ( !f.open( QIODevice.IO_ReadOnly ) ) + return; + + if(fn.indexOf(".gif") != -1) { + QWidget tmp=new QWidget(this); + setFocusProxy(tmp); + setCentralWidget(tmp); + medit.hide(); + QMovie qm=new QMovie(fn); +// qm.setDisplayWidget(tmp); + tmp.setBackgroundMode(QWidget.NoBackground); + tmp.show(); + mmovie=qm; + } else { + mmovie = null; + + QTextStream t = new QTextStream(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(); + QFile f = new QFile( filename ); + if ( !f.open( QIODevice.IO_WriteOnly ) ) { + emit("message", "Could not write to " + filename, + 2000 ); + return; + } + + QTextStream t = new QTextStream( f ); + t.writeRawBytes( text, text.length() ); + f.close(); + + setCaption( filename ); + + emit("message", "File " + filename + " saved", 2000 ); +} + +void saveAs() +{ + String fn = QFileDialog.getSaveFileName( filename, "", this ); + if ( !fn.equals("") ) { + filename = fn; + save(); + } else { + emit("message", "Saving aborted", 2000 ); + } +} + +void print( QPrinter printer) +{ + int Margin = 10; + int pageNo = 1; + + if ( printer.setup(this) ) { // printer dialog + emit("message", "Printing...", 0 ); + QPainter p = new QPainter(); + if ( !p.begin( printer ) ) + return; // paint on printer + p.setFont( medit.font() ); + int yPos = 0; // y position for each line + QFontMetrics fm = p.fontMetrics(); + QPaintDeviceMetrics metrics = new QPaintDeviceMetrics( 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 ); + } +} + +} + diff --git a/qtjava/javalib/examples/mdi/Main.java b/qtjava/javalib/examples/mdi/Main.java new file mode 100644 index 00000000..8190b7cf --- /dev/null +++ b/qtjava/javalib/examples/mdi/Main.java @@ -0,0 +1,27 @@ +/*************************************************************************** +* $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.kde.qt.*; + +public class Main { + +public static void main(String[] args) { + QApplication a = new QApplication( args ); + ApplicationWindow mw = new ApplicationWindow(); + mw.setCaption( "Qt Example - Multiple Documents Interface (MDI)" ); + mw.show(); + a.connect( a, Qt.SIGNAL("lastWindowClosed()"), a, Qt.SLOT("quit()") ); + int res = a.exec(); + return; +} + static { + qtjava.initialize(); + } +} diff --git a/qtjava/javalib/examples/mdi/document.xpm b/qtjava/javalib/examples/mdi/document.xpm new file mode 100644 index 00000000..c08f63e9 --- /dev/null +++ b/qtjava/javalib/examples/mdi/document.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * document_xpm[] = { +"12 16 6 1", +" c #040404", +". c None", +"X c white", +"o c #808304", +"O c black", +"+ c #f3f7f3", +" .....", +" XXXXX ....", +" XXXXX X ...", +" XXXXX XX ..", +" XooXX O.", +" X+XXX+XXXO.", +" XXXXXXXXXO.", +" XoooXooXXO.", +" XXXXXXXXXO.", +" XXXXXXXXXO.", +" XoXXoooXXO.", +" XXXXXXXXXO.", +"OXXXXXXXXXO.", +"OXXXXXXXXXO.", +"OOOOOOOOOOO.", +"............"}; |