summaryrefslogtreecommitdiffstats
path: root/tdejava/koala/examples/kscribble
diff options
context:
space:
mode:
authorDarrell Anderson <humanreadable@yahoo.com>2014-01-08 20:06:00 +0100
committerSlávek Banko <slavek.banko@axis.cz>2014-01-08 20:06:00 +0100
commit636f509299122d02087c6fd62e1e4a46dbd22026 (patch)
tree70e43efceeb5b00e7f19cdac8da44928bd2fb459 /tdejava/koala/examples/kscribble
parent719b61750c08343f530068ed4127623aeac71cf0 (diff)
downloadtdebindings-636f509299122d02087c6fd62e1e4a46dbd22026.tar.gz
tdebindings-636f509299122d02087c6fd62e1e4a46dbd22026.zip
Rename many classes to avoid conflicts with KDE
Diffstat (limited to 'tdejava/koala/examples/kscribble')
-rw-r--r--tdejava/koala/examples/kscribble/KPenBrushDlg.java82
-rw-r--r--tdejava/koala/examples/kscribble/KScribbleApp.java1039
-rw-r--r--tdejava/koala/examples/kscribble/KScribbleDoc.java300
-rw-r--r--tdejava/koala/examples/kscribble/KScribbleView.java342
-rw-r--r--tdejava/koala/examples/kscribble/Main.java78
-rw-r--r--tdejava/koala/examples/kscribble/Resource.java71
6 files changed, 1912 insertions, 0 deletions
diff --git a/tdejava/koala/examples/kscribble/KPenBrushDlg.java b/tdejava/koala/examples/kscribble/KPenBrushDlg.java
new file mode 100644
index 00000000..afbe7d38
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/KPenBrushDlg.java
@@ -0,0 +1,82 @@
+import java.util.*;
+
+import org.trinitydesktop.qt.*;
+import org.trinitydesktop.koala.*;
+
+/**
+ * The base class for JavaApiTest application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. An instance of KBaseView creates your center view, which is connected
+ * to the window's Doc object.
+ * KBase reimplements the methods that TDEMainWindow provides for main window handling and supports
+ * full session management as well as using TDEActions.
+ * @see TDEMainWindow
+ * @see TDEApplication
+ * @see TDEConfig
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class KPenBrushDlg extends TQDialog {
+
+ private TQSpinBox width_spbox;
+ private TQLabel width_label;
+ private TQPushButton default_btn;
+ private TQPushButton ok_btn;
+ private TQPushButton cancel_btn;
+
+ public KPenBrushDlg(int curr, TQWidget parent, String name) {
+ super (parent,name,true,WStyle_ContextHelp);
+ initDialog();
+ TQWhatsThis.add(width_spbox,i18n("Select brush width"));
+
+ width_spbox.setValue(curr);
+ connect(default_btn, SIGNAL("clicked()"), this, SLOT("slotDefault()"));
+ connect(ok_btn, SIGNAL("clicked()"), this, SLOT("accept()"));
+ connect(cancel_btn, SIGNAL("clicked()"), this, SLOT("reject()"));
+
+
+ }
+
+ int getPenWidth() {
+ return width_spbox.value();
+ };
+
+ void initDialog(){
+ this.resize(370,210);
+ this.setMinimumSize(0,0);
+ width_spbox= new TQSpinBox(this,"width_spbox");
+ width_spbox.setGeometry(150,50,100,25);
+ width_spbox.setMinimumSize(0,0);
+ width_spbox.setValue(1);
+ width_spbox.setRange(1,99);
+
+ width_label= new TQLabel(this,"width_label");
+ width_label.setGeometry(20,50,120,25);
+ width_label.setMinimumSize(0,0);
+ width_label.setText(i18n("Pen width:"));
+
+ default_btn= new TQPushButton(this,"default");
+ default_btn.setGeometry(30,160,100,30);
+ default_btn.setMinimumSize(0,0);
+ default_btn.setText(i18n("&Default"));
+ default_btn.setAutoDefault(true);
+
+ ok_btn= new TQPushButton(this,"ok");
+ ok_btn.setGeometry(140,160,100,30);
+ ok_btn.setMinimumSize(0,0);
+ ok_btn.setText(i18n("&OK"));
+ ok_btn.setAutoDefault(true);
+
+ cancel_btn= new TQPushButton(this,"cancel");
+ cancel_btn.setGeometry(250,160,100,30);
+ cancel_btn.setMinimumSize(0,0);
+ cancel_btn.setText(i18n("&Cancel"));
+ cancel_btn.setAutoDefault(true);
+
+ }
+
+ void slotDefault(){
+ width_spbox.setValue(3);
+ }
+}
diff --git a/tdejava/koala/examples/kscribble/KScribbleApp.java b/tdejava/koala/examples/kscribble/KScribbleApp.java
new file mode 100644
index 00000000..729b6244
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/KScribbleApp.java
@@ -0,0 +1,1039 @@
+import java.util.*;
+import org.trinitydesktop.qt.*;
+import org.trinitydesktop.koala.*;
+
+/**
+ * The base class for KScribble application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. In initView(), your main view is created as the MDI child window manager.
+ * Child windows are created in createClient(), which gets a document instance as it's document to
+ * display whereby one document can have several views.The MDI child is an instance of KScribbleView,
+ * the document an instance of KScribbleDoc.
+ * KScribbleApp reimplements the methods that TDEMainWindow provides for main window handling and supports
+ * full session management as well as keyboard accelerator configuration by using TDEAccel.
+ * @see TDEMainWindow
+ * @see TDEApplication
+ * @see TDEConfig
+ * @see TDEAccel
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.1 code generation
+ */
+public class KScribbleApp extends TDEMainWindow implements Resource {
+
+ /** the configuration object of the application */
+ private TDEConfig config;
+ /** view is the main widget which represents your working area. The View
+ * class should handle all events of the view widget. It is kept empty so
+ * you can create your view according to your application's needs by
+ * changing the view class.
+ */
+ private KScribbleView view;
+ /** doc represents your actual document and is created only once. It keeps
+ * information such as filename and does the serialization of your files.
+ */
+ private KScribbleDoc doc;
+
+ /** contains the recently used filenames */
+ ArrayList recentFiles = null;
+
+ // menus
+ private TQPopupMenu pFileMenu;
+ private TQPopupMenu pEditMenu;
+ private TQPopupMenu pPenMenu;
+ private TQPopupMenu pViewMenu;
+ private TQPopupMenu pWindowMenu;
+ private TQPopupMenu pHelpMenu;
+ private TQPopupMenu pRecentFileMenu;
+
+ private TQWorkspace pWorkspace;
+ private TQPrinter printer;
+ private int untitledCount = 0;
+ private ArrayList pDocList;
+ private TDEApplication kapp;
+ private TDEIconLoader k = new TDEIconLoader();
+
+ /** construtor of KScribbleApp, calls all init functions to create the application.
+ */
+ public KScribbleApp(TQWidget parent, String name) {
+ super(parent,name, 0);
+ kapp = TDEApplication.kApplication();
+ config=kapp.config();
+
+ printer = new TQPrinter();
+ untitledCount=0;
+ pDocList = new ArrayList();
+ setAcceptDrops(true);
+ ///////////////////////////////////////////////////////////////////
+ // call inits to invoke all other construction parts
+ initMenuBar();
+ initToolBar();
+ initStatusBar();
+ initKeyAccel();
+ initView();
+
+ readOptions();
+
+ ///////////////////////////////////////////////////////////////////
+ // disable menu and toolbar items at startup
+ disableCommand(ID_EDIT_UNDO);
+
+ }
+
+ public KScribbleApp() {
+ this(null, null);
+ }
+
+ /** initializes the TDEActions of the application */
+ protected void initKeyAccel() {
+
+ TDEAccel keyAccel = new TDEAccel(this);
+
+ // fileMenu accelerators
+ keyAccel.insert(TDEStdAccel.New, this, SLOT("slotFileNew()"));
+ keyAccel.insert(TDEStdAccel.Open, this, SLOT("slotFileOpen()"));
+ keyAccel.insert(TDEStdAccel.Save, this, SLOT("slotFileSave()"));
+ keyAccel.insert(TDEStdAccel.Close, this, SLOT("slotFileClose()"));
+ keyAccel.insert(TDEStdAccel.Print, this, SLOT("slotFilePrint()"));
+ keyAccel.insert(TDEStdAccel.Quit, this, SLOT("slotFileQuit()"));
+
+ // editMenu accelerators
+ keyAccel.insert(TDEStdAccel.Cut, this, SLOT("slotEditCut()"));
+ keyAccel.insert(TDEStdAccel.Copy, this, SLOT("slotEditCopy()"));
+ keyAccel.insert(TDEStdAccel.Paste, this, SLOT("slotEditPaste()"));
+
+ // help accelerator
+ keyAccel.insert(TDEStdAccel.Help, this, SLOT("appHelpActivated()"));
+
+ keyAccel.readSettings();
+
+ }
+
+
+ void initMenuBar() {
+ ///////////////////////////////////////////////////////////////////
+ // MENUBAR
+
+ pRecentFileMenu = new TQPopupMenu(this);
+ connect(pRecentFileMenu, SIGNAL("activated(int)"), SLOT("slotFileOpenRecent(int)"));
+
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry file-Menu
+ pFileMenu = new TQPopupMenu(this);
+
+
+ pFileMenu.insertItem(KDE.BarIconSet("filenew"),i18n("&New"), ID_FILE_NEW,-1);
+ pFileMenu.insertItem(KDE.BarIconSet("fileopen"),i18n("&Open..."), ID_FILE_OPEN,-1);
+ pFileMenu.insertItem(i18n("Open &recent"), pRecentFileMenu, ID_FILE_OPEN_RECENT,-1);
+
+ pFileMenu.insertItem(i18n("&Close"), ID_FILE_CLOSE,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(KDE.BarIconSet("filefloppy") ,i18n("&Save"), ID_FILE_SAVE,-1);
+ pFileMenu.insertItem(i18n("Save &As..."), ID_FILE_SAVE_AS,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(KDE.BarIconSet("fileprint"), i18n("&Print..."), ID_FILE_PRINT,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(i18n("E&xit"), ID_FILE_QUIT,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry edit-Menu
+ pEditMenu = new TQPopupMenu(this);
+ pEditMenu.insertItem(KDE.BarIconSet("undo"), i18n("&Undo"), ID_EDIT_UNDO,-1);
+ pEditMenu.insertSeparator();
+ pEditMenu.insertItem(KDE.BarIconSet("editcut"), i18n("Cu&t"), ID_EDIT_CUT,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("editcopy"), i18n("&Copy"), ID_EDIT_COPY,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("editpaste"), i18n("&Paste"), ID_EDIT_PASTE,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("delete"),i18n("&Clear All"), ID_EDIT_CLEAR_ALL,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry pen-Menu
+ pPenMenu = new TQPopupMenu();
+ pPenMenu.insertItem(i18n("&Color"), ID_PEN_COLOR,-1);
+ pPenMenu.insertItem(i18n("&Brush"), ID_PEN_BRUSH,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry view-Menu
+ pViewMenu = new TQPopupMenu(this);
+ pViewMenu.setCheckable(true);
+ pViewMenu.insertItem(i18n("&Toolbar"), ID_VIEW_TOOLBAR,-1);
+ pViewMenu.insertItem(i18n("&Statusbar"), ID_VIEW_STATUSBAR,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry window-Menu
+ pWindowMenu = new TQPopupMenu(this);
+ pWindowMenu.setCheckable(true);
+
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry helpMenu
+
+ TQPopupMenu pHelpMenu = helpMenu(i18n("Java KScribble " + Main.VERSION + "\n\n(c) 2002 by\n" +
+ "Ralf Nolden\nRalf.Nolden@post.rwth-aachen.de"),true);
+
+ ///////////////////////////////////////////////////////////////////
+ // MENUBAR CONFIGURATION
+ // insert your popup menus with the according menubar entries in the order
+ // they will appear later from left to right
+ menuBar().insertItem(i18n("&File"), pFileMenu);
+ menuBar().insertItem(i18n("&Edit"), pEditMenu);
+ menuBar().insertItem(i18n("&Pen"), pPenMenu);
+ menuBar().insertItem(i18n("&View"), pViewMenu);
+ menuBar().insertItem(i18n("&Window"), pWindowMenu );
+ menuBar().insertItem(i18n("&Help"), pHelpMenu);
+
+ ///////////////////////////////////////////////////////////////////
+ // CONNECT THE MENU SLOTS WITH SIGNALS
+ // for execution slots and statusbar messages
+ connect(pFileMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pFileMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pEditMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pEditMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pPenMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pPenMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pViewMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pViewMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pWindowMenu, SIGNAL("aboutToShow()" ), SLOT( "windowMenuAboutToShow()" ) );
+ connect(pWindowMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pWindowMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ }
+
+
+ private void initToolBar() {
+
+ ///////////////////////////////////////////////////////////////////
+ // TOOLBAR
+
+ toolBar().insertButton(KDE.BarIcon("filenew"), ID_FILE_NEW, true, i18n("New File"),-1);
+ toolBar().insertButton(KDE.BarIcon("fileopen"), ID_FILE_OPEN, true, i18n("Open File"),-1);
+ toolBar().insertButton(KDE.BarIcon("filefloppy"), ID_FILE_SAVE, true, i18n("Save File"),-1);
+ toolBar().insertButton(KDE.BarIcon("fileprint"), ID_FILE_PRINT, true, i18n("Print"),-1);
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("editcut"), ID_EDIT_CUT, true, i18n("Cut"),-1);
+ toolBar().insertButton(KDE.BarIcon("editcopy"), ID_EDIT_COPY, true, i18n("Copy"),-1);
+ toolBar().insertButton(KDE.BarIcon("editpaste"), ID_EDIT_PASTE, true, i18n("Paste"),-1);
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("pencolor"), ID_PEN_COLOR, true, i18n("Color"),-1 );
+ toolBar().insertButton(KDE.BarIcon("penwidth"), ID_PEN_BRUSH, true, i18n("Width"),-1 );
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("help"), ID_HELP_CONTENTS, SIGNAL("clicked()"),
+ this, SLOT("appHelpActivated()"), true,i18n("Help"),-1);
+
+ TQToolButton btnwhat = TQWhatsThis.whatsThisButton(toolBar());
+ TQToolTip.add(btnwhat, i18n("What's this...?"));
+ toolBar().insertWidget(ID_HELP_WHATS_THIS, btnwhat.sizeHint().width(), btnwhat);
+
+ ///////////////////////////////////////////////////////////////////
+ // INSERT YOUR APPLICATION SPECIFIC TOOLBARS HERE WITH toolBar(n)
+
+
+ ///////////////////////////////////////////////////////////////////
+ // CONNECT THE TOOLBAR SLOTS WITH SIGNALS - add new created toolbars by their according number
+ // connect for invoking the slot actions
+ connect(toolBar(), SIGNAL("clicked(int)"), SLOT("commandCallback(int)"));
+ // connect for the status help on holing icons pressed with the mouse button
+ connect(toolBar(), SIGNAL("pressed(int)"), SLOT("statusCallback(int)"));
+
+ }
+
+
+ /** sets up the kstatusBar for the main window by initialzing a statuslabel.
+ */
+ protected void initStatusBar() {
+ ///////////////////////////////////////////////////////////////////
+ // STATUSBAR
+ // TODO: add your own items you need for displaying current application status.
+ kstatusBar().insertItem(i18n("Ready."), ID_STATUS_MSG);
+ }
+
+ /** creates the centerwidget of the KTMainWindow instance and sets it as the view
+ */
+ protected void initView() {
+
+ ////////////////////////////////////////////////////////////////////
+ // here the main view of the KTMainWindow is created by a background box and
+ // the TQWorkspace instance for MDI view.
+ TQVBox view_back = new TQVBox( this );
+ view_back.setFrameStyle( TQFrame.StyledPanel | TQFrame.Sunken );
+ pWorkspace = new TQWorkspace( view_back, "" );
+ connect(pWorkspace, SIGNAL("windowActivated(TQWidget)"), this, SLOT("setWndTitle(TQWidget)"));
+// setView(view_back);
+ setCentralWidget(view_back);
+ }
+
+ void createClient(KScribbleDoc doc) {
+ KScribbleView w = new KScribbleView(doc, pWorkspace,null,WDestructiveClose);
+ w.installEventFilter(this);
+ doc.addView(w);
+ w.setIcon(kapp.miniIcon());
+ if ( pWorkspace.windowList().isEmpty() ) // show the very first window in maximized mode
+ w.showMaximized();
+ else
+ w.show();
+ }
+
+ void addRecentFile(String file) {
+
+
+ if(recentFiles != null && recentFiles.contains(file))
+ return; // it's already there
+
+ if( recentFiles.size() < 5)
+ recentFiles.add(0,file);
+ else{
+ recentFiles.remove(recentFiles.remove(recentFiles.size()-1));
+ recentFiles.add(0,file);
+ }
+
+ pRecentFileMenu.clear();
+
+ Iterator it = recentFiles.iterator();
+ while (it.hasNext()) {
+ pRecentFileMenu.insertItem((String)it.next());
+ }
+
+ }
+
+ /** opens a file specified by commandline option
+ */
+ public void openDocumentFile(KURL url) {
+ slotStatusMsg(i18n("Opening file..."));
+
+ KScribbleDoc doc;
+ String file = url.directory(false,true) + url.fileName();
+
+ Iterator it = pDocList.iterator();
+
+ while (it.hasNext()) {
+
+ doc = (KScribbleDoc)it.next();
+ // check, if document already open. If yes, set the focus to the first view
+ if(doc.pathName().equals(file)) {
+
+ KScribbleView view=doc.firstView();
+ view.setFocus();
+ return;
+ }
+ }
+ doc = new KScribbleDoc();
+ pDocList.add(doc);
+ doc.newDocument();
+ // Creates an untitled window if file is 0
+ if(file == null || file.length() == 0) {
+ untitledCount+=1;
+ String fileName= i18n("Untitled" +untitledCount);
+ doc.setPathName(fileName);
+ doc.setTitle(fileName);
+ }
+ // Open the file
+ else {
+
+ String format= TQImageIO.imageFormat(file);
+ if(!doc.openDocument(file,format))
+ KMessageBox.error (this,i18n("Could not open document !"), i18n("Error !"),KMessageBox.Notify);
+ addRecentFile(file);
+ }
+ // create the window
+ createClient(doc);
+ slotStatusMsg(i18n("Ready."));
+
+ }
+
+
+ public void openDocumentFile() {
+ openDocumentFile(new KURL());
+ return;
+ }
+
+ void windowMenuAboutToShow() {
+ pWindowMenu.clear();
+
+ pWindowMenu.insertItem(i18n("&New Window"), ID_WINDOW_NEW_WINDOW);
+ pWindowMenu.insertItem(i18n("&Cascade"),
+ pWorkspace, SLOT("cascade()" ),new TQKeySequence(0) , ID_WINDOW_CASCADE );
+ pWindowMenu.insertItem(i18n("&Tile"),
+ pWorkspace, SLOT("tile()" ),new TQKeySequence(0) , ID_WINDOW_TILE );
+
+ if ( pWorkspace.windowList().isEmpty() ) {
+
+ disableCommand(ID_WINDOW_NEW_WINDOW);
+ disableCommand(ID_WINDOW_CASCADE);
+ disableCommand(ID_WINDOW_TILE);
+ }
+
+ pWindowMenu.insertSeparator();
+
+ ArrayList windows = pWorkspace.windowList();
+
+ for ( int i = 0; i < windows.size(); ++i ) {
+ int id = pWindowMenu.insertItem((i+1)+ ((TQWidget)windows.get(i)).caption(),
+ this, SLOT( "windowMenuActivated( int )" ) );
+ pWindowMenu.setItemParameter( id, i );
+ pWindowMenu.setItemChecked( id, pWorkspace.activeWindow() == (TQWidget)windows.get(i) );
+ }
+ }
+
+ void windowMenuActivated( int id ) {
+ TQWidget w = (TQWidget)pWorkspace.windowList().get( id );
+ if ( w != null )
+ w.setFocus();
+ }
+
+ void setWndTitle(TQWidget qw){
+ setCaption(pWorkspace.activeWindow() != null ? pWorkspace.activeWindow().caption() : "");
+ }
+
+ void enableCommand(int id_) {
+ ///////////////////////////////////////////////////////////////////
+ // enable menu and toolbar functions by their ID's
+ menuBar().setItemEnabled(id_, true);
+ toolBar().setItemEnabled(id_, true);
+ }
+
+ void disableCommand(int id_) {
+ ///////////////////////////////////////////////////////////////////
+ // disable menu and toolbar functions by their ID's
+ menuBar().setItemEnabled(id_, false);
+ toolBar().setItemEnabled(id_, false);
+ }
+
+ void commandCallback(int id_) {
+ switch (id_) {
+ case ID_FILE_NEW:
+ slotFileNew();
+ break;
+
+ case ID_FILE_OPEN:
+ slotFileOpen();
+ break;
+
+ case ID_FILE_SAVE:
+ slotFileSave();
+ break;
+
+ case ID_FILE_SAVE_AS:
+ slotFileSaveAs();
+ break;
+
+ case ID_FILE_CLOSE:
+ slotFileClose();
+ break;
+
+ case ID_FILE_PRINT:
+ slotFilePrint();
+ break;
+
+ case ID_FILE_QUIT:
+ slotFileQuit();
+ break;
+
+ case ID_EDIT_CUT:
+ slotEditCut();
+ break;
+
+ case ID_EDIT_COPY:
+ slotEditCopy();
+ break;
+
+ case ID_EDIT_PASTE:
+ slotEditPaste();
+ break;
+
+ case ID_EDIT_CLEAR_ALL:
+ slotEditClearAll();
+ break;
+
+ case ID_PEN_BRUSH:
+ slotPenBrush();
+ break;
+
+ case ID_PEN_COLOR:
+ slotPenColor();
+ break;
+
+ case ID_VIEW_TOOLBAR:
+ slotViewToolBar();
+ break;
+
+ case ID_VIEW_STATUSBAR:
+ slotViewStatusBar();
+ break;
+
+ case ID_WINDOW_NEW_WINDOW:
+ slotWindowNewWindow();
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ void statusCallback(int id_) {
+ switch (id_) {
+ case ID_FILE_NEW:
+ slotStatusHelpMsg(i18n("Creates a new document"));
+ break;
+
+ case ID_FILE_OPEN:
+ slotStatusHelpMsg(i18n("Opens an existing document"));
+ break;
+
+ case ID_FILE_OPEN_RECENT:
+ slotStatusHelpMsg(i18n("Opens a recently used file"));
+ break;
+
+ case ID_FILE_SAVE:
+ slotStatusHelpMsg(i18n("Saves the currently active document"));
+ break;
+
+ case ID_FILE_SAVE_AS:
+ slotStatusHelpMsg(i18n("Saves the currently active document as under a new filename"));
+ break;
+
+ case ID_FILE_CLOSE:
+ slotStatusHelpMsg(i18n("Closes the currently active document"));
+ break;
+
+ case ID_FILE_PRINT:
+ slotStatusHelpMsg(i18n("Prints out the actual document"));
+ break;
+
+ case ID_FILE_QUIT:
+ slotStatusHelpMsg(i18n("Quits the application"));
+ break;
+
+ case ID_EDIT_UNDO:
+ slotStatusHelpMsg(i18n("Reverts the last editing action"));
+ break;
+
+ case ID_EDIT_CUT:
+ slotStatusHelpMsg(i18n("Cuts the selected section and puts it to the clipboard"));
+ break;
+
+ case ID_EDIT_COPY:
+ slotStatusHelpMsg(i18n("Copies the selected section to the clipboard"));
+ break;
+
+ case ID_EDIT_PASTE:
+ slotStatusHelpMsg(i18n("Pastes the clipboard contents to actual position"));
+ break;
+
+ case ID_EDIT_CLEAR_ALL:
+ slotStatusHelpMsg(i18n("Clears the document contents"));
+ break;
+
+ case ID_PEN_BRUSH:
+ slotStatusHelpMsg(i18n("Sets the pen width"));
+ break;
+
+ case ID_PEN_COLOR:
+ slotStatusHelpMsg(i18n("Sets the current pen color"));
+ break;
+
+ case ID_VIEW_TOOLBAR:
+ slotStatusHelpMsg(i18n("Enables/disables the toolbar"));
+ break;
+
+ case ID_VIEW_STATUSBAR:
+ slotStatusHelpMsg(i18n("Enables/disables the statusbar"));
+ break;
+
+ case ID_WINDOW_NEW_WINDOW:
+ slotStatusHelpMsg(i18n("Opens a new view for the current document"));
+ break;
+
+ case ID_WINDOW_CASCADE:
+ slotStatusHelpMsg(i18n("Cascades all windows"));
+ break;
+
+ case ID_WINDOW_TILE:
+ slotStatusHelpMsg(i18n("Tiles all windows"));
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ void slotStatusHelpMsg(String text) {
+ ///////////////////////////////////////////////////////////////////
+ // change status message of whole statusbar temporary (text, msec)
+ statusBar().message(text, 2000);
+ }
+
+
+ /** returns a pointer to the current document connected to the KTMainWindow instance and is used by
+ * the View class to access the document object's methods
+ */
+ public KScribbleDoc getDocument() {
+ return doc;
+ }
+
+ /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration
+ * file
+ */
+ protected void saveOptions() {
+ config.setGroup("General Options");
+ config.writeEntry("Geometry", size());
+ config.writeEntry("Show Toolbar", toolBar().isVisible());
+ config.writeEntry("Show Statusbar",statusBar().isVisible());
+ config.writeEntry("ToolBarPos", (int) toolBar().barPos());
+ String[] rf = new String[recentFiles.size()];
+ rf = (String[]) recentFiles.toArray(rf);
+ if (rf != null)
+ config.writeEntry("Recent Files", rf);
+ }
+
+
+
+ /** read general Options again and initialize all variables like the recent file list
+ */
+ private void readOptions() {
+
+ config.setGroup("General Options");
+
+ // bar status settings
+ boolean bViewToolbar = config.readBoolEntry("Show Toolbar", true);
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, bViewToolbar);
+ if(!bViewToolbar) {
+ toolBar("mainToolBar").hide();
+ }
+
+ boolean bViewStatusbar = config.readBoolEntry("Show Statusbar", true);
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, bViewStatusbar);
+ if(!bViewStatusbar) {
+ toolBar("mainToolBar").hide();
+ }
+
+ // bar position settings
+ int toolBarPos = TDEToolBar.Top;
+ toolBarPos = config.readUnsignedNumEntry("ToolBarPos", TDEToolBar.Top);
+ toolBar().setBarPos(toolBarPos);
+
+ // initialize the recent file list
+ // commented out until fix is applied.
+ recentFiles = config.readListEntry("Recent Files");
+ Iterator it = recentFiles.iterator();
+ while (it.hasNext()) {
+ pRecentFileMenu.insertItem((String) it.next());
+ }
+
+ // Read the size information and resize from settings.
+ TQSize size = new TQSize();
+ config.readSizeEntry("Geometry",size);
+ if(!size.isEmpty()) {
+ resize(size);
+ }
+ else
+ resize(400,350);
+
+ }
+
+ /** saves the window properties for each open window during session end to the session config file, including saving the currently
+ * opened file by a temporary filename provided by TDEApplication.
+ * @see KTMainWindow#saveProperties
+ */
+ protected void saveProperties(TDEConfig _cfg) {
+
+ }
+
+
+ /** reads the session config file and restores the application's state including the last opened files and documents by reading the
+ * temporary files saved by saveProperties()
+ * @see KTMainWindow#readProperties
+ */
+ protected void readProperties(TDEConfig _cfg) {
+ }
+
+ /** queryClose is called by KTMainWindow on each closeEvent of a window. Against the
+ * default implementation (only returns true), this calles saveModified() on the document object to ask if the document shall
+ * be saved if Modified; on cancel the closeEvent is rejected.
+ * @see KTMainWindow#queryClose
+ * @see KTMainWindow#closeEvent
+ */
+ protected boolean queryClose() {
+
+ ArrayList saveFiles = new ArrayList();
+ KScribbleDoc doc;
+
+ if(pDocList.isEmpty())
+ return true;
+
+ Iterator it = pDocList.iterator();
+
+ while (it.hasNext()) {
+ doc = (KScribbleDoc)it.next();
+ if(doc.isModified())
+ saveFiles.add(doc.title());
+
+ }
+
+ if(saveFiles.isEmpty())
+ return true;
+
+ // lets load up a String array with the documents to save.
+ String[] sf = new String[saveFiles.size()];
+ for (int x = 0; x < saveFiles.size(); x++) {
+ sf[x] = (String)saveFiles.get(x);
+ }
+ switch (KMessageBox.questionYesNoList(this,
+ i18n("One or more documents have been modified.\nSave changes before exiting?"),sf))
+ {
+ case KMessageBox.Yes:
+
+ Iterator itr = pDocList.iterator();
+
+ while (itr.hasNext()) {
+ doc = (KScribbleDoc)itr.next();
+ if(doc.title().indexOf(i18n("Untitled")) > 0) {
+
+ slotFileSaveAs();
+ }
+ else {
+ if(!doc.saveDocument(doc.pathName())){
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify);
+ return false;
+ }
+
+ }
+
+
+ }
+ return true;
+ case KMessageBox.No:
+ default:
+ return true;
+ }
+
+ }
+
+ /** queryExit is called by KTMainWindow when the last window of the application is going to be closed during the closeEvent().
+ * Against the default implementation that just returns true, this calls saveOptions() to save the settings of the last window's
+ * properties.
+ * @see KTMainWindow#queryExit
+ * @see KTMainWindow#closeEvent
+ */
+ protected boolean queryExit() {
+ saveOptions();
+ return true;
+ }
+
+/////////////////////////////////////////////////////////////////////
+// SLOT IMPLEMENTATION
+/////////////////////////////////////////////////////////////////////
+
+
+ void slotFileNew() {
+ slotStatusMsg(i18n("Creating new document..."));
+
+ openDocumentFile();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileOpen() {
+ slotStatusMsg(i18n("Opening file..."));
+
+ String fileToOpen=KFileDialog.getOpenFileName(TQDir.currentDirPath(),
+ KImageIO.pattern(KImageIO.Reading), this, i18n("Open File..."));
+ if(fileToOpen != null && fileToOpen.length() > 0) {
+ openDocumentFile(new KURL(fileToOpen));
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+
+ void slotFileSave() {
+ slotStatusMsg(i18n("Saving file..."));
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null) {
+ KScribbleDoc doc = m.getDocument();
+ if(doc.title().indexOf(i18n("Untitled")) > 0)
+ slotFileSaveAs();
+ else
+ if(!doc.saveDocument(doc.pathName()))
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify); }
+
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileSaveAs() {
+ slotStatusMsg(i18n("Saving file with a new filename..."));
+
+ String newName=KFileDialog.getSaveFileName(TQDir.currentDirPath(),
+ KImageIO.pattern(KImageIO.Writing), this, i18n("Save as..."));
+
+ if(newName != null) {
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null ) {
+ KScribbleDoc doc = m.getDocument();
+
+ String format=new TQFileInfo(newName).extension();
+ format=format.toUpperCase();
+
+ if(!doc.saveDocument(newName,format)) {
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify);
+ return;
+ }
+ doc.changedViewList();
+ setWndTitle(m);
+ }
+
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileClose() {
+ slotStatusMsg(i18n("Closing file..."));
+
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null ) {
+ KScribbleDoc doc=m.getDocument();
+ doc.closeDocument();
+ }
+
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFilePrint() {
+ slotStatusMsg(i18n("Printing..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null)
+ m.print( printer );
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileQuit() {
+ slotStatusMsg(i18n("Exiting..."));
+ saveOptions();
+ // close the first window, the list makes the next one the first again.
+ // This ensures that queryClose() is called on each window to ask for closing
+ TDEMainWindow w;
+
+ ArrayList memberlist = memberList();
+ if(memberlist != null) {
+ Iterator it = memberlist.iterator();
+ while (it.hasNext()) {
+ w = (TDEMainWindow)it.next();
+ // only close the window if the closeEvent is accepted. If the user
+ // presses Cancel on the saveModified() dialog,
+ // the window and the application stay open.
+ if(!w.close())
+ break;
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileOpenRecent(int id_) {
+ slotStatusMsg(i18n("Opening file..."));
+
+ KURL kurl = new KURL(pRecentFileMenu.text(id_));
+// openDocumentFile(pRecentFileMenu.text(id_));
+ openDocumentFile(kurl);
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotEditClearAll() {
+ slotStatusMsg(i18n("Clearing the document contents..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ){
+ KScribbleDoc pDoc = m.getDocument();
+ pDoc.editClearAll();
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotPenBrush() {
+ slotStatusMsg(i18n("Setting brush width..."));
+
+ // get one window with document for a current pen width
+ ArrayList windows = pWorkspace.windowList();
+ KScribbleView m = (KScribbleView)windows.get(0);
+ KScribbleDoc pDoc = m.getDocument();
+ int curr_width=pDoc.penWidth();
+
+ // create the dialog, get the new width and set the pen width for all documents
+ KPenBrushDlg dlg= new KPenBrushDlg(curr_width,this,"");
+ if(dlg.exec() > 0){
+ int width=dlg.getPenWidth();
+ for ( int i = 0; i < windows.size(); ++i ) {
+ m = (KScribbleView)windows.get(i);
+ if ( m != null ) {
+ pDoc = m.getDocument();
+ pDoc.setPenWidth(width);
+ }
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotPenColor() {
+ slotStatusMsg(i18n("Selecting pen color..."));
+
+ TQColor myColor = new TQColor();
+ int result = KColorDialog.getColor( myColor, this );
+ if ( result == KColorDialog.Accepted )
+ {
+ ArrayList windows = pWorkspace.windowList();
+ KScribbleDoc pDoc;
+ KScribbleView m;
+ for ( int i = 0; i < windows.size(); ++i ) {
+ m = (KScribbleView)windows.get(i);
+ if ( m != null) {
+ pDoc = m.getDocument();
+ pDoc.setPenColor(myColor);
+ }
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotEditUndo() {
+ slotStatusMsg(i18n("Reverting last action..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+// if ( m != null )
+// m.undo();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** put the marked object into the clipboard and remove
+ * it from the document
+ */
+ void slotEditCut() {
+ slotStatusMsg(i18n("Cutting selection..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null )
+ m.cutSelection();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** put the marked text/object into the clipboard
+ */
+ public void slotEditCopy() {
+ slotStatusMsg(i18n("Copying selection to clipboard..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null)
+ m.copySelection();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** paste the clipboard into the document
+ */
+ public void slotEditPaste() {
+ slotStatusMsg(i18n("Inserting clipboard contents..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ) {
+ m.pasteSelection();
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** toggles the toolbar
+ */
+
+ void slotViewToolBar() {
+ slotStatusMsg(i18n("Toggle the toolbar..."));
+ ///////////////////////////////////////////////////////////////////
+ // turn Toolbar on or off
+ if( menuBar().isItemChecked(ID_VIEW_TOOLBAR)) {
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, false);
+ toolBar("mainToolBar").hide();
+
+ }
+ else {
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, true);
+ toolBar("mainToolBar").show();
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** toggles the statusbar
+ */
+ void slotViewStatusBar() {
+ slotStatusMsg(i18n("Toggle the statusbar..."));
+ ///////////////////////////////////////////////////////////////////
+ //turn Statusbar on or off
+ if( menuBar().isItemChecked(ID_VIEW_STATUSBAR)) {
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, false);
+ kstatusBar().hide();
+
+ }
+ else {
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, true);
+ kstatusBar().show();
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotWindowNewWindow() {
+ slotStatusMsg(i18n("Opening a new application window..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ){
+ KScribbleDoc doc = m.getDocument();
+ createClient(doc);
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** changes the statusbar contents for the standard label permanently, used to indicate current actions.
+ * @param text the text that is displayed in the statusbar
+ */
+ public void slotStatusMsg(String text) {
+ ///////////////////////////////////////////////////////////////////
+ // change status message permanently
+ kstatusBar().clear();
+ kstatusBar().changeItem(text, ID_STATUS_MSG);
+ }
+
+ /** accepts drops and opens a new document
+ for each drop */
+ protected void dropEvent( TQDropEvent e){
+ TQImage img = new TQImage();
+ if ( TQImageDrag.decode(e, img) ) {
+ KScribbleDoc doc = new KScribbleDoc();
+ untitledCount+=1;
+ String fileName= i18n("Untitled") + untitledCount;
+ doc.setPathName(fileName);
+ doc.setTitle(fileName);
+ doc.newDocument();
+ pDocList.add(doc);
+ KPixmap tmp = new KPixmap();
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ doc.setPixmap(tmp);
+ doc.resizeDocument(tmp.size());
+ doc.setModified();
+ createClient(doc);
+ }
+ }
+ /** accepts drag events for images */
+ protected void dragEnterEvent( TQDragEnterEvent e){
+ e.accept(TQImageDrag.canDecode(e));
+ }
+
+
+}
diff --git a/tdejava/koala/examples/kscribble/KScribbleDoc.java b/tdejava/koala/examples/kscribble/KScribbleDoc.java
new file mode 100644
index 00000000..427db194
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/KScribbleDoc.java
@@ -0,0 +1,300 @@
+import java.util.*;
+
+import org.trinitydesktop.qt.*;
+import org.trinitydesktop.koala.*;
+
+/** KScribbleDoc provides a document object for a document-view model.
+ *
+ * The KScribbleDoc class provides a document object that can be used in conjunction with the classes JavaApiTestApp and KScribbleView
+ * to create a document-view model for standard KDE applications based on TDEApplication and TDEMainWindow. Thereby, the document object
+ * is created by the JavaApiTestApp instance and contains the document structure with the according methods for manipulation of the document
+ * data by KScribbleView objects. Also, KScribbleDoc contains the methods for serialization of the document data from and to files.
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class KScribbleDoc extends TQObject {
+
+ /** the list of the views currently connected to the document */
+ private ArrayList pViewList;
+ private String m_title;
+ private String m_filename;
+ private TQSize size;
+ private TQPen pen;
+ public TQPointArray polyline;
+ public KPixmap buffer;
+
+ /** the modified flag of the current document */
+ private boolean modified;
+ private KURL doc_url;
+
+
+ public KScribbleDoc() {
+
+ pViewList = new ArrayList();
+ }
+
+ void addView(KScribbleView view) {
+ pViewList.add(view);
+ changedViewList();
+ }
+
+ void removeView(KScribbleView view) {
+ pViewList.remove(view);
+ if(!pViewList.isEmpty())
+ changedViewList();
+ else
+ deleteContents();
+ }
+
+ void changedViewList(){
+
+ KScribbleView w;
+ if(pViewList.size() == 1){
+ w=(KScribbleView)pViewList.get(0);
+ w.setCaption(m_title);
+ }
+ else{
+ int i = 1;
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ w.setCaption(m_title + ":"+ i++);
+
+ }
+ }
+ }
+
+ boolean isLastView() {
+ return (pViewList.size() == 1);
+ }
+
+
+ void updateAllViews(KScribbleView sender) {
+ KScribbleView w;
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ w.update(sender);
+
+ }
+
+ }
+
+ void setPathName(String name) {
+ m_filename=name;
+ m_title= new TQFileInfo(name).fileName();
+ }
+
+ String pathName() {
+ return m_filename;
+ }
+
+ /** returns the current pen in use */
+ TQPen currentPen() {
+ return pen;
+ }
+
+ /** returns the pen color */
+ int penWidth() {
+ return pen.width();
+ }
+
+ /** returns the pen color */
+ TQColor penColor(){
+ return pen.color();
+ }
+
+ /** sets the pen width */
+ void setPenWidth( int w ){
+ pen.setWidth( w );
+ }
+
+ /** sets the pen color */
+ void setPenColor( TQColor c ){
+ pen.setColor( c );
+ }
+
+ /** sets the pen style by a second toolbar */
+// void setPenStyle( PenStyle s) {
+// pen.setStyle(s);
+// }
+
+ void setTitle(String title) {
+
+ m_title=title;
+ }
+
+ String title() {
+ return m_title;
+ }
+
+ /** sets the pixmap contents. Used by KScribbleApp
+ to create a new document by drop events */
+ void setPixmap(KPixmap pix) {
+ buffer=pix;
+ };
+ void resizeDocument(TQSize m_size) {
+ size=m_size;
+ };
+
+ void closeDocument() {
+ KScribbleView w;
+ if(!isLastView()) {
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ if (!w.close())
+ break;
+
+ }
+
+ }
+ if(isLastView()) {
+ w= (KScribbleView)pViewList.get(0);
+ w.close();
+ }
+ }
+
+ boolean newDocument() {
+ /////////////////////////////////////////////////
+ // TODO: Add your document initialization code here
+ size=new TQSize(300,200 );
+ pen= new TQPen();
+ pen.setColor(Qt.black());
+ pen.setWidth(3);
+ polyline= new TQPointArray(3);
+ if (buffer == null) {
+ buffer = new KPixmap();
+ }
+ buffer.resize(size);
+ buffer.fill( Qt.white() );
+ /////////////////////////////////////////////////
+ modified=false;
+ return true;
+ }
+
+ public boolean openDocument(String filename, String format) {
+
+ TQFile f = new TQFile( filename );
+ // if ( !f.open( IO_ReadOnly ) )
+ // return false;
+ /////////////////////////////////////////////////
+ // TODO: Add your document opening code here
+ if(!buffer.load( filename, format, 0))
+ return false;
+ size=buffer.size();
+ /////////////////////////////////////////////////
+ // f.close();
+
+ modified=false;
+ m_filename=filename;
+ m_title=new TQFileInfo(f).fileName();
+ return true;
+ }
+
+ boolean saveDocument(String filename) {
+ return saveDocument(filename,"") ;
+ }
+
+ /** returns the first view instance */
+ KScribbleView firstView(){
+ return (KScribbleView) pViewList.get(0);
+ };
+
+ boolean saveDocument(String filename, String format /*=0*/) {
+ TQFile f = new TQFile( filename );
+ // if ( !f.open( IO_WriteOnly ) )
+ // return false;
+
+ /////////////////////////////////////////////////
+ // TODO: Add your document saving code here
+ if(!buffer.save( filename, format ))
+ return false;
+ /////////////////////////////////////////////////
+
+ // f.close();
+
+ modified=false;
+ m_filename=filename;
+ m_title=new TQFileInfo(f).fileName();
+ return true;
+ }
+
+ void deleteContents() {
+ /////////////////////////////////////////////////
+ // TODO: Add implementation to delete the document contents
+ buffer.fill( Qt.white() );
+ /////////////////////////////////////////////////
+
+ }
+
+ boolean isModified() {
+ return modified;
+ }
+
+ void setModified() {
+ modified = true;
+ }
+
+ boolean canCloseFrame(KScribbleView pFrame) {
+ if(!isLastView())
+ return true;
+
+ boolean ret=false;
+ if(isModified()) {
+ String saveName = new String();
+ switch(KMessageBox.warningYesNoCancel(pFrame, i18n("The current file has been modified.\n" +
+ "Do you want to save it?"),title()))
+ {
+ case KMessageBox.Yes:
+ if(title().indexOf(i18n("Untitled")) > 0) {
+ saveName= KFileDialog.getSaveFileName(TQDir.currentDirPath(),
+ i18n("*|All files"), pFrame, i18n("Save as..."));
+ if(saveName == null || saveName.length() == 0)
+ return false;
+ }
+ else
+ saveName=pathName();
+
+ if(!saveDocument(saveName)) {
+ switch(KMessageBox.warningYesNo(pFrame,i18n("Could not save the current document !\n" +
+ "Close anyway ?"), i18n("I/O Error !")))
+ {
+ case KMessageBox.Yes:
+ ret=true;
+ case KMessageBox.No:
+ ret=false;
+ }
+ }
+ else
+ ret=true;
+ break;
+ case KMessageBox.No:
+ ret=true;
+ break;
+ case KMessageBox.Cancel:
+ default:
+ ret=false;
+ break;
+ }
+ }
+ else
+ ret=true;
+
+ return ret;
+ }
+
+ /** get the document size */
+ TQSize docSize() {
+ return size;
+ }
+
+ void editClearAll() {
+ deleteContents();
+ setModified();
+ updateAllViews(null);
+
+ }
+
+}
diff --git a/tdejava/koala/examples/kscribble/KScribbleView.java b/tdejava/koala/examples/kscribble/KScribbleView.java
new file mode 100644
index 00000000..71b17329
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/KScribbleView.java
@@ -0,0 +1,342 @@
+import org.trinitydesktop.qt.*;
+import org.trinitydesktop.koala.*;
+
+/** The KScribbleView class provides the view widget for the KScribble instance.
+ * The View instance inherits TQWidget as a base class and represents the view object of a TDEMainWindow. As KScribbleView is part of the
+ * docuement-view model, it needs a reference to the document object connected with it by the KScribble class to manipulate and display
+ * the document structure provided by the KScribbleDoc class.
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 0.4 code generation
+ */
+public class KScribbleView extends TQScrollView {
+
+ private TQClipboard cb;
+ private KScribbleDoc doc;
+ private static final int IDLE = 0;
+ private static final int DRAW = 1;
+ private static final int SELECT = 2;
+ private static final int PASTE = 3;
+ private static final int DRAG = 4;
+
+ private TQPixmap tmp = new TQPixmap();
+
+ private int action = IDLE;
+ private TQRect select = new TQRect();
+
+ private TDEIconLoader k = new TDEIconLoader();
+ private TQImageDrag qid;
+
+ public KScribbleView(KScribbleDoc pDoc, TQWidget parent, String name, int wflags) {
+ super(parent, name,wflags | WPaintClever | WNorthWestGravity | WRepaintNoErase);
+ setBackgroundMode(PaletteBase);
+ cb = TQApplication.clipboard();
+ viewport().setAcceptDrops(true);
+ setDragAutoScroll(true);
+ doc=pDoc;
+ action=IDLE;
+ viewport().setCursor( Qt.crossCursor() );
+
+ TQSize size=doc.docSize();
+ resizeContents(size.width(), size.height());
+ resize(size);
+
+ }
+
+ void update(KScribbleView pSender){
+ if(pSender != this)
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ public KScribbleDoc getDocument() {
+ return doc;
+ }
+
+ protected void keyPressEvent( TQKeyEvent e ) {
+ switch (e.key()) {
+ case Key_Right:
+ scrollBy( 10, 0 );
+ break;
+ case Key_Left:
+ scrollBy( -10,0);
+ break;
+ case Key_Up:
+ scrollBy( 0, -10 );
+ break;
+ case Key_Down:
+ scrollBy( 0, 10 );
+ break;
+ case Key_Home:
+ setContentsPos(0,0);
+ break;
+ case Key_End:
+ setContentsPos(0,viewport().height()-viewport().height());
+ break;
+ case Key_PageUp:
+ scrollBy( 0, -viewport().height() );
+ break;
+ case Key_PageDown:
+ scrollBy( 0, viewport().height() );
+ break;
+ }
+
+ }
+
+ /** cuts out a selection */
+ void cutSelection() {
+ select=select.normalize();
+ TQPixmap cb_pix = new TQPixmap();
+ cb_pix.resize(select.size());
+ // copy selection to cb_pix and copy to clipboard
+ bitBlt(cb_pix,0, 0, doc.buffer, select.x()+contentsX(), select.y()+contentsY(), cb_pix.width(),cb_pix.height());
+ cb.setPixmap(cb_pix);
+ // fill cb_pix with white and copy to selection area
+ cb_pix.fill(Qt.white());
+ bitBlt(doc.buffer, select.x()+contentsX(), select.y()+contentsY(),cb_pix, 0, 0, cb_pix.width(), cb_pix.height());
+ action = IDLE;
+ doc.setModified();
+ doc.updateAllViews(this);
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ /** pastes the clipboard contents to a selection that can be inserted into the picture */
+ void pasteSelection(){
+ select=cb.pixmap().rect();
+ action = PASTE;
+ viewport().setCursor( Qt.sizeAllCursor() );
+ }
+
+ /** copies a selection to the clipboard */
+ void copySelection(){
+ select=select.normalize();
+ TQPixmap cb_pix = new TQPixmap();
+ cb_pix.resize(select.size());
+ // copy selection to cb_pix and copy to clipboard
+ bitBlt(cb_pix, 0, 0,doc.buffer, select.x()+contentsX(), select.y()+contentsY(), cb_pix.width(),cb_pix.height());
+ cb.setPixmap(cb_pix);
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ public void print(TQPrinter pPrinter) {
+ if (pPrinter.setup(this)) {
+ TQPainter p = new TQPainter();
+ p.begin(pPrinter);
+
+ ///////////////////////////////
+ // TODO: add your printing code here
+ p.drawPixmap(0,0,doc.buffer);
+ ///////////////////////////////
+ p.end();
+ }
+ }
+
+ protected void viewportMousePressEvent( TQMouseEvent e ) {
+ if ( e.button() == LeftButton && action == IDLE) {
+ action=DRAW;
+ doc.polyline.setPoint(0,viewportToContents(e.pos()));
+ doc.polyline.setPoint(1,viewportToContents(e.pos()));
+ doc.polyline.setPoint(2,viewportToContents(e.pos()));
+ doc.updateAllViews(this);
+ }
+ else if ( e.button() == RightButton && action == IDLE) {
+ action = SELECT;
+ TQPoint pt=e.pos();
+ int x = pt.x() > contentsWidth() ? contentsWidth() : pt.x();
+ int y = pt.y() > contentsHeight() ? contentsHeight() : pt.y();
+ select.setLeft(x-1);
+ select.setTop(y-1);
+ select.setRight(x-1);
+ select.setBottom(y-1);
+ }
+ else if( action == SELECT ) {
+ action = IDLE;
+
+ select=select.normalize();
+ // drag
+ if(select.contains(e.pos(), true)) { // point inside the selection
+ tmp.resize(select.size());
+ bitBlt(tmp, 0, 0, doc.buffer, select.x()+contentsX(), select.y()+contentsY(), tmp.width(),tmp.height());
+ TQImage img =tmp.convertToImage();
+ TQDragObject d = new TQImageDrag( img, viewport(), "" );
+ d.setPixmap(KDE.BarIcon("filenew"));
+ d.drag();
+ }
+ // remove selection
+ else
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ else if( action == PASTE ) {
+ if ( e.button() == RightButton ) {
+ action = IDLE;
+ viewport().setCursor( Qt.crossCursor() );
+ }
+ TQPoint mv_pt = new TQPoint(viewport().height(), viewport().width());
+ if(new TQRect(0,0,mv_pt.x(),mv_pt.y()).contains(e.pos()))
+ select.moveCenter(e.pos());
+ else {
+ select.moveBottomRight(mv_pt);
+ }
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ }
+
+ protected void viewportMouseReleaseEvent( TQMouseEvent e ) {
+ if ( action == DRAW ) {
+ action = IDLE;
+ doc.updateAllViews(this);
+ }
+ if ( action == SELECT) {
+ TQPoint pt=e.pos();
+ int x = pt.x() > 0 ? pt.x() : 0;
+ int y = pt.y() > 0 ? pt.y() : 0;
+ select.setRight(x);
+ select.setBottom(y);
+ TQSize size=doc.docSize();
+ select = select.intersect(new TQRect(0,0,size.width(), size.height()));
+ }
+ }
+
+ /** On paste actions inserts the pasted clipboard contents
+ */
+ protected void viewportMouseDoubleClickEvent(TQMouseEvent e) {
+ if( action == PASTE ) {
+ action = IDLE;
+ select.moveCenter(e.pos());
+ viewport().setCursor( Qt.crossCursor() );
+ TQPixmap cb_pix = new TQPixmap();
+ cb_pix.resize(cb.pixmap().size());
+ cb_pix=cb.pixmap();
+ bitBlt( doc.buffer,contentsX()+select.x(), contentsY()+select.y(),cb_pix, 0, 0, select.width(), select.height());
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+
+ }
+
+ protected void viewportMouseMoveEvent( TQMouseEvent e ) {
+ if ( action == DRAW ) {
+ TQPainter painter = new TQPainter();
+ painter.begin( doc.buffer );
+ painter.setPen( doc.currentPen() );
+ doc.polyline.setPoint(2, doc.polyline.at(1));
+ doc.polyline.setPoint(1, doc.polyline.at(0));
+ doc.polyline.setPoint(0, viewportToContents(e.pos()));
+ painter.drawPolyline( doc.polyline );
+ painter.end();
+
+ TQRect r = doc.polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft( r.left() - doc.penWidth() );
+ r.setTop( r.top() - doc.penWidth() );
+ r.setRight( r.right() + doc.penWidth() );
+ r.setBottom( r.bottom() + doc.penWidth() );
+
+ bitBlt(viewport(), r.x()-contentsX(), r.y()-contentsY(), doc.buffer, r.x(), r.y(), r.width(),r.height());
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ if ( action == SELECT ) {
+ TQPoint pt=e.pos();
+ select.setWidth(select.x()+pt.x());
+ select.setHeight(select.y()+pt.y());
+ select.setRight(pt.x());
+ select.setBottom(pt.y());
+ TQSize size=doc.docSize();
+ select = select.intersect(new TQRect(0,0,size.width(), size.height()));
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ if( action == PASTE ) {
+ TQPoint mv_pt = new TQPoint(viewport().height(), viewport().width());
+ if(new TQRect(0,0,mv_pt.x(),mv_pt.y()).contains(e.pos()))
+ select.moveCenter(e.pos());
+ else {
+ select.moveBottomRight(mv_pt);
+ }
+ TQRect pm_rect=cb.pixmap().rect();
+ select.setWidth(pm_rect.width());
+ select.setHeight(pm_rect.height());
+ TQSize size=doc.docSize();
+ select = select.intersect(new TQRect(0,0,size.width(), size.height()));
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ }
+
+ //void KScribbleView::viewportResizeEvent( TQResizeEvent *e )
+ //{
+ //}
+
+ protected void viewportPaintEvent( TQPaintEvent e ) {
+ bitBlt( viewport(),0, 0, doc.buffer, contentsX(), contentsY(), doc.buffer.width(),doc.buffer.width());
+
+ if( action == PASTE )
+ {
+ tmp.resize(cb.pixmap().size());
+ tmp=cb.pixmap();
+ }
+ if( action == PASTE || action == DRAG )
+ {
+ TQSize size=doc.docSize();
+ select = select.intersect(new TQRect(0,0,size.width(), size.height()));
+ if(select.intersects(e.rect()))
+ bitBlt(viewport(), select.x(), select.y(), tmp, 0, 0, select.width(), select.height());
+ }
+ if( action == PASTE || action == DRAG || action == SELECT ) {
+ if(select.intersects(e.rect())) {
+ TQPainter paint_area = new TQPainter();
+ paint_area.begin(viewport());
+ paint_area.setPen(new TQPen(Qt.black(), 0, DashLine));
+ paint_area.drawRect( select );
+ paint_area.end();
+ }
+ }
+
+ // not implemented for TQScrollView yet
+// super.viewportPaintEvent(e);
+ }
+
+ protected void viewportDragEnterEvent ( TQDragEnterEvent e) {
+ e.accept(TQImageDrag.canDecode(e));
+ action = DRAG;
+ }
+
+ protected void viewportDragMoveEvent ( TQDragMoveEvent e) {
+ TQImage img = new TQImage();
+
+ if ( TQImageDrag.canDecode(e) ){
+ TQImageDrag.decode(e, img);
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ select.setWidth(tmp.width());
+ select.setHeight(tmp.height());
+ select.moveCenter(e.pos());
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ }
+
+ protected void viewportDragLeaveEvent ( TQDragLeaveEvent e ) {
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ protected void viewportDropEvent ( TQDropEvent e) {
+ TQImage img = new TQImage();
+ if ( TQImageDrag.canDecode(e) ) {
+ TQImageDrag.decode(e, img);
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ select.setWidth(tmp.width());
+ select.setHeight(tmp.height());
+ select.moveCenter(e.pos());
+ bitBlt(doc.buffer, select.x()+contentsX(), select.y()+contentsY(), tmp,0,0,tmp.width(), tmp.height());
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+}
diff --git a/tdejava/koala/examples/kscribble/Main.java b/tdejava/koala/examples/kscribble/Main.java
new file mode 100644
index 00000000..bd6ee697
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/Main.java
@@ -0,0 +1,78 @@
+/***************************************************************************
+ KScribble.java - KScribble using java bindings
+ -------------------
+ begin : Mon Jan 31 11:05:05 CET 2000
+ copyright : (C) 2000 by Ralf Nolden
+ email : Ralf.Nolden@post.rwth-aachen.de
+ java translation : Kenneth J. Pouncey
+ email : kjpou@hotmail.com
+ ***************************************************************************/
+
+
+import java.util.*;
+import org.trinitydesktop.qt.*;
+import org.trinitydesktop.koala.*;
+
+/**
+ * The base class for JavaApiTest application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. An instance of KBaseView creates your center view, which is connected
+ * to the window's Doc object.
+ * KBase reimplements the methods that TDEMainWindow provides for main window handling and supports
+ * full session management as well as using TDEActions.
+ * @see TDEMainWindow
+ * @see TDEApplication
+ * @see TDEConfig
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class Main {
+
+ static String description = "java KDE 3 example application";
+
+
+ static String[][] options = {
+ { "+[File]", "image file to open", null }
+ };
+
+static String VERSION = "0.1";
+
+ public static void main(String[] cmdLineArgs) {
+
+ TDEAboutData aboutData = new TDEAboutData( "kscribble", "KScribble",
+ VERSION, description, TDEAboutData.License_GPL,
+ "(C) 2000 by Ralf Nolden");
+ TDECmdLineArgs.init( cmdLineArgs, aboutData );
+ TDECmdLineArgs.addCmdLineOptions( options ); // Add our own options.
+
+ TDEApplication app = new TDEApplication();
+ KImageIO.registerFormats();
+ KScribbleApp kscribbleapp = new KScribbleApp();
+
+ if (app.isRestored()) {
+ kscribbleapp.RESTORE("kscribbleapp");
+ }
+ else {
+ kscribbleapp.show();
+ TDECmdLineArgs args = TDECmdLineArgs.parsedArgs();
+
+ if (args.count() > 0) {
+ kscribbleapp.openDocumentFile(new KURL(args.arg(0)));
+ }
+ else {
+ kscribbleapp.openDocumentFile();
+ }
+ args.clear();
+ }
+
+ app.exec();
+ return;
+ }
+
+ static {
+ qtjava.initialize();
+ tdejava.initialize();
+ }
+
+}
diff --git a/tdejava/koala/examples/kscribble/Resource.java b/tdejava/koala/examples/kscribble/Resource.java
new file mode 100644
index 00000000..8277dea6
--- /dev/null
+++ b/tdejava/koala/examples/kscribble/Resource.java
@@ -0,0 +1,71 @@
+
+ ///////////////////////////////////////////////////////////////////
+ // resource.h -- contains macros used for commands
+public interface Resource {
+
+ ///////////////////////////////////////////////////////////////////
+ // COMMAND VALUES FOR MENUBAR AND TOOLBAR ENTRIES
+
+
+ ///////////////////////////////////////////////////////////////////
+ // File-menu entries
+ static final int ID_FILE_NEW = 10010;
+ static final int ID_FILE_OPEN = 10020;
+ static final int ID_FILE_OPEN_RECENT = 10030;
+ static final int ID_FILE_CLOSE = 10040;
+
+ static final int ID_FILE_SAVE = 10050;
+ static final int ID_FILE_SAVE_AS = 10060;
+
+ static final int ID_FILE_PRINT = 10070;
+
+ static final int ID_FILE_QUIT = 10080;
+
+ ///////////////////////////////////////////////////////////////////
+ // Edit-menu entries
+ static final int ID_EDIT_UNDO = 11010;
+ static final int ID_EDIT_COPY = 11020;
+ static final int ID_EDIT_CUT = 11030;
+ static final int ID_EDIT_PASTE = 11040;
+ static final int ID_EDIT_CLEAR_ALL = 11050;
+
+ ///////////////////////////////////////////////////////////////////
+ // Pen-menu entries
+ static final int ID_PEN_COLOR = 14010;
+ static final int ID_PEN_BRUSH = 14020;
+
+ ///////////////////////////////////////////////////////////////////
+ // Draw-menu entries
+ static final int ID_DRAW_FIND = 15010;
+ static final int ID_DRAW_FREEHAND = 15020;
+ static final int ID_DRAW_LINE = 15030;
+ static final int ID_DRAW_RECT = 15040;
+ static final int ID_DRAW_RECT_FILL = 15050;
+ static final int ID_DRAW_CIRCLE = 15060;
+ static final int ID_DRAW_CIRCLE_FILL = 15070;
+ static final int ID_DRAW_ELLIPSE = 15080;
+ static final int ID_DRAW_ELLIPSE_FILL = 15090;
+ static final int ID_DRAW_SPRAY = 15100;
+ static final int ID_DRAW_FILL = 15110;
+ static final int ID_DRAW_ERASE = 15120;
+
+ ///////////////////////////////////////////////////////////////////
+ // View-menu entries
+ static final int ID_VIEW_TOOLBAR = 12010;
+ static final int ID_VIEW_STATUSBAR = 12020;
+
+ ///////////////////////////////////////////////////////////////////
+ // Window-menu entries
+ static final int ID_WINDOW_NEW_WINDOW = 13010;
+ static final int ID_WINDOW_CASCADE = 13020;
+ static final int ID_WINDOW_TILE = 13030;
+
+ ///////////////////////////////////////////////////////////////////
+ // Help-menu entries
+ static final int ID_HELP_CONTENTS = 1002;
+ static final int ID_HELP_WHATS_THIS = 1003;
+ ///////////////////////////////////////////////////////////////////
+ // General application values
+ static final int ID_STATUS_MSG = 1001;
+ static final int TOOLS_TOOLBAR = 1;
+} \ No newline at end of file