Diffstat (limited to 'noncore/apps/tinykate/tinykate.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 157 |
1 files changed, 101 insertions, 56 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index ea7ea45..dda8405 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp @@ -10,3 +10,3 @@ * * - * This program is free softwaSre; you can redistribute it and/or modify * + * 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 * @@ -19,4 +19,4 @@ #include <qlayout.h> -#include <qtoolbutton.h> -#include <qmenubar.h> +#include <qpe/qpetoolbar.h> +#include <qpe/qpemenubar.h> #include <qpe/resource.h> @@ -27,2 +27,4 @@ +#include "cgotoline.h" + #include "tinykate.h" @@ -36,3 +38,3 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : QMainWindow( parent, name, f ) -{ +{ nextUnnamed=0; @@ -40,7 +42,13 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : viewCount=0; - setCaption(tr("TinyKATE")); + setCaption("TinyKATE : line 1 col 1"); KGlobal::setAppName("TinyKATE"); - QMenuBar *mb = new QMenuBar( this ); - mb->setMargin( 0 ); + curLine=curCol=1; + + setToolBarsMovable(FALSE); + + QPEToolBar *bar = new QPEToolBar( this ); + bar->setHorizontalStretchable( TRUE ); + QPEMenuBar *mb = new QPEMenuBar( bar ); + mb->setMargin( 0 ); @@ -54,3 +62,3 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for creating a new document - QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); + QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, CTRL+Key_N, this, 0 ); a->addTo( popup ); @@ -59,3 +67,3 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for opening an exisiting document - a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 ); + a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, CTRL+Key_O, this, 0 ); a->addTo(popup); @@ -65,3 +73,3 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for saving document - a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); + a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ), QString::null, CTRL+Key_S, this, 0 ); a->addTo(popup); @@ -70,3 +78,3 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for saving document to a new name - a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 ); + a = new QAction( tr( "Save As" ), Resource::loadPixmap( "save" ), QString::null, 0, this, 0 ); a->addTo(popup); @@ -75,6 +83,6 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for closing the currently active document - a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 ); + a = new QAction( tr( "Close" ), Resource::loadPixmap( "close" ), QString::null, CTRL+Key_W, this, 0 ); a->addTo(popup); connect(a, SIGNAL(activated()), this, SLOT(slotClose())); - + @@ -85,30 +93,27 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : // Action for cutting text - editCut = new QToolButton( 0 ); - editCut->setAutoRaise( true ); - editCut->setIconSet( Resource::loadPixmap( "cut" ) ); + editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, CTRL+Key_X, this, 0 ); + editCut->addTo( bar ); // Action for Copying text - editCopy = new QToolButton( 0 ); - editCopy->setAutoRaise( true ); - editCopy->setIconSet( Resource::loadPixmap( "copy" ) ); + editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, CTRL+Key_C, this, 0 ); + editCopy->addTo( bar ); // Action for pasting text - editPaste = new QToolButton( 0 ); - editPaste->setAutoRaise( true ); - editPaste->setIconSet( Resource::loadPixmap( "paste" ) ); + editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, CTRL+Key_V, this, 0 ); + editPaste->addTo( bar ); + // Action for finding / replacing text - editFindReplace = new QToolButton( 0 ); - editFindReplace->setAutoRaise( true ); - editFindReplace->setIconSet( Resource::loadPixmap("find") ); + editFindReplace = new QAction( tr( "Replace" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_R, this, 0 ); + editFind = new QAction( tr( "Find" ), Resource::loadPixmap("find"), QString::null, CTRL+Key_F, this, 0 ); + editFind->addTo( bar ); - // Action for undo - editUndo = new QToolButton( 0 ); - editUndo->setAutoRaise( true ); - editUndo->setIconSet( Resource::loadPixmap( "undo" ) ); + // Action for undo + editUndo = new QAction( tr( "Undo" ), Resource::loadPixmap( "undo" ), QString::null, CTRL+Key_Z, this, 0 ); + editUndo->addTo( bar ); // Action for redo - editRedo = new QToolButton( 0 ); - editRedo->setAutoRaise( true ); - editRedo->setIconSet( Resource::loadPixmap( "redo" ) ); + editRedo = new QAction( tr( "Redo" ), Resource::loadPixmap( "redo" ), QString::null, CTRL+SHIFT+Key_Z, this, 0 ); + editRedo->addTo( bar ); + @@ -116,3 +121,7 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : popup = new QPopupMenu( this ); - + + a = new QAction( tr( "Goto" ), QString::null, CTRL+Key_G, this, 0 ); + a->addTo( popup ); + connect(a, SIGNAL(activated()), this, SLOT(slotGoTo())); + viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); @@ -123,15 +132,8 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : - mb->insertItem(tr("View"),popup); - - popup = new QPopupMenu( this ); - mb->insertItem(tr("Utils"),popup); + mb->insertItem(tr("View"),popup); - mb->insertItem( editCut ); - mb->insertItem( editCopy ); - mb->insertItem( editPaste ); - mb->insertItem( editFindReplace ); - mb->insertItem( editUndo ); - mb->insertItem( editRedo ); + popup = new QPopupMenu( this ); + mb->insertItem(tr("Utils"),popup); @@ -150,2 +152,6 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : + popup->insertSeparator(); + editFind->addTo(popup); + editFindReplace->addTo(popup); + if( qApp->argc() > 1) open(qApp->argv()[1]); @@ -158,3 +164,5 @@ TinyKate::~TinyKate( ) qWarning("TinyKate destructor\n"); + printf("~TinyKate()\n"); if( KGlobal::config() != 0 ) { + printf("~TinyKate(): delete configs...\n"); qWarning("deleting KateConfig object..\n"); @@ -167,3 +175,3 @@ void TinyKate::slotOpen( ) QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, - QPEApplication::documentDir()); + QString::null); if (!filename.isEmpty()) { @@ -187,5 +195,6 @@ void TinyKate::open(const QString & filename) -void TinyKate::setDocument(const QString& fileref) +void TinyKate::setDocument(const QString &doc) { - open( fileref ); + printf("tinykate: setDocument(\"%s\")\n",(const char*)doc); + open(doc); } @@ -201,6 +210,9 @@ void TinyKate::slotCurrentChanged( QWidget * view) disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); - disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); - disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); + disconnect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace())); + disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find())); + disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); + disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); + disconnect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved())); } @@ -208,8 +220,10 @@ void TinyKate::slotCurrentChanged( QWidget * view) currentView=(KTextEditor::View*)view; - - connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); - connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); - connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); - connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); - connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); + + connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); + connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); + connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); + connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); + connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); + connect(editFindReplace,SIGNAL(activated()),currentView,SLOT(replace())); + connect(editFind,SIGNAL(activated()),currentView,SLOT(find())); connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); @@ -218,3 +232,3 @@ void TinyKate::slotCurrentChanged( QWidget * view) connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); - + connect(currentView,SIGNAL(newCurPos()),this,SLOT(slotCursorMoved())); } @@ -262,3 +276,3 @@ void TinyKate::slotSaveAs() { QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, - QPEApplication::documentDir()); + QString::null); if (!filename.isEmpty()) { @@ -276 +290,32 @@ void TinyKate::slotSaveAs() { } + +void TinyKate::slotGoTo() +{ + int l,c; + if (currentView==0) return; + + currentView->getCursorPosition(&l,&c); + + CGotoLine g(l); + + if(g.exec()==QDialog::Accepted) + { + currentView->setCursorPosition( g.line(), c ); + } +} + +void TinyKate::slotCursorMoved() +{ + char buf[100]; + int newLine,newCol; + currentView->getCursorPosition(&newLine,&newCol); + newLine++; + newCol++; + if((newLine!=curLine)||(newCol!=curCol)) + { + sprintf(buf,"TinyKATE : line %-6d col %d",newLine,newCol); + setCaption(buf); + curLine=newLine; + curCol=newCol; + } +} |