summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/mainwindow
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/mainwindow') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/mainwindow/.cvsignore3
-rw-r--r--noncore/apps/tinykate/mainwindow/cgotobase.ui65
-rw-r--r--noncore/apps/tinykate/mainwindow/cgotoline.cpp23
-rw-r--r--noncore/apps/tinykate/mainwindow/cgotoline.h10
-rw-r--r--noncore/apps/tinykate/mainwindow/main.cpp25
-rw-r--r--noncore/apps/tinykate/mainwindow/mainwindow.pro12
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.cpp284
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.h66
8 files changed, 488 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/mainwindow/.cvsignore b/noncore/apps/tinykate/mainwindow/.cvsignore
new file mode 100644
index 0000000..e737538
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/.cvsignore
@@ -0,0 +1,3 @@
1Makefile*
2.moc
3.obj
diff --git a/noncore/apps/tinykate/mainwindow/cgotobase.ui b/noncore/apps/tinykate/mainwindow/cgotobase.ui
new file mode 100644
index 0000000..6660cb8
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/cgotobase.ui
@@ -0,0 +1,65 @@
1<!DOCTYPE UI><UI>
2<class>CGotoBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>CGotoBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>215</width>
15 <height>50</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Goto Line</string>
21 </property>
22 <hbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QLabel</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>TextLabel1</cstring>
36 </property>
37 <property stdset="1">
38 <name>sizePolicy</name>
39 <sizepolicy>
40 <hsizetype>0</hsizetype>
41 <vsizetype>1</vsizetype>
42 </sizepolicy>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>Line:</string>
47 </property>
48 <property stdset="1">
49 <name>alignment</name>
50 <set>AlignVCenter|AlignRight</set>
51 </property>
52 <property>
53 <name>hAlign</name>
54 </property>
55 </widget>
56 <widget>
57 <class>QSpinBox</class>
58 <property stdset="1">
59 <name>name</name>
60 <cstring>mLine</cstring>
61 </property>
62 </widget>
63 </hbox>
64</widget>
65</UI>
diff --git a/noncore/apps/tinykate/mainwindow/cgotoline.cpp b/noncore/apps/tinykate/mainwindow/cgotoline.cpp
new file mode 100644
index 0000000..97f2ea5
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/cgotoline.cpp
@@ -0,0 +1,23 @@
1#include "cgotoline.h"
2#include <qspinbox.h>
3// copyright 2003 Craig Graham <cgraham@accessdevices.co.uk>
4
5CGotoLine::CGotoLine(int l) : CGotoBase(0,0,true)
6{
7 mLine->setValue(l+1);
8}
9
10int CGotoLine::line()
11{
12 return mLine->value()-1;
13}
14
15void CGotoLine::keyPressEvent(QKeyEvent *e)
16{
17 if((e->key()==Key_Return)||(e->key()==Key_Enter))
18 {
19 accept();
20 }else{
21 QDialog::keyPressEvent(e);
22 }
23}
diff --git a/noncore/apps/tinykate/mainwindow/cgotoline.h b/noncore/apps/tinykate/mainwindow/cgotoline.h
new file mode 100644
index 0000000..29d6f42
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/cgotoline.h
@@ -0,0 +1,10 @@
1//
2// copyright 2003 Craig Graham <cgraham@accessdevices.co.uk>
3#include "cgotobase.h"
4class CGotoLine : public CGotoBase {
5public:
6 CGotoLine(int line);
7 int line();
8protected:
9 virtual void keyPressEvent(QKeyEvent *e);
10};
diff --git a/noncore/apps/tinykate/mainwindow/main.cpp b/noncore/apps/tinykate/mainwindow/main.cpp
new file mode 100644
index 0000000..c14d10a
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/main.cpp
@@ -0,0 +1,25 @@
1/***************************************************************************
2
3 main.cpp
4 -------------------
5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * *
16 ***************************************************************************/
17
18#include <opie2/oapplicationfactory.h>
19
20#include "tinykate.h"
21
22using namespace Opie::Core;
23
24OPIE_EXPORT_APP( OApplicationFactory<TinyKate> )
25
diff --git a/noncore/apps/tinykate/mainwindow/mainwindow.pro b/noncore/apps/tinykate/mainwindow/mainwindow.pro
new file mode 100644
index 0000000..94d00bd
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/mainwindow.pro
@@ -0,0 +1,12 @@
1TEMPLATE = app
2CONFIG = qt warn_on quick-app
3DESTDIR = $(OPIEDIR)/bin
4HEADERS = tinykate.h
5SOURCES = tinykate.cpp main.cpp
6INCLUDEPATH = $(OPIEDIR)/include ../libkate \
7 ../libkate/ktexteditor ../libkate/document ../libkate/microkde ../libkate/qt3back ../libkate/view ../libkate/interfaces
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe -lkate -lopiecore2 -lopieui2
10TARGET = tinykate
11
12include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp
new file mode 100644
index 0000000..9865c35
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp
@@ -0,0 +1,284 @@
1/***************************************************************************
2 tinykate.cpp
3 Tiny KATE mainwindow
4 -------------------
5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free softwaSre; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * *
16 ***************************************************************************/
17
18#include "tinykate.h"
19
20#include "katedocument.h"
21#include "kglobal.h"
22
23/* OPIE */
24#include <opie2/odebug.h>
25#include <opie2/ofiledialog.h>
26#include <qpe/resource.h>
27#include <qpe/qpeapplication.h>
28
29/* QT */
30#include <qaction.h>
31#include <qtoolbutton.h>
32#include <qmenubar.h>
33
34
35using namespace Opie::Ui;
36TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
37 QMainWindow( parent, name, f )
38{
39 shutDown=false;
40 nextUnnamed=0;
41 currentView=0;
42 viewCount=0;
43 setCaption(tr("TinyKATE"));
44 KGlobal::setAppName("TinyKATE");
45
46 QMenuBar *mb = new QMenuBar( this );
47 mb->setMargin( 0 );
48
49 tabwidget=new OTabWidget(this);
50 setCentralWidget(tabwidget);
51 connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*)));
52
53//FILE ACTIONS
54 QPopupMenu *popup = new QPopupMenu( this );
55
56 // Action for creating a new document
57 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
58 a->addTo( popup );
59 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
60
61 // Action for opening an exisiting document
62 a = new QAction( tr( "Open" ),Resource::loadPixmap( "fileopen" ) , QString::null, 0, this, 0 );
63 a->addTo(popup);
64 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
65
66
67 // Action for saving document
68 a = new QAction( tr( "Save" ), Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 );
69 a->addTo(popup);
70 connect(a, SIGNAL(activated()), this, SLOT(slotSave()));
71
72 // Action for saving document to a new name
73 a = new QAction( tr( "Save As" ),Resource::loadPixmap( "save" ) , QString::null, 0, this, 0 );
74 a->addTo(popup);
75 connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs()));
76
77 // Action for closing the currently active document
78 a = new QAction( tr( "Close" ), Resource::loadPixmap( "quit_icon" ) , QString::null, 0, this, 0 );
79 a->addTo(popup);
80 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
81
82
83 mb->insertItem(tr("File"),popup);
84
85//EDIT ACTIONS
86
87 // Action for cutting text
88 editCut = new QToolButton( 0 );
89 editCut->setAutoRaise( true );
90 editCut->setIconSet( Resource::loadPixmap( "cut" ) );
91
92 // Action for Copying text
93 editCopy = new QToolButton( 0 );
94 editCopy->setAutoRaise( true );
95 editCopy->setIconSet( Resource::loadPixmap( "copy" ) );
96
97 // Action for pasting text
98 editPaste = new QToolButton( 0 );
99 editPaste->setAutoRaise( true );
100 editPaste->setIconSet( Resource::loadPixmap( "paste" ) );
101
102 // Action for finding / replacing text
103 editFindReplace = new QToolButton( 0 );
104 editFindReplace->setAutoRaise( true );
105 editFindReplace->setIconSet( Resource::loadPixmap("find") );
106
107 // Action for undo
108 editUndo = new QToolButton( 0 );
109 editUndo->setAutoRaise( true );
110 editUndo->setIconSet( Resource::loadPixmap( "undo" ) );
111
112 // Action for redo
113 editRedo = new QToolButton( 0 );
114 editRedo->setAutoRaise( true );
115 editRedo->setIconSet( Resource::loadPixmap( "redo" ) );
116
117//VIEW ACITONS
118 popup = new QPopupMenu( this );
119
120 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
121 viewIncFontSizes->addTo( popup );
122
123 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
124 viewDecFontSizes->addTo( popup );
125
126 mb->insertItem(tr("View"),popup);
127
128 popup = new QPopupMenu( this );
129 mb->insertItem(tr("Utils"),popup);
130
131
132 mb->insertItem( editCut );
133 mb->insertItem( editCopy );
134 mb->insertItem( editPaste );
135 mb->insertItem( editFindReplace );
136 mb->insertItem( editUndo );
137 mb->insertItem( editRedo );
138
139
140//Highlight management
141 hlmenu=new QPopupMenu(this);
142 HlManager *hlm=HlManager::self();
143 for (int i=0;i<hlm->highlights();i++)
144 {
145 hlmenu->insertItem(hlm->hlName(i),i);
146 }
147 popup->insertItem(tr("Highlighting"),hlmenu);
148
149
150 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
151 utilSettings->addTo( popup);
152
153 if( qApp->argc() > 1) open(qApp->argv()[1]);
154 else slotNew();
155
156}
157
158TinyKate::~TinyKate( )
159{
160 owarn << "TinyKate destructor\n" << oendl;
161
162 shutDown=true;
163 while (currentView!=0) {
164 slotClose();
165 }
166
167 if( KGlobal::config() != 0 ) {
168 owarn << "deleting KateConfig object..\n" << oendl;
169 delete KGlobal::config();
170 }
171}
172
173void TinyKate::slotOpen( )
174{
175 QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
176 QString::null);
177 if (!filename.isEmpty()) {
178 open(filename);
179 }
180}
181
182void TinyKate::open(const QString & filename)
183{
184 KateDocument *kd= new KateDocument(false, false, this,0,this);
185 KTextEditor::View *kv;
186 QFileInfo fi(filename);
187 QString filenamed = fi.fileName();
188 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed );
189 odebug << filename << oendl;
190
191 kd->setDocName( filenamed);
192 kd->open( filename );
193 viewCount++;
194}
195
196void TinyKate::setDocument(const QString& fileref)
197{
198 open( fileref );
199}
200
201void TinyKate::slotCurrentChanged( QWidget * view)
202{
203 if (currentView) {
204
205 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
206 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
207 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
208 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
209 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
210 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
211 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
212 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
213 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
214 }
215
216 currentView=(KTextEditor::View*)view;
217
218 connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
219 connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
220 connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
221 connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
222 connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
223 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
224 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
225 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
226 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
227
228}
229
230void TinyKate::slotNew( )
231{
232 KateDocument *kd= new KateDocument(false, false, this,0,this);
233 KTextEditor::View *kv;
234 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
235 "tinykate/tinykate",
236 tr("Unnamed %1").arg(nextUnnamed++));
237 viewCount++;
238}
239
240void TinyKate::slotClose( )
241{
242 if (currentView==0) return;
243 KTextEditor::View *dv=currentView;
244 currentView=0;
245 tabwidget->removePage(dv);
246 delete dv->document();
247 viewCount--;
248 if ((!viewCount) && (!shutDown)) slotNew();
249}
250
251void TinyKate::slotSave() {
252 // feel free to make this how you want
253 if (currentView==0) return;
254
255 // KateView *kv = (KateView*) currentView;
256 KateDocument *kd = (KateDocument*) currentView->document();
257 // odebug << "saving file "+kd->docName() << oendl;
258 if( kd->docName().isEmpty())
259 slotSaveAs();
260 else
261 kd->saveFile();
262 // kv->save();
263 // kd->saveFile();
264}
265
266void TinyKate::slotSaveAs() {
267 if (currentView==0) return;
268 KateDocument *kd = (KateDocument*) currentView->document();
269
270 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
271 QString::null);
272 if (!filename.isEmpty()) {
273 odebug << "saving file "+filename << oendl;
274 QFileInfo fi(filename);
275 QString filenamed = fi.fileName();
276 kd->setDocFile( filename);
277 kd->setDocName( filenamed);
278 kd->saveFile();
279// KTextEditor::View *dv = currentView;
280// tabwidget->changeTab( dv, filenamed);
281 // need to change tab label here
282 }
283
284}
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.h b/noncore/apps/tinykate/mainwindow/tinykate.h
new file mode 100644
index 0000000..f435c03
--- a/dev/null
+++ b/noncore/apps/tinykate/mainwindow/tinykate.h
@@ -0,0 +1,66 @@
1/***************************************************************************
2 tinykate.h
3 Tiny KATE mainwindow
4 -------------------
5 begin : November 2002
6 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation. *
14 * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE *
15 * *
16 ***************************************************************************/
17
18#ifndef __TINYKATE_H__
19#define __TINYKATE_H__
20
21
22#include <qmainwindow.h>
23#include <opie2/otabwidget.h>
24#include <ktexteditor.h>
25
26class QToolButton;
27class QAction;
28class QPopupMenu;
29
30class TinyKate : public QMainWindow
31{
32Q_OBJECT
33public:
34 TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
35 ~TinyKate( );
36 static QString appName() { return QString::fromLatin1( "kate" ); };
37
38
39public slots:
40 void slotNew();
41 void setDocument(const QString& fileref);
42
43protected slots:
44 void slotOpen();
45 void slotClose();
46 void slotCurrentChanged(QWidget *);
47 void slotSave();
48 void slotSaveAs();
49protected:
50 void open(const QString&);
51private:
52 QString currentFileName;
53 Opie::Ui::OTabWidget *tabwidget;
54 KTextEditor::View *currentView;
55 bool shutDown;
56
57 QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo, *editFindReplace;
58 QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings;
59
60 QPopupMenu *hlmenu;
61 uint nextUnnamed;
62 uint viewCount;
63};
64
65
66#endif // __TINYKATE_H__